map.h 9.1 KB

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