map.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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 Location
  66. {
  67. int x, y;
  68. bool z; // underground
  69. };
  70. struct SheroName //name of starting hero
  71. {
  72. int heroID;
  73. std::string heroName;
  74. };
  75. struct PlayerInfo
  76. {
  77. int p8, p9;
  78. bool canHumanPlay;
  79. bool canComputerPlay;
  80. unsigned int AITactic; //(00 - random, 01 - warrior, 02 - builder, 03 - explorer)
  81. unsigned int allowedFactions; //(01 - castle; 02 - rampart; 04 - tower; 08 - inferno; 16 - necropolis; 32 - dungeon; 64 - stronghold; 128 - fortress; 256 - conflux);
  82. bool isFactionRandom;
  83. unsigned int mainHeroPortrait; //it's ID of hero with choosen portrait; 255 if standard
  84. std::string mainHeroName;
  85. std::vector<SheroName> heroesNames;
  86. bool hasMainTown;
  87. bool generateHeroAtMainTown;
  88. Location posOfMainTown;
  89. int team;
  90. bool generateHero;
  91. };
  92. struct LossCondition
  93. {
  94. ElossCon typeOfLossCon;
  95. union
  96. {
  97. Location castlePos;
  98. Location heroPos;
  99. int timeLimit; // in days
  100. };
  101. };
  102. struct CspecificVictoryConidtions
  103. {
  104. bool allowNormalVictory;
  105. bool appliesToAI;
  106. };
  107. struct VicCon0 : public CspecificVictoryConidtions //acquire artifact
  108. {
  109. int ArtifactID;
  110. };
  111. struct VicCon1 : public CspecificVictoryConidtions //accumulate creatures
  112. {
  113. int monsterID;
  114. int neededQuantity;
  115. };
  116. struct VicCon2 : public CspecificVictoryConidtions // accumulate resources
  117. {
  118. int resourceID;
  119. int neededQuantity;
  120. };
  121. struct VicCon3 : public CspecificVictoryConidtions // upgrade specific town
  122. {
  123. Location posOfCity;
  124. int councilNeededLevel; //0 - town; 1 - city; 2 - capitol
  125. int fortNeededLevel;// 0 - fort; 1 - citadel; 2 - castle
  126. };
  127. struct VicCon4 : public CspecificVictoryConidtions // build grail structure
  128. {
  129. bool anyLocation;
  130. Location whereBuildGrail;
  131. };
  132. struct VicCon5 : public CspecificVictoryConidtions // defeat a specific hero
  133. {
  134. Location locationOfHero;
  135. };
  136. struct VicCon6 : public CspecificVictoryConidtions // capture a specific town
  137. {
  138. Location locationOfTown;
  139. };
  140. struct VicCon7 : public CspecificVictoryConidtions // defeat a specific monster
  141. {
  142. Location locationOfMonster;
  143. };
  144. /*struct VicCon8 : public CspecificVictoryConidtions // flag all creature dwellings
  145. {
  146. };
  147. struct VicCon9 : public CspecificVictoryConidtions // flag all mines
  148. {
  149. };*/
  150. struct VicCona : public CspecificVictoryConidtions //transport specific artifact
  151. {
  152. int artifactID;
  153. Location destinationPlace;
  154. };
  155. struct Rumor
  156. {
  157. std::string name, text;
  158. };
  159. class CMapEvent
  160. {
  161. public:
  162. std::string name, message;
  163. int wood, mercury, ore, sulfur, crystal, gems, gold; //gained / taken resources
  164. unsigned char players; //affected players
  165. bool humanAffected;
  166. bool computerAffected;
  167. int firstOccurence;
  168. int nextOccurence; //after nextOccurance day event will occure; if it it 0, event occures only one time;
  169. };
  170. struct Mapa
  171. {
  172. Eformat version; // version of map Eformat
  173. int twoLevel; // if map has underground level
  174. int difficulty; // 0 easy - 4 impossible
  175. int levelLimit;
  176. bool areAnyPLayers; // if there are any playable players on map
  177. std::string name; //name of map
  178. std::string description; //and description
  179. int height, width;
  180. TerrainTile** terrain;
  181. TerrainTile** undergroungTerrain; // used only if there is underground level
  182. std::vector<Rumor> rumors;
  183. std::vector<CGDefInfo *> defy; // list of .def files
  184. PlayerInfo players[8]; // info about players
  185. std::vector<int> teams; // teams[i] = team of player no i
  186. LossCondition lossCondition;
  187. EvictoryConditions victoryCondition; //victory conditions
  188. CspecificVictoryConidtions * vicConDetails; // used only if vistory conditions aren't standard
  189. int howManyTeams;
  190. std::vector<CMapEvent> events;
  191. };
  192. class CMapHeader
  193. {
  194. public:
  195. Eformat version; // version of map Eformat
  196. bool areAnyPLayers; // if there are any playable players on map
  197. int height, width;
  198. bool twoLevel; // if map has underground level
  199. std::string name; //name of map
  200. std::string description; //and description
  201. int difficulty; // 0 easy - 4 impossible
  202. int levelLimit;
  203. LossCondition lossCondition;
  204. EvictoryConditions victoryCondition; //victory conditions
  205. CspecificVictoryConidtions * vicConDetails; // used only if vistory conditions aren't standard
  206. PlayerInfo players[8]; // info about players
  207. std::vector<int> teams; // teams[i] = team of player no i
  208. int howManyTeams;
  209. CMapHeader(unsigned char *map); //an argument is a reference to string described a map (unpacked)
  210. };
  211. class CMapInfo : public CMapHeader
  212. {
  213. public:
  214. std::string filename;
  215. int playerAmnt, humenPlayers;
  216. CMapInfo(std::string fname, unsigned char *map):CMapHeader(map),filename(fname)
  217. {
  218. playerAmnt=humenPlayers=0;
  219. for (int i=0;i<PLAYER_LIMIT;i++)
  220. {
  221. if (players[i].canHumanPlay) {playerAmnt++;humenPlayers++;}
  222. else if (players[i].canComputerPlay) {playerAmnt++;}
  223. }
  224. };
  225. };
  226. class mapSorter
  227. {
  228. public:
  229. ESortBy sortBy;
  230. bool operator()(CMapHeader & a, CMapHeader& b)
  231. {
  232. switch (sortBy)
  233. {
  234. case ESortBy::format:
  235. return (a.version<b.version);
  236. break;
  237. case ESortBy::loscon:
  238. return (a.lossCondition.typeOfLossCon<b.lossCondition.typeOfLossCon);
  239. break;
  240. case ESortBy::playerAm:
  241. int playerAmntB,humenPlayersB,playerAmntA,humenPlayersA;
  242. playerAmntB=humenPlayersB=playerAmntA=humenPlayersA=0;
  243. for (int i=0;i<8;i++)
  244. {
  245. if (a.players[i].canHumanPlay) {playerAmntA++;humenPlayersA++;}
  246. else if (a.players[i].canComputerPlay) {playerAmntA++;}
  247. if (b.players[i].canHumanPlay) {playerAmntB++;humenPlayersB++;}
  248. else if (b.players[i].canComputerPlay) {playerAmntB++;}
  249. }
  250. if (playerAmntB!=playerAmntA)
  251. return (playerAmntA<playerAmntB);
  252. else
  253. return (humenPlayersA<humenPlayersB);
  254. break;
  255. case ESortBy::size:
  256. return (a.width<b.width);
  257. break;
  258. case ESortBy::viccon:
  259. return (a.victoryCondition<b.victoryCondition);
  260. break;
  261. case ESortBy::name:
  262. return (a.name<b.name);
  263. break;
  264. default:
  265. return (a.name<b.name);
  266. break;
  267. }
  268. };
  269. mapSorter(ESortBy es):sortBy(es){};
  270. };
  271. #endif //MAPD_H