map.h 9.1 KB

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