Michał W. Urbańczyk 14 years ago
parent
commit
4f20c5a376
4 changed files with 15 additions and 6 deletions
  1. 1 1
      client/CPlayerInterface.cpp
  2. 6 3
      client/Client.cpp
  3. 6 1
      server/CGameHandler.cpp
  4. 2 1
      server/NetPacksServer.cpp

+ 1 - 1
client/CPlayerInterface.cpp

@@ -894,7 +894,7 @@ void CPlayerInterface::battleAttack(const BattleAttack *ba)
 
 void CPlayerInterface::yourTacticPhase(int distance)
 {
-	while(battleInt->tacticsMode)
+	while(battleInt && battleInt->tacticsMode)
 		boost::this_thread::sleep(boost::posix_time::millisec(1));
 }
 

+ 6 - 3
client/Client.cpp

@@ -598,7 +598,7 @@ void CClient::battleStarted(const BattleInfo * info)
 
 	if(info->tacticDistance && vstd::contains(battleints,info->sides[info->tacticsSide]))
 	{
-		boost::thread hlp = boost::thread(&CClient::commenceTacticPhaseForInt, this, battleints[info->sides[info->tacticsSide]]);
+		boost::thread(&CClient::commenceTacticPhaseForInt, this, battleints[info->sides[info->tacticsSide]]);
 	}
 }
 
@@ -636,8 +636,11 @@ void CClient::commenceTacticPhaseForInt(CBattleGameInterface *battleInt)
 	try
 	{
 		battleInt->yourTacticPhase(gs->curB->tacticDistance);
-		MakeAction ma(BattleAction::makeEndOFTacticPhase(battleInt->playerID));
-		serv->sendPack(ma);
+		if(gs && !!gs->curB && gs->curB->tacticDistance) //while awaiting for end of tactics phase, many things can happen (end of battle... or game)
+		{
+			MakeAction ma(BattleAction::makeEndOFTacticPhase(battleInt->playerID));
+			serv->sendPack(ma);
+		}
 	} HANDLE_EXCEPTION
 }
 

+ 6 - 1
server/CGameHandler.cpp

@@ -4915,7 +4915,7 @@ void CGameHandler::runBattle()
 
 	//tactic round
 	{
-		while(gs->curB->tacticDistance)
+		while(gs->curB->tacticDistance && !battleResult.get())
 			boost::this_thread::sleep(boost::posix_time::milliseconds(50));
 	}
 
@@ -5191,6 +5191,11 @@ void CGameHandler::giveHeroNewArtifact(const CGHeroInstance *h, const CArtifact
 
 void CGameHandler::setBattleResult(int resultType, int victoriusSide)
 {
+	if(battleResult.get())
+	{
+		complain("There is already set result?");
+		return;
+	}
 	BattleResult *br = new BattleResult;
 	br->result = resultType;
 	br->winner = victoriusSide; //surrendering side loses

+ 2 - 1
server/NetPacksServer.cpp

@@ -236,7 +236,8 @@ bool MakeAction::applyGh( CGameHandler *gh )
 	
 	if(b->tacticDistance)
 	{
-		if(ba.actionType != BattleAction::WALK  &&  ba.actionType != BattleAction::END_TACTIC_PHASE)
+		if(ba.actionType != BattleAction::WALK  &&  ba.actionType != BattleAction::END_TACTIC_PHASE  
+			&& ba.actionType != BattleAction::RETREAT && ba.actionType != BattleAction::SURRENDER)
 			ERROR_AND_RETURN;
 		if(gh->connections[b->sides[b->tacticsSide]] != c) 
 			ERROR_AND_RETURN;