Commit ad40194f authored by Max-Wilhelm Bruker's avatar Max-Wilhelm Bruker
Browse files

nextTurn cleanup -> fixed the bug that the game would begin with active player...

nextTurn cleanup -> fixed the bug that the game would begin with active player 0 even if there is no player 0
parent cbfbc542
......@@ -138,7 +138,8 @@ void Server_Game::startGameIfReady()
query.exec();
}
*/
setActivePlayer(0);
activePlayer = -1;
nextTurn();
}
void Server_Game::stopGameIfFinished()
......@@ -254,6 +255,21 @@ void Server_Game::setActivePhase(int _activePhase)
sendGameEvent(new Event_SetActivePhase(-1, activePhase));
}
void Server_Game::nextTurn()
{
const QList<int> keys = players.keys();
int listPos = -1;
if (activePlayer != -1)
listPos = keys.indexOf(activePlayer);
do {
++listPos;
if (listPos == keys.size())
listPos = 0;
} while (players.value(keys[listPos])->getSpectator());
setActivePlayer(keys[listPos]);
}
QList<ServerInfo_Player *> Server_Game::getGameState(Server_Player *playerWhosAsking) const
{
QList<ServerInfo_Player *> result;
......
......@@ -76,6 +76,7 @@ public:
int getActivePhase() const { return activePhase; }
void setActivePlayer(int _activePlayer);
void setActivePhase(int _activePhase);
void nextTurn();
QList<ServerInfo_Player *> getGameState(Server_Player *playerWhosAsking) const;
void sendGameEvent(GameEvent *event, GameEventContext *context = 0, Server_Player *exclude = 0);
......
......@@ -952,18 +952,7 @@ ResponseCode Server_ProtocolHandler::cmdNextTurn(Command_NextTurn * /*cmd*/, Com
if (!game->getGameStarted())
return RespGameNotStarted;
const QMap<int, Server_Player *> &players = game->getPlayers();
const QList<int> keys = players.keys();
int activePlayer = game->getActivePlayer();
int listPos = keys.indexOf(activePlayer);
do {
++listPos;
if (listPos == keys.size())
listPos = 0;
} while (players.value(keys[listPos])->getSpectator());
game->setActivePlayer(keys[listPos]);
game->nextTurn();
return RespOk;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment