CBankInstanceConstructor.h 3.1 KB

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