2007-07-28 18:23:15 +03:00
# ifndef CGAMESTATE_H
# define CGAMESTATE_H
2008-03-10 22:19:41 +02:00
2007-10-16 20:46:01 +03:00
# include "mapHandler.h"
2007-11-24 16:17:57 +02:00
# include <set>
2008-02-25 01:06:27 +02:00
# include <tchar.h>
2008-03-10 22:19:41 +02:00
2007-11-19 00:58:28 +02:00
class CScriptCallback ;
2007-08-27 17:15:03 +03:00
class CCallback ;
2007-11-19 00:58:28 +02:00
class CLuaCallback ;
2007-11-24 16:17:57 +02:00
class CCPPObjectScript ;
2008-02-25 01:06:27 +02:00
class CCreatureSet ;
class CStack ;
class CGHeroInstance ;
class CArmedInstance ;
2008-03-10 22:19:41 +02:00
2007-07-28 18:23:15 +03:00
struct PlayerState
{
2007-08-04 22:01:22 +03:00
public :
2007-11-19 00:58:28 +02:00
int color , serial ;
2007-10-16 20:46:01 +03:00
//std::vector<std::vector<std::vector<char> > > fogOfWarMap; //true - visible, false - hidden
PseudoV < PseudoV < PseudoV < unsigned char > > > fogOfWarMap ; //true - visible, false - hidden
2007-07-28 18:23:15 +03:00
std : : vector < int > resources ;
2007-10-27 22:38:48 +03:00
std : : vector < CGHeroInstance * > heroes ;
std : : vector < CGTownInstance * > towns ;
2007-09-18 16:30:26 +03:00
PlayerState ( ) : color ( - 1 ) { } ;
2007-07-29 02:01:25 +03:00
} ;
2008-03-10 22:19:41 +02:00
2008-02-25 01:06:27 +02:00
struct BattleInfo
{
int side1 , side2 ;
int round , activeStack ;
int siege ; // = 0 ordinary battle = 1 a siege with a Fort = 2 a siege with a Citadel = 3 a siege with a Castle
int3 tile ; //for background and bonuses
CGHeroInstance * hero1 , * hero2 ;
CCreatureSet * army1 , * army2 ;
std : : vector < CStack * > stacks ;
2008-03-29 12:59:18 +02:00
bool stackActionPerformed ; //true if current stack has been moved
2008-02-25 01:06:27 +02:00
} ;
2008-03-10 22:19:41 +02:00
2008-03-10 01:06:35 +02:00
class CStack
{
public :
2008-03-14 20:24:37 +02:00
int ID ; //unique ID of stack
2008-03-10 01:06:35 +02:00
CCreature * creature ;
int amount ;
int owner ;
2008-04-14 21:24:46 +03:00
bool attackerOwned ; //if true, this stack is owned by attakcer (this one from left hand side of battle)
2008-03-10 22:19:41 +02:00
int position ; //position on battlefield
bool alive ; //true if it is alive
2008-04-14 21:24:46 +03:00
CStack ( CCreature * C , int A , int O , int I , bool AO ) : creature ( C ) , amount ( A ) , owner ( O ) , alive ( true ) , position ( - 1 ) , ID ( I ) , attackerOwned ( AO ) { } ;
CStack ( ) : creature ( NULL ) , amount ( - 1 ) , owner ( 255 ) , alive ( true ) , position ( - 1 ) , ID ( - 1 ) , attackerOwned ( true ) { } ;
2008-03-10 01:06:35 +02:00
} ;
2008-03-10 22:19:41 +02:00
2007-07-28 18:23:15 +03:00
class CGameState
{
2007-11-19 00:58:28 +02:00
private :
2007-08-04 22:01:22 +03:00
int currentPlayer ;
2008-02-25 01:06:27 +02:00
BattleInfo * curB ; //current battle
2007-09-18 16:30:26 +03:00
int day ; //total number of days in game
2007-07-29 02:01:25 +03:00
std : : map < int , PlayerState > players ; //color <-> playerstate
2007-11-24 16:17:57 +02:00
std : : set < CCPPObjectScript * > cppscripts ;
std : : map < int , std : : map < std : : string , CObjectScript * > > objscr ; //custom user scripts (as for now only Lua)
2007-11-19 00:58:28 +02:00
bool checkFunc ( int obid , std : : string name )
{
if ( objscr . find ( obid ) ! = objscr . end ( ) )
{
if ( objscr [ obid ] . find ( name ) ! = objscr [ obid ] . end ( ) )
{
return true ;
}
}
return false ;
}
CGHeroInstance * getHero ( int ID , int mode )
{
if ( mode ! = 0 )
throw new std : : exception ( " gs->getHero: This mode is not supported! " ) ;
for ( std : : map < int , PlayerState > : : iterator i = players . begin ( ) ; i ! = players . end ( ) ; i + + )
{
for ( int j = 0 ; j < ( * i ) . second . heroes . size ( ) ; j + + )
{
if ( i - > second . heroes [ j ] - > subID = = ID )
return i - > second . heroes [ j ] ;
}
}
return NULL ;
}
2008-02-25 01:06:27 +02:00
void battle ( CCreatureSet * army1 , CCreatureSet * army2 , int3 tile , CArmedInstance * hero1 , CArmedInstance * hero2 ) ;
2008-03-23 19:25:38 +02:00
bool battleMoveCreatureStack ( int ID , int dest ) ;
2008-03-29 12:59:18 +02:00
std : : vector < int > battleGetRange ( int ID ) ; //called by std::vector<int> CCallback::battleGetAvailableHexes(int ID);
2007-08-27 17:15:03 +03:00
public :
friend CCallback ;
2008-02-23 21:20:41 +02:00
friend CPathfinder ; ;
2007-11-19 00:58:28 +02:00
friend CLuaCallback ;
2007-08-27 17:15:03 +03:00
friend int _tmain ( int argc , _TCHAR * argv [ ] ) ;
2007-09-14 16:11:10 +03:00
friend void initGameState ( CGameInfo * cgi ) ;
2007-11-19 00:58:28 +02:00
friend CScriptCallback ;
2007-11-24 16:17:57 +02:00
friend void handleCPPObjS ( std : : map < int , CCPPObjectScript * > * mapa , CCPPObjectScript * script ) ;
2007-09-30 19:16:00 +03:00
//CCallback * cb; //for communication between PlayerInterface/AI and GameState
2007-10-27 23:14:25 +03:00
2008-02-11 20:40:10 +02:00
friend SDL_Surface * CMapHandler : : terrainRect ( int x , int y , int dx , int dy , int level , unsigned char anim , PseudoV < PseudoV < PseudoV < unsigned char > > > & visibilityMap , bool otherHeroAnim , unsigned char heroAnim , SDL_Surface * extSurf , SDL_Rect * extRect ) ; //todo: wywalic koniecznie, tylko do flag obecnie!!!!
2007-07-29 02:01:25 +03:00
} ;
2007-07-28 18:23:15 +03:00
2007-09-14 16:11:10 +03:00
# endif //CGAMESTATE_H