PlayerLocalState.h 3.0 KB

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