mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Fix handling of turn order in case of player defeat
This commit is contained in:
parent
f451c15932
commit
a19cdb57ba
@ -3480,6 +3480,8 @@ void CGameHandler::checkVictoryLossConditionsForPlayer(PlayerColor player)
|
||||
peg.victoryLossCheckResult = victoryLossCheckResult;
|
||||
sendAndApply(&peg);
|
||||
|
||||
turnOrder->onPlayerEndsGame(player);
|
||||
|
||||
if (victoryLossCheckResult.victory())
|
||||
{
|
||||
//one player won -> all enemies lost
|
||||
@ -3545,13 +3547,6 @@ void CGameHandler::checkVictoryLossConditionsForPlayer(PlayerColor player)
|
||||
}
|
||||
checkVictoryLossConditions(playerColors);
|
||||
}
|
||||
|
||||
auto playerInfo = getPlayerState(gs->currentPlayer, false);
|
||||
|
||||
// If we are called before the actual game start, there might be no current player
|
||||
// If player making turn has lost his turn must be over as well
|
||||
if (playerInfo && playerInfo->status != EPlayerStatus::INGAME)
|
||||
turnOrder->onPlayerEndsTurn(gs->currentPlayer, PlayerTurnEndReason::GAME_END);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,7 @@ void ApplyGhNetPackVisitor::visitEndTurn(EndTurn & pack)
|
||||
if (!gh.hasPlayerAt(pack.player, pack.c))
|
||||
gh.throwAndComplain(&pack, "No such pack.player!");
|
||||
|
||||
result = gh.turnOrder->onPlayerEndsTurn(pack.player, PlayerTurnEndReason::CLIENT_REQUEST);
|
||||
result = gh.turnOrder->onPlayerEndsTurn(pack.player);
|
||||
}
|
||||
|
||||
void ApplyGhNetPackVisitor::visitDismissHero(DismissHero & pack)
|
||||
|
@ -85,7 +85,7 @@ void TurnTimerHandler::onPlayerMakingTurn(PlayerState & state, int waitTime)
|
||||
onPlayerMakingTurn(state, waitTime);
|
||||
}
|
||||
else if(!gameHandler.queries->topQuery(state.color))
|
||||
gameHandler.turnOrder->onPlayerEndsTurn(state.color, PlayerTurnEndReason::TURN_TIMEOUT);
|
||||
gameHandler.turnOrder->onPlayerEndsTurn(state.color);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -108,12 +108,11 @@ void TurnOrderProcessor::doStartPlayerTurn(PlayerColor which)
|
||||
assert(gameHandler->getCurrentPlayer() == *actingPlayers.begin());
|
||||
}
|
||||
|
||||
void TurnOrderProcessor::doEndPlayerTurn(PlayerColor which, PlayerTurnEndReason reason)
|
||||
void TurnOrderProcessor::doEndPlayerTurn(PlayerColor which)
|
||||
{
|
||||
assert(playerMakingTurn(which));
|
||||
|
||||
actingPlayers.erase(which);
|
||||
if (reason != PlayerTurnEndReason::GAME_END)
|
||||
actedPlayers.insert(which);
|
||||
|
||||
if (!awaitingPlayers.empty())
|
||||
@ -132,7 +131,24 @@ void TurnOrderProcessor::addPlayer(PlayerColor which)
|
||||
awaitingPlayers.insert(which);
|
||||
}
|
||||
|
||||
bool TurnOrderProcessor::onPlayerEndsTurn(PlayerColor which, PlayerTurnEndReason reason)
|
||||
void TurnOrderProcessor::onPlayerEndsGame(PlayerColor which)
|
||||
{
|
||||
awaitingPlayers.erase(which);
|
||||
actingPlayers.erase(which);
|
||||
actedPlayers.erase(which);
|
||||
|
||||
if (!awaitingPlayers.empty())
|
||||
tryStartTurnsForPlayers();
|
||||
|
||||
if (actingPlayers.empty())
|
||||
doStartNewDay();
|
||||
|
||||
assert(!actingPlayers.empty());
|
||||
assert(actingPlayers.size() == 1); // No simturns yet :(
|
||||
assert(gameHandler->getCurrentPlayer() == *actingPlayers.begin());
|
||||
}
|
||||
|
||||
bool TurnOrderProcessor::onPlayerEndsTurn(PlayerColor which)
|
||||
{
|
||||
if (!playerMakingTurn(which))
|
||||
{
|
||||
@ -152,10 +168,9 @@ bool TurnOrderProcessor::onPlayerEndsTurn(PlayerColor which, PlayerTurnEndReason
|
||||
return false;
|
||||
}
|
||||
|
||||
if (reason != PlayerTurnEndReason::GAME_END)
|
||||
gameHandler->onPlayerTurnEnded(which);
|
||||
|
||||
doEndPlayerTurn(which, reason);
|
||||
doEndPlayerTurn(which);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -13,13 +13,6 @@
|
||||
|
||||
class CGameHandler;
|
||||
|
||||
enum class PlayerTurnEndReason
|
||||
{
|
||||
CLIENT_REQUEST, // client requested end of turn (e.g. press End Turn button)
|
||||
TURN_TIMEOUT, // Player's turn timer has run out
|
||||
GAME_END // Player have won or lost the game
|
||||
};
|
||||
|
||||
class TurnOrderProcessor : boost::noncopyable
|
||||
{
|
||||
CGameHandler * gameHandler;
|
||||
@ -42,7 +35,7 @@ class TurnOrderProcessor : boost::noncopyable
|
||||
|
||||
void doStartNewDay();
|
||||
void doStartPlayerTurn(PlayerColor which);
|
||||
void doEndPlayerTurn(PlayerColor which, PlayerTurnEndReason reason);
|
||||
void doEndPlayerTurn(PlayerColor which);
|
||||
|
||||
public:
|
||||
TurnOrderProcessor(CGameHandler * owner);
|
||||
@ -51,7 +44,9 @@ public:
|
||||
void addPlayer(PlayerColor which);
|
||||
|
||||
/// NetPack call-in
|
||||
bool onPlayerEndsTurn(PlayerColor which, PlayerTurnEndReason reason);
|
||||
bool onPlayerEndsTurn(PlayerColor which);
|
||||
|
||||
void onPlayerEndsGame(PlayerColor which);
|
||||
|
||||
/// Start game (or resume from save) and send YourTurn pack to player(s)
|
||||
void onGameStarted();
|
||||
|
Loading…
Reference in New Issue
Block a user