From 0cce1ef2f114cf7a4c81a04fd23edf067c1b2f22 Mon Sep 17 00:00:00 2001 From: AlexVinS Date: Fri, 3 Apr 2015 00:02:15 +0300 Subject: [PATCH] Move ANOTHER_ELEMENTAL_SUMMONED problem check to SummonMechanics class --- lib/CBattleCallback.cpp | 17 ----------------- lib/spells/BattleSpellMechanics.cpp | 22 ++++++++++++++++++++++ lib/spells/BattleSpellMechanics.h | 2 ++ 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/lib/CBattleCallback.cpp b/lib/CBattleCallback.cpp index e0c30ddaf..09a952536 100644 --- a/lib/CBattleCallback.cpp +++ b/lib/CBattleCallback.cpp @@ -1623,26 +1623,9 @@ ESpellCastProblem::ESpellCastProblem CBattleInfoCallback::battleCanCastThisSpell return ESpellCastProblem::NO_APPROPRIATE_TARGET; } - if(battleMaxSpellLevel() < spell->level) //effect like Recanter's Cloak or Orb of Inhibition return ESpellCastProblem::SPELL_LEVEL_LIMIT_EXCEEDED; - //IDs of summon elemental spells (fire, earth, water, air) - int spellIDs[] = { SpellID::SUMMON_FIRE_ELEMENTAL, SpellID::SUMMON_EARTH_ELEMENTAL, - SpellID::SUMMON_WATER_ELEMENTAL, SpellID::SUMMON_AIR_ELEMENTAL }; - //(fire, earth, water, air) elementals - int creIDs[] = {CreatureID::FIRE_ELEMENTAL, CreatureID::EARTH_ELEMENTAL, - CreatureID::WATER_ELEMENTAL, CreatureID::AIR_ELEMENTAL}; - - int arpos = vstd::find_pos(spellIDs, spell->id); - if(arpos < ARRAY_COUNT(spellIDs)) - { - //check if there are summoned elementals of other type - for(const CStack * st : battleAliveStacks(side)) - if(vstd::contains(st->state, EBattleStackState::SUMMONED) && st->getCreature()->idNumber != creIDs[arpos]) - return ESpellCastProblem::ANOTHER_ELEMENTAL_SUMMONED; - } - //checking if there exists an appropriate target switch(spell->getTargetType()) { diff --git a/lib/spells/BattleSpellMechanics.cpp b/lib/spells/BattleSpellMechanics.cpp index 3437adc8f..361d62f74 100644 --- a/lib/spells/BattleSpellMechanics.cpp +++ b/lib/spells/BattleSpellMechanics.cpp @@ -469,6 +469,28 @@ ESpellCastProblem::ESpellCastProblem SpecialRisingSpellMechanics::isImmuneByStac } ///SummonMechanics +ESpellCastProblem::ESpellCastProblem SummonMechanics::canBeCasted(const CBattleInfoCallback * cb, PlayerColor player) const +{ + const ui8 side = cb->playerToSide(player); + //IDs of summon elemental spells (fire, earth, water, air) + int spellIDs[] = { SpellID::SUMMON_FIRE_ELEMENTAL, SpellID::SUMMON_EARTH_ELEMENTAL, + SpellID::SUMMON_WATER_ELEMENTAL, SpellID::SUMMON_AIR_ELEMENTAL }; + //(fire, earth, water, air) elementals + int creIDs[] = {CreatureID::FIRE_ELEMENTAL, CreatureID::EARTH_ELEMENTAL, + CreatureID::WATER_ELEMENTAL, CreatureID::AIR_ELEMENTAL}; + + int arpos = vstd::find_pos(spellIDs, owner->id); + if(arpos < ARRAY_COUNT(spellIDs)) + { + //check if there are summoned elementals of other type + for(const CStack * st : cb->battleAliveStacks(side)) + if(vstd::contains(st->state, EBattleStackState::SUMMONED) && st->getCreature()->idNumber != creIDs[arpos]) + return ESpellCastProblem::ANOTHER_ELEMENTAL_SUMMONED; + } + + return ESpellCastProblem::OK; +} + void SummonMechanics::applyBattleEffects(const SpellCastEnvironment * env, BattleSpellCastParameters & parameters, SpellCastContext & ctx) const { //todo: make configurable diff --git a/lib/spells/BattleSpellMechanics.h b/lib/spells/BattleSpellMechanics.h index 9a26245b5..25a1f1dcb 100644 --- a/lib/spells/BattleSpellMechanics.h +++ b/lib/spells/BattleSpellMechanics.h @@ -112,6 +112,8 @@ class DLL_LINKAGE SummonMechanics : public DefaultSpellMechanics { public: SummonMechanics(CSpell * s): DefaultSpellMechanics(s){}; + + ESpellCastProblem::ESpellCastProblem canBeCasted(const CBattleInfoCallback * cb, PlayerColor player) const override; protected: void applyBattleEffects(const SpellCastEnvironment * env, BattleSpellCastParameters & parameters, SpellCastContext & ctx) const override; };