2010-12-17 20:47:07 +02:00
2009-04-15 17:03:31 +03:00
/*
2012-11-03 16:30:47 +03:00
* CMap . h , part of VCMI engine
2009-04-15 17:03:31 +03:00
*
* Authors : listed in file AUTHORS in main folder
*
* License : GNU General Public License v2 .0 or later
* Full text of license available in license . txt file , in main folder
*
*/
2012-11-03 16:30:47 +03:00
# pragma once
# include "../ConstTransitivePtr.h"
2012-11-20 20:53:45 +03:00
# include "../CObjectHandler.h"
2012-11-03 16:30:47 +03:00
# include "../ResourceSet.h"
# include "../int3.h"
# include "../GameConstants.h"
2010-12-17 20:47:07 +02:00
class CArtifactInstance ;
2008-12-27 03:01:59 +02:00
class CGDefInfo ;
class CGObjectInstance ;
class CGHeroInstance ;
2012-04-22 20:38:36 +03:00
class CCommanderInstance ;
2010-02-02 19:05:03 +02:00
class CGCreature ;
2008-12-27 03:01:59 +02:00
class CQuest ;
class CGTownInstance ;
2010-11-10 02:06:25 +02:00
class IModableArt ;
2012-09-16 16:34:01 +03:00
class IQuestObject ;
2012-09-26 16:13:39 +03:00
class CInputStream ;
2012-10-26 20:51:05 +03:00
/**
2012-11-06 19:39:29 +03:00
* The hero name struct consists of the hero id and the hero name .
2012-10-26 20:51:05 +03:00
*/
2012-11-06 19:39:29 +03:00
struct DLL_LINKAGE SHeroName
2012-10-26 20:51:05 +03:00
{
2012-11-11 15:23:31 +03:00
/**
* Default c - tor .
*/
SHeroName ( ) ;
/** the id of the hero */
int heroId ;
/** the name of the hero */
std : : string heroName ;
/**
* Serialize method .
*/
template < typename Handler >
void serialize ( Handler & h , const int version )
{
h & heroId & heroName ;
}
2008-12-27 03:01:59 +02:00
} ;
2011-02-22 13:52:36 +02:00
2012-11-06 19:39:29 +03:00
namespace EAiTactic
{
2012-11-11 15:23:31 +03:00
enum EAiTactic
{
NONE = - 1 ,
RANDOM ,
WARRIOR ,
BUILDER ,
EXPLORER
} ;
2012-11-06 19:39:29 +03:00
}
2012-10-26 20:51:05 +03:00
/**
* The player info constains data about which factions are allowed , AI tactical settings ,
2012-11-06 19:39:29 +03:00
* the main hero name , where to generate the hero , whether the faction should be selected randomly , . . .
2012-10-26 20:51:05 +03:00
*/
2011-12-14 00:23:17 +03:00
struct DLL_LINKAGE PlayerInfo
2008-12-27 03:01:59 +02:00
{
2012-11-11 15:23:31 +03:00
/**
* Default constructor .
*/
PlayerInfo ( ) ;
2012-11-06 19:39:29 +03:00
2012-11-11 15:23:31 +03:00
/**
* Gets the default faction id or - 1 for a random faction .
*
* @ return the default faction id or - 1 for a random faction
*/
si8 defaultCastle ( ) const ;
2012-11-06 19:39:29 +03:00
2012-11-11 15:23:31 +03:00
/**
* Gets - 1 for random hero .
*
* @ return - 1 for random hero
*/
si8 defaultHero ( ) const ;
2012-11-06 19:39:29 +03:00
2012-11-20 20:53:45 +03:00
/** True if the player can be played by a human. */
2012-11-11 15:23:31 +03:00
bool canHumanPlay ;
2012-10-26 20:51:05 +03:00
2012-11-20 20:53:45 +03:00
/** True if th player can be played by the computer */
2012-11-11 15:23:31 +03:00
bool canComputerPlay ;
2012-10-26 20:51:05 +03:00
2012-11-20 20:53:45 +03:00
/** Defines the tactical setting of the AI. The default value is EAiTactic::RANDOM. */
2012-11-11 15:23:31 +03:00
EAiTactic : : EAiTactic aiTactic ;
2012-10-26 20:51:05 +03:00
2012-11-20 20:53:45 +03:00
/** A list of unique IDs of allowed factions. */
2012-12-02 15:21:44 +03:00
std : : set < TFaction > allowedFactions ;
2012-10-26 20:51:05 +03:00
2012-11-20 20:53:45 +03:00
/** Unused. True if the faction should be chosen randomly. */
2012-11-11 15:23:31 +03:00
bool isFactionRandom ;
2012-10-26 20:51:05 +03:00
2012-12-10 17:28:27 +03:00
/** Specifies the ID of the main hero with chosen portrait. The default value is -1. */
si32 mainHeroPortrait ;
2012-10-26 20:51:05 +03:00
2012-11-20 20:53:45 +03:00
/** The name of the main hero. */
2012-11-11 15:23:31 +03:00
std : : string mainHeroName ;
2012-10-26 20:51:05 +03:00
2012-11-20 20:53:45 +03:00
/** The list of renamed heroes. */
2012-11-11 15:23:31 +03:00
std : : vector < SHeroName > heroesNames ;
2012-10-26 20:51:05 +03:00
2013-01-06 22:30:12 +03:00
/** True if the player has a main town. The default value is false. */
2012-11-11 15:23:31 +03:00
bool hasMainTown ;
2012-10-26 20:51:05 +03:00
2013-01-06 22:30:12 +03:00
/** True if the main hero should be generated at the main town. The default value is false. */
2012-11-11 15:23:31 +03:00
bool generateHeroAtMainTown ;
2008-12-27 03:01:59 +02:00
2012-11-20 20:53:45 +03:00
/** The position of the main town. */
2012-11-11 15:23:31 +03:00
int3 posOfMainTown ;
2009-05-29 06:53:53 +03:00
2012-11-20 20:53:45 +03:00
/** The team id to which the player belongs to. The default value is 255 representing that the player belongs to no team. */
2012-11-11 15:23:31 +03:00
ui8 team ;
2012-10-06 11:47:13 +03:00
2012-11-20 20:53:45 +03:00
/** Unused. True if a hero should be generated. */
2012-11-11 15:23:31 +03:00
bool generateHero ;
2012-10-26 20:51:05 +03:00
2012-11-20 20:53:45 +03:00
/** Unknown and unused. */
si32 p7 ;
2012-12-10 17:28:27 +03:00
/** Player has a (custom?) hero */
bool hasHero ;
2012-11-20 20:53:45 +03:00
2012-12-10 17:28:27 +03:00
/** ID of custom hero, -1 if none */
si32 customHeroID ;
2012-11-20 20:53:45 +03:00
/**
* Unused . Count of hero placeholders containing hero type .
* WARNING : powerPlaceholders sometimes gives false 0 ( eg . even if there is one placeholder ) ,
* maybe different meaning ? ? ?
*/
ui8 powerPlaceholders ;
2012-11-11 15:23:31 +03:00
/**
* Serialize method .
*/
template < typename Handler >
void serialize ( Handler & h , const int version )
{
2012-12-10 17:28:27 +03:00
h & p7 & hasHero & customHeroID & canHumanPlay & canComputerPlay & aiTactic & allowedFactions & isFactionRandom &
2012-11-11 15:23:31 +03:00
mainHeroPortrait & mainHeroName & heroesNames & hasMainTown & generateHeroAtMainTown &
posOfMainTown & team & generateHero ;
}
2008-12-27 03:01:59 +02:00
} ;
2011-02-22 13:52:36 +02:00
2012-10-26 20:51:05 +03:00
/**
* The loss condition describes the condition to lose the game . ( e . g . lose all own heroes / castles )
*/
2011-12-14 00:23:17 +03:00
struct DLL_LINKAGE LossCondition
2008-12-27 03:01:59 +02:00
{
2012-11-11 15:23:31 +03:00
/**
* Default constructor .
*/
LossCondition ( ) ;
/** specifies the condition type */
ELossConditionType : : ELossConditionType typeOfLossCon ;
/** the position of an object which mustn't be lost */
int3 pos ;
/** time limit in days, -1 if not used */
si32 timeLimit ;
/** set during map parsing: hero/town (depending on typeOfLossCon); nullptr if not used */
const CGObjectInstance * obj ;
/**
* Serialize method .
*/
template < typename Handler >
void serialize ( Handler & h , const int version )
{
h & typeOfLossCon & pos & timeLimit & obj ;
}
2008-12-27 03:01:59 +02:00
} ;
2011-02-22 13:52:36 +02:00
2012-10-26 20:51:05 +03:00
/**
* The victory condition describes the condition to win the game . ( e . g . defeat all enemy heroes / castles ,
* receive a specific artifact , . . . )
*/
struct DLL_LINKAGE VictoryCondition
2008-12-27 03:01:59 +02:00
{
2012-11-11 15:23:31 +03:00
/**
* Default constructor .
*/
VictoryCondition ( ) ;
2012-11-06 19:39:29 +03:00
2012-11-11 15:23:31 +03:00
/** specifies the condition type */
EVictoryConditionType : : EVictoryConditionType condition ;
2012-10-26 20:51:05 +03:00
2012-11-11 15:23:31 +03:00
/** true if a normal victory is allowed (defeat all enemy towns, heroes) */
bool allowNormalVictory ;
2012-10-26 20:51:05 +03:00
2012-11-11 15:23:31 +03:00
/** true if this victory condition also applies to the AI */
bool appliesToAI ;
2012-10-26 20:51:05 +03:00
2012-11-11 15:23:31 +03:00
/** 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) */
int3 pos ;
2009-01-06 20:42:20 +02:00
2012-11-11 15:23:31 +03:00
/** artifact ID (0); monster ID (1); resource ID (2); needed fort level in upgraded town (3); artifact ID (8) */
si32 objectId ;
2009-01-06 20:42:20 +02:00
2012-11-11 15:23:31 +03:00
/** needed count for creatures (1) / resource (2); upgraded town hall level (3); */
si32 count ;
2010-01-29 22:52:45 +02:00
2012-11-11 15:23:31 +03:00
/** object of specific monster / city / hero instance (NULL if not used); set during map parsing */
const CGObjectInstance * obj ;
2009-01-06 20:42:20 +02:00
2012-11-11 15:23:31 +03:00
/**
* Serialize method .
*/
template < typename Handler >
void serialize ( Handler & h , const int version )
{
h & condition & allowNormalVictory & appliesToAI & pos & objectId & count & obj ;
}
2008-12-27 03:01:59 +02:00
} ;
2009-01-06 20:42:20 +02:00
2012-10-26 20:51:05 +03:00
/**
* The rumor struct consists of a rumor name and text .
*/
2011-12-14 00:23:17 +03:00
struct DLL_LINKAGE Rumor
2008-12-27 03:01:59 +02:00
{
2012-11-11 15:23:31 +03:00
/** the name of the rumor */
std : : string name ;
/** the content of the rumor */
std : : string text ;
/**
* Serialize method .
*/
template < typename Handler >
void serialize ( Handler & h , const int version )
{
h & name & text ;
}
2008-12-27 03:01:59 +02:00
} ;
2012-10-26 20:51:05 +03:00
/**
* The disposed hero struct describes which hero can be hired from which player .
*/
2011-12-14 00:23:17 +03:00
struct DLL_LINKAGE DisposedHero
2008-12-27 03:01:59 +02:00
{
2012-11-11 15:23:31 +03:00
/**
* Default c - tor .
*/
DisposedHero ( ) ;
/** the id of the hero */
ui32 heroId ;
/** the portrait id of the hero, 0xFF is default */
ui16 portrait ;
/** the name of the hero */
std : : string name ;
/** who can hire this hero (bitfield) */
ui8 players ;
/**
* Serialize method .
*/
template < typename Handler >
void serialize ( Handler & h , const int version )
{
h & heroId & portrait & name & players ;
}
2008-12-27 03:01:59 +02:00
} ;
2012-10-26 20:51:05 +03:00
/**
2013-01-06 22:30:12 +03:00
* The map event is an event which e . g . gives or takes resources of a specific
* amount to / from players and can appear regularly or once a time .
2012-10-26 20:51:05 +03:00
*/
2011-12-14 00:23:17 +03:00
class DLL_LINKAGE CMapEvent
2008-12-27 03:01:59 +02:00
{
public :
2012-11-11 15:23:31 +03:00
/**
* Default c - tor .
*/
CMapEvent ( ) ;
/**
* Returns true if this map event occurs earlier than the other map event for the first time .
*
* @ param other the other map event to compare with
* @ return true if this event occurs earlier than the other map event , false if not
*/
bool earlierThan ( const CMapEvent & other ) const ;
/**
* Returns true if this map event occurs earlier than or at the same day than the other map event for the first time .
*
* @ param other the other map event to compare with
* @ return true if this event occurs earlier than or at the same day than the other map event , false if not
*/
bool earlierThanOrEqual ( const CMapEvent & other ) const ;
/** the name of the event */
std : : string name ;
/** the message to display */
std : : string message ;
/** gained or taken resources */
TResources resources ;
/** affected players */
ui8 players ;
/** affected humans */
ui8 humanAffected ;
/** affacted computer players */
ui8 computerAffected ;
/** the day counted continously when the event happens */
ui32 firstOccurence ;
/** specifies after how many days the event will occur the next time; 0 if event occurs only one time */
ui32 nextOccurence ;
/**
* Serialize method .
*/
template < typename Handler >
void serialize ( Handler & h , const int version )
{
h & name & message & resources
& players & humanAffected & computerAffected & firstOccurence & nextOccurence ;
}
2008-12-27 03:01:59 +02:00
} ;
2010-08-18 17:24:30 +03:00
2012-10-26 20:51:05 +03:00
/**
* The castle event builds / adds buildings / creatures for a specific town .
*/
2011-12-14 00:23:17 +03:00
class DLL_LINKAGE CCastleEvent : public CMapEvent
2010-08-18 17:24:30 +03:00
{
public :
2012-11-11 15:23:31 +03:00
/**
* Default c - tor .
*/
CCastleEvent ( ) ;
/** build specific buildings */
2013-02-11 22:11:34 +03:00
std : : set < BuildingID > buildings ;
2012-11-11 15:23:31 +03:00
/** additional creatures in i-th level dwelling */
std : : vector < si32 > creatures ;
/** owner of this event */
CGTownInstance * town ;
/**
* Serialize method .
*/
template < typename Handler >
void serialize ( Handler & h , const int version )
{
h & static_cast < CMapEvent & > ( * this ) ;
h & buildings & creatures ;
}
2010-08-18 17:24:30 +03:00
} ;
2012-11-06 19:39:29 +03:00
namespace ERiverType
{
2012-11-11 15:23:31 +03:00
enum ERiverType
{
NO_RIVER , CLEAR_RIVER , ICY_RIVER , MUDDY_RIVER , LAVA_RIVER
} ;
2012-11-06 19:39:29 +03:00
}
namespace ERoadType
{
2012-11-11 15:23:31 +03:00
enum ERoadType
{
NO_ROAD , DIRT_ROAD , GRAVEL_ROAD , COBBLESTONE_ROAD
} ;
2012-11-06 19:39:29 +03:00
}
/**
* The terrain tile describes the terrain type and the visual representation of the terrain .
* Furthermore the struct defines whether the tile is visitable or / and blocked and which objects reside in it .
*/
struct DLL_LINKAGE TerrainTile
{
2012-11-11 15:23:31 +03:00
/**
* Default c - tor .
*/
TerrainTile ( ) ;
/**
* Gets true if the terrain is not a rock . If from is water / land , same type is also required .
*
* @ param from
* @ return
*/
bool entrableTerrain ( const TerrainTile * from = NULL ) const ;
/**
* Gets true if the terrain is not a rock . If from is water / land , same type is also required .
*
* @ param allowLand
* @ param allowSea
* @ return
*/
bool entrableTerrain ( bool allowLand , bool allowSea ) const ;
/**
* Checks for blocking objects and terraint type ( water / land ) .
*
* @ param from
* @ return
*/
bool isClear ( const TerrainTile * from = NULL ) const ;
/**
* Gets the ID of the top visitable object or - 1 if there is none .
*
* @ return the ID of the top visitable object or - 1 if there is none
*/
int topVisitableId ( ) const ;
/**
* Gets true if the terrain type is water .
*
* @ return true if the terrain type is water
*/
bool isWater ( ) const ;
/**
* Gets true if the terrain tile is coastal .
*
* @ return true if the terrain tile is coastal
*/
bool isCoastal ( ) const ;
/**
* Gets true if the terrain tile has favourable winds .
*
* @ return true if the terrain tile has favourable winds
*/
bool hasFavourableWinds ( ) const ;
/** the type of terrain */
2013-02-13 01:24:48 +03:00
ETerrainType terType ;
2012-11-11 15:23:31 +03:00
/** the visual representation of the terrain */
ui8 terView ;
/** the type of the river. 0 if there is no river */
ERiverType : : ERiverType riverType ;
/** the direction of the river */
ui8 riverDir ;
/** the type of the road. 0 if there is no river */
ERoadType : : ERoadType roadType ;
/** the direction of the road */
ui8 roadDir ;
/**
* first two bits - how to rotate terrain graphic ( next two - river graphic , next two - road ) ;
* 7 th bit - whether tile is coastal ( allows disembarking if land or block movement if water ) ; 8 th bit - Favourable Winds effect
*/
ui8 extTileFlags ;
/** true if it is visitable, false if not */
bool visitable ;
/** true if it is blocked, false if not */
bool blocked ;
/** pointers to objects which the hero can visit while being on this tile */
std : : vector < CGObjectInstance * > visitableObjects ;
/** pointers to objects that are blocking this tile */
std : : vector < CGObjectInstance * > blockingObjects ;
/**
* Serialize method .
*/
template < typename Handler >
void serialize ( Handler & h , const int version )
{
h & terType & terView & riverType & riverDir & roadType & roadDir & extTileFlags & blocked ;
if ( ! h . saving )
{
visitable = false ;
//these flags (and obj vectors) will be restored in map serialization
}
}
2012-11-06 19:39:29 +03:00
} ;
2012-10-26 20:51:05 +03:00
namespace EMapFormat
{
2012-11-11 15:23:31 +03:00
enum EMapFormat
{
INVALID , WOG = 0x33 , AB = 0x15 , ROE = 0x0e , SOD = 0x1c
} ;
2012-10-26 20:51:05 +03:00
}
/**
* The map header holds information about loss / victory condition ,
* map format , version , players , height , width , . . .
*/
2011-12-14 00:23:17 +03:00
class DLL_LINKAGE CMapHeader
2008-12-27 03:01:59 +02:00
{
public :
2012-11-11 15:23:31 +03:00
/**
* Default constructor .
*/
CMapHeader ( ) ;
2012-10-26 20:51:05 +03:00
2012-11-11 15:23:31 +03:00
/**
* D - tor .
*/
virtual ~ CMapHeader ( ) ;
2012-10-26 20:51:05 +03:00
2012-11-20 20:53:45 +03:00
/** The version of the map. The default value is EMapFormat::SOD. */
2012-11-11 15:23:31 +03:00
EMapFormat : : EMapFormat version ;
2012-10-26 20:51:05 +03:00
2012-11-20 20:53:45 +03:00
/** The height of the map. The default value is 72. */
2012-11-11 15:23:31 +03:00
si32 height ;
2012-10-26 20:51:05 +03:00
2012-11-20 20:53:45 +03:00
/** The width of the map. The default value is 72. */
2012-11-11 15:23:31 +03:00
si32 width ;
2012-10-26 20:51:05 +03:00
2012-11-20 20:53:45 +03:00
/** Specifies if the map has two levels. The default value is true. */
bool twoLevel ;
2012-10-26 20:51:05 +03:00
2012-11-20 20:53:45 +03:00
/** The name of the map. */
2012-11-11 15:23:31 +03:00
std : : string name ;
2012-10-26 20:51:05 +03:00
2012-11-20 20:53:45 +03:00
/** The description of the map. */
2012-11-11 15:23:31 +03:00
std : : string description ;
2012-10-26 20:51:05 +03:00
2012-11-20 20:53:45 +03:00
/**
* Specifies the difficulty of the map ranging from 0 easy to 4 impossible .
* The default value is 1 representing a normal map difficulty .
*/
2012-11-11 15:23:31 +03:00
ui8 difficulty ;
2012-10-26 20:51:05 +03:00
2012-11-20 20:53:45 +03:00
/**
* Specifies the maximum level to reach for a hero . A value of 0 states that there is no
* maximum level for heroes .
*/
2012-11-11 15:23:31 +03:00
ui8 levelLimit ;
2012-10-26 20:51:05 +03:00
2012-11-20 20:53:45 +03:00
/** Specifies the loss condition. The default value is lose all your towns and heroes. */
2012-11-11 15:23:31 +03:00
LossCondition lossCondition ;
2012-10-26 20:51:05 +03:00
2012-11-20 20:53:45 +03:00
/** Specifies the victory condition. The default value is defeat all enemies. */
2012-11-11 15:23:31 +03:00
VictoryCondition victoryCondition ;
2012-10-26 20:51:05 +03:00
2013-01-06 22:30:12 +03:00
/** A list containing information about players. The default size of the vector is GameConstants::PLAYER_LIMIT. */
2012-11-11 15:23:31 +03:00
std : : vector < PlayerInfo > players ;
2012-10-26 20:51:05 +03:00
2012-11-20 20:53:45 +03:00
/** The number of teams. */
2012-11-11 15:23:31 +03:00
ui8 howManyTeams ;
2009-01-11 00:08:18 +02:00
2012-11-20 20:53:45 +03:00
/**
2013-02-05 00:58:42 +03:00
* A list of allowed heroes . The index is the hero id and the value = hero allowed .
2012-11-20 20:53:45 +03:00
* The default value is a list of default allowed heroes . See CHeroHandler : : getDefaultAllowedHeroes for more info .
*/
2013-02-05 00:58:42 +03:00
std : : vector < bool > allowedHeroes ;
2009-01-11 00:08:18 +02:00
2012-11-20 20:53:45 +03:00
/** A list of placeholded heroes. The index is the id of a hero type. */
2012-11-11 15:23:31 +03:00
std : : vector < ui16 > placeholdedHeroes ;
2012-10-26 20:51:05 +03:00
2012-11-20 20:53:45 +03:00
/** Unused. True if there are any playable players on the map. */
bool areAnyPlayers ;
2012-11-11 15:23:31 +03:00
/**
* Serialize method .
*/
template < typename Handler >
void serialize ( Handler & h , const int Version )
{
h & version & name & description & width & height & twoLevel & difficulty & levelLimit & areAnyPlayers ;
h & players & lossCondition & victoryCondition & howManyTeams & allowedHeroes ;
}
2008-12-27 03:01:59 +02:00
} ;
2009-01-06 20:42:20 +02:00
2012-10-26 20:51:05 +03:00
/**
* The map contains the map header , the tiles of the terrain , objects ,
* heroes , towns , rumors . . .
*/
class DLL_LINKAGE CMap : public CMapHeader
2008-12-27 03:01:59 +02:00
{
2012-10-26 20:51:05 +03:00
public :
2012-11-11 15:23:31 +03:00
/**
* Default constructor .
*/
CMap ( ) ;
/**
* Destructor .
*/
~ CMap ( ) ;
/**
* Erases an artifact instance .
*
* @ param art the artifact to erase
*/
void eraseArtifactInstance ( CArtifactInstance * art ) ;
/**
* Gets the topmost object or the lowermost object depending on the flag
* lookForHero from the specified position .
*
* @ param pos the position of the tile
* @ param lookForHero true if you want to get the lowermost object , false if
* you want to get the topmost object
* @ return the object at the given position and level
*/
const CGObjectInstance * getObjectiveObjectFrom ( int3 pos , bool lookForHero ) ;
/**
* Sets the victory / loss condition objectives .
*/
void checkForObjectives ( ) ;
/**
* Adds an visitable / blocking object to a terrain tile .
*
* @ param obj the visitable / blocking object to add to a tile
*/
void addBlockVisTiles ( CGObjectInstance * obj ) ;
/**
* Removes an visitable / blocking object from a terrain tile .
*
* @ param obj the visitable / blocking object to remove from a tile
* @ param total
*/
void removeBlockVisTiles ( CGObjectInstance * obj , bool total = false ) ;
/**
* Gets the terrain tile of the specified position .
*
* @ param tile the position of the tile
* @ return the terrain tile of the specified position
*/
TerrainTile & getTile ( const int3 & tile ) ;
/**
* Gets the terrain tile as a const of the specified position .
*
* @ param tile the position of the tile
* @ return the terrain tile as a const of the specified position
*/
const TerrainTile & getTile ( const int3 & tile ) const ;
/**
* Gets the hero with the given id .
* @ param heroId the hero id
* @ return the hero with the given id
*/
CGHeroInstance * getHero ( int heroId ) ;
/**
* Validates if the position is in the bounds of the map .
*
* @ param pos the position to test
* @ return true if the position is in the bounds of the map
*/
bool isInTheMap ( const int3 & pos ) const ;
/**
* Validates if the tile at the given position is a water terrain type .
*
* @ param pos the position to test
* @ return true if the tile at the given position is a water terrain type
*/
bool isWaterTile ( const int3 & pos ) const ;
/**
* Adds the specified artifact instance to the list of artifacts of this map .
*
* @ param art the artifact which should be added to the list of artifacts
*/
void addNewArtifactInstance ( CArtifactInstance * art ) ;
2013-01-06 22:30:12 +03:00
/**
* Adds the specified quest instance to the list of quests .
*
* @ param quest the quest object which should be added to the list of quests
*/
void addQuest ( CGObjectInstance * quest ) ;
/**
* Initializes the terrain of the map by allocating memory .
*/
void initTerrain ( ) ;
2012-11-11 15:23:31 +03:00
/** the checksum of the map */
ui32 checksum ;
2013-01-06 22:30:12 +03:00
/** a 3-dimensional array of terrain tiles, access is as follows: x, y, level. where level=1 is underground */
2012-11-11 15:23:31 +03:00
TerrainTile * * * terrain ;
/** list of rumors */
std : : vector < Rumor > rumors ;
/** list of disposed heroes */
std : : vector < DisposedHero > disposedHeroes ;
/** list of predefined heroes */
std : : vector < ConstTransitivePtr < CGHeroInstance > > predefinedHeroes ;
/** list of .def files with definitions from .h3m (may be custom) */
std : : vector < ConstTransitivePtr < CGDefInfo > > customDefs ;
/** list of allowed spells, index is the spell id */
2013-02-05 00:58:42 +03:00
std : : vector < bool > allowedSpell ;
2012-11-11 15:23:31 +03:00
/** list of allowed artifacts, index is the artifact id */
2013-02-05 00:58:42 +03:00
std : : vector < bool > allowedArtifact ;
2012-11-11 15:23:31 +03:00
/** list of allowed abilities, index is the ability id */
2013-02-05 00:58:42 +03:00
std : : vector < bool > allowedAbilities ;
2012-11-11 15:23:31 +03:00
/** list of map events */
std : : list < ConstTransitivePtr < CMapEvent > > events ;
/** specifies the position of the grail */
int3 grailPos ;
/** specifies the radius of the grail */
int grailRadious ;
/** list of objects */
std : : vector < ConstTransitivePtr < CGObjectInstance > > objects ;
/** list of heroes */
std : : vector < ConstTransitivePtr < CGHeroInstance > > heroes ;
/** list of towns */
std : : vector < ConstTransitivePtr < CGTownInstance > > towns ;
/** list of artifacts */
std : : vector < ConstTransitivePtr < CArtifactInstance > > artInstances ;
/** list of quests */
std : : vector < ConstTransitivePtr < CQuest > > quests ;
/** associative list to identify which hero/creature id belongs to which object id(index for objects) */
bmap < si32 , si32 > questIdentifierToId ;
/**
* Serialize method .
*/
template < typename Handler >
void serialize ( Handler & h , const int formatVersion )
{
h & static_cast < CMapHeader & > ( * this ) ;
h & rumors & allowedSpell & allowedAbilities & allowedArtifact & events & grailPos ;
h & artInstances & quests ;
h & questIdentifierToId ;
//TODO: viccondetails
if ( h . saving )
{
// Save terrain
for ( int i = 0 ; i < width ; + + i )
{
for ( int j = 0 ; j < height ; + + j )
{
2012-11-20 20:53:45 +03:00
for ( int k = 0 ; k < ( twoLevel ? 2 : 1 ) ; + + k )
2012-11-11 15:23:31 +03:00
{
h & terrain [ i ] [ j ] [ k ] ;
}
}
}
}
else
{
// Load terrain
terrain = new TerrainTile * * [ width ] ;
for ( int ii = 0 ; ii < width ; + + ii )
{
terrain [ ii ] = new TerrainTile * [ height ] ;
for ( int jj = 0 ; jj < height ; + + jj )
{
2012-11-20 20:53:45 +03:00
terrain [ ii ] [ jj ] = new TerrainTile [ twoLevel ? 2 : 1 ] ;
2012-11-11 15:23:31 +03:00
}
}
for ( int i = 0 ; i < width ; + + i )
{
for ( int j = 0 ; j < height ; + + j )
{
2012-11-20 20:53:45 +03:00
for ( int k = 0 ; k < ( twoLevel ? 2 : 1 ) ; + + k )
2012-11-11 15:23:31 +03:00
{
h & terrain [ i ] [ j ] [ k ] ;
}
}
}
}
h & customDefs & objects ;
// static members
h & CGTeleport : : objs ;
h & CGTeleport : : gates ;
h & CGKeys : : playerKeyMap ;
h & CGMagi : : eyelist ;
h & CGObelisk : : obeliskCount & CGObelisk : : visited ;
h & CGTownInstance : : merchantArtifacts ;
2012-12-13 16:07:56 +03:00
h & CGTownInstance : : universitySkills ;
2012-11-11 15:23:31 +03:00
if ( ! h . saving )
{
for ( ui32 i = 0 ; i < objects . size ( ) ; + + i )
{
if ( ! objects [ i ] ) continue ;
switch ( objects [ i ] - > ID )
{
case Obj : : HERO :
heroes . push_back ( static_cast < CGHeroInstance * > ( + objects [ i ] ) ) ;
break ;
case Obj : : TOWN :
towns . push_back ( static_cast < CGTownInstance * > ( + objects [ i ] ) ) ;
break ;
}
// recreate blockvis map
addBlockVisTiles ( objects [ i ] ) ;
}
// if hero is visiting/garrisoned in town set appropriate pointers
for ( ui32 i = 0 ; i < heroes . size ( ) ; + + i )
{
int3 vistile = heroes [ i ] - > pos ;
vistile . x + + ;
for ( ui32 j = 0 ; j < towns . size ( ) ; + + j )
{
// hero stands on the town entrance
if ( vistile = = towns [ j ] - > pos )
{
if ( heroes [ i ] - > inTownGarrison )
{
towns [ j ] - > garrisonHero = heroes [ i ] ;
removeBlockVisTiles ( heroes [ i ] ) ;
}
else
{
towns [ j ] - > visitingHero = heroes [ i ] ;
}
heroes [ i ] - > visitedTown = towns [ j ] ;
break ;
}
}
vistile . x - = 2 ; //manifest pos
const TerrainTile & t = getTile ( vistile ) ;
if ( t . terType ! = ETerrainType : : WATER ) continue ;
//hero stands on the water - he must be in the boat
for ( ui32 j = 0 ; j < t . visitableObjects . size ( ) ; + + j )
{
if ( t . visitableObjects [ j ] - > ID = = Obj : : BOAT )
{
CGBoat * b = static_cast < CGBoat * > ( t . visitableObjects [ j ] ) ;
heroes [ i ] - > boat = b ;
b - > hero = heroes [ i ] ;
removeBlockVisTiles ( b ) ;
break ;
}
}
}
}
}
2008-12-27 03:01:59 +02:00
} ;