1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-10-31 00:07:39 +02:00
This commit is contained in:
AlexVinS
2016-09-06 12:26:01 +03:00
parent cc4362211c
commit 686cd00c68
6 changed files with 30 additions and 49 deletions

View File

@@ -685,11 +685,7 @@ void SacrificeMechanics::applyBattleEffects(const SpellCastEnvironment * env, co
{ {
victim = parameters.destinations[1].stackValue; victim = parameters.destinations[1].stackValue;
} }
else
{
//todo: remove and report error
victim = parameters.selectedStack;
}
if(nullptr == victim) if(nullptr == victim)
{ {
env->complain("SacrificeMechanics: No stack to sacrifice"); env->complain("SacrificeMechanics: No stack to sacrifice");
@@ -712,11 +708,7 @@ int SacrificeMechanics::calculateHealedHP(const SpellCastEnvironment* env, const
{ {
victim = parameters.destinations[1].stackValue; victim = parameters.destinations[1].stackValue;
} }
else
{
//todo: remove and report error
victim = parameters.selectedStack;
}
if(nullptr == victim) if(nullptr == victim)
{ {
env->complain("SacrificeMechanics: No stack to sacrifice"); env->complain("SacrificeMechanics: No stack to sacrifice");
@@ -817,20 +809,22 @@ void TeleportMechanics::applyBattleEffects(const SpellCastEnvironment * env, con
//todo: check legal teleport //todo: check legal teleport
if(parameters.destinations.size() == 2) if(parameters.destinations.size() == 2)
{ {
//first destination creature to move //first destination hex to move to
const CStack * target = parameters.destinations[0].stackValue; const BattleHex destination = parameters.destinations[0].hexValue;
if(nullptr == target)
{
env->complain("TeleportMechanics: no stack to teleport");
return;
}
//second destination hex to move to
const BattleHex destination = parameters.destinations[1].hexValue;
if(!destination.isValid()) if(!destination.isValid())
{ {
env->complain("TeleportMechanics: invalid teleport destination"); env->complain("TeleportMechanics: invalid teleport destination");
return; 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; BattleStackMoved bsm;
bsm.distance = -1; bsm.distance = -1;
bsm.stack = target->ID; bsm.stack = target->ID;
@@ -842,15 +836,8 @@ void TeleportMechanics::applyBattleEffects(const SpellCastEnvironment * env, con
} }
else else
{ {
//todo: remove and report error env->complain("TeleportMechanics: 2 destinations required.");
BattleStackMoved bsm; return;
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);
} }
} }

View File

@@ -217,7 +217,6 @@ void DefaultSpellMechanics::battleCast(const SpellCastEnvironment * env, const B
mirrorParameters.spellLvl = 0; mirrorParameters.spellLvl = 0;
mirrorParameters.aimToHex(targetHex); mirrorParameters.aimToHex(targetHex);
mirrorParameters.mode = ECastingMode::MAGIC_MIRROR; mirrorParameters.mode = ECastingMode::MAGIC_MIRROR;
mirrorParameters.selectedStack = nullptr;
mirrorParameters.spellLvl = parameters.spellLvl; mirrorParameters.spellLvl = parameters.spellLvl;
mirrorParameters.effectLevel = parameters.effectLevel; mirrorParameters.effectLevel = parameters.effectLevel;
mirrorParameters.effectPower = parameters.effectPower; 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()); 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); handleMagicMirror(env, ctx, reflected);
@@ -317,7 +316,7 @@ void DefaultSpellMechanics::castMagicMirror(const SpellCastEnvironment * env, co
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);
applyBattleEffects(env, parameters, ctx); applyBattleEffects(env, parameters, ctx);
@@ -543,7 +542,6 @@ void DefaultSpellMechanics::applyBattleEffects(const SpellCastEnvironment * env,
if(!sse.stacks.empty()) if(!sse.stacks.empty())
env->sendAndApply(&sse); env->sendAndApply(&sse);
} }
} }
@@ -661,7 +659,6 @@ std::vector<const CStack *> DefaultSpellMechanics::calculateAffectedStacks(const
{ {
attackedCres.insert(stacks.front()); attackedCres.insert(stacks.front());
} }
} }
else if(ctx.ti.massive) 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 //checking if creatures resist
//resistance is applied only to negative spells //resistance is applied only to negative spells
if(owner->isNegative()) if(owner->isNegative())
{ {
std::vector <const CStack*> resisted; std::vector <const CStack*> resisted;
for(auto s : attackedCres) for(auto s : ctx.attackedCres)
{ {
//magic resistance //magic resistance
const int prob = std::min((s)->magicResistance(), 100); //probability of resistance in % 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); return vstd::contains(resisted, s);
}); });
@@ -795,7 +792,7 @@ void DefaultSpellMechanics::handleResistance(const SpellCastEnvironment * env, s
BattleSpellCast::CustomEffect effect; BattleSpellCast::CustomEffect effect;
effect.effect = 78; effect.effect = 78;
effect.stack = s->ID; effect.stack = s->ID;
sc.customEffects.push_back(effect); ctx.sc.customEffects.push_back(effect);
} }
} }
} }

View File

@@ -70,7 +70,7 @@ private:
void handleImmunities(const CBattleInfoCallback * cb, const SpellTargetingContext & ctx, std::vector<const CStack *> & stacks) const; 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 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; friend class SpellCastContext;
}; };

View File

@@ -37,7 +37,7 @@ BattleSpellCastParameters::Destination::Destination(const BattleHex & destinatio
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), casterColor(caster->getOwner()), casterSide(cb->whatSide(casterColor)), : cb(cb), caster(caster), casterColor(caster->getOwner()), casterSide(cb->whatSide(casterColor)),
casterHero(nullptr), 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) spellLvl(-1), effectLevel(-1), effectPower(0), enchantPower(0), effectValue(0)
{ {
casterStack = dynamic_cast<const CStack *>(caster); casterStack = dynamic_cast<const CStack *>(caster);
@@ -52,10 +52,12 @@ void BattleSpellCastParameters::aimToHex(const BattleHex& destination)
void BattleSpellCastParameters::aimToStack(const CStack * 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 BattleHex BattleSpellCastParameters::getFirstDestinationHex() const
{ {
return destinations.at(0).hexValue; return destinations.at(0).hexValue;

View File

@@ -60,7 +60,6 @@ public:
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;//deprecated
///spell school level ///spell school level
int spellLvl; int spellLvl;

View File

@@ -4171,7 +4171,6 @@ bool CGameHandler::makeBattleAction( BattleAction &ba )
parameters.effectLevel = parameters.spellLvl; parameters.effectLevel = parameters.spellLvl;
parameters.mode = ECastingMode::CREATURE_ACTIVE_CASTING; parameters.mode = ECastingMode::CREATURE_ACTIVE_CASTING;
parameters.aimToHex(destination);//todo: allow multiple destinations parameters.aimToHex(destination);//todo: allow multiple destinations
parameters.selectedStack = nullptr;
spell->battleCast(spellEnv, parameters); spell->battleCast(spellEnv, parameters);
} }
sendAndApply(&end_action); sendAndApply(&end_action);
@@ -4370,7 +4369,8 @@ bool CGameHandler::makeCustomAction( BattleAction &ba )
BattleSpellCastParameters parameters(gs->curB, h, s); BattleSpellCastParameters parameters(gs->curB, h, s);
parameters.aimToHex(ba.destinationTile);//todo: allow multiple destinations parameters.aimToHex(ba.destinationTile);//todo: allow multiple destinations
parameters.mode = ECastingMode::HERO_CASTING; 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)? ESpellCastProblem::ESpellCastProblem escp = gs->curB->battleCanCastThisSpell(h, s, ECastingMode::HERO_CASTING);//todo: should we check aimed cast(battleCanCastThisSpellHere)?
if(escp != ESpellCastProblem::OK) if(escp != ESpellCastProblem::OK)
@@ -4522,7 +4522,6 @@ void CGameHandler::stackTurnTrigger(const CStack * st)
parameters.effectLevel = bonus->val;//todo: recheck parameters.effectLevel = bonus->val;//todo: recheck
parameters.aimToHex(BattleHex::INVALID); parameters.aimToHex(BattleHex::INVALID);
parameters.mode = ECastingMode::ENCHANTER_CASTING; parameters.mode = ECastingMode::ENCHANTER_CASTING;
parameters.selectedStack = nullptr;
spell->battleCast(spellEnv, parameters); spell->battleCast(spellEnv, parameters);
@@ -5233,7 +5232,6 @@ void CGameHandler::attackCasting(const BattleAttack & bat, Bonus::BonusType atta
parameters.effectLevel = spellLevel; parameters.effectLevel = spellLevel;
parameters.aimToStack(oneOfAttacked); parameters.aimToStack(oneOfAttacked);
parameters.mode = ECastingMode::AFTER_ATTACK_CASTING; parameters.mode = ECastingMode::AFTER_ATTACK_CASTING;
parameters.selectedStack = nullptr;
spell->battleCast(spellEnv, parameters); 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.aimToStack(gs->curB->battleGetStackByID(bat.bsa.at(0).stackAttacked));
parameters.effectPower = power; parameters.effectPower = power;
parameters.mode = ECastingMode::AFTER_ATTACK_CASTING; parameters.mode = ECastingMode::AFTER_ATTACK_CASTING;
parameters.selectedStack = nullptr;
spell->battleCast(this->spellEnv, parameters); spell->battleCast(this->spellEnv, parameters);
}; };
@@ -5570,7 +5567,6 @@ void CGameHandler::runBattle()
parameters.effectLevel = 3; parameters.effectLevel = 3;
parameters.aimToHex(BattleHex::INVALID); parameters.aimToHex(BattleHex::INVALID);
parameters.mode = ECastingMode::PASSIVE_CASTING; parameters.mode = ECastingMode::PASSIVE_CASTING;
parameters.selectedStack = nullptr;
parameters.enchantPower = b->val; parameters.enchantPower = b->val;
spell->battleCast(spellEnv, parameters); spell->battleCast(spellEnv, parameters);
} }