CMap.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897
  1. /*
  2. * CMap.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "../ConstTransitivePtr.h"
  12. #include "../CObjectHandler.h"
  13. #include "../ResourceSet.h"
  14. #include "../int3.h"
  15. #include "../GameConstants.h"
  16. class CArtifactInstance;
  17. class CGDefInfo;
  18. class CGObjectInstance;
  19. class CGHeroInstance;
  20. class CCommanderInstance;
  21. class CGCreature;
  22. class CQuest;
  23. class CGTownInstance;
  24. class IModableArt;
  25. class IQuestObject;
  26. class CInputStream;
  27. /**
  28. * The hero name struct consists of the hero id and the hero name.
  29. */
  30. struct DLL_LINKAGE SHeroName
  31. {
  32. /**
  33. * Default c-tor.
  34. */
  35. SHeroName();
  36. /** the id of the hero */
  37. int heroId;
  38. /** the name of the hero */
  39. std::string heroName;
  40. /**
  41. * Serialize method.
  42. */
  43. template <typename Handler>
  44. void serialize(Handler & h, const int version)
  45. {
  46. h & heroId & heroName;
  47. }
  48. };
  49. namespace EAiTactic
  50. {
  51. enum EAiTactic
  52. {
  53. NONE = -1,
  54. RANDOM,
  55. WARRIOR,
  56. BUILDER,
  57. EXPLORER
  58. };
  59. }
  60. /**
  61. * The player info constains data about which factions are allowed, AI tactical settings,
  62. * the main hero name, where to generate the hero, whether the faction should be selected randomly,...
  63. */
  64. struct DLL_LINKAGE PlayerInfo
  65. {
  66. /**
  67. * Default constructor.
  68. */
  69. PlayerInfo();
  70. /**
  71. * Gets the default faction id or -1 for a random faction.
  72. *
  73. * @return the default faction id or -1 for a random faction
  74. */
  75. si8 defaultCastle() const;
  76. /**
  77. * Gets -1 for random hero.
  78. *
  79. * @return -1 for random hero
  80. */
  81. si8 defaultHero() const;
  82. /** True if the player can be played by a human. */
  83. bool canHumanPlay;
  84. /** True if th player can be played by the computer */
  85. bool canComputerPlay;
  86. /** Defines the tactical setting of the AI. The default value is EAiTactic::RANDOM. */
  87. EAiTactic::EAiTactic aiTactic;
  88. /** A list of unique IDs of allowed factions. */
  89. std::set<TFaction> allowedFactions;
  90. /** Unused. True if the faction should be chosen randomly. */
  91. bool isFactionRandom;
  92. /** Specifies the ID of the main hero with chosen portrait. The default value is -1. */
  93. si32 mainHeroPortrait;
  94. /** The name of the main hero. */
  95. std::string mainHeroName;
  96. /** The list of renamed heroes. */
  97. std::vector<SHeroName> heroesNames;
  98. /** True if the player has a main town. The default value is false. */
  99. bool hasMainTown;
  100. /** True if the main hero should be generated at the main town. The default value is false. */
  101. bool generateHeroAtMainTown;
  102. /** The position of the main town. */
  103. int3 posOfMainTown;
  104. /** The team id to which the player belongs to. The default value is 255 representing that the player belongs to no team. */
  105. TeamID team;
  106. /** Unused. True if a hero should be generated. */
  107. bool generateHero;
  108. /** Unknown and unused. */
  109. si32 p7;
  110. /** Player has a (custom?) hero */
  111. bool hasHero;
  112. /** ID of custom hero, -1 if none */
  113. si32 customHeroID;
  114. /**
  115. * Unused. Count of hero placeholders containing hero type.
  116. * WARNING: powerPlaceholders sometimes gives false 0 (eg. even if there is one placeholder),
  117. * maybe different meaning ???
  118. */
  119. ui8 powerPlaceholders;
  120. /**
  121. * Serialize method.
  122. */
  123. template <typename Handler>
  124. void serialize(Handler & h, const int version)
  125. {
  126. h & p7 & hasHero & customHeroID & canHumanPlay & canComputerPlay & aiTactic & allowedFactions & isFactionRandom &
  127. mainHeroPortrait & mainHeroName & heroesNames & hasMainTown & generateHeroAtMainTown &
  128. posOfMainTown & team & generateHero;
  129. }
  130. };
  131. /**
  132. * The loss condition describes the condition to lose the game. (e.g. lose all own heroes/castles)
  133. */
  134. struct DLL_LINKAGE LossCondition
  135. {
  136. /**
  137. * Default constructor.
  138. */
  139. LossCondition();
  140. /** specifies the condition type */
  141. ELossConditionType::ELossConditionType typeOfLossCon;
  142. /** the position of an object which mustn't be lost */
  143. int3 pos;
  144. /** time limit in days, -1 if not used */
  145. si32 timeLimit;
  146. /** set during map parsing: hero/town (depending on typeOfLossCon); nullptr if not used */
  147. const CGObjectInstance * obj;
  148. /**
  149. * Serialize method.
  150. */
  151. template <typename Handler>
  152. void serialize(Handler & h, const int version)
  153. {
  154. h & typeOfLossCon & pos & timeLimit & obj;
  155. }
  156. };
  157. /**
  158. * The victory condition describes the condition to win the game. (e.g. defeat all enemy heroes/castles,
  159. * receive a specific artifact, ...)
  160. */
  161. struct DLL_LINKAGE VictoryCondition
  162. {
  163. /**
  164. * Default constructor.
  165. */
  166. VictoryCondition();
  167. /** specifies the condition type */
  168. EVictoryConditionType::EVictoryConditionType condition;
  169. /** true if a normal victory is allowed (defeat all enemy towns, heroes) */
  170. bool allowNormalVictory;
  171. /** true if this victory condition also applies to the AI */
  172. bool appliesToAI;
  173. /** pos of city to upgrade (3); pos of town to build grail, {-1,-1,-1} if not relevant (4); hero pos (5); town pos(6); monster pos (7); destination pos(8) */
  174. int3 pos;
  175. /** artifact ID (0); monster ID (1); resource ID (2); needed fort level in upgraded town (3); artifact ID (8) */
  176. si32 objectId;
  177. /** needed count for creatures (1) / resource (2); upgraded town hall level (3); */
  178. si32 count;
  179. /** object of specific monster / city / hero instance (NULL if not used); set during map parsing */
  180. const CGObjectInstance * obj;
  181. /**
  182. * Serialize method.
  183. */
  184. template <typename Handler>
  185. void serialize(Handler & h, const int version)
  186. {
  187. h & condition & allowNormalVictory & appliesToAI & pos & objectId & count & obj;
  188. }
  189. };
  190. /**
  191. * The rumor struct consists of a rumor name and text.
  192. */
  193. struct DLL_LINKAGE Rumor
  194. {
  195. /** the name of the rumor */
  196. std::string name;
  197. /** the content of the rumor */
  198. std::string text;
  199. /**
  200. * Serialize method.
  201. */
  202. template <typename Handler>
  203. void serialize(Handler & h, const int version)
  204. {
  205. h & name & text;
  206. }
  207. };
  208. /**
  209. * The disposed hero struct describes which hero can be hired from which player.
  210. */
  211. struct DLL_LINKAGE DisposedHero
  212. {
  213. /**
  214. * Default c-tor.
  215. */
  216. DisposedHero();
  217. /** the id of the hero */
  218. ui32 heroId;
  219. /** the portrait id of the hero, 0xFF is default */
  220. ui16 portrait;
  221. /** the name of the hero */
  222. std::string name;
  223. /** who can hire this hero (bitfield) */
  224. ui8 players;
  225. /**
  226. * Serialize method.
  227. */
  228. template <typename Handler>
  229. void serialize(Handler & h, const int version)
  230. {
  231. h & heroId & portrait & name & players;
  232. }
  233. };
  234. /**
  235. * The map event is an event which e.g. gives or takes resources of a specific
  236. * amount to/from players and can appear regularly or once a time.
  237. */
  238. class DLL_LINKAGE CMapEvent
  239. {
  240. public:
  241. /**
  242. * Default c-tor.
  243. */
  244. CMapEvent();
  245. /**
  246. * Returns true if this map event occurs earlier than the other map event for the first time.
  247. *
  248. * @param other the other map event to compare with
  249. * @return true if this event occurs earlier than the other map event, false if not
  250. */
  251. bool earlierThan(const CMapEvent & other) const;
  252. /**
  253. * Returns true if this map event occurs earlier than or at the same day than the other map event for the first time.
  254. *
  255. * @param other the other map event to compare with
  256. * @return true if this event occurs earlier than or at the same day than the other map event, false if not
  257. */
  258. bool earlierThanOrEqual(const CMapEvent & other) const;
  259. /** the name of the event */
  260. std::string name;
  261. /** the message to display */
  262. std::string message;
  263. /** gained or taken resources */
  264. TResources resources;
  265. /** affected players */
  266. ui8 players;
  267. /** affected humans */
  268. ui8 humanAffected;
  269. /** affacted computer players */
  270. ui8 computerAffected;
  271. /** the day counted continously when the event happens */
  272. ui32 firstOccurence;
  273. /** specifies after how many days the event will occur the next time; 0 if event occurs only one time */
  274. ui32 nextOccurence;
  275. /**
  276. * Serialize method.
  277. */
  278. template <typename Handler>
  279. void serialize(Handler & h, const int version)
  280. {
  281. h & name & message & resources
  282. & players & humanAffected & computerAffected & firstOccurence & nextOccurence;
  283. }
  284. };
  285. /**
  286. * The castle event builds/adds buildings/creatures for a specific town.
  287. */
  288. class DLL_LINKAGE CCastleEvent: public CMapEvent
  289. {
  290. public:
  291. /**
  292. * Default c-tor.
  293. */
  294. CCastleEvent();
  295. /** build specific buildings */
  296. std::set<BuildingID> buildings;
  297. /** additional creatures in i-th level dwelling */
  298. std::vector<si32> creatures;
  299. /** owner of this event */
  300. CGTownInstance * town;
  301. /**
  302. * Serialize method.
  303. */
  304. template <typename Handler>
  305. void serialize(Handler & h, const int version)
  306. {
  307. h & static_cast<CMapEvent &>(*this);
  308. h & buildings & creatures;
  309. }
  310. };
  311. namespace ERiverType
  312. {
  313. enum ERiverType
  314. {
  315. NO_RIVER, CLEAR_RIVER, ICY_RIVER, MUDDY_RIVER, LAVA_RIVER
  316. };
  317. }
  318. namespace ERoadType
  319. {
  320. enum ERoadType
  321. {
  322. NO_ROAD, DIRT_ROAD, GRAVEL_ROAD, COBBLESTONE_ROAD
  323. };
  324. }
  325. /**
  326. * The terrain tile describes the terrain type and the visual representation of the terrain.
  327. * Furthermore the struct defines whether the tile is visitable or/and blocked and which objects reside in it.
  328. */
  329. struct DLL_LINKAGE TerrainTile
  330. {
  331. /**
  332. * Default c-tor.
  333. */
  334. TerrainTile();
  335. /**
  336. * Gets true if the terrain is not a rock. If from is water/land, same type is also required.
  337. *
  338. * @param from
  339. * @return
  340. */
  341. bool entrableTerrain(const TerrainTile * from = NULL) const;
  342. /**
  343. * Gets true if the terrain is not a rock. If from is water/land, same type is also required.
  344. *
  345. * @param allowLand
  346. * @param allowSea
  347. * @return
  348. */
  349. bool entrableTerrain(bool allowLand, bool allowSea) const;
  350. /**
  351. * Checks for blocking objects and terraint type (water / land).
  352. *
  353. * @param from
  354. * @return
  355. */
  356. bool isClear(const TerrainTile * from = NULL) const;
  357. /**
  358. * Gets the ID of the top visitable object or -1 if there is none.
  359. *
  360. * @return the ID of the top visitable object or -1 if there is none
  361. */
  362. int topVisitableId() const;
  363. /**
  364. * Gets true if the terrain type is water.
  365. *
  366. * @return true if the terrain type is water
  367. */
  368. bool isWater() const;
  369. /**
  370. * Gets true if the terrain tile is coastal.
  371. *
  372. * @return true if the terrain tile is coastal
  373. */
  374. bool isCoastal() const;
  375. /**
  376. * Gets true if the terrain tile has favourable winds.
  377. *
  378. * @return true if the terrain tile has favourable winds
  379. */
  380. bool hasFavourableWinds() const;
  381. /** the type of terrain */
  382. ETerrainType terType;
  383. /** the visual representation of the terrain */
  384. ui8 terView;
  385. /** the type of the river. 0 if there is no river */
  386. ERiverType::ERiverType riverType;
  387. /** the direction of the river */
  388. ui8 riverDir;
  389. /** the type of the road. 0 if there is no river */
  390. ERoadType::ERoadType roadType;
  391. /** the direction of the road */
  392. ui8 roadDir;
  393. /**
  394. * first two bits - how to rotate terrain graphic (next two - river graphic, next two - road);
  395. * 7th bit - whether tile is coastal (allows disembarking if land or block movement if water); 8th bit - Favourable Winds effect
  396. */
  397. ui8 extTileFlags;
  398. /** true if it is visitable, false if not */
  399. bool visitable;
  400. /** true if it is blocked, false if not */
  401. bool blocked;
  402. /** pointers to objects which the hero can visit while being on this tile */
  403. std::vector<CGObjectInstance *> visitableObjects;
  404. /** pointers to objects that are blocking this tile */
  405. std::vector<CGObjectInstance *> blockingObjects;
  406. /**
  407. * Serialize method.
  408. */
  409. template <typename Handler>
  410. void serialize(Handler & h, const int version)
  411. {
  412. h & terType & terView & riverType & riverDir & roadType &roadDir & extTileFlags & blocked;
  413. if(!h.saving)
  414. {
  415. visitable = false;
  416. //these flags (and obj vectors) will be restored in map serialization
  417. }
  418. }
  419. };
  420. namespace EMapFormat
  421. {
  422. enum EMapFormat
  423. {
  424. INVALID, WOG=0x33, AB=0x15, ROE=0x0e, SOD=0x1c
  425. };
  426. }
  427. /**
  428. * The map header holds information about loss/victory condition,
  429. * map format, version, players, height, width,...
  430. */
  431. class DLL_LINKAGE CMapHeader
  432. {
  433. public:
  434. /**
  435. * Default constructor.
  436. */
  437. CMapHeader();
  438. /**
  439. * D-tor.
  440. */
  441. virtual ~CMapHeader();
  442. /** The version of the map. The default value is EMapFormat::SOD. */
  443. EMapFormat::EMapFormat version;
  444. /** The height of the map. The default value is 72. */
  445. si32 height;
  446. /** The width of the map. The default value is 72. */
  447. si32 width;
  448. /** Specifies if the map has two levels. The default value is true. */
  449. bool twoLevel;
  450. /** The name of the map. */
  451. std::string name;
  452. /** The description of the map. */
  453. std::string description;
  454. /**
  455. * Specifies the difficulty of the map ranging from 0 easy to 4 impossible.
  456. * The default value is 1 representing a normal map difficulty.
  457. */
  458. ui8 difficulty;
  459. /**
  460. * Specifies the maximum level to reach for a hero. A value of 0 states that there is no
  461. * maximum level for heroes.
  462. */
  463. ui8 levelLimit;
  464. /** Specifies the loss condition. The default value is lose all your towns and heroes. */
  465. LossCondition lossCondition;
  466. /** Specifies the victory condition. The default value is defeat all enemies. */
  467. VictoryCondition victoryCondition;
  468. /** A list containing information about players. The default size of the vector is PlayerColor::PLAYER_LIMIT. */
  469. std::vector<PlayerInfo> players;
  470. /** The number of teams. */
  471. ui8 howManyTeams;
  472. /**
  473. * A list of allowed heroes. The index is the hero id and the value = hero allowed.
  474. * The default value is a list of default allowed heroes. See CHeroHandler::getDefaultAllowedHeroes for more info.
  475. */
  476. std::vector<bool> allowedHeroes;
  477. /** A list of placeholded heroes. The index is the id of a hero type. */
  478. std::vector<ui16> placeholdedHeroes;
  479. /** Unused. True if there are any playable players on the map. */
  480. bool areAnyPlayers;
  481. /**
  482. * Serialize method.
  483. */
  484. template <typename Handler>
  485. void serialize(Handler & h, const int Version)
  486. {
  487. h & version & name & description & width & height & twoLevel & difficulty & levelLimit & areAnyPlayers;
  488. h & players & lossCondition & victoryCondition & howManyTeams & allowedHeroes;
  489. }
  490. };
  491. /**
  492. * The map contains the map header, the tiles of the terrain, objects,
  493. * heroes, towns, rumors...
  494. */
  495. class DLL_LINKAGE CMap : public CMapHeader
  496. {
  497. public:
  498. /**
  499. * Default constructor.
  500. */
  501. CMap();
  502. /**
  503. * Destructor.
  504. */
  505. ~CMap();
  506. /**
  507. * Erases an artifact instance.
  508. *
  509. * @param art the artifact to erase
  510. */
  511. void eraseArtifactInstance(CArtifactInstance * art);
  512. /**
  513. * Gets the topmost object or the lowermost object depending on the flag
  514. * lookForHero from the specified position.
  515. *
  516. * @param pos the position of the tile
  517. * @param lookForHero true if you want to get the lowermost object, false if
  518. * you want to get the topmost object
  519. * @return the object at the given position and level
  520. */
  521. const CGObjectInstance * getObjectiveObjectFrom(int3 pos, bool lookForHero);
  522. /**
  523. * Sets the victory/loss condition objectives.
  524. */
  525. void checkForObjectives();
  526. /**
  527. * Adds an visitable/blocking object to a terrain tile.
  528. *
  529. * @param obj the visitable/blocking object to add to a tile
  530. */
  531. void addBlockVisTiles(CGObjectInstance * obj);
  532. /**
  533. * Removes an visitable/blocking object from a terrain tile.
  534. *
  535. * @param obj the visitable/blocking object to remove from a tile
  536. * @param total
  537. */
  538. void removeBlockVisTiles(CGObjectInstance * obj, bool total = false);
  539. /**
  540. * Gets the terrain tile of the specified position.
  541. *
  542. * @param tile the position of the tile
  543. * @return the terrain tile of the specified position
  544. */
  545. TerrainTile & getTile(const int3 & tile);
  546. /**
  547. * Gets the terrain tile as a const of the specified position.
  548. *
  549. * @param tile the position of the tile
  550. * @return the terrain tile as a const of the specified position
  551. */
  552. const TerrainTile & getTile(const int3 & tile) const;
  553. /**
  554. * Gets the hero with the given id.
  555. * @param heroId the hero id
  556. * @return the hero with the given id
  557. */
  558. CGHeroInstance * getHero(int heroId);
  559. /**
  560. * Validates if the position is in the bounds of the map.
  561. *
  562. * @param pos the position to test
  563. * @return true if the position is in the bounds of the map
  564. */
  565. bool isInTheMap(const int3 & pos) const;
  566. /**
  567. * Validates if the tile at the given position is a water terrain type.
  568. *
  569. * @param pos the position to test
  570. * @return true if the tile at the given position is a water terrain type
  571. */
  572. bool isWaterTile(const int3 & pos) const;
  573. /**
  574. * Adds the specified artifact instance to the list of artifacts of this map.
  575. *
  576. * @param art the artifact which should be added to the list of artifacts
  577. */
  578. void addNewArtifactInstance(CArtifactInstance * art);
  579. /**
  580. * Adds the specified quest instance to the list of quests.
  581. *
  582. * @param quest the quest object which should be added to the list of quests
  583. */
  584. void addQuest(CGObjectInstance * quest);
  585. /**
  586. * Initializes the terrain of the map by allocating memory.
  587. */
  588. void initTerrain();
  589. /** the checksum of the map */
  590. ui32 checksum;
  591. /** a 3-dimensional array of terrain tiles, access is as follows: x, y, level. where level=1 is underground */
  592. TerrainTile*** terrain;
  593. /** list of rumors */
  594. std::vector<Rumor> rumors;
  595. /** list of disposed heroes */
  596. std::vector<DisposedHero> disposedHeroes;
  597. /** list of predefined heroes */
  598. std::vector<ConstTransitivePtr<CGHeroInstance> > predefinedHeroes;
  599. /** list of .def files with definitions from .h3m (may be custom) */
  600. std::vector<ConstTransitivePtr<CGDefInfo> > customDefs;
  601. /** list of allowed spells, index is the spell id */
  602. std::vector<bool> allowedSpell;
  603. /** list of allowed artifacts, index is the artifact id */
  604. std::vector<bool> allowedArtifact;
  605. /** list of allowed abilities, index is the ability id */
  606. std::vector<bool> allowedAbilities;
  607. /** list of map events */
  608. std::list<CMapEvent> events;
  609. /** specifies the position of the grail */
  610. int3 grailPos;
  611. /** specifies the radius of the grail */
  612. int grailRadious;
  613. /** list of objects */
  614. std::vector< ConstTransitivePtr<CGObjectInstance> > objects;
  615. /** list of heroes */
  616. std::vector< ConstTransitivePtr<CGHeroInstance> > heroes;
  617. /** list of towns */
  618. std::vector< ConstTransitivePtr<CGTownInstance> > towns;
  619. /** list of artifacts */
  620. std::vector< ConstTransitivePtr<CArtifactInstance> > artInstances;
  621. /** list of quests */
  622. std::vector< ConstTransitivePtr<CQuest> > quests;
  623. /** associative list to identify which hero/creature id belongs to which object id(index for objects) */
  624. bmap<si32, ObjectInstanceID> questIdentifierToId;
  625. /**
  626. * Serialize method.
  627. */
  628. template <typename Handler>
  629. void serialize(Handler &h, const int formatVersion)
  630. {
  631. h & static_cast<CMapHeader&>(*this);
  632. h & rumors & allowedSpell & allowedAbilities & allowedArtifact & events & grailPos;
  633. h & artInstances & quests;
  634. h & questIdentifierToId;
  635. //TODO: viccondetails
  636. if(h.saving)
  637. {
  638. // Save terrain
  639. for(int i = 0; i < width ; ++i)
  640. {
  641. for(int j = 0; j < height ; ++j)
  642. {
  643. for(int k = 0; k < (twoLevel ? 2 : 1); ++k)
  644. {
  645. h & terrain[i][j][k];
  646. }
  647. }
  648. }
  649. }
  650. else
  651. {
  652. // Load terrain
  653. terrain = new TerrainTile**[width];
  654. for(int ii = 0; ii < width; ++ii)
  655. {
  656. terrain[ii] = new TerrainTile*[height];
  657. for(int jj = 0; jj < height; ++jj)
  658. {
  659. terrain[ii][jj] = new TerrainTile[twoLevel ? 2 : 1];
  660. }
  661. }
  662. for(int i = 0; i < width ; ++i)
  663. {
  664. for(int j = 0; j < height ; ++j)
  665. {
  666. for(int k = 0; k < (twoLevel ? 2 : 1); ++k)
  667. {
  668. h & terrain[i][j][k];
  669. }
  670. }
  671. }
  672. }
  673. h & customDefs & objects;
  674. // static members
  675. h & CGTeleport::objs;
  676. h & CGTeleport::gates;
  677. h & CGKeys::playerKeyMap;
  678. h & CGMagi::eyelist;
  679. h & CGObelisk::obeliskCount & CGObelisk::visited;
  680. h & CGTownInstance::merchantArtifacts;
  681. h & CGTownInstance::universitySkills;
  682. if(!h.saving)
  683. {
  684. for(ui32 i = 0; i < objects.size(); ++i)
  685. {
  686. if(!objects[i]) continue;
  687. switch (objects[i]->ID)
  688. {
  689. case Obj::HERO:
  690. heroes.push_back (static_cast<CGHeroInstance*>(+objects[i]));
  691. break;
  692. case Obj::TOWN:
  693. towns.push_back (static_cast<CGTownInstance*>(+objects[i]));
  694. break;
  695. }
  696. // recreate blockvis map
  697. addBlockVisTiles(objects[i]);
  698. }
  699. // if hero is visiting/garrisoned in town set appropriate pointers
  700. for(ui32 i = 0; i < heroes.size(); ++i)
  701. {
  702. int3 vistile = heroes[i]->pos;
  703. vistile.x++;
  704. for(ui32 j = 0; j < towns.size(); ++j)
  705. {
  706. // hero stands on the town entrance
  707. if(vistile == towns[j]->pos)
  708. {
  709. if(heroes[i]->inTownGarrison)
  710. {
  711. towns[j]->garrisonHero = heroes[i];
  712. removeBlockVisTiles(heroes[i]);
  713. }
  714. else
  715. {
  716. towns[j]->visitingHero = heroes[i];
  717. }
  718. heroes[i]->visitedTown = towns[j];
  719. break;
  720. }
  721. }
  722. vistile.x -= 2; //manifest pos
  723. const TerrainTile & t = getTile(vistile);
  724. if(t.terType != ETerrainType::WATER) continue;
  725. //hero stands on the water - he must be in the boat
  726. for(ui32 j = 0; j < t.visitableObjects.size(); ++j)
  727. {
  728. if(t.visitableObjects[j]->ID == Obj::BOAT)
  729. {
  730. CGBoat * b = static_cast<CGBoat *>(t.visitableObjects[j]);
  731. heroes[i]->boat = b;
  732. b->hero = heroes[i];
  733. removeBlockVisTiles(b);
  734. break;
  735. }
  736. }
  737. }
  738. }
  739. }
  740. };