瀏覽代碼

- Correct handling of who manages which players(player count may differ from initial start options for a RMG map) - Fixed warning

beegee1 12 年之前
父節點
當前提交
a4129f43f2
共有 3 個文件被更改,包括 26 次插入27 次删除
  1. 18 16
      client/Client.cpp
  2. 1 1
      lib/CArtHandler.cpp
  3. 7 10
      server/CGameHandler.cpp

+ 18 - 16
client/Client.cpp

@@ -289,7 +289,6 @@ void CClient::loadGame( const std::string & fname )
 void CClient::newGame( CConnection *con, StartInfo *si )
 {
 	enum {SINGLE, HOST, GUEST} networkMode = SINGLE;
-	std::set<TPlayerColor> myPlayers;
 
 	if (con == NULL) 
 	{
@@ -302,18 +301,6 @@ void CClient::newGame( CConnection *con, StartInfo *si )
 		networkMode = (con->connectionID == 1) ? HOST : GUEST;
 	}
 
-	for(auto it = si->playerInfos.begin(); it != si->playerInfos.end(); ++it)
-	{
-		if((networkMode == SINGLE)                                                      //single - one client has all player
-		   || (networkMode != SINGLE && serv->connectionID == it->second.playerID)      //multi - client has only "its players"
-		   || (networkMode == HOST && it->second.playerID == PlayerSettings::PLAYER_AI))//multi - host has all AI players
-		{
-			myPlayers.insert(it->first); //add player
-		}
-	}
-	if(networkMode != GUEST)
-		myPlayers.insert(GameConstants::NEUTRAL_PLAYER);
-
 	CStopWatch tmh;
 	const_cast<CGameInfo*>(CGI)->state = new CGameState();
 	tlog0 <<"\tGamestate: "<<tmh.getDiff()<<std::endl;
@@ -332,19 +319,34 @@ void CClient::newGame( CConnection *con, StartInfo *si )
 			tlog0 << "Server opened map properly.\n";
 	}
 
-	c << myPlayers;
-
-
 	c >> si;
 	tlog0 <<"\tSending/Getting info to/from the server: "<<tmh.getDiff()<<std::endl;
 	c.enableStackSendingByID();
 	c.disableSmartPointerSerialization();
 
+	// Initialize game state
 	gs = const_cast<CGameInfo*>(CGI)->state;
 	gs->scenarioOps = si;
 	gs->init(si);
 	tlog0 <<"Initializing GameState (together): "<<tmh.getDiff()<<std::endl;
 
+	// Now after possible random map gen, we know exact player count.
+	// Inform server about how many players client handles
+	std::set<TPlayerColor> myPlayers;
+	for(auto it = gs->scenarioOps->playerInfos.begin(); it != gs->scenarioOps->playerInfos.end(); ++it)
+	{
+		if((networkMode == SINGLE)                                                      //single - one client has all player
+		   || (networkMode != SINGLE && serv->connectionID == it->second.playerID)      //multi - client has only "its players"
+		   || (networkMode == HOST && it->second.playerID == PlayerSettings::PLAYER_AI))//multi - host has all AI players
+		{
+			myPlayers.insert(it->first); //add player
+		}
+	}
+	if(networkMode != GUEST)
+		myPlayers.insert(GameConstants::NEUTRAL_PLAYER);
+	c << myPlayers;
+
+	// Init map handler
 	if(gs->map)
 	{
 		const_cast<CGameInfo*>(CGI)->mh = new CMapHandler();

+ 1 - 1
lib/CArtHandler.cpp

@@ -779,7 +779,7 @@ void CArtHandler::clearHlpLists()
 bool CArtHandler::legalArtifact(int id)
 {
 	return (artifacts[id]->possibleSlots[ArtBearer::HERO].size() ||
-			artifacts[id]->possibleSlots[ArtBearer::COMMANDER].size() && VLC->modh->modules.COMMANDERS) ||
+			(artifacts[id]->possibleSlots[ArtBearer::COMMANDER].size() && VLC->modh->modules.COMMANDERS)) ||
 			(artifacts[id]->possibleSlots[ArtBearer::CREATURE].size() && VLC->modh->modules.STACK_ARTIFACT);
 }
 

+ 7 - 10
server/CGameHandler.cpp

@@ -1461,25 +1461,22 @@ void CGameHandler::run(bool resume)
 {
 	using namespace boost::posix_time;
 	BOOST_FOREACH(CConnection *cc, conns)
-	{//init conn.
-		ui32 quantity;
-		TPlayerColor pom;
-		//ui32 seed;
+	{
 		if(!resume)
 		{
 			(*cc) << gs->initialOpts; // gs->scenarioOps
 		}
 
-		(*cc) >> quantity; //how many players will be handled at that client
+		std::set<TPlayerColor> players;
+		(*cc) >> players; //how many players will be handled at that client
 
-		tlog0 << "Connection " << cc->connectionID << " will handle " << quantity << " player: ";
-		for(int i=0;i<quantity;i++)
+		tlog0 << "Connection " << cc->connectionID << " will handle " << players.size() << " player: ";
+		BOOST_FOREACH(TPlayerColor color, players)
 		{
-			(*cc) >> pom; //read player color
-			tlog0 << (int)pom << " ";
+			tlog0 << static_cast<int>(color) << " ";
 			{
 				boost::unique_lock<boost::recursive_mutex> lock(gsm);
-				connections[pom] = cc;
+				connections[color] = cc;
 			}
 		}
 		tlog0 << std::endl;