CPlayerInterface.h 11 KB

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