2011-12-14 00:23:17 +03:00
# pragma once
2011-05-03 06:14:18 +03:00
# include "lib/IGameCallback.h"
2009-04-16 14:14:13 +03:00
2009-04-15 17:03:31 +03:00
/*
* CCallback . 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
*
2009-04-16 14:14:13 +03:00
*/
2009-08-05 03:21:06 +03:00
2009-04-16 14:14:13 +03:00
class CGHeroInstance ;
class CGameState ;
struct CPath ;
class CGObjectInstance ;
class CArmedInstance ;
struct BattleAction ;
class CGTownInstance ;
struct lua_State ;
class CClient ;
2009-07-26 06:33:13 +03:00
class IShipyard ;
2009-08-30 15:47:40 +03:00
struct CGPathNode ;
struct CGPath ;
2011-05-03 06:14:18 +03:00
struct CPathsInfo ;
2011-08-26 03:27:58 +03:00
struct CPack ;
2009-07-20 05:56:35 +03:00
2010-12-22 22:14:40 +02:00
class IBattleCallback
2009-04-16 14:14:13 +03:00
{
public :
2009-08-04 02:53:18 +03:00
bool waitTillRealize ; //if true, request functions will return after they are realized by server
2011-07-05 22:05:41 +03:00
bool unlockGsWhenWaiting ; //if true after sending each request, gs mutex will be unlocked so the changes can be applied; NOTICE caller must have gs mx locked prior to any call to actiob callback!
2010-12-22 22:14:40 +02:00
//battle
virtual int battleMakeAction ( BattleAction * action ) = 0 ; //for casting spells by hero - DO NOT use it for moving active stack
2011-02-12 18:12:48 +02:00
virtual bool battleMakeTacticAction ( BattleAction * action ) = 0 ; // performs tactic phase actions
2010-12-22 22:14:40 +02:00
} ;
2011-05-03 06:14:18 +03:00
class IGameActionCallback
2010-12-22 22:14:40 +02:00
{
public :
2009-08-03 22:22:05 +03:00
//hero
2009-08-04 02:53:18 +03:00
virtual bool moveHero ( const CGHeroInstance * h , int3 dst ) = 0 ; //dst must be free, neighbouring tile (this function can move hero only by one tile)
2009-08-03 22:22:05 +03:00
virtual bool dismissHero ( const CGHeroInstance * hero ) = 0 ; //dismisses given hero; true - successfuly, false - not successfuly
2011-05-03 06:14:18 +03:00
virtual void dig ( const CGObjectInstance * hero ) = 0 ;
2013-02-11 02:24:57 +03:00
virtual void castSpell ( const CGHeroInstance * hero , SpellID spellID , const int3 & pos = int3 ( - 1 , - 1 , - 1 ) ) = 0 ; //cast adventure map spell
2011-05-03 06:14:18 +03:00
2009-08-03 22:22:05 +03:00
//town
2010-07-09 02:03:27 +03:00
virtual void recruitHero ( const CGObjectInstance * townOrTavern , const CGHeroInstance * hero ) = 0 ;
2009-08-03 22:22:05 +03:00
virtual bool buildBuilding ( const CGTownInstance * town , si32 buildingID ) = 0 ;
2013-02-11 02:24:57 +03:00
virtual void recruitCreatures ( const CGObjectInstance * obj , CreatureID ID , ui32 amount , si32 level = - 1 ) = 0 ;
virtual bool upgradeCreature ( const CArmedInstance * obj , int stackPos , CreatureID newID = CreatureID : : NONE ) = 0 ; //if newID==-1 then best possible upgrade will be made
2009-08-03 22:22:05 +03:00
virtual void swapGarrisonHero ( const CGTownInstance * town ) = 0 ;
2011-05-03 06:14:18 +03:00
2013-02-04 22:43:16 +03:00
virtual void trade ( const CGObjectInstance * market , EMarketMode : : EMarketMode mode , int id1 , int id2 , int val1 , const CGHeroInstance * hero = NULL ) = 0 ; //mode==0: sell val1 units of id1 resource for id2 resiurce
2011-05-03 06:14:18 +03:00
2012-07-15 18:34:00 +03:00
virtual int selectionMade ( int selection , int queryID ) = 0 ;
2011-05-03 06:14:18 +03:00
virtual int swapCreatures ( const CArmedInstance * s1 , const CArmedInstance * s2 , int p1 , int p2 ) = 0 ; //swaps creatures between two possibly different garrisons // TODO: AI-unsafe code - fix it!
virtual int mergeStacks ( const CArmedInstance * s1 , const CArmedInstance * s2 , int p1 , int p2 ) = 0 ; //joins first stack to the second (creatures must be same type)
2012-03-11 04:26:11 +03:00
virtual int mergeOrSwapStacks ( const CArmedInstance * s1 , const CArmedInstance * s2 , int p1 , int p2 ) = 0 ; //first goes to the second
2009-04-16 14:14:13 +03:00
virtual int splitStack ( const CArmedInstance * s1 , const CArmedInstance * s2 , int p1 , int p2 , int val ) = 0 ; //split creatures from the first stack
2012-01-30 19:07:52 +03:00
//virtual bool swapArtifacts(const CGHeroInstance * hero1, ui16 pos1, const CGHeroInstance * hero2, ui16 pos2)=0; //swaps artifacts between two given heroes
2012-04-14 05:20:22 +03:00
virtual bool swapArtifacts ( const ArtifactLocation & l1 , const ArtifactLocation & l2 ) = 0 ;
2013-02-07 02:24:43 +03:00
virtual bool assembleArtifacts ( const CGHeroInstance * hero , ArtifactPosition : : ArtifactPosition artifactSlot , bool assemble , ui32 assembleTo ) = 0 ;
2009-04-16 14:14:13 +03:00
virtual bool dismissCreature ( const CArmedInstance * obj , int stackPos ) = 0 ;
virtual void endTurn ( ) = 0 ;
2013-02-11 02:24:57 +03:00
virtual void buyArtifact ( const CGHeroInstance * hero , ArtifactID aid ) = 0 ; //used to buy artifacts in towns (including spell book in the guild and war machines in blacksmith)
2009-04-16 14:14:13 +03:00
virtual void setFormation ( const CGHeroInstance * hero , bool tight ) = 0 ;
virtual void setSelection ( const CArmedInstance * obj ) = 0 ;
2009-08-03 22:22:05 +03:00
2011-05-03 06:14:18 +03:00
2009-04-16 14:14:13 +03:00
virtual void save ( const std : : string & fname ) = 0 ;
virtual void sendMessage ( const std : : string & mess ) = 0 ;
2009-07-26 06:33:13 +03:00
virtual void buildBoat ( const IShipyard * obj ) = 0 ;
2009-04-16 14:14:13 +03:00
} ;
2011-08-30 09:36:57 +03:00
struct CPack ;
2012-08-26 12:07:48 +03:00
class CBattleCallback : public IBattleCallback , public CPlayerBattleCallback
2009-04-16 14:14:13 +03:00
{
2010-12-22 22:14:40 +02:00
protected :
2012-07-15 18:34:00 +03:00
int sendRequest ( const CPack * request ) ; //returns requestID (that'll be matched to requestID in PackageApplied)
2009-04-16 14:14:13 +03:00
CClient * cl ;
2011-05-03 06:14:18 +03:00
//virtual bool hasAccess(int playerId) const;
2010-12-22 22:14:40 +02:00
public :
2013-02-11 17:42:09 +03:00
CBattleCallback ( CGameState * GS , boost : : optional < TPlayerColor > Player , CClient * C ) ;
2011-01-07 12:48:31 +02:00
int battleMakeAction ( BattleAction * action ) OVERRIDE ; //for casting spells by hero - DO NOT use it for moving active stack
2011-02-12 18:12:48 +02:00
bool battleMakeTacticAction ( BattleAction * action ) OVERRIDE ; // performs tactic phase actions
2012-07-15 18:34:00 +03:00
2011-02-06 19:26:27 +02:00
friend class CCallback ;
friend class CClient ;
2010-12-22 22:14:40 +02:00
} ;
2011-05-03 06:14:18 +03:00
class CCallback : public CPlayerSpecificInfoCallback , public IGameActionCallback , public CBattleCallback
2010-12-22 22:14:40 +02:00
{
private :
2012-02-26 21:31:59 +03:00
void validatePaths ( ) ; //recalcualte paths if necessary
2009-04-16 14:14:13 +03:00
public :
2013-02-11 17:42:09 +03:00
CCallback ( CGameState * GS , boost : : optional < TPlayerColor > Player , CClient * C ) ;
2012-03-06 19:59:55 +03:00
2011-05-30 02:49:25 +03:00
//client-specific functionalities (pathfinding)
2011-05-03 06:14:18 +03:00
virtual const CGPathNode * getPathInfo ( int3 tile ) ; //uses main, client pathfinder info
virtual bool getPath2 ( int3 dest , CGPath & ret ) ; //uses main, client pathfinder info
2012-02-26 21:31:59 +03:00
2011-05-03 06:14:18 +03:00
virtual void calculatePaths ( const CGHeroInstance * hero , CPathsInfo & out , int3 src = int3 ( - 1 , - 1 , - 1 ) , int movement = - 1 ) ;
virtual void recalculatePaths ( ) ; //updates main, client pathfinder info (should be called when moving hero is over)
2012-07-15 18:34:00 +03:00
2011-05-30 02:49:25 +03:00
void unregisterMyInterface ( ) ; //stops delivering information about game events to that player's interface -> can be called ONLY after victory/loss
2009-04-16 14:14:13 +03:00
//commands
2009-08-04 02:53:18 +03:00
bool moveHero ( const CGHeroInstance * h , int3 dst ) ; //dst must be free, neighbouring tile (this function can move hero only by one tile)
2010-06-30 22:27:35 +03:00
bool teleportHero ( const CGHeroInstance * who , const CGTownInstance * where ) ;
2012-07-15 18:34:00 +03:00
int selectionMade ( int selection , int queryID ) ;
2009-04-16 14:14:13 +03:00
int swapCreatures ( const CArmedInstance * s1 , const CArmedInstance * s2 , int p1 , int p2 ) ;
2012-03-11 04:26:11 +03:00
int mergeOrSwapStacks ( const CArmedInstance * s1 , const CArmedInstance * s2 , int p1 , int p2 ) ; //first goes to the second
2009-04-16 14:14:13 +03:00
int mergeStacks ( const CArmedInstance * s1 , const CArmedInstance * s2 , int p1 , int p2 ) ; //first goes to the second
int splitStack ( const CArmedInstance * s1 , const CArmedInstance * s2 , int p1 , int p2 , int val ) ;
bool dismissHero ( const CGHeroInstance * hero ) ;
2012-01-30 19:07:52 +03:00
//bool swapArtifacts(const CGHeroInstance * hero1, ui16 pos1, const CGHeroInstance * hero2, ui16 pos2);
2012-04-14 05:20:22 +03:00
bool swapArtifacts ( const ArtifactLocation & l1 , const ArtifactLocation & l2 ) ;
2012-01-30 19:07:52 +03:00
//bool moveArtifact(const CGHeroInstance * hero, ui16 src, const CStackInstance * stack, ui16 dest); // TODO: unify classes
//bool moveArtifact(const CStackInstance * stack, ui16 src , const CGHeroInstance * hero, ui16 dest); // TODO: unify classes
2013-02-07 02:24:43 +03:00
bool assembleArtifacts ( const CGHeroInstance * hero , ArtifactPosition : : ArtifactPosition artifactSlot , bool assemble , ui32 assembleTo ) ;
2009-04-16 14:14:13 +03:00
bool buildBuilding ( const CGTownInstance * town , si32 buildingID ) ;
2013-02-11 02:24:57 +03:00
void recruitCreatures ( const CGObjectInstance * obj , CreatureID ID , ui32 amount , si32 level = - 1 ) ;
2009-04-16 14:14:13 +03:00
bool dismissCreature ( const CArmedInstance * obj , int stackPos ) ;
2013-02-11 02:24:57 +03:00
bool upgradeCreature ( const CArmedInstance * obj , int stackPos , CreatureID newID = CreatureID : : NONE ) OVERRIDE ;
2009-04-16 14:14:13 +03:00
void endTurn ( ) ;
void swapGarrisonHero ( const CGTownInstance * town ) ;
2013-02-11 02:24:57 +03:00
void buyArtifact ( const CGHeroInstance * hero , ArtifactID aid ) OVERRIDE ;
2013-02-04 22:43:16 +03:00
void trade ( const CGObjectInstance * market , EMarketMode : : EMarketMode mode , int id1 , int id2 , int val1 , const CGHeroInstance * hero = NULL ) ;
2009-04-16 14:14:13 +03:00
void setFormation ( const CGHeroInstance * hero , bool tight ) ;
void setSelection ( const CArmedInstance * obj ) ;
2010-07-09 02:03:27 +03:00
void recruitHero ( const CGObjectInstance * townOrTavern , const CGHeroInstance * hero ) ;
2009-04-16 14:14:13 +03:00
void save ( const std : : string & fname ) ;
void sendMessage ( const std : : string & mess ) ;
2009-07-26 06:33:13 +03:00
void buildBoat ( const IShipyard * obj ) ;
2010-02-21 17:03:30 +02:00
void dig ( const CGObjectInstance * hero ) ;
2013-02-11 02:24:57 +03:00
void castSpell ( const CGHeroInstance * hero , SpellID spellID , const int3 & pos = int3 ( - 1 , - 1 , - 1 ) ) ;
2009-04-16 14:14:13 +03:00
//friends
friend class CClient ;
} ;