mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-26 03:52:01 +02:00
Don't give a turn to player who is about to lose (days without town).
This commit is contained in:
parent
abe88ea890
commit
716c324695
@ -167,10 +167,11 @@ struct YourTurn : public CPackForClient //100
|
||||
DLL_LINKAGE void applyGs(CGameState *gs);
|
||||
|
||||
PlayerColor player;
|
||||
ui8 daysWithoutCastle;
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & player;
|
||||
h & player & daysWithoutCastle;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1623,18 +1623,8 @@ DLL_LINKAGE void YourTurn::applyGs( CGameState *gs )
|
||||
{
|
||||
gs->currentPlayer = player;
|
||||
|
||||
//count days without town
|
||||
auto & playerState = gs->players[player];
|
||||
if(playerState.towns.empty())
|
||||
{
|
||||
if(playerState.daysWithoutCastle)
|
||||
++(*playerState.daysWithoutCastle);
|
||||
else playerState.daysWithoutCastle = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
playerState.daysWithoutCastle = boost::none;
|
||||
}
|
||||
playerState.daysWithoutCastle = daysWithoutCastle;
|
||||
}
|
||||
|
||||
DLL_LINKAGE Component::Component(const CStackBasicDescriptor &stack)
|
||||
|
@ -1583,19 +1583,42 @@ void CGameHandler::run(bool resume)
|
||||
}
|
||||
|
||||
resume = false;
|
||||
for(; it != playerTurnOrder.end(); it++)
|
||||
for (; it != playerTurnOrder.end(); it++)
|
||||
{
|
||||
auto playerColor = *it;
|
||||
if(gs->players[playerColor].status == EPlayerStatus::INGAME)
|
||||
|
||||
auto playerState = gs->players[playerColor];
|
||||
if (playerState.status == EPlayerStatus::INGAME)
|
||||
{
|
||||
states.setFlag(playerColor, &PlayerStatus::makingTurn, true);
|
||||
states.setFlag (playerColor, &PlayerStatus::makingTurn, true);
|
||||
|
||||
//count days without town
|
||||
if (playerState.towns.empty())
|
||||
{
|
||||
if (playerState.daysWithoutCastle)
|
||||
++(*playerState.daysWithoutCastle);
|
||||
else playerState.daysWithoutCastle = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
playerState.daysWithoutCastle = boost::none; //TODO: reset this immediatelly when player conquers any castle
|
||||
}
|
||||
|
||||
//if player runs out of time, he shouldn't get the turn (especially AI)
|
||||
checkVictoryLossConditionsForAll();
|
||||
|
||||
if (gs->players[playerColor].status != EPlayerStatus::INGAME)
|
||||
{ //player lost at the beginning of his turn
|
||||
continue;
|
||||
}
|
||||
|
||||
YourTurn yt;
|
||||
yt.player = playerColor;
|
||||
//Change local daysWithoutCastle counter for local interface message //TODO: needed?
|
||||
if (playerState.daysWithoutCastle)
|
||||
yt.daysWithoutCastle = playerState.daysWithoutCastle.get();
|
||||
applyAndSend(&yt);
|
||||
|
||||
checkVictoryLossConditionsForAll();
|
||||
|
||||
//wait till turn is done
|
||||
boost::unique_lock<boost::mutex> lock(states.mx);
|
||||
while(states.players.at(playerColor).makingTurn && !end2)
|
||||
|
Loading…
x
Reference in New Issue
Block a user