CGDwelling.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * CGDwelling.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 "IOwnableObject.h"
  12. #include "army/CArmedInstance.h"
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. class CGDwelling;
  15. class DLL_LINKAGE CGDwellingRandomizationInfo
  16. {
  17. public:
  18. std::set<FactionID> allowedFactions;
  19. std::string instanceId;//vcmi map instance identifier
  20. int32_t identifier = 0;//h3m internal identifier
  21. uint8_t minLevel = 1;
  22. uint8_t maxLevel = 7; //minimal and maximal level of creature in dwelling: <1, 7>
  23. void serializeJson(JsonSerializeFormat & handler);
  24. };
  25. class DLL_LINKAGE CGDwelling : public CArmedInstance, public IOwnableObject
  26. {
  27. public:
  28. using TCreaturesSet = std::vector<std::pair<ui32, std::vector<CreatureID> > >;
  29. std::optional<CGDwellingRandomizationInfo> randomizationInfo; //random dwelling options; not serialized
  30. TCreaturesSet creatures; //creatures[level] -> <vector of alternative ids (base creature and upgrades, creatures amount>
  31. CGDwelling(IGameInfoCallback *cb, BonusNodeType nodeType);
  32. CGDwelling(IGameInfoCallback *cb);
  33. ~CGDwelling() override;
  34. const IOwnableObject * asOwnable() const final;
  35. ResourceSet dailyIncome() const override;
  36. std::vector<CreatureID> providedCreatures() const override;
  37. AnimationPath getKingdomOverviewImage() const;
  38. protected:
  39. void serializeJsonOptions(JsonSerializeFormat & handler) override;
  40. private:
  41. FactionID randomizeFaction(IGameRandomizer & gameRandomizer);
  42. int randomizeLevel(vstd::RNG & rand);
  43. void pickRandomObject(IGameRandomizer & gameRandomizer) override;
  44. void initObj(IGameRandomizer & gameRandomizer) override;
  45. void onHeroVisit(IGameEventCallback & gameEvents, const CGHeroInstance * h) const override;
  46. void newTurn(IGameEventCallback & gameEvents, IGameRandomizer & gameRandomizer) const override;
  47. void setPropertyDer(ObjProperty what, ObjPropertyID identifier) override;
  48. void battleFinished(IGameEventCallback & gameEvents, const CGHeroInstance *hero, const BattleResult &result) const override;
  49. void blockingDialogAnswered(IGameEventCallback & gameEvents, const CGHeroInstance *hero, int32_t answer) const override;
  50. std::vector<Component> getPopupComponents(PlayerColor player) const override;
  51. bool wasVisited (PlayerColor player) const override;
  52. void updateGuards(IGameEventCallback & gameEvents) const;
  53. void heroAcceptsCreatures(IGameEventCallback & gameEvents, const CGHeroInstance *h) const;
  54. public:
  55. template <typename Handler> void serialize(Handler &h)
  56. {
  57. h & static_cast<CArmedInstance&>(*this);
  58. h & creatures;
  59. }
  60. };
  61. VCMI_LIB_NAMESPACE_END