summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGriffinR <griffin.g.richards@gmail.com>2021-10-28 18:13:05 -0400
committerGitHub <noreply@github.com>2021-10-28 18:13:05 -0400
commitc793949f466d4b1ccc47396fbc99a92106aa9a8d (patch)
treebf6d51c32d55461d478d7177f52cd3d62ab0d118
parent1a5fa347903b114791fc96b6633e4eb8158fd720 (diff)
parent7f49f2633113175b78978bffe01000dcf1e858a8 (diff)
Merge pull request #1531 from GriffinRichards/fix-statoverflow
Restore ModifyStatByNature bug notes
-rw-r--r--src/pokemon.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/src/pokemon.c b/src/pokemon.c
index 6e3d37ae3..0f943734b 100644
--- a/src/pokemon.c
+++ b/src/pokemon.c
@@ -5775,27 +5775,36 @@ u8 GetTrainerEncounterMusicId(u16 trainerOpponentId)
return TRAINER_ENCOUNTER_MUSIC(trainerOpponentId);
}
-u16 ModifyStatByNature(u8 nature, u16 n, u8 statIndex)
-{
+u16 ModifyStatByNature(u8 nature, u16 stat, u8 statIndex)
+{
+// Because this is a u16 it will be unable to store the
+// result of the multiplication for any stat > 595 for a
+// positive nature and > 728 for a negative nature.
+// Neither occur in the base game, but this can happen if
+// any Nature-affected base stat is increased to a value
+// above 248. The closest by default is Shuckle at 230.
+#ifdef BUGFIX
+ u32 retVal;
+#else
u16 retVal;
+#endif
+
// Don't modify HP, Accuracy, or Evasion by nature
if (statIndex <= STAT_HP || statIndex > NUM_NATURE_STATS)
- {
- return n;
- }
+ return stat;
switch (gNatureStatTable[nature][statIndex - 1])
{
case 1:
- retVal = n * 110;
+ retVal = stat * 110;
retVal /= 100;
break;
case -1:
- retVal = n * 90;
+ retVal = stat * 90;
retVal /= 100;
break;
default:
- retVal = n;
+ retVal = stat;
break;
}