PlayerLocalState.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. void saveHeroPaths(std::map<const CGHeroInstance *, int3> & paths);
  28. void loadHeroPaths(std::map<const CGHeroInstance *, int3> & paths);
  29. public:
  30. struct SpellbookLastSetting
  31. {
  32. //on which page we left spellbook
  33. int spellbookLastPageBattle = 0;
  34. int spellbokLastPageAdvmap = 0;
  35. int spellbookLastTabBattle = 4;
  36. int spellbookLastTabAdvmap = 4;
  37. template <typename Handler> void serialize( Handler &h, const int version )
  38. {
  39. h & spellbookLastPageBattle;
  40. h & spellbokLastPageAdvmap;
  41. h & spellbookLastTabBattle;
  42. h & spellbookLastTabAdvmap;
  43. }
  44. } spellbookSettings;
  45. std::vector<const CGHeroInstance *> wanderingHeroes; //our heroes on the adventure map (not the garrisoned ones)
  46. std::vector<const CGTownInstance *> ownedTowns; //our towns on the adventure map
  47. explicit PlayerLocalState(CPlayerInterface & owner);
  48. bool isHeroSleeping(const CGHeroInstance * hero) const;
  49. void setHeroAsleep(const CGHeroInstance * hero);
  50. void setHeroAwaken(const CGHeroInstance * hero);
  51. void setPath(const CGHeroInstance *h, const CGPath & path);
  52. bool setPath(const CGHeroInstance *h, const int3 & destination);
  53. const CGPath & getPath(const CGHeroInstance *h) const;
  54. bool hasPath(const CGHeroInstance *h) const;
  55. void removeLastNode(const CGHeroInstance *h);
  56. void erasePath(const CGHeroInstance *h);
  57. void verifyPath(const CGHeroInstance *h);
  58. /// Returns currently selected object
  59. const CGHeroInstance * getCurrentHero() const;
  60. const CGTownInstance * getCurrentTown() const;
  61. const CArmedInstance * getCurrentArmy() const;
  62. /// Changes currently selected object
  63. void setSelection(const CArmedInstance *selection);
  64. template <typename Handler>
  65. void serialize( Handler &h, int version )
  66. {
  67. //WARNING: this code is broken and not used. See CClient::loadGame
  68. std::map<const CGHeroInstance *, int3> pathsMap; //hero -> dest
  69. if(h.saving)
  70. saveHeroPaths(pathsMap);
  71. h & pathsMap;
  72. if(!h.saving)
  73. loadHeroPaths(pathsMap);
  74. h & ownedTowns;
  75. h & wanderingHeroes;
  76. h & sleepingHeroes;
  77. }
  78. };