1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-09-16 09:26:28 +02:00

Make bonus limiters/updaters/propagators const

All pointers held by bonus itself are now const.

To support OppositeSideLimiter (the only stateful limiter) bonuses now
hold their player owner instead.

No changes in functionality or mods
This commit is contained in:
Ivan Savenko
2025-06-03 19:23:40 +03:00
parent 4fda657296
commit 20f0b51912
11 changed files with 55 additions and 245 deletions

View File

@@ -399,13 +399,13 @@ static BonusParams convertDeprecatedBonus(const JsonNode &ability)
static TUpdaterPtr parseUpdater(const JsonNode & updaterJson)
{
const std::map<std::string, std::function<TUpdaterPtr()>> bonusUpdaterMap =
const std::map<std::string, std::shared_ptr<IUpdater>> bonusUpdaterMap =
{
{"TIMES_HERO_LEVEL", std::make_shared<TimesHeroLevelUpdater>},
{"TIMES_HERO_LEVEL_DIVIDE_STACK_LEVEL", std::make_shared<TimesHeroLevelDivideStackLevelUpdater>},
{"DIVIDE_STACK_LEVEL", std::make_shared<DivideStackLevelUpdater>},
{"TIMES_STACK_LEVEL", std::make_shared<TimesStackLevelUpdater>},
{"BONUS_OWNER_UPDATER", std::make_shared<OwnerUpdater>}
{"TIMES_HERO_LEVEL", std::make_shared<TimesHeroLevelUpdater>()},
{"TIMES_HERO_LEVEL_DIVIDE_STACK_LEVEL", std::make_shared<TimesHeroLevelDivideStackLevelUpdater>()},
{"DIVIDE_STACK_LEVEL", std::make_shared<DivideStackLevelUpdater>()},
{"TIMES_STACK_LEVEL", std::make_shared<TimesStackLevelUpdater>()},
{"BONUS_OWNER_UPDATER", std::make_shared<OwnerUpdater>()}
};
switch(updaterJson.getType())
@@ -414,7 +414,7 @@ static TUpdaterPtr parseUpdater(const JsonNode & updaterJson)
{
auto it = bonusUpdaterMap.find(updaterJson.String());
if (it != bonusUpdaterMap.end())
return it->second();
return it->second;
logGlobal->error("Unknown bonus updater type '%s'", updaterJson.String());
return nullptr;
@@ -458,7 +458,7 @@ std::shared_ptr<Bonus> JsonUtils::parseBonus(const JsonVector & ability_vec)
return b;
}
std::shared_ptr<ILimiter> JsonUtils::parseLimiter(const JsonNode & limiter)
std::shared_ptr<const ILimiter> JsonUtils::parseLimiter(const JsonNode & limiter)
{
switch(limiter.getType())
{

View File

@@ -24,7 +24,7 @@ namespace JsonUtils
std::shared_ptr<Bonus> parseBonus(const JsonVector & ability_vec);
std::shared_ptr<Bonus> parseBonus(const JsonNode & ability, const TextIdentifier & descriptionID = "");
bool parseBonus(const JsonNode & ability, Bonus * placement, const TextIdentifier & descriptionID = "");
std::shared_ptr<ILimiter> parseLimiter(const JsonNode & limiter);
std::shared_ptr<const ILimiter> parseLimiter(const JsonNode & limiter);
CSelector parseSelector(const JsonNode &ability);
}