1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-02-03 13:01:33 +02:00

Limit resources to 1000 000 000 to prevent overflow

This commit is contained in:
Ivan Savenko 2023-11-20 20:50:37 +02:00
parent 842d66afbc
commit a4d5c4917b
2 changed files with 3 additions and 0 deletions

View File

@ -50,6 +50,7 @@ namespace GameConstants
constexpr int CREATURES_COUNT = 197;
constexpr ui32 BASE_MOVEMENT_COST = 100; //default cost for non-diagonal movement
constexpr int64_t PLAYER_RESOURCES_CAP = 1000 * 1000 * 1000;
}
VCMI_LIB_NAMESPACE_END

View File

@ -797,6 +797,7 @@ void SetResources::applyGs(CGameState * gs) const
gs->getPlayerState(player)->resources = res;
else
gs->getPlayerState(player)->resources += res;
gs->getPlayerState(player)->resources.amin(GameConstants::PLAYER_RESOURCES_CAP);
//just ensure that player resources are not negative
//server is responsible to check if player can afford deal
@ -2022,6 +2023,7 @@ void NewTurn::applyGs(CGameState *gs)
{
assert(re.first.isValidPlayer());
gs->getPlayerState(re.first)->resources = re.second;
gs->getPlayerState(re.first)->resources.amin(GameConstants::PLAYER_RESOURCES_CAP);
}
for(const auto & creatureSet : cres) //set available creatures in towns