CBankInstanceConstructor.h 2.9 KB

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