mirror of
https://github.com/vcmi/vcmi.git
synced 2025-03-25 21:38:59 +02:00
Cleanup.
This commit is contained in:
parent
cc4362211c
commit
686cd00c68
@ -685,11 +685,7 @@ void SacrificeMechanics::applyBattleEffects(const SpellCastEnvironment * env, co
|
||||
{
|
||||
victim = parameters.destinations[1].stackValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
//todo: remove and report error
|
||||
victim = parameters.selectedStack;
|
||||
}
|
||||
|
||||
if(nullptr == victim)
|
||||
{
|
||||
env->complain("SacrificeMechanics: No stack to sacrifice");
|
||||
@ -712,11 +708,7 @@ int SacrificeMechanics::calculateHealedHP(const SpellCastEnvironment* env, const
|
||||
{
|
||||
victim = parameters.destinations[1].stackValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
//todo: remove and report error
|
||||
victim = parameters.selectedStack;
|
||||
}
|
||||
|
||||
if(nullptr == victim)
|
||||
{
|
||||
env->complain("SacrificeMechanics: No stack to sacrifice");
|
||||
@ -817,20 +809,22 @@ void TeleportMechanics::applyBattleEffects(const SpellCastEnvironment * env, con
|
||||
//todo: check legal teleport
|
||||
if(parameters.destinations.size() == 2)
|
||||
{
|
||||
//first destination creature to move
|
||||
const CStack * target = parameters.destinations[0].stackValue;
|
||||
if(nullptr == target)
|
||||
{
|
||||
env->complain("TeleportMechanics: no stack to teleport");
|
||||
return;
|
||||
}
|
||||
//second destination hex to move to
|
||||
const BattleHex destination = parameters.destinations[1].hexValue;
|
||||
//first destination hex to move to
|
||||
const BattleHex destination = parameters.destinations[0].hexValue;
|
||||
if(!destination.isValid())
|
||||
{
|
||||
env->complain("TeleportMechanics: invalid teleport destination");
|
||||
return;
|
||||
}
|
||||
|
||||
//second destination creature to move
|
||||
const CStack * target = parameters.destinations[1].stackValue;
|
||||
if(nullptr == target)
|
||||
{
|
||||
env->complain("TeleportMechanics: no stack to teleport");
|
||||
return;
|
||||
}
|
||||
|
||||
BattleStackMoved bsm;
|
||||
bsm.distance = -1;
|
||||
bsm.stack = target->ID;
|
||||
@ -842,15 +836,8 @@ void TeleportMechanics::applyBattleEffects(const SpellCastEnvironment * env, con
|
||||
}
|
||||
else
|
||||
{
|
||||
//todo: remove and report error
|
||||
BattleStackMoved bsm;
|
||||
bsm.distance = -1;
|
||||
bsm.stack = parameters.selectedStack->ID;
|
||||
std::vector<BattleHex> tiles;
|
||||
tiles.push_back(parameters.getFirstDestinationHex());
|
||||
bsm.tilesToMove = tiles;
|
||||
bsm.teleporting = true;
|
||||
env->sendAndApply(&bsm);
|
||||
env->complain("TeleportMechanics: 2 destinations required.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -217,7 +217,6 @@ void DefaultSpellMechanics::battleCast(const SpellCastEnvironment * env, const B
|
||||
mirrorParameters.spellLvl = 0;
|
||||
mirrorParameters.aimToHex(targetHex);
|
||||
mirrorParameters.mode = ECastingMode::MAGIC_MIRROR;
|
||||
mirrorParameters.selectedStack = nullptr;
|
||||
mirrorParameters.spellLvl = parameters.spellLvl;
|
||||
mirrorParameters.effectLevel = parameters.effectLevel;
|
||||
mirrorParameters.effectPower = parameters.effectPower;
|
||||
@ -261,9 +260,9 @@ void DefaultSpellMechanics::castNormal(const SpellCastEnvironment * env, const B
|
||||
|
||||
ctx.attackedCres = owner->getAffectedStacks(parameters.cb, parameters.mode, parameters.caster, parameters.spellLvl, parameters.getFirstDestinationHex());
|
||||
|
||||
logGlobal->debugStream() << "will affect: " << ctx.attackedCres.size() << " stacks";
|
||||
logGlobal->debugStream() << "will affect " << ctx.attackedCres.size() << " stacks";
|
||||
|
||||
handleResistance(env, ctx.attackedCres, ctx.sc);
|
||||
handleResistance(env, ctx);
|
||||
|
||||
handleMagicMirror(env, ctx, reflected);
|
||||
|
||||
@ -317,7 +316,7 @@ void DefaultSpellMechanics::castMagicMirror(const SpellCastEnvironment * env, co
|
||||
|
||||
logGlobal->debugStream() << "will affect: " << ctx.attackedCres.size() << " stacks";
|
||||
|
||||
handleResistance(env, ctx.attackedCres, ctx.sc);
|
||||
handleResistance(env, ctx);
|
||||
|
||||
applyBattleEffects(env, parameters, ctx);
|
||||
|
||||
@ -543,7 +542,6 @@ void DefaultSpellMechanics::applyBattleEffects(const SpellCastEnvironment * env,
|
||||
|
||||
if(!sse.stacks.empty())
|
||||
env->sendAndApply(&sse);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -661,7 +659,6 @@ std::vector<const CStack *> DefaultSpellMechanics::calculateAffectedStacks(const
|
||||
{
|
||||
attackedCres.insert(stacks.front());
|
||||
}
|
||||
|
||||
}
|
||||
else if(ctx.ti.massive)
|
||||
{
|
||||
@ -767,14 +764,14 @@ void DefaultSpellMechanics::handleMagicMirror(const SpellCastEnvironment * env,
|
||||
}
|
||||
}
|
||||
|
||||
void DefaultSpellMechanics::handleResistance(const SpellCastEnvironment * env, std::vector<const CStack* >& attackedCres, BattleSpellCast& sc) const
|
||||
void DefaultSpellMechanics::handleResistance(const SpellCastEnvironment * env, SpellCastContext & ctx) const
|
||||
{
|
||||
//checking if creatures resist
|
||||
//resistance is applied only to negative spells
|
||||
if(owner->isNegative())
|
||||
{
|
||||
std::vector <const CStack*> resisted;
|
||||
for(auto s : attackedCres)
|
||||
for(auto s : ctx.attackedCres)
|
||||
{
|
||||
//magic resistance
|
||||
const int prob = std::min((s)->magicResistance(), 100); //probability of resistance in %
|
||||
@ -785,7 +782,7 @@ void DefaultSpellMechanics::handleResistance(const SpellCastEnvironment * env, s
|
||||
}
|
||||
}
|
||||
|
||||
vstd::erase_if(attackedCres, [&resisted](const CStack * s)
|
||||
vstd::erase_if(ctx.attackedCres, [&resisted](const CStack * s)
|
||||
{
|
||||
return vstd::contains(resisted, s);
|
||||
});
|
||||
@ -795,7 +792,7 @@ void DefaultSpellMechanics::handleResistance(const SpellCastEnvironment * env, s
|
||||
BattleSpellCast::CustomEffect effect;
|
||||
effect.effect = 78;
|
||||
effect.stack = s->ID;
|
||||
sc.customEffects.push_back(effect);
|
||||
ctx.sc.customEffects.push_back(effect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ private:
|
||||
|
||||
void handleImmunities(const CBattleInfoCallback * cb, const SpellTargetingContext & ctx, std::vector<const CStack *> & stacks) const;
|
||||
void handleMagicMirror(const SpellCastEnvironment * env, SpellCastContext & ctx, std::vector <const CStack*> & reflected) const;
|
||||
void handleResistance(const SpellCastEnvironment * env, std::vector<const CStack*> & attackedCres, BattleSpellCast & sc) const;
|
||||
void handleResistance(const SpellCastEnvironment * env, SpellCastContext & ctx) const;
|
||||
|
||||
friend class SpellCastContext;
|
||||
};
|
||||
|
@ -37,7 +37,7 @@ BattleSpellCastParameters::Destination::Destination(const BattleHex & destinatio
|
||||
BattleSpellCastParameters::BattleSpellCastParameters(const BattleInfo * cb, const ISpellCaster * caster, const CSpell * spell)
|
||||
: cb(cb), caster(caster), casterColor(caster->getOwner()), casterSide(cb->whatSide(casterColor)),
|
||||
casterHero(nullptr),
|
||||
mode(ECastingMode::HERO_CASTING), casterStack(nullptr), selectedStack(nullptr),
|
||||
mode(ECastingMode::HERO_CASTING), casterStack(nullptr),
|
||||
spellLvl(-1), effectLevel(-1), effectPower(0), enchantPower(0), effectValue(0)
|
||||
{
|
||||
casterStack = dynamic_cast<const CStack *>(caster);
|
||||
@ -52,10 +52,12 @@ void BattleSpellCastParameters::aimToHex(const BattleHex& destination)
|
||||
|
||||
void BattleSpellCastParameters::aimToStack(const CStack * destination)
|
||||
{
|
||||
destinations.push_back(Destination(destination));
|
||||
if(nullptr == destination)
|
||||
logGlobal->error("BattleSpellCastParameters::aimToStack invalid stack.");
|
||||
else
|
||||
destinations.push_back(Destination(destination));
|
||||
}
|
||||
|
||||
|
||||
BattleHex BattleSpellCastParameters::getFirstDestinationHex() const
|
||||
{
|
||||
return destinations.at(0).hexValue;
|
||||
|
@ -60,7 +60,6 @@ public:
|
||||
const CGHeroInstance * casterHero; //deprecated
|
||||
ECastingMode::ECastingMode mode;
|
||||
const CStack * casterStack; //deprecated
|
||||
const CStack * selectedStack;//deprecated
|
||||
|
||||
///spell school level
|
||||
int spellLvl;
|
||||
|
@ -4171,7 +4171,6 @@ bool CGameHandler::makeBattleAction( BattleAction &ba )
|
||||
parameters.effectLevel = parameters.spellLvl;
|
||||
parameters.mode = ECastingMode::CREATURE_ACTIVE_CASTING;
|
||||
parameters.aimToHex(destination);//todo: allow multiple destinations
|
||||
parameters.selectedStack = nullptr;
|
||||
spell->battleCast(spellEnv, parameters);
|
||||
}
|
||||
sendAndApply(&end_action);
|
||||
@ -4370,7 +4369,8 @@ bool CGameHandler::makeCustomAction( BattleAction &ba )
|
||||
BattleSpellCastParameters parameters(gs->curB, h, s);
|
||||
parameters.aimToHex(ba.destinationTile);//todo: allow multiple destinations
|
||||
parameters.mode = ECastingMode::HERO_CASTING;
|
||||
parameters.selectedStack = gs->curB->battleGetStackByID(ba.selectedStack, false);
|
||||
if(ba.selectedStack >= 0)
|
||||
parameters.aimToStack(gs->curB->battleGetStackByID(ba.selectedStack, false));
|
||||
|
||||
ESpellCastProblem::ESpellCastProblem escp = gs->curB->battleCanCastThisSpell(h, s, ECastingMode::HERO_CASTING);//todo: should we check aimed cast(battleCanCastThisSpellHere)?
|
||||
if(escp != ESpellCastProblem::OK)
|
||||
@ -4522,7 +4522,6 @@ void CGameHandler::stackTurnTrigger(const CStack * st)
|
||||
parameters.effectLevel = bonus->val;//todo: recheck
|
||||
parameters.aimToHex(BattleHex::INVALID);
|
||||
parameters.mode = ECastingMode::ENCHANTER_CASTING;
|
||||
parameters.selectedStack = nullptr;
|
||||
|
||||
spell->battleCast(spellEnv, parameters);
|
||||
|
||||
@ -5233,7 +5232,6 @@ void CGameHandler::attackCasting(const BattleAttack & bat, Bonus::BonusType atta
|
||||
parameters.effectLevel = spellLevel;
|
||||
parameters.aimToStack(oneOfAttacked);
|
||||
parameters.mode = ECastingMode::AFTER_ATTACK_CASTING;
|
||||
parameters.selectedStack = nullptr;
|
||||
|
||||
spell->battleCast(spellEnv, parameters);
|
||||
}
|
||||
@ -5263,7 +5261,6 @@ void CGameHandler::handleAfterAttackCasting( const BattleAttack & bat )
|
||||
parameters.aimToStack(gs->curB->battleGetStackByID(bat.bsa.at(0).stackAttacked));
|
||||
parameters.effectPower = power;
|
||||
parameters.mode = ECastingMode::AFTER_ATTACK_CASTING;
|
||||
parameters.selectedStack = nullptr;
|
||||
|
||||
spell->battleCast(this->spellEnv, parameters);
|
||||
};
|
||||
@ -5570,7 +5567,6 @@ void CGameHandler::runBattle()
|
||||
parameters.effectLevel = 3;
|
||||
parameters.aimToHex(BattleHex::INVALID);
|
||||
parameters.mode = ECastingMode::PASSIVE_CASTING;
|
||||
parameters.selectedStack = nullptr;
|
||||
parameters.enchantPower = b->val;
|
||||
spell->battleCast(spellEnv, parameters);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user