CPlayerState.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. struct VisitedObjectGlobal
  26. {
  27. MapObjectID id;
  28. MapObjectSubID subID;
  29. bool operator < (const VisitedObjectGlobal & other) const
  30. {
  31. if (id != other.id)
  32. return id < other.id;
  33. else
  34. return subID < other.subID;
  35. }
  36. template <typename Handler> void serialize(Handler &h)
  37. {
  38. h & id;
  39. subID.serializeIdentifier(h, id);
  40. }
  41. };
  42. public:
  43. PlayerColor color;
  44. bool human; //true if human controlled player, false for AI
  45. TeamID team;
  46. TResources resources;
  47. /// list of objects that were "destroyed" by player, either via simple pick-up (e.g. resources) or defeated heroes or wandering monsters
  48. std::set<ObjectInstanceID> destroyedObjects;
  49. std::set<ObjectInstanceID> visitedObjects; // as a std::set, since most accesses here will be from visited status checks
  50. std::set<VisitedObjectGlobal> visitedObjectsGlobal;
  51. std::vector<ConstTransitivePtr<CGHeroInstance> > heroes;
  52. std::vector<ConstTransitivePtr<CGTownInstance> > towns;
  53. std::vector<ConstTransitivePtr<CGDwelling> > dwellings; //used for town growth
  54. std::vector<QuestInfo> quests; //store info about all received quests
  55. std::vector<Bonus> battleBonuses; //additional bonuses to be added during battle with neutrals
  56. std::map<uint32_t, std::map<ArtifactPosition, ArtifactID>> costumesArtifacts;
  57. bool cheated;
  58. bool enteredWinningCheatCode, enteredLosingCheatCode; //if true, this player has entered cheat codes for loss / victory
  59. EPlayerStatus status;
  60. std::optional<ui8> daysWithoutCastle;
  61. TurnTimerInfo turnTimer;
  62. PlayerState();
  63. ~PlayerState();
  64. std::string nodeName() const override;
  65. PlayerColor getId() const override;
  66. TeamID getTeam() const override;
  67. bool isHuman() const override;
  68. const IBonusBearer * getBonusBearer() const override;
  69. int getResourceAmount(int type) const override;
  70. int32_t getIndex() const override;
  71. int32_t getIconIndex() const override;
  72. std::string getJsonKey() const override;
  73. std::string getNameTranslated() const override;
  74. std::string getNameTextID() const override;
  75. void registerIcons(const IconRegistar & cb) const override;
  76. bool checkVanquished() const
  77. {
  78. return heroes.empty() && towns.empty();
  79. }
  80. template <typename Handler> void serialize(Handler &h)
  81. {
  82. h & color;
  83. h & human;
  84. h & team;
  85. h & resources;
  86. h & status;
  87. h & turnTimer;
  88. h & heroes;
  89. h & towns;
  90. h & dwellings;
  91. h & quests;
  92. h & visitedObjects;
  93. h & visitedObjectsGlobal;
  94. h & status;
  95. h & daysWithoutCastle;
  96. h & cheated;
  97. h & battleBonuses;
  98. h & costumesArtifacts;
  99. h & enteredLosingCheatCode;
  100. h & enteredWinningCheatCode;
  101. h & static_cast<CBonusSystemNode&>(*this);
  102. if (h.version >= Handler::Version::DESTROYED_OBJECTS)
  103. h & destroyedObjects;
  104. }
  105. };
  106. struct DLL_LINKAGE TeamState : public CBonusSystemNode
  107. {
  108. public:
  109. TeamID id; //position in gameState::teams
  110. std::set<PlayerColor> players; // members of this team
  111. //TODO: boost::array, bool if possible
  112. std::unique_ptr<boost::multi_array<ui8, 3>> fogOfWarMap; //[z][x][y] true - visible, false - hidden
  113. TeamState();
  114. template <typename Handler> void serialize(Handler &h)
  115. {
  116. h & id;
  117. h & players;
  118. h & fogOfWarMap;
  119. h & static_cast<CBonusSystemNode&>(*this);
  120. }
  121. };
  122. VCMI_LIB_NAMESPACE_END