2007-08-27 14:15:03 +00:00
# ifndef CCALLBACK_H
# define CCALLBACK_H
2007-10-16 17:46:01 +00:00
# include "mapHandler.h"
2007-11-18 22:58:28 +00:00
# include "tchar.h"
2007-08-27 14:15:03 +00:00
class CGameState ;
2007-10-05 18:16:22 +00:00
class CPath ;
2007-10-27 19:38:48 +00:00
class CGObjectInstance ;
2007-12-09 12:42:45 +00:00
class SComponent ;
2007-12-25 16:25:53 +00:00
class IChosen ;
2007-12-27 00:11:46 +00:00
class CSelectableComponent ;
2007-11-18 22:58:28 +00:00
typedef struct lua_State lua_State ;
2007-12-06 18:32:06 +00:00
class ICallback
{
public :
virtual bool moveHero ( int ID , CPath * path , int idtype , int pathType = 0 ) = 0 ; //idtype: 0 - position in vector of heroes (of that player); 1 - ID of hero
//pathType: 0 - nodes are manifestation pos, 1 - nodes are object pos
//get info
virtual bool verifyPath ( CPath * path , bool blockSea ) = 0 ;
virtual int getDate ( int mode = 0 ) = 0 ; //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month
virtual PseudoV < PseudoV < PseudoV < unsigned char > > > & getVisibilityMap ( ) = 0 ; //returns visibility map (TODO: make it const)
virtual const CGHeroInstance * getHeroInfo ( int player , int val , bool mode ) = 0 ; //mode = 0 -> val = serial; mode = 1 -> val = ID
virtual int getResourceAmount ( int type ) = 0 ;
virtual int howManyHeroes ( ) = 0 ;
virtual const CGTownInstance * getTownInfo ( int val , bool mode ) = 0 ; //mode = 0 -> val = serial; mode = 1 -> val = ID
virtual int howManyTowns ( ) = 0 ;
virtual std : : vector < std : : string > getObjDescriptions ( int3 pos ) = 0 ; //returns descriptions of objects at pos in order from the lowest to the highest
2007-12-06 19:06:07 +00:00
virtual std : : vector < const CGHeroInstance * > getHeroesInfo ( bool onlyOur = true ) = 0 ;
2007-12-06 18:32:06 +00:00
virtual bool isVisible ( int3 pos ) = 0 ;
virtual int getMyColor ( ) = 0 ;
virtual int getMySerial ( ) = 0 ;
2007-12-06 19:06:07 +00:00
virtual int getHeroSerial ( const CGHeroInstance * hero ) = 0 ;
2008-01-28 14:01:09 +00:00
virtual int swapCreatures ( const CGObjectInstance * s1 , const CGObjectInstance * s2 , int p1 , int p2 ) = 0 ; //swaps creatures between two posiibly different garrisons // TODO: AI-unsafe code - fix it!
2008-01-29 22:47:43 +00:00
virtual int mergeStacks ( const CGObjectInstance * s1 , const CGObjectInstance * s2 , int p1 , int p2 ) = 0 ; //joins first stack tothe second (creatures must be same type)
virtual int splitStack ( const CGObjectInstance * s1 , const CGObjectInstance * s2 , int p1 , int p2 , int val ) = 0 ; //split creatures from the first stack
2008-01-27 16:07:27 +00:00
virtual bool dismissHero ( const CGHeroInstance * hero ) = 0 ; //dismisses diven hero; true - successfuly, false - not successfuly
2008-01-28 14:01:09 +00:00
virtual const CCreatureSet * getGarrison ( const CGObjectInstance * obj ) = 0 ;
2008-01-30 10:55:43 +00:00
virtual bool swapArifacts ( const CGHeroInstance * hero1 , bool worn1 , int pos1 , const CGHeroInstance * hero2 , bool worn2 , int pos2 ) = 0 ; //swaps artifacts between two given heroes
2007-12-06 18:32:06 +00:00
} ;
2007-08-29 10:05:50 +00:00
struct HeroMoveDetails
{
int3 src , dst ; //source and destination points
2007-10-27 19:38:48 +00:00
CGHeroInstance * ho ; //object instance of this hero
2007-08-29 10:05:50 +00:00
int owner ;
2007-11-25 13:16:45 +00:00
bool successful ;
2007-08-29 10:05:50 +00:00
} ;
2007-10-16 17:46:01 +00:00
2007-12-06 18:32:06 +00:00
class CCallback : public ICallback
2007-08-27 14:15:03 +00:00
{
2007-09-14 13:11:10 +00:00
private :
void newTurn ( ) ;
2007-09-30 16:16:00 +00:00
CCallback ( CGameState * GS , int Player ) : gs ( GS ) , player ( Player ) { } ;
2007-10-03 18:53:49 +00:00
CGameState * gs ;
2007-10-27 19:38:48 +00:00
int lowestSpeed ( CGHeroInstance * chi ) ; //speed of the slowest stack
int valMovePoints ( CGHeroInstance * chi ) ;
2007-10-19 21:12:37 +00:00
bool isVisible ( int3 pos , int Player ) ;
2007-09-14 13:11:10 +00:00
2007-08-27 14:15:03 +00:00
protected :
2007-10-03 18:53:49 +00:00
int player ;
2007-08-29 10:05:50 +00:00
2007-08-27 14:15:03 +00:00
public :
2007-10-19 21:12:37 +00:00
//commands
2007-10-05 18:16:22 +00:00
bool moveHero ( int ID , CPath * path , int idtype , int pathType = 0 ) ; //idtype: 0 - position in vector of heroes (of that player); 1 - ID of hero
//pathType: 0 - nodes are manifestation pos, 1 - nodes are object pos
2007-12-25 16:25:53 +00:00
void selectionMade ( int selection , int asker ) ;
2007-09-18 13:30:26 +00:00
2007-10-19 21:12:37 +00:00
//get info
bool verifyPath ( CPath * path , bool blockSea ) ;
int getDate ( int mode = 0 ) ; //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month
PseudoV < PseudoV < PseudoV < unsigned char > > > & getVisibilityMap ( ) ; //returns visibility map (TODO: make it const)
2007-10-27 19:38:48 +00:00
const CGHeroInstance * getHeroInfo ( int player , int val , bool mode ) ; //mode = 0 -> val = serial; mode = 1 -> val = ID
2007-09-16 17:21:23 +00:00
int getResourceAmount ( int type ) ;
2007-10-19 21:12:37 +00:00
int howManyHeroes ( ) ;
2007-10-27 19:38:48 +00:00
const CGTownInstance * getTownInfo ( int val , bool mode ) ; //mode = 0 -> val = serial; mode = 1 -> val = ID
2007-10-19 21:12:37 +00:00
int howManyTowns ( ) ;
std : : vector < std : : string > getObjDescriptions ( int3 pos ) ; //returns descriptions of objects at pos in order from the lowest to the highest
2007-12-06 18:55:58 +00:00
std : : vector < const CGHeroInstance * > getHeroesInfo ( bool onlyOur = true ) ;
2007-10-19 21:12:37 +00:00
bool isVisible ( int3 pos ) ;
2007-12-01 12:50:33 +00:00
int getMyColor ( ) ;
2007-12-06 19:06:07 +00:00
int getHeroSerial ( const CGHeroInstance * hero ) ;
2007-12-01 12:50:33 +00:00
int getMySerial ( ) ;
2008-01-28 14:01:09 +00:00
int swapCreatures ( const CGObjectInstance * s1 , const CGObjectInstance * s2 , int p1 , int p2 ) ;
2008-01-29 22:47:43 +00:00
int mergeStacks ( const CGObjectInstance * s1 , const CGObjectInstance * s2 , int p1 , int p2 ) ;
int splitStack ( const CGObjectInstance * s1 , const CGObjectInstance * s2 , int p1 , int p2 , int val ) ;
2008-01-27 16:07:27 +00:00
bool dismissHero ( const CGHeroInstance * hero ) ;
2008-01-28 14:01:09 +00:00
const CCreatureSet * getGarrison ( const CGObjectInstance * obj ) ;
2008-01-30 10:55:43 +00:00
bool swapArifacts ( const CGHeroInstance * hero1 , bool worn1 , int pos1 , const CGHeroInstance * hero2 , bool worn2 , int pos2 ) ;
2007-10-19 21:12:37 +00:00
//friends
2007-09-30 16:16:00 +00:00
friend int _tmain ( int argc , _TCHAR * argv [ ] ) ;
2007-08-27 14:15:03 +00:00
} ;
2007-11-18 22:58:28 +00:00
class CScriptCallback
{
public :
CGameState * gs ;
2007-08-27 14:15:03 +00:00
2007-11-25 13:16:45 +00:00
//get info
2007-11-18 22:58:28 +00:00
static int3 getPos ( CGObjectInstance * ob ) ;
int getHeroOwner ( int heroID ) ;
int getSelectedHero ( ) ;
2007-11-23 22:33:55 +00:00
int getDate ( int mode = 0 ) ;
2007-11-25 13:16:45 +00:00
//do sth
static void changePrimSkill ( int ID , int which , int val ) ;
2007-12-28 00:00:57 +00:00
void showInfoDialog ( int player , std : : string text , std : : vector < SComponent * > * components ) ; //TODO: obslugiwac nulle
2007-12-27 00:11:46 +00:00
void showSelDialog ( int player , std : : string text , std : : vector < CSelectableComponent * > * components , IChosen * asker ) ;
2007-11-23 22:33:55 +00:00
void giveResource ( int player , int which , int val ) ;
2007-12-22 14:40:27 +00:00
void showCompInfo ( int player , SComponent * comp ) ;
2008-01-28 14:01:09 +00:00
void heroVisitCastle ( CGObjectInstance * ob , int heroID ) ;
void stopHeroVisitCastle ( CGObjectInstance * ob , int heroID ) ;
2007-11-25 13:16:45 +00:00
//friends
2007-11-18 22:58:28 +00:00
friend void initGameState ( CGameInfo * cgi ) ;
} ;
class CLuaCallback : public CScriptCallback
2007-10-27 19:38:48 +00:00
{
2007-11-18 22:58:28 +00:00
private :
static void registerFuncs ( lua_State * L ) ;
static int getPos ( lua_State * L ) ; //(CGObjectInstance * object);
static int changePrimSkill ( lua_State * L ) ; //(int ID, int which, int val);
static int getGnrlText ( lua_State * L ) ; //(int ID, int which, int val);
static int getSelectedHero ( lua_State * L ) ; //()
friend void initGameState ( CGameInfo * cgi ) ;
2007-10-27 19:38:48 +00:00
} ;
2007-08-27 14:15:03 +00:00
# endif //CCALLBACK_H