summaryrefslogtreecommitdiff
path: root/src/pokemon.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/pokemon.c')
-rw-r--r--src/pokemon.c53
1 files changed, 28 insertions, 25 deletions
diff --git a/src/pokemon.c b/src/pokemon.c
index 72fb4984c..d4b785964 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
@@ -70,7 +69,7 @@ EWRAM_DATA u8 gEnemyPartyCount = 0;
EWRAM_DATA struct Pokemon gPlayerParty[PARTY_SIZE] = {0};
EWRAM_DATA struct Pokemon gEnemyParty[PARTY_SIZE] = {0};
EWRAM_DATA struct SpriteTemplate gMultiuseSpriteTemplate = {0};
-EWRAM_DATA struct Unknown_806F160_Struct *gUnknown_020249B4[2] = {NULL, NULL};
+EWRAM_DATA struct Unknown_806F160_Struct *gUnknown_020249B4[2] = {NULL};
// const rom data
#include "data/battle_moves.h"
@@ -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,6 +2860,8 @@ 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.
+ // To fix that set currentHP = 1 if currentHP <= 0.
currentHP += newMaxHP - oldMaxHP;
else
return;
@@ -4911,19 +4912,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))
@@ -5747,7 +5750,7 @@ u8 GetTrainerEncounterMusicId(u16 trainerOpponentId)
u16 ModifyStatByNature(u8 nature, u16 n, u8 statIndex)
{
u16 retVal;
- // Dont modify HP, Accuracy, or Evasion by nature
+ // Don't modify HP, Accuracy, or Evasion by nature
if (statIndex <= STAT_HP || statIndex > NUM_NATURE_STATS)
{
return n;
@@ -6808,8 +6811,6 @@ static bool8 ShouldSkipFriendshipChange(void)
return FALSE;
}
-#define MAGIC_NUMBER 0xA3
-
static void sub_806F160(struct Unknown_806F160_Struct* structPtr)
{
u16 i, j;
@@ -6858,7 +6859,7 @@ struct Unknown_806F160_Struct *sub_806F2AC(u8 id, u8 arg1)
structPtr->field_0_0 = 7;
structPtr->field_0_1 = 7;
structPtr->field_1 = 4;
- structPtr->size = 1;
+ structPtr->field_3_0 = 1;
structPtr->field_3_1 = 2;
break;
case 0:
@@ -6866,12 +6867,12 @@ struct Unknown_806F160_Struct *sub_806F2AC(u8 id, u8 arg1)
structPtr->field_0_0 = 4;
structPtr->field_0_1 = 4;
structPtr->field_1 = 4;
- structPtr->size = 1;
+ structPtr->field_3_0 = 1;
structPtr->field_3_1 = 0;
break;
}
- structPtr->bytes = AllocZeroed(structPtr->size * 0x800 * 4 * structPtr->field_0_0);
+ structPtr->bytes = AllocZeroed(structPtr->field_3_0 * 0x800 * 4 * structPtr->field_0_0);
structPtr->byteArrays = AllocZeroed(structPtr->field_0_0 * 32);
if (structPtr->bytes == NULL || structPtr->byteArrays == NULL)
{
@@ -6880,7 +6881,7 @@ struct Unknown_806F160_Struct *sub_806F2AC(u8 id, u8 arg1)
else
{
for (i = 0; i < structPtr->field_0_0; i++)
- structPtr->byteArrays[i] = structPtr->bytes + (structPtr->size * (i << 0xD));
+ structPtr->byteArrays[i] = structPtr->bytes + (structPtr->field_3_0 * (i << 0xD));
}
structPtr->templates = AllocZeroed(sizeof(struct SpriteTemplate) * structPtr->field_0_0);
@@ -6899,8 +6900,8 @@ struct Unknown_806F160_Struct *sub_806F2AC(u8 id, u8 arg1)
case 2:
sub_806F1FC(structPtr);
break;
- case 1:
case 0:
+ case 1:
default:
sub_806F160(structPtr);
break;
@@ -6929,7 +6930,7 @@ struct Unknown_806F160_Struct *sub_806F2AC(u8 id, u8 arg1)
}
else
{
- structPtr->magic = MAGIC_NUMBER;
+ structPtr->magic = 0xA3;
gUnknown_020249B4[id] = structPtr;
}
@@ -6940,12 +6941,12 @@ void sub_806F47C(u8 id)
{
struct Unknown_806F160_Struct *structPtr;
- id &= 1;
+ id %= 2;
structPtr = gUnknown_020249B4[id];
if (structPtr == NULL)
return;
- if (structPtr->magic != MAGIC_NUMBER)
+ if (structPtr->magic != 0xA3)
{
memset(structPtr, 0, sizeof(struct Unknown_806F160_Struct));
}
@@ -6969,13 +6970,15 @@ void sub_806F47C(u8 id)
u8 *sub_806F4F8(u8 id, u8 arg1)
{
struct Unknown_806F160_Struct *structPtr = gUnknown_020249B4[id % 2];
- if (structPtr->magic != MAGIC_NUMBER)
+ if (structPtr->magic != 0xA3)
{
return NULL;
}
-
- if (arg1 >= structPtr->field_0_0)
- arg1 = 0;
+ else
+ {
+ if (arg1 >= structPtr->field_0_0)
+ arg1 = 0;
- return structPtr->byteArrays[arg1];
+ return structPtr->byteArrays[arg1];
+ }
}