2009-02-20 15:06:20 +02:00
# ifndef __CPLAYERINTERFACE_H__
# define __CPLAYERINTERFACE_H__
2009-05-20 13:08:56 +03:00
# include "../global.h"
# include "../CGameInterface.h"
2009-11-01 03:15:16 +02:00
# include "../lib/CondSh.h"
2009-02-20 15:06:20 +02:00
# include "SDL_framerate.h"
# include <map>
# include <list>
2009-03-21 19:22:16 +02:00
# include <algorithm>
2009-12-28 06:08:24 +02:00
# include "GUIBase.h"
2009-02-20 15:06:20 +02:00
# ifdef __GNUC__
# define sprintf_s snprintf
# endif
2009-03-21 19:22:16 +02:00
# ifdef max
# undef max
# endif
# ifdef min
# undef min
# endif
2009-04-15 17:03:31 +03: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
*
*/
2009-02-20 15:06:20 +02:00
class CDefEssential ;
class AdventureMapButton ;
class CHighlightableButtonsGroup ;
class CDefHandler ;
2009-07-03 22:57:14 +03:00
struct TryMoveHero ;
2009-02-20 15:06:20 +02:00
class CDefEssential ;
class CGHeroInstance ;
class CAdvMapInt ;
class CCastleInterface ;
class CBattleInterface ;
class CStack ;
class SComponent ;
class CCreature ;
struct SDL_Surface ;
2009-09-07 05:29:44 +03:00
struct CGPath ;
2009-02-20 15:06:20 +02:00
class CCreatureAnimation ;
class CSelectableComponent ;
class CCreatureSet ;
class CGObjectInstance ;
class CSlider ;
struct UpgradeInfo ;
template < typename T > struct CondSh ;
2009-04-03 18:55:26 +03:00
class CInGameConsole ;
2009-04-14 15:47:09 +03:00
class CGarrisonInt ;
2009-05-19 21:23:04 +03:00
class CInGameConsole ;
union SDL_Event ;
class IStatusBar ;
class CInfoWindow ;
class IShowActivable ;
class ClickableL ;
class ClickableR ;
class Hoverable ;
class KeyInterested ;
class MotionInterested ;
class TimeInterested ;
class IShowable ;
2009-08-30 15:47:40 +03:00
struct CPathsInfo ;
2009-02-20 15:06:20 +02:00
namespace boost
{
class mutex ;
class recursive_mutex ;
} ;
2009-07-18 06:13:13 +03:00
struct SystemOptions
{
2009-09-24 16:23:52 +03:00
ui8 heroMoveSpeed ; /*, enemyMoveSpeed*/ //speed of player's hero movement
2009-07-18 06:13:13 +03:00
ui8 mapScrollingSpeed ; //map scrolling speed
ui8 musicVolume , soundVolume ;
//TODO: rest of system options
2009-09-24 16:23:52 +03:00
//battle settings
ui8 printCellBorders ; //if true, cell borders will be printed
ui8 printStackRange ; //if true,range of active stack will be printed
ui8 animSpeed ; //speed of animation; 1 - slowest, 2 - medium, 4 - fastest
ui8 printMouseShadow ; //if true, hex under mouse will be shaded
ui8 showQueue ;
2009-07-18 06:13:13 +03:00
2009-09-24 16:23:52 +03:00
SystemOptions ( ) ;
2009-07-18 06:13:13 +03:00
void setHeroMoveSpeed ( int newSpeed ) ; //set for the member above
void setMapScrollingSpeed ( int newSpeed ) ; //set the member above
void setMusicVolume ( int newVolume ) ;
void setSoundVolume ( int newVolume ) ;
void settingsChanged ( ) ; //updates file with "default" settings for next running of application
void apply ( ) ;
2009-09-24 16:23:52 +03:00
template < typename Handler > void serialize ( Handler & h , const int version )
{
h & heroMoveSpeed & mapScrollingSpeed & musicVolume & soundVolume ;
h & printCellBorders & printStackRange & animSpeed & printMouseShadow & showQueue ;
}
2009-07-18 06:13:13 +03:00
} ;
extern SystemOptions GDefaultOptions ; //defined and inited in CMT.cpp, stores default settings loaded with application
2009-12-28 06:08:24 +02:00
class CPlayerInterface : public CGameInterface , public IUpdateable
2009-02-20 15:06:20 +02:00
{
public :
//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
boost : : recursive_mutex * pim ;
bool makingTurn ; //if player is already making his turn
2009-12-28 06:08:24 +02:00
int firstCall ; // -1 - just loaded game; 1 - just started game; 0 otherwise
int autosaveCount ;
static const int SAVES_COUNT = 5 ;
2010-05-27 00:59:58 +03:00
static int howManyPeople ;
2009-04-14 15:47:09 +03:00
2009-07-18 06:13:13 +03:00
SystemOptions sysOpts ;
2009-04-14 15:47:09 +03:00
CCastleInterface * castleInt ; //NULL if castle window isn't opened
2010-02-19 18:02:34 +02:00
static CBattleInterface * battleInt ; //NULL if no battle
2009-04-14 15:47:09 +03:00
FPSmanager * mainFPSmng ; //to keep const framerate
2009-08-07 01:36:51 +03:00
CInGameConsole * cingconsole ;
2009-04-14 15:47:09 +03:00
CCallback * cb ; //to communicate with engine
const BattleAction * curAction ; //during the battle - action currently performed by active stack (or NULL)
std : : list < CInfoWindow * > dialogs ; //queue of dialogs awaiting to be shown (not currently shown!)
2009-08-07 01:36:51 +03:00
2009-03-09 21:40:43 +02:00
2009-06-11 20:21:06 +03:00
std : : vector < const CGHeroInstance * > wanderingHeroes ; //our heroes on the adventure map (not the garrisoned ones)
2010-02-26 13:18:09 +02:00
std : : vector < const CGTownInstance * > towns ; //our heroes on the adventure map (not the garrisoned ones)
2010-02-20 15:24:38 +02:00
std : : map < const CGHeroInstance * , CGPath > paths ; //maps hero => selected path in adventure map
2009-12-28 06:08:24 +02:00
2010-07-21 13:09:29 +03:00
struct SpellbookLastSetting
{
int spellbookLastPageBattle , spellbokLastPageAdvmap ; //on which page we left spellbook
int spellbookLastTabBattle , spellbookLastTabAdvmap ; //on which page we left spellbook
SpellbookLastSetting ( ) ;
template < typename Handler > void serialize ( Handler & h , const int version )
{
h & spellbookLastPageBattle & spellbokLastPageAdvmap & spellbookLastTabBattle & spellbookLastTabAdvmap ;
}
} spellbookSettings ;
2009-12-28 06:08:24 +02:00
void update ( ) ;
2010-02-26 13:18:09 +02:00
void recreateHeroTownList ( ) ;
2009-06-11 20:21:06 +03:00
const CGHeroInstance * getWHero ( int pos ) ; //returns NULL if position is not valid
2009-12-28 06:08:24 +02:00
int getLastIndex ( std : : string namePrefix ) ;
2009-06-11 20:21:06 +03:00
2009-02-20 15:06:20 +02:00
//overloaded funcs from CGameInterface
void buildChanged ( const CGTownInstance * town , int buildingID , int what ) ; //what: 1 - built, 2 - demolished
void garrisonChanged ( const CGObjectInstance * obj ) ;
2009-05-07 20:20:41 +03:00
void heroArtifactSetChanged ( const CGHeroInstance * hero ) ;
2009-02-20 15:06:20 +02:00
void heroCreated ( const CGHeroInstance * hero ) ;
void heroGotLevel ( const CGHeroInstance * hero , int pskill , std : : vector < ui16 > & skills , boost : : function < void ( ui32 ) > & callback ) ;
void heroInGarrisonChange ( const CGTownInstance * town ) ;
2009-07-03 22:57:14 +03:00
void heroMoved ( const TryMoveHero & details ) ;
2009-08-16 18:39:18 +03:00
void heroPrimarySkillChanged ( const CGHeroInstance * hero , int which , si64 val ) ;
2010-07-20 17:08:13 +03:00
void heroSecondarySkillChanged ( const CGHeroInstance * hero , int which , int val ) ;
2009-02-20 15:06:20 +02:00
void heroManaPointsChanged ( const CGHeroInstance * hero ) ;
void heroMovePointsChanged ( const CGHeroInstance * hero ) ;
void heroVisitsTown ( const CGHeroInstance * hero , const CGTownInstance * town ) ;
void receivedResource ( int type , int val ) ;
2009-04-30 17:59:30 +03:00
void showInfoDialog ( const std : : string & text , const std : : vector < Component * > & components , int soundID ) ;
2009-07-26 13:43:22 +03:00
void showRecruitmentDialog ( const CGDwelling * dwelling , const CArmedInstance * dst , int level ) ;
2009-07-26 06:33:13 +03:00
void showShipyardDialog ( const IShipyard * obj ) ; //obj may be town or shipyard;
2009-04-30 17:59:30 +03:00
void showBlockingDialog ( const std : : string & text , const std : : vector < Component > & components , ui32 askID , int soundID , bool selection , bool cancel ) ; //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.
2009-09-09 20:49:03 +03:00
void showGarrisonDialog ( const CArmedInstance * up , const CGHeroInstance * down , bool removableUnits , boost : : function < void ( ) > & onEnd ) ;
2010-02-27 03:05:39 +02:00
void showArtifactAssemblyDialog ( ui32 artifactID , ui32 assembleTo , bool assemble , CFunctionList < void ( ) > onYes , CFunctionList < void ( ) > onNo ) ;
2010-02-10 04:56:00 +02:00
void showPuzzleMap ( ) ;
2010-05-18 10:01:54 +03:00
void showMarketWindow ( const IMarket * market , const CGHeroInstance * visitor ) ;
2010-07-20 17:08:13 +03:00
void showUniversityWindow ( const IMarket * market , const CGHeroInstance * visitor ) ;
2010-07-22 03:32:45 +03:00
void showHillFortWindow ( const CGObjectInstance * object , const CGHeroInstance * visitor ) ;
2010-07-09 02:03:27 +03:00
void showTavernWindow ( const CGObjectInstance * townOrTavern ) ;
2010-05-16 16:42:19 +03:00
void advmapSpellCast ( const CGHeroInstance * caster , int spellID ) ; //called when a hero casts a spell
2009-05-07 20:20:41 +03:00
void tileHidden ( const std : : set < int3 > & pos ) ; //called when given tiles become hidden under fog of war
void tileRevealed ( const std : : set < int3 > & pos ) ; //called when fog of war disappears from given tiles
2009-07-26 06:33:13 +03:00
void newObject ( const CGObjectInstance * obj ) ;
2010-06-27 19:03:01 +03:00
void availableArtifactsChanged ( const CGBlackMarket * bm = NULL ) ; //bm may be NULL, then artifacts are changed in the global pool (used by merchants in towns)
2009-02-20 15:06:20 +02:00
void yourTurn ( ) ;
2009-07-26 13:43:22 +03:00
void availableCreaturesChanged ( const CGDwelling * town ) ;
2010-05-02 21:20:26 +03:00
void heroBonusChanged ( const CGHeroInstance * hero , const Bonus & bonus , bool gain ) ; //if gain hero received bonus, else he lost it
void playerBonusChanged ( const Bonus & bonus , bool gain ) ;
2009-04-21 01:57:07 +03:00
void requestRealized ( PackageApplied * pa ) ;
2009-06-16 14:18:14 +03:00
void heroExchangeStarted ( si32 hero1 , si32 hero2 ) ;
2009-08-13 04:03:11 +03:00
void centerView ( int3 pos , int focusTime ) ;
2009-07-30 15:49:45 +03:00
void objectPropertyChanged ( const SetObjectProperty * sop ) ;
2009-08-04 02:53:18 +03:00
void objectRemoved ( const CGObjectInstance * obj ) ;
2010-01-29 22:52:45 +02:00
void gameOver ( ui8 player , bool victory ) ;
2009-04-03 18:55:26 +03:00
void serialize ( COSer < CSaveFile > & h , const int version ) ; //saving
2009-03-28 20:46:20 +02:00
void serialize ( CISer < CLoadFile > & h , const int version ) ; //loading
2009-02-20 15:06:20 +02:00
//for battles
void actionFinished ( const BattleAction * action ) ; //occurs AFTER action taken by active stack or by the hero
void actionStarted ( const BattleAction * action ) ; //occurs BEFORE action taken by active stack or by the hero
BattleAction activeStack ( int stackID ) ; //called when it's turn of that stack
void battleAttack ( BattleAttack * ba ) ; //stack performs attack
2009-03-22 18:04:46 +02:00
void battleEnd ( BattleResult * br ) ; //end of battle
2009-04-14 15:47:09 +03:00
//void battleResultQuited();
2010-05-07 15:29:41 +03:00
void battleNewRoundFirst ( int round ) ; //called at the beginning of each turn before changes are applied; used for HP regen handling
2009-02-20 15:06:20 +02:00
void battleNewRound ( int round ) ; //called at the beggining of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn
2009-03-31 23:47:53 +03:00
void battleStackMoved ( int ID , int dest , int distance , bool end ) ;
2010-05-16 16:42:19 +03:00
void battleSpellCast ( BattleSpellCast * sc ) ;
2009-03-21 18:03:07 +02:00
void battleStacksEffectsSet ( SetStackEffect & sse ) ; //called when a specific effect is set to stacks
2010-02-20 15:24:38 +02:00
void battleStacksAttacked ( std : : vector < BattleStackAttacked > & bsa ) ;
2010-05-02 21:20:26 +03:00
void battleStart ( const CCreatureSet * army1 , const CCreatureSet * army2 , int3 tile , CGHeroInstance * hero1 , CGHeroInstance * hero2 , bool side ) ; //called by engine when battle starts; side=0 - left, side=1 - right
2009-02-20 15:06:20 +02:00
void battlefieldPrepared ( int battlefieldType , std : : vector < CObstacle * > obstacles ) ; //called when battlefield is prepared, prior the battle beginning
2010-05-07 15:29:41 +03:00
void battleStacksHealedRes ( const std : : vector < std : : pair < ui32 , ui32 > > & healedStacks , bool lifeDrain , si32 lifeDrainFrom ) ; //called when stacks are healed / resurrected
2009-08-06 17:02:21 +03:00
void battleNewStackAppeared ( int stackID ) ; //not called at the beginning of a battle or by resurrection; called eg. when elemental is summoned
2009-08-19 13:59:42 +03:00
void battleObstaclesRemoved ( const std : : set < si32 > & removedObstacles ) ; //called when a certain set of obstacles is removed from batlefield; IDs of them are given
2009-09-01 16:54:13 +03:00
void battleCatapultAttacked ( const CatapultAttack & ca ) ; //called when catapult makes an attack
2009-09-05 17:10:26 +03:00
void battleStacksRemoved ( const BattleStacksRemoved & bsr ) ; //called when certain stack is completely removed from battlefield
2009-02-20 15:06:20 +02:00
//-------------//
2009-08-04 02:53:18 +03:00
void heroKilled ( const CGHeroInstance * hero ) ;
2009-07-21 02:34:06 +03:00
void waitWhileDialog ( ) ;
2009-05-07 20:20:41 +03:00
bool shiftPressed ( ) const ; //determines if shift key is pressed (left or right or both)
2009-11-29 04:46:30 +02:00
bool ctrlPressed ( ) const ; //determines if ctrl key is pressed (left or right or both)
2010-07-21 13:09:29 +03:00
bool altPressed ( ) const ; //determines if alt key is pressed (left or right or both)
2009-02-20 15:06:20 +02:00
void redrawHeroWin ( const CGHeroInstance * hero ) ;
2009-03-22 18:04:46 +02:00
void showComp ( SComponent comp ) ; //TODO: comment me
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
SDL_Surface * infoWin ( const CGObjectInstance * specific ) ; //specific=0 => draws info about selected town/hero
2010-03-21 00:17:19 +02:00
void updateInfo ( const CGObjectInstance * specific ) ;
2009-02-20 15:06:20 +02:00
void init ( ICallback * CB ) ;
2009-03-22 18:04:46 +02:00
int3 repairScreenPos ( int3 pos ) ; //returns position closest to pos we can center screen on
2010-07-21 13:09:29 +03:00
void showInfoDialog ( const std : : string & text , const std : : vector < SComponent * > & components = std : : vector < SComponent * > ( ) , int soundID = 0 , bool delComps = false ) ;
2009-04-14 15:47:09 +03:00
void showYesNoDialog ( const std : : string & text , const std : : vector < SComponent * > & components , CFunctionList < void ( ) > onYes , CFunctionList < void ( ) > onNo , bool DelComps ) ; //deactivateCur - whether current main interface should be deactivated; delComps - if components will be deleted on window close
2010-05-14 05:18:37 +03:00
void stopMovement ( ) ;
2009-09-07 05:29:44 +03:00
bool moveHero ( const CGHeroInstance * h , CGPath path ) ;
2010-01-02 03:48:44 +02:00
void initMovement ( const TryMoveHero & details , const CGHeroInstance * ho , const int3 & hp ) ; //initializing objects and performing first step of move
void movementPxStep ( const TryMoveHero & details , int i , const int3 & hp , const CGHeroInstance * ho ) ; //performing step of movement
void finishMovement ( const TryMoveHero & details , const int3 & hp , const CGHeroInstance * ho ) ; //finish movement
2010-05-16 16:42:19 +03:00
void eraseCurrentPathOf ( const CGHeroInstance * ho , bool checkForExistanceOfPath = true ) ;
2010-02-20 15:24:38 +02:00
CGPath * getAndVerifyPath ( const CGHeroInstance * h ) ;
2010-02-24 15:03:36 +02:00
void acceptTurn ( ) ; //used during hot seat after your turn message is close
void tryDiggging ( const CGHeroInstance * h ) ;
2010-07-13 08:25:40 +03:00
void showShipyardDialogOrProblemPopup ( const IShipyard * obj ) ; //obj may be town or shipyard;
2010-08-18 12:50:25 +03:00
void requestReturningToMainMenu ( ) ;
2009-02-20 15:06:20 +02:00
2010-08-03 14:36:52 +03:00
CPlayerInterface ( int Player ) ; //c-tor
2009-02-20 15:06:20 +02:00
~ CPlayerInterface ( ) ; //d-tor
2009-03-28 20:46:20 +02:00
2009-11-01 03:15:16 +02:00
CondSh < bool > terminate_cond ; // confirm termination
2009-03-28 20:46:20 +02:00
//////////////////////////////////////////////////////////////////////////
template < typename Handler > void serializeTempl ( Handler & h , const int version ) ;
2009-02-20 15:06:20 +02:00
} ;
2009-03-28 20:46:20 +02:00
2009-02-20 15:06:20 +02:00
extern CPlayerInterface * LOCPLINT ;
# endif // __CPLAYERINTERFACE_H__