Pārlūkot izejas kodu

NKAI: fix gosolo when human is lead by gosolo AI + multiplayer

Andrii Danylchenko 1 gadu atpakaļ
vecāks
revīzija
7571fb7046
2 mainītis faili ar 30 papildinājumiem un 11 dzēšanām
  1. 12 0
      AI/Nullkiller/AIGateway.cpp
  2. 18 11
      client/ClientCommandManager.cpp

+ 12 - 0
AI/Nullkiller/AIGateway.cpp

@@ -28,6 +28,7 @@
 #include "../../lib/networkPacks/StackLocation.h"
 #include "../../lib/battle/BattleStateInfoForRetreat.h"
 #include "../../lib/battle/BattleInfo.h"
+#include "../../lib/CPlayerState.h"
 
 #include "AIGateway.h"
 #include "Goals/Goals.h"
@@ -1166,6 +1167,17 @@ void AIGateway::battleEnd(const BattleID & battleID, const BattleResult * br, Qu
 	battlename.clear();
 
 	CAdventureAI::battleEnd(battleID, br, queryID);
+
+	// gosolo
+	if(queryID != QueryID::NONE && myCb->getPlayerState(playerID)->isHuman())
+	{
+		status.addQuery(queryID, "Confirm battle query");
+
+		requestActionASAP([=]()
+			{
+				answerQuery(queryID, 0);
+			});
+	}
 }
 
 void AIGateway::waitTillFree()

+ 18 - 11
client/ClientCommandManager.cpp

@@ -39,6 +39,7 @@
 #include "../lib/VCMIDirs.h"
 #include "../lib/logging/VisualLogger.h"
 #include "CMT.h"
+#include "../lib/serializer/Connection.h"
 
 #ifdef SCRIPTING_ENABLED
 #include "../lib/ScriptHandler.h"
@@ -82,31 +83,37 @@ void ClientCommandManager::handleGoSoloCommand()
 		printCommandMessage("Game is not in playing state");
 		return;
 	}
-	PlayerColor color;
+
 	if(session["aiSolo"].Bool())
 	{
-		for(auto & elem : CSH->client->gameState()->players)
+		// unlikely it will work but just in case to be consistent
+		for(auto & color : CSH->getAllClientPlayers(CSH->logicConnection->connectionID))
 		{
-			if(elem.second.human)
-				CSH->client->installNewPlayerInterface(std::make_shared<CPlayerInterface>(elem.first), elem.first);
+			if(CSH->client->getStartInfo()->playerInfos.at(color).isControlledByHuman())
+			{
+				CSH->client->installNewPlayerInterface(std::make_shared<CPlayerInterface>(color), color);
+			}
 		}
 	}
 	else
 	{
-		color = LOCPLINT->playerID;
+		PlayerColor currentColor = LOCPLINT->playerID;
 		CSH->client->removeGUI();
-		for(auto & elem : CSH->client->gameState()->players)
+		
+		for(auto & color : CSH->getAllClientPlayers(CSH->logicConnection->connectionID))
 		{
-			if(elem.second.human)
+			if(CSH->client->getStartInfo()->playerInfos.at(color).isControlledByHuman())
 			{
-				auto AiToGive = CSH->client->aiNameForPlayer(*CSH->client->getPlayerSettings(elem.first), false, false);
-				printCommandMessage("Player " + elem.first.toString() + " will be lead by " + AiToGive, ELogLevel::INFO);
-				CSH->client->installNewPlayerInterface(CDynLibHandler::getNewAI(AiToGive), elem.first);
+				auto AiToGive = CSH->client->aiNameForPlayer(*CSH->client->getPlayerSettings(color), false, false);
+				printCommandMessage("Player " + color.toString() + " will be lead by " + AiToGive, ELogLevel::INFO);
+				CSH->client->installNewPlayerInterface(CDynLibHandler::getNewAI(AiToGive), color);
 			}
 		}
+
 		GH.windows().totalRedraw();
-		giveTurn(color);
+		giveTurn(currentColor);
 	}
+
 	session["aiSolo"].Bool() = !session["aiSolo"].Bool();
 }