From what I have glimpsed in the code and on the wiki, on two types of bonuses can currently scale with level, and the code for this, in CGHeroInstance::Updatespecialty() is rather ugly. I would propose the following redesign for improved flexibility:
- In HeroSpecial, replace field growsWithLevel with two new floating-point fields valBase and valPerLevel.
- In CGHeroInstance::Updatespecialty() field val is then recalculated as val = floor(valBase + level * valPerLevel).
- Legacy json is converted into new structure when parsed.
Bonuses that don’t grow with level can be expressed by leaving valPerLevel = 0.
Issue that I can see with this:
- It won’t be possible to express original HMM3 bonus progression for creature specialty exactly, due to intermediate rounding.
- Need to be careful with rounding to ensure e.g. that valPerLevel = 0.1 evaluates to 1 at level 10, not as floor(10*0.099999999) = 0.