2009-04-15 17:03:31 +03:00
/*
* CGameInterface . 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
*/
2017-07-13 10:26:03 +02:00
# pragma once
# include "battle/BattleAction.h"
# include "IGameEventsReceiver.h"
# include "CGameStateFwd.h"
# include "spells/ViewSpellInt.h"
# include "mapObjects/CObjectHandler.h"
2009-04-16 14:14:13 +03:00
2013-11-07 15:48:41 +03:00
using boost : : logic : : tribool ;
2009-04-16 14:14:13 +03:00
class CCallback ;
2012-09-20 19:55:21 +03:00
class CBattleCallback ;
2009-04-16 14:14:13 +03:00
class ICallback ;
class CGlobalAI ;
2010-02-10 04:56:00 +02:00
struct Component ;
2009-04-16 14:14:13 +03:00
class CSelectableComponent ;
2009-07-03 22:57:14 +03:00
struct TryMoveHero ;
2009-04-16 14:14:13 +03:00
class CGHeroInstance ;
class CGTownInstance ;
class CGObjectInstance ;
2010-06-27 19:03:01 +03:00
class CGBlackMarket ;
2009-07-06 22:41:27 +03:00
class CGDwelling ;
2009-04-16 14:14:13 +03:00
class CCreatureSet ;
class CArmedInstance ;
2009-07-26 06:33:13 +03:00
class IShipyard ;
2010-05-18 10:01:54 +03:00
class IMarket ;
2009-04-16 14:14:13 +03:00
struct BattleResult ;
struct BattleAttack ;
struct BattleStackAttacked ;
2010-05-16 16:42:19 +03:00
struct BattleSpellCast ;
2009-04-16 14:14:13 +03:00
struct SetStackEffect ;
2010-05-02 21:20:26 +03:00
struct Bonus ;
2009-04-16 14:14:13 +03:00
struct PackageApplied ;
2009-07-30 15:49:45 +03:00
struct SetObjectProperty ;
2009-09-01 16:54:13 +03:00
struct CatapultAttack ;
2010-12-14 23:55:23 +02:00
struct StackLocation ;
class CStackInstance ;
2012-05-16 20:29:05 +03:00
class CCommanderInstance ;
2010-12-23 22:18:10 +02:00
class CStack ;
2016-08-30 04:13:45 +02:00
struct CPathsInfo ;
2010-12-14 23:55:23 +02:00
class CCreature ;
2009-04-16 14:14:13 +03:00
class CLoadFile ;
class CSaveFile ;
2016-09-10 02:32:40 +02:00
class BinaryDeserializer ;
class BinarySerializer ;
2011-01-06 22:00:19 +02:00
struct ArtifactLocation ;
2011-06-20 14:41:04 +03:00
class CScriptingModule ;
2009-04-16 14:14:13 +03:00
2013-05-09 14:09:23 +03:00
class DLL_LINKAGE CBattleGameInterface : public IBattleEventsReceiver
2009-04-16 14:14:13 +03:00
{
public :
bool human ;
2013-03-03 20:06:03 +03:00
PlayerColor playerID ;
2009-04-16 14:14:13 +03:00
std : : string dllName ;
2010-12-22 22:14:40 +02:00
virtual ~ CBattleGameInterface ( ) { } ;
2015-12-29 04:43:33 +02:00
virtual void init ( std : : shared_ptr < CBattleCallback > CB ) { } ;
2010-12-22 22:14:40 +02:00
//battle call-ins
2010-12-23 22:18:10 +02:00
virtual BattleAction activeStack ( const CStack * stack ) = 0 ; //called when it's turn of that stack
2011-08-25 18:24:37 +03:00
virtual void yourTacticPhase ( int distance ) { } ; //called when interface has opportunity to use Tactics skill -> use cb->battleMakeTacticAction from this function
2013-05-09 14:09:23 +03:00
2016-09-10 02:32:40 +02:00
virtual void saveGame ( BinarySerializer & h , const int version ) ;
virtual void loadGame ( BinaryDeserializer & h , const int version ) ;
2013-05-09 14:09:23 +03:00
2010-12-22 22:14:40 +02:00
} ;
2011-02-22 13:52:36 +02:00
/// Central class for managing human player / AI interface logic
2014-09-21 16:42:08 +03:00
class DLL_LINKAGE CGameInterface : public CBattleGameInterface , public IGameEventsReceiver
2010-12-22 22:14:40 +02:00
{
public :
2016-10-22 16:22:00 +02:00
virtual ~ CGameInterface ( ) = default ;
2015-12-29 04:43:33 +02:00
virtual void init ( std : : shared_ptr < CCallback > CB ) { } ;
2011-07-17 21:49:05 +03:00
virtual void yourTurn ( ) { } ; //called AFTER playerStartsTurn(player)
2012-06-27 23:44:01 +03:00
//pskill is gained primary skill, interface has to choose one of given skills and call callback with selection id
2013-05-27 13:53:28 +03:00
virtual void heroGotLevel ( const CGHeroInstance * hero , PrimarySkill : : PrimarySkill pskill , std : : vector < SecondarySkill > & skills , QueryID queryID ) = 0 ;
virtual void commanderGotLevel ( const CCommanderInstance * commander , std : : vector < ui32 > skills , QueryID queryID ) = 0 ;
2012-06-27 23:44:01 +03:00
// Show a dialog, player must take decision. If selection then he has to choose between one of given components,
// if cancel he is allowed to not choose. After making choice, CCallback::selectionMade should be called
// with number of selected component (1 - n) or 0 for cancel (if allowed) and askID.
2013-05-27 13:53:28 +03:00
virtual void showBlockingDialog ( const std : : string & text , const std : : vector < Component > & components , QueryID askID , const int soundID , bool selection , bool cancel ) = 0 ;
2012-06-27 23:44:01 +03:00
// all stacks operations between these objects become allowed, interface has to call onEnd when done
2013-05-27 13:53:28 +03:00
virtual void showGarrisonDialog ( const CArmedInstance * up , const CGHeroInstance * down , bool removableUnits , QueryID queryID ) = 0 ;
2015-11-28 01:41:30 +02:00
virtual void showTeleportDialog ( TeleportChannelID channel , TTeleportExitsList exits , bool impassable , QueryID askID ) = 0 ;
2017-06-06 06:53:51 +02:00
virtual void showMapObjectSelectDialog ( QueryID askID , const Component & icon , const MetaString & title , const MetaString & description , const std : : vector < ObjectInstanceID > & objects ) = 0 ;
2012-02-22 16:41:27 +03:00
virtual void finish ( ) { } ; //if for some reason we want to end
2016-08-30 04:13:45 +02:00
2015-02-26 16:15:17 +02:00
virtual void showWorldViewEx ( const std : : vector < ObjectPosInfo > & objectPositions ) { } ;
2009-04-16 14:14:13 +03:00
} ;
2010-12-22 22:14:40 +02:00
2011-12-14 00:23:17 +03:00
class DLL_LINKAGE CDynLibHandler
2009-04-16 14:14:13 +03:00
{
public :
2015-12-29 04:43:33 +02:00
static std : : shared_ptr < CGlobalAI > getNewAI ( std : : string dllname ) ;
static std : : shared_ptr < CBattleGameInterface > getNewBattleAI ( std : : string dllname ) ;
static std : : shared_ptr < CScriptingModule > getNewScriptingModule ( std : : string dllname ) ;
2009-04-16 14:14:13 +03:00
} ;
2011-06-20 14:41:04 +03:00
2011-12-14 00:23:17 +03:00
class DLL_LINKAGE CGlobalAI : public CGameInterface // AI class (to derivate)
2009-04-16 14:14:13 +03:00
{
public :
2011-07-05 09:14:07 +03:00
CGlobalAI ( ) ;
2013-06-26 14:18:27 +03:00
virtual BattleAction activeStack ( const CStack * stack ) override ;
2009-04-16 14:14:13 +03:00
} ;
2011-07-05 09:14:07 +03:00
//class to be inherited by adventure-only AIs, it cedes battle actions to given battle-AI
2011-12-14 00:23:17 +03:00
class DLL_LINKAGE CAdventureAI : public CGlobalAI
2011-07-05 09:14:07 +03:00
{
public :
2013-06-23 22:35:54 +03:00
CAdventureAI ( ) { } ;
2011-07-05 09:14:07 +03:00
2015-12-29 04:43:33 +02:00
std : : shared_ptr < CBattleGameInterface > battleAI ;
std : : shared_ptr < CBattleCallback > cbc ;
2011-07-05 09:14:07 +03:00
2012-09-29 13:59:43 +03:00
virtual std : : string getBattleAIName ( ) const = 0 ; //has to return name of the battle AI to be used
2011-07-05 09:14:07 +03:00
//battle interface
2015-10-12 15:47:10 +02:00
virtual BattleAction activeStack ( const CStack * stack ) override ;
virtual void yourTacticPhase ( int distance ) override ;
virtual void battleNewRound ( int round ) override ;
virtual void battleCatapultAttacked ( const CatapultAttack & ca ) override ;
virtual void battleStart ( const CCreatureSet * army1 , const CCreatureSet * army2 , int3 tile , const CGHeroInstance * hero1 , const CGHeroInstance * hero2 , bool side ) override ;
2017-07-20 06:08:49 +02:00
virtual void battleStacksAttacked ( const std : : vector < BattleStackAttacked > & bsa , const std : : vector < MetaString > & battleLog ) override ;
2015-10-12 15:47:10 +02:00
virtual void actionStarted ( const BattleAction & action ) override ;
virtual void battleNewRoundFirst ( int round ) override ;
virtual void actionFinished ( const BattleAction & action ) override ;
virtual void battleStacksEffectsSet ( const SetStackEffect & sse ) override ;
2017-07-20 06:08:49 +02:00
virtual void battleObstaclesChanged ( const std : : vector < ObstacleChanges > & obstacles ) override ;
2015-10-12 15:47:10 +02:00
virtual void battleStackMoved ( const CStack * stack , std : : vector < BattleHex > dest , int distance ) override ;
virtual void battleAttack ( const BattleAttack * ba ) override ;
virtual void battleSpellCast ( const BattleSpellCast * sc ) override ;
virtual void battleEnd ( const BattleResult * br ) override ;
2017-07-20 06:08:49 +02:00
virtual void battleUnitsChanged ( const std : : vector < UnitChanges > & units , const std : : vector < CustomEffectInfo > & customEffects , const std : : vector < MetaString > & battleLog ) override ;
2015-10-12 15:47:10 +02:00
2016-09-10 02:32:40 +02:00
virtual void saveGame ( BinarySerializer & h , const int version ) override ; //saving
virtual void loadGame ( BinaryDeserializer & h , const int version ) override ; //loading
2011-07-05 09:14:07 +03:00
} ;