mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-12 02:28:11 +02:00
split getBonusLocalFirst into two distinct method:
- const method getFirstBonus that returns single matching bonusToString - non-const method getLocalBonus that returns bonus from current node
This commit is contained in:
parent
496c13b34a
commit
6e629a6a5f
@ -530,7 +530,7 @@ void StackInfoBasicPanel::initializeData(const CStack * stack)
|
|||||||
if (hasGraphics)
|
if (hasGraphics)
|
||||||
{
|
{
|
||||||
//FIXME: support permanent duration
|
//FIXME: support permanent duration
|
||||||
int duration = stack->getBonusLocalFirst(Selector::source(BonusSource::SPELL_EFFECT, BonusSourceID(effect)))->turnsRemain;
|
int duration = stack->getFirstBonus(Selector::source(BonusSource::SPELL_EFFECT, BonusSourceID(effect)))->turnsRemain;
|
||||||
|
|
||||||
icons.push_back(std::make_shared<CAnimImage>(AnimationPath::builtin("SpellInt"), effect + 1, 0, firstPos.x + offset.x * printed, firstPos.y + offset.y * printed));
|
icons.push_back(std::make_shared<CAnimImage>(AnimationPath::builtin("SpellInt"), effect + 1, 0, firstPos.x + offset.x * printed, firstPos.y + offset.y * printed));
|
||||||
if(settings["general"]["enableUiEnhancements"].Bool())
|
if(settings["general"]["enableUiEnhancements"].Bool())
|
||||||
|
@ -601,7 +601,7 @@ void BattleWindow::bSpellf()
|
|||||||
{
|
{
|
||||||
//TODO: move to spell mechanics, add more information to spell cast problem
|
//TODO: move to spell mechanics, add more information to spell cast problem
|
||||||
//Handle Orb of Inhibition-like effects -> we want to display dialog with info, why casting is impossible
|
//Handle Orb of Inhibition-like effects -> we want to display dialog with info, why casting is impossible
|
||||||
auto blockingBonus = owner.currentHero()->getBonusLocalFirst(Selector::type()(BonusType::BLOCK_ALL_MAGIC));
|
auto blockingBonus = owner.currentHero()->getFirstBonus(Selector::type()(BonusType::BLOCK_ALL_MAGIC));
|
||||||
if (!blockingBonus)
|
if (!blockingBonus)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -225,7 +225,7 @@ CStackWindow::ActiveSpellsSection::ActiveSpellsSection(CStackWindow * owner, int
|
|||||||
spellText = CGI->generaltexth->allTexts[610]; //"%s, duration: %d rounds."
|
spellText = CGI->generaltexth->allTexts[610]; //"%s, duration: %d rounds."
|
||||||
boost::replace_first(spellText, "%s", spell->getNameTranslated());
|
boost::replace_first(spellText, "%s", spell->getNameTranslated());
|
||||||
//FIXME: support permanent duration
|
//FIXME: support permanent duration
|
||||||
int duration = battleStack->getBonusLocalFirst(Selector::source(BonusSource::SPELL_EFFECT, BonusSourceID(effect)))->turnsRemain;
|
int duration = battleStack->getFirstBonus(Selector::source(BonusSource::SPELL_EFFECT, BonusSourceID(effect)))->turnsRemain;
|
||||||
boost::replace_first(spellText, "%d", std::to_string(duration));
|
boost::replace_first(spellText, "%d", std::to_string(duration));
|
||||||
|
|
||||||
spellIcons.push_back(std::make_shared<CAnimImage>(AnimationPath::builtin("SpellInt"), effect + 1, 0, firstPos.x + offset.x * printed, firstPos.y + offset.y * printed));
|
spellIcons.push_back(std::make_shared<CAnimImage>(AnimationPath::builtin("SpellInt"), effect + 1, 0, firstPos.x + offset.x * printed, firstPos.y + offset.y * printed));
|
||||||
|
@ -62,7 +62,7 @@ void CCombinedArtifactInstance::addPlacementMap(CArtifactSet::ArtPlacementMap &
|
|||||||
SpellID CScrollArtifactInstance::getScrollSpellID() const
|
SpellID CScrollArtifactInstance::getScrollSpellID() const
|
||||||
{
|
{
|
||||||
auto artInst = static_cast<const CArtifactInstance*>(this);
|
auto artInst = static_cast<const CArtifactInstance*>(this);
|
||||||
const auto bonus = artInst->getBonusLocalFirst(Selector::type()(BonusType::SPELL));
|
const auto bonus = artInst->getFirstBonus(Selector::type()(BonusType::SPELL));
|
||||||
if(!bonus)
|
if(!bonus)
|
||||||
return SpellID::NONE;
|
return SpellID::NONE;
|
||||||
return bonus->subtype.as<SpellID>();
|
return bonus->subtype.as<SpellID>();
|
||||||
|
@ -20,7 +20,7 @@ VCMI_LIB_NAMESPACE_BEGIN
|
|||||||
std::atomic<int64_t> CBonusSystemNode::treeChanged(1);
|
std::atomic<int64_t> CBonusSystemNode::treeChanged(1);
|
||||||
constexpr bool CBonusSystemNode::cachingEnabled = true;
|
constexpr bool CBonusSystemNode::cachingEnabled = true;
|
||||||
|
|
||||||
std::shared_ptr<Bonus> CBonusSystemNode::getBonusLocalFirst(const CSelector & selector)
|
std::shared_ptr<Bonus> CBonusSystemNode::getLocalBonus(const CSelector & selector)
|
||||||
{
|
{
|
||||||
auto ret = bonuses.getFirst(selector);
|
auto ret = bonuses.getFirst(selector);
|
||||||
if(ret)
|
if(ret)
|
||||||
@ -28,7 +28,7 @@ std::shared_ptr<Bonus> CBonusSystemNode::getBonusLocalFirst(const CSelector & se
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<const Bonus> CBonusSystemNode::getBonusLocalFirst(const CSelector & selector) const
|
std::shared_ptr<const Bonus> CBonusSystemNode::getFirstBonus(const CSelector & selector) const
|
||||||
{
|
{
|
||||||
auto ret = bonuses.getFirst(selector);
|
auto ret = bonuses.getFirst(selector);
|
||||||
if(ret)
|
if(ret)
|
||||||
@ -38,7 +38,7 @@ std::shared_ptr<const Bonus> CBonusSystemNode::getBonusLocalFirst(const CSelecto
|
|||||||
getParents(lparents);
|
getParents(lparents);
|
||||||
for(const CBonusSystemNode *pname : lparents)
|
for(const CBonusSystemNode *pname : lparents)
|
||||||
{
|
{
|
||||||
ret = pname->getBonusLocalFirst(selector);
|
ret = pname->getFirstBonus(selector);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -88,10 +88,12 @@ public:
|
|||||||
TBonusListPtr limitBonuses(const BonusList &allBonuses) const; //same as above, returns out by val for convienence
|
TBonusListPtr limitBonuses(const BonusList &allBonuses) const; //same as above, returns out by val for convienence
|
||||||
TConstBonusListPtr getAllBonuses(const CSelector &selector, const CSelector &limit, const CBonusSystemNode *root = nullptr, const std::string &cachingStr = "") const override;
|
TConstBonusListPtr getAllBonuses(const CSelector &selector, const CSelector &limit, const CBonusSystemNode *root = nullptr, const std::string &cachingStr = "") const override;
|
||||||
void getParents(TCNodes &out) const; //retrieves list of parent nodes (nodes to inherit bonuses from),
|
void getParents(TCNodes &out) const; //retrieves list of parent nodes (nodes to inherit bonuses from),
|
||||||
std::shared_ptr<const Bonus> getBonusLocalFirst(const CSelector & selector) const;
|
|
||||||
|
|
||||||
//non-const interface
|
/// Returns first bonus matching selector
|
||||||
std::shared_ptr<Bonus> getBonusLocalFirst(const CSelector & selector);
|
std::shared_ptr<const Bonus> getFirstBonus(const CSelector & selector) const;
|
||||||
|
|
||||||
|
/// Provides write access to first bonus from this node that matches selector
|
||||||
|
std::shared_ptr<Bonus> getLocalBonus(const CSelector & selector);
|
||||||
|
|
||||||
void attachTo(CBonusSystemNode & parent);
|
void attachTo(CBonusSystemNode & parent);
|
||||||
void attachToSource(const CBonusSystemNode & parent);
|
void attachToSource(const CBonusSystemNode & parent);
|
||||||
|
@ -91,7 +91,7 @@ void CGameStateCampaign::trimCrossoverHeroesParameters(std::vector<CampaignHeroR
|
|||||||
.And(Selector::subtype()(BonusSubtypeID(g)))
|
.And(Selector::subtype()(BonusSubtypeID(g)))
|
||||||
.And(Selector::sourceType()(BonusSource::HERO_BASE_SKILL));
|
.And(Selector::sourceType()(BonusSource::HERO_BASE_SKILL));
|
||||||
|
|
||||||
cgh->getBonusLocalFirst(sel)->val = cgh->type->heroClass->primarySkillInitial[g.getNum()];
|
cgh->getLocalBonus(sel)->val = cgh->type->heroClass->primarySkillInitial[g.getNum()];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1412,7 +1412,7 @@ void CGHeroInstance::setPrimarySkill(PrimarySkill primarySkill, si64 value, ui8
|
|||||||
{
|
{
|
||||||
if(primarySkill < PrimarySkill::EXPERIENCE)
|
if(primarySkill < PrimarySkill::EXPERIENCE)
|
||||||
{
|
{
|
||||||
auto skill = getBonusLocalFirst(Selector::type()(BonusType::PRIMARY_SKILL)
|
auto skill = getLocalBonus(Selector::type()(BonusType::PRIMARY_SKILL)
|
||||||
.And(Selector::subtype()(BonusSubtypeID(primarySkill)))
|
.And(Selector::subtype()(BonusSubtypeID(primarySkill)))
|
||||||
.And(Selector::sourceType()(BonusSource::HERO_BASE_SKILL)));
|
.And(Selector::sourceType()(BonusSource::HERO_BASE_SKILL)));
|
||||||
assert(skill);
|
assert(skill);
|
||||||
|
@ -929,7 +929,7 @@ void CGArtifact::serializeJsonOptions(JsonSerializeFormat& handler)
|
|||||||
|
|
||||||
if(handler.saving && ID == Obj::SPELL_SCROLL)
|
if(handler.saving && ID == Obj::SPELL_SCROLL)
|
||||||
{
|
{
|
||||||
const std::shared_ptr<Bonus> b = storedArtifact->getBonusLocalFirst(Selector::type()(BonusType::SPELL));
|
const auto & b = storedArtifact->getFirstBonus(Selector::type()(BonusType::SPELL));
|
||||||
SpellID spellId(b->subtype.as<SpellID>());
|
SpellID spellId(b->subtype.as<SpellID>());
|
||||||
|
|
||||||
handler.serializeId("spell", spellId, SpellID::NONE);
|
handler.serializeId("spell", spellId, SpellID::NONE);
|
||||||
|
@ -2147,7 +2147,7 @@ void BattleTriggerEffect::applyGs(CGameState * gs) const
|
|||||||
}
|
}
|
||||||
case BonusType::POISON:
|
case BonusType::POISON:
|
||||||
{
|
{
|
||||||
auto b = st->getBonusLocalFirst(Selector::source(BonusSource::SPELL_EFFECT, SpellID(SpellID::POISON))
|
auto b = st->getLocalBonus(Selector::source(BonusSource::SPELL_EFFECT, SpellID(SpellID::POISON))
|
||||||
.And(Selector::type()(BonusType::STACK_HEALTH)));
|
.And(Selector::type()(BonusType::STACK_HEALTH)));
|
||||||
if (b)
|
if (b)
|
||||||
b->val = val;
|
b->val = val;
|
||||||
|
@ -475,7 +475,7 @@ bool BaseMechanics::adaptProblem(ESpellCastProblem source, Problem & target) con
|
|||||||
return adaptGenericProblem(target);
|
return adaptGenericProblem(target);
|
||||||
|
|
||||||
//Recanter's Cloak or similar effect. Try to retrieve bonus
|
//Recanter's Cloak or similar effect. Try to retrieve bonus
|
||||||
const auto b = hero->getBonusLocalFirst(Selector::type()(BonusType::BLOCK_MAGIC_ABOVE));
|
const auto b = hero->getFirstBonus(Selector::type()(BonusType::BLOCK_MAGIC_ABOVE));
|
||||||
//TODO what about other values and non-artifact sources?
|
//TODO what about other values and non-artifact sources?
|
||||||
if(b && b->val == 2 && b->source == BonusSource::ARTIFACT)
|
if(b && b->val == 2 && b->source == BonusSource::ARTIFACT)
|
||||||
{
|
{
|
||||||
|
@ -112,9 +112,9 @@ void Timed::apply(ServerCallback * server, const Mechanics * m, const EffectTarg
|
|||||||
const auto *casterHero = dynamic_cast<const CGHeroInstance *>(m->caster);
|
const auto *casterHero = dynamic_cast<const CGHeroInstance *>(m->caster);
|
||||||
if(casterHero)
|
if(casterHero)
|
||||||
{
|
{
|
||||||
peculiarBonus = casterHero->getBonusLocalFirst(Selector::typeSubtype(BonusType::SPECIAL_PECULIAR_ENCHANT, BonusSubtypeID(m->getSpellId())));
|
peculiarBonus = casterHero->getFirstBonus(Selector::typeSubtype(BonusType::SPECIAL_PECULIAR_ENCHANT, BonusSubtypeID(m->getSpellId())));
|
||||||
addedValueBonus = casterHero->getBonusLocalFirst(Selector::typeSubtype(BonusType::SPECIAL_ADD_VALUE_ENCHANT, BonusSubtypeID(m->getSpellId())));
|
addedValueBonus = casterHero->getFirstBonus(Selector::typeSubtype(BonusType::SPECIAL_ADD_VALUE_ENCHANT, BonusSubtypeID(m->getSpellId())));
|
||||||
fixedValueBonus = casterHero->getBonusLocalFirst(Selector::typeSubtype(BonusType::SPECIAL_FIXED_VALUE_ENCHANT, BonusSubtypeID(m->getSpellId())));
|
fixedValueBonus = casterHero->getFirstBonus(Selector::typeSubtype(BonusType::SPECIAL_FIXED_VALUE_ENCHANT, BonusSubtypeID(m->getSpellId())));
|
||||||
}
|
}
|
||||||
//TODO: does hero specialty should affects his stack casting spells?
|
//TODO: does hero specialty should affects his stack casting spells?
|
||||||
|
|
||||||
|
@ -886,7 +886,7 @@ void CGameHandler::onNewTurn()
|
|||||||
{
|
{
|
||||||
if (getPlayerStatus(player.first) == EPlayerStatus::INGAME &&
|
if (getPlayerStatus(player.first) == EPlayerStatus::INGAME &&
|
||||||
getPlayerRelations(player.first, t->tempOwner) == PlayerRelations::ENEMIES)
|
getPlayerRelations(player.first, t->tempOwner) == PlayerRelations::ENEMIES)
|
||||||
changeFogOfWar(t->visitablePos(), t->getBonusLocalFirst(Selector::type()(BonusType::DARKNESS))->val, player.first, ETileVisibility::HIDDEN);
|
changeFogOfWar(t->visitablePos(), t->getFirstBonus(Selector::type()(BonusType::DARKNESS))->val, player.first, ETileVisibility::HIDDEN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -404,7 +404,7 @@ bool BattleActionProcessor::doCatapultAction(const CBattleInfoCallback & battle,
|
|||||||
if (!canStackAct(battle, stack))
|
if (!canStackAct(battle, stack))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
std::shared_ptr<const Bonus> catapultAbility = stack->getBonusLocalFirst(Selector::type()(BonusType::CATAPULT));
|
std::shared_ptr<const Bonus> catapultAbility = stack->getFirstBonus(Selector::type()(BonusType::CATAPULT));
|
||||||
if(!catapultAbility || catapultAbility->subtype == BonusSubtypeID())
|
if(!catapultAbility || catapultAbility->subtype == BonusSubtypeID())
|
||||||
{
|
{
|
||||||
gameHandler->complain("We do not know how to shoot :P");
|
gameHandler->complain("We do not know how to shoot :P");
|
||||||
@ -492,7 +492,7 @@ bool BattleActionProcessor::doHealAction(const CBattleInfoCallback & battle, con
|
|||||||
}
|
}
|
||||||
|
|
||||||
const battle::Unit * destStack = nullptr;
|
const battle::Unit * destStack = nullptr;
|
||||||
std::shared_ptr<const Bonus> healerAbility = stack->getBonusLocalFirst(Selector::type()(BonusType::HEALER));
|
std::shared_ptr<const Bonus> healerAbility = stack->getFirstBonus(Selector::type()(BonusType::HEALER));
|
||||||
|
|
||||||
if(target.at(0).unitValue)
|
if(target.at(0).unitValue)
|
||||||
destStack = target.at(0).unitValue;
|
destStack = target.at(0).unitValue;
|
||||||
@ -975,7 +975,7 @@ void BattleActionProcessor::makeAttack(const CBattleInfoCallback & battle, const
|
|||||||
drainedLife += applyBattleEffects(battle, bat, attackerState, fireShield, stack, distance, true);
|
drainedLife += applyBattleEffects(battle, bat, attackerState, fireShield, stack, distance, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<const Bonus> bonus = attacker->getBonusLocalFirst(Selector::type()(BonusType::SPELL_LIKE_ATTACK));
|
std::shared_ptr<const Bonus> bonus = attacker->getFirstBonus(Selector::type()(BonusType::SPELL_LIKE_ATTACK));
|
||||||
if(bonus && ranged) //TODO: make it work in melee?
|
if(bonus && ranged) //TODO: make it work in melee?
|
||||||
{
|
{
|
||||||
//this is need for displaying hit animation
|
//this is need for displaying hit animation
|
||||||
|
@ -664,7 +664,7 @@ void BattleFlowProcessor::stackTurnTrigger(const CBattleInfoCallback & battle, c
|
|||||||
|
|
||||||
if (st->hasBonusOfType(BonusType::POISON))
|
if (st->hasBonusOfType(BonusType::POISON))
|
||||||
{
|
{
|
||||||
std::shared_ptr<const Bonus> b = st->getBonusLocalFirst(Selector::source(BonusSource::SPELL_EFFECT, BonusSourceID(SpellID(SpellID::POISON))).And(Selector::type()(BonusType::STACK_HEALTH)));
|
std::shared_ptr<const Bonus> b = st->getFirstBonus(Selector::source(BonusSource::SPELL_EFFECT, BonusSourceID(SpellID(SpellID::POISON))).And(Selector::type()(BonusType::STACK_HEALTH)));
|
||||||
if (b) //TODO: what if not?...
|
if (b) //TODO: what if not?...
|
||||||
{
|
{
|
||||||
bte.val = std::max (b->val - 10, -(st->valOfBonuses(BonusType::POISON)));
|
bte.val = std::max (b->val - 10, -(st->valOfBonuses(BonusType::POISON)));
|
||||||
|
Loading…
Reference in New Issue
Block a user