2007-07-28 15:23:15 +00:00
# ifndef CGAMESTATE_H
# define CGAMESTATE_H
2008-06-30 00:06:41 +00:00
# include "global.h"
2008-08-04 23:04:15 +00:00
# ifndef _MSC_VER
2008-08-20 06:57:53 +00:00
# include "hch/CCreatureHandler.h"
2008-08-04 20:27:47 +00:00
# include "lib/VCMI_Lib.h"
2008-08-04 23:04:15 +00:00
# endif
2007-11-24 14:17:57 +00:00
# include <set>
2008-06-30 00:06:41 +00:00
# include <vector>
2008-08-02 15:08:03 +00:00
# ifdef _WIN32
2008-02-24 23:06:27 +00:00
# include <tchar.h>
2008-08-02 15:08:03 +00:00
# else
# include "tchar_amigaos4.h"
# endif
2008-03-10 20:19:41 +00:00
2007-11-18 22:58:28 +00:00
class CScriptCallback ;
2007-08-27 14:15:03 +00:00
class CCallback ;
2007-11-18 22:58:28 +00:00
class CLuaCallback ;
2007-11-24 14:17:57 +00:00
class CCPPObjectScript ;
2008-02-24 23:06:27 +00:00
class CCreatureSet ;
class CStack ;
class CGHeroInstance ;
2008-06-30 00:06:41 +00:00
class CGTownInstance ;
2008-02-24 23:06:27 +00:00
class CArmedInstance ;
2008-06-30 00:06:41 +00:00
class CGDefInfo ;
class CObjectScript ;
class CGObjectInstance ;
class CCreature ;
2008-06-21 13:27:52 +00:00
struct Mapa ;
2008-06-30 00:06:41 +00:00
struct StartInfo ;
struct SDL_Surface ;
class CMapHandler ;
class CPathfinder ;
2008-07-26 13:57:32 +00:00
struct IPack ;
2008-03-10 20:19:41 +00:00
2008-07-27 17:07:37 +00:00
namespace boost
{
class shared_mutex ;
}
2008-06-30 00:06:41 +00:00
struct DLL_EXPORT PlayerState
2007-07-28 15:23:15 +00:00
{
2007-08-04 19:01:22 +00:00
public :
2008-08-01 11:21:15 +00:00
ui8 color , serial ;
std : : vector < std : : vector < std : : vector < ui8 > > > fogOfWarMap ; //true - visible, false - hidden
std : : vector < si32 > resources ;
2007-10-27 19:38:48 +00:00
std : : vector < CGHeroInstance * > heroes ;
std : : vector < CGTownInstance * > towns ;
2007-09-18 13:30:26 +00:00
PlayerState ( ) : color ( - 1 ) { } ;
2007-07-28 23:01:25 +00:00
} ;
2008-03-10 20:19:41 +00:00
2008-06-30 00:06:41 +00:00
struct DLL_EXPORT BattleInfo
2008-02-24 23:06:27 +00:00
{
2008-08-04 15:56:36 +00:00
ui8 side1 , side2 ;
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
2008-02-24 23:06:27 +00:00
int3 tile ; //for background and bonuses
2008-08-04 15:56:36 +00:00
si32 hero1 , hero2 ;
CCreatureSet army1 , army2 ;
2008-02-24 23:06:27 +00:00
std : : vector < CStack * > stacks ;
2008-08-04 15:56:36 +00:00
template < typename Handler > void serialize ( Handler & h , const int version )
{
2008-09-09 07:05:02 +00:00
h & side1 & side2 & round & activeStack & siege & tile & stacks & army1 & army2 & hero1 & hero2 ;
2008-08-04 15:56:36 +00:00
}
2008-08-04 23:04:15 +00:00
CStack * getStack ( int stackID ) ;
CStack * getStackT ( int tileID ) ;
2008-08-06 17:49:47 +00:00
void getAccessibilityMap ( bool * accessibility , int stackToOmmit = - 1 ) ; //send pointer to at least 187 allocated bytes
void getAccessibilityMapForTwoHex ( bool * accessibility , bool atackerSide , int stackToOmmit = - 1 ) ; //send pointer to at least 187 allocated bytes
2008-08-05 23:33:08 +00:00
void makeBFS ( int start , bool * accessibility , int * predecessor , int * dists ) ; //*accessibility must be prepared bool[187] array; last two pointers must point to the at least 187-elements int arrays - there is written result
2008-08-04 23:04:15 +00:00
std : : vector < int > getPath ( int start , int dest , bool * accessibility ) ;
2008-08-05 23:33:08 +00:00
std : : vector < int > getAccessibility ( int stackID ) ; //returns vector of accessible tiles (taking into account the creature range)
2008-08-06 17:49:47 +00:00
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 ) ;
2008-08-08 23:02:32 +00:00
static int calculateDmg ( const CStack * attacker , const CStack * defender ) ; //TODO: add additional conditions and require necessary data
2008-09-09 07:05:02 +00:00
void calculateCasualties ( std : : set < std : : pair < ui32 , si32 > > * casualties ) ;
2008-02-24 23:06:27 +00:00
} ;
2008-03-10 20:19:41 +00:00
2008-06-30 00:06:41 +00:00
class DLL_EXPORT CStack
2008-09-12 08:51:46 +00:00
{
2008-03-09 23:06:35 +00:00
public :
2008-08-04 15:56:36 +00:00
ui32 ID ; //unique ID of stack
2008-03-09 23:06:35 +00:00
CCreature * creature ;
2008-09-09 07:05:02 +00:00
ui32 amount , baseAmount ;
2008-08-04 15:56:36 +00:00
ui32 firstHPleft ; //HP of first creature in stack
2008-09-12 08:51:46 +00:00
ui8 owner , slot ; //owner - player colour (255 for neutrals), slot - position in garrison (may be 255 for neutrals/called creatures)
2008-08-04 15:56:36 +00:00
ui8 attackerOwned ; //if true, this stack is owned by attakcer (this one from left hand side of battle)
ui16 position ; //position on battlefield
2008-09-23 10:58:54 +00: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)
2008-09-12 08:51:46 +00:00
std : : set < EAbilities > abilities ;
std : : set < ECombatInfo > state ;
2008-08-04 15:56:36 +00:00
2008-09-09 07:05:02 +00:00
CStack ( CCreature * C , int A , int O , int I , bool AO , int S ) ;
2008-09-23 10:58:54 +00:00
CStack ( ) : creature ( NULL ) , amount ( - 1 ) , owner ( 255 ) , position ( - 1 ) , ID ( - 1 ) , attackerOwned ( true ) , firstHPleft ( - 1 ) , slot ( 255 ) , baseAmount ( - 1 ) , counterAttacks ( 1 ) { } ;
2008-08-04 15:56:36 +00: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 ] ;
2008-09-12 08:51:46 +00:00
abilities = creature - > abilities ;
2008-08-04 15:56:36 +00:00
}
template < typename Handler > void serialize ( Handler & h , const int version )
{
2008-09-12 08:51:46 +00:00
h & ID & amount & baseAmount & firstHPleft & owner & slot & attackerOwned & position & state & counterAttacks ;
2008-08-04 15:56:36 +00:00
if ( h . saving )
save ( h , version ) ;
else
load ( h , version ) ;
}
2008-09-12 08:51:46 +00:00
bool alive ( )
{
return vstd : : contains ( state , ALIVE ) ;
}
2008-03-09 23:06:35 +00:00
} ;
2008-03-10 20:19:41 +00:00
2008-08-15 12:11:42 +00: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 ; } ;
} ;
2008-06-30 00:06:41 +00:00
class DLL_EXPORT CGameState
2007-07-28 15:23:15 +00:00
{
2007-11-18 22:58:28 +00:00
private :
2008-06-30 00:06:41 +00:00
StartInfo * scenarioOps ;
2008-07-25 17:28:28 +00:00
ui32 seed ;
ui8 currentPlayer ; //ID of player currently having turn
2008-02-24 23:06:27 +00:00
BattleInfo * curB ; //current battle
2008-07-25 17:28:28 +00:00
ui32 day ; //total number of days in game
2008-06-21 13:27:52 +00:00
Mapa * map ;
2008-07-25 17:28:28 +00:00
std : : map < ui8 , PlayerState > players ; //ID <-> playerstate
2008-06-30 00:06:41 +00:00
std : : map < int , CGDefInfo * > villages , forts , capitols ; //def-info for town graphics
2008-09-07 03:38:37 +00:00
std : : vector < ui32 > resVals ;
2007-11-18 22:58:28 +00:00
2008-07-27 17:07:37 +00:00
boost : : shared_mutex * mx ;
2008-06-30 00:06:41 +00:00
2008-07-27 17:07:37 +00:00
CGameState ( ) ;
~ CGameState ( ) ;
2008-07-25 17:28:28 +00:00
void init ( StartInfo * si , Mapa * map , int Seed ) ;
2008-08-10 04:46:16 +00:00
void applyNL ( IPack * pack ) ;
2008-07-26 13:57:32 +00:00
void apply ( IPack * pack ) ;
2008-06-30 00:06:41 +00:00
void randomizeObject ( CGObjectInstance * cur ) ;
std : : pair < int , int > pickObject ( CGObjectInstance * obj ) ;
int pickHero ( int owner ) ;
2008-08-04 15:56:36 +00:00
CGHeroInstance * getHero ( int objid ) ;
2008-08-13 09:28:06 +00:00
CGTownInstance * getTown ( int objid ) ;
2008-08-04 15:56:36 +00:00
2008-03-23 17:25:38 +00:00
bool battleMoveCreatureStack ( int ID , int dest ) ;
2008-05-27 13:16:35 +00:00
bool battleAttackCreatureStack ( int ID , int dest ) ;
2008-08-02 15:08:03 +00:00
bool battleShootCreatureStack ( int ID , int dest ) ;
int battleGetStack ( int pos ) ; //returns ID of stack at given tile
2008-08-15 12:11:42 +00:00
UpgradeInfo getUpgradeInfo ( CArmedInstance * obj , int stackPos ) ;
2008-09-07 03:38:37 +00:00
float getMarketEfficiency ( int player , int mode = 0 ) ;
2008-09-23 10:58:54 +00:00
std : : set < int3 > tilesToReveal ( int3 pos , int radious , int player ) ; //if player==-1 => adds all tiles in radious
2007-08-27 14:15:03 +00:00
public :
2008-07-25 17:28:28 +00: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
2008-08-20 06:57:53 +00:00
2008-07-25 17:28:28 +00:00
friend class CCallback ;
friend class CPathfinder ; ;
friend class CLuaCallback ;
friend class CClient ;
2008-06-11 01:53:57 +00:00
friend void initGameState ( Mapa * map , CGameInfo * cgi ) ;
2008-07-25 17:28:28 +00:00
friend class CScriptCallback ;
2008-07-02 08:39:56 +00:00
friend class CMapHandler ;
2008-07-25 17:28:28 +00:00
friend class CGameHandler ;
2007-07-28 23:01:25 +00:00
} ;
2007-07-28 15:23:15 +00:00
2007-09-14 13:11:10 +00:00
# endif //CGAMESTATE_H