CMap.h 22 KB

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