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:
@@ -55,6 +55,10 @@ void CBonusSystemNode::getAllParents(TCNodes & out) const //retrieves list of pa
|
||||
{
|
||||
for(auto * parent : parentsToInherit)
|
||||
{
|
||||
// Diamond found! One of the parents of the targeted node can be discovered in two ways.
|
||||
// For example, a hero has been attached to both the player node and the global node (to which the player node is also attached).
|
||||
// This is illegal and can be a source of duplicate bonuses.
|
||||
assert(out.count(parent) == 0);
|
||||
out.insert(parent);
|
||||
parent->getAllParents(out);
|
||||
}
|
||||
@@ -63,13 +67,10 @@ void CBonusSystemNode::getAllParents(TCNodes & out) const //retrieves list of pa
|
||||
void CBonusSystemNode::getAllBonusesRec(BonusList &out, const CSelector & selector) const
|
||||
{
|
||||
BonusList beforeUpdate;
|
||||
TCNodes lparents;
|
||||
getAllParents(lparents);
|
||||
|
||||
for(const auto * parent : lparents)
|
||||
{
|
||||
for(const auto * parent : parentsToInherit)
|
||||
parent->getAllBonusesRec(beforeUpdate, selector);
|
||||
}
|
||||
|
||||
bonuses.getAllBonuses(beforeUpdate);
|
||||
|
||||
for(const auto & b : beforeUpdate)
|
||||
@@ -79,18 +80,7 @@ void CBonusSystemNode::getAllBonusesRec(BonusList &out, const CSelector & select
|
||||
? getUpdatedBonus(b, b->updater)
|
||||
: b;
|
||||
|
||||
//do not add bonus with updater
|
||||
bool bonusExists = false;
|
||||
for(const auto & bonus : out)
|
||||
{
|
||||
if (bonus == updated)
|
||||
bonusExists = true;
|
||||
if (bonus->updater && bonus->updater == updated->updater)
|
||||
bonusExists = true;
|
||||
}
|
||||
|
||||
if (!bonusExists)
|
||||
out.push_back(updated);
|
||||
out.push_back(updated);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user