map.h 7.6 KB

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