CGDwelling.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 "CArmedInstance.h"
  12. #include "IOwnableObject.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(IGameCallback *cb);
  32. ~CGDwelling() override;
  33. const IOwnableObject * asOwnable() const final;
  34. ResourceSet dailyIncome() const override;
  35. std::vector<CreatureID> providedCreatures() const override;
  36. protected:
  37. void serializeJsonOptions(JsonSerializeFormat & handler) override;
  38. private:
  39. FactionID randomizeFaction(vstd::RNG & rand);
  40. int randomizeLevel(vstd::RNG & rand);
  41. void pickRandomObject(vstd::RNG & rand) override;
  42. void initObj(vstd::RNG & rand) override;
  43. void onHeroVisit(const CGHeroInstance * h) const override;
  44. void newTurn(vstd::RNG & rand) const override;
  45. void setPropertyDer(ObjProperty what, ObjPropertyID identifier) override;
  46. void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override;
  47. void blockingDialogAnswered(const CGHeroInstance *hero, int32_t answer) const override;
  48. std::vector<Component> getPopupComponents(PlayerColor player) const override;
  49. void updateGuards() const;
  50. void heroAcceptsCreatures(const CGHeroInstance *h) const;
  51. public:
  52. template <typename Handler> void serialize(Handler &h)
  53. {
  54. h & static_cast<CArmedInstance&>(*this);
  55. h & creatures;
  56. }
  57. };
  58. VCMI_LIB_NAMESPACE_END