diff options
author | Sierra A <6080951+Sierraffinity@users.noreply.github.com> | 2020-05-03 02:26:18 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-03 02:26:18 -0700 |
commit | 8778aec7d6c042bd9c87a227a30410fe5dad8211 (patch) | |
tree | 4c80573d01b41106f06932502ad7be96a814241e | |
parent | 5c49bc6d347f526c5f95ac91e30cef89d7918ad5 (diff) | |
parent | 84f012fc6e653df33158e494bab95e18557a2161 (diff) |
Merge pull request #1031 from hondew/berry-yield
Document minor berry yield bug
-rw-r--r-- | include/constants/berry.h | 7 | ||||
-rw-r--r-- | src/berry.c | 16 |
2 files changed, 20 insertions, 3 deletions
diff --git a/include/constants/berry.h b/include/constants/berry.h index d413b9947..8f1e7cd82 100644 --- a/include/constants/berry.h +++ b/include/constants/berry.h @@ -25,4 +25,11 @@ #define BERRY_STAGE_BERRIES 5 #define BERRY_STAGE_SPARKLING 255 +// Berries can be watered in the following stages: +// - BERRY_STAGE_PLANTED +// - BERRY_STAGE_SPROUTED +// - BERRY_STAGE_TALLER +// - BERRY_STAGE_FLOWERING +#define NUM_WATER_STAGES 4 + #endif // GUARD_CONSTANTS_BERRY_H diff --git a/src/berry.c b/src/berry.c index 7a8ab37fa..fe4a66af6 100644 --- a/src/berry.c +++ b/src/berry.c @@ -1200,6 +1200,15 @@ static u8 GetNumStagesWateredByBerryTreeId(u8 id) return BerryTreeGetNumStagesWatered(GetBerryTreeInfo(id)); } +// Berries can be watered at 4 stages of growth. This function is likely meant +// to divide the berry yield range equally into quartiles. If you watered the +// tree n times, your yield is a random number in the nth quartile. +// +// However, this function actually skews towards higher berry yields, because +// it rounds `extraYield` to the nearest whole number. +// +// See resulting yields: https://gist.github.com/hondew/2a099dbe54aa91414decdbfaa524327d, +// and bug fix: https://gist.github.com/hondew/0f0164e5b9dadfd72d24f30f2c049a0b. static u8 CalcBerryYieldInternal(u16 max, u16 min, u8 water) { u32 randMin; @@ -1215,10 +1224,11 @@ static u8 CalcBerryYieldInternal(u16 max, u16 min, u8 water) randMax = (max - min) * (water); rand = randMin + Random() % (randMax - randMin + 1); - if ((rand & 3) > 1) - extraYield = rand / 4 + 1; + // Round upwards + if ((rand % NUM_WATER_STAGES) >= NUM_WATER_STAGES / 2) + extraYield = rand / NUM_WATER_STAGES + 1; else - extraYield = rand / 4; + extraYield = rand / NUM_WATER_STAGES; return extraYield + min; } } |