1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-27 21:49:10 +02:00

Support hotseat over multiplier

This commit is contained in:
nordsoft 2022-10-05 01:54:31 +04:00
parent 77ff6a64e6
commit 3ff38b84a2
4 changed files with 40 additions and 30 deletions

View File

@ -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)
for(auto player : players)
{
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);
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);
}
}
}

View File

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

View File

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

View File

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