CBankInstanceConstructor.h 2.7 KB

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