PlayerLocalState.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. #include "../lib/constants/EntityIdentifiers.h"
  12. VCMI_LIB_NAMESPACE_BEGIN
  13. class CGHeroInstance;
  14. class CGTownInstance;
  15. class CArmedInstance;
  16. class JsonNode;
  17. struct CGPath;
  18. class int3;
  19. struct CPathsInfo;
  20. VCMI_LIB_NAMESPACE_END
  21. class CPlayerInterface;
  22. struct PlayerSpellbookSetting
  23. {
  24. //on which page we left spellbook
  25. int spellbookLastPageBattle = 0;
  26. int spellbookLastPageAdvmap = 0;
  27. SpellSchool spellbookLastTabBattle = SpellSchool::ANY;
  28. SpellSchool spellbookLastTabAdvmap = SpellSchool::ANY;
  29. };
  30. /// Class that contains potentially serializeable state of a local player
  31. class PlayerLocalState
  32. {
  33. CPlayerInterface & owner;
  34. /// Currently selected object, can be town, hero or null
  35. const CArmedInstance * currentSelection;
  36. std::map<const CGHeroInstance *, CGPath> paths; //maps hero => selected path in adventure map
  37. std::vector<const CGHeroInstance *> sleepingHeroes; //if hero is in here, he's sleeping
  38. std::vector<const CGHeroInstance *> wanderingHeroes; //our heroes on the adventure map (not the garrisoned ones)
  39. std::vector<const CGTownInstance *> ownedTowns; //our towns on the adventure map
  40. PlayerSpellbookSetting spellbookSettings;
  41. void syncronizeState();
  42. public:
  43. explicit PlayerLocalState(CPlayerInterface & owner);
  44. bool isHeroSleeping(const CGHeroInstance * hero) const;
  45. void setHeroAsleep(const CGHeroInstance * hero);
  46. void setHeroAwaken(const CGHeroInstance * hero);
  47. const PlayerSpellbookSetting & getSpellbookSettings() const;
  48. void setSpellbookSettings(const PlayerSpellbookSetting & newSettings);
  49. const std::vector<const CGTownInstance *> & getOwnedTowns();
  50. const CGTownInstance * getOwnedTown(size_t index);
  51. void addOwnedTown(const CGTownInstance * hero);
  52. void removeOwnedTown(const CGTownInstance * hero);
  53. void swapOwnedTowns(size_t pos1, size_t pos2);
  54. const std::vector<const CGHeroInstance *> & getWanderingHeroes();
  55. const CGHeroInstance * getWanderingHero(size_t index);
  56. const CGHeroInstance * getNextWanderingHero(const CGHeroInstance * hero);
  57. void addWanderingHero(const CGHeroInstance * hero);
  58. void removeWanderingHero(const CGHeroInstance * hero);
  59. void swapWanderingHero(size_t pos1, size_t pos2);
  60. void setPath(const CGHeroInstance * h, const CGPath & path);
  61. bool setPath(const CGHeroInstance * h, const int3 & destination);
  62. const CGPath & getPath(const CGHeroInstance * h) const;
  63. bool hasPath(const CGHeroInstance * h) const;
  64. void removeLastNode(const CGHeroInstance * h);
  65. void erasePath(const CGHeroInstance * h);
  66. void verifyPath(const CGHeroInstance * h);
  67. /// Returns currently selected object
  68. const CGHeroInstance * getCurrentHero() const;
  69. const CGTownInstance * getCurrentTown() const;
  70. const CArmedInstance * getCurrentArmy() const;
  71. void serialize(JsonNode & dest) const;
  72. void deserialize(const JsonNode & source);
  73. /// Changes currently selected object
  74. void setSelection(const CArmedInstance *sel);
  75. };