Skip to content
Permalink
Browse files

Fix mantiss 0002167

* also refactored summon mechanics
  • Loading branch information
alexvins committed Apr 11, 2015
1 parent e5b9f76 commit 2d8288d95a8c6e2c68d3f3f31467bd2e629cfa31
Showing with 21 additions and 40 deletions.
  1. +13 −38 lib/spells/BattleSpellMechanics.cpp
  2. +3 −1 lib/spells/BattleSpellMechanics.h
  3. +5 −1 lib/spells/ISpellMechanics.cpp
@@ -570,53 +570,29 @@ ESpellCastProblem::ESpellCastProblem SpecialRisingSpellMechanics::isImmuneByStac
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

auto otherSummoned = cb->battleGetStacksIf([side, this](const CStack * st)
{
//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 (st->attackerOwned == !side)
&& (vstd::contains(st->state, EBattleStackState::SUMMONED))
&& (st->getCreature()->idNumber != creatureToSummon);
});

if(!otherSummoned.empty())
return ESpellCastProblem::ANOTHER_ELEMENTAL_SUMMONED;

return ESpellCastProblem::OK;
}

void SummonMechanics::applyBattleEffects(const SpellCastEnvironment * env, BattleSpellCastParameters & parameters, SpellCastContext & ctx) const
{
//todo: make configurable
CreatureID creID = CreatureID::NONE;
switch(owner->id)
{
case SpellID::SUMMON_FIRE_ELEMENTAL:
creID = CreatureID::FIRE_ELEMENTAL;
break;
case SpellID::SUMMON_EARTH_ELEMENTAL:
creID = CreatureID::EARTH_ELEMENTAL;
break;
case SpellID::SUMMON_WATER_ELEMENTAL:
creID = CreatureID::WATER_ELEMENTAL;
break;
case SpellID::SUMMON_AIR_ELEMENTAL:
creID = CreatureID::AIR_ELEMENTAL;
break;
default:
env->complain("Unable to determine summoned creature");
return;
}

BattleStackAdded bsa;
bsa.creID = creID;
bsa.creID = creatureToSummon;
bsa.attacker = !(bool)parameters.casterSide;
bsa.summoned = true;
bsa.pos = parameters.cb->getAvaliableHex(creID, !(bool)parameters.casterSide); //TODO: unify it
bsa.pos = parameters.cb->getAvaliableHex(creatureToSummon, !(bool)parameters.casterSide); //TODO: unify it

//TODO stack casting -> probably power will be zero; set the proper number of creatures manually
int percentBonus = parameters.caster ? parameters.caster->valOfBonuses(Bonus::SPECIFIC_SPELL_DAMAGE, owner->id.toEnum()) : 0;
@@ -630,7 +606,6 @@ void SummonMechanics::applyBattleEffects(const SpellCastEnvironment * env, Battl
env->complain("Summoning didn't summon any!");
}


///TeleportMechanics
void TeleportMechanics::applyBattleEffects(const SpellCastEnvironment * env, BattleSpellCastParameters & parameters, SpellCastContext & ctx) const
{
@@ -124,11 +124,13 @@ class DLL_LINKAGE SpecialRisingSpellMechanics : public RisingSpellMechanics
class DLL_LINKAGE SummonMechanics : public DefaultSpellMechanics
{
public:
SummonMechanics(CSpell * s): DefaultSpellMechanics(s){};
SummonMechanics(CSpell * s, CreatureID cre): DefaultSpellMechanics(s), creatureToSummon(cre){};

ESpellCastProblem::ESpellCastProblem canBeCasted(const CBattleInfoCallback * cb, PlayerColor player) const override;
protected:
void applyBattleEffects(const SpellCastEnvironment * env, BattleSpellCastParameters & parameters, SpellCastContext & ctx) const override;
private:
CreatureID creatureToSummon;
};

class DLL_LINKAGE TeleportMechanics: public DefaultSpellMechanics
@@ -59,10 +59,13 @@ ISpellMechanics * ISpellMechanics::createMechanics(CSpell * s)
case SpellID::SACRIFICE:
return new SacrificeMechanics(s);
case SpellID::SUMMON_FIRE_ELEMENTAL:
return new SummonMechanics(s, CreatureID::FIRE_ELEMENTAL);
case SpellID::SUMMON_EARTH_ELEMENTAL:
return new SummonMechanics(s, CreatureID::EARTH_ELEMENTAL);
case SpellID::SUMMON_WATER_ELEMENTAL:
return new SummonMechanics(s, CreatureID::WATER_ELEMENTAL);
case SpellID::SUMMON_AIR_ELEMENTAL:
return new SummonMechanics(s);
return new SummonMechanics(s, CreatureID::AIR_ELEMENTAL);
case SpellID::TELEPORT:
return new TeleportMechanics(s);
case SpellID::SUMMON_BOAT:
@@ -89,3 +92,4 @@ ISpellMechanics * ISpellMechanics::createMechanics(CSpell * s)
return new DefaultSpellMechanics(s);
}
}

0 comments on commit 2d8288d

Please sign in to comment.
You can’t perform that action at this time.