2014-11-12 10:36:34 +02:00
|
|
|
/*
|
2015-02-02 11:22:19 +02:00
|
|
|
* ISpellMechanics.cpp, part of VCMI engine
|
2014-11-12 10:36:34 +02:00
|
|
|
*
|
|
|
|
* 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"
|
2015-02-02 10:25:26 +02:00
|
|
|
#include "ISpellMechanics.h"
|
2014-11-12 10:36:34 +02:00
|
|
|
|
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"
|
2014-11-12 10:36:34 +02:00
|
|
|
|
2015-02-02 11:22:19 +02:00
|
|
|
#include "AdventureSpellMechanics.h"
|
|
|
|
#include "BattleSpellMechanics.h"
|
|
|
|
#include "CreatureSpellMechanics.h"
|
2014-11-13 03:53:25 +02:00
|
|
|
|
2015-09-29 20:47:04 +02:00
|
|
|
BattleSpellCastParameters::Destination::Destination(const CStack * destination):
|
|
|
|
stackValue(destination),
|
|
|
|
hexValue(destination->position)
|
|
|
|
{
|
2016-02-15 12:34:37 +02:00
|
|
|
|
2015-09-29 20:47:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
BattleSpellCastParameters::Destination::Destination(const BattleHex & destination):
|
|
|
|
stackValue(nullptr),
|
2016-02-15 12:34:37 +02:00
|
|
|
hexValue(destination)
|
2015-09-29 20:47:04 +02:00
|
|
|
{
|
2016-02-15 12:34:37 +02:00
|
|
|
|
2015-09-29 20:47:04 +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)),
|
2015-09-29 20:47:04 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-09-29 20:47:04 +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
|
|
|
|
2014-11-13 06:34:20 +02:00
|
|
|
///ISpellMechanics
|
|
|
|
ISpellMechanics::ISpellMechanics(CSpell * s):
|
|
|
|
owner(s)
|
|
|
|
{
|
2015-02-26 19:59:18 +02:00
|
|
|
|
2014-11-13 06:34:20 +02:00
|
|
|
}
|
|
|
|
|
2016-09-04 07:19:28 +02:00
|
|
|
std::unique_ptr<ISpellMechanics> ISpellMechanics::createMechanics(CSpell * s)
|
2014-11-25 13:58:42 +02:00
|
|
|
{
|
|
|
|
switch (s->id)
|
|
|
|
{
|
2015-04-03 02:28:20 +02:00
|
|
|
case SpellID::ANTI_MAGIC:
|
2016-09-04 07:19:28 +02:00
|
|
|
return make_unique<AntimagicMechanics>(s);
|
2014-11-25 22:59:21 +02:00
|
|
|
case SpellID::ACID_BREATH_DAMAGE:
|
2016-09-04 07:19:28 +02:00
|
|
|
return make_unique<AcidBreathDamageMechanics>(s);
|
2014-11-25 22:59:21 +02:00
|
|
|
case SpellID::CHAIN_LIGHTNING:
|
2016-09-04 07:19:28 +02:00
|
|
|
return make_unique<ChainLightningMechanics>(s);
|
2014-11-25 13:58:42 +02:00
|
|
|
case SpellID::CLONE:
|
2016-09-04 07:19:28 +02:00
|
|
|
return make_unique<CloneMechanics>(s);
|
2014-11-25 22:59:21 +02:00
|
|
|
case SpellID::CURE:
|
2016-09-04 07:19:28 +02:00
|
|
|
return make_unique<CureMechanics>(s);
|
2014-11-25 22:59:21 +02:00
|
|
|
case SpellID::DEATH_STARE:
|
2016-09-04 07:19:28 +02:00
|
|
|
return make_unique<DeathStareMechanics>(s);
|
2014-11-25 22:59:21 +02:00
|
|
|
case SpellID::DISPEL:
|
2016-09-04 07:19:28 +02:00
|
|
|
return make_unique<DispellMechanics>(s);
|
2014-11-25 13:58:42 +02:00
|
|
|
case SpellID::DISPEL_HELPFUL_SPELLS:
|
2016-09-04 07:19:28 +02:00
|
|
|
return make_unique<DispellHelpfulMechanics>(s);
|
2015-03-18 12:27:07 +02:00
|
|
|
case SpellID::EARTHQUAKE:
|
2016-09-04 07:19:28 +02:00
|
|
|
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:
|
2016-09-04 07:19:28 +02:00
|
|
|
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:
|
2016-09-04 07:19:28 +02:00
|
|
|
return make_unique<RemoveObstacleMechanics>(s);
|
2014-11-25 22:59:21 +02:00
|
|
|
case SpellID::SACRIFICE:
|
2016-09-04 07:19:28 +02:00
|
|
|
return make_unique<SacrificeMechanics>(s);
|
2014-11-25 16:35:20 +02:00
|
|
|
case SpellID::SUMMON_FIRE_ELEMENTAL:
|
2016-09-04 07:19:28 +02:00
|
|
|
return make_unique<SummonMechanics>(s, CreatureID::FIRE_ELEMENTAL);
|
2014-11-25 16:35:20 +02:00
|
|
|
case SpellID::SUMMON_EARTH_ELEMENTAL:
|
2016-09-04 07:19:28 +02:00
|
|
|
return make_unique<SummonMechanics>(s, CreatureID::EARTH_ELEMENTAL);
|
2014-11-25 16:35:20 +02:00
|
|
|
case SpellID::SUMMON_WATER_ELEMENTAL:
|
2016-09-04 07:19:28 +02:00
|
|
|
return make_unique<SummonMechanics>(s, CreatureID::WATER_ELEMENTAL);
|
2014-11-25 16:35:20 +02:00
|
|
|
case SpellID::SUMMON_AIR_ELEMENTAL:
|
2016-09-04 07:19:28 +02:00
|
|
|
return make_unique<SummonMechanics>(s, CreatureID::AIR_ELEMENTAL);
|
2014-11-25 22:59:21 +02:00
|
|
|
case SpellID::TELEPORT:
|
2016-09-04 07:19:28 +02:00
|
|
|
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:
|
2016-09-04 07:19:28 +02:00
|
|
|
return make_unique<SummonBoatMechanics>(s);
|
2015-02-26 19:59:18 +02:00
|
|
|
case SpellID::SCUTTLE_BOAT:
|
2016-09-04 07:19:28 +02:00
|
|
|
return make_unique<ScuttleBoatMechanics>(s);
|
2014-12-25 23:02:50 +02:00
|
|
|
case SpellID::DIMENSION_DOOR:
|
2016-09-04 07:19:28 +02:00
|
|
|
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:
|
2016-09-04 07:19:28 +02:00
|
|
|
return make_unique<AdventureSpellMechanics>(s); //implemented using bonus system
|
2014-12-25 23:02:50 +02:00
|
|
|
case SpellID::TOWN_PORTAL:
|
2016-09-04 07:19:28 +02:00
|
|
|
return make_unique<TownPortalMechanics>(s);
|
2014-12-25 23:02:50 +02:00
|
|
|
case SpellID::VIEW_EARTH:
|
2016-09-04 07:19:28 +02:00
|
|
|
return make_unique<ViewEarthMechanics>(s);
|
2015-02-26 19:59:18 +02:00
|
|
|
case SpellID::VIEW_AIR:
|
2016-09-04 07:19:28 +02:00
|
|
|
return make_unique<ViewAirMechanics>(s);
|
2015-02-26 19:59:18 +02:00
|
|
|
default:
|
2016-09-04 07:19:28 +02:00
|
|
|
return std::unique_ptr<IAdventureSpellMechanics>();
|
2015-02-26 19:59:18 +02:00
|
|
|
}
|
2014-11-25 13:58:42 +02:00
|
|
|
}
|