CPlayerInterface.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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. struct SpellbookLastSetting
  120. {
  121. int spellbookLastPageBattle, spellbokLastPageAdvmap; //on which page we left spellbook
  122. int spellbookLastTabBattle, spellbookLastTabAdvmap; //on which page we left spellbook
  123. SpellbookLastSetting();
  124. template <typename Handler> void serialize( Handler &h, const int version )
  125. {
  126. h & spellbookLastPageBattle & spellbokLastPageAdvmap & spellbookLastTabBattle & spellbookLastTabAdvmap;
  127. }
  128. } spellbookSettings;
  129. void update();
  130. void recreateHeroTownList();
  131. const CGHeroInstance *getWHero(int pos); //returns NULL if position is not valid
  132. int getLastIndex(std::string namePrefix);
  133. //overloaded funcs from CGameInterface
  134. void buildChanged(const CGTownInstance *town, int buildingID, int what); //what: 1 - built, 2 - demolished
  135. void garrisonChanged(const CGObjectInstance * obj);
  136. void heroArtifactSetChanged(const CGHeroInstance* hero);
  137. void heroCreated(const CGHeroInstance* hero);
  138. void heroGotLevel(const CGHeroInstance *hero, int pskill, std::vector<ui16> &skills, boost::function<void(ui32)> &callback);
  139. void heroInGarrisonChange(const CGTownInstance *town);
  140. void heroMoved(const TryMoveHero & details);
  141. void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, si64 val);
  142. void heroSecondarySkillChanged(const CGHeroInstance * hero, int which, int val);
  143. void heroManaPointsChanged(const CGHeroInstance * hero);
  144. void heroMovePointsChanged(const CGHeroInstance * hero);
  145. void heroVisitsTown(const CGHeroInstance* hero, const CGTownInstance * town);
  146. void receivedResource(int type, int val);
  147. void showInfoDialog(const std::string &text, const std::vector<Component*> &components, int soundID);
  148. void showRecruitmentDialog(const CGDwelling *dwelling, const CArmedInstance *dst, int level);
  149. void showShipyardDialog(const IShipyard *obj); //obj may be town or shipyard;
  150. 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.
  151. void showGarrisonDialog(const CArmedInstance *up, const CGHeroInstance *down, bool removableUnits, boost::function<void()> &onEnd);
  152. void showArtifactAssemblyDialog(ui32 artifactID, ui32 assembleTo, bool assemble, CFunctionList<void()> onYes, CFunctionList<void()> onNo);
  153. void showPuzzleMap();
  154. void showMarketWindow(const IMarket *market, const CGHeroInstance *visitor);
  155. void showUniversityWindow(const IMarket *market, const CGHeroInstance *visitor);
  156. void showHillFortWindow(const CGObjectInstance *object, const CGHeroInstance *visitor);
  157. void showTavernWindow(const CGObjectInstance *townOrTavern);
  158. void advmapSpellCast(const CGHeroInstance * caster, int spellID); //called when a hero casts a spell
  159. void tileHidden(const std::set<int3> &pos); //called when given tiles become hidden under fog of war
  160. void tileRevealed(const std::set<int3> &pos); //called when fog of war disappears from given tiles
  161. void newObject(const CGObjectInstance * obj);
  162. void availableArtifactsChanged(const CGBlackMarket *bm = NULL); //bm may be NULL, then artifacts are changed in the global pool (used by merchants in towns)
  163. void yourTurn();
  164. void availableCreaturesChanged(const CGDwelling *town);
  165. void heroBonusChanged(const CGHeroInstance *hero, const Bonus &bonus, bool gain);//if gain hero received bonus, else he lost it
  166. void playerBonusChanged(const Bonus &bonus, bool gain);
  167. void requestRealized(PackageApplied *pa);
  168. void heroExchangeStarted(si32 hero1, si32 hero2);
  169. void centerView (int3 pos, int focusTime);
  170. void objectPropertyChanged(const SetObjectProperty * sop);
  171. void objectRemoved(const CGObjectInstance *obj);
  172. void gameOver(ui8 player, bool victory);
  173. void serialize(COSer<CSaveFile> &h, const int version); //saving
  174. void serialize(CISer<CLoadFile> &h, const int version); //loading
  175. //for battles
  176. void actionFinished(const BattleAction* action);//occurs AFTER action taken by active stack or by the hero
  177. void actionStarted(const BattleAction* action);//occurs BEFORE action taken by active stack or by the hero
  178. BattleAction activeStack(int stackID); //called when it's turn of that stack
  179. void battleAttack(BattleAttack *ba); //stack performs attack
  180. void battleEnd(BattleResult *br); //end of battle
  181. //void battleResultQuited();
  182. void battleNewRoundFirst(int round); //called at the beginning of each turn before changes are applied; used for HP regen handling
  183. void battleNewRound(int round); //called at the beggining of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn
  184. void battleStackMoved(int ID, int dest, int distance, bool end);
  185. void battleSpellCast(BattleSpellCast *sc);
  186. void battleStacksEffectsSet(SetStackEffect & sse); //called when a specific effect is set to stacks
  187. void battleStacksAttacked(std::vector<BattleStackAttacked> & bsa);
  188. 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
  189. void battlefieldPrepared(int battlefieldType, std::vector<CObstacle*> obstacles); //called when battlefield is prepared, prior the battle beginning
  190. void battleStacksHealedRes(const std::vector<std::pair<ui32, ui32> > & healedStacks, bool lifeDrain, si32 lifeDrainFrom); //called when stacks are healed / resurrected
  191. void battleNewStackAppeared(int stackID); //not called at the beginning of a battle or by resurrection; called eg. when elemental is summoned
  192. void battleObstaclesRemoved(const std::set<si32> & removedObstacles); //called when a certain set of obstacles is removed from batlefield; IDs of them are given
  193. void battleCatapultAttacked(const CatapultAttack & ca); //called when catapult makes an attack
  194. void battleStacksRemoved(const BattleStacksRemoved & bsr); //called when certain stack is completely removed from battlefield
  195. //-------------//
  196. void heroKilled(const CGHeroInstance* hero);
  197. void waitWhileDialog();
  198. bool shiftPressed() const; //determines if shift key is pressed (left or right or both)
  199. bool ctrlPressed() const; //determines if ctrl key is pressed (left or right or both)
  200. bool altPressed() const; //determines if alt key is pressed (left or right or both)
  201. void redrawHeroWin(const CGHeroInstance * hero);
  202. void showComp(SComponent comp); //TODO: comment me
  203. void openTownWindow(const CGTownInstance * town); //shows townscreen
  204. void openHeroWindow(const CGHeroInstance * hero); //shows hero window with given hero
  205. SDL_Surface * infoWin(const CGObjectInstance * specific); //specific=0 => draws info about selected town/hero
  206. void updateInfo(const CGObjectInstance * specific);
  207. void init(ICallback * CB);
  208. int3 repairScreenPos(int3 pos); //returns position closest to pos we can center screen on
  209. void showInfoDialog(const std::string &text, const std::vector<SComponent*> & components = std::vector<SComponent*>(), int soundID = 0, bool delComps = false);
  210. 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
  211. void stopMovement();
  212. bool moveHero(const CGHeroInstance *h, CGPath path);
  213. void initMovement(const TryMoveHero &details, const CGHeroInstance * ho, const int3 &hp );//initializing objects and performing first step of move
  214. void movementPxStep( const TryMoveHero &details, int i, const int3 &hp, const CGHeroInstance * ho );//performing step of movement
  215. void finishMovement( const TryMoveHero &details, const int3 &hp, const CGHeroInstance * ho ); //finish movement
  216. void eraseCurrentPathOf( const CGHeroInstance * ho, bool checkForExistanceOfPath = true );
  217. CGPath *getAndVerifyPath( const CGHeroInstance * h );
  218. void acceptTurn(); //used during hot seat after your turn message is close
  219. void tryDiggging(const CGHeroInstance *h);
  220. void showShipyardDialogOrProblemPopup(const IShipyard *obj); //obj may be town or shipyard;
  221. void requestReturningToMainMenu();
  222. void requestStoppingClient();
  223. void sendCustomEvent(int code);
  224. CPlayerInterface(int Player);//c-tor
  225. ~CPlayerInterface();//d-tor
  226. CondSh<bool> terminate_cond; // confirm termination
  227. //////////////////////////////////////////////////////////////////////////
  228. template <typename Handler> void serializeTempl(Handler &h, const int version);
  229. };
  230. extern CPlayerInterface * LOCPLINT;
  231. #endif // __CPLAYERINTERFACE_H__