CPlayerState.h 2.9 KB

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