1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +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();

View File

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

View File

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