From 508d68f77cebaf5288b00684a7004d54bc7cf633 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Thu, 30 Mar 2023 22:29:58 +0300 Subject: [PATCH] Rewardables will use per-object name, if available --- lib/mapObjects/CRewardableConstructor.cpp | 14 ++++++++++++++ lib/mapObjects/CRewardableConstructor.h | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/lib/mapObjects/CRewardableConstructor.cpp b/lib/mapObjects/CRewardableConstructor.cpp index 7e860c074..cb3d0f741 100644 --- a/lib/mapObjects/CRewardableConstructor.cpp +++ b/lib/mapObjects/CRewardableConstructor.cpp @@ -16,6 +16,7 @@ #include "../CModHandler.h" #include "JsonRandom.h" #include "../IGameCallback.h" +#include "../CGeneralTextHandler.h" VCMI_LIB_NAMESPACE_BEGIN @@ -307,9 +308,22 @@ bool CRandomRewardObjectInfo::givesBonuses() const return testForKey(parameters, "bonuses"); } +const JsonNode & CRandomRewardObjectInfo::getParameters() const +{ + return parameters; +} + void CRewardableConstructor::initTypeData(const JsonNode & config) { objectInfo.init(config); + + if (!config["name"].isNull()) + VLC->generaltexth->registerString( config.meta, getNameTextID(), config["name"].String()); +} + +bool CRewardableConstructor::hasNameTextID() const +{ + return !objectInfo.getParameters()["name"].isNull(); } CGObjectInstance * CRewardableConstructor::create(std::shared_ptr tmpl) const diff --git a/lib/mapObjects/CRewardableConstructor.h b/lib/mapObjects/CRewardableConstructor.h index 6e41c7ce6..f47571410 100644 --- a/lib/mapObjects/CRewardableConstructor.h +++ b/lib/mapObjects/CRewardableConstructor.h @@ -28,6 +28,8 @@ class DLL_LINKAGE CRandomRewardObjectInfo : public IObjectInfo void configureReward(CRewardableObject * object, CRandomGenerator & rng, CRewardInfo & info, const JsonNode & source) const; void configureResetInfo(CRewardableObject * object, CRandomGenerator & rng, CRewardResetInfo & info, const JsonNode & source) const; public: + const JsonNode & getParameters() const; + bool givesResources() const override; bool givesExperience() const override; @@ -60,6 +62,8 @@ class DLL_LINKAGE CRewardableConstructor : public AObjectTypeHandler void initTypeData(const JsonNode & config) override; public: + bool hasNameTextID() const override; + CGObjectInstance * create(std::shared_ptr tmpl = nullptr) const override; void configureObject(CGObjectInstance * object, CRandomGenerator & rng) const override;