CPlayerInterface.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. #ifndef __CPLAYERINTERFACE_H__
  2. #define __CPLAYERINTERFACE_H__
  3. #include "../global.h"
  4. #include "../CGameInterface.h"
  5. #include "SDL_framerate.h"
  6. #include <map>
  7. #include <list>
  8. #include <algorithm>
  9. #ifdef __GNUC__
  10. #define sprintf_s snprintf
  11. #endif
  12. #ifdef max
  13. #undef max
  14. #endif
  15. #ifdef min
  16. #undef min
  17. #endif
  18. /*
  19. * CPlayerInterface.h, part of VCMI engine
  20. *
  21. * Authors: listed in file AUTHORS in main folder
  22. *
  23. * License: GNU General Public License v2.0 or later
  24. * Full text of license available in license.txt file, in main folder
  25. *
  26. */
  27. class CDefEssential;
  28. class AdventureMapButton;
  29. class CHighlightableButtonsGroup;
  30. class CDefHandler;
  31. struct TryMoveHero;
  32. class CDefEssential;
  33. class CGHeroInstance;
  34. class CAdvMapInt;
  35. class CCastleInterface;
  36. class CBattleInterface;
  37. class CStack;
  38. class SComponent;
  39. class CCreature;
  40. struct SDL_Surface;
  41. struct CPath;
  42. class CCreatureAnimation;
  43. class CSelectableComponent;
  44. class CCreatureSet;
  45. class CGObjectInstance;
  46. class CSlider;
  47. struct UpgradeInfo;
  48. template <typename T> struct CondSh;
  49. class CInGameConsole;
  50. class CGarrisonInt;
  51. class CInGameConsole;
  52. union SDL_Event;
  53. class IStatusBar;
  54. class CInfoWindow;
  55. class IShowActivable;
  56. class ClickableL;
  57. class ClickableR;
  58. class Hoverable;
  59. class KeyInterested;
  60. class MotionInterested;
  61. class TimeInterested;
  62. class IShowable;
  63. namespace boost
  64. {
  65. class mutex;
  66. class recursive_mutex;
  67. };
  68. struct SystemOptions
  69. {
  70. ui8 heroMoveSpeed; //speed of player's hero movement
  71. //TODO: enemy hero speed
  72. ui8 mapScrollingSpeed; //map scrolling speed
  73. ui8 musicVolume, soundVolume;
  74. //TODO: rest of system options
  75. template <typename Handler> void serialize(Handler &h, const int version)
  76. {
  77. h & heroMoveSpeed & mapScrollingSpeed & musicVolume & soundVolume;
  78. }
  79. SystemOptions()
  80. {
  81. heroMoveSpeed = 2;
  82. mapScrollingSpeed = 2;
  83. musicVolume = 88;
  84. soundVolume = 88;
  85. }
  86. void setHeroMoveSpeed(int newSpeed); //set for the member above
  87. void setMapScrollingSpeed(int newSpeed); //set the member above
  88. void setMusicVolume(int newVolume);
  89. void setSoundVolume(int newVolume);
  90. void settingsChanged(); //updates file with "default" settings for next running of application
  91. void apply();
  92. };
  93. extern SystemOptions GDefaultOptions; //defined and inited in CMT.cpp, stores default settings loaded with application
  94. class CPlayerInterface : public CGameInterface
  95. {
  96. public:
  97. //minor interfaces
  98. CondSh<bool> *showingDialog; //indicates if dialog box is displayed
  99. boost::recursive_mutex *pim;
  100. bool makingTurn; //if player is already making his turn
  101. SystemOptions sysOpts;
  102. CAdvMapInt * adventureInt;
  103. CCastleInterface * castleInt; //NULL if castle window isn't opened
  104. CBattleInterface * battleInt; //NULL if no battle
  105. FPSmanager * mainFPSmng; //to keep const framerate
  106. CInGameConsole * cingconsole;
  107. IStatusBar *statusbar; //current statusbar - will be used to show hover tooltips
  108. CCallback * cb; //to communicate with engine
  109. const BattleAction *curAction; //during the battle - action currently performed by active stack (or NULL)
  110. std::list<CInfoWindow *> dialogs; //queue of dialogs awaiting to be shown (not currently shown!)
  111. std::vector<const CGHeroInstance *> wanderingHeroes; //our heroes on the adventure map (not the garrisoned ones)
  112. void recreateWanderingHeroes();
  113. const CGHeroInstance *getWHero(int pos); //returns NULL if position is not valid
  114. //overloaded funcs from CGameInterface
  115. void buildChanged(const CGTownInstance *town, int buildingID, int what); //what: 1 - built, 2 - demolished
  116. void garrisonChanged(const CGObjectInstance * obj);
  117. void heroArtifactSetChanged(const CGHeroInstance* hero);
  118. void heroCreated(const CGHeroInstance* hero);
  119. void heroGotLevel(const CGHeroInstance *hero, int pskill, std::vector<ui16> &skills, boost::function<void(ui32)> &callback);
  120. void heroInGarrisonChange(const CGTownInstance *town);
  121. void heroMoved(const TryMoveHero & details);
  122. void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val);
  123. void heroManaPointsChanged(const CGHeroInstance * hero);
  124. void heroMovePointsChanged(const CGHeroInstance * hero);
  125. void heroVisitsTown(const CGHeroInstance* hero, const CGTownInstance * town);
  126. void receivedResource(int type, int val);
  127. void showInfoDialog(const std::string &text, const std::vector<Component*> &components, int soundID);
  128. void showRecruitmentDialog(const CGDwelling *dwelling, const CArmedInstance *dst, int level);
  129. void showShipyardDialog(const IShipyard *obj); //obj may be town or shipyard;
  130. 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.
  131. void showGarrisonDialog(const CArmedInstance *up, const CGHeroInstance *down, boost::function<void()> &onEnd);
  132. void tileHidden(const std::set<int3> &pos); //called when given tiles become hidden under fog of war
  133. void tileRevealed(const std::set<int3> &pos); //called when fog of war disappears from given tiles
  134. void newObject(const CGObjectInstance * obj);
  135. void yourTurn();
  136. void availableCreaturesChanged(const CGDwelling *town);
  137. void heroBonusChanged(const CGHeroInstance *hero, const HeroBonus &bonus, bool gain);//if gain hero received bonus, else he lost it
  138. void requestRealized(PackageApplied *pa);
  139. void heroExchangeStarted(si32 hero1, si32 hero2);
  140. void centerView (int3 pos);
  141. void objectPropertyChanged(const SetObjectProperty * sop);
  142. void objectRemoved(const CGObjectInstance *obj);
  143. void serialize(COSer<CSaveFile> &h, const int version); //saving
  144. void serialize(CISer<CLoadFile> &h, const int version); //loading
  145. //for battles
  146. void actionFinished(const BattleAction* action);//occurs AFTER action taken by active stack or by the hero
  147. void actionStarted(const BattleAction* action);//occurs BEFORE action taken by active stack or by the hero
  148. BattleAction activeStack(int stackID); //called when it's turn of that stack
  149. void battleAttack(BattleAttack *ba); //stack performs attack
  150. void battleEnd(BattleResult *br); //end of battle
  151. //void battleResultQuited();
  152. void battleNewRound(int round); //called at the beggining of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn
  153. void battleStackMoved(int ID, int dest, int distance, bool end);
  154. void battleSpellCast(SpellCast *sc);
  155. void battleStacksEffectsSet(SetStackEffect & sse); //called when a specific effect is set to stacks
  156. void battleStacksAttacked(std::set<BattleStackAttacked> & bsa);
  157. void battleStart(CCreatureSet *army1, CCreatureSet *army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2, bool side); //called by engine when battle starts; side=0 - left, side=1 - right
  158. void battlefieldPrepared(int battlefieldType, std::vector<CObstacle*> obstacles); //called when battlefield is prepared, prior the battle beginning
  159. void battleStacksHealedRes(const std::vector<std::pair<ui32, ui32> > & healedStacks); //called when stacks are healed / resurrected
  160. void battleNewStackAppeared(int stackID); //not called at the beginning of a battle or by resurrection; called eg. when elemental is summoned
  161. //-------------//
  162. void heroKilled(const CGHeroInstance* hero);
  163. void waitWhileDialog();
  164. bool shiftPressed() const; //determines if shift key is pressed (left or right or both)
  165. void redrawHeroWin(const CGHeroInstance * hero);
  166. void updateWater();
  167. void showComp(SComponent comp); //TODO: comment me
  168. void openTownWindow(const CGTownInstance * town); //shows townscreen
  169. void openHeroWindow(const CGHeroInstance * hero); //shows hero window with given hero
  170. SDL_Surface * infoWin(const CGObjectInstance * specific); //specific=0 => draws info about selected town/hero
  171. void init(ICallback * CB);
  172. int3 repairScreenPos(int3 pos); //returns position closest to pos we can center screen on
  173. void showInfoDialog(const std::string &text, const std::vector<SComponent*> & components = std::vector<SComponent*>(), int soundID = 0);
  174. 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
  175. bool moveHero(const CGHeroInstance *h, CPath path);
  176. CPlayerInterface(int Player, int serial);//c-tor
  177. ~CPlayerInterface();//d-tor
  178. //////////////////////////////////////////////////////////////////////////
  179. template <typename Handler> void serializeTempl(Handler &h, const int version);
  180. };
  181. extern CPlayerInterface * LOCPLINT;
  182. #endif // __CPLAYERINTERFACE_H__