1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-04-11 11:31:52 +02:00

Move mechanics factory

This commit is contained in:
AlexVinS 2014-11-25 14:58:42 +03:00
parent 226b737b6b
commit c8f1e6d1a1
3 changed files with 29 additions and 30 deletions

View File

@ -537,38 +537,9 @@ void CSpell::setupMechanics()
{
logGlobal->errorStream() << "Spell " << this->name << " mechanics already set";
delete mechanics;
mechanics = nullptr;
}
switch (id)
{
case SpellID::CLONE:
mechanics = new CloneMechanics(this);
break;
case SpellID::DISPEL_HELPFUL_SPELLS:
mechanics = new DispellHelpfulMechanics(this);
break;
case SpellID::SACRIFICE:
mechanics = new SacrificeMechanics(this);
break;
case SpellID::CHAIN_LIGHTNING:
mechanics = new ChainLightningMechanics(this);
break;
case SpellID::FIRE_WALL:
case SpellID::FORCE_FIELD:
mechanics = new WallMechanics(this);
break;
case SpellID::LAND_MINE:
case SpellID::QUICKSAND:
mechanics = new ObstacleMechanics(this);
default:
if(isRisingSpell())
mechanics = new SpecialRisingSpellMechanics(this);
else
mechanics = new DefaultSpellMechanics(this);
break;
}
mechanics = ISpellMechanics::createMechanics(this);
}
///CSpell::TargetInfo

View File

@ -127,6 +127,32 @@ ISpellMechanics::ISpellMechanics(CSpell * s):
}
ISpellMechanics * ISpellMechanics::createMechanics(CSpell* s)
{
switch (s->id)
{
case SpellID::CLONE:
return new CloneMechanics(s);
case SpellID::DISPEL_HELPFUL_SPELLS:
return new DispellHelpfulMechanics(s);
case SpellID::SACRIFICE:
return new SacrificeMechanics(s);
case SpellID::CHAIN_LIGHTNING:
return new ChainLightningMechanics(s);
case SpellID::FIRE_WALL:
case SpellID::FORCE_FIELD:
return new WallMechanics(s);
case SpellID::LAND_MINE:
case SpellID::QUICKSAND:
return new ObstacleMechanics(s);
default:
if(s->isRisingSpell())
return new SpecialRisingSpellMechanics(s);
else
return new DefaultSpellMechanics(s);
}
}
///DefaultSpellMechanics

View File

@ -51,6 +51,8 @@ public:
//virtual bool adventureCast(const SpellCastContext & context) const = 0;
virtual bool battleCast(const SpellCastEnvironment * env, const BattleSpellCastParameters & parameters) const = 0;
static ISpellMechanics * createMechanics(CSpell * s);
protected:
CSpell * owner;
};