From ef4245572c832bd727d0965fcfbaa6b267d1e704 Mon Sep 17 00:00:00 2001 From: Matt Date: Sun, 22 Dec 2019 23:15:44 +0100 Subject: [PATCH] Use integer math for guest initial happiness calculation --- src/openrct2/world/Park.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/openrct2/world/Park.cpp b/src/openrct2/world/Park.cpp index 855171e30a..42e22b7c92 100644 --- a/src/openrct2/world/Park.cpp +++ b/src/openrct2/world/Park.cpp @@ -657,7 +657,10 @@ uint8_t Park::CalculateGuestInitialHappiness(uint8_t percentage) // This sequence can be defined as PI*(9+n)/2 (the value is floored) for (uint8_t n = 1; n < 55; n++) { - if ((3.14159 * (9 + n)) / 2 >= percentage) + // Avoid floating point math by rescaling PI up. + constexpr int32_t SCALE = 100000; + constexpr int32_t PI_SCALED = 314159; // PI * SCALE; + if (((PI_SCALED * (9 + n)) / SCALE) / 2 >= percentage) { return (9 + n) * 4; }