CBankInstanceConstructor.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * CBankInstanceConstructor.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 "CDefaultObjectTypeHandler.h"
  12. #include "IObjectInfo.h"
  13. #include "../CCreatureSet.h"
  14. #include "../ResourceSet.h"
  15. #include "../json/JsonNode.h"
  16. #include "../mapObjects/CBank.h"
  17. VCMI_LIB_NAMESPACE_BEGIN
  18. struct BankConfig
  19. {
  20. ui32 chance = 0; //chance for this level being chosen
  21. std::vector<CStackBasicDescriptor> guards; //creature ID, amount
  22. ResourceSet resources; //resources given in case of victory
  23. std::vector<CStackBasicDescriptor> creatures; //creatures granted in case of victory (creature ID, amount)
  24. std::vector<ArtifactID> artifacts; //artifacts given in case of victory
  25. std::vector<SpellID> spells; // granted spell(s), for Pyramid
  26. template <typename Handler> void serialize(Handler &h)
  27. {
  28. h & chance;
  29. h & guards;
  30. h & resources;
  31. h & creatures;
  32. h & artifacts;
  33. h & spells;
  34. }
  35. };
  36. using TPossibleGuards = std::vector<std::pair<ui8, IObjectInfo::CArmyStructure>>;
  37. template <typename T>
  38. struct DLL_LINKAGE PossibleReward
  39. {
  40. int chance;
  41. T data;
  42. PossibleReward(int chance, const T & data) : chance(chance), data(data) {}
  43. };
  44. class DLL_LINKAGE CBankInfo : public IObjectInfo
  45. {
  46. const JsonVector & config;
  47. public:
  48. CBankInfo(const JsonVector & Config);
  49. TPossibleGuards getPossibleGuards(IGameCallback * cb) const;
  50. std::vector<PossibleReward<TResources>> getPossibleResourcesReward() const;
  51. std::vector<PossibleReward<CStackBasicDescriptor>> getPossibleCreaturesReward(IGameCallback * cb) const;
  52. bool givesResources() const override;
  53. bool givesArtifacts() const override;
  54. bool givesCreatures() const override;
  55. bool givesSpells() const override;
  56. };
  57. class CBankInstanceConstructor : public CDefaultObjectTypeHandler<CBank>
  58. {
  59. BankConfig generateConfig(IGameCallback * cb, const JsonNode & conf, CRandomGenerator & rng) const;
  60. JsonVector levels;
  61. // all banks of this type will be reset N days after clearing,
  62. si32 bankResetDuration = 0;
  63. // bank is only visitable from adjacent tile
  64. bool blockVisit;
  65. // bank is visitable from land even when bank is on water tile
  66. bool coastVisitable;
  67. protected:
  68. void initTypeData(const JsonNode & input) override;
  69. public:
  70. void randomizeObject(CBank * object, CRandomGenerator & rng) const override;
  71. bool hasNameTextID() const override;
  72. std::unique_ptr<IObjectInfo> getObjectInfo(std::shared_ptr<const ObjectTemplate> tmpl) const override;
  73. };
  74. VCMI_LIB_NAMESPACE_END