map.h 9.3 KB

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