PlayerLocalState.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. class JsonNode;
  16. struct CGPath;
  17. class int3;
  18. VCMI_LIB_NAMESPACE_END
  19. class CPlayerInterface;
  20. struct PlayerSpellbookSetting
  21. {
  22. //on which page we left spellbook
  23. int spellbookLastPageBattle = 0;
  24. int spellbookLastPageAdvmap = 0;
  25. int spellbookLastTabBattle = 4;
  26. int spellbookLastTabAdvmap = 4;
  27. };
  28. /// Class that contains potentially serializeable state of a local player
  29. class PlayerLocalState
  30. {
  31. CPlayerInterface & owner;
  32. /// Currently selected object, can be town, hero or null
  33. const CArmedInstance * currentSelection;
  34. std::map<const CGHeroInstance *, CGPath> paths; //maps hero => selected path in adventure map
  35. std::vector<const CGHeroInstance *> sleepingHeroes; //if hero is in here, he's sleeping
  36. std::vector<const CGHeroInstance *> wanderingHeroes; //our heroes on the adventure map (not the garrisoned ones)
  37. std::vector<const CGTownInstance *> ownedTowns; //our towns on the adventure map
  38. PlayerSpellbookSetting spellbookSettings;
  39. void syncronizeState();
  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() const;
  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. void serialize(JsonNode & dest) const;
  70. void deserialize(const JsonNode & source);
  71. /// Changes currently selected object
  72. void setSelection(const CArmedInstance *sel);
  73. };