2017-07-13 10:26:03 +02:00
/*
* CPlayerInterface . 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
*
*/
2011-12-14 00:23:17 +03:00
# pragma once
2013-11-30 13:08:38 +03:00
# include "../lib/FunctionList.h"
2011-12-14 00:23:17 +03:00
# include "../lib/CGameInterface.h"
2013-04-07 14:52:07 +03:00
# include "gui/CIntObject.h"
2009-02-20 15:06:20 +02:00
2022-07-26 15:07:42 +02:00
VCMI_LIB_NAMESPACE_BEGIN
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 Artifact ;
2009-07-03 22:57:14 +03:00
struct TryMoveHero ;
2009-02-20 15:06:20 +02:00
class CGHeroInstance ;
class CStack ;
class CCreature ;
2009-09-07 05:29:44 +03:00
struct CGPath ;
2009-02-20 15:06:20 +02:00
class CCreatureSet ;
class CGObjectInstance ;
struct UpgradeInfo ;
template < typename T > struct CondSh ;
2022-07-26 15:07:42 +02:00
struct CPathsInfo ;
VCMI_LIB_NAMESPACE_END
class CButton ;
2023-05-08 14:18:34 +02:00
class AdventureMapInterface ;
2022-07-26 15:07:42 +02:00
class CCastleInterface ;
2022-12-09 13:26:17 +02:00
class BattleInterface ;
2022-07-26 15:07:42 +02:00
class CComponent ;
class CSelectableComponent ;
class CSlider ;
2009-04-03 18:55:26 +03:00
class CInGameConsole ;
2009-05-19 21:23:04 +03:00
class CInfoWindow ;
2011-12-17 21:59:59 +03:00
class IShowActivatable ;
2009-05-19 21:23:04 +03:00
class ClickableL ;
class ClickableR ;
class Hoverable ;
class KeyInterested ;
class MotionInterested ;
2023-04-17 01:02:31 +02:00
class PlayerLocalState ;
2009-05-19 21:23:04 +03:00
class TimeInterested ;
2022-07-26 15:07:42 +02:00
2009-02-20 15:06:20 +02:00
namespace boost
{
class mutex ;
class recursive_mutex ;
2012-09-15 22:16:16 +03:00
}
2009-02-20 15:06:20 +02:00
2011-02-22 13:52:36 +02:00
/// Central class for managing user interface logic
2015-06-22 20:53:47 +02:00
class CPlayerInterface : public CGameInterface , public IUpdateable
2009-02-20 15:06:20 +02:00
{
2023-04-17 12:06:58 +02:00
bool duringMovement ;
bool ignoreEvents ;
size_t numOfMovedArts ;
2023-04-17 00:09:25 +02:00
// -1 - just loaded game; 1 - just started game; 0 otherwise
int firstCall ;
int autosaveCount ;
std : : list < std : : shared_ptr < CInfoWindow > > dialogs ; //queue of dialogs awaiting to be shown (not currently shown!)
2023-02-15 12:08:32 +02:00
2015-03-08 16:17:24 +02:00
ObjectInstanceID destinationTeleport ; //contain -1 or object id if teleportation
2015-12-02 16:56:26 +02:00
int3 destinationTeleportPos ;
2010-12-23 02:33:48 +02:00
2023-04-17 00:09:25 +02:00
public : // TODO: make private
std : : shared_ptr < Environment > env ;
2023-04-17 01:02:31 +02:00
std : : unique_ptr < PlayerLocalState > localState ;
2023-04-17 00:09:25 +02:00
2009-02-20 15:06:20 +02:00
//minor interfaces
2009-03-22 18:04:46 +02:00
CondSh < bool > * showingDialog ; //indicates if dialog box is displayed
2009-04-14 15:47:09 +03:00
2011-02-24 15:57:47 +02:00
static boost : : recursive_mutex * pim ;
2009-04-14 15:47:09 +03:00
bool makingTurn ; //if player is already making his turn
2013-06-26 14:18:27 +03:00
CCastleInterface * castleInt ; //nullptr if castle window isn't opened
2022-12-21 17:02:53 +02:00
static std : : shared_ptr < BattleInterface > battleInt ; //nullptr if no battle
2009-08-07 01:36:51 +03:00
CInGameConsole * cingconsole ;
2012-09-15 22:16:16 +03:00
2015-12-29 04:43:33 +02:00
std : : shared_ptr < CCallback > cb ; //to communicate with engine
2009-08-07 01:36:51 +03:00
2013-06-23 14:25:48 +03:00
//During battle is quick combat mode is used
2015-12-29 04:43:33 +02:00
std : : shared_ptr < CBattleGameInterface > autofightingAI ; //AI that makes decisions
2013-06-23 14:25:48 +03:00
bool isAutoFightOn ; //Flag, switch it to stop quick combat. Don't touch if there is no battle interface.
2023-04-17 12:06:58 +02:00
protected : // Call-ins from server, should not be called directly, but only via GameInterface
2014-07-03 21:05:59 +03:00
void update ( ) override ;
2023-04-17 12:06:58 +02:00
void initGameInterface ( std : : shared_ptr < Environment > ENV , std : : shared_ptr < CCallback > CB ) override ;
2009-06-11 20:21:06 +03:00
2018-03-10 23:19:36 +02:00
void garrisonsChanged ( ObjectInstanceID id1 , ObjectInstanceID id2 ) override ;
2013-06-26 14:18:27 +03:00
void buildChanged ( const CGTownInstance * town , BuildingID buildingID , int what ) override ; //what: 1 - built, 2 - demolished
2011-01-06 22:00:19 +02:00
2015-10-12 15:47:10 +02:00
void artifactPut ( const ArtifactLocation & al ) override ;
void artifactRemoved ( const ArtifactLocation & al ) override ;
void artifactMoved ( const ArtifactLocation & src , const ArtifactLocation & dst ) override ;
2023-02-13 21:10:53 +02:00
void bulkArtMovementStart ( size_t numOfArts ) override ;
2015-10-12 15:47:10 +02:00
void artifactAssembled ( const ArtifactLocation & al ) override ;
2023-02-13 21:10:53 +02:00
void askToAssembleArtifact ( const ArtifactLocation & dst ) override ;
2015-10-12 15:47:10 +02:00
void artifactDisassembled ( const ArtifactLocation & al ) override ;
2011-01-06 22:00:19 +02:00
2017-09-13 02:35:58 +02:00
void heroVisit ( const CGHeroInstance * visitor , const CGObjectInstance * visitedObj , bool start ) override ;
2013-06-26 14:18:27 +03:00
void heroCreated ( const CGHeroInstance * hero ) override ;
void heroGotLevel ( const CGHeroInstance * hero , PrimarySkill : : PrimarySkill pskill , std : : vector < SecondarySkill > & skills , QueryID queryID ) override ;
void commanderGotLevel ( const CCommanderInstance * commander , std : : vector < ui32 > skills , QueryID queryID ) override ;
void heroInGarrisonChange ( const CGTownInstance * town ) override ;
2022-01-25 13:19:48 +02:00
void heroMoved ( const TryMoveHero & details , bool verbose = true ) override ;
2013-06-26 14:18:27 +03:00
void heroPrimarySkillChanged ( const CGHeroInstance * hero , int which , si64 val ) override ;
void heroSecondarySkillChanged ( const CGHeroInstance * hero , int which , int val ) override ;
void heroManaPointsChanged ( const CGHeroInstance * hero ) override ;
void heroMovePointsChanged ( const CGHeroInstance * hero ) override ;
void heroVisitsTown ( const CGHeroInstance * hero , const CGTownInstance * town ) override ;
2016-11-26 14:14:43 +02:00
void receivedResource ( ) override ;
2023-03-06 01:30:21 +02:00
void showInfoDialog ( EInfoWindowMode type , const std : : string & text , const std : : vector < Component > & components , int soundID ) override ;
2013-06-26 14:18:27 +03:00
void showRecruitmentDialog ( const CGDwelling * dwelling , const CArmedInstance * dst , int level ) override ;
2016-11-27 21:14:41 +02:00
void showBlockingDialog ( const std : : string & text , const std : : vector < Component > & components , QueryID askID , const int soundID , bool selection , bool cancel ) override ; //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.
2015-12-02 16:56:26 +02:00
void showTeleportDialog ( TeleportChannelID channel , TTeleportExitsList exits , bool impassable , QueryID askID ) override ;
2013-06-26 14:18:27 +03:00
void showGarrisonDialog ( const CArmedInstance * up , const CGHeroInstance * down , bool removableUnits , QueryID queryID ) override ;
2017-06-06 06:53:51 +02:00
void showMapObjectSelectDialog ( QueryID askID , const Component & icon , const MetaString & title , const MetaString & description , const std : : vector < ObjectInstanceID > & objects ) override ;
2013-06-26 14:18:27 +03:00
void showMarketWindow ( const IMarket * market , const CGHeroInstance * visitor ) override ;
void showUniversityWindow ( const IMarket * market , const CGHeroInstance * visitor ) override ;
void showHillFortWindow ( const CGObjectInstance * object , const CGHeroInstance * visitor ) override ;
void advmapSpellCast ( const CGHeroInstance * caster , int spellID ) override ; //called when a hero casts a spell
2023-04-16 00:48:49 +02:00
void tileHidden ( const std : : unordered_set < int3 > & pos ) override ; //called when given tiles become hidden under fog of war
void tileRevealed ( const std : : unordered_set < int3 > & pos ) override ; //called when fog of war disappears from given tiles
2013-06-26 14:18:27 +03:00
void newObject ( const CGObjectInstance * obj ) override ;
void availableArtifactsChanged ( const CGBlackMarket * bm = nullptr ) override ; //bm may be nullptr, then artifacts are changed in the global pool (used by merchants in towns)
void yourTurn ( ) override ;
void availableCreaturesChanged ( const CGDwelling * town ) override ;
void heroBonusChanged ( const CGHeroInstance * hero , const Bonus & bonus , bool gain ) override ; //if gain hero received bonus, else he lost it
void playerBonusChanged ( const Bonus & bonus , bool gain ) override ;
void requestRealized ( PackageApplied * pa ) override ;
void heroExchangeStarted ( ObjectInstanceID hero1 , ObjectInstanceID hero2 , QueryID query ) override ;
void centerView ( int3 pos , int focusTime ) override ;
2023-07-04 19:02:41 +02:00
void beforeObjectPropertyChanged ( const SetObjectProperty * sop ) override ;
2013-06-26 14:18:27 +03:00
void objectPropertyChanged ( const SetObjectProperty * sop ) override ;
void objectRemoved ( const CGObjectInstance * obj ) override ;
2023-02-12 13:02:06 +02:00
void objectRemovedAfter ( ) override ;
2019-05-03 12:01:48 +02:00
void playerBlocked ( int reason , bool start ) override ;
2013-11-17 20:57:04 +03:00
void gameOver ( PlayerColor player , const EVictoryLossCheckResult & victoryLossCheckResult ) override ;
2013-06-26 14:18:27 +03:00
void playerStartsTurn ( PlayerColor player ) override ; //called before yourTurn on active itnerface
2016-09-10 02:32:40 +02:00
void saveGame ( BinarySerializer & h , const int version ) override ; //saving
void loadGame ( BinaryDeserializer & h , const int version ) override ; //loading
2023-02-21 14:38:08 +02:00
void showWorldViewEx ( const std : : vector < ObjectPosInfo > & objectPositions , bool showTerrain ) override ;
2009-03-28 20:46:20 +02:00
2009-02-20 15:06:20 +02:00
//for battles
2013-06-26 14:18:27 +03:00
void actionFinished ( const BattleAction & action ) override ; //occurs AFTER action taken by active stack or by the hero
void actionStarted ( const BattleAction & action ) override ; //occurs BEFORE action taken by active stack or by the hero
2023-07-18 18:55:59 +02:00
void activeStack ( const CStack * stack ) override ; //called when it's turn of that stack
2013-06-26 14:18:27 +03:00
void battleAttack ( const BattleAttack * ba ) override ; //stack performs attack
2023-04-06 17:34:07 +02:00
void battleEnd ( const BattleResult * br , QueryID queryID ) override ; //end of battle
2013-06-26 14:18:27 +03:00
void battleNewRoundFirst ( int round ) override ; //called at the beginning of each turn before changes are applied; used for HP regen handling
void battleNewRound ( int round ) override ; //called at the beginning of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn
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
void battleLogMessage ( const std : : vector < MetaString > & lines ) override ;
2022-12-18 18:26:43 +02:00
void battleStackMoved ( const CStack * stack , std : : vector < BattleHex > dest , int distance , bool teleport ) override ;
2013-06-26 14:18:27 +03:00
void battleSpellCast ( const BattleSpellCast * sc ) override ;
void battleStacksEffectsSet ( const SetStackEffect & sse ) override ; //called when a specific effect is set to stacks
void battleTriggerEffect ( const BattleTriggerEffect & bte ) override ; //various one-shot effect
2022-12-09 13:10:35 +02:00
void battleStacksAttacked ( const std : : vector < BattleStackAttacked > & bsa , bool ranged ) override ;
2013-09-14 22:09:35 +03:00
void battleStartBefore ( const CCreatureSet * army1 , const CCreatureSet * army2 , int3 tile , const CGHeroInstance * hero1 , const CGHeroInstance * hero2 ) override ; //called by engine just before battle starts; side=0 - left, side=1 - right
2023-07-27 17:40:47 +02:00
void battleStart ( const CCreatureSet * army1 , const CCreatureSet * army2 , int3 tile , const CGHeroInstance * hero1 , const CGHeroInstance * hero2 , bool side , bool replayAllowed ) override ; //called by engine when battle starts; side=0 - left, side=1 - right
2022-12-17 17:35:15 +02:00
void battleUnitsChanged ( const std : : vector < UnitChanges > & units ) override ;
2017-07-20 06:08:49 +02:00
void battleObstaclesChanged ( const std : : vector < ObstacleChanges > & obstacles ) override ;
2013-06-26 14:18:27 +03:00
void battleCatapultAttacked ( const CatapultAttack & ca ) override ; //called when catapult makes an attack
2016-02-13 16:40:31 +02:00
void battleGateStateChanged ( const EGateState state ) override ;
2013-06-26 14:18:27 +03:00
void yourTacticPhase ( int distance ) override ;
2023-08-17 18:18:14 +02:00
std : : optional < BattleAction > makeSurrenderRetreatDecision ( const BattleStateInfoForRetreat & battleState ) override ;
2009-02-20 15:06:20 +02:00
2023-04-17 12:06:58 +02:00
public : // public interface for use by client via LOCPLINT access
// part of GameInterface that is also used by client code
void showPuzzleMap ( ) override ;
void viewWorldMap ( ) override ;
void showQuestLog ( ) override ;
void showThievesGuildWindow ( const CGObjectInstance * obj ) override ;
void showTavernWindow ( const CGObjectInstance * townOrTavern ) override ;
void showShipyardDialog ( const IShipyard * obj ) override ; //obj may be town or shipyard;
void showHeroExchange ( ObjectInstanceID hero1 , ObjectInstanceID hero2 ) ;
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
void showArtifactAssemblyDialog ( const Artifact * artifact , const Artifact * assembledArtifact , CFunctionList < bool ( ) > onYes ) ;
2012-04-06 18:02:15 +03:00
void waitWhileDialog ( bool unlockPim = true ) ;
void waitForAllDialogs ( bool unlockPim = true ) ;
2009-02-20 15:06:20 +02:00
void openTownWindow ( const CGTownInstance * town ) ; //shows townscreen
void openHeroWindow ( const CGHeroInstance * hero ) ; //shows hero window with given hero
2013-11-30 12:43:31 +03:00
2018-04-07 13:34:11 +02:00
void showInfoDialog ( const std : : string & text , std : : shared_ptr < CComponent > component ) ;
void showInfoDialog ( const std : : string & text , const std : : vector < std : : shared_ptr < CComponent > > & components = std : : vector < std : : shared_ptr < CComponent > > ( ) , int soundID = 0 ) ;
2013-11-30 12:43:31 +03:00
void showInfoDialogAndWait ( std : : vector < Component > & components , const MetaString & text ) ;
2018-04-07 13:34:11 +02:00
void showYesNoDialog ( const std : : string & text , CFunctionList < void ( ) > onYes , CFunctionList < void ( ) > onNo , const std : : vector < std : : shared_ptr < CComponent > > & components = std : : vector < std : : shared_ptr < CComponent > > ( ) ) ;
2013-11-30 12:43:31 +03:00
2010-05-14 05:18:37 +03:00
void stopMovement ( ) ;
2023-02-15 12:08:32 +02:00
void moveHero ( const CGHeroInstance * h , const CGPath & path ) ;
2014-09-19 00:18:49 +03:00
2023-07-13 21:56:53 +02:00
void tryDigging ( const CGHeroInstance * h ) ;
2012-09-15 22:16:16 +03:00
void showShipyardDialogOrProblemPopup ( const IShipyard * obj ) ; //obj may be town or shipyard;
2012-04-09 05:53:50 +03:00
void proposeLoadingGame ( ) ;
2023-07-13 22:07:42 +02:00
void performAutosave ( ) ;
2009-02-20 15:06:20 +02:00
2014-06-18 13:31:11 +03:00
///returns true if all events are processed internally
bool capturedAllEvents ( ) ;
2017-07-17 23:04:00 +02:00
CPlayerInterface ( PlayerColor Player ) ;
~ CPlayerInterface ( ) ;
2009-03-28 20:46:20 +02:00
2014-06-18 13:31:11 +03:00
private :
2014-06-21 16:41:05 +03:00
struct IgnoreEvents
{
CPlayerInterface & owner ;
IgnoreEvents ( CPlayerInterface & Owner ) : owner ( Owner )
{
owner . ignoreEvents = true ;
} ;
~ IgnoreEvents ( )
{
owner . ignoreEvents = false ;
} ;
2015-01-13 21:57:41 +02:00
2014-06-21 16:41:05 +03:00
} ;
2015-01-13 21:57:41 +02:00
2023-04-17 12:06:58 +02:00
void heroKilled ( const CGHeroInstance * hero ) ;
void garrisonsChanged ( std : : vector < const CGObjectInstance * > objs ) ;
void requestReturningToMainMenu ( bool won ) ;
void acceptTurn ( ) ; //used during hot seat after your turn message is close
void initializeHeroTownList ( ) ;
int getLastIndex ( std : : string namePrefix ) ;
2014-06-18 13:31:11 +03:00
void doMoveHero ( const CGHeroInstance * h , CGPath path ) ;
2016-01-22 23:35:41 +02:00
void setMovementStatus ( bool value ) ;
2023-04-17 00:09:25 +02:00
2009-02-20 15:06:20 +02:00
} ;
2009-03-28 20:46:20 +02:00
2023-04-17 12:06:58 +02:00
/// Provides global access to instance of interface of currently active player
2009-02-20 15:06:20 +02:00
extern CPlayerInterface * LOCPLINT ;