CPlayerInterface.h 9.7 KB

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