CPlayerInterface.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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 CGPath;
  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. struct CPathsInfo;
  64. namespace boost
  65. {
  66. class mutex;
  67. class recursive_mutex;
  68. };
  69. struct SystemOptions
  70. {
  71. ui8 heroMoveSpeed;/*, enemyMoveSpeed*/ //speed of player's hero movement
  72. ui8 mapScrollingSpeed; //map scrolling speed
  73. ui8 musicVolume, soundVolume;
  74. //TODO: rest of system options
  75. //battle settings
  76. ui8 printCellBorders; //if true, cell borders will be printed
  77. ui8 printStackRange; //if true,range of active stack will be printed
  78. ui8 animSpeed; //speed of animation; 1 - slowest, 2 - medium, 4 - fastest
  79. ui8 printMouseShadow; //if true, hex under mouse will be shaded
  80. ui8 showQueue;
  81. SystemOptions();
  82. void setHeroMoveSpeed(int newSpeed); //set for the member above
  83. void setMapScrollingSpeed(int newSpeed); //set the member above
  84. void setMusicVolume(int newVolume);
  85. void setSoundVolume(int newVolume);
  86. void settingsChanged(); //updates file with "default" settings for next running of application
  87. void apply();
  88. template <typename Handler> void serialize(Handler &h, const int version)
  89. {
  90. h & heroMoveSpeed & mapScrollingSpeed & musicVolume & soundVolume;
  91. h & printCellBorders & printStackRange & animSpeed & printMouseShadow & showQueue;
  92. }
  93. };
  94. extern SystemOptions GDefaultOptions; //defined and inited in CMT.cpp, stores default settings loaded with application
  95. class CPlayerInterface : public CGameInterface
  96. {
  97. public:
  98. //minor interfaces
  99. CondSh<bool> *showingDialog; //indicates if dialog box is displayed
  100. boost::recursive_mutex *pim;
  101. bool makingTurn; //if player is already making his turn
  102. SystemOptions sysOpts;
  103. CAdvMapInt * adventureInt;
  104. CCastleInterface * castleInt; //NULL if castle window isn't opened
  105. CBattleInterface * battleInt; //NULL if no battle
  106. FPSmanager * mainFPSmng; //to keep const framerate
  107. CInGameConsole * cingconsole;
  108. IStatusBar *statusbar; //current statusbar - will be used to show hover tooltips
  109. CCallback * cb; //to communicate with engine
  110. const BattleAction *curAction; //during the battle - action currently performed by active stack (or NULL)
  111. std::list<CInfoWindow *> dialogs; //queue of dialogs awaiting to be shown (not currently shown!)
  112. std::vector<const CGHeroInstance *> wanderingHeroes; //our heroes on the adventure map (not the garrisoned ones)
  113. void recreateWanderingHeroes();
  114. const CGHeroInstance *getWHero(int pos); //returns NULL if position is not valid
  115. //overloaded funcs from CGameInterface
  116. void buildChanged(const CGTownInstance *town, int buildingID, int what); //what: 1 - built, 2 - demolished
  117. void garrisonChanged(const CGObjectInstance * obj);
  118. void heroArtifactSetChanged(const CGHeroInstance* hero);
  119. void heroCreated(const CGHeroInstance* hero);
  120. void heroGotLevel(const CGHeroInstance *hero, int pskill, std::vector<ui16> &skills, boost::function<void(ui32)> &callback);
  121. void heroInGarrisonChange(const CGTownInstance *town);
  122. void heroMoved(const TryMoveHero & details);
  123. void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, si64 val);
  124. void heroManaPointsChanged(const CGHeroInstance * hero);
  125. void heroMovePointsChanged(const CGHeroInstance * hero);
  126. void heroVisitsTown(const CGHeroInstance* hero, const CGTownInstance * town);
  127. void receivedResource(int type, int val);
  128. void showInfoDialog(const std::string &text, const std::vector<Component*> &components, int soundID);
  129. void showRecruitmentDialog(const CGDwelling *dwelling, const CArmedInstance *dst, int level);
  130. void showShipyardDialog(const IShipyard *obj); //obj may be town or shipyard;
  131. 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.
  132. void showGarrisonDialog(const CArmedInstance *up, const CGHeroInstance *down, bool removableUnits, boost::function<void()> &onEnd);
  133. void tileHidden(const std::set<int3> &pos); //called when given tiles become hidden under fog of war
  134. void tileRevealed(const std::set<int3> &pos); //called when fog of war disappears from given tiles
  135. void newObject(const CGObjectInstance * obj);
  136. void yourTurn();
  137. void availableCreaturesChanged(const CGDwelling *town);
  138. void heroBonusChanged(const CGHeroInstance *hero, const HeroBonus &bonus, bool gain);//if gain hero received bonus, else he lost it
  139. void requestRealized(PackageApplied *pa);
  140. void heroExchangeStarted(si32 hero1, si32 hero2);
  141. void centerView (int3 pos, int focusTime);
  142. void objectPropertyChanged(const SetObjectProperty * sop);
  143. void objectRemoved(const CGObjectInstance *obj);
  144. void serialize(COSer<CSaveFile> &h, const int version); //saving
  145. void serialize(CISer<CLoadFile> &h, const int version); //loading
  146. //for battles
  147. void actionFinished(const BattleAction* action);//occurs AFTER action taken by active stack or by the hero
  148. void actionStarted(const BattleAction* action);//occurs BEFORE action taken by active stack or by the hero
  149. BattleAction activeStack(int stackID); //called when it's turn of that stack
  150. void battleAttack(BattleAttack *ba); //stack performs attack
  151. void battleEnd(BattleResult *br); //end of battle
  152. //void battleResultQuited();
  153. void battleNewRound(int round); //called at the beggining of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn
  154. void battleStackMoved(int ID, int dest, int distance, bool end);
  155. void battleSpellCast(SpellCast *sc);
  156. void battleStacksEffectsSet(SetStackEffect & sse); //called when a specific effect is set to stacks
  157. void battleStacksAttacked(std::set<BattleStackAttacked> & bsa);
  158. 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
  159. void battlefieldPrepared(int battlefieldType, std::vector<CObstacle*> obstacles); //called when battlefield is prepared, prior the battle beginning
  160. void battleStacksHealedRes(const std::vector<std::pair<ui32, ui32> > & healedStacks); //called when stacks are healed / resurrected
  161. void battleNewStackAppeared(int stackID); //not called at the beginning of a battle or by resurrection; called eg. when elemental is summoned
  162. void battleObstaclesRemoved(const std::set<si32> & removedObstacles); //called when a certain set of obstacles is removed from batlefield; IDs of them are given
  163. void battleCatapultAttacked(const CatapultAttack & ca); //called when catapult makes an attack
  164. void battleStacksRemoved(const BattleStacksRemoved & bsr); //called when certain stack is completely removed from battlefield
  165. //-------------//
  166. void heroKilled(const CGHeroInstance* hero);
  167. void waitWhileDialog();
  168. bool shiftPressed() const; //determines if shift key is pressed (left or right or both)
  169. void redrawHeroWin(const CGHeroInstance * hero);
  170. void updateWater();
  171. void showComp(SComponent comp); //TODO: comment me
  172. void openTownWindow(const CGTownInstance * town); //shows townscreen
  173. void openHeroWindow(const CGHeroInstance * hero); //shows hero window with given hero
  174. SDL_Surface * infoWin(const CGObjectInstance * specific); //specific=0 => draws info about selected town/hero
  175. void init(ICallback * CB);
  176. int3 repairScreenPos(int3 pos); //returns position closest to pos we can center screen on
  177. void showInfoDialog(const std::string &text, const std::vector<SComponent*> & components = std::vector<SComponent*>(), int soundID = 0);
  178. 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
  179. bool moveHero(const CGHeroInstance *h, CGPath path);
  180. CPlayerInterface(int Player, int serial);//c-tor
  181. ~CPlayerInterface();//d-tor
  182. //////////////////////////////////////////////////////////////////////////
  183. template <typename Handler> void serializeTempl(Handler &h, const int version);
  184. };
  185. extern CPlayerInterface * LOCPLINT;
  186. #endif // __CPLAYERINTERFACE_H__