map.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. #ifndef MAPD_H
  2. #define MAPD_H
  3. #include <string>
  4. #include <vector>
  5. #include "global.h"
  6. #include "hch\CSemiDefHandler.h"
  7. #include "hch\CDefHandler.h"
  8. enum ESortBy{name,playerAm,size,format, viccon,loscon};
  9. struct Sresource
  10. {
  11. std::string resName; //name of this resource
  12. int amount; //it can be greater and lesser than 0
  13. };
  14. struct TimeEvent
  15. {
  16. std::string eventName;
  17. std::string message;
  18. std::vector<Sresource> decIncRes; //decreases / increases of resources
  19. unsigned int whichPlayers; //which players are affected by this event (+1 - first, +2 - second, +4 - third, +8 - fourth etc.)
  20. bool areHumansAffected;
  21. bool areCompsAffected;
  22. int firstAfterNDays; //how many days after appears this event
  23. int nextAfterNDays; //how many days after the epperance before appaers this event
  24. //bajty wydarzeñ (59 + |teksty|)
  25. //4 bajty na d³ugoœæ nazwy zdarzenia
  26. //nazwa zdarzenia (bajty dodatkowe)
  27. //4 bajty na d³ugoœæ wiadomoœci
  28. //wiadomoϾ (bajty dodatkowe)
  29. //4 bajty na zwiêkszenie siê ilosci drewna (zapis normalny) lub ff,ff,ff,ff - iloœæ drewna do odebrania (maksymalna iloœæ drewna, któr¹ mo¿na daæ/odebraæ to 32767)
  30. //4 bajty na zwiêkszenie siê ilosci rtêci (zapis normalny) lub ff,ff,ff,ff - iloœæ rtêci do odebrania (maksymalna iloœæ rtêci, któr¹ mo¿na daæ/odebraæ to 32767)
  31. //4 bajty na zwiêkszenie siê ilosci rudy (zapis normalny) lub ff,ff,ff,ff - iloœæ rudy do odebrania (maksymalna iloœæ rudy, któr¹ mo¿na daæ/odebraæ to 32767)
  32. //4 bajty na zwiêkszenie siê ilosci siarki (zapis normalny) lub ff,ff,ff,ff - iloœæ siarki do odebrania (maksymalna iloœæ siarki, któr¹ mo¿na daæ/odebraæ to 32767)
  33. //4 bajty na zwiêkszenie siê ilosci kryszta³u (zapis normalny) lub ff,ff,ff,ff - iloœæ kryszta³u do odebrania (maksymalna iloœæ kryszta³u, któr¹ mo¿na daæ/odebraæ to 32767)
  34. //4 bajty na zwiêkszenie siê ilosci klejnotów (zapis normalny) lub ff,ff,ff,ff - iloœæ klejnotów do odebrania (maksymalna iloœæ klejnotów, któr¹ mo¿na daæ/odebraæ to 32767)
  35. //4 bajty na zwiêkszenie siê ilosci z³ota (zapis normalny) lub ff,ff,ff,ff - iloœæ z³ota do odebrania (maksymalna iloœæ z³ota, któr¹ mo¿na daæ/odebraæ to 32767)
  36. //1 bajt - których graczy dotyczy zdarzenie (pole bitowe, +1 - pierwszy, +2 - drugi, +4 - trzeci, +8 - czwarty, +16 - pi¹ty, +32 - szósty, +64 - siódmy, +128 - ósmy)
  37. //1 bajt - czy zdarzenie odnosi siê do graczy - ludzi (00 - nie, 01 - tak)
  38. //1 bajt - czy zdarzenie odnosi siê do graczy komputerowych (00 - nie, 01 - tak)
  39. //2 bajty - opóŸnienie pierwszego wyst¹pienia (w dniach, zapis normalny, maks 671)
  40. //1 bajt - co ile dni wystêpuje zdarzenie (maks 28, 00 oznacza zdarzenie jednorazowe)
  41. //17 bajtów zerowych
  42. };
  43. struct TerrainTile
  44. {
  45. EterrainType tertype; // type of terrain
  46. unsigned int terview; // look of terrain
  47. Eriver nuine; // type of Eriver (0 if there is no Eriver)
  48. unsigned int rivDir; // direction of Eriver
  49. Eroad malle; // type of Eroad (0 if there is no Eriver)
  50. unsigned int roadDir; // direction of Eroad
  51. unsigned int siodmyTajemniczyBajt; // mysterius byte // jak bedzie waidomo co to, to sie nazwie inaczej
  52. };
  53. struct DefInfo //information from def declaration
  54. {
  55. std::string name;
  56. int bytes [42];
  57. //CSemiDefHandler * handler;
  58. CDefHandler * handler;
  59. int printPriority;
  60. bool isOnDefList;
  61. bool isVisitable();
  62. };
  63. struct Location
  64. {
  65. int x, y;
  66. bool z; // underground
  67. };
  68. struct SheroName //name of starting hero
  69. {
  70. int heroID;
  71. std::string heroName;
  72. };
  73. struct PlayerInfo
  74. {
  75. int p8, p9;
  76. bool canHumanPlay;
  77. bool canComputerPlay;
  78. unsigned int AITactic; //(00 - random, 01 - warrior, 02 - builder, 03 - explorer)
  79. unsigned int allowedFactions; //(01 - castle; 02 - rampart; 04 - tower; 08 - inferno; 16 - necropolis; 32 - dungeon; 64 - stronghold; 128 - fortress; 256 - conflux);
  80. bool isFactionRandom;
  81. unsigned int mainHeroPortrait; //it's ID of hero with choosen portrait; 255 if standard
  82. std::string mainHeroName;
  83. std::vector<SheroName> heroesNames;
  84. bool hasMainTown;
  85. bool generateHeroAtMainTown;
  86. Location posOfMainTown;
  87. int team;
  88. bool generateHero;
  89. };
  90. struct LossCondition
  91. {
  92. ElossCon typeOfLossCon;
  93. union
  94. {
  95. Location castlePos;
  96. Location heroPos;
  97. int timeLimit; // in days
  98. };
  99. };
  100. struct CspecificVictoryConidtions
  101. {
  102. bool allowNormalVictory;
  103. bool appliesToAI;
  104. };
  105. struct VicCon0 : public CspecificVictoryConidtions //acquire artifact
  106. {
  107. int ArtifactID;
  108. };
  109. struct VicCon1 : public CspecificVictoryConidtions //accumulate creatures
  110. {
  111. int monsterID;
  112. int neededQuantity;
  113. };
  114. struct VicCon2 : public CspecificVictoryConidtions // accumulate resources
  115. {
  116. int resourceID;
  117. int neededQuantity;
  118. };
  119. struct VicCon3 : public CspecificVictoryConidtions // upgrade specific town
  120. {
  121. Location posOfCity;
  122. int councilNeededLevel; //0 - town; 1 - city; 2 - capitol
  123. int fortNeededLevel;// 0 - fort; 1 - citadel; 2 - castle
  124. };
  125. struct VicCon4 : public CspecificVictoryConidtions // build grail structure
  126. {
  127. bool anyLocation;
  128. Location whereBuildGrail;
  129. };
  130. struct VicCon5 : public CspecificVictoryConidtions // defeat a specific hero
  131. {
  132. Location locationOfHero;
  133. };
  134. struct VicCon6 : public CspecificVictoryConidtions // capture a specific town
  135. {
  136. Location locationOfTown;
  137. };
  138. struct VicCon7 : public CspecificVictoryConidtions // defeat a specific monster
  139. {
  140. Location locationOfMonster;
  141. };
  142. /*struct VicCon8 : public CspecificVictoryConidtions // flag all creature dwellings
  143. {
  144. };
  145. struct VicCon9 : public CspecificVictoryConidtions // flag all mines
  146. {
  147. };*/
  148. struct VicCona : public CspecificVictoryConidtions //transport specific artifact
  149. {
  150. int artifactID;
  151. Location destinationPlace;
  152. };
  153. struct Rumor
  154. {
  155. std::string name, text;
  156. };
  157. class CMapEvent
  158. {
  159. public:
  160. std::string name, message;
  161. int wood, mercury, ore, sulfur, crystal, gems, gold; //gained / taken resources
  162. unsigned char players; //affected players
  163. bool humanAffected;
  164. bool computerAffected;
  165. int firstOccurence;
  166. int nextOccurence; //after nextOccurance day event will occure; if it it 0, event occures only one time;
  167. };
  168. struct Mapa
  169. {
  170. Eformat version; // version of map Eformat
  171. bool twoLevel; // if map has underground level
  172. int difficulty; // 0 easy - 4 impossible
  173. int levelLimit;
  174. bool areAnyPLayers; // if there are any playable players on map
  175. std::string name; //name of map
  176. std::string description; //and description
  177. int height, width;
  178. TerrainTile** terrain;
  179. TerrainTile** undergroungTerrain; // used only if there is underground level
  180. std::vector<Rumor> rumors;
  181. std::vector<DefInfo> defy; // list of .def files
  182. PlayerInfo players[8]; // info about players
  183. std::vector<int> teams; // teams[i] = team of player no i
  184. LossCondition lossCondition;
  185. EvictoryConditions victoryCondition; //victory conditions
  186. CspecificVictoryConidtions * vicConDetails; // used only if vistory conditions aren't standard
  187. int howManyTeams;
  188. std::vector<CMapEvent> events;
  189. };
  190. class CMapHeader
  191. {
  192. public:
  193. Eformat version; // version of map Eformat
  194. bool areAnyPLayers; // if there are any playable players on map
  195. int height, width;
  196. bool twoLevel; // if map has underground level
  197. std::string name; //name of map
  198. std::string description; //and description
  199. int difficulty; // 0 easy - 4 impossible
  200. int levelLimit;
  201. LossCondition lossCondition;
  202. EvictoryConditions victoryCondition; //victory conditions
  203. CspecificVictoryConidtions * vicConDetails; // used only if vistory conditions aren't standard
  204. PlayerInfo players[8]; // info about players
  205. std::vector<int> teams; // teams[i] = team of player no i
  206. int howManyTeams;
  207. CMapHeader(unsigned char *map); //an argument is a reference to string described a map (unpacked)
  208. };
  209. class CMapInfo : public CMapHeader
  210. {
  211. public:
  212. std::string filename;
  213. int playerAmnt, humenPlayers;
  214. CMapInfo(std::string fname, unsigned char *map):CMapHeader(map),filename(fname)
  215. {
  216. playerAmnt=humenPlayers=0;
  217. for (int i=0;i<PLAYER_LIMIT;i++)
  218. {
  219. if (players[i].canHumanPlay) {playerAmnt++;humenPlayers++;}
  220. else if (players[i].canComputerPlay) {playerAmnt++;}
  221. }
  222. };
  223. };
  224. class mapSorter
  225. {
  226. public:
  227. ESortBy sortBy;
  228. bool operator()(CMapHeader & a, CMapHeader& b)
  229. {
  230. switch (sortBy)
  231. {
  232. case ESortBy::format:
  233. return (a.version<b.version);
  234. break;
  235. case ESortBy::loscon:
  236. return (a.lossCondition.typeOfLossCon<b.lossCondition.typeOfLossCon);
  237. break;
  238. case ESortBy::playerAm:
  239. int playerAmntB,humenPlayersB,playerAmntA,humenPlayersA;
  240. playerAmntB=humenPlayersB=playerAmntA=humenPlayersA=0;
  241. for (int i=0;i<8;i++)
  242. {
  243. if (a.players[i].canHumanPlay) {playerAmntA++;humenPlayersA++;}
  244. else if (a.players[i].canComputerPlay) {playerAmntA++;}
  245. if (b.players[i].canHumanPlay) {playerAmntB++;humenPlayersB++;}
  246. else if (b.players[i].canComputerPlay) {playerAmntB++;}
  247. }
  248. if (playerAmntB!=playerAmntA)
  249. return (playerAmntA<playerAmntB);
  250. else
  251. return (humenPlayersA<humenPlayersB);
  252. break;
  253. case ESortBy::size:
  254. return (a.width<b.width);
  255. break;
  256. case ESortBy::viccon:
  257. return (a.victoryCondition<b.victoryCondition);
  258. break;
  259. case ESortBy::name:
  260. return (a.name<b.name);
  261. break;
  262. default:
  263. return (a.name<b.name);
  264. break;
  265. }
  266. };
  267. mapSorter(ESortBy es):sortBy(es){};
  268. };
  269. #endif //MAPD_H