PlayerLocalState.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 spellbokLastPageAdvmap = 0;
  37. int spellbookLastTabBattle = 4;
  38. int spellbookLastTabAdvmap = 4;
  39. template<typename Handler>
  40. void serialize(Handler & h, const int version)
  41. {
  42. h & spellbookLastPageBattle;
  43. h & spellbokLastPageAdvmap;
  44. h & spellbookLastTabBattle;
  45. h & spellbookLastTabAdvmap;
  46. }
  47. } spellbookSettings;
  48. explicit PlayerLocalState(CPlayerInterface & owner);
  49. bool isHeroSleeping(const CGHeroInstance * hero) const;
  50. void setHeroAsleep(const CGHeroInstance * hero);
  51. void setHeroAwaken(const CGHeroInstance * hero);
  52. const std::vector<const CGTownInstance *> & getOwnedTowns();
  53. const CGTownInstance * getOwnedTown(size_t index);
  54. void addOwnedTown(const CGTownInstance * hero);
  55. void removeOwnedTown(const CGTownInstance * hero);
  56. void swapOwnedTowns(int pos1, int pos2);
  57. const std::vector<const CGHeroInstance *> & getWanderingHeroes();
  58. const CGHeroInstance * getWanderingHero(size_t index);
  59. const CGHeroInstance * getNextWanderingHero(const CGHeroInstance * hero);
  60. void addWanderingHero(const CGHeroInstance * hero);
  61. void removeWanderingHero(const CGHeroInstance * hero);
  62. void swapWanderingHero(int pos1, int pos2);
  63. void setPath(const CGHeroInstance * h, const CGPath & path);
  64. bool setPath(const CGHeroInstance * h, const int3 & destination);
  65. const CGPath & getPath(const CGHeroInstance * h) const;
  66. bool hasPath(const CGHeroInstance * h) const;
  67. void removeLastNode(const CGHeroInstance * h);
  68. void erasePath(const CGHeroInstance * h);
  69. void verifyPath(const CGHeroInstance * h);
  70. /// Returns currently selected object
  71. const CGHeroInstance * getCurrentHero() const;
  72. const CGTownInstance * getCurrentTown() const;
  73. const CArmedInstance * getCurrentArmy() const;
  74. /// Changes currently selected object
  75. void setSelection(const CArmedInstance *sel);
  76. template<typename Handler>
  77. void serialize(Handler & h, int version)
  78. {
  79. //WARNING: this code is broken and not used. See CClient::loadGame
  80. std::map<const CGHeroInstance *, int3> pathsMap; //hero -> dest
  81. if(h.saving)
  82. saveHeroPaths(pathsMap);
  83. h & pathsMap;
  84. if(!h.saving)
  85. loadHeroPaths(pathsMap);
  86. h & ownedTowns;
  87. h & wanderingHeroes;
  88. h & sleepingHeroes;
  89. }
  90. };