CPlayerState.h 2.8 KB

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