CPlayerState.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. std::set<ObjectInstanceID> visitedObjects; // as a std::set, since most accesses here will be from visited status checks
  48. std::set<VisitedObjectGlobal> visitedObjectsGlobal;
  49. std::vector<ConstTransitivePtr<CGHeroInstance> > heroes;
  50. std::vector<ConstTransitivePtr<CGTownInstance> > towns;
  51. std::vector<ConstTransitivePtr<CGDwelling> > dwellings; //used for town growth
  52. std::vector<QuestInfo> quests; //store info about all received quests
  53. std::vector<Bonus> battleBonuses; //additional bonuses to be added during battle with neutrals
  54. bool cheated;
  55. bool enteredWinningCheatCode, enteredLosingCheatCode; //if true, this player has entered cheat codes for loss / victory
  56. EPlayerStatus status;
  57. std::optional<ui8> daysWithoutCastle;
  58. TurnTimerInfo turnTimer;
  59. PlayerState();
  60. ~PlayerState();
  61. std::string nodeName() const override;
  62. PlayerColor getId() const override;
  63. TeamID getTeam() const override;
  64. bool isHuman() const override;
  65. const IBonusBearer * getBonusBearer() const override;
  66. int getResourceAmount(int type) const override;
  67. int32_t getIndex() const override;
  68. int32_t getIconIndex() const override;
  69. std::string getJsonKey() const override;
  70. std::string getNameTranslated() const override;
  71. std::string getNameTextID() const override;
  72. void registerIcons(const IconRegistar & cb) const override;
  73. bool checkVanquished() const
  74. {
  75. return heroes.empty() && towns.empty();
  76. }
  77. template <typename Handler> void serialize(Handler &h)
  78. {
  79. h & color;
  80. h & human;
  81. h & team;
  82. h & resources;
  83. h & status;
  84. h & turnTimer;
  85. h & heroes;
  86. h & towns;
  87. h & dwellings;
  88. h & quests;
  89. h & visitedObjects;
  90. h & visitedObjectsGlobal;
  91. h & status;
  92. h & daysWithoutCastle;
  93. h & cheated;
  94. h & battleBonuses;
  95. h & enteredLosingCheatCode;
  96. h & enteredWinningCheatCode;
  97. h & static_cast<CBonusSystemNode&>(*this);
  98. }
  99. };
  100. struct DLL_LINKAGE TeamState : public CBonusSystemNode
  101. {
  102. public:
  103. TeamID id; //position in gameState::teams
  104. std::set<PlayerColor> players; // members of this team
  105. //TODO: boost::array, bool if possible
  106. std::unique_ptr<boost::multi_array<ui8, 3>> fogOfWarMap; //[z][x][y] true - visible, false - hidden
  107. TeamState();
  108. template <typename Handler> void serialize(Handler &h)
  109. {
  110. h & id;
  111. h & players;
  112. h & fogOfWarMap;
  113. h & static_cast<CBonusSystemNode&>(*this);
  114. }
  115. };
  116. VCMI_LIB_NAMESPACE_END