summaryrefslogtreecommitdiff
path: root/src/berry.c
diff options
context:
space:
mode:
authorSierraffinity <sierra@domoreaweso.me>2020-05-04 20:54:27 -0700
committerSierraffinity <sierra@domoreaweso.me>2020-05-04 20:54:27 -0700
commita1244aa5dd4c7519ba6c2dcba5796eec2eba1c90 (patch)
tree76cd7fa5a9ed806e19221e8d9a11337355f074f5 /src/berry.c
parent072a98ca9aea8bfea7edc65f0a4a230974362b96 (diff)
parentb3b99b52ca978104ebed318f1d238fc97892836a (diff)
Merge branch 'master' of github.com:pret/pokeemerald
Diffstat (limited to 'src/berry.c')
-rw-r--r--src/berry.c16
1 files changed, 13 insertions, 3 deletions
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;
}
}