mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-25 22:42:04 +02:00
Better support for Adela specialty (+new modding functionality for it)
Fixes Adela specialty that was apparently broken back in #1518 and replaced with logic that was clearly not tested - it was neither functional, nor it was following H3 behavior. - `HAS_ANOTHER_BONUS_LIMITER` now accepts `null` in place of bonus type, for cases when limiting is needed by bonus source or bonus subtype. This allows Adela Bless specialty to always work, irregardless of which bonuses are provided by Bless. - Implemented `DIVIDE_STACK_LEVEL` updater that functions same as `TIMES_STACK_LEVEL`, but it divides bonus value, instead of multiplying it (to make Adela specialty weaker for high-tier units, as in H3) - Implemented `TIMES_HERO_LEVEL_DIVIDE_STACK_LEVEL` updater that combines two existing updaters, to implement `val * heroLevel / unitLevel` formula needed for Adela specialty - Removed deprecated `ARMY_MOVEMENT` updater. Its functionality has already been removed in 1.6.X releases, and it was remaining only as a placeholder - Updated modding documentation to account for these changes & to remove some TODO's Fixed regression from #777 that could led to either duplicated bonuses or to multiple application of updaters. It introduced double-recursion - node parents were gathered recursively, and then bonuses were also collected recursively within each parent. This created situation where updater could be applied different number of times. For example, hero bonus that is propagated to unit in combat could be selected directly, or via hero->combat unit chain, or via hero->garrison unit->combat unit chains, leading to different calls to updaters if updater handles garrison unit node type
This commit is contained in:
@@ -328,8 +328,9 @@ static TUpdaterPtr parseUpdater(const JsonNode & updaterJson)
|
||||
const std::map<std::string, std::function<TUpdaterPtr()>> 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>},
|
||||
{"ARMY_MOVEMENT", std::make_shared<ArmyMovementUpdater>},
|
||||
{"BONUS_OWNER_UPDATER", std::make_shared<OwnerUpdater>}
|
||||
};
|
||||
|
||||
@@ -354,24 +355,6 @@ static TUpdaterPtr parseUpdater(const JsonNode & updaterJson)
|
||||
updater->stepSize = static_cast<int>(param[1].Integer());
|
||||
return updater;
|
||||
}
|
||||
else if (updaterJson["type"].String() == "ARMY_MOVEMENT")
|
||||
{
|
||||
auto updater = std::make_shared<ArmyMovementUpdater>();
|
||||
if(updaterJson["parameters"].isVector())
|
||||
{
|
||||
const auto & param = updaterJson["parameters"].Vector();
|
||||
if(param.size() < 4)
|
||||
logMod->warn("Invalid ARMY_MOVEMENT parameters, using default!");
|
||||
else
|
||||
{
|
||||
updater->base = static_cast<si32>(param.at(0).Integer());
|
||||
updater->divider = static_cast<si32>(param.at(1).Integer());
|
||||
updater->multiplier = static_cast<si32>(param.at(2).Integer());
|
||||
updater->max = static_cast<si32>(param.at(3).Integer());
|
||||
}
|
||||
return updater;
|
||||
}
|
||||
}
|
||||
else
|
||||
logMod->warn("Unknown updater type \"%s\"", updaterJson["type"].String());
|
||||
break;
|
||||
@@ -522,47 +505,52 @@ std::shared_ptr<ILimiter> JsonUtils::parseLimiter(const JsonNode & limiter)
|
||||
}
|
||||
else if(limiterType == "HAS_ANOTHER_BONUS_LIMITER")
|
||||
{
|
||||
std::string anotherBonusType = parameters[0].String();
|
||||
auto it = bonusNameMap.find(anotherBonusType);
|
||||
if(it == bonusNameMap.end())
|
||||
auto bonusLimiter = std::make_shared<HasAnotherBonusLimiter>();
|
||||
|
||||
if (!parameters[0].isNull())
|
||||
{
|
||||
logMod->error("Error: invalid ability type %s.", anotherBonusType);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto bonusLimiter = std::make_shared<HasAnotherBonusLimiter>();
|
||||
bonusLimiter->type = it->second;
|
||||
auto findSource = [&](const JsonNode & parameter)
|
||||
std::string anotherBonusType = parameters[0].String();
|
||||
auto it = bonusNameMap.find(anotherBonusType);
|
||||
if(it != bonusNameMap.end())
|
||||
{
|
||||
if(parameter.getType() == JsonNode::JsonType::DATA_STRUCT)
|
||||
bonusLimiter->type = it->second;
|
||||
}
|
||||
else
|
||||
{
|
||||
logMod->error("Error: invalid ability type %s.", anotherBonusType);
|
||||
}
|
||||
}
|
||||
|
||||
auto findSource = [&](const JsonNode & parameter)
|
||||
{
|
||||
if(parameter.getType() == JsonNode::JsonType::DATA_STRUCT)
|
||||
{
|
||||
auto sourceIt = bonusSourceMap.find(parameter["type"].String());
|
||||
if(sourceIt != bonusSourceMap.end())
|
||||
{
|
||||
auto sourceIt = bonusSourceMap.find(parameter["type"].String());
|
||||
if(sourceIt != bonusSourceMap.end())
|
||||
{
|
||||
bonusLimiter->source = sourceIt->second;
|
||||
bonusLimiter->isSourceRelevant = true;
|
||||
if(!parameter["id"].isNull()) {
|
||||
loadBonusSourceInstance(bonusLimiter->sid, bonusLimiter->source, parameter["id"]);
|
||||
bonusLimiter->isSourceIDRelevant = true;
|
||||
}
|
||||
bonusLimiter->source = sourceIt->second;
|
||||
bonusLimiter->isSourceRelevant = true;
|
||||
if(!parameter["id"].isNull()) {
|
||||
loadBonusSourceInstance(bonusLimiter->sid, bonusLimiter->source, parameter["id"]);
|
||||
bonusLimiter->isSourceIDRelevant = true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
if(parameters.size() > 1)
|
||||
{
|
||||
if(findSource(parameters[1]) && parameters.size() == 2)
|
||||
return bonusLimiter;
|
||||
else
|
||||
{
|
||||
loadBonusSubtype(bonusLimiter->subtype, bonusLimiter->type, parameters[1]);
|
||||
bonusLimiter->isSubtypeRelevant = true;
|
||||
if(parameters.size() > 2)
|
||||
findSource(parameters[2]);
|
||||
}
|
||||
}
|
||||
return bonusLimiter;
|
||||
return false;
|
||||
};
|
||||
if(parameters.size() > 1)
|
||||
{
|
||||
if(findSource(parameters[1]) && parameters.size() == 2)
|
||||
return bonusLimiter;
|
||||
else
|
||||
{
|
||||
loadBonusSubtype(bonusLimiter->subtype, bonusLimiter->type, parameters[1]);
|
||||
bonusLimiter->isSubtypeRelevant = true;
|
||||
if(parameters.size() > 2)
|
||||
findSource(parameters[2]);
|
||||
}
|
||||
}
|
||||
return bonusLimiter;
|
||||
}
|
||||
else if(limiterType == "CREATURE_ALIGNMENT_LIMITER")
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user