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