map.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. #ifndef MAPD_H
  2. #define MAPD_H
  3. #pragma warning (disable : 4482)
  4. #include <string>
  5. #include <vector>
  6. #include <map>
  7. #include "global.h"
  8. class CGDefInfo;
  9. class CHeroObjInfo;
  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. };
  27. struct TerrainTile
  28. {
  29. EterrainType tertype; // type of terrain
  30. unsigned char terview; // look of terrain
  31. Eriver nuine; // type of Eriver (0 if there is no Eriver)
  32. unsigned char rivDir; // direction of Eriver
  33. Eroad malle; // type of Eroad (0 if there is no Eriver)
  34. unsigned char roadDir; // direction of Eroad
  35. unsigned char siodmyTajemniczyBajt; // mysterius byte // jak bedzie waidomo co to, to sie nazwie inaczej
  36. };
  37. struct SheroName //name of starting hero
  38. {
  39. int heroID;
  40. std::string heroName;
  41. };
  42. struct PlayerInfo
  43. {
  44. int p7, p8, p9;
  45. bool canHumanPlay;
  46. bool canComputerPlay;
  47. unsigned int AITactic; //(00 - random, 01 - warrior, 02 - builder, 03 - explorer)
  48. unsigned int allowedFactions; //(01 - castle; 02 - rampart; 04 - tower; 08 - inferno; 16 - necropolis; 32 - dungeon; 64 - stronghold; 128 - fortress; 256 - conflux);
  49. bool isFactionRandom;
  50. unsigned int mainHeroPortrait; //it's ID of hero with choosen portrait; 255 if standard
  51. std::string mainHeroName;
  52. std::vector<SheroName> heroesNames;
  53. bool hasMainTown;
  54. bool generateHeroAtMainTown;
  55. int3 posOfMainTown;
  56. int team;
  57. bool generateHero;
  58. };
  59. struct LossCondition
  60. {
  61. ElossCon typeOfLossCon;
  62. int3 castlePos;
  63. int3 heroPos;
  64. int timeLimit; // in days
  65. };
  66. struct CspecificVictoryConidtions
  67. {
  68. bool allowNormalVictory;
  69. bool appliesToAI;
  70. };
  71. struct VicCon0 : public CspecificVictoryConidtions //acquire artifact
  72. {
  73. int ArtifactID;
  74. };
  75. struct VicCon1 : public CspecificVictoryConidtions //accumulate creatures
  76. {
  77. int monsterID;
  78. int neededQuantity;
  79. };
  80. struct VicCon2 : public CspecificVictoryConidtions // accumulate resources
  81. {
  82. int resourceID;
  83. int neededQuantity;
  84. };
  85. struct VicCon3 : public CspecificVictoryConidtions // upgrade specific town
  86. {
  87. int3 posOfCity;
  88. int councilNeededLevel; //0 - town; 1 - city; 2 - capitol
  89. int fortNeededLevel;// 0 - fort; 1 - citadel; 2 - castle
  90. };
  91. struct VicCon4 : public CspecificVictoryConidtions // build grail structure
  92. {
  93. bool anyLocation;
  94. int3 whereBuildGrail;
  95. };
  96. struct VicCon5 : public CspecificVictoryConidtions // defeat a specific hero
  97. {
  98. int3 locationOfHero;
  99. };
  100. struct VicCon6 : public CspecificVictoryConidtions // capture a specific town
  101. {
  102. int3 locationOfTown;
  103. };
  104. struct VicCon7 : public CspecificVictoryConidtions // defeat a specific monster
  105. {
  106. int3 locationOfMonster;
  107. };
  108. /*struct VicCon8 : public CspecificVictoryConidtions // flag all creature dwellings
  109. {
  110. };
  111. struct VicCon9 : public CspecificVictoryConidtions // flag all mines
  112. {
  113. };*/
  114. struct VicCona : public CspecificVictoryConidtions //transport specific artifact
  115. {
  116. int artifactID;
  117. int3 destinationPlace;
  118. };
  119. struct Rumor
  120. {
  121. std::string name, text;
  122. };
  123. struct DisposedHero
  124. {
  125. int ID;
  126. int portrait; //0xFF - default
  127. std::string name;
  128. bool players[8]; //who can hire this hero
  129. };
  130. class CMapEvent
  131. {
  132. public:
  133. std::string name, message;
  134. int wood, mercury, ore, sulfur, crystal, gems, gold; //gained / taken resources
  135. unsigned char players; //affected players
  136. bool humanAffected;
  137. bool computerAffected;
  138. int firstOccurence;
  139. int nextOccurence; //after nextOccurance day event will occure; if it it 0, event occures only one time;
  140. };
  141. struct Mapa
  142. {
  143. Eformat version; // version of map Eformat
  144. int twoLevel; // if map has underground level
  145. int difficulty; // 0 easy - 4 impossible
  146. int levelLimit;
  147. bool areAnyPLayers; // if there are any playable players on map
  148. std::string name; //name of map
  149. std::string description; //and description
  150. int height, width;
  151. TerrainTile** terrain;
  152. TerrainTile** undergroungTerrain; // used only if there is underground level
  153. std::vector<Rumor> rumors;
  154. std::vector<DisposedHero> disposedHeroes;
  155. std::vector<CHeroObjInfo*> predefinedHeroes;
  156. std::vector<CGDefInfo *> defy; // list of .def files
  157. PlayerInfo players[8]; // info about players
  158. std::vector<int> teams; // teams[i] = team of player no i
  159. LossCondition lossCondition;
  160. EvictoryConditions victoryCondition; //victory conditions
  161. CspecificVictoryConidtions * vicConDetails; // used only if vistory conditions aren't standard
  162. int howManyTeams;
  163. std::vector<CMapEvent> events;
  164. };
  165. class CMapHeader
  166. {
  167. public:
  168. Eformat version; // version of map Eformat
  169. bool areAnyPLayers; // if there are any playable players on map
  170. int height, width;
  171. bool twoLevel; // if map has underground level
  172. std::string name; //name of map
  173. std::string description; //and description
  174. int difficulty; // 0 easy - 4 impossible
  175. int levelLimit;
  176. LossCondition lossCondition;
  177. EvictoryConditions victoryCondition; //victory conditions
  178. CspecificVictoryConidtions * vicConDetails; // used only if vistory conditions aren't standard
  179. PlayerInfo players[8]; // info about players
  180. std::vector<int> teams; // teams[i] = team of player no i
  181. int howManyTeams;
  182. CMapHeader(unsigned char *map); //an argument is a reference to string described a map (unpacked)
  183. };
  184. class CMapInfo : public CMapHeader
  185. {
  186. public:
  187. std::string filename;
  188. int playerAmnt, humenPlayers;
  189. CMapInfo(std::string fname, unsigned char *map):CMapHeader(map),filename(fname)
  190. {
  191. playerAmnt=humenPlayers=0;
  192. for (int i=0;i<PLAYER_LIMIT;i++)
  193. {
  194. if (players[i].canHumanPlay) {playerAmnt++;humenPlayers++;}
  195. else if (players[i].canComputerPlay) {playerAmnt++;}
  196. }
  197. };
  198. };
  199. class mapSorter
  200. {
  201. public:
  202. ESortBy sortBy;
  203. bool operator()(CMapHeader & a, CMapHeader& b)
  204. {
  205. switch (sortBy)
  206. {
  207. case ESortBy::format:
  208. return (a.version<b.version);
  209. break;
  210. case ESortBy::loscon:
  211. return (a.lossCondition.typeOfLossCon<b.lossCondition.typeOfLossCon);
  212. break;
  213. case ESortBy::playerAm:
  214. int playerAmntB,humenPlayersB,playerAmntA,humenPlayersA;
  215. playerAmntB=humenPlayersB=playerAmntA=humenPlayersA=0;
  216. for (int i=0;i<8;i++)
  217. {
  218. if (a.players[i].canHumanPlay) {playerAmntA++;humenPlayersA++;}
  219. else if (a.players[i].canComputerPlay) {playerAmntA++;}
  220. if (b.players[i].canHumanPlay) {playerAmntB++;humenPlayersB++;}
  221. else if (b.players[i].canComputerPlay) {playerAmntB++;}
  222. }
  223. if (playerAmntB!=playerAmntA)
  224. return (playerAmntA<playerAmntB);
  225. else
  226. return (humenPlayersA<humenPlayersB);
  227. break;
  228. case ESortBy::size:
  229. return (a.width<b.width);
  230. break;
  231. case ESortBy::viccon:
  232. return (a.victoryCondition<b.victoryCondition);
  233. break;
  234. case ESortBy::name:
  235. return (a.name<b.name);
  236. break;
  237. default:
  238. return (a.name<b.name);
  239. break;
  240. }
  241. };
  242. mapSorter(ESortBy es):sortBy(es){};
  243. };
  244. #endif //MAPD_H