Browse Source

Support hotseat over multiplier

nordsoft 3 năm trước cách đây
mục cha
commit
3ff38b84a2
4 tập tin đã thay đổi với 41 bổ sung31 xóa
  1. 21 18
      client/NetPacksClient.cpp
  2. 2 2
      lib/NetPacks.h
  3. 4 1
      lib/NetPacksLib.cpp
  4. 14 10
      server/CVCMIServer.cpp

+ 21 - 18
client/NetPacksClient.cpp

@@ -347,24 +347,27 @@ void PlayerEndsGame::applyCl(CClient *cl)
 
 void PlayerReinitInterface::applyCl(CClient * cl)
 {
-	auto & plSettings = CSH->si->getIthPlayersSettings(player);
-	if(playerConnectionId == PlayerSettings::PLAYER_AI)
-	{
-		plSettings.connectedPlayerIDs.clear();
-		cl->initPlayerEnvironments();
-		cl->initPlayerInterfaces();
-		auto currentPlayer = cl->gameState()->currentPlayer;
-		callAllInterfaces(cl, &IGameEventsReceiver::playerStartsTurn, currentPlayer);
-		callOnlyThatInterface(cl, currentPlayer, &CGameInterface::yourTurn);
-	}
-	else if(playerConnectionId == CSH->c->connectionID)
-	{
-		plSettings.connectedPlayerIDs.insert(playerConnectionId);
-		cl->playerint.clear();
-		cl->initPlayerInterfaces();
-		auto currentPlayer = cl->gameState()->currentPlayer;
-		callAllInterfaces(cl, &IGameEventsReceiver::playerStartsTurn, currentPlayer);
-		callOnlyThatInterface(cl, currentPlayer, &CGameInterface::yourTurn);
+	for(auto player : players)
+	{
+		auto & plSettings = CSH->si->getIthPlayersSettings(player);
+		if(playerConnectionId == PlayerSettings::PLAYER_AI)
+		{
+			plSettings.connectedPlayerIDs.clear();
+			cl->initPlayerEnvironments();
+			cl->initPlayerInterfaces();
+			auto currentPlayer = cl->gameState()->currentPlayer;
+			callAllInterfaces(cl, &IGameEventsReceiver::playerStartsTurn, currentPlayer);
+			callOnlyThatInterface(cl, currentPlayer, &CGameInterface::yourTurn);
+		}
+		else if(playerConnectionId == CSH->c->connectionID)
+		{
+			plSettings.connectedPlayerIDs.insert(playerConnectionId);
+			cl->playerint.clear();
+			cl->initPlayerInterfaces();
+			auto currentPlayer = cl->gameState()->currentPlayer;
+			callAllInterfaces(cl, &IGameEventsReceiver::playerStartsTurn, currentPlayer);
+			callOnlyThatInterface(cl, currentPlayer, &CGameInterface::yourTurn);
+		}
 	}
 }
 

+ 2 - 2
lib/NetPacks.h

@@ -426,12 +426,12 @@ struct PlayerReinitInterface : public CPackForClient
 	void applyCl(CClient * cl);
 	DLL_LINKAGE void applyGs(CGameState *gs);
 	
-	PlayerColor player;
+	std::vector<PlayerColor> players;
 	ui8 playerConnectionId; //PLAYER_AI fro AI player
 	
 	template <typename Handler> void serialize(Handler &h, const int version)
 	{
-		h & player;
+		h & players;
 		h & playerConnectionId;
 	}
 };

+ 4 - 1
lib/NetPacksLib.cpp

@@ -372,7 +372,10 @@ DLL_LINKAGE void PlayerReinitInterface::applyGs(CGameState *gs)
 	
 	//TODO: what does mean if more that one player connected?
 	if(playerConnectionId == PlayerSettings::PLAYER_AI)
-		gs->scenarioOps->getIthPlayersSettings(player).connectedPlayerIDs.clear();
+	{
+		for(auto player : players)
+			gs->scenarioOps->getIthPlayersSettings(player).connectedPlayerIDs.clear();
+	}
 }
 
 DLL_LINKAGE void RemoveBonus::applyGs(CGameState *gs)

+ 14 - 10
server/CVCMIServer.cpp

@@ -507,6 +507,9 @@ void CVCMIServer::clientDisconnected(std::shared_ptr<CConnection> c)
 		return;
 	}
 	
+	PlayerReinitInterface startAiPack;
+	startAiPack.playerConnectionId = PlayerSettings::PLAYER_AI;
+	
 	for(auto it = playerNames.begin(); it != playerNames.end();)
 	{
 		if(it->second.connection != c->connectionID)
@@ -532,16 +535,19 @@ void CVCMIServer::clientDisconnected(std::shared_ptr<CConnection> c)
 		{
 			gh->playerMessage(playerSettings->color, playerLeftMsgText, ObjectInstanceID{});
 			gh->connections[playerSettings->color].insert(hostClient);
-			PlayerReinitInterface startAiPack;
-			startAiPack.player = playerSettings->color;
-			startAiPack.playerConnectionId = PlayerSettings::PLAYER_AI;
-			gh->sendAndApply(&startAiPack);
+			startAiPack.players.push_back(playerSettings->color);
 		}
 	}
+	
+	if(!startAiPack.players.empty())
+		gh->sendAndApply(&startAiPack);
 }
 
 void CVCMIServer::reconnectPlayer(int connId)
 {
+	PlayerReinitInterface startAiPack;
+	startAiPack.playerConnectionId = connId;
+	
 	if(gh && si && state == EServerState::GAMEPLAY)
 	{
 		for(auto it = playerNames.begin(); it != playerNames.end(); ++it)
@@ -557,13 +563,11 @@ void CVCMIServer::reconnectPlayer(int connId)
 			std::string messageText = boost::str(boost::format("%s (cid %d) is connected") % playerSettings->name % connId);
 			gh->playerMessage(playerSettings->color, messageText, ObjectInstanceID{});
 			
-			PlayerReinitInterface startAiPack;
-			startAiPack.player = playerSettings->color;
-			startAiPack.playerConnectionId = connId;
-			gh->sendAndApply(&startAiPack);
+			startAiPack.players.push_back(playerSettings->color);
 		}
-		//gh->playerMessage(playerSettings->color, playerLeftMsgText, ObjectInstanceID{});
-		//gh->connections[playerSettings->color].insert(hostClient);
+
+		if(!startAiPack.players.empty())
+			gh->sendAndApply(&startAiPack);
 	}
 }