summaryrefslogtreecommitdiff
path: root/src/pokemon.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/pokemon.c')
-rw-r--r--src/pokemon.c84
1 files changed, 47 insertions, 37 deletions
diff --git a/src/pokemon.c b/src/pokemon.c
index 188624d6a..b5eee16b2 100644
--- a/src/pokemon.c
+++ b/src/pokemon.c
@@ -44,7 +44,6 @@
#include "constants/layouts.h"
#include "constants/moves.h"
#include "constants/songs.h"
-#include "constants/species.h"
#include "constants/trainers.h"
struct SpeciesItem
@@ -58,7 +57,7 @@ static u16 CalculateBoxMonChecksum(struct BoxPokemon *boxMon);
static union PokemonSubstruct *GetSubstruct(struct BoxPokemon *boxMon, u32 personality, u8 substructType);
static void EncryptBoxMon(struct BoxPokemon *boxMon);
static void DecryptBoxMon(struct BoxPokemon *boxMon);
-static void sub_806E6CC(u8 taskId);
+static void Task_PlayMapChosenOrBattleBGM(u8 taskId);
static bool8 ShouldGetStatBadgeBoost(u16 flagId, u8 battlerId);
static u16 GiveMoveToBoxMon(struct BoxPokemon *boxMon, u16 move);
static bool8 ShouldSkipFriendshipChange(void);
@@ -2579,7 +2578,7 @@ void CreateMonWithEVSpreadNatureOTID(struct Pokemon *mon, u16 species, u8 level,
CalculateMonStats(mon);
}
-void sub_80686FC(struct Pokemon *mon, struct BattleTowerPokemon *dest)
+void ConvertPokemonToBattleTowerPokemon(struct Pokemon *mon, struct BattleTowerPokemon *dest)
{
s32 i;
u16 heldItem;
@@ -2588,7 +2587,7 @@ void sub_80686FC(struct Pokemon *mon, struct BattleTowerPokemon *dest)
heldItem = GetMonData(mon, MON_DATA_HELD_ITEM, NULL);
if (heldItem == ITEM_ENIGMA_BERRY)
- heldItem = 0;
+ heldItem = ITEM_NONE;
dest->heldItem = heldItem;
@@ -2837,9 +2836,9 @@ void CalculateMonStats(struct Pokemon *mon)
newMaxHP = (((n + hpEV / 4) * level) / 100) + level + 10;
}
- gBattleScripting.field_23 = newMaxHP - oldMaxHP;
- if (gBattleScripting.field_23 == 0)
- gBattleScripting.field_23 = 1;
+ gBattleScripting.levelUpHP = newMaxHP - oldMaxHP;
+ if (gBattleScripting.levelUpHP == 0)
+ gBattleScripting.levelUpHP = 1;
SetMonData(mon, MON_DATA_MAX_HP, &newMaxHP);
@@ -2861,7 +2860,12 @@ void CalculateMonStats(struct Pokemon *mon)
if (currentHP == 0 && oldMaxHP == 0)
currentHP = newMaxHP;
else if (currentHP != 0)
+ // BUG: currentHP is unintentionally able to become <= 0 after the instruction below. This causes the pomeg berry glitch.
currentHP += newMaxHP - oldMaxHP;
+ #ifdef BUGFIX
+ if (currentHP <= 0)
+ currentHP = 1;
+ #endif
else
return;
}
@@ -4911,19 +4915,21 @@ bool8 PokemonUseItemEffects(struct Pokemon *mon, u16 item, u8 partyIndex, u8 mov
break;
}
}
+
+ // Get amount of HP to restore
dataUnsigned = itemEffect[var_3C++];
switch (dataUnsigned)
{
- case 0xFF:
+ case ITEM6_HEAL_FULL:
dataUnsigned = GetMonData(mon, MON_DATA_MAX_HP, NULL) - GetMonData(mon, MON_DATA_HP, NULL);
break;
- case 0xFE:
+ case ITEM6_HEAL_HALF:
dataUnsigned = GetMonData(mon, MON_DATA_MAX_HP, NULL) / 2;
if (dataUnsigned == 0)
dataUnsigned = 1;
break;
- case 0xFD:
- dataUnsigned = gBattleScripting.field_23;
+ case ITEM6_HEAL_LVL_UP:
+ dataUnsigned = gBattleScripting.levelUpHP;
break;
}
if (GetMonData(mon, MON_DATA_MAX_HP, NULL) != GetMonData(mon, MON_DATA_HP, NULL))
@@ -5591,8 +5597,8 @@ u16 SpeciesToCryId(u16 species)
void sub_806D544(u16 species, u32 personality, u8 *dest)
{
if (species == SPECIES_SPINDA
- && dest != gMonSpritesGfxPtr->sprites[0]
- && dest != gMonSpritesGfxPtr->sprites[2])
+ && dest != gMonSpritesGfxPtr->sprites.ptr[0]
+ && dest != gMonSpritesGfxPtr->sprites.ptr[2])
{
int i;
for (i = 0; i < 4; i++)
@@ -5746,25 +5752,29 @@ u8 GetTrainerEncounterMusicId(u16 trainerOpponentId)
u16 ModifyStatByNature(u8 nature, u16 n, u8 statIndex)
{
- // Dont modify HP, Accuracy, or Evasion by nature
+ u16 retVal;
+ // Don't modify HP, Accuracy, or Evasion by nature
if (statIndex <= STAT_HP || statIndex > NUM_NATURE_STATS)
{
- // Should just be "return n", but it wouldn't match without this.
- u16 retVal = n;
- retVal++;
- retVal--;
- return retVal;
+ return n;
}
switch (gNatureStatTable[nature][statIndex - 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 = n * 110;
+ retVal /= 100;
+ break;
case -1:
- return (u16)(n * 90) / 100; // NOTE: will overflow for n > 728, see above
+ retVal = n * 90;
+ retVal /= 100;
+ break;
+ default:
+ retVal = n;
+ break;
}
- return n;
+ return retVal;
}
#define IS_LEAGUE_BATTLE \
@@ -6324,26 +6334,31 @@ void PlayMapChosenOrBattleBGM(u16 songId)
PlayNewMapMusic(GetBattleBGM());
}
-void sub_806E694(u16 songId)
+// Identical to PlayMapChosenOrBattleBGM, but uses a task instead
+// Only used by Battle Dome
+#define tSongId data[0]
+void CreateTask_PlayMapChosenOrBattleBGM(u16 songId)
{
u8 taskId;
ResetMapMusic();
m4aMPlayAllStop();
- taskId = CreateTask(sub_806E6CC, 0);
- gTasks[taskId].data[0] = songId;
+ taskId = CreateTask(Task_PlayMapChosenOrBattleBGM, 0);
+ gTasks[taskId].tSongId = songId;
}
-static void sub_806E6CC(u8 taskId)
+static void Task_PlayMapChosenOrBattleBGM(u8 taskId)
{
- if (gTasks[taskId].data[0])
- PlayNewMapMusic(gTasks[taskId].data[0]);
+ if (gTasks[taskId].tSongId)
+ PlayNewMapMusic(gTasks[taskId].tSongId);
else
PlayNewMapMusic(GetBattleBGM());
DestroyTask(taskId);
}
+#undef tSongId
+
const u32 *GetMonFrontSpritePal(struct Pokemon *mon)
{
u16 species = GetMonData(mon, MON_DATA_SPECIES2, 0);
@@ -6804,19 +6819,14 @@ static bool8 ShouldSkipFriendshipChange(void)
return FALSE;
}
-#define FORCE_SIGNED(x)(-(x * (-1)))
-
static void sub_806F160(struct Unknown_806F160_Struct* structPtr)
{
u16 i, j;
- for (i = 0; i < FORCE_SIGNED(structPtr->field_0_0); i++)
+ for (i = 0; i < structPtr->field_0_0; i++)
{
structPtr->templates[i] = gUnknown_08329D98[i];
for (j = 0; j < structPtr->field_1; j++)
{
- #ifndef NONMATCHING
- asm("");
- #endif
structPtr->frameImages[i * structPtr->field_1 + j].data = &structPtr->byteArrays[i][j * 0x800];
}
structPtr->templates[i].images = &structPtr->frameImages[i * structPtr->field_1];
@@ -6826,7 +6836,7 @@ static void sub_806F160(struct Unknown_806F160_Struct* structPtr)
static void sub_806F1FC(struct Unknown_806F160_Struct* structPtr)
{
u16 i, j;
- for (i = 0; i < FORCE_SIGNED(structPtr->field_0_0); i++)
+ for (i = 0; i < structPtr->field_0_0; i++)
{
structPtr->templates[i] = gUnknown_08329F28;
for (j = 0; j < structPtr->field_1; j++)
@@ -6878,7 +6888,7 @@ struct Unknown_806F160_Struct *sub_806F2AC(u8 id, u8 arg1)
}
else
{
- for (i = 0; i < FORCE_SIGNED(structPtr->field_0_0); i++)
+ for (i = 0; i < structPtr->field_0_0; i++)
structPtr->byteArrays[i] = structPtr->bytes + (structPtr->field_3_0 * (i << 0xD));
}
@@ -6974,7 +6984,7 @@ u8 *sub_806F4F8(u8 id, u8 arg1)
}
else
{
- if (arg1 >= FORCE_SIGNED(structPtr->field_0_0))
+ if (arg1 >= structPtr->field_0_0)
arg1 = 0;
return structPtr->byteArrays[arg1];