CPlayerState.h 2.6 KB

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