瀏覽代碼

Fixed action cancel on active stack remove

AlexVinS 10 年之前
父節點
當前提交
2677d4a677
共有 4 個文件被更改,包括 21 次插入16 次删除
  1. 9 13
      client/CPlayerInterface.cpp
  2. 6 3
      client/Client.cpp
  3. 5 0
      client/battle/CBattleInterface.cpp
  4. 1 0
      lib/GameConstants.h

+ 9 - 13
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;
 }
 

+ 6 - 3
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&)

+ 5 - 0
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);
 		}
 	}

+ 1 - 0
lib/GameConstants.h

@@ -700,6 +700,7 @@ namespace Battle
 {
 	enum ActionType
 	{
+		CANCEL = -3,
 		END_TACTIC_PHASE = -2,
 		INVALID = -1,
 		NO_ACTION = 0,