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

Tweak BattleSpellCastParameters

This commit is contained in:
AlexVinS 2015-09-17 09:29:57 +03:00
parent 2b434111bf
commit 660203b436
11 changed files with 34 additions and 38 deletions

View File

@ -1219,6 +1219,12 @@ int CStack::getEffectValue(const CSpell * spell) const
return valOfBonuses(Bonus::SPECIFIC_SPELL_POWER, spell->id.toEnum()) * count; return valOfBonuses(Bonus::SPECIFIC_SPELL_POWER, spell->id.toEnum()) * count;
} }
const PlayerColor CStack::getOwner() const
{
return owner;
}
bool CMP_stack::operator()( const CStack* a, const CStack* b ) bool CMP_stack::operator()( const CStack* a, const CStack* b )
{ {
switch(phase) switch(phase)

View File

@ -248,6 +248,8 @@ public:
///damage/heal override(ignores spell configuration, effect level and effect power) ///damage/heal override(ignores spell configuration, effect level and effect power)
int getEffectValue(const CSpell * spell) const override; int getEffectValue(const CSpell * spell) const override;
const PlayerColor getOwner() const override;
template <typename Handler> void serialize(Handler &h, const int version) template <typename Handler> void serialize(Handler &h, const int version)
{ {
assert(isIndependentNode()); assert(isIndependentNode());

View File

@ -925,6 +925,11 @@ int CGHeroInstance::getEffectValue(const CSpell * spell) const
return 0; return 0;
} }
const PlayerColor CGHeroInstance::getOwner() const
{
return tempOwner;
}
bool CGHeroInstance::canCastThisSpell(const CSpell * spell) const bool CGHeroInstance::canCastThisSpell(const CSpell * spell) const
{ {
if(nullptr == getArt(ArtifactPosition::SPELLBOOK)) if(nullptr == getArt(ArtifactPosition::SPELLBOOK))

View File

@ -222,6 +222,8 @@ public:
///damage/heal override(ignores spell configuration, effect level and effect power) ///damage/heal override(ignores spell configuration, effect level and effect power)
int getEffectValue(const CSpell * spell) const override; int getEffectValue(const CSpell * spell) const override;
const PlayerColor getOwner() const override;
void deserializationFix(); void deserializationFix();
void initObj() override; void initObj() override;

View File

@ -28,7 +28,7 @@ void HealingSpellMechanics::applyBattleEffects(const SpellCastEnvironment* env,
{ {
StacksHealedOrResurrected::HealInfo hi; StacksHealedOrResurrected::HealInfo hi;
hi.stackID = (attackedCre)->ID; hi.stackID = (attackedCre)->ID;
int stackHPgained = ctx.caster->getSpellBonus(owner, hpGained, attackedCre); int stackHPgained = parameters.caster->getSpellBonus(owner, hpGained, attackedCre);
hi.healedHP = attackedCre->calculateHealedHealthPoints(stackHPgained, resurrect); hi.healedHP = attackedCre->calculateHealedHealthPoints(stackHPgained, resurrect);
hi.lowLevelResurrection = (healLevel == EHealLevel::RESURRECT); hi.lowLevelResurrection = (healLevel == EHealLevel::RESURRECT);
shr.healedStacks.push_back(hi); shr.healedStacks.push_back(hi);

View File

@ -231,8 +231,6 @@ void DefaultSpellMechanics::battleCast(const SpellCastEnvironment * env, BattleS
return; return;
} }
const ISpellCaster * caster = parameters.caster;
BattleSpellCast sc; BattleSpellCast sc;
prepareBattleCast(parameters, sc); prepareBattleCast(parameters, sc);
@ -307,9 +305,6 @@ void DefaultSpellMechanics::battleCast(const SpellCastEnvironment * env, BattleS
StacksInjured si; StacksInjured si;
SpellCastContext ctx(attackedCres, sc, si); SpellCastContext ctx(attackedCres, sc, si);
ctx.caster = caster;
applyBattleEffects(env, parameters, ctx); applyBattleEffects(env, parameters, ctx);
env->sendAndApply(&sc); env->sendAndApply(&sc);
@ -366,16 +361,16 @@ void DefaultSpellMechanics::battleCast(const SpellCastEnvironment * env, BattleS
{ {
int targetHex = (*RandomGeneratorUtil::nextItem(mirrorTargets, env->getRandomGenerator()))->position; int targetHex = (*RandomGeneratorUtil::nextItem(mirrorTargets, env->getRandomGenerator()))->position;
BattleSpellCastParameters mirrorParameters = parameters; BattleSpellCastParameters mirrorParameters(parameters.cb, attackedCre, owner);
mirrorParameters.spellLvl = 0; mirrorParameters.spellLvl = 0;
mirrorParameters.casterSide = 1-parameters.casterSide;
mirrorParameters.casterColor = (attackedCre)->owner;
mirrorParameters.casterHero = nullptr;
mirrorParameters.destination = targetHex; mirrorParameters.destination = targetHex;
mirrorParameters.mode = ECastingMode::MAGIC_MIRROR; mirrorParameters.mode = ECastingMode::MAGIC_MIRROR;
mirrorParameters.casterStack = (attackedCre);
mirrorParameters.selectedStack = nullptr; mirrorParameters.selectedStack = nullptr;
mirrorParameters.spellLvl = parameters.spellLvl;
mirrorParameters.effectLevel = parameters.effectLevel;
mirrorParameters.effectPower = parameters.effectPower;
mirrorParameters.effectValue = parameters.effectValue;
mirrorParameters.enchantPower = parameters.enchantPower;
castMagicMirror(env, mirrorParameters); castMagicMirror(env, mirrorParameters);
} }
} }
@ -490,9 +485,9 @@ void DefaultSpellMechanics::applyBattleEffects(const SpellCastEnvironment * env,
{ {
BattleStackAttacked bsa; BattleStackAttacked bsa;
if(spellDamage != 0) if(spellDamage != 0)
bsa.damageAmount = owner->adjustRawDamage(ctx.caster, attackedCre, spellDamage) >> chainLightningModifier; bsa.damageAmount = owner->adjustRawDamage(parameters.caster, attackedCre, spellDamage) >> chainLightningModifier;
else else
bsa.damageAmount = owner->calculateDamage(ctx.caster, attackedCre, parameters.effectLevel, parameters.effectPower) >> chainLightningModifier; bsa.damageAmount = owner->calculateDamage(parameters.caster, attackedCre, parameters.effectLevel, parameters.effectPower) >> chainLightningModifier;
ctx.sc.dmgToDisplay += bsa.damageAmount; ctx.sc.dmgToDisplay += bsa.damageAmount;
@ -798,7 +793,6 @@ void DefaultSpellMechanics::castMagicMirror(const SpellCastEnvironment* env, Bat
StacksInjured si; StacksInjured si;
SpellCastContext ctx(attackedCres, sc, si); SpellCastContext ctx(attackedCres, sc, si);
ctx.caster = parameters.casterStack;
applyBattleEffects(env, parameters, ctx); applyBattleEffects(env, parameters, ctx);
env->sendAndApply(&sc); env->sendAndApply(&sc);

View File

@ -25,9 +25,6 @@ struct SpellCastContext
std::vector<const CStack *> & attackedCres; std::vector<const CStack *> & attackedCres;
BattleSpellCast & sc; BattleSpellCast & sc;
StacksInjured & si; StacksInjured & si;
///stack or hero
const ISpellCaster * caster;
}; };
enum class ESpellCastResult enum class ESpellCastResult

View File

@ -21,10 +21,10 @@
#include "CreatureSpellMechanics.h" #include "CreatureSpellMechanics.h"
BattleSpellCastParameters::BattleSpellCastParameters(const BattleInfo * cb, const ISpellCaster * caster, const CSpell * spell) BattleSpellCastParameters::BattleSpellCastParameters(const BattleInfo * cb, const ISpellCaster * caster, const CSpell * spell)
: cb(cb), caster(caster), casterSide(0),casterColor(PlayerColor::CANNOT_DETERMINE), : cb(cb), caster(caster), casterColor(caster->getOwner()), casterSide(cb->whatSide(casterColor)),
spellLvl(-1), destination(BattleHex::INVALID),casterHero(nullptr), destination(BattleHex::INVALID),casterHero(nullptr),
mode(ECastingMode::HERO_CASTING), casterStack(nullptr), selectedStack(nullptr), mode(ECastingMode::HERO_CASTING), casterStack(nullptr), selectedStack(nullptr),
effectLevel(-1), effectPower(0), enchantPower(0), effectValue(0) spellLvl(-1), effectLevel(-1), effectPower(0), enchantPower(0), effectValue(0)
{ {
casterStack = dynamic_cast<const CStack *>(caster); casterStack = dynamic_cast<const CStack *>(caster);
casterHero = dynamic_cast<const CGHeroInstance *>(caster); casterHero = dynamic_cast<const CGHeroInstance *>(caster);

View File

@ -37,17 +37,17 @@ public:
BattleSpellCastParameters(const BattleInfo * cb, const ISpellCaster * caster, const CSpell * spell); BattleSpellCastParameters(const BattleInfo * cb, const ISpellCaster * caster, const CSpell * spell);
const BattleInfo * cb; const BattleInfo * cb;
const ISpellCaster * caster; const ISpellCaster * caster;
ui8 casterSide; const PlayerColor casterColor;
PlayerColor casterColor; const ui8 casterSide;
///spell school level , -1-use default
int spellLvl;
BattleHex destination; BattleHex destination;
const CGHeroInstance * casterHero; //deprecated const CGHeroInstance * casterHero; //deprecated
ECastingMode::ECastingMode mode; ECastingMode::ECastingMode mode;
const CStack * casterStack; //deprecated const CStack * casterStack; //deprecated
const CStack * selectedStack; const CStack * selectedStack;
///spell school level
int spellLvl;
///spell school level to use for effects ///spell school level to use for effects
int effectLevel; int effectLevel;
///actual spell-power affecting effect values ///actual spell-power affecting effect values

View File

@ -17,6 +17,7 @@
class CSpell; class CSpell;
class CStack; class CStack;
class PlayerColor;
class DLL_LINKAGE ISpellCaster class DLL_LINKAGE ISpellCaster
{ {
@ -43,4 +44,5 @@ public:
///damage/heal override(ignores spell configuration, effect level and effect power) ///damage/heal override(ignores spell configuration, effect level and effect power)
virtual int getEffectValue(const CSpell * spell) const = 0; virtual int getEffectValue(const CSpell * spell) const = 0;
virtual const PlayerColor getOwner() const = 0;
}; };

View File

@ -3877,10 +3877,8 @@ bool CGameHandler::makeBattleAction( BattleAction &ba )
vstd::amax(parameters.spellLvl, randSpellcaster->val); vstd::amax(parameters.spellLvl, randSpellcaster->val);
vstd::amin (parameters.spellLvl, 3); vstd::amin (parameters.spellLvl, 3);
parameters.effectLevel = parameters.spellLvl; parameters.effectLevel = parameters.spellLvl;
parameters.casterSide = gs->curB->whatSide(stack->owner);
parameters.mode = ECastingMode::CREATURE_ACTIVE_CASTING; parameters.mode = ECastingMode::CREATURE_ACTIVE_CASTING;
parameters.destination = destination; parameters.destination = destination;
parameters.casterColor = stack->owner;
parameters.selectedStack = nullptr; parameters.selectedStack = nullptr;
spell->battleCast(spellEnv, parameters); spell->battleCast(spellEnv, parameters);
} }
@ -4072,8 +4070,6 @@ bool CGameHandler::makeCustomAction( BattleAction &ba )
BattleSpellCastParameters parameters(gs->curB, h, s); BattleSpellCastParameters parameters(gs->curB, h, s);
parameters.destination = ba.destinationTile; parameters.destination = ba.destinationTile;
parameters.casterSide = ba.side;
parameters.casterColor = h->tempOwner;
parameters.mode = ECastingMode::HERO_CASTING; parameters.mode = ECastingMode::HERO_CASTING;
parameters.selectedStack = gs->curB->battleGetStackByID(ba.selectedStack, false); parameters.selectedStack = gs->curB->battleGetStackByID(ba.selectedStack, false);
@ -4227,8 +4223,6 @@ void CGameHandler::stackTurnTrigger(const CStack * st)
parameters.spellLvl = bonus->val; parameters.spellLvl = bonus->val;
parameters.effectLevel = bonus->val;//todo: recheck parameters.effectLevel = bonus->val;//todo: recheck
parameters.destination = BattleHex::INVALID; parameters.destination = BattleHex::INVALID;
parameters.casterSide = side;
parameters.casterColor = st->owner;
parameters.mode = ECastingMode::ENCHANTER_CASTING; parameters.mode = ECastingMode::ENCHANTER_CASTING;
parameters.selectedStack = nullptr; parameters.selectedStack = nullptr;
@ -4938,8 +4932,6 @@ void CGameHandler::attackCasting(const BattleAttack & bat, Bonus::BonusType atta
parameters.spellLvl = spellLevel; parameters.spellLvl = spellLevel;
parameters.effectLevel = spellLevel; parameters.effectLevel = spellLevel;
parameters.destination = destination; parameters.destination = destination;
parameters.casterSide = !attacker->attackerOwned;
parameters.casterColor = attacker->owner;
parameters.mode = ECastingMode::AFTER_ATTACK_CASTING; parameters.mode = ECastingMode::AFTER_ATTACK_CASTING;
parameters.selectedStack = nullptr; parameters.selectedStack = nullptr;
@ -4969,8 +4961,6 @@ void CGameHandler::handleAfterAttackCasting( const BattleAttack & bat )
parameters.spellLvl = 0; parameters.spellLvl = 0;
parameters.effectLevel = 0; parameters.effectLevel = 0;
parameters.destination = gs->curB->battleGetStackByID(bat.bsa.at(0).stackAttacked)->position; parameters.destination = gs->curB->battleGetStackByID(bat.bsa.at(0).stackAttacked)->position;
parameters.casterSide = !attacker->attackerOwned;
parameters.casterColor = attacker->owner;
parameters.effectPower = power; parameters.effectPower = power;
parameters.mode = ECastingMode::AFTER_ATTACK_CASTING; parameters.mode = ECastingMode::AFTER_ATTACK_CASTING;
parameters.selectedStack = nullptr; parameters.selectedStack = nullptr;
@ -5279,8 +5269,6 @@ void CGameHandler::runBattle()
parameters.spellLvl = 3; parameters.spellLvl = 3;
parameters.effectLevel = 3; parameters.effectLevel = 3;
parameters.destination = BattleHex::INVALID; parameters.destination = BattleHex::INVALID;
parameters.casterSide = i;
parameters.casterColor = h->tempOwner;
parameters.mode = ECastingMode::PASSIVE_CASTING; parameters.mode = ECastingMode::PASSIVE_CASTING;
parameters.selectedStack = nullptr; parameters.selectedStack = nullptr;
parameters.enchantPower = b->val; parameters.enchantPower = b->val;