2007-08-27 17:15:03 +03:00
# ifndef CCALLBACK_H
# define CCALLBACK_H
2007-10-16 20:46:01 +03:00
# include "mapHandler.h"
2008-07-16 21:26:15 +03:00
# ifdef _WIN32
2007-11-19 00:58:28 +02:00
# include "tchar.h"
2008-07-16 21:26:15 +03:00
# else
# include "tchar_amigaos4.h"
# endif
2008-03-14 20:24:37 +02:00
# include "CGameState.h"
2007-08-27 17:15:03 +03:00
class CGameState ;
2008-04-20 18:56:03 +03:00
struct CPath ;
2007-10-27 22:38:48 +03:00
class CGObjectInstance ;
2007-12-09 14:42:45 +02:00
class SComponent ;
2007-12-25 18:25:53 +02:00
class IChosen ;
2007-12-27 02:11:46 +02:00
class CSelectableComponent ;
2008-03-29 12:59:18 +02:00
struct BattleAction ;
2007-11-19 00:58:28 +02:00
typedef struct lua_State lua_State ;
2007-12-06 20:32:06 +02:00
2008-05-23 22:50:11 +03:00
//structure gathering info about upgrade possibilites
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 ; } ;
} ;
2007-12-06 20:32:06 +02:00
class ICallback
2008-07-16 21:26:15 +03:00
{
2007-12-06 20:32:06 +02:00
public :
2008-07-16 21:26:15 +03:00
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
2007-12-06 20:32:06 +02:00
//pathType: 0 - nodes are manifestation pos, 1 - nodes are object pos
2008-04-11 20:41:02 +03: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!
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
virtual bool dismissHero ( const CGHeroInstance * hero ) = 0 ; //dismisses diven hero; true - successfuly, false - not successfuly
virtual bool swapArifacts ( const CGHeroInstance * hero1 , bool worn1 , int pos1 , const CGHeroInstance * hero2 , bool worn2 , int pos2 ) = 0 ; //swaps artifacts between two given heroes
virtual void recruitCreatures ( const CGObjectInstance * obj , int ID , int amount ) = 0 ;
2008-05-23 22:50:11 +03:00
virtual bool dismissCreature ( const CArmedInstance * obj , int stackPos ) = 0 ;
2008-05-31 23:37:54 +03:00
virtual bool upgradeCreature ( const CArmedInstance * obj , int stackPos , int newID = - 1 ) = 0 ; //if newID==-1 then best possible upgrade will be made
2007-12-06 20:32:06 +02:00
//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 21:06:07 +02:00
virtual std : : vector < const CGHeroInstance * > getHeroesInfo ( bool onlyOur = true ) = 0 ;
2007-12-06 20:32:06 +02:00
virtual bool isVisible ( int3 pos ) = 0 ;
virtual int getMyColor ( ) = 0 ;
virtual int getMySerial ( ) = 0 ;
2007-12-06 21:06:07 +02:00
virtual int getHeroSerial ( const CGHeroInstance * hero ) = 0 ;
2008-01-28 16:01:09 +02:00
virtual const CCreatureSet * getGarrison ( const CGObjectInstance * obj ) = 0 ;
2008-05-23 22:50:11 +03:00
virtual UpgradeInfo getUpgradeInfo ( const CArmedInstance * obj , int stackPos ) = 0 ;
2008-04-13 14:05:39 +03:00
//battle
virtual int battleGetBattlefieldType ( ) = 0 ; // 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
2008-07-16 21:26:15 +03:00
virtual int battleGetObstaclesAtTile ( int tile ) = 0 ; //returns bitfield
2008-04-13 14:05:39 +03:00
virtual int battleGetStack ( int pos ) = 0 ; //returns ID of stack on the tile
virtual CStack battleGetStackByID ( int ID ) = 0 ; //returns stack info by given ID
2008-06-10 14:34:20 +03:00
virtual CStack battleGetStackByPos ( int pos ) = 0 ; //returns stack info by given pos
2008-04-13 14:05:39 +03:00
virtual int battleGetPos ( int stack ) = 0 ; //returns position (tile ID) of stack
2008-04-15 19:52:31 +03:00
//virtual int battleMakeAction(BattleAction* action)=0;//perform action with an active stack (or custom action)
2008-04-13 14:05:39 +03:00
virtual std : : map < int , CStack > battleGetStacks ( ) = 0 ; //returns stacks on battlefield
virtual CCreature battleGetCreature ( int number ) = 0 ; //returns type of creature by given number of stack
2008-04-15 19:52:31 +03:00
//virtual bool battleMoveCreature(int ID, int dest)=0; //moves creature with id ID to dest if possible
2008-04-13 14:05:39 +03:00
virtual std : : vector < int > battleGetAvailableHexes ( int ID ) = 0 ; //reutrns numbers of hexes reachable by creature with id ID
virtual bool battleIsStackMine ( int ID ) = 0 ; //returns true if stack with id ID belongs to caller
2008-07-11 12:43:13 +03:00
virtual bool battleCanShoot ( int ID , int dest ) = 0 ; //returns true if unit with id ID can shoot to dest
2007-12-06 20:32:06 +02:00
} ;
2007-08-29 13:05:50 +03:00
struct HeroMoveDetails
{
int3 src , dst ; //source and destination points
2007-10-27 22:38:48 +03:00
CGHeroInstance * ho ; //object instance of this hero
2007-08-29 13:05:50 +03:00
int owner ;
2007-11-25 15:16:45 +02:00
bool successful ;
2007-08-29 13:05:50 +03:00
} ;
2007-10-16 20:46:01 +03:00
2007-12-06 20:32:06 +02:00
class CCallback : public ICallback
2007-08-27 17:15:03 +03:00
{
2007-09-14 16:11:10 +03:00
private :
void newTurn ( ) ;
2007-09-30 19:16:00 +03:00
CCallback ( CGameState * GS , int Player ) : gs ( GS ) , player ( Player ) { } ;
2007-10-03 21:53:49 +03:00
CGameState * gs ;
2007-10-27 22:38:48 +03:00
int lowestSpeed ( CGHeroInstance * chi ) ; //speed of the slowest stack
2008-07-16 21:26:15 +03:00
int valMovePoints ( CGHeroInstance * chi ) ;
2007-10-20 00:12:37 +03:00
bool isVisible ( int3 pos , int Player ) ;
2007-09-14 16:11:10 +03:00
2007-08-27 17:15:03 +03:00
protected :
2007-10-03 21:53:49 +03:00
int player ;
2007-08-29 13:05:50 +03:00
2007-08-27 17:15:03 +03:00
public :
2007-10-20 00:12:37 +03:00
//commands
2008-07-16 21:26:15 +03: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
2007-10-05 21:16:22 +03:00
//pathType: 0 - nodes are manifestation pos, 1 - nodes are object pos
2007-12-25 18:25:53 +02:00
void selectionMade ( int selection , int asker ) ;
2008-05-23 22:50:11 +03:00
int swapCreatures ( const CGObjectInstance * s1 , const CGObjectInstance * s2 , int p1 , int p2 ) ;
int mergeStacks ( const CGObjectInstance * s1 , const CGObjectInstance * s2 , int p1 , int p2 ) ; //first goes to the second
int splitStack ( const CGObjectInstance * s1 , const CGObjectInstance * s2 , int p1 , int p2 , int val ) ;
bool dismissHero ( const CGHeroInstance * hero ) ;
bool swapArifacts ( const CGHeroInstance * hero1 , bool worn1 , int pos1 , const CGHeroInstance * hero2 , bool worn2 , int pos2 ) ;
bool buildBuilding ( const CGTownInstance * town , int buildingID ) ;
2008-04-11 20:41:02 +03:00
void recruitCreatures ( const CGObjectInstance * obj , int ID , int amount ) ;
2008-05-23 22:50:11 +03:00
bool dismissCreature ( const CArmedInstance * obj , int stackPos ) ;
2008-05-31 23:37:54 +03:00
bool upgradeCreature ( const CArmedInstance * obj , int stackPos , int newID = - 1 ) ;
2008-04-11 20:41:02 +03:00
2007-09-18 16:30:26 +03:00
2007-10-20 00:12:37 +03: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 22:38:48 +03:00
const CGHeroInstance * getHeroInfo ( int player , int val , bool mode ) ; //mode = 0 -> val = serial; mode = 1 -> val = ID
2007-09-16 20:21:23 +03:00
int getResourceAmount ( int type ) ;
2008-05-12 08:46:04 +03:00
std : : vector < int > getResourceAmount ( ) ;
2007-10-20 00:12:37 +03:00
int howManyHeroes ( ) ;
2007-10-27 22:38:48 +03:00
const CGTownInstance * getTownInfo ( int val , bool mode ) ; //mode = 0 -> val = serial; mode = 1 -> val = ID
2008-02-18 23:14:28 +02:00
std : : vector < const CGTownInstance * > getTownsInfo ( bool onlyOur = true ) ;
2007-10-20 00:12:37 +03: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 20:55:58 +02:00
std : : vector < const CGHeroInstance * > getHeroesInfo ( bool onlyOur = true ) ;
2007-10-20 00:12:37 +03:00
bool isVisible ( int3 pos ) ;
2007-12-01 14:50:33 +02:00
int getMyColor ( ) ;
2007-12-06 21:06:07 +02:00
int getHeroSerial ( const CGHeroInstance * hero ) ;
2007-12-01 14:50:33 +02:00
int getMySerial ( ) ;
2008-01-28 16:01:09 +02:00
const CCreatureSet * getGarrison ( const CGObjectInstance * obj ) ;
2008-05-23 22:50:11 +03:00
UpgradeInfo getUpgradeInfo ( const CArmedInstance * obj , int stackPos ) ;
2008-02-25 01:06:27 +02:00
//battle
int battleGetBattlefieldType ( ) ; // 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
2008-07-16 21:26:15 +03:00
int battleGetObstaclesAtTile ( int tile ) ; //returns bitfield
2008-02-25 01:06:27 +02:00
int battleGetStack ( int pos ) ; //returns ID of stack on the tile
2008-04-07 20:51:46 +03:00
CStack battleGetStackByID ( int ID ) ; //returns stack info by given ID
2008-06-10 14:34:20 +03:00
CStack battleGetStackByPos ( int pos ) ; //returns stack info by given pos
2008-02-25 01:06:27 +02:00
int battleGetPos ( int stack ) ; //returns position (tile ID) of stack
2008-04-15 19:52:31 +03:00
//int battleMakeAction(BattleAction* action);//perform action with an active stack (or custom action)
2008-03-14 20:24:37 +02:00
std : : map < int , CStack > battleGetStacks ( ) ; //returns stacks on battlefield
2008-03-23 19:25:38 +02:00
CCreature battleGetCreature ( int number ) ; //returns type of creature by given number of stack
2008-04-15 19:52:31 +03:00
//bool battleMoveCreature(int ID, int dest); //moves creature with id ID to dest if possible
2008-03-29 12:59:18 +02:00
std : : vector < int > battleGetAvailableHexes ( int ID ) ; //reutrns numbers of hexes reachable by creature with id ID
2008-04-07 20:51:46 +03:00
bool battleIsStackMine ( int ID ) ; //returns true if stack with id ID belongs to caller
2008-07-11 12:43:13 +03:00
bool battleCanShoot ( int ID , int dest ) ; //returns true if unit with id ID can shoot to dest
2008-07-16 21:26:15 +03:00
2007-10-20 00:12:37 +03:00
//friends
2008-07-16 21:26:15 +03:00
# ifndef __GNUC__
2007-09-30 19:16:00 +03:00
friend int _tmain ( int argc , _TCHAR * argv [ ] ) ;
2008-07-16 21:26:15 +03:00
# else
friend int main ( int argc , _TCHAR * argv [ ] ) ;
# endif
2007-08-27 17:15:03 +03:00
} ;
2007-11-19 00:58:28 +02:00
class CScriptCallback
{
public :
CGameState * gs ;
2007-08-27 17:15:03 +03:00
2007-11-25 15:16:45 +02:00
//get info
2007-11-19 00:58:28 +02:00
static int3 getPos ( CGObjectInstance * ob ) ;
int getHeroOwner ( int heroID ) ;
int getSelectedHero ( ) ;
2007-11-24 00:33:55 +02:00
int getDate ( int mode = 0 ) ;
2007-11-25 15:16:45 +02:00
//do sth
static void changePrimSkill ( int ID , int which , int val ) ;
2007-12-28 02:00:57 +02:00
void showInfoDialog ( int player , std : : string text , std : : vector < SComponent * > * components ) ; //TODO: obslugiwac nulle
2007-12-27 02:11:46 +02:00
void showSelDialog ( int player , std : : string text , std : : vector < CSelectableComponent * > * components , IChosen * asker ) ;
2007-11-24 00:33:55 +02:00
void giveResource ( int player , int which , int val ) ;
2007-12-22 16:40:27 +02:00
void showCompInfo ( int player , SComponent * comp ) ;
2008-01-28 16:01:09 +02:00
void heroVisitCastle ( CGObjectInstance * ob , int heroID ) ;
void stopHeroVisitCastle ( CGObjectInstance * ob , int heroID ) ;
2008-02-07 20:45:22 +02:00
void giveHeroArtifact ( int artid , int hid , int position ) ; //pos==-1 - first free slot in backpack
2008-02-25 01:06:27 +02:00
void startBattle ( CCreatureSet * army1 , CCreatureSet * army2 , int3 tile , CGHeroInstance * hero1 , CGHeroInstance * hero2 ) ; //use hero=NULL for no hero
void startBattle ( int heroID , CCreatureSet * army , int3 tile ) ; //for hero<=>neutral army
2007-11-25 15:16:45 +02:00
//friends
2007-11-19 00:58:28 +02:00
friend void initGameState ( CGameInfo * cgi ) ;
} ;
class CLuaCallback : public CScriptCallback
2007-10-27 22:38:48 +03:00
{
2007-11-19 00:58:28 +02: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 22:38:48 +03:00
} ;
2008-07-16 21:26:15 +03:00
# endif //CCALLBACK_H