diff --git a/client/CPlayerInterface.cpp b/client/CPlayerInterface.cpp index e043f16dc..1bfe4ae98 100644 --- a/client/CPlayerInterface.cpp +++ b/client/CPlayerInterface.cpp @@ -813,21 +813,17 @@ BattleAction CPlayerInterface::activeStack(const CStack * stack) //called when i //tidy up BattleAction ret = *(b->givenCommand->data); - //todo: remove this evil hack - //dirty evil hack... - //if active stack was changed, new thread was started for new active stack but we will receive notification too - //we need check that givenCommand is for our stack (use ID as stack object may be even destroyed) - if(stackId != ret.stackNumber) + vstd::clear_pointer(b->givenCommand->data); + + if(ret.actionType == Battle::CANCEL) { - logGlobal->traceStream() << "Interrupted command for " << stackName; - throw boost::thread_interrupted(); + if(stackId != ret.stackNumber) + logGlobal->error("Not current active stack action canceled"); + logGlobal->traceStream() << "Canceled command for " << stackName; } - - delete b->givenCommand->data; - b->givenCommand->data = nullptr; - - //return command - logGlobal->traceStream() << "Giving command for " << stackName; + else + logGlobal->traceStream() << "Giving command for " << stackName; + return ret; } diff --git a/client/Client.cpp b/client/Client.cpp index f01ff0eb3..756725f34 100644 --- a/client/Client.cpp +++ b/client/Client.cpp @@ -140,9 +140,12 @@ void CClient::waitForMoveAndSend(PlayerColor color) setThreadName("CClient::waitForMoveAndSend"); assert(vstd::contains(battleints, color)); BattleAction ba = battleints[color]->activeStack(gs->curB->battleGetStackByID(gs->curB->activeStack, false)); - logNetwork->traceStream() << "Send battle action to server: " << ba; - MakeAction temp_action(ba); - sendRequest(&temp_action, color); + if(ba.actionType != Battle::CANCEL) + { + logNetwork->traceStream() << "Send battle action to server: " << ba; + MakeAction temp_action(ba); + sendRequest(&temp_action, color); + } return; } catch(boost::thread_interrupted&) diff --git a/client/battle/CBattleInterface.cpp b/client/battle/CBattleInterface.cpp index 382997d02..452b41d76 100644 --- a/client/battle/CBattleInterface.cpp +++ b/client/battle/CBattleInterface.cpp @@ -1009,6 +1009,11 @@ void CBattleInterface::stackRemoved(int stackID) { if(activeStack->ID == stackID) { + BattleAction * action = new BattleAction(); + action->side = defendingHeroInstance ? (curInt->playerID == defendingHeroInstance->tempOwner) : false; + action->actionType = Battle::CANCEL; + action->stackNumber = activeStack->ID; + givenCommand->setn(action); setActiveStack(nullptr); } } diff --git a/lib/GameConstants.h b/lib/GameConstants.h index 24ab8789c..b6e24c7d3 100644 --- a/lib/GameConstants.h +++ b/lib/GameConstants.h @@ -700,6 +700,7 @@ namespace Battle { enum ActionType { + CANCEL = -3, END_TACTIC_PHASE = -2, INVALID = -1, NO_ACTION = 0,