1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-21 17:17:06 +02:00

Small refactoring

This commit is contained in:
Andrii Danylchenko 2022-10-23 16:30:40 +03:00
parent 591f9c096d
commit 2c3511e847

View File

@ -2217,28 +2217,28 @@ EVictoryLossCheckResult CGameState::checkForVictoryAndLoss(PlayerColor player) c
return this->checkForVictory(player, condition);
};
const PlayerState *p = CGameInfoCallback::getPlayerState(player);
const PlayerState * p = CGameInfoCallback::getPlayerState(player);
//cheater or tester, but has entered the code...
if (p->enteredWinningCheatCode)
if(p->enteredWinningCheatCode)
return EVictoryLossCheckResult::victory(messageWonSelf, messageWonOther);
if (p->enteredLosingCheatCode)
if(p->enteredLosingCheatCode)
return EVictoryLossCheckResult::defeat(messageLostSelf, messageLostOther);
for (const TriggeredEvent & event : map->triggeredEvents)
for(const TriggeredEvent & event : map->triggeredEvents)
{
if (event.trigger.test(evaluateEvent))
if(event.trigger.test(evaluateEvent))
{
if (event.effect.type == EventEffect::VICTORY)
if(event.effect.type == EventEffect::VICTORY)
return EVictoryLossCheckResult::victory(event.onFulfill, event.effect.toOtherMessage);
if (event.effect.type == EventEffect::DEFEAT)
if(event.effect.type == EventEffect::DEFEAT)
return EVictoryLossCheckResult::defeat(event.onFulfill, event.effect.toOtherMessage);
}
}
if (checkForStandardLoss(player))
if(checkForStandardLoss(player))
{
return EVictoryLossCheckResult::defeat(messageLostSelf, messageLostOther);
}
@ -2283,23 +2283,6 @@ bool CGameState::checkForVictory(PlayerColor player, const EventCondition & cond
{
return p->resources[condition.objectType] >= condition.value;
}
case EventCondition::HAVE_BUILDING:
{
if (condition.object) // specific town
{
const CGTownInstance *t = static_cast<const CGTownInstance *>(condition.object);
return (t->tempOwner == player && t->hasBuilt(BuildingID(condition.objectType)));
}
else // any town
{
for (const CGTownInstance * t : p->towns)
{
if (t->hasBuilt(BuildingID(condition.objectType)))
return true;
}
return false;
}
}
case EventCondition::DESTROY:
{
if (condition.object) // mode A - destroy specific object of this type
@ -2352,21 +2335,29 @@ bool CGameState::checkForVictory(PlayerColor player, const EventCondition & cond
return false;
case EventCondition::DAYS_PASSED:
return (si32)gs->day > condition.value;
case EventCondition::IS_HUMAN:
return p->human ? condition.value == 1 : condition.value == 0;
case EventCondition::DAYS_WITHOUT_TOWN:
if (p->daysWithoutCastle)
return p->daysWithoutCastle.get() >= condition.value;
else
return false;
case EventCondition::CONST_VALUE:
return condition.value; // just convert to bool
case EventCondition::HAVE_0:
return checkForHaveCondition(p, condition);
case EventCondition::HAVE_BUILDING:
case EventCondition::HAVE_BUILDING_0:
return checkForHaveBuildingCondition(p, condition);
case EventCondition::DESTROY_0:
return checkForDestroyCondition(p, condition);
default:
logGlobal->error("Invalid event condition type: %d", (int)condition.condition);
return false;