2009-04-15 17:03:31 +03:00
/*
* IGameCallback . 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
*
*/
2017-07-13 10:26:03 +02:00
# pragma once
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
# include <vcmi/Metatype.h>
2017-07-13 10:26:03 +02:00
# include "CGameInfoCallback.h" // for CGameInfoCallback
# include "CRandomGenerator.h"
2009-04-15 17:03:31 +03:00
2022-07-26 15:07:42 +02:00
VCMI_LIB_NAMESPACE_BEGIN
2014-04-20 10:13:37 +03:00
struct SetMovePoints ;
2009-02-04 15:40:54 +02:00
struct GiveBonus ;
2009-04-11 04:32:50 +03:00
struct BlockingDialog ;
2015-03-08 15:52:50 +02:00
struct TeleportDialog ;
2008-12-27 03:01:59 +02:00
struct MetaString ;
struct ShowInInfobox ;
2010-11-27 03:46:19 +02:00
struct StackLocation ;
2010-12-26 16:34:11 +02:00
struct ArtifactLocation ;
2011-05-10 01:20:47 +03:00
class CCreatureSet ;
class CStackBasicDescriptor ;
2011-05-28 04:02:28 +03:00
class CGCreature ;
2014-04-20 10:13:37 +03:00
struct ShashInt3 ;
2022-09-21 18:31:14 +02:00
# if SCRIPTING_ENABLED
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
namespace scripting
{
class Pool ;
}
2022-09-21 18:31:14 +02:00
# endif
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
2018-02-10 20:52:23 +02:00
class DLL_LINKAGE CPrivilegedInfoCallback : public CGameInfoCallback
2014-04-20 10:13:37 +03:00
{
public :
2022-12-30 16:51:13 +02:00
enum class MapTerrainFilterMode
{
NONE = 0 ,
LAND = 1 ,
WATER = 2 ,
LAND_CARTOGRAPHER = 3 ,
UNDERGROUND_CARTOGRAPHER = 4
} ;
CGameState * gameState ( ) ;
//used for random spawns
void getFreeTiles ( std : : vector < int3 > & tiles ) const ;
//mode 1 - only unrevealed tiles; mode 0 - all, mode -1 - only revealed
void getTilesInRange ( std : : unordered_set < int3 , ShashInt3 > & tiles , int3 pos , int radious ,
boost : : optional < PlayerColor > player = boost : : optional < PlayerColor > ( ) , int mode = 0 ,
int3 : : EDistanceFormula formula = int3 : : DIST_2D ) const ;
//returns all tiles on given level (-1 - both levels, otherwise number of level)
void getAllTiles ( std : : unordered_set < int3 , ShashInt3 > & tiles , boost : : optional < PlayerColor > player = boost : : optional < PlayerColor > ( ) ,
int level = - 1 , MapTerrainFilterMode tileFilterMode = MapTerrainFilterMode : : NONE ) const ;
void pickAllowedArtsSet ( std : : vector < const CArtifact * > & out ,
CRandomGenerator & rand ) ; //gives 3 treasures, 3 minors, 1 major -> used by Black Market and Artifact Merchant
2014-04-20 10:13:37 +03:00
void getAllowedSpells ( std : : vector < SpellID > & out , ui16 level ) ;
template < typename Saver >
void saveCommonState ( Saver & out ) const ; //stores GS and VLC
template < typename Loader >
void loadCommonState ( Loader & in ) ; //loads GS and VLC
} ;
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
class DLL_LINKAGE IGameEventCallback
2014-04-20 10:13:37 +03:00
{
public :
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
virtual void setObjProperty ( ObjectInstanceID objid , int prop , si64 val ) = 0 ;
virtual void showInfoDialog ( InfoWindow * iw ) = 0 ;
virtual void showInfoDialog ( const std : : string & msg , PlayerColor player ) = 0 ;
2014-04-20 10:13:37 +03:00
virtual void changeSpells ( const CGHeroInstance * hero , bool give , const std : : set < SpellID > & spells ) = 0 ;
virtual bool removeObject ( const CGObjectInstance * obj ) = 0 ;
virtual void setOwner ( const CGObjectInstance * objid , PlayerColor owner ) = 0 ;
virtual void changePrimSkill ( const CGHeroInstance * hero , PrimarySkill : : PrimarySkill which , si64 val , bool abs = false ) = 0 ;
2016-11-13 12:38:42 +02:00
virtual void changeSecSkill ( const CGHeroInstance * hero , SecondarySkill which , int val , bool abs = false ) = 0 ;
2014-04-20 10:13:37 +03:00
virtual void showBlockingDialog ( BlockingDialog * iw ) = 0 ;
virtual void showGarrisonDialog ( ObjectInstanceID upobj , ObjectInstanceID hid , bool removableUnits ) = 0 ; //cb will be called when player closes garrison window
2015-03-08 15:52:50 +02:00
virtual void showTeleportDialog ( TeleportDialog * iw ) = 0 ;
2014-04-20 10:13:37 +03:00
virtual void showThievesGuildWindow ( PlayerColor player , ObjectInstanceID requestingObjId ) = 0 ;
virtual void giveResource ( PlayerColor player , Res : : ERes which , int val ) = 0 ;
virtual void giveResources ( PlayerColor player , TResources resources ) = 0 ;
virtual void giveCreatures ( const CArmedInstance * objid , const CGHeroInstance * h , const CCreatureSet & creatures , bool remove ) = 0 ;
virtual void takeCreatures ( ObjectInstanceID objid , const std : : vector < CStackBasicDescriptor > & creatures ) = 0 ;
virtual bool changeStackCount ( const StackLocation & sl , TQuantity count , bool absoluteValue = false ) = 0 ;
2015-09-04 17:08:25 +02:00
virtual bool changeStackType ( const StackLocation & sl , const CCreature * c ) = 0 ;
2014-04-20 10:13:37 +03:00
virtual bool insertNewStack ( const StackLocation & sl , const CCreature * c , TQuantity count = - 1 ) = 0 ; //count -1 => moves whole stack
virtual bool eraseStack ( const StackLocation & sl , bool forceRemoval = false ) = 0 ;
virtual bool swapStacks ( const StackLocation & sl1 , const StackLocation & sl2 ) = 0 ;
virtual bool addToSlot ( const StackLocation & sl , const CCreature * c , TQuantity count ) = 0 ; //makes new stack or increases count of already existing
virtual void tryJoiningArmy ( const CArmedInstance * src , const CArmedInstance * dst , bool removeObjWhenFinished , bool allowMerging ) = 0 ; //merges army from src do dst or opens a garrison window
virtual bool moveStack ( const StackLocation & src , const StackLocation & dst , TQuantity count ) = 0 ;
virtual void removeAfterVisit ( const CGObjectInstance * object ) = 0 ; //object will be destroyed when interaction is over. Do not call when interaction is not ongoing!
virtual void giveHeroNewArtifact ( const CGHeroInstance * h , const CArtifact * artType , ArtifactPosition pos ) = 0 ;
virtual void giveHeroArtifact ( const CGHeroInstance * h , const CArtifactInstance * a , ArtifactPosition pos ) = 0 ; //pos==-1 - first free slot in backpack=0; pos==-2 - default if available or backpack
virtual void putArtifact ( const ArtifactLocation & al , const CArtifactInstance * a ) = 0 ;
virtual void removeArtifact ( const ArtifactLocation & al ) = 0 ;
virtual bool moveArtifact ( const ArtifactLocation & al1 , const ArtifactLocation & al2 ) = 0 ;
virtual void showCompInfo ( ShowInInfobox * comp ) = 0 ;
virtual void heroVisitCastle ( const CGTownInstance * obj , const CGHeroInstance * hero ) = 0 ;
2020-09-28 00:32:33 +02:00
virtual void visitCastleObjects ( const CGTownInstance * obj , const CGHeroInstance * hero ) = 0 ;
2014-04-20 10:13:37 +03:00
virtual void stopHeroVisitCastle ( const CGTownInstance * obj , const CGHeroInstance * hero ) = 0 ;
virtual void startBattlePrimary ( const CArmedInstance * army1 , const CArmedInstance * army2 , int3 tile , const CGHeroInstance * hero1 , const CGHeroInstance * hero2 , bool creatureBank = false , const CGTownInstance * town = nullptr ) = 0 ; //use hero=nullptr for no hero
virtual void startBattleI ( const CArmedInstance * army1 , const CArmedInstance * army2 , int3 tile , bool creatureBank = false ) = 0 ; //if any of armies is hero, hero will be used
virtual void startBattleI ( const CArmedInstance * army1 , const CArmedInstance * army2 , bool creatureBank = false ) = 0 ; //if any of armies is hero, hero will be used, visitable tile of second obj is place of battle
2015-03-08 16:04:09 +02:00
virtual bool moveHero ( ObjectInstanceID hid , int3 dst , ui8 teleporting , bool transit = false , PlayerColor asker = PlayerColor : : NEUTRAL ) = 0 ;
2021-09-12 13:30:54 +02:00
virtual bool swapGarrisonOnSiege ( ObjectInstanceID tid ) = 0 ;
2014-04-20 10:13:37 +03:00
virtual void giveHeroBonus ( GiveBonus * bonus ) = 0 ;
virtual void setMovePoints ( SetMovePoints * smp ) = 0 ;
virtual void setManaPoints ( ObjectInstanceID hid , int val ) = 0 ;
virtual void giveHero ( ObjectInstanceID id , PlayerColor player ) = 0 ;
2023-02-16 21:35:15 +02:00
virtual void changeObjPos ( ObjectInstanceID objid , int3 newPos ) = 0 ;
2018-02-25 18:16:15 +02:00
virtual void sendAndApply ( CPackForClient * pack ) = 0 ;
2014-04-20 10:13:37 +03:00
virtual void heroExchange ( ObjectInstanceID hero1 , ObjectInstanceID hero2 ) = 0 ; //when two heroes meet on adventure map
2014-06-24 14:50:27 +03:00
virtual void changeFogOfWar ( int3 center , ui32 radius , PlayerColor player , bool hide ) = 0 ;
virtual void changeFogOfWar ( std : : unordered_set < int3 , ShashInt3 > & tiles , PlayerColor player , bool hide ) = 0 ;
2014-04-20 10:13:37 +03:00
} ;
2018-02-10 20:52:23 +02:00
class DLL_LINKAGE CNonConstInfoCallback : public CPrivilegedInfoCallback
2014-04-20 10:13:37 +03:00
{
public :
2022-12-07 21:50:45 +02:00
//keep const version of callback accessible
using CGameInfoCallback : : getPlayerState ;
using CGameInfoCallback : : getTeam ;
using CGameInfoCallback : : getPlayerTeam ;
using CGameInfoCallback : : getHero ;
using CGameInfoCallback : : getTown ;
using CGameInfoCallback : : getTile ;
using CGameInfoCallback : : getArtInstance ;
using CGameInfoCallback : : getObjInstance ;
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
PlayerState * getPlayerState ( PlayerColor color , bool verbose = true ) ;
2014-04-20 10:13:37 +03:00
TeamState * getTeam ( TeamID teamID ) ; //get team by team ID
TeamState * getPlayerTeam ( PlayerColor color ) ; // get team by player color
CGHeroInstance * getHero ( ObjectInstanceID objid ) ;
CGTownInstance * getTown ( ObjectInstanceID objid ) ;
TerrainTile * getTile ( int3 pos ) ;
CArtifactInstance * getArtInstance ( ArtifactInstanceID aid ) ;
CGObjectInstance * getObjInstance ( ObjectInstanceID oid ) ;
2018-03-10 23:19:36 +02:00
CArmedInstance * getArmyInstance ( ObjectInstanceID oid ) ;
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
virtual void updateEntity ( Metatype metatype , int32_t index , const JsonNode & data ) = 0 ;
2014-04-20 10:13:37 +03:00
} ;
2011-05-22 21:46:52 +03:00
/// Interface class for handling general game logic and actions
2018-02-10 20:52:23 +02:00
class DLL_LINKAGE IGameCallback : public CPrivilegedInfoCallback , public IGameEventCallback
2011-05-22 21:46:52 +03:00
{
public :
virtual ~ IGameCallback ( ) { } ;
2022-09-21 18:31:14 +02:00
# if SCRIPTING_ENABLED
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
virtual scripting : : Pool * getGlobalContextPool ( ) const = 0 ;
2022-09-21 18:31:14 +02:00
# endif
2009-03-14 13:25:25 +02:00
2013-05-28 00:46:04 +03:00
//get info
virtual bool isVisitCoveredByAnotherQuery ( const CGObjectInstance * obj , const CGHeroInstance * hero ) ;
2009-09-21 12:00:33 +03:00
friend struct CPack ;
2009-03-07 00:25:19 +02:00
friend struct CPackForClient ;
2009-03-09 12:37:49 +02:00
friend struct CPackForServer ;
2008-12-27 03:01:59 +02:00
} ;
2014-04-19 20:44:21 +03:00
2022-07-26 15:07:42 +02:00
VCMI_LIB_NAMESPACE_END