PlayerLocalState.h 2.8 KB

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