1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-25 22:42:04 +02:00

Don't give a turn to player who is about to lose (days without town).

This commit is contained in:
DjWarmonger
2015-10-24 16:21:30 +02:00
parent abe88ea890
commit 716c324695
3 changed files with 31 additions and 17 deletions

View File

@@ -167,10 +167,11 @@ struct YourTurn : public CPackForClient //100
DLL_LINKAGE void applyGs(CGameState *gs); DLL_LINKAGE void applyGs(CGameState *gs);
PlayerColor player; PlayerColor player;
ui8 daysWithoutCastle;
template <typename Handler> void serialize(Handler &h, const int version) template <typename Handler> void serialize(Handler &h, const int version)
{ {
h & player; h & player & daysWithoutCastle;
} }
}; };

View File

@@ -1623,18 +1623,8 @@ DLL_LINKAGE void YourTurn::applyGs( CGameState *gs )
{ {
gs->currentPlayer = player; gs->currentPlayer = player;
//count days without town
auto & playerState = gs->players[player]; auto & playerState = gs->players[player];
if(playerState.towns.empty()) playerState.daysWithoutCastle = daysWithoutCastle;
{
if(playerState.daysWithoutCastle)
++(*playerState.daysWithoutCastle);
else playerState.daysWithoutCastle = 0;
}
else
{
playerState.daysWithoutCastle = boost::none;
}
} }
DLL_LINKAGE Component::Component(const CStackBasicDescriptor &stack) DLL_LINKAGE Component::Component(const CStackBasicDescriptor &stack)

View File

@@ -1586,16 +1586,39 @@ void CGameHandler::run(bool resume)
for (; it != playerTurnOrder.end(); it++) for (; it != playerTurnOrder.end(); it++)
{ {
auto playerColor = *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; YourTurn yt;
yt.player = playerColor; yt.player = playerColor;
//Change local daysWithoutCastle counter for local interface message //TODO: needed?
if (playerState.daysWithoutCastle)
yt.daysWithoutCastle = playerState.daysWithoutCastle.get();
applyAndSend(&yt); applyAndSend(&yt);
checkVictoryLossConditionsForAll();
//wait till turn is done //wait till turn is done
boost::unique_lock<boost::mutex> lock(states.mx); boost::unique_lock<boost::mutex> lock(states.mx);
while(states.players.at(playerColor).makingTurn && !end2) while(states.players.at(playerColor).makingTurn && !end2)