From 660203b436abc16f0b2e2e4f1351fac70de55df5 Mon Sep 17 00:00:00 2001 From: AlexVinS Date: Thu, 17 Sep 2015 09:29:57 +0300 Subject: [PATCH] Tweak BattleSpellCastParameters --- lib/BattleState.cpp | 6 ++++++ lib/BattleState.h | 2 ++ lib/mapObjects/CGHeroInstance.cpp | 5 +++++ lib/mapObjects/CGHeroInstance.h | 2 ++ lib/spells/BattleSpellMechanics.cpp | 2 +- lib/spells/CDefaultSpellMechanics.cpp | 22 ++++++++-------------- lib/spells/CDefaultSpellMechanics.h | 3 --- lib/spells/ISpellMechanics.cpp | 6 +++--- lib/spells/ISpellMechanics.h | 10 +++++----- lib/spells/Magic.h | 2 ++ server/CGameHandler.cpp | 12 ------------ 11 files changed, 34 insertions(+), 38 deletions(-) diff --git a/lib/BattleState.cpp b/lib/BattleState.cpp index b8d9aff93..cd6d2b0b5 100644 --- a/lib/BattleState.cpp +++ b/lib/BattleState.cpp @@ -1219,6 +1219,12 @@ int CStack::getEffectValue(const CSpell * spell) const 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 ) { switch(phase) diff --git a/lib/BattleState.h b/lib/BattleState.h index 60716cfb2..44260ad32 100644 --- a/lib/BattleState.h +++ b/lib/BattleState.h @@ -247,6 +247,8 @@ public: ///damage/heal override(ignores spell configuration, effect level and effect power) int getEffectValue(const CSpell * spell) const override; + + const PlayerColor getOwner() const override; template void serialize(Handler &h, const int version) { diff --git a/lib/mapObjects/CGHeroInstance.cpp b/lib/mapObjects/CGHeroInstance.cpp index 05d1d62aa..704bedfd8 100644 --- a/lib/mapObjects/CGHeroInstance.cpp +++ b/lib/mapObjects/CGHeroInstance.cpp @@ -925,6 +925,11 @@ int CGHeroInstance::getEffectValue(const CSpell * spell) const return 0; } +const PlayerColor CGHeroInstance::getOwner() const +{ + return tempOwner; +} + bool CGHeroInstance::canCastThisSpell(const CSpell * spell) const { if(nullptr == getArt(ArtifactPosition::SPELLBOOK)) diff --git a/lib/mapObjects/CGHeroInstance.h b/lib/mapObjects/CGHeroInstance.h index 26583f874..266009e32 100644 --- a/lib/mapObjects/CGHeroInstance.h +++ b/lib/mapObjects/CGHeroInstance.h @@ -222,6 +222,8 @@ public: ///damage/heal override(ignores spell configuration, effect level and effect power) int getEffectValue(const CSpell * spell) const override; + const PlayerColor getOwner() const override; + void deserializationFix(); void initObj() override; diff --git a/lib/spells/BattleSpellMechanics.cpp b/lib/spells/BattleSpellMechanics.cpp index d32d596a2..c598f6339 100644 --- a/lib/spells/BattleSpellMechanics.cpp +++ b/lib/spells/BattleSpellMechanics.cpp @@ -28,7 +28,7 @@ void HealingSpellMechanics::applyBattleEffects(const SpellCastEnvironment* env, { StacksHealedOrResurrected::HealInfo hi; 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.lowLevelResurrection = (healLevel == EHealLevel::RESURRECT); shr.healedStacks.push_back(hi); diff --git a/lib/spells/CDefaultSpellMechanics.cpp b/lib/spells/CDefaultSpellMechanics.cpp index 3b4adacce..51071d8ef 100644 --- a/lib/spells/CDefaultSpellMechanics.cpp +++ b/lib/spells/CDefaultSpellMechanics.cpp @@ -231,8 +231,6 @@ void DefaultSpellMechanics::battleCast(const SpellCastEnvironment * env, BattleS return; } - const ISpellCaster * caster = parameters.caster; - BattleSpellCast sc; prepareBattleCast(parameters, sc); @@ -307,9 +305,6 @@ void DefaultSpellMechanics::battleCast(const SpellCastEnvironment * env, BattleS StacksInjured si; SpellCastContext ctx(attackedCres, sc, si); - - ctx.caster = caster; - applyBattleEffects(env, parameters, ctx); env->sendAndApply(&sc); @@ -366,16 +361,16 @@ void DefaultSpellMechanics::battleCast(const SpellCastEnvironment * env, BattleS { int targetHex = (*RandomGeneratorUtil::nextItem(mirrorTargets, env->getRandomGenerator()))->position; - BattleSpellCastParameters mirrorParameters = parameters; + BattleSpellCastParameters mirrorParameters(parameters.cb, attackedCre, owner); mirrorParameters.spellLvl = 0; - mirrorParameters.casterSide = 1-parameters.casterSide; - mirrorParameters.casterColor = (attackedCre)->owner; - mirrorParameters.casterHero = nullptr; mirrorParameters.destination = targetHex; mirrorParameters.mode = ECastingMode::MAGIC_MIRROR; - mirrorParameters.casterStack = (attackedCre); 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); } } @@ -490,9 +485,9 @@ void DefaultSpellMechanics::applyBattleEffects(const SpellCastEnvironment * env, { BattleStackAttacked bsa; if(spellDamage != 0) - bsa.damageAmount = owner->adjustRawDamage(ctx.caster, attackedCre, spellDamage) >> chainLightningModifier; + bsa.damageAmount = owner->adjustRawDamage(parameters.caster, attackedCre, spellDamage) >> chainLightningModifier; 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; @@ -798,7 +793,6 @@ void DefaultSpellMechanics::castMagicMirror(const SpellCastEnvironment* env, Bat StacksInjured si; SpellCastContext ctx(attackedCres, sc, si); - ctx.caster = parameters.casterStack; applyBattleEffects(env, parameters, ctx); env->sendAndApply(&sc); diff --git a/lib/spells/CDefaultSpellMechanics.h b/lib/spells/CDefaultSpellMechanics.h index cf4e3bf24..04e27fd8f 100644 --- a/lib/spells/CDefaultSpellMechanics.h +++ b/lib/spells/CDefaultSpellMechanics.h @@ -25,9 +25,6 @@ struct SpellCastContext std::vector & attackedCres; BattleSpellCast & sc; StacksInjured & si; - - ///stack or hero - const ISpellCaster * caster; }; enum class ESpellCastResult diff --git a/lib/spells/ISpellMechanics.cpp b/lib/spells/ISpellMechanics.cpp index 30b736d23..dddbe8c7c 100644 --- a/lib/spells/ISpellMechanics.cpp +++ b/lib/spells/ISpellMechanics.cpp @@ -21,10 +21,10 @@ #include "CreatureSpellMechanics.h" BattleSpellCastParameters::BattleSpellCastParameters(const BattleInfo * cb, const ISpellCaster * caster, const CSpell * spell) - : cb(cb), caster(caster), casterSide(0),casterColor(PlayerColor::CANNOT_DETERMINE), - spellLvl(-1), destination(BattleHex::INVALID),casterHero(nullptr), + : cb(cb), caster(caster), casterColor(caster->getOwner()), casterSide(cb->whatSide(casterColor)), + destination(BattleHex::INVALID),casterHero(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(caster); casterHero = dynamic_cast(caster); diff --git a/lib/spells/ISpellMechanics.h b/lib/spells/ISpellMechanics.h index a247bc36a..2c7e7ed75 100644 --- a/lib/spells/ISpellMechanics.h +++ b/lib/spells/ISpellMechanics.h @@ -37,17 +37,17 @@ public: BattleSpellCastParameters(const BattleInfo * cb, const ISpellCaster * caster, const CSpell * spell); const BattleInfo * cb; const ISpellCaster * caster; - ui8 casterSide; - PlayerColor casterColor; - ///spell school level , -1-use default - int spellLvl; + const PlayerColor casterColor; + const ui8 casterSide; + BattleHex destination; const CGHeroInstance * casterHero; //deprecated ECastingMode::ECastingMode mode; const CStack * casterStack; //deprecated const CStack * selectedStack; - + ///spell school level + int spellLvl; ///spell school level to use for effects int effectLevel; ///actual spell-power affecting effect values diff --git a/lib/spells/Magic.h b/lib/spells/Magic.h index bfedf881d..4dfa822a3 100644 --- a/lib/spells/Magic.h +++ b/lib/spells/Magic.h @@ -17,6 +17,7 @@ class CSpell; class CStack; +class PlayerColor; class DLL_LINKAGE ISpellCaster { @@ -43,4 +44,5 @@ public: ///damage/heal override(ignores spell configuration, effect level and effect power) virtual int getEffectValue(const CSpell * spell) const = 0; + virtual const PlayerColor getOwner() const = 0; }; diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 32bd6e315..cd50b3be7 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -3877,10 +3877,8 @@ bool CGameHandler::makeBattleAction( BattleAction &ba ) vstd::amax(parameters.spellLvl, randSpellcaster->val); vstd::amin (parameters.spellLvl, 3); parameters.effectLevel = parameters.spellLvl; - parameters.casterSide = gs->curB->whatSide(stack->owner); parameters.mode = ECastingMode::CREATURE_ACTIVE_CASTING; parameters.destination = destination; - parameters.casterColor = stack->owner; parameters.selectedStack = nullptr; spell->battleCast(spellEnv, parameters); } @@ -4072,8 +4070,6 @@ bool CGameHandler::makeCustomAction( BattleAction &ba ) BattleSpellCastParameters parameters(gs->curB, h, s); parameters.destination = ba.destinationTile; - parameters.casterSide = ba.side; - parameters.casterColor = h->tempOwner; parameters.mode = ECastingMode::HERO_CASTING; parameters.selectedStack = gs->curB->battleGetStackByID(ba.selectedStack, false); @@ -4227,8 +4223,6 @@ void CGameHandler::stackTurnTrigger(const CStack * st) parameters.spellLvl = bonus->val; parameters.effectLevel = bonus->val;//todo: recheck parameters.destination = BattleHex::INVALID; - parameters.casterSide = side; - parameters.casterColor = st->owner; parameters.mode = ECastingMode::ENCHANTER_CASTING; parameters.selectedStack = nullptr; @@ -4938,8 +4932,6 @@ void CGameHandler::attackCasting(const BattleAttack & bat, Bonus::BonusType atta parameters.spellLvl = spellLevel; parameters.effectLevel = spellLevel; parameters.destination = destination; - parameters.casterSide = !attacker->attackerOwned; - parameters.casterColor = attacker->owner; parameters.mode = ECastingMode::AFTER_ATTACK_CASTING; parameters.selectedStack = nullptr; @@ -4969,8 +4961,6 @@ void CGameHandler::handleAfterAttackCasting( const BattleAttack & bat ) parameters.spellLvl = 0; parameters.effectLevel = 0; parameters.destination = gs->curB->battleGetStackByID(bat.bsa.at(0).stackAttacked)->position; - parameters.casterSide = !attacker->attackerOwned; - parameters.casterColor = attacker->owner; parameters.effectPower = power; parameters.mode = ECastingMode::AFTER_ATTACK_CASTING; parameters.selectedStack = nullptr; @@ -5279,8 +5269,6 @@ void CGameHandler::runBattle() parameters.spellLvl = 3; parameters.effectLevel = 3; parameters.destination = BattleHex::INVALID; - parameters.casterSide = i; - parameters.casterColor = h->tempOwner; parameters.mode = ECastingMode::PASSIVE_CASTING; parameters.selectedStack = nullptr; parameters.enchantPower = b->val;