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

Fix checking PlayerColor's for validness

This commit is contained in:
Ivan Savenko
2023-08-27 01:35:38 +03:00
parent 3b06abd0d7
commit ce20d913e0
25 changed files with 55 additions and 49 deletions

View File

@@ -804,7 +804,7 @@ void CGameHandler::onNewTurn()
setPortalDwelling(t, true, (n.specialWeek == NewTurn::PLAGUE ? true : false)); //set creatures for Portal of Summoning
if (!firstTurn)
if (t->hasBuilt(BuildingSubID::TREASURY) && player < PlayerColor::PLAYER_LIMIT)
if (t->hasBuilt(BuildingSubID::TREASURY) && player.isValidPlayer())
n.res[player][EGameResID::GOLD] += hadGold.at(player)/10; //give 10% of starting gold
if (!vstd::contains(n.cres, t->id))
@@ -845,7 +845,7 @@ void CGameHandler::onNewTurn()
}
}
}
if (!firstTurn && player < PlayerColor::PLAYER_LIMIT)//not the first day and town not neutral
if (!firstTurn && player.isValidPlayer())//not the first day and town not neutral
{
n.res[player] = n.res[player] + t->dailyIncome();
}
@@ -1312,13 +1312,13 @@ void CGameHandler::setOwner(const CGObjectInstance * obj, const PlayerColor owne
const CGTownInstance * town = dynamic_cast<const CGTownInstance *>(obj);
if (town) //town captured
{
if (owner < PlayerColor::PLAYER_LIMIT) //new owner is real player
if (owner.isValidPlayer()) //new owner is real player
{
if (town->hasBuilt(BuildingSubID::PORTAL_OF_SUMMONING))
setPortalDwelling(town, true, false);
}
if (oldOwner < PlayerColor::PLAYER_LIMIT) //old owner is real player
if (oldOwner.isValidPlayer()) //old owner is real player
{
if (getPlayerState(oldOwner)->towns.empty() && getPlayerState(oldOwner)->status != EPlayerStatus::LOSER) //previous player lost last last town
{