2008-12-27 03:01:59 +02:00
# ifndef __CGAMESTATE_H__
# define __CGAMESTATE_H__
2009-05-20 13:08:56 +03:00
# include "../global.h"
2009-12-01 23:05:57 +02:00
# include <cassert>
2008-12-27 03:01:59 +02:00
# ifndef _MSC_VER
2009-05-20 13:08:56 +03:00
# include "../hch/CCreatureHandler.h"
# include "VCMI_Lib.h"
2009-01-30 20:36:00 +02:00
# include "map.h"
2008-12-27 03:01:59 +02:00
# endif
# include <set>
# include <vector>
2010-02-01 19:51:33 +02:00
# include <list>
2009-05-20 13:08:56 +03:00
# include "StackFeature.h"
2010-02-10 04:56:00 +02:00
# include "HeroBonus.h"
2008-12-27 03:01:59 +02:00
# ifdef _WIN32
# include <tchar.h>
# else
2009-05-21 03:55:30 +03:00
# include "../tchar_amigaos4.h"
2008-12-27 03:01:59 +02:00
# endif
2009-04-15 17:03:31 +03:00
/*
* CGameState . h , part of VCMI engine
*
* 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
*
*/
2008-12-27 03:01:59 +02:00
class CTown ;
class CScriptCallback ;
class CCallback ;
class CLuaCallback ;
class CCPPObjectScript ;
class CCreatureSet ;
class CStack ;
class CGHeroInstance ;
class CGTownInstance ;
class CArmedInstance ;
2009-10-24 22:21:32 +03:00
class CGDwelling ;
2008-12-27 03:01:59 +02:00
class CGDefInfo ;
class CObjectScript ;
class CGObjectInstance ;
class CCreature ;
struct Mapa ;
struct StartInfo ;
struct SDL_Surface ;
class CMapHandler ;
class CPathfinder ;
struct SetObjectProperty ;
struct MetaString ;
2009-03-07 00:25:19 +02:00
struct CPack ;
2009-05-07 18:19:52 +03:00
class CSpell ;
2009-08-30 15:47:40 +03:00
struct TerrainTile ;
2010-02-07 17:06:14 +02:00
class CHeroClass ;
2008-12-27 03:01:59 +02:00
namespace boost
{
class shared_mutex ;
}
2010-02-07 17:06:14 +02:00
struct DLL_EXPORT InfoAboutHero
{
2010-02-07 19:56:06 +02:00
private :
void assign ( const InfoAboutHero & iah ) ;
public :
2010-02-07 17:06:14 +02:00
struct DLL_EXPORT Details
{
std : : vector < int > primskills ;
int mana , luck , morale ;
} * details ;
char owner ;
const CHeroClass * hclass ;
std : : string name ;
int portrait ;
CCreatureSet army ; //numbers of creatures are exact numbers if detailed else they are quantity ids (0 - a few, 1 - several and so on)
InfoAboutHero ( ) ;
2010-02-07 19:56:06 +02:00
InfoAboutHero ( const InfoAboutHero & iah ) ;
InfoAboutHero & operator = ( const InfoAboutHero & iah ) ;
2010-02-07 17:06:14 +02:00
~ InfoAboutHero ( ) ;
void initFromHero ( const CGHeroInstance * h , bool detailed ) ;
} ;
2010-02-01 19:51:33 +02:00
struct DLL_EXPORT SThievesGuildInfo
{
std : : vector < ui8 > playerColors ; //colors of players that are in-game
std : : vector < std : : list < ui8 > > numOfTowns , numOfHeroes , gold , woodOre , mercSulfCrystGems , obelisks , artifacts , army , income ; // [place] -> [colours of players]
2010-02-04 20:40:40 +02:00
std : : map < ui8 , InfoAboutHero > colorToBestHero ; //maps player's color to his best heros'
2010-02-01 19:51:33 +02:00
2010-02-06 15:49:14 +02:00
std : : map < ui8 , si8 > personality ; // color to personality // -1 - human, AI -> (00 - random, 01 - warrior, 02 - builder, 03 - explorer)
std : : map < ui8 , si32 > bestCreature ; // color to ID // id or -1 if not known
2010-02-07 17:06:14 +02:00
// template <typename Handler> void serialize(Handler &h, const int version)
// {
// h & playerColors & numOfTowns & numOfHeroes & gold & woodOre & mercSulfCrystGems & obelisks & artifacts & army & income;
// h & colorToBestHero & personality & bestCreature;
// }
2010-02-01 19:51:33 +02:00
} ;
2008-12-27 03:01:59 +02:00
struct DLL_EXPORT PlayerState
{
public :
2010-01-29 22:52:45 +02:00
enum EStatus { INGAME , LOSER , WINNER } ;
2008-12-27 03:01:59 +02:00
ui8 color , serial ;
2009-03-09 21:40:43 +02:00
ui8 human ; //true if human controlled player, false for AI
2008-12-27 03:01:59 +02:00
ui32 currentSelection ; //id of hero/town, 0xffffffff if none
std : : vector < std : : vector < std : : vector < ui8 > > > fogOfWarMap ; //true - visible, false - hidden
std : : vector < si32 > resources ;
std : : vector < CGHeroInstance * > heroes ;
std : : vector < CGTownInstance * > towns ;
std : : vector < CGHeroInstance * > availableHeroes ; //heroes available in taverns
2009-10-24 22:21:32 +03:00
std : : vector < CGDwelling * > dwellings ; //used for town growth
2010-02-10 04:56:00 +02:00
BonusList bonuses ; //player bonuses
2009-09-07 05:29:44 +03:00
2010-01-29 22:52:45 +02:00
ui8 status ; //0 - in game, 1 - loser, 2 - winner <- uses EStatus enum
ui8 daysWithoutCastle ;
2009-09-07 05:29:44 +03:00
PlayerState ( ) ;
2008-12-27 03:01:59 +02:00
template < typename Handler > void serialize ( Handler & h , const int version )
{
2010-01-29 22:52:45 +02:00
h & color & serial & human & currentSelection & fogOfWarMap & resources & status ;
2010-02-10 04:56:00 +02:00
h & heroes & towns & availableHeroes & dwellings & bonuses & status & daysWithoutCastle ;
2010-01-29 22:52:45 +02:00
// ui32 size;
// if(h.saving) //write subids of available heroes
// {
// size = availableHeroes.size();
// h & size;
// for(size_t i=0; i < size; i++)
// {
// if(availableHeroes[i])
// {
// h & availableHeroes[i]->subID;
// }
// else
// {
// ui32 none = 0xffffffff;
// h & none;
// }
// }
// }
// else
// {
// ui32 hid;
// h & size;
// for(size_t i=0; i < size; i++)
// {
// //fill availableHeroes with dummy hero instances, holding subids
// h & hid;
// availableHeroes.push_back(new CGHeroInstance);
// availableHeroes[availableHeroes.size()-1]->subID = hid;
// }
// }
2008-12-27 03:01:59 +02:00
}
} ;
2009-02-09 16:50:32 +02:00
struct DLL_EXPORT CObstacleInstance
{
2009-08-19 13:59:42 +03:00
int uniqueID ;
int ID ; //ID of obstacle (defines type of it)
2009-02-09 16:50:32 +02:00
int pos ; //position on battlefield
template < typename Handler > void serialize ( Handler & h , const int version )
{
2009-08-19 13:59:42 +03:00
h & ID & pos & uniqueID ;
2009-02-09 16:50:32 +02:00
}
} ;
2009-08-26 17:09:55 +03:00
//only for use in BattleInfo
struct DLL_EXPORT SiegeInfo
{
2009-09-01 16:54:13 +03:00
ui8 wallState [ 8 ] ; //[0] - keep, [1] - bottom tower, [2] - bottom wall, [3] - below gate, [4] - over gate, [5] - upper wall, [6] - uppert tower, [7] - gate; 1 - intact, 2 - damaged, 3 - destroyed
2009-08-26 17:09:55 +03:00
template < typename Handler > void serialize ( Handler & h , const int version )
{
h & wallState ;
}
} ;
2008-12-27 03:01:59 +02:00
struct DLL_EXPORT BattleInfo
{
2009-04-16 17:01:27 +03:00
ui8 side1 , side2 ; //side1 - attacker, side2 - defender
2008-12-27 03:01:59 +02:00
si32 round , activeStack ;
ui8 siege ; // = 0 ordinary battle = 1 a siege with a Fort = 2 a siege with a Citadel = 3 a siege with a Castle
2009-08-22 16:59:15 +03:00
si32 tid ; //used during town siege - id of attacked town; -1 if not town defence
2008-12-27 03:01:59 +02:00
int3 tile ; //for background and bonuses
2009-10-06 03:32:33 +03:00
CGHeroInstance * heroes [ 2 ] ;
2008-12-27 03:01:59 +02:00
CCreatureSet army1 , army2 ;
std : : vector < CStack * > stacks ;
2009-02-09 16:50:32 +02:00
std : : vector < CObstacleInstance > obstacles ;
2009-05-12 06:35:51 +03:00
ui8 castSpells [ 2 ] ; //[0] - attacker, [1] - defender
2009-08-26 17:09:55 +03:00
SiegeInfo si ;
2008-12-27 03:01:59 +02:00
template < typename Handler > void serialize ( Handler & h , const int version )
{
2009-10-06 03:32:33 +03:00
h & side1 & side2 & round & activeStack & siege & tid & tile & stacks & army1 & army2 & obstacles
2009-08-26 17:09:55 +03:00
& castSpells & si ;
2009-10-06 03:32:33 +03:00
h & heroes ;
2008-12-27 03:01:59 +02:00
}
2009-09-07 05:29:44 +03:00
const CStack * getNextStack ( ) const ; //which stack will have turn after current one
2009-09-20 15:47:40 +03:00
void getStackQueue ( std : : vector < const CStack * > & out , int howMany , int turn = 0 , int lastMoved = - 1 ) const ; //returns stack in order of their movement action
2009-08-05 15:46:08 +03:00
CStack * getStack ( int stackID , bool onlyAlive = true ) ;
2009-09-02 17:10:19 +03:00
const CStack * getStack ( int stackID , bool onlyAlive = true ) const ;
2009-08-05 15:46:08 +03:00
CStack * getStackT ( int tileID , bool onlyAlive = true ) ;
2009-09-02 17:10:19 +03:00
const CStack * getStackT ( int tileID , bool onlyAlive = true ) const ;
void getAccessibilityMap ( bool * accessibility , bool twoHex , bool attackerOwned , bool addOccupiable , std : : set < int > & occupyable , bool flying , int stackToOmmit = - 1 ) const ; //send pointer to at least 187 allocated bytes
2009-08-04 18:38:26 +03:00
static bool isAccessible ( int hex , bool * accessibility , bool twoHex , bool attackerOwned , bool flying , bool lastPos ) ; //helper for makeBFS
2009-09-06 20:46:20 +03:00
void makeBFS ( int start , bool * accessibility , int * predecessor , int * dists , bool twoHex , bool attackerOwned , bool flying , bool fillPredecessors ) const ; //*accessibility must be prepared bool[187] array; last two pointers must point to the at least 187-elements int arrays - there is written result
2009-08-02 17:21:18 +03:00
std : : pair < std : : vector < int > , int > getPath ( int start , int dest , bool * accessibility , bool flyingCreature , bool twoHex , bool attackerOwned ) ; //returned value: pair<path, length>; length may be different than number of elements in path since flying vreatures jump between distant hexes
2009-09-02 17:10:19 +03:00
std : : vector < int > getAccessibility ( int stackID , bool addOccupiable ) const ; //returns vector of accessible tiles (taking into account the creature range)
2008-12-27 03:01:59 +02:00
bool isStackBlocked ( int ID ) ; //returns true if there is neighbouring enemy stack
static signed char mutualPosition ( int hex1 , int hex2 ) ; //returns info about mutual position of given hexes (-1 - they're distant, 0 - left top, 1 - right top, 2 - right, 3 - right bottom, 4 - left bottom, 5 - left)
static std : : vector < int > neighbouringTiles ( int hex ) ;
2009-08-29 20:09:07 +03:00
static ui32 calculateDmg ( const CStack * attacker , const CStack * defender , const CGHeroInstance * attackerHero , const CGHeroInstance * defendingHero , bool shooting , ui8 charge ) ; //charge - number of hexes travelled before attack (for champion's jousting)
static std : : pair < ui32 , ui32 > calculateDmgRange ( const CStack * attacker , const CStack * defender , const CGHeroInstance * attackerHero , const CGHeroInstance * defendingHero , bool shooting , ui8 charge ) ; //charge - number of hexes travelled before attack (for champion's jousting); returns pair <min dmg, max dmg>
2009-09-24 16:23:52 +03:00
void calculateCasualties ( std : : map < ui32 , si32 > * casualties ) const ; //casualties are array of maps size 2 (attacker, defeneder), maps are (crid => amount)
2009-05-07 18:19:52 +03:00
std : : set < CStack * > getAttackedCreatures ( const CSpell * s , const CGHeroInstance * caster , int destinationTile ) ; //calculates stack affected by given spell
2009-08-06 17:02:21 +03:00
static int calculateSpellDuration ( const CSpell * spell , const CGHeroInstance * caster ) ;
2009-09-02 17:10:19 +03:00
CStack * generateNewStack ( const CGHeroInstance * owner , int creatureID , int amount , int stackID , bool attackerOwned , int slot , int /*TerrainTile::EterrainType*/ terrain , int position ) const ; //helper for CGameHandler::setupBattle and spells addign new stacks to the battlefield
ui32 getSpellCost ( const CSpell * sp , const CGHeroInstance * caster ) const ; //returns cost of given spell
int hexToWallPart ( int hex ) const ; //returns part of destructible wall / gate / keep under given hex or -1 if not found
std : : pair < const CStack * , int > getNearestStack ( const CStack * closest , boost : : logic : : tribool attackerOwned ) const ; //if attackerOwned is indetermnate, returened stack is of any owner; hex is the number of hex we should be looking from; returns (nerarest creature, predecessorHex)
2009-11-08 16:44:58 +02:00
ui32 calculateSpellDmg ( const CSpell * sp , const CGHeroInstance * caster , const CStack * affectedCreature ) const ; //calculates damage inflicted by spell
2008-12-27 03:01:59 +02:00
} ;
class DLL_EXPORT CStack
{
public :
ui32 ID ; //unique ID of stack
CCreature * creature ;
ui32 amount , baseAmount ;
ui32 firstHPleft ; //HP of first creature in stack
ui8 owner , slot ; //owner - player colour (255 for neutrals), slot - position in garrison (may be 255 for neutrals/called creatures)
ui8 attackerOwned ; //if true, this stack is owned by attakcer (this one from left hand side of battle)
2009-09-04 17:11:42 +03:00
si16 position ; //position on battlefield; -2 - keep, -3 - lower tower, -4 - upper tower
2008-12-27 03:01:59 +02:00
ui8 counterAttacks ; //how many counter attacks can be performed more in this turn (by default set at the beginning of the round to 1)
si16 shots ; //how many shots left
2009-02-05 11:49:45 +02:00
si8 morale , luck ; //base stack luck/morale
2008-12-27 03:01:59 +02:00
2009-05-08 19:55:04 +03:00
std : : vector < StackFeature > features ;
2008-12-27 03:01:59 +02:00
std : : set < ECombatInfo > state ;
struct StackEffect
{
ui16 id ; //spell id
ui8 level ; //skill level
ui16 turnsRemain ;
template < typename Handler > void serialize ( Handler & h , const int version )
{
h & id & level & turnsRemain ;
}
} ;
std : : vector < StackEffect > effects ;
2009-09-20 15:47:40 +03:00
int valOfFeatures ( StackFeature : : ECombatFeatures type , int subtype = - 1024 , int turn = 0 ) const ; //subtype -> subtype of bonus, if -1024 then any
bool hasFeatureOfType ( StackFeature : : ECombatFeatures type , int subtype = - 1024 , int turn = 0 ) const ; //determines if stack has a bonus of given type (and optionally subtype)
2009-05-08 19:55:04 +03:00
2009-05-01 16:42:41 +03:00
CStack ( CCreature * C , int A , int O , int I , bool AO , int S ) ; //c-tor
2009-05-08 19:55:04 +03:00
CStack ( ) : ID ( - 1 ) , creature ( NULL ) , amount ( - 1 ) , baseAmount ( - 1 ) , firstHPleft ( - 1 ) , owner ( 255 ) , slot ( 255 ) , attackerOwned ( true ) , position ( - 1 ) , counterAttacks ( 1 ) { } //c-tor
2009-09-20 15:47:40 +03:00
const StackEffect * getEffect ( ui16 id , int turn = 0 ) const ; //effect id (SP)
2009-04-21 20:32:43 +03:00
ui8 howManyEffectsSet ( ui16 id ) const ; //returns amount of effects with given id set for this stack
2009-09-20 15:47:40 +03:00
bool willMove ( int turn = 0 ) const ; //if stack has remaining move this turn
bool moved ( int turn = 0 ) const ; //if stack was already moved this turn
bool canMove ( int turn = 0 ) const ; //if stack can move
ui32 Speed ( int turn = 0 ) const ; //get speed of creature with all modificators
2009-05-01 16:42:41 +03:00
si8 Morale ( ) const ; //get morale of stack with all modificators
si8 Luck ( ) const ; //get luck of stack with all modificators
si32 Attack ( ) const ; //get attack of stack with all modificators
2009-05-17 18:24:50 +03:00
si32 Defense ( bool withFrenzy = true ) const ; //get defense of stack with all modificators
2009-06-28 16:49:39 +03:00
ui16 MaxHealth ( ) const ; //get max HP of stack with all modifiers
2008-12-27 03:01:59 +02:00
template < typename Handler > void save ( Handler & h , const int version )
{
h & creature - > idNumber ;
}
template < typename Handler > void load ( Handler & h , const int version )
{
ui32 id ;
h & id ;
creature = & VLC - > creh - > creatures [ id ] ;
2009-05-30 19:00:26 +03:00
//features = creature->abilities;
2008-12-27 03:01:59 +02:00
}
template < typename Handler > void serialize ( Handler & h , const int version )
{
h & ID & amount & baseAmount & firstHPleft & owner & slot & attackerOwned & position & state & counterAttacks
2009-05-30 19:00:26 +03:00
& shots & morale & luck & features ;
2008-12-27 03:01:59 +02:00
if ( h . saving )
save ( h , version ) ;
else
load ( h , version ) ;
}
2009-05-01 16:42:41 +03:00
bool alive ( ) const //determines if stack is alive
2008-12-27 03:01:59 +02:00
{
return vstd : : contains ( state , ALIVE ) ;
}
} ;
2009-09-07 05:29:44 +03:00
class DLL_EXPORT CMP_stack
{
int phase ; //rules of which phase will be used
2009-09-20 15:47:40 +03:00
int turn ;
2009-09-07 05:29:44 +03:00
public :
bool operator ( ) ( const CStack * a , const CStack * b ) ;
2009-09-20 15:47:40 +03:00
CMP_stack ( int Phase = 1 , int Turn = 0 ) ;
2009-09-07 05:29:44 +03:00
} ;
2008-12-27 03:01:59 +02:00
struct UpgradeInfo
{
int oldID ; //creature to be upgraded
std : : vector < int > newID ; //possible upgrades
std : : vector < std : : set < std : : pair < int , int > > > cost ; // cost[upgrade_serial] -> set of pairs<resource_ID,resource_amount>
UpgradeInfo ( ) { oldID = - 1 ; } ;
} ;
2009-03-19 21:04:46 +02:00
struct CPathNode
{
2009-10-16 05:09:58 +03:00
bool accessible ; //true if a hero can be on this node
2009-03-19 21:04:46 +02:00
int dist ; //distance from the first node of searching; -1 is infinity
CPathNode * theNodeBefore ;
int3 coord ; //coordiantes
bool visited ;
} ;
2009-08-28 12:03:58 +03:00
struct CGPathNode
{
2009-12-20 19:14:14 +02:00
enum
{
ACCESSIBLE = 1 , //tile can be entered and passed
VISITABLE , //tile can be entered as the last tile in path
BLOCKVIS , //visitable from neighbouring tile but not passable
BLOCKED //tile can't be entered nor visited
} ;
2009-08-28 12:03:58 +03:00
ui8 accessible ; //the enum above
2009-08-30 15:47:40 +03:00
ui8 land ;
2009-08-28 12:03:58 +03:00
ui8 turns ;
ui32 moveRemains ;
2009-08-30 15:47:40 +03:00
CGPathNode * theNodeBefore ;
int3 coord ; //coordinates
2009-08-28 12:03:58 +03:00
CGPathNode ( ) ;
} ;
2009-03-19 21:04:46 +02:00
struct DLL_EXPORT CPath
{
std : : vector < CPathNode > nodes ; //just get node by node
int3 startPos ( ) const ; // start point
int3 endPos ( ) const ; //destination point
void convert ( ui8 mode ) ; //mode=0 -> from 'manifest' to 'object'
2009-03-19 16:17:19 +02:00
} ;
2009-08-30 15:47:40 +03:00
struct DLL_EXPORT CGPath
{
std : : vector < CGPathNode > nodes ; //just get node by node
int3 startPos ( ) const ; // start point
int3 endPos ( ) const ; //destination point
void convert ( ui8 mode ) ; //mode=0 -> from 'manifest' to 'object'
} ;
struct DLL_EXPORT CPathsInfo
2009-08-28 12:03:58 +03:00
{
2009-09-07 05:29:44 +03:00
const CGHeroInstance * hero ;
int3 hpos ;
2009-08-28 12:03:58 +03:00
int3 sizes ;
CGPathNode * * * nodes ; //[w][h][level]
2009-08-30 15:47:40 +03:00
bool getPath ( const int3 & dst , CGPath & out ) ;
CPathsInfo ( const int3 & Sizes ) ;
2009-08-28 12:03:58 +03:00
~ CPathsInfo ( ) ;
} ;
2008-12-27 03:01:59 +02:00
class DLL_EXPORT CGameState
{
2009-03-07 00:11:17 +02:00
public :
2008-12-27 03:01:59 +02:00
StartInfo * scenarioOps ;
ui32 seed ;
ui8 currentPlayer ; //ID of player currently having turn
BattleInfo * curB ; //current battle
ui32 day ; //total number of days in game
Mapa * map ;
2010-01-29 22:52:45 +02:00
std : : map < ui8 , PlayerState > players ; //ID <-> player state
2008-12-27 03:01:59 +02:00
std : : map < int , CGDefInfo * > villages , forts , capitols ; //def-info for town graphics
2009-05-07 20:20:41 +03:00
std : : vector < ui32 > resVals ; //default values of resources in gold
2008-12-27 03:01:59 +02:00
struct DLL_EXPORT HeroesPool
{
std : : map < ui32 , CGHeroInstance * > heroesPool ; //[subID] - heroes available to buy; NULL if not available
2009-11-15 16:06:25 +02:00
std : : map < ui32 , ui8 > pavailable ; // [subid] -> which players can recruit hero (binary flags)
2008-12-27 03:01:59 +02:00
2009-08-05 03:05:37 +03:00
CGHeroInstance * pickHeroFor ( bool native , int player , const CTown * town , std : : map < ui32 , CGHeroInstance * > & available ) const ;
2009-01-06 20:42:20 +02:00
template < typename Handler > void serialize ( Handler & h , const int version )
{
h & heroesPool & pavailable ;
}
2008-12-27 03:01:59 +02:00
} hpool ; //we have here all heroes available on this map that are not hired
boost : : shared_mutex * mx ;
2010-02-10 04:56:00 +02:00
PlayerState * getPlayer ( ui8 color , bool verbose = true ) ;
const PlayerState * getPlayer ( ui8 color , bool verbose = true ) const ;
2008-12-27 03:01:59 +02:00
void init ( StartInfo * si , Mapa * map , int Seed ) ;
void loadTownDInfos ( ) ;
void randomizeObject ( CGObjectInstance * cur ) ;
2009-09-28 17:21:48 +03:00
std : : pair < int , int > pickObject ( CGObjectInstance * obj ) ; //chooses type of object to be randomized, returns <type, subtype>
2008-12-27 03:01:59 +02:00
int pickHero ( int owner ) ;
2009-03-07 00:25:19 +02:00
void apply ( CPack * pack ) ;
2008-12-27 03:01:59 +02:00
CGHeroInstance * getHero ( int objid ) ;
CGTownInstance * getTown ( int objid ) ;
2010-01-29 22:52:45 +02:00
const CGHeroInstance * getHero ( int objid ) const ;
const CGTownInstance * getTown ( int objid ) const ;
2008-12-27 03:01:59 +02:00
bool battleMoveCreatureStack ( int ID , int dest ) ;
bool battleAttackCreatureStack ( int ID , int dest ) ;
bool battleShootCreatureStack ( int ID , int dest ) ;
2009-08-16 16:44:17 +03:00
bool battleCanFlee ( int player ) ; //returns true if player can flee from the battle
2009-08-05 15:46:08 +03:00
int battleGetStack ( int pos , bool onlyAlive ) ; //returns ID of stack at given tile
2009-02-09 16:50:32 +02:00
int battleGetBattlefieldType ( int3 tile = int3 ( ) ) ; // 1. sand/shore 2. sand/mesas 3. dirt/birches 4. dirt/hills 5. dirt/pines 6. grass/hills 7. grass/pines 8. lava 9. magic plains 10. snow/mountains 11. snow/trees 12. subterranean 13. swamp/trees 14. fiery fields 15. rock lands 16. magic clouds 17. lucid pools 18. holy ground 19. clover field 20. evil fog 21. "favourable winds" text on magic plains background 22. cursed ground 23. rough 24. ship to ship 25. ship
2009-09-05 17:10:26 +03:00
const CGHeroInstance * battleGetOwner ( int stackID ) ; //returns hero that owns given stack; NULL if none
2009-05-10 16:00:15 +03:00
si8 battleMaxSpellLevel ( ) ; //calculates maximum spell level possible to be cast on battlefield - takes into account artifacts of both heroes; if no effects are set, SPELL_LEVELS is returned
2009-09-04 17:11:42 +03:00
bool battleCanShoot ( int ID , int dest ) ; //determines if stack with given ID shoot at the selected destination
2009-09-25 15:33:29 +03:00
UpgradeInfo getUpgradeInfo ( const CArmedInstance * obj , int stackPos ) ;
2010-01-01 14:15:20 +02:00
float getMarketEfficiency ( int player , int mode = 0 ) ;
2009-12-29 15:40:16 +02:00
std : : set < int > getBuildingRequiments ( const CGTownInstance * t , int ID ) ;
2009-02-20 17:44:49 +02:00
int canBuildStructure ( const CGTownInstance * t , int ID ) ; // 0 - no more than one capitol, 1 - lack of water, 2 - forbidden, 3 - Add another level to Mage Guild, 4 - already built, 5 - cannot build, 6 - cannot afford, 7 - build, 8 - lack of requirements
2009-08-30 15:47:40 +03:00
bool checkForVisitableDir ( const int3 & src , const int3 & dst ) const ; //check if src tile is visitable from dst tile
bool checkForVisitableDir ( const int3 & src , const TerrainTile * pom , const int3 & dst ) const ; //check if src tile is visitable from dst tile
2009-06-11 20:21:06 +03:00
bool getPath ( int3 src , int3 dest , const CGHeroInstance * hero , CPath & ret ) ; //calculates path between src and dest; returns pointer to newly allocated CPath or NULL if path does not exists
2009-08-30 15:47:40 +03:00
void calculatePaths ( const CGHeroInstance * hero , CPathsInfo & out , int3 src = int3 ( - 1 , - 1 , - 1 ) , int movement = - 1 ) ; //calculates possible paths for hero, by default uses current hero position and movement left; returns pointer to newly allocated CPath or NULL if path does not exists
2010-01-29 22:52:45 +02:00
int victoryCheck ( ui8 player ) const ; //checks if given player is winner; -1 if std victory, 1 if special victory, 0 else
int lossCheck ( ui8 player ) const ; //checks if given player is loser; -1 if std loss, 1 if special, 0 else
ui8 checkForStandardWin ( ) const ; //returns color of player that accomplished standard victory conditions or 255 if no winner
bool checkForStandardLoss ( ui8 player ) const ; //checks if given player lost the game
2010-02-01 19:51:33 +02:00
void obtainPlayersStats ( SThievesGuildInfo & tgi , int level ) ; //fills tgi with info about other players that is available at given level of thieves' guild
2009-03-07 00:11:17 +02:00
2009-07-30 15:49:45 +03:00
bool isVisible ( int3 pos , int player ) ;
bool isVisible ( const CGObjectInstance * obj , int player ) ;
2009-05-07 20:20:41 +03:00
CGameState ( ) ; //c-tor
~ CGameState ( ) ; //d-tor
2009-08-30 15:47:40 +03:00
void getNeighbours ( const TerrainTile & srct , int3 tile , std : : vector < int3 > & vec , const boost : : logic : : tribool & onLand ) ;
int getMovementCost ( const CGHeroInstance * h , const int3 & src , const int3 & dest , int remainingMovePoints = - 1 , bool checkLast = true ) ;
2008-12-27 03:01:59 +02:00
int getDate ( int mode = 0 ) const ; //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month
template < typename Handler > void serialize ( Handler & h , const int version )
{
2009-01-06 20:42:20 +02:00
h & scenarioOps & seed & currentPlayer & day & map & players & resVals & hpool ;
2008-12-27 03:01:59 +02:00
if ( ! h . saving )
{
loadTownDInfos ( ) ;
2009-01-11 00:08:18 +02:00
2010-01-29 22:52:45 +02:00
// //recreating towns/heroes vectors in players entries
// for(int i=0; i<map->towns.size(); i++)
// if(map->towns[i]->tempOwner < PLAYER_LIMIT)
// getPlayer(map->towns[i]->tempOwner)->towns.push_back(map->towns[i]);
// for(int i=0; i<map->heroes.size(); i++)
// if(map->heroes[i]->tempOwner < PLAYER_LIMIT)
// getPlayer(map->heroes[i]->tempOwner)->heroes.push_back(map->heroes[i]);
// //recreating available heroes
// for(std::map<ui8,PlayerState>::iterator i=players.begin(); i!=players.end(); i++)
// {
// for(size_t j=0; j < i->second.availableHeroes.size(); j++)
// {
// ui32 hlp = i->second.availableHeroes[j]->subID;
// delete i->second.availableHeroes[j];
// if(hlp != 0xffffffff)
// {
// assert(vstd::contains(hpool.heroesPool, hlp));
// i->second.availableHeroes[j] = hpool.heroesPool[hlp];
// }
// else
// {
// i->second.availableHeroes[j] = NULL;
// }
// }
// }
2008-12-27 03:01:59 +02:00
}
}
friend class CCallback ;
friend class CLuaCallback ;
friend class CClient ;
friend void initGameState ( Mapa * map , CGameInfo * cgi ) ;
friend class IGameCallback ;
friend class CMapHandler ;
friend class CGameHandler ;
} ;
# endif // __CGAMESTATE_H__