1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

cleaned up secondary skill bonus merging

This commit is contained in:
Henning Koehler 2017-08-27 15:35:04 +12:00
parent 06d2507371
commit 9bbfb57b93
4 changed files with 14 additions and 9 deletions

View File

@ -257,7 +257,7 @@ const std::shared_ptr<Bonus> CSkillHandler::defaultBonus(SecondarySkill skill, i
case SecondarySkill::FIRST_AID: case SecondarySkill::FIRST_AID:
bonusVal = 25 + 25 * level; break; bonusVal = 25 + 25 * level; break;
default: default:
valueType = Bonus::INDEPENDENT_MIN; break; break;
} }
return std::make_shared<Bonus>(Bonus::PERMANENT, bonusType, Bonus::SECONDARY_SKILL, bonusVal, skill, skill, valueType); return std::make_shared<Bonus>(Bonus::PERMANENT, bonusType, Bonus::SECONDARY_SKILL, bonusVal, skill, skill, valueType);

View File

@ -1166,6 +1166,11 @@ namespace Selector
return CSelectFieldEqual<Bonus::BonusSource>(&Bonus::source)(source); return CSelectFieldEqual<Bonus::BonusSource>(&Bonus::source)(source);
} }
CSelector DLL_LINKAGE valueType(Bonus::ValueType valType)
{
return CSelectFieldEqual<Bonus::ValueType>(&Bonus::valType)(valType);
}
DLL_LINKAGE CSelector all([](const Bonus * b){return true;}); DLL_LINKAGE CSelector all([](const Bonus * b){return true;});
DLL_LINKAGE CSelector none([](const Bonus * b){return false;}); DLL_LINKAGE CSelector none([](const Bonus * b){return false;});

View File

@ -950,6 +950,7 @@ namespace Selector
CSelector DLL_LINKAGE typeSubtypeInfo(Bonus::BonusType type, TBonusSubtype subtype, si32 info); CSelector DLL_LINKAGE typeSubtypeInfo(Bonus::BonusType type, TBonusSubtype subtype, si32 info);
CSelector DLL_LINKAGE source(Bonus::BonusSource source, ui32 sourceID); CSelector DLL_LINKAGE source(Bonus::BonusSource source, ui32 sourceID);
CSelector DLL_LINKAGE sourceTypeSel(Bonus::BonusSource source); CSelector DLL_LINKAGE sourceTypeSel(Bonus::BonusSource source);
CSelector DLL_LINKAGE valueType(Bonus::ValueType valType);
/** /**
* Selects all bonuses * Selects all bonuses

View File

@ -769,15 +769,14 @@ void CGHeroInstance::updateSkill(SecondarySkill which, int val)
auto skillBonus = (*VLC->skillh)[which]->getBonus(val); auto skillBonus = (*VLC->skillh)[which]->getBonus(val);
for (auto b : skillBonus) for (auto b : skillBonus)
{ {
// TODO: add standard method for joining bonuses, should match on valType as well // bonuses provided by different levels of a secondary skill are aggregated via max (not + as usual)
std::shared_ptr<Bonus> existing = getBonusLocalFirst(Selector::typeSubtype(b->type,b->subtype).And(Selector::source(Bonus::SECONDARY_SKILL, b->sid))); // different secondary skills providing the same bonus (e.g. ballistics might improve archery as well) are kept separate
std::shared_ptr<Bonus> existing = getBonusLocalFirst(
Selector::typeSubtype(b->type, b->subtype).And(
Selector::source(Bonus::SECONDARY_SKILL, b->sid).And(
Selector::valueType(b->valType))));
if(existing) if(existing)
{ vstd::amax(existing->val, b->val);
if(b->valType == Bonus::INDEPENDENT_MIN || b->valType == Bonus::BASE_NUMBER)
existing->val = b->val;
else
existing->val += b->val;
}
else else
addNewBonus(std::make_shared<Bonus>(*b)); addNewBonus(std::make_shared<Bonus>(*b));
} }