mirror of
https://github.com/vcmi/vcmi.git
synced 2025-06-15 00:05:02 +02:00
Add helper functions for integer division rounding
Added set of functions that perform integer division with different rounding modes: - divideAndCeil - rounds up to next integer - divideAndRound - rounds to nearest integer - divideAndFloor - rounds to previous integer (equivalent to default division) Intended for use in library, where usage of floating point might lead to desync in multiplayer games. Replaced some cases that I knew of, including recent handicap PR
This commit is contained in:
@ -200,7 +200,7 @@ ui32 CGMine::getProducedQuantity() const
|
||||
{
|
||||
auto * playerSettings = cb->getPlayerSettings(getOwner());
|
||||
// always round up income - we don't want mines to always produce zero if handicap in use
|
||||
return (producedQuantity * playerSettings->handicap.percentIncome + 99) / 100;
|
||||
return vstd::divideAndCeil(producedQuantity * playerSettings->handicap.percentIncome, 100);
|
||||
}
|
||||
|
||||
void CGMine::battleFinished(const CGHeroInstance *hero, const BattleResult &result) const
|
||||
|
Reference in New Issue
Block a user