From 939a9180e27973508441f5d548e52e3932f32204 Mon Sep 17 00:00:00 2001 From: AlexVinS Date: Wed, 30 Sep 2015 22:38:50 +0300 Subject: [PATCH] Added new BattleSpellCastParameters support to TELEPORT spell. --- lib/spells/BattleSpellMechanics.cpp | 47 +++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/lib/spells/BattleSpellMechanics.cpp b/lib/spells/BattleSpellMechanics.cpp index 323c18698..2052eeb91 100644 --- a/lib/spells/BattleSpellMechanics.cpp +++ b/lib/spells/BattleSpellMechanics.cpp @@ -668,14 +668,43 @@ void SummonMechanics::applyBattleEffects(const SpellCastEnvironment * env, const void TeleportMechanics::applyBattleEffects(const SpellCastEnvironment * env, const BattleSpellCastParameters & parameters, SpellCastContext & ctx) const { //todo: check legal teleport - - BattleStackMoved bsm; - bsm.distance = -1; - bsm.stack = parameters.selectedStack->ID;//todo: use destinations - std::vector tiles; - tiles.push_back(parameters.getFirstDestinationHex()); - bsm.tilesToMove = tiles; - bsm.teleporting = true; - env->sendAndApply(&bsm); + 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; + if(!destination.isValid()) + { + env->complain("TeleportMechanics: invalid teleport destination"); + return; + } + BattleStackMoved bsm; + bsm.distance = -1; + bsm.stack = target->ID; + std::vector tiles; + tiles.push_back(destination); + bsm.tilesToMove = tiles; + bsm.teleporting = true; + env->sendAndApply(&bsm); + } + else + { + //todo: remove and report error + BattleStackMoved bsm; + bsm.distance = -1; + bsm.stack = parameters.selectedStack->ID; + std::vector tiles; + tiles.push_back(parameters.getFirstDestinationHex()); + bsm.tilesToMove = tiles; + bsm.teleporting = true; + env->sendAndApply(&bsm); + } } +