PlayerLocalState.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * PlayerLocalState.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. VCMI_LIB_NAMESPACE_BEGIN
  12. class CGHeroInstance;
  13. class CGTownInstance;
  14. class CArmedInstance;
  15. struct CGPath;
  16. class int3;
  17. VCMI_LIB_NAMESPACE_END
  18. class CPlayerInterface;
  19. struct PlayerSpellbookSetting
  20. {
  21. //on which page we left spellbook
  22. int spellbookLastPageBattle = 0;
  23. int spellbookLastPageAdvmap = 0;
  24. int spellbookLastTabBattle = 4;
  25. int spellbookLastTabAdvmap = 4;
  26. };
  27. /// Class that contains potentially serializeable state of a local player
  28. class PlayerLocalState
  29. {
  30. CPlayerInterface & owner;
  31. /// Currently selected object, can be town, hero or null
  32. const CArmedInstance * currentSelection;
  33. std::map<const CGHeroInstance *, CGPath> paths; //maps hero => selected path in adventure map
  34. std::vector<const CGHeroInstance *> sleepingHeroes; //if hero is in here, he's sleeping
  35. std::vector<const CGHeroInstance *> wanderingHeroes; //our heroes on the adventure map (not the garrisoned ones)
  36. std::vector<const CGTownInstance *> ownedTowns; //our towns on the adventure map
  37. PlayerSpellbookSetting spellbookSettings;
  38. void saveHeroPaths(std::map<const CGHeroInstance *, int3> & paths);
  39. void loadHeroPaths(std::map<const CGHeroInstance *, int3> & paths);
  40. public:
  41. explicit PlayerLocalState(CPlayerInterface & owner);
  42. bool isHeroSleeping(const CGHeroInstance * hero) const;
  43. void setHeroAsleep(const CGHeroInstance * hero);
  44. void setHeroAwaken(const CGHeroInstance * hero);
  45. const PlayerSpellbookSetting & getSpellbookSettings();
  46. void setSpellbookSettings(const PlayerSpellbookSetting & newSettings);
  47. const std::vector<const CGTownInstance *> & getOwnedTowns();
  48. const CGTownInstance * getOwnedTown(size_t index);
  49. void addOwnedTown(const CGTownInstance * hero);
  50. void removeOwnedTown(const CGTownInstance * hero);
  51. void swapOwnedTowns(size_t pos1, size_t pos2);
  52. const std::vector<const CGHeroInstance *> & getWanderingHeroes();
  53. const CGHeroInstance * getWanderingHero(size_t index);
  54. const CGHeroInstance * getNextWanderingHero(const CGHeroInstance * hero);
  55. void addWanderingHero(const CGHeroInstance * hero);
  56. void removeWanderingHero(const CGHeroInstance * hero);
  57. void swapWanderingHero(size_t pos1, size_t pos2);
  58. void setPath(const CGHeroInstance * h, const CGPath & path);
  59. bool setPath(const CGHeroInstance * h, const int3 & destination);
  60. const CGPath & getPath(const CGHeroInstance * h) const;
  61. bool hasPath(const CGHeroInstance * h) const;
  62. void removeLastNode(const CGHeroInstance * h);
  63. void erasePath(const CGHeroInstance * h);
  64. void verifyPath(const CGHeroInstance * h);
  65. /// Returns currently selected object
  66. const CGHeroInstance * getCurrentHero() const;
  67. const CGTownInstance * getCurrentTown() const;
  68. const CArmedInstance * getCurrentArmy() const;
  69. /// Changes currently selected object
  70. void setSelection(const CArmedInstance *sel);
  71. };