1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-05 00:49:09 +02:00

Fix handling of "7 days without town" loss condition

This commit is contained in:
Ivan Savenko
2023-08-24 21:35:01 +03:00
parent 66f555f1f7
commit f9410145d6
9 changed files with 70 additions and 39 deletions

View File

@ -108,6 +108,11 @@ void YourTurn::visitTyped(ICPackVisitor & visitor)
visitor.visitYourTurn(*this);
}
void DaysWithoutTown::visitTyped(ICPackVisitor & visitor)
{
visitor.visitYourTurn(*this);
}
void EntitiesChanged::visitTyped(ICPackVisitor & visitor)
{
visitor.visitEntitiesChanged(*this);
@ -2025,26 +2030,6 @@ void NewTurn::applyGs(CGameState *gs)
if(gs->getDate(Date::DAY_OF_WEEK) == 1)
gs->updateRumor();
//count days without town for all players, regardless of their turn order
for (auto &p : gs->players)
{
PlayerState & playerState = p.second;
if (playerState.status == EPlayerStatus::INGAME)
{
if (playerState.towns.empty())
{
if (playerState.daysWithoutCastle)
++(*playerState.daysWithoutCastle);
else
playerState.daysWithoutCastle = std::make_optional(0);
}
else
{
playerState.daysWithoutCastle = std::nullopt;
}
}
}
}
void SetObjectProperty::applyGs(CGameState * gs) const
@ -2063,8 +2048,16 @@ void SetObjectProperty::applyGs(CGameState * gs) const
{
auto * t = dynamic_cast<CGTownInstance *>(obj);
assert(t);
if(t->tempOwner < PlayerColor::PLAYER_LIMIT)
gs->getPlayerState(t->tempOwner)->towns -= t;
PlayerColor oldOwner = t->tempOwner;
if(oldOwner.isValidPlayer())
{
auto * state = gs->getPlayerState(oldOwner);
state->towns -= t;
if(state->towns.empty())
*state->daysWithoutCastle = 0;
}
if(val < PlayerColor::PLAYER_LIMIT_I)
{
PlayerState * p = gs->getPlayerState(PlayerColor(val));
@ -2509,7 +2502,10 @@ void PlayerCheated::applyGs(CGameState * gs) const
void YourTurn::applyGs(CGameState * gs) const
{
gs->currentPlayer = player;
}
void DaysWithoutTown::applyGs(CGameState * gs) const
{
auto & playerState = gs->players[player];
playerState.daysWithoutCastle = daysWithoutCastle;
}