From 5d64da9b6c07bf10ae014dc0b6cc90210da5eb64 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Thu, 3 Oct 2024 12:35:15 +0000 Subject: [PATCH] Fixes randomization of Witch Hut preconfigured in map editor --- lib/mapObjectConstructors/CRewardableConstructor.cpp | 5 +++-- lib/mapObjectConstructors/CRewardableConstructor.h | 2 +- lib/mapObjects/CRewardableObject.cpp | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/mapObjectConstructors/CRewardableConstructor.cpp b/lib/mapObjectConstructors/CRewardableConstructor.cpp index 3fbcba73d..80d842a47 100644 --- a/lib/mapObjectConstructors/CRewardableConstructor.cpp +++ b/lib/mapObjectConstructors/CRewardableConstructor.cpp @@ -43,9 +43,10 @@ CGObjectInstance * CRewardableConstructor::create(IGameCallback * cb, std::share return ret; } -Rewardable::Configuration CRewardableConstructor::generateConfiguration(IGameCallback * cb, vstd::RNG & rand, MapObjectID objectID) const +Rewardable::Configuration CRewardableConstructor::generateConfiguration(IGameCallback * cb, vstd::RNG & rand, MapObjectID objectID, const std::map & presetVariables) const { Rewardable::Configuration result; + result.variables.preset = presetVariables; objectInfo.configureObject(result, rand, cb); for(auto & rewardInfo : result.info) @@ -67,7 +68,7 @@ void CRewardableConstructor::configureObject(CGObjectInstance * object, vstd::RN if (!rewardableObject) throw std::runtime_error("Object " + std::to_string(object->getObjGroupIndex()) + ", " + std::to_string(object->getObjTypeIndex()) + " is not a rewardable object!" ); - rewardableObject->configuration = generateConfiguration(object->cb, rng, object->ID); + rewardableObject->configuration = generateConfiguration(object->cb, rng, object->ID, rewardableObject->configuration.variables.preset); rewardableObject->initializeGuards(); if (rewardableObject->configuration.info.empty()) diff --git a/lib/mapObjectConstructors/CRewardableConstructor.h b/lib/mapObjectConstructors/CRewardableConstructor.h index eab0e500a..a9f30d500 100644 --- a/lib/mapObjectConstructors/CRewardableConstructor.h +++ b/lib/mapObjectConstructors/CRewardableConstructor.h @@ -31,7 +31,7 @@ public: std::unique_ptr getObjectInfo(std::shared_ptr tmpl) const override; - Rewardable::Configuration generateConfiguration(IGameCallback * cb, vstd::RNG & rand, MapObjectID objectID) const; + Rewardable::Configuration generateConfiguration(IGameCallback * cb, vstd::RNG & rand, MapObjectID objectID, const std::map & presetVariables) const; }; VCMI_LIB_NAMESPACE_END diff --git a/lib/mapObjects/CRewardableObject.cpp b/lib/mapObjects/CRewardableObject.cpp index 44ecf20a6..86c43cc8d 100644 --- a/lib/mapObjects/CRewardableObject.cpp +++ b/lib/mapObjects/CRewardableObject.cpp @@ -329,7 +329,7 @@ void CRewardableObject::newTurn(vstd::RNG & rand) const if (configuration.resetParameters.rewards) { auto handler = std::dynamic_pointer_cast(getObjectHandler()); - auto newConfiguration = handler->generateConfiguration(cb, rand, ID); + auto newConfiguration = handler->generateConfiguration(cb, rand, ID, configuration.variables.preset); cb->setRewardableObjectConfiguration(id, newConfiguration); } if (configuration.resetParameters.visitors)