CGDwelling.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. protected:
  38. void serializeJsonOptions(JsonSerializeFormat & handler) override;
  39. private:
  40. FactionID randomizeFaction(IGameRandomizer & gameRandomizer);
  41. int randomizeLevel(vstd::RNG & rand);
  42. void pickRandomObject(IGameRandomizer & gameRandomizer) override;
  43. void initObj(IGameRandomizer & gameRandomizer) override;
  44. void onHeroVisit(IGameEventCallback & gameEvents, const CGHeroInstance * h) const override;
  45. void newTurn(IGameEventCallback & gameEvents, IGameRandomizer & gameRandomizer) const override;
  46. void setPropertyDer(ObjProperty what, ObjPropertyID identifier) override;
  47. void battleFinished(IGameEventCallback & gameEvents, const CGHeroInstance *hero, const BattleResult &result) const override;
  48. void blockingDialogAnswered(IGameEventCallback & gameEvents, const CGHeroInstance *hero, int32_t answer) const override;
  49. std::vector<Component> getPopupComponents(PlayerColor player) const override;
  50. bool wasVisited (PlayerColor player) const override;
  51. void updateGuards(IGameEventCallback & gameEvents) const;
  52. void heroAcceptsCreatures(IGameEventCallback & gameEvents, const CGHeroInstance *h) const;
  53. public:
  54. template <typename Handler> void serialize(Handler &h)
  55. {
  56. h & static_cast<CArmedInstance&>(*this);
  57. h & creatures;
  58. }
  59. };
  60. VCMI_LIB_NAMESPACE_END