1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-20 20:23:03 +02:00
vcmi/lib/spells/ISpellMechanics.cpp

172 lines
4.9 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
}
2015-09-17 07:42:30 +02:00
BattleSpellCastParameters::BattleSpellCastParameters(const BattleInfo * cb, const ISpellCaster * caster, const CSpell * spell)
2015-09-17 08:29:57 +02:00
: cb(cb), caster(caster), casterColor(caster->getOwner()), casterSide(cb->whatSide(casterColor)),
casterHero(nullptr),
2015-09-17 07:42:30 +02:00
mode(ECastingMode::HERO_CASTING), casterStack(nullptr), selectedStack(nullptr),
2015-09-17 08:29:57 +02:00
spellLvl(-1), effectLevel(-1), 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);
prepare(spell);
2015-09-16 09:50:33 +02:00
}
void BattleSpellCastParameters::aimToHex(const BattleHex& destination)
{
destinations.push_back(Destination(destination));
}
void BattleSpellCastParameters::aimToStack(const CStack * destination)
{
destinations.push_back(Destination(destination));
}
BattleHex BattleSpellCastParameters::getFirstDestinationHex() const
{
return destinations.at(0).hexValue;
}
2015-09-17 07:42:30 +02:00
void BattleSpellCastParameters::prepare(const CSpell * spell)
{
spellLvl = caster->getSpellSchoolLevel(spell);
effectLevel = caster->getEffectLevel(spell);
effectPower = caster->getEffectPower(spell);
effectValue = caster->getEffectValue(spell);
enchantPower = caster->getEnchantPower(spell);
2016-02-15 12:34:37 +02:00
2015-09-17 07:42:30 +02:00
vstd::amax(spellLvl, 0);
vstd::amax(effectLevel, 0);
2016-02-15 12:34:37 +02:00
vstd::amax(enchantPower, 0);
2015-09-17 07:42:30 +02:00
vstd::amax(enchantPower, 0);
vstd::amax(effectValue, 0);
}
2015-09-16 09:50:33 +02:00
///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
}