PlayerLocalState.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. SpellID currentSpell;
  42. void syncronizeState();
  43. public:
  44. explicit PlayerLocalState(CPlayerInterface & owner);
  45. bool isHeroSleeping(const CGHeroInstance * hero) const;
  46. void setHeroAsleep(const CGHeroInstance * hero);
  47. void setHeroAwaken(const CGHeroInstance * hero);
  48. const PlayerSpellbookSetting & getSpellbookSettings() const;
  49. void setSpellbookSettings(const PlayerSpellbookSetting & newSettings);
  50. const std::vector<const CGTownInstance *> & getOwnedTowns();
  51. const CGTownInstance * getOwnedTown(size_t index);
  52. void addOwnedTown(const CGTownInstance * hero);
  53. void removeOwnedTown(const CGTownInstance * hero);
  54. void swapOwnedTowns(size_t pos1, size_t pos2);
  55. const std::vector<const CGHeroInstance *> & getWanderingHeroes();
  56. const CGHeroInstance * getWanderingHero(size_t index);
  57. const CGHeroInstance * getNextWanderingHero(const CGHeroInstance * hero);
  58. void addWanderingHero(const CGHeroInstance * hero);
  59. void removeWanderingHero(const CGHeroInstance * hero);
  60. void swapWanderingHero(size_t pos1, size_t pos2);
  61. void setPath(const CGHeroInstance * h, const CGPath & path);
  62. bool setPath(const CGHeroInstance * h, const int3 & destination);
  63. const CGPath & getPath(const CGHeroInstance * h) const;
  64. bool hasPath(const CGHeroInstance * h) const;
  65. void removeLastNode(const CGHeroInstance * h);
  66. void erasePath(const CGHeroInstance * h);
  67. void verifyPath(const CGHeroInstance * h);
  68. /// Returns currently selected object
  69. const CGHeroInstance * getCurrentHero() const;
  70. const CGTownInstance * getCurrentTown() const;
  71. const CArmedInstance * getCurrentArmy() const;
  72. // returns currently cast spell, if any
  73. SpellID getCurrentSpell() const;
  74. void setCurrentSpell(SpellID castedSpell);
  75. void serialize(JsonNode & dest) const;
  76. void deserialize(const JsonNode & source);
  77. /// Changes currently selected object
  78. void setSelection(const CArmedInstance *sel);
  79. };