map.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. #ifndef MAPD_H
  2. #define MAPD_H
  3. #pragma warning (disable : 4482)
  4. #include <cstring>
  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. std::vector <CGObjectInstance*> blockingObjects; //pointers to objects that are blocking this tile
  263. template <typename Handler> void serialize(Handler &h, const int version)
  264. {
  265. h & tertype & terview & nuine & rivDir & malle &roadDir & siodmyTajemniczyBajt;
  266. }
  267. };
  268. struct DLL_EXPORT SheroName //name of starting hero
  269. {
  270. int heroID;
  271. std::string heroName;
  272. template <typename Handler> void serialize(Handler &h, const int version)
  273. {
  274. h & heroID & heroName;
  275. }
  276. };
  277. struct DLL_EXPORT PlayerInfo
  278. {
  279. si32 p7, p8, p9;
  280. ui8 canHumanPlay;
  281. ui8 canComputerPlay;
  282. ui32 AITactic; //(00 - random, 01 - warrior, 02 - builder, 03 - explorer)
  283. ui32 allowedFactions; //(01 - castle; 02 - rampart; 04 - tower; 08 - inferno; 16 - necropolis; 32 - dungeon; 64 - stronghold; 128 - fortress; 256 - conflux);
  284. ui8 isFactionRandom;
  285. ui32 mainHeroPortrait; //it's ID of hero with choosen portrait; 255 if standard
  286. std::string mainHeroName;
  287. std::vector<SheroName> heroesNames;
  288. ui8 hasMainTown;
  289. ui8 generateHeroAtMainTown;
  290. int3 posOfMainTown;
  291. ui8 team;
  292. ui8 generateHero;
  293. template <typename Handler> void serialize(Handler &h, const int version)
  294. {
  295. h & p7 & p8 & p9 & canHumanPlay & canComputerPlay & AITactic & allowedFactions & isFactionRandom &
  296. mainHeroPortrait & mainHeroName & heroesNames & hasMainTown & generateHeroAtMainTown &
  297. posOfMainTown & team & generateHero;
  298. }
  299. };
  300. struct DLL_EXPORT LossCondition
  301. {
  302. ElossCon typeOfLossCon;
  303. int3 castlePos;
  304. int3 heroPos;
  305. int timeLimit; // in days
  306. template <typename Handler> void serialize(Handler &h, const int version)
  307. {
  308. h & typeOfLossCon & castlePos & heroPos & timeLimit;
  309. }
  310. };
  311. struct DLL_EXPORT CspecificVictoryConidtions
  312. {
  313. bool allowNormalVictory;
  314. bool appliesToAI;
  315. };
  316. struct DLL_EXPORT VicCon0 : public CspecificVictoryConidtions //acquire artifact
  317. {
  318. int ArtifactID;
  319. };
  320. struct DLL_EXPORT VicCon1 : public CspecificVictoryConidtions //accumulate creatures
  321. {
  322. int monsterID;
  323. int neededQuantity;
  324. };
  325. struct DLL_EXPORT VicCon2 : public CspecificVictoryConidtions // accumulate resources
  326. {
  327. int resourceID;
  328. int neededQuantity;
  329. };
  330. struct DLL_EXPORT VicCon3 : public CspecificVictoryConidtions // upgrade specific town
  331. {
  332. int3 posOfCity;
  333. int councilNeededLevel; //0 - town; 1 - city; 2 - capitol
  334. int fortNeededLevel;// 0 - fort; 1 - citadel; 2 - castle
  335. };
  336. struct DLL_EXPORT VicCon4 : public CspecificVictoryConidtions // build grail structure
  337. {
  338. bool anyLocation;
  339. int3 whereBuildGrail;
  340. };
  341. struct DLL_EXPORT VicCon5 : public CspecificVictoryConidtions // defeat a specific hero
  342. {
  343. int3 locationOfHero;
  344. };
  345. struct DLL_EXPORT VicCon6 : public CspecificVictoryConidtions // capture a specific town
  346. {
  347. int3 locationOfTown;
  348. };
  349. struct DLL_EXPORT VicCon7 : public CspecificVictoryConidtions // defeat a specific monster
  350. {
  351. int3 locationOfMonster;
  352. };
  353. struct DLL_EXPORT VicCona : public CspecificVictoryConidtions //transport specific artifact
  354. {
  355. int artifactID;
  356. int3 destinationPlace;
  357. };
  358. struct DLL_EXPORT Rumor
  359. {
  360. std::string name, text;
  361. template <typename Handler> void serialize(Handler &h, const int version)
  362. {
  363. h & name & text;
  364. }
  365. };
  366. struct DLL_EXPORT DisposedHero
  367. {
  368. ui32 ID;
  369. ui16 portrait; //0xFF - default
  370. std::string name;
  371. ui8 players; //who can hire this hero (bitfield)
  372. template <typename Handler> void serialize(Handler &h, const int version)
  373. {
  374. h & ID & portrait & name & players;
  375. }
  376. };
  377. class DLL_EXPORT CMapEvent
  378. {
  379. public:
  380. std::string name, message;
  381. si32 wood, mercury, ore, sulfur, crystal, gems, gold; //gained / taken resources
  382. ui8 players; //affected players
  383. ui8 humanAffected;
  384. ui8 computerAffected;
  385. ui32 firstOccurence;
  386. ui32 nextOccurence; //after nextOccurance day event will occure; if it it 0, event occures only one time;
  387. template <typename Handler> void serialize(Handler &h, const int version)
  388. {
  389. h & name & message & wood & mercury & ore & sulfur & crystal & gems & gold
  390. & players & humanAffected & computerAffected & firstOccurence & nextOccurence;
  391. }
  392. };
  393. class DLL_EXPORT CMapHeader
  394. {
  395. public:
  396. Eformat version; // version of map Eformat
  397. bool areAnyPLayers; // if there are any playable players on map
  398. int height, width;
  399. bool twoLevel; // if map has underground level
  400. std::string name; //name of map
  401. std::string description; //and description
  402. int difficulty; // 0 easy - 4 impossible
  403. int levelLimit;
  404. LossCondition lossCondition;
  405. EvictoryConditions victoryCondition; //victory conditions
  406. CspecificVictoryConidtions * vicConDetails; // used only if vistory conditions aren't standard
  407. PlayerInfo players[8]; // info about players
  408. std::vector<int> teams; // teams[i] = team of player no i
  409. int howManyTeams;
  410. CMapHeader(unsigned char *map); //an argument is a reference to string described a map (unpacked)
  411. };
  412. class DLL_EXPORT CMapInfo : public CMapHeader
  413. {
  414. public:
  415. std::string filename;
  416. int playerAmnt, humenPlayers;
  417. CMapInfo(std::string fname, unsigned char *map):CMapHeader(map),filename(fname)
  418. {
  419. playerAmnt=humenPlayers=0;
  420. for (int i=0;i<PLAYER_LIMIT;i++)
  421. {
  422. if (players[i].canHumanPlay) {playerAmnt++;humenPlayers++;}
  423. else if (players[i].canComputerPlay) {playerAmnt++;}
  424. }
  425. };
  426. };
  427. class DLL_EXPORT mapSorter
  428. {
  429. public:
  430. ESortBy sortBy;
  431. bool operator()(const CMapHeader & a, const CMapHeader& b)
  432. {
  433. switch (sortBy)
  434. {
  435. case _format:
  436. return (a.version<b.version);
  437. break;
  438. case _loscon:
  439. return (a.lossCondition.typeOfLossCon<b.lossCondition.typeOfLossCon);
  440. break;
  441. case _playerAm:
  442. int playerAmntB,humenPlayersB,playerAmntA,humenPlayersA;
  443. playerAmntB=humenPlayersB=playerAmntA=humenPlayersA=0;
  444. for (int i=0;i<8;i++)
  445. {
  446. if (a.players[i].canHumanPlay) {playerAmntA++;humenPlayersA++;}
  447. else if (a.players[i].canComputerPlay) {playerAmntA++;}
  448. if (b.players[i].canHumanPlay) {playerAmntB++;humenPlayersB++;}
  449. else if (b.players[i].canComputerPlay) {playerAmntB++;}
  450. }
  451. if (playerAmntB!=playerAmntA)
  452. return (playerAmntA<playerAmntB);
  453. else
  454. return (humenPlayersA<humenPlayersB);
  455. break;
  456. case _size:
  457. return (a.width<b.width);
  458. break;
  459. case _viccon:
  460. return (a.victoryCondition<b.victoryCondition);
  461. break;
  462. case _name:
  463. return (a.name<b.name);
  464. break;
  465. default:
  466. return (a.name<b.name);
  467. break;
  468. }
  469. };
  470. mapSorter(ESortBy es):sortBy(es){};
  471. };
  472. struct DLL_EXPORT Mapa
  473. {
  474. Eformat version; // version of map Eformat
  475. ui32 checksum;
  476. int twoLevel; // if map has underground level
  477. int difficulty; // 0 easy - 4 impossible
  478. int levelLimit;
  479. bool areAnyPLayers; // if there are any playable players on map
  480. std::string name; //name of map
  481. std::string description; //and description
  482. int height, width;
  483. TerrainTile*** terrain;
  484. std::vector<Rumor> rumors;
  485. std::vector<DisposedHero> disposedHeroes;
  486. std::vector<CGHeroInstance*> predefinedHeroes;
  487. std::vector<CGDefInfo *> defy; // list of .def files with definitions from .h3m (may be custom)
  488. std::set<CGDefInfo *> defs; // other defInfos - for randomized objects, objects added or modified by scripts
  489. PlayerInfo players[8]; // info about players
  490. std::vector<int> teams; // teams[i] = team of player no i
  491. LossCondition lossCondition;
  492. EvictoryConditions victoryCondition; //victory conditions
  493. CspecificVictoryConidtions * vicConDetails; // used only if vistory conditions aren't standard
  494. int howManyTeams;
  495. std::vector<bool> allowedSpell; //allowedSpell[spell_ID] - if the spell is allowed
  496. std::vector<bool> allowedArtifact; //allowedArtifact[artifact_ID] - if the artifact is allowed
  497. std::vector<bool> allowedAbilities; //allowedAbilities[ability_ID] - if the ability is allowed
  498. std::vector<bool> allowedHeroes; //allowedHeroes[hero_ID] - if the hero is allowed
  499. std::vector<CMapEvent> events;
  500. std::vector<CGObjectInstance*> objects;
  501. std::vector<CGHeroInstance*> heroes;
  502. std::vector<CGTownInstance*> towns;
  503. void initFromBytes(unsigned char * bufor); //creates map from decompressed .h3m data
  504. void readEvents( unsigned char * bufor, int &i);
  505. void readObjects( unsigned char * bufor, int &i);
  506. void readDefInfo( unsigned char * bufor, int &i);
  507. void readTerrain( unsigned char * bufor, int &i);
  508. void readPredefinedHeroes( unsigned char * bufor, int &i);
  509. void readHeader( unsigned char * bufor, int &i);
  510. void readRumors( unsigned char * bufor, int &i);
  511. void loadViCLossConditions( unsigned char * bufor, int &i);
  512. void loadPlayerInfo( int &pom, unsigned char * bufor, int &i);
  513. void loadHero( CGObjectInstance * &nobj, unsigned char * bufor, int &i);
  514. void loadTown( CGObjectInstance * &nobj, unsigned char * bufor, int &i);
  515. int loadSeerHut( unsigned char * bufor, int i, CGObjectInstance * nobj);
  516. void addBlockVisTiles(CGObjectInstance * obj);
  517. void removeBlockVisTiles(CGObjectInstance * obj);
  518. Mapa(std::string filename); //creates map structure from .h3m file
  519. CGHeroInstance * getHero(int ID, int mode=0);
  520. bool isInTheMap(int3 pos);
  521. template <typename Handler> void serialize(Handler &h, const int version)
  522. {
  523. h & version & name & description & width & height & twoLevel & difficulty & levelLimit & rumors & defy & defs
  524. & players & teams & lossCondition & victoryCondition & howManyTeams & allowedSpell & allowedAbilities
  525. & allowedArtifact &allowedHeroes & events;
  526. //TODO: viccondetails
  527. if(h.saving)
  528. {
  529. //saving terrain
  530. for (int i = 0; i < width ; i++)
  531. for (int j = 0; j < height ; j++)
  532. for (int k = 0; k <= twoLevel ; k++)
  533. h & terrain[i][j][k];
  534. }
  535. else
  536. {
  537. //loading terrain
  538. terrain = new TerrainTile**[width]; // allocate memory
  539. for (int ii=0;ii<width;ii++)
  540. {
  541. terrain[ii] = new TerrainTile*[height]; // allocate memory
  542. for(int jj=0;jj<height;jj++)
  543. terrain[ii][jj] = new TerrainTile[twoLevel+1];
  544. }
  545. for (int i = 0; i < width ; i++)
  546. for (int j = 0; j < height ; j++)
  547. for (int k = 0; k <= twoLevel ; k++)
  548. h & terrain[i][j][k];
  549. }
  550. //TODO: recreate blockvis maps
  551. }
  552. };
  553. #endif //MAPD_H