CPlayerState.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. std::vector<Bonus> battleBonuses; //additional bonuses to be added during battle with neutrals
  36. bool enteredWinningCheatCode, enteredLosingCheatCode; //if true, this player has entered cheat codes for loss / victory
  37. EPlayerStatus status;
  38. std::optional<ui8> daysWithoutCastle;
  39. TurnTimerInfo turnTimer;
  40. PlayerState();
  41. PlayerState(PlayerState && other) noexcept;
  42. ~PlayerState();
  43. std::string nodeName() const override;
  44. PlayerColor getId() const override;
  45. TeamID getTeam() const override;
  46. bool isHuman() const override;
  47. const IBonusBearer * getBonusBearer() const override;
  48. int getResourceAmount(int type) const override;
  49. int32_t getIndex() const override;
  50. int32_t getIconIndex() const override;
  51. std::string getJsonKey() const override;
  52. std::string getNameTranslated() const override;
  53. std::string getNameTextID() const override;
  54. void registerIcons(const IconRegistar & cb) const override;
  55. bool checkVanquished() const
  56. {
  57. return heroes.empty() && towns.empty();
  58. }
  59. template <typename Handler> void serialize(Handler &h, const int version)
  60. {
  61. h & color;
  62. h & human;
  63. h & team;
  64. h & resources;
  65. h & status;
  66. h & turnTimer;
  67. h & heroes;
  68. h & towns;
  69. h & dwellings;
  70. h & quests;
  71. h & visitedObjects;
  72. h & status;
  73. h & daysWithoutCastle;
  74. h & battleBonuses;
  75. h & enteredLosingCheatCode;
  76. h & enteredWinningCheatCode;
  77. h & static_cast<CBonusSystemNode&>(*this);
  78. }
  79. };
  80. struct DLL_LINKAGE TeamState : public CBonusSystemNode
  81. {
  82. public:
  83. TeamID id; //position in gameState::teams
  84. std::set<PlayerColor> players; // members of this team
  85. //TODO: boost::array, bool if possible
  86. std::shared_ptr<boost::multi_array<ui8, 3>> fogOfWarMap; //[z][x][y] true - visible, false - hidden
  87. TeamState();
  88. TeamState(TeamState && other) noexcept;
  89. template <typename Handler> void serialize(Handler &h, const int version)
  90. {
  91. h & id;
  92. h & players;
  93. h & fogOfWarMap;
  94. h & static_cast<CBonusSystemNode&>(*this);
  95. }
  96. };
  97. VCMI_LIB_NAMESPACE_END