Fixup ModifyStatByNature

This commit is contained in:
PokeCodec 2020-09-05 11:47:24 -04:00
parent 16ecbc6446
commit a7a64ecba0
2 changed files with 19 additions and 22 deletions

View File

@ -181,9 +181,8 @@ u32 GetMewMoveDirection(void)
{ {
if (ShouldMewMoveEast(mew, 1)) if (ShouldMewMoveEast(mew, 1))
return GetRandomMewDirectionCandidate(2); return GetRandomMewDirectionCandidate(2);
else if (ShouldMewMoveWest(mew, 1)) if (ShouldMewMoveWest(mew, 1))
return GetRandomMewDirectionCandidate(2); return GetRandomMewDirectionCandidate(2);
else
return DIR_NORTH; return DIR_NORTH;
} }
@ -191,9 +190,8 @@ u32 GetMewMoveDirection(void)
{ {
if (ShouldMewMoveEast(mew, 1)) if (ShouldMewMoveEast(mew, 1))
return GetRandomMewDirectionCandidate(2); return GetRandomMewDirectionCandidate(2);
else if (ShouldMewMoveWest(mew, 1)) if (ShouldMewMoveWest(mew, 1))
return GetRandomMewDirectionCandidate(2); return GetRandomMewDirectionCandidate(2);
else
return DIR_SOUTH; return DIR_SOUTH;
} }
@ -201,9 +199,8 @@ u32 GetMewMoveDirection(void)
{ {
if (ShouldMewMoveNorth(mew, 1)) if (ShouldMewMoveNorth(mew, 1))
return GetRandomMewDirectionCandidate(2); return GetRandomMewDirectionCandidate(2);
else if (ShouldMewMoveSouth(mew, 1)) if (ShouldMewMoveSouth(mew, 1))
return GetRandomMewDirectionCandidate(2); return GetRandomMewDirectionCandidate(2);
else
return DIR_EAST; return DIR_EAST;
} }
@ -211,9 +208,8 @@ u32 GetMewMoveDirection(void)
{ {
if (ShouldMewMoveNorth(mew, 1)) if (ShouldMewMoveNorth(mew, 1))
return GetRandomMewDirectionCandidate(2); return GetRandomMewDirectionCandidate(2);
else if (ShouldMewMoveSouth(mew, 1)) if (ShouldMewMoveSouth(mew, 1))
return GetRandomMewDirectionCandidate(2); return GetRandomMewDirectionCandidate(2);
else
return DIR_WEST; return DIR_WEST;
} }
@ -315,7 +311,6 @@ static u8 GetValidMewMoveDirection(u8 ignoredDir)
if (count > 1) if (count > 1)
return sMewDirectionCandidates[VarGet(VAR_FARAWAY_ISLAND_STEP_COUNTER) % count]; return sMewDirectionCandidates[VarGet(VAR_FARAWAY_ISLAND_STEP_COUNTER) % count];
else
return sMewDirectionCandidates[0]; return sMewDirectionCandidates[0];
} }

View File

@ -5746,25 +5746,27 @@ u8 GetTrainerEncounterMusicId(u16 trainerOpponentId)
u16 ModifyStatByNature(u8 nature, u16 n, u8 statIndex) u16 ModifyStatByNature(u8 nature, u16 n, u8 statIndex)
{ {
u16 retVal;
// Dont modify HP, Accuracy, or Evasion by nature // Dont modify HP, Accuracy, or Evasion by nature
if (statIndex <= STAT_HP || statIndex > NUM_NATURE_STATS) if (statIndex <= STAT_HP || statIndex > NUM_NATURE_STATS)
{ {
// Should just be "return n", but it wouldn't match without this. return n;
u16 retVal = n;
retVal++;
retVal--;
return retVal;
} }
switch (gNatureStatTable[nature][statIndex - 1]) switch (gNatureStatTable[nature][statIndex - 1])
{ {
case 1: case 1:
return (u16)(n * 110) / 100; // NOTE: will overflow for n > 595 because the intermediate value is cast to u16 before the division. Fix by removing (u16) cast retVal = (u16)(n * 110) / 100; // NOTE: will overflow for n > 595 because the intermediate value is cast to u16 before the division. Fix by removing (u16) cast
break;
case -1: case -1:
return (u16)(n * 90) / 100; // NOTE: will overflow for n > 728, see above retVal = (u16)(n * 90) / 100; // NOTE: will overflow for n > 728, see above
break;
default:
retVal = n;
break;
} }
return n; return retVal;
} }
#define IS_LEAGUE_BATTLE \ #define IS_LEAGUE_BATTLE \