TavernHeroesPool.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * TavernHeroesPool.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 "../GameConstants.h"
  12. #include "TavernSlot.h"
  13. #include "../mapObjects/CGObjectInstance.h"
  14. #include "../serializer/Serializeable.h"
  15. VCMI_LIB_NAMESPACE_BEGIN
  16. class CGHeroInstance;
  17. class CTown;
  18. class CHeroClass;
  19. class CGameState;
  20. class CSimpleArmy;
  21. class DLL_LINKAGE TavernHeroesPool : public Serializeable
  22. {
  23. CGameState * owner;
  24. struct TavernSlot
  25. {
  26. HeroTypeID hero;
  27. TavernHeroSlot slot;
  28. TavernSlotRole role;
  29. PlayerColor player;
  30. template <typename Handler> void serialize(Handler &h)
  31. {
  32. if (h.hasFeature(Handler::Version::NO_RAW_POINTERS_IN_SERIALIZER))
  33. {
  34. h & hero;
  35. }
  36. else
  37. {
  38. std::shared_ptr<CGObjectInstance> pointer;
  39. h & pointer;
  40. hero = HeroTypeID(pointer->subID);
  41. }
  42. h & slot;
  43. h & role;
  44. h & player;
  45. }
  46. };
  47. /// list of all heroes in pool, including those currently present in taverns
  48. std::vector<HeroTypeID> heroesPool;
  49. /// list of which players are able to purchase specific hero
  50. /// if hero is not present in list, he is available for everyone
  51. std::map<HeroTypeID, std::set<PlayerColor>> perPlayerAvailability;
  52. /// list of heroes currently available in taverns
  53. std::vector<TavernSlot> currentTavern;
  54. public:
  55. TavernHeroesPool() = default;
  56. TavernHeroesPool(CGameState * owner);
  57. void setGameState(CGameState * owner);
  58. /// Returns heroes currently available in tavern of a specific player
  59. std::vector<const CGHeroInstance *> getHeroesFor(PlayerColor color) const;
  60. /// returns heroes in pool without heroes that are available in taverns
  61. std::map<HeroTypeID, CGHeroInstance* > unusedHeroesFromPool() const;
  62. /// Returns true if hero is available to a specific player
  63. bool isHeroAvailableFor(HeroTypeID hero, PlayerColor color) const;
  64. TavernSlotRole getSlotRole(HeroTypeID hero) const;
  65. std::shared_ptr<CGHeroInstance> takeHeroFromPool(HeroTypeID hero);
  66. /// reset mana and movement points for all heroes in pool
  67. void onNewDay();
  68. void addHeroToPool(HeroTypeID hero);
  69. /// Marks hero as available to only specific set of players
  70. void setAvailability(HeroTypeID hero, std::set<PlayerColor> mask);
  71. /// Makes hero available in tavern of specified player
  72. void setHeroForPlayer(PlayerColor player, TavernHeroSlot slot, HeroTypeID hero, CSimpleArmy & army, TavernSlotRole role, bool replenishPoints);
  73. template <typename Handler> void serialize(Handler &h)
  74. {
  75. if (h.hasFeature(Handler::Version::NO_RAW_POINTERS_IN_SERIALIZER))
  76. h & heroesPool;
  77. else
  78. {
  79. std::map<HeroTypeID, std::shared_ptr<CGObjectInstance>> objectPtrs;
  80. h & objectPtrs;
  81. for (const auto & ptr : objectPtrs)
  82. heroesPool.push_back(ptr.first);
  83. }
  84. h & perPlayerAvailability;
  85. h & currentTavern;
  86. }
  87. };
  88. VCMI_LIB_NAMESPACE_END