CPlayerState.h 4.3 KB

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