CPlayerState.h 2.9 KB

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