1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-26 22:57:00 +02:00
vcmi/lib/spells/ISpellMechanics.cpp

189 lines
5.8 KiB
C++
Raw Normal View History

/*
2015-02-02 11:22:19 +02:00
* ISpellMechanics.cpp, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#include "StdInc.h"
#include "ISpellMechanics.h"
2015-09-17 07:42:30 +02:00
#include "../BattleState.h"
#include "../NetPacks.h"
2015-02-02 11:22:19 +02:00
#include "CDefaultSpellMechanics.h"
2015-02-02 11:22:19 +02:00
#include "AdventureSpellMechanics.h"
#include "BattleSpellMechanics.h"
#include "CreatureSpellMechanics.h"
BattleSpellCastParameters::Destination::Destination(const CStack * destination):
stackValue(destination),
hexValue(destination->position)
{
2016-02-15 12:34:37 +02:00
}
BattleSpellCastParameters::Destination::Destination(const BattleHex & destination):
stackValue(nullptr),
2016-02-15 12:34:37 +02:00
hexValue(destination)
{
2016-02-15 12:34:37 +02:00
}
2016-09-06 12:33:11 +02:00
BattleSpellCastParameters::BattleSpellCastParameters(const BattleInfo * cb, const ISpellCaster * caster, const CSpell * spell_)
: spell(spell_), cb(cb), caster(caster), casterColor(caster->getOwner()), casterSide(cb->whatSide(casterColor)),
casterHero(nullptr),
2016-09-06 11:26:01 +02:00
mode(ECastingMode::HERO_CASTING), casterStack(nullptr),
2016-09-10 08:37:18 +02:00
spellLvl(0), effectLevel(0), effectPower(0), enchantPower(0), effectValue(0)
2015-09-16 09:50:33 +02:00
{
2015-09-17 07:42:30 +02:00
casterStack = dynamic_cast<const CStack *>(caster);
casterHero = dynamic_cast<const CGHeroInstance *>(caster);
2016-09-06 12:33:11 +02:00
spellLvl = caster->getSpellSchoolLevel(spell);
effectLevel = caster->getEffectLevel(spell);
effectPower = caster->getEffectPower(spell);
effectValue = caster->getEffectValue(spell);
enchantPower = caster->getEnchantPower(spell);
vstd::amax(spellLvl, 0);
vstd::amax(effectLevel, 0);
vstd::amax(enchantPower, 0);
vstd::amax(enchantPower, 0);
vstd::amax(effectValue, 0);
2015-09-16 09:50:33 +02:00
}
2016-09-06 12:51:53 +02:00
BattleSpellCastParameters::BattleSpellCastParameters(const BattleSpellCastParameters & orig, const ISpellCaster * caster)
:spell(orig.spell), cb(orig.cb), caster(caster), casterColor(caster->getOwner()), casterSide(cb->whatSide(casterColor)),
casterHero(nullptr), mode(ECastingMode::MAGIC_MIRROR), casterStack(nullptr),
spellLvl(orig.spellLvl), effectLevel(orig.effectLevel), effectPower(orig.effectPower), enchantPower(orig.enchantPower), effectValue(orig.effectValue)
{
casterStack = dynamic_cast<const CStack *>(caster);
casterHero = dynamic_cast<const CGHeroInstance *>(caster);
}
void BattleSpellCastParameters::aimToHex(const BattleHex& destination)
{
destinations.push_back(Destination(destination));
}
void BattleSpellCastParameters::aimToStack(const CStack * destination)
{
2016-09-06 11:26:01 +02:00
if(nullptr == destination)
logGlobal->error("BattleSpellCastParameters::aimToStack invalid stack.");
else
destinations.push_back(Destination(destination));
}
2016-09-06 12:33:11 +02:00
void BattleSpellCastParameters::cast(const SpellCastEnvironment * env)
{
2016-09-06 12:33:11 +02:00
spell->battleCast(env, *this);
}
2016-09-06 12:33:11 +02:00
BattleHex BattleSpellCastParameters::getFirstDestinationHex() const
2015-09-17 07:42:30 +02:00
{
2016-09-06 12:33:11 +02:00
return destinations.at(0).hexValue;
2015-09-17 07:42:30 +02:00
}
2015-09-16 09:50:33 +02:00
int BattleSpellCastParameters::getEffectValue() const
{
return (effectValue == 0) ? spell->calculateRawEffectValue(effectLevel, effectPower) : effectValue;
}
///ISpellMechanics
ISpellMechanics::ISpellMechanics(CSpell * s):
owner(s)
{
2015-02-26 19:59:18 +02:00
}
std::unique_ptr<ISpellMechanics> ISpellMechanics::createMechanics(CSpell * s)
2014-11-25 13:58:42 +02:00
{
switch (s->id)
{
case SpellID::ANTI_MAGIC:
return make_unique<AntimagicMechanics>(s);
2014-11-25 22:59:21 +02:00
case SpellID::ACID_BREATH_DAMAGE:
return make_unique<AcidBreathDamageMechanics>(s);
2014-11-25 22:59:21 +02:00
case SpellID::CHAIN_LIGHTNING:
return make_unique<ChainLightningMechanics>(s);
2014-11-25 13:58:42 +02:00
case SpellID::CLONE:
return make_unique<CloneMechanics>(s);
2014-11-25 22:59:21 +02:00
case SpellID::CURE:
return make_unique<CureMechanics>(s);
2014-11-25 22:59:21 +02:00
case SpellID::DEATH_STARE:
return make_unique<DeathStareMechanics>(s);
2014-11-25 22:59:21 +02:00
case SpellID::DISPEL:
return make_unique<DispellMechanics>(s);
2014-11-25 13:58:42 +02:00
case SpellID::DISPEL_HELPFUL_SPELLS:
return make_unique<DispellHelpfulMechanics>(s);
2015-03-18 12:27:07 +02:00
case SpellID::EARTHQUAKE:
return make_unique<EarthquakeMechanics>(s);
2014-11-25 13:58:42 +02:00
case SpellID::FIRE_WALL:
2016-09-05 12:34:48 +02:00
return make_unique<FireWallMechanics>(s);
2014-11-25 13:58:42 +02:00
case SpellID::FORCE_FIELD:
2016-09-05 12:34:48 +02:00
return make_unique<ForceFieldMechanics>(s);
2014-11-25 22:59:21 +02:00
case SpellID::HYPNOTIZE:
return make_unique<HypnotizeMechanics>(s);
2014-11-25 13:58:42 +02:00
case SpellID::LAND_MINE:
2016-09-05 12:34:48 +02:00
return make_unique<LandMineMechanics>(s);
2014-11-25 13:58:42 +02:00
case SpellID::QUICKSAND:
2016-09-05 12:34:48 +02:00
return make_unique<QuicksandMechanics>(s);
2014-11-25 22:59:21 +02:00
case SpellID::REMOVE_OBSTACLE:
return make_unique<RemoveObstacleMechanics>(s);
2014-11-25 22:59:21 +02:00
case SpellID::SACRIFICE:
return make_unique<SacrificeMechanics>(s);
2014-11-25 16:35:20 +02:00
case SpellID::SUMMON_FIRE_ELEMENTAL:
return make_unique<SummonMechanics>(s, CreatureID::FIRE_ELEMENTAL);
2014-11-25 16:35:20 +02:00
case SpellID::SUMMON_EARTH_ELEMENTAL:
return make_unique<SummonMechanics>(s, CreatureID::EARTH_ELEMENTAL);
2014-11-25 16:35:20 +02:00
case SpellID::SUMMON_WATER_ELEMENTAL:
return make_unique<SummonMechanics>(s, CreatureID::WATER_ELEMENTAL);
2014-11-25 16:35:20 +02:00
case SpellID::SUMMON_AIR_ELEMENTAL:
return make_unique<SummonMechanics>(s, CreatureID::AIR_ELEMENTAL);
2014-11-25 22:59:21 +02:00
case SpellID::TELEPORT:
return make_unique<TeleportMechanics>(s);
default:
if(s->isRisingSpell())
return make_unique<SpecialRisingSpellMechanics>(s);
else
return make_unique<DefaultSpellMechanics>(s);
}
}
//IAdventureSpellMechanics
IAdventureSpellMechanics::IAdventureSpellMechanics(CSpell * s):
owner(s)
{
}
std::unique_ptr<IAdventureSpellMechanics> IAdventureSpellMechanics::createMechanics(CSpell * s)
{
switch (s->id)
{
2014-12-25 23:02:50 +02:00
case SpellID::SUMMON_BOAT:
return make_unique<SummonBoatMechanics>(s);
2015-02-26 19:59:18 +02:00
case SpellID::SCUTTLE_BOAT:
return make_unique<ScuttleBoatMechanics>(s);
2014-12-25 23:02:50 +02:00
case SpellID::DIMENSION_DOOR:
return make_unique<DimensionDoorMechanics>(s);
2014-12-25 23:02:50 +02:00
case SpellID::FLY:
case SpellID::WATER_WALK:
2015-02-06 14:41:26 +02:00
case SpellID::VISIONS:
case SpellID::DISGUISE:
return make_unique<AdventureSpellMechanics>(s); //implemented using bonus system
2014-12-25 23:02:50 +02:00
case SpellID::TOWN_PORTAL:
return make_unique<TownPortalMechanics>(s);
2014-12-25 23:02:50 +02:00
case SpellID::VIEW_EARTH:
return make_unique<ViewEarthMechanics>(s);
2015-02-26 19:59:18 +02:00
case SpellID::VIEW_AIR:
return make_unique<ViewAirMechanics>(s);
2015-02-26 19:59:18 +02:00
default:
return std::unique_ptr<IAdventureSpellMechanics>();
2015-02-26 19:59:18 +02:00
}
2014-11-25 13:58:42 +02:00
}