map.h 9.1 KB

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