map.h 7.6 KB

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