CPlayerInterface.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. #pragma once
  2. #include "../lib/CondSh.h"
  3. #include "FunctionList.h"
  4. #include "../lib/CGameInterface.h"
  5. #include "UIFramework/CIntObject.h"
  6. #ifdef __GNUC__
  7. #define sprintf_s snprintf
  8. #endif
  9. #ifdef max
  10. #undef max
  11. #endif
  12. #ifdef min
  13. #undef min
  14. #endif
  15. /*
  16. * CPlayerInterface.h, part of VCMI engine
  17. *
  18. * Authors: listed in file AUTHORS in main folder
  19. *
  20. * License: GNU General Public License v2.0 or later
  21. * Full text of license available in license.txt file, in main folder
  22. *
  23. */
  24. class CDefEssential;
  25. class CAdventureMapButton;
  26. class CHighlightableButtonsGroup;
  27. class CDefHandler;
  28. struct TryMoveHero;
  29. class CDefEssential;
  30. class CGHeroInstance;
  31. class CAdvMapInt;
  32. class CCastleInterface;
  33. class CBattleInterface;
  34. class CStack;
  35. class CComponent;
  36. class CCreature;
  37. struct SDL_Surface;
  38. struct CGPath;
  39. class CCreatureAnimation;
  40. class CSelectableComponent;
  41. class CCreatureSet;
  42. class CGObjectInstance;
  43. class CSlider;
  44. struct UpgradeInfo;
  45. template <typename T> struct CondSh;
  46. class CInGameConsole;
  47. class CGarrisonInt;
  48. class CInGameConsole;
  49. union SDL_Event;
  50. class IStatusBar;
  51. class CInfoWindow;
  52. class IShowActivatable;
  53. class ClickableL;
  54. class ClickableR;
  55. class Hoverable;
  56. class KeyInterested;
  57. class MotionInterested;
  58. class TimeInterested;
  59. class IShowable;
  60. struct CPathsInfo;
  61. namespace boost
  62. {
  63. class mutex;
  64. class recursive_mutex;
  65. };
  66. /// Central class for managing user interface logic
  67. class CPlayerInterface : public CGameInterface, public IUpdateable
  68. {
  69. public:
  70. bool observerInDuelMode;
  71. //minor interfaces
  72. CondSh<bool> *showingDialog; //indicates if dialog box is displayed
  73. static boost::recursive_mutex *pim;
  74. bool makingTurn; //if player is already making his turn
  75. int firstCall; // -1 - just loaded game; 1 - just started game; 0 otherwise
  76. int autosaveCount;
  77. static const int SAVES_COUNT = 5;
  78. static int howManyPeople;
  79. CCastleInterface * castleInt; //NULL if castle window isn't opened
  80. static CBattleInterface * battleInt; //NULL if no battle
  81. CInGameConsole * cingconsole;
  82. CCallback * cb; //to communicate with engine
  83. const BattleAction *curAction; //during the battle - action currently performed by active stack (or NULL)
  84. std::list<CInfoWindow *> dialogs; //queue of dialogs awaiting to be shown (not currently shown!)
  85. std::vector<const CGHeroInstance *> wanderingHeroes; //our heroes on the adventure map (not the garrisoned ones)
  86. std::vector<const CGTownInstance *> towns; //our heroes on the adventure map (not the garrisoned ones)
  87. std::map<const CGHeroInstance *, CGPath> paths; //maps hero => selected path in adventure map
  88. std::vector<const CGHeroInstance *> sleepingHeroes; //if hero is in here, he's sleeping
  89. struct SpellbookLastSetting
  90. {
  91. int spellbookLastPageBattle, spellbokLastPageAdvmap; //on which page we left spellbook
  92. int spellbookLastTabBattle, spellbookLastTabAdvmap; //on which page we left spellbook
  93. SpellbookLastSetting();
  94. template <typename Handler> void serialize( Handler &h, const int version )
  95. {
  96. h & spellbookLastPageBattle & spellbokLastPageAdvmap & spellbookLastTabBattle & spellbookLastTabAdvmap;
  97. }
  98. } spellbookSettings;
  99. void update();
  100. void recreateHeroTownList();
  101. const CGHeroInstance *getWHero(int pos); //returns NULL if position is not valid
  102. int getLastIndex(std::string namePrefix);
  103. //overridden funcs from CGameInterface
  104. void buildChanged(const CGTownInstance *town, int buildingID, int what) OVERRIDE; //what: 1 - built, 2 - demolished
  105. void stackChagedCount(const StackLocation &location, const TQuantity &change, bool isAbsolute) OVERRIDE; //if absolute, change is the new count; otherwise count was modified by adding change
  106. void stackChangedType(const StackLocation &location, const CCreature &newType) OVERRIDE; //used eg. when upgrading creatures
  107. void stacksErased(const StackLocation &location) OVERRIDE; //stack removed from previously filled slot
  108. void stacksSwapped(const StackLocation &loc1, const StackLocation &loc2) OVERRIDE;
  109. void newStackInserted(const StackLocation &location, const CStackInstance &stack) OVERRIDE; //new stack inserted at given (previously empty position)
  110. void stacksRebalanced(const StackLocation &src, const StackLocation &dst, TQuantity count) OVERRIDE; //moves creatures from src stack to dst slot, may be used for merging/splittint/moving stacks
  111. void artifactPut(const ArtifactLocation &al);
  112. void artifactRemoved(const ArtifactLocation &al);
  113. void artifactMoved(const ArtifactLocation &src, const ArtifactLocation &dst);
  114. void artifactAssembled(const ArtifactLocation &al);
  115. void artifactDisassembled(const ArtifactLocation &al);
  116. void heroCreated(const CGHeroInstance* hero) OVERRIDE;
  117. void heroGotLevel(const CGHeroInstance *hero, int pskill, std::vector<ui16> &skills, boost::function<void(ui32)> &callback) OVERRIDE;
  118. void heroInGarrisonChange(const CGTownInstance *town) OVERRIDE;
  119. void heroMoved(const TryMoveHero & details) OVERRIDE;
  120. void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, si64 val) OVERRIDE;
  121. void heroSecondarySkillChanged(const CGHeroInstance * hero, int which, int val) OVERRIDE;
  122. void heroManaPointsChanged(const CGHeroInstance * hero) OVERRIDE;
  123. void heroMovePointsChanged(const CGHeroInstance * hero) OVERRIDE;
  124. void heroVisitsTown(const CGHeroInstance* hero, const CGTownInstance * town) OVERRIDE;
  125. void receivedResource(int type, int val) OVERRIDE;
  126. void showInfoDialog(const std::string &text, const std::vector<Component*> &components, int soundID) OVERRIDE;
  127. void showRecruitmentDialog(const CGDwelling *dwelling, const CArmedInstance *dst, int level) OVERRIDE;
  128. void showShipyardDialog(const IShipyard *obj) OVERRIDE; //obj may be town or shipyard;
  129. void showBlockingDialog(const std::string &text, const std::vector<Component> &components, ui32 askID, 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.
  130. void showGarrisonDialog(const CArmedInstance *up, const CGHeroInstance *down, bool removableUnits, boost::function<void()> &onEnd) OVERRIDE;
  131. void showPuzzleMap() OVERRIDE;
  132. void showMarketWindow(const IMarket *market, const CGHeroInstance *visitor) OVERRIDE;
  133. void showUniversityWindow(const IMarket *market, const CGHeroInstance *visitor) OVERRIDE;
  134. void showHillFortWindow(const CGObjectInstance *object, const CGHeroInstance *visitor) OVERRIDE;
  135. void showTavernWindow(const CGObjectInstance *townOrTavern) OVERRIDE;
  136. void advmapSpellCast(const CGHeroInstance * caster, int spellID) OVERRIDE; //called when a hero casts a spell
  137. void tileHidden(const boost::unordered_set<int3, ShashInt3> &pos) OVERRIDE; //called when given tiles become hidden under fog of war
  138. void tileRevealed(const boost::unordered_set<int3, ShashInt3> &pos) OVERRIDE; //called when fog of war disappears from given tiles
  139. void newObject(const CGObjectInstance * obj) OVERRIDE;
  140. void availableArtifactsChanged(const CGBlackMarket *bm = NULL) OVERRIDE; //bm may be NULL, then artifacts are changed in the global pool (used by merchants in towns)
  141. void yourTurn() OVERRIDE;
  142. void availableCreaturesChanged(const CGDwelling *town) OVERRIDE;
  143. void heroBonusChanged(const CGHeroInstance *hero, const Bonus &bonus, bool gain) OVERRIDE;//if gain hero received bonus, else he lost it
  144. void playerBonusChanged(const Bonus &bonus, bool gain) OVERRIDE;
  145. void requestRealized(PackageApplied *pa) OVERRIDE;
  146. void heroExchangeStarted(si32 hero1, si32 hero2) OVERRIDE;
  147. void centerView (int3 pos, int focusTime) OVERRIDE;
  148. void objectPropertyChanged(const SetObjectProperty * sop) OVERRIDE;
  149. void objectRemoved(const CGObjectInstance *obj) OVERRIDE;
  150. void gameOver(ui8 player, bool victory) OVERRIDE;
  151. void playerStartsTurn(ui8 player) OVERRIDE;
  152. void serialize(COSer<CSaveFile> &h, const int version) OVERRIDE; //saving
  153. void serialize(CISer<CLoadFile> &h, const int version) OVERRIDE; //loading
  154. //for battles
  155. void actionFinished(const BattleAction* action) OVERRIDE;//occurs AFTER action taken by active stack or by the hero
  156. void actionStarted(const BattleAction* action) OVERRIDE;//occurs BEFORE action taken by active stack or by the hero
  157. BattleAction activeStack(const CStack * stack) OVERRIDE; //called when it's turn of that stack
  158. void battleAttack(const BattleAttack *ba) OVERRIDE; //stack performs attack
  159. void battleEnd(const BattleResult *br) OVERRIDE; //end of battle
  160. void battleNewRoundFirst(int round) OVERRIDE; //called at the beginning of each turn before changes are applied; used for HP regen handling
  161. 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
  162. void battleStackMoved(const CStack * stack, std::vector<BattleHex> dest, int distance) OVERRIDE;
  163. void battleSpellCast(const BattleSpellCast *sc) OVERRIDE;
  164. void battleStacksEffectsSet(const SetStackEffect & sse) OVERRIDE; //called when a specific effect is set to stacks
  165. void battleTriggerEffect(const BattleTriggerEffect & bte) OVERRIDE; //various one-shot effect
  166. void battleStacksAttacked(const std::vector<BattleStackAttacked> & bsa) OVERRIDE;
  167. void battleStart(const CCreatureSet *army1, const CCreatureSet *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, bool side) OVERRIDE; //called by engine when battle starts; side=0 - left, side=1 - right
  168. void battleStacksHealedRes(const std::vector<std::pair<ui32, ui32> > & healedStacks, bool lifeDrain, bool tentHeal, si32 lifeDrainFrom) OVERRIDE; //called when stacks are healed / resurrected
  169. void battleNewStackAppeared(const CStack * stack) OVERRIDE; //not called at the beginning of a battle or by resurrection; called eg. when elemental is summoned
  170. void battleObstaclesRemoved(const std::set<si32> & removedObstacles) OVERRIDE; //called when a certain set of obstacles is removed from batlefield; IDs of them are given
  171. void battleCatapultAttacked(const CatapultAttack & ca) OVERRIDE; //called when catapult makes an attack
  172. void battleStacksRemoved(const BattleStacksRemoved & bsr) OVERRIDE; //called when certain stack is completely removed from battlefield
  173. void yourTacticPhase(int distance) OVERRIDE;
  174. //-------------//
  175. void showArtifactAssemblyDialog(ui32 artifactID, ui32 assembleTo, bool assemble, CFunctionList<void()> onYes, CFunctionList<void()> onNo);
  176. void garrisonChanged(const CGObjectInstance * obj, bool updateInfobox = true);
  177. void heroKilled(const CGHeroInstance* hero);
  178. void waitWhileDialog();
  179. void waitForAllDialogs();
  180. bool shiftPressed() const; //determines if shift key is pressed (left or right or both)
  181. bool ctrlPressed() const; //determines if ctrl key is pressed (left or right or both)
  182. bool altPressed() const; //determines if alt key is pressed (left or right or both)
  183. void redrawHeroWin(const CGHeroInstance * hero);
  184. void showComp(CComponent comp); //TODO: comment me
  185. void openTownWindow(const CGTownInstance * town); //shows townscreen
  186. void openHeroWindow(const CGHeroInstance * hero); //shows hero window with given hero
  187. SDL_Surface * infoWin(const CGObjectInstance * specific); //specific=0 => draws info about selected town/hero
  188. void updateInfo(const CGObjectInstance * specific);
  189. void init(CCallback * CB);
  190. int3 repairScreenPos(int3 pos); //returns position closest to pos we can center screen on
  191. void showInfoDialog(const std::string &text, const std::vector<CComponent*> & components = std::vector<CComponent*>(), int soundID = 0, bool delComps = false);
  192. void showYesNoDialog(const std::string &text, const std::vector<CComponent*> & 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
  193. void stopMovement();
  194. bool moveHero(const CGHeroInstance *h, CGPath path);
  195. void initMovement(const TryMoveHero &details, const CGHeroInstance * ho, const int3 &hp );//initializing objects and performing first step of move
  196. void movementPxStep( const TryMoveHero &details, int i, const int3 &hp, const CGHeroInstance * ho );//performing step of movement
  197. void finishMovement( const TryMoveHero &details, const int3 &hp, const CGHeroInstance * ho ); //finish movement
  198. void eraseCurrentPathOf( const CGHeroInstance * ho, bool checkForExistanceOfPath = true );
  199. void removeLastNodeFromPath(const CGHeroInstance *ho);
  200. CGPath *getAndVerifyPath( const CGHeroInstance * h );
  201. void acceptTurn(); //used during hot seat after your turn message is close
  202. void tryDiggging(const CGHeroInstance *h);
  203. void showShipyardDialogOrProblemPopup(const IShipyard *obj); //obj may be town or shipyard;
  204. void requestReturningToMainMenu();
  205. void requestStoppingClient();
  206. void sendCustomEvent(int code);
  207. CPlayerInterface(int Player);//c-tor
  208. ~CPlayerInterface();//d-tor
  209. CondSh<bool> terminate_cond; // confirm termination
  210. //////////////////////////////////////////////////////////////////////////
  211. template <typename Handler> void serializeTempl(Handler &h, const int version);
  212. };
  213. extern CPlayerInterface * LOCPLINT;