CPlayerState.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. if(version < 760)
  61. {
  62. //was: h & getBonusList();
  63. BonusList junk;
  64. h & junk;
  65. }
  66. h & status;
  67. h & daysWithoutCastle;
  68. h & enteredLosingCheatCode;
  69. h & enteredWinningCheatCode;
  70. h & static_cast<CBonusSystemNode&>(*this);
  71. }
  72. };
  73. struct DLL_LINKAGE TeamState : public CBonusSystemNode
  74. {
  75. public:
  76. TeamID id; //position in gameState::teams
  77. std::set<PlayerColor> players; // members of this team
  78. //TODO: boost::array, bool if possible
  79. std::vector<std::vector<std::vector<ui8> > > fogOfWarMap; //true - visible, false - hidden
  80. TeamState();
  81. TeamState(TeamState && other);
  82. template <typename Handler> void serialize(Handler &h, const int version)
  83. {
  84. h & id;
  85. h & players;
  86. h & fogOfWarMap;
  87. h & static_cast<CBonusSystemNode&>(*this);
  88. }
  89. };