1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-25 22:42:04 +02:00

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

This commit is contained in:
beegee1
2013-01-21 20:49:19 +00:00
parent 5b2f176c27
commit a4129f43f2
3 changed files with 26 additions and 27 deletions

View File

@@ -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();