CPlayerState.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * CPlayerState.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 <vcmi/Player.h>
  12. #include <vcmi/Team.h>
  13. #include "bonuses/Bonus.h"
  14. #include "bonuses/CBonusSystemNode.h"
  15. #include "ResourceSet.h"
  16. VCMI_LIB_NAMESPACE_BEGIN
  17. class CGHeroInstance;
  18. class CGTownInstance;
  19. class CGDwelling;
  20. struct QuestInfo;
  21. struct DLL_LINKAGE PlayerState : public CBonusSystemNode, public Player
  22. {
  23. public:
  24. PlayerColor color;
  25. bool human; //true if human controlled player, false for AI
  26. TeamID team;
  27. TResources resources;
  28. std::set<ObjectInstanceID> visitedObjects; // as a std::set, since most accesses here will be from visited status checks
  29. std::vector<ConstTransitivePtr<CGHeroInstance> > heroes;
  30. std::vector<ConstTransitivePtr<CGTownInstance> > towns;
  31. std::vector<ConstTransitivePtr<CGHeroInstance> > availableHeroes; //heroes available in taverns
  32. std::vector<ConstTransitivePtr<CGDwelling> > dwellings; //used for town growth
  33. std::vector<QuestInfo> quests; //store info about all received quests
  34. bool enteredWinningCheatCode, enteredLosingCheatCode; //if true, this player has entered cheat codes for loss / victory
  35. EPlayerStatus::EStatus status;
  36. std::optional<ui8> daysWithoutCastle;
  37. PlayerState();
  38. PlayerState(PlayerState && other) noexcept;
  39. ~PlayerState();
  40. std::string nodeName() const override;
  41. PlayerColor getId() const override;
  42. TeamID getTeam() const override;
  43. bool isHuman() const override;
  44. const IBonusBearer * getBonusBearer() const override;
  45. int getResourceAmount(int type) const override;
  46. int32_t getIndex() const override;
  47. int32_t getIconIndex() const override;
  48. std::string getJsonKey() const override;
  49. std::string getNameTranslated() const override;
  50. std::string getNameTextID() const override;
  51. void registerIcons(const IconRegistar & cb) const override;
  52. bool checkVanquished() const
  53. {
  54. return heroes.empty() && towns.empty();
  55. }
  56. template <typename Handler> void serialize(Handler &h, const int version)
  57. {
  58. h & color;
  59. h & human;
  60. h & team;
  61. h & resources;
  62. h & status;
  63. h & heroes;
  64. h & towns;
  65. h & availableHeroes;
  66. h & dwellings;
  67. h & quests;
  68. h & visitedObjects;
  69. h & status;
  70. h & daysWithoutCastle;
  71. h & enteredLosingCheatCode;
  72. h & enteredWinningCheatCode;
  73. h & static_cast<CBonusSystemNode&>(*this);
  74. }
  75. };
  76. struct DLL_LINKAGE TeamState : public CBonusSystemNode
  77. {
  78. public:
  79. TeamID id; //position in gameState::teams
  80. std::set<PlayerColor> players; // members of this team
  81. //TODO: boost::array, bool if possible
  82. std::shared_ptr<boost::multi_array<ui8, 3>> fogOfWarMap; //[z][x][y] true - visible, false - hidden
  83. TeamState();
  84. TeamState(TeamState && other) noexcept;
  85. template <typename Handler> void serialize(Handler &h, const int version)
  86. {
  87. h & id;
  88. h & players;
  89. h & fogOfWarMap;
  90. h & static_cast<CBonusSystemNode&>(*this);
  91. }
  92. };
  93. VCMI_LIB_NAMESPACE_END