map.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. #ifndef MAPD_H
  2. #define MAPD_H
  3. #pragma warning (disable : 4482)
  4. #include <string>
  5. #include <vector>
  6. #include <map>
  7. #include <set>
  8. #include "global.h"
  9. class CGDefInfo;
  10. class CGObjectInstance;
  11. class CGHeroInstance;
  12. class CGTownInstance;
  13. enum ESortBy{name,playerAm,size,format, viccon,loscon};
  14. enum EDefType {TOWN_DEF, HERO_DEF, CREATURES_DEF, SEERHUT_DEF, RESOURCE_DEF, TERRAINOBJ_DEF,
  15. EVENTOBJ_DEF, SIGN_DEF, GARRISON_DEF, ARTIFACT_DEF, WITCHHUT_DEF, SCHOLAR_DEF, PLAYERONLY_DEF,
  16. SHRINE_DEF, SPELLSCROLL_DEF, PANDORA_DEF, GRAIL_DEF, CREGEN_DEF, CREGEN2_DEF, CREGEN3_DEF,
  17. BORDERGUARD_DEF, HEROPLACEHOLDER_DEF};
  18. class DLL_EXPORT CSpecObjInfo //class with object - specific info (eg. different information for creatures and heroes); use inheritance to make object - specific classes
  19. {
  20. };
  21. class DLL_EXPORT CEventObjInfo : public CSpecObjInfo
  22. {
  23. public:
  24. bool areGuarders; //true if there are
  25. CCreatureSet guarders;
  26. bool isMessage; //true if there is a message
  27. std::string message;
  28. unsigned int gainedExp;
  29. int manaDiff; //amount of gained / lost mana
  30. int moraleDiff; //morale modifier
  31. int luckDiff; //luck modifier
  32. int wood, mercury, ore, sulfur, crystal, gems, gold; //gained / lost resources
  33. unsigned int attack; //added attack points
  34. unsigned int defence; //added defence points
  35. unsigned int power; //added power points
  36. unsigned int knowledge; //added knowledge points
  37. std::vector<int> abilities; //gained abilities
  38. std::vector<int> abilityLevels; //levels of gained abilities
  39. std::vector<int> artifacts; //gained artifacts
  40. std::vector<int> spells; //gained spells
  41. CCreatureSet creatures; //gained creatures
  42. unsigned char availableFor; //players whom this event is available for
  43. bool computerActivate; //true if computre player can activate this event
  44. bool humanActivate; //true if human player can activate this event
  45. };
  46. class DLL_EXPORT CCreatureObjInfo : public CSpecObjInfo
  47. {
  48. public:
  49. unsigned char bytes[4]; //mysterious bytes identifying creature
  50. unsigned int number; //number of units (0 - random)
  51. unsigned char character; //chracter of this set of creatures (0 - the most friendly, 4 - the most hostile)
  52. std::string message; //message printed for attacking hero
  53. int wood, mercury, ore, sulfur, crytal, gems, gold; //resources gained to hero that has won with monsters
  54. int gainedArtifact; //ID of artifact gained to hero
  55. bool neverFlees; //if true, the troops will never flee
  56. bool notGrowingTeam; //if true, number of units won't grow
  57. };
  58. class DLL_EXPORT CSignObjInfo : public CSpecObjInfo
  59. {
  60. public:
  61. std::string message; //message
  62. };
  63. class DLL_EXPORT CSeerHutObjInfo : public CSpecObjInfo
  64. {
  65. public:
  66. unsigned char missionType; //type of mission: 0 - no mission; 1 - reach level; 2 - reach main statistics values; 3 - win with a certain hero; 4 - win with a certain creature; 5 - collect some atifacts; 6 - have certain troops in army; 7 - collect resources; 8 - be a certain hero; 9 - be a certain player
  67. bool isDayLimit; //if true, there is a day limit
  68. int lastDay; //after this day (first day is 0) mission cannot be completed
  69. int m1level; //for mission 1
  70. int m2attack, m2defence, m2power, m2knowledge;//for mission 2
  71. unsigned char m3bytes[4];//for mission 3
  72. unsigned char m4bytes[4];//for mission 4
  73. std::vector<int> m5arts;//for mission 5 - artifact ID
  74. std::vector<CCreature *> m6cre;//for mission 6
  75. std::vector<int> m6number;
  76. int m7wood, m7mercury, m7ore, m7sulfur, m7crystal, m7gems, m7gold; //for mission 7
  77. int m8hero;//for mission 8 - hero ID
  78. int m9player; //for mission 9 - number; from 0 to 7
  79. std::string firstVisitText, nextVisitText, completedText;
  80. char rewardType; //type of reward: 0 - no reward; 1 - experience; 2 - mana points; 3 - morale bonus; 4 - luck bonus; 5 - resources; 6 - main ability bonus (attak, defence etd.); 7 - secondary ability gain; 8 - artifact; 9 - spell; 10 - creature
  81. //for reward 1
  82. int r1exp;
  83. //for reward 2
  84. int r2mana;
  85. //for reward 3
  86. int r3morale;
  87. //for reward 4
  88. int r4luck;
  89. //for reward 5
  90. unsigned char r5type; //0 - wood, 1 - mercury, 2 - ore, 3 - sulfur, 4 - crystal, 5 - gems, 6 - gold
  91. int r5amount;
  92. //for reward 6
  93. unsigned char r6type; //0 - attack, 1 - defence, 2 - power, 3 - knowledge
  94. int r6amount;
  95. //for reward 7
  96. int r7ability; //ability id
  97. unsigned char r7level; //1 - basic, 2 - advanced, 3 - expert
  98. //for reward 8
  99. int r8art;//artifact id
  100. //for reward 9
  101. int r9spell;//spell id
  102. //for reward 10
  103. int r10creature; //creature id
  104. int r10amount;
  105. };
  106. class DLL_EXPORT CWitchHutObjInfo : public CSpecObjInfo
  107. {
  108. public:
  109. std::vector<int> allowedAbilities;
  110. };
  111. class DLL_EXPORT CScholarObjInfo : public CSpecObjInfo
  112. {
  113. public:
  114. unsigned char bonusType; //255 - random, 0 - primary skill, 1 - secondary skill, 2 - spell
  115. unsigned char r0type;
  116. int r1; //Ability ID
  117. int r2; //Spell ID
  118. };
  119. class DLL_EXPORT CGarrisonObjInfo : public CSpecObjInfo
  120. {
  121. public:
  122. unsigned char player; //255 - nobody; 0 - 7 - players
  123. CCreatureSet units;
  124. bool movableUnits; //if true, units can be moved
  125. };
  126. class DLL_EXPORT CArtifactObjInfo : public CSpecObjInfo
  127. {
  128. public:
  129. bool areGuards;
  130. std::string message;
  131. CCreatureSet guards;
  132. };
  133. class DLL_EXPORT CResourceObjInfo : public CSpecObjInfo
  134. {
  135. public:
  136. bool randomAmount;
  137. int amount; //if not random
  138. bool areGuards;
  139. CCreatureSet guards;
  140. std::string message;
  141. };
  142. class DLL_EXPORT CPlayerOnlyObjInfo : public CSpecObjInfo
  143. {
  144. public:
  145. unsigned char player; //FF - nobody, 0 - 7
  146. };
  147. class DLL_EXPORT CShrineObjInfo : public CSpecObjInfo
  148. {
  149. public:
  150. unsigned char spell; //number of spell or 255
  151. };
  152. class DLL_EXPORT CSpellScrollObjinfo : public CSpecObjInfo
  153. {
  154. public:
  155. std::string message;
  156. int spell;
  157. bool areGuarders;
  158. CCreatureSet guarders;
  159. };
  160. class DLL_EXPORT CPandorasBoxObjInfo : public CSpecObjInfo
  161. {
  162. public:
  163. std::string message;
  164. bool areGuarders;
  165. CCreatureSet guarders;
  166. //gained things:
  167. unsigned int gainedExp;
  168. int manaDiff;
  169. int moraleDiff;
  170. int luckDiff;
  171. int wood, mercury, ore, sulfur, crystal, gems, gold;
  172. int attack, defence, power, knowledge;
  173. std::vector<int> abilities;
  174. std::vector<int> abilityLevels;
  175. std::vector<int> artifacts;
  176. std::vector<int> spells;
  177. CCreatureSet creatures;
  178. };
  179. class DLL_EXPORT CGrailObjInfo : public CSpecObjInfo
  180. {
  181. public:
  182. int radius; //place grail at the distance lesser or equal radius from this place
  183. };
  184. class DLL_EXPORT CCreGenObjInfo : public CSpecObjInfo
  185. {
  186. public:
  187. unsigned char player; //owner
  188. bool asCastle;
  189. int identifier;
  190. unsigned char castles[2]; //allowed castles
  191. };
  192. class DLL_EXPORT CCreGen2ObjInfo : public CSpecObjInfo
  193. {
  194. public:
  195. unsigned char player; //owner
  196. bool asCastle;
  197. int identifier;
  198. unsigned char castles[2]; //allowed castles
  199. unsigned char minLevel, maxLevel; //minimal and maximal level of creature in dwelling: <0, 6>
  200. };
  201. class DLL_EXPORT CCreGen3ObjInfo : public CSpecObjInfo
  202. {
  203. public:
  204. unsigned char player; //owner
  205. unsigned char minLevel, maxLevel; //minimal and maximal level of creature in dwelling: <0, 6>
  206. };
  207. class DLL_EXPORT CBorderGuardObjInfo : public CSpecObjInfo //copied form seer huts, seems to be similar
  208. {
  209. public:
  210. char missionType; //type of mission: 0 - no mission; 1 - reach level; 2 - reach main statistics values; 3 - win with a certain hero; 4 - win with a certain creature; 5 - collect some atifacts; 6 - have certain troops in army; 7 - collect resources; 8 - be a certain hero; 9 - be a certain player
  211. bool isDayLimit; //if true, there is a day limit
  212. int lastDay; //after this day (first day is 0) mission cannot be completed
  213. //for mission 1
  214. int m1level;
  215. //for mission 2
  216. int m2attack, m2defence, m2power, m2knowledge;
  217. //for mission 3
  218. unsigned char m3bytes[4];
  219. //for mission 4
  220. unsigned char m4bytes[4];
  221. //for mission 5
  222. std::vector<int> m5arts; //artifacts id
  223. //for mission 6
  224. std::vector<CCreature *> m6cre;
  225. std::vector<int> m6number;
  226. //for mission 7
  227. int m7wood, m7mercury, m7ore, m7sulfur, m7crystal, m7gems, m7gold;
  228. //for mission 8
  229. int m8hero; //hero id
  230. //for mission 9
  231. int m9player; //number; from 0 to 7
  232. std::string firstVisitText, nextVisitText, completedText;
  233. };
  234. struct DLL_EXPORT Sresource
  235. {
  236. std::string resName; //name of this resource
  237. int amount; //it can be greater and lesser than 0
  238. };
  239. struct DLL_EXPORT TimeEvent
  240. {
  241. std::string eventName;
  242. std::string message;
  243. std::vector<Sresource> decIncRes; //decreases / increases of resources
  244. unsigned int whichPlayers; //which players are affected by this event (+1 - first, +2 - second, +4 - third, +8 - fourth etc.)
  245. bool areHumansAffected;
  246. bool areCompsAffected;
  247. int firstAfterNDays; //how many days after appears this event
  248. int nextAfterNDays; //how many days after the epperance before appaers this event
  249. };
  250. struct DLL_EXPORT TerrainTile
  251. {
  252. EterrainType tertype; // type of terrain
  253. unsigned char terview; // look of terrain
  254. Eriver nuine; // type of Eriver (0 if there is no Eriver)
  255. unsigned char rivDir; // direction of Eriver
  256. Eroad malle; // type of Eroad (0 if there is no Eriver)
  257. unsigned char roadDir; // direction of Eroad
  258. unsigned char siodmyTajemniczyBajt; //bitfield, info whether this tile is coastal and how to rotate tile graphics
  259. bool visitable; //false = not visitable; true = visitable
  260. bool blocked; //false = free; true = blocked;
  261. std::vector <CGObjectInstance*> visitableObjects; //pointers to objects hero can visit while being on this tile
  262. };
  263. struct DLL_EXPORT SheroName //name of starting hero
  264. {
  265. int heroID;
  266. std::string heroName;
  267. };
  268. struct DLL_EXPORT PlayerInfo
  269. {
  270. int p7, p8, p9;
  271. bool canHumanPlay;
  272. bool canComputerPlay;
  273. unsigned int AITactic; //(00 - random, 01 - warrior, 02 - builder, 03 - explorer)
  274. unsigned int allowedFactions; //(01 - castle; 02 - rampart; 04 - tower; 08 - inferno; 16 - necropolis; 32 - dungeon; 64 - stronghold; 128 - fortress; 256 - conflux);
  275. bool isFactionRandom;
  276. unsigned int mainHeroPortrait; //it's ID of hero with choosen portrait; 255 if standard
  277. std::string mainHeroName;
  278. std::vector<SheroName> heroesNames;
  279. bool hasMainTown;
  280. bool generateHeroAtMainTown;
  281. int3 posOfMainTown;
  282. int team;
  283. bool generateHero;
  284. };
  285. struct DLL_EXPORT LossCondition
  286. {
  287. ElossCon typeOfLossCon;
  288. int3 castlePos;
  289. int3 heroPos;
  290. int timeLimit; // in days
  291. };
  292. struct DLL_EXPORT CspecificVictoryConidtions
  293. {
  294. bool allowNormalVictory;
  295. bool appliesToAI;
  296. };
  297. struct DLL_EXPORT VicCon0 : public CspecificVictoryConidtions //acquire artifact
  298. {
  299. int ArtifactID;
  300. };
  301. struct DLL_EXPORT VicCon1 : public CspecificVictoryConidtions //accumulate creatures
  302. {
  303. int monsterID;
  304. int neededQuantity;
  305. };
  306. struct DLL_EXPORT VicCon2 : public CspecificVictoryConidtions // accumulate resources
  307. {
  308. int resourceID;
  309. int neededQuantity;
  310. };
  311. struct DLL_EXPORT VicCon3 : public CspecificVictoryConidtions // upgrade specific town
  312. {
  313. int3 posOfCity;
  314. int councilNeededLevel; //0 - town; 1 - city; 2 - capitol
  315. int fortNeededLevel;// 0 - fort; 1 - citadel; 2 - castle
  316. };
  317. struct DLL_EXPORT VicCon4 : public CspecificVictoryConidtions // build grail structure
  318. {
  319. bool anyLocation;
  320. int3 whereBuildGrail;
  321. };
  322. struct DLL_EXPORT VicCon5 : public CspecificVictoryConidtions // defeat a specific hero
  323. {
  324. int3 locationOfHero;
  325. };
  326. struct DLL_EXPORT VicCon6 : public CspecificVictoryConidtions // capture a specific town
  327. {
  328. int3 locationOfTown;
  329. };
  330. struct DLL_EXPORT VicCon7 : public CspecificVictoryConidtions // defeat a specific monster
  331. {
  332. int3 locationOfMonster;
  333. };
  334. struct DLL_EXPORT VicCona : public CspecificVictoryConidtions //transport specific artifact
  335. {
  336. int artifactID;
  337. int3 destinationPlace;
  338. };
  339. struct DLL_EXPORT Rumor
  340. {
  341. std::string name, text;
  342. };
  343. struct DLL_EXPORT DisposedHero
  344. {
  345. int ID;
  346. int portrait; //0xFF - default
  347. std::string name;
  348. bool players[8]; //who can hire this hero
  349. };
  350. class DLL_EXPORT CMapEvent
  351. {
  352. public:
  353. std::string name, message;
  354. int wood, mercury, ore, sulfur, crystal, gems, gold; //gained / taken resources
  355. unsigned char players; //affected players
  356. bool humanAffected;
  357. bool computerAffected;
  358. int firstOccurence;
  359. int nextOccurence; //after nextOccurance day event will occure; if it it 0, event occures only one time;
  360. };
  361. class DLL_EXPORT CMapHeader
  362. {
  363. public:
  364. Eformat version; // version of map Eformat
  365. bool areAnyPLayers; // if there are any playable players on map
  366. int height, width;
  367. bool twoLevel; // if map has underground level
  368. std::string name; //name of map
  369. std::string description; //and description
  370. int difficulty; // 0 easy - 4 impossible
  371. int levelLimit;
  372. LossCondition lossCondition;
  373. EvictoryConditions victoryCondition; //victory conditions
  374. CspecificVictoryConidtions * vicConDetails; // used only if vistory conditions aren't standard
  375. PlayerInfo players[8]; // info about players
  376. std::vector<int> teams; // teams[i] = team of player no i
  377. int howManyTeams;
  378. CMapHeader(unsigned char *map); //an argument is a reference to string described a map (unpacked)
  379. };
  380. class DLL_EXPORT CMapInfo : public CMapHeader
  381. {
  382. public:
  383. std::string filename;
  384. int playerAmnt, humenPlayers;
  385. CMapInfo(std::string fname, unsigned char *map):CMapHeader(map),filename(fname)
  386. {
  387. playerAmnt=humenPlayers=0;
  388. for (int i=0;i<PLAYER_LIMIT;i++)
  389. {
  390. if (players[i].canHumanPlay) {playerAmnt++;humenPlayers++;}
  391. else if (players[i].canComputerPlay) {playerAmnt++;}
  392. }
  393. };
  394. };
  395. class DLL_EXPORT mapSorter
  396. {
  397. public:
  398. ESortBy sortBy;
  399. bool operator()(CMapHeader & a, CMapHeader& b)
  400. {
  401. switch (sortBy)
  402. {
  403. case ESortBy::format:
  404. return (a.version<b.version);
  405. break;
  406. case ESortBy::loscon:
  407. return (a.lossCondition.typeOfLossCon<b.lossCondition.typeOfLossCon);
  408. break;
  409. case ESortBy::playerAm:
  410. int playerAmntB,humenPlayersB,playerAmntA,humenPlayersA;
  411. playerAmntB=humenPlayersB=playerAmntA=humenPlayersA=0;
  412. for (int i=0;i<8;i++)
  413. {
  414. if (a.players[i].canHumanPlay) {playerAmntA++;humenPlayersA++;}
  415. else if (a.players[i].canComputerPlay) {playerAmntA++;}
  416. if (b.players[i].canHumanPlay) {playerAmntB++;humenPlayersB++;}
  417. else if (b.players[i].canComputerPlay) {playerAmntB++;}
  418. }
  419. if (playerAmntB!=playerAmntA)
  420. return (playerAmntA<playerAmntB);
  421. else
  422. return (humenPlayersA<humenPlayersB);
  423. break;
  424. case ESortBy::size:
  425. return (a.width<b.width);
  426. break;
  427. case ESortBy::viccon:
  428. return (a.victoryCondition<b.victoryCondition);
  429. break;
  430. case ESortBy::name:
  431. return (a.name<b.name);
  432. break;
  433. default:
  434. return (a.name<b.name);
  435. break;
  436. }
  437. };
  438. mapSorter(ESortBy es):sortBy(es){};
  439. };
  440. struct DLL_EXPORT Mapa
  441. {
  442. Eformat version; // version of map Eformat
  443. ui32 checksum;
  444. int twoLevel; // if map has underground level
  445. int difficulty; // 0 easy - 4 impossible
  446. int levelLimit;
  447. bool areAnyPLayers; // if there are any playable players on map
  448. std::string name; //name of map
  449. std::string description; //and description
  450. int height, width;
  451. TerrainTile** terrain;
  452. TerrainTile** undergroungTerrain; // used only if there is underground level
  453. std::vector<Rumor> rumors;
  454. std::vector<DisposedHero> disposedHeroes;
  455. std::vector<CGHeroInstance*> predefinedHeroes;
  456. std::vector<CGDefInfo *> defy; // list of .def files with definitions from .h3m (may be custom)
  457. std::set<CGDefInfo *> defs; // other defInfos - for randomized objects, objects added or modified by scripts
  458. PlayerInfo players[8]; // info about players
  459. std::vector<int> teams; // teams[i] = team of player no i
  460. LossCondition lossCondition;
  461. EvictoryConditions victoryCondition; //victory conditions
  462. CspecificVictoryConidtions * vicConDetails; // used only if vistory conditions aren't standard
  463. int howManyTeams;
  464. std::vector<bool> allowedSpell; //allowedSpell[spell_ID] - if the spell is allowed
  465. std::vector<bool> allowedArtifact; //allowedArtifact[artifact_ID] - if the artifact is allowed
  466. std::vector<bool> allowedAbilities; //allowedAbilities[ability_ID] - if the ability is allowed
  467. std::vector<bool> allowedHeroes; //allowedHeroes[hero_ID] - if the hero is allowed
  468. std::vector<CMapEvent> events;
  469. std::vector<CGObjectInstance*> objects;
  470. std::vector<CGHeroInstance*> heroes;
  471. std::vector<CGTownInstance*> towns;
  472. void initFromBytes(unsigned char * bufor); //creates map from decompressed .h3m data
  473. Mapa(std::string filename); //creates map structure from .h3m file
  474. CGHeroInstance * getHero(int ID, int mode=0);
  475. };
  476. #endif //MAPD_H