Skip to content

Commit

Permalink
Tidy up some newlines and replace int with u32/s32 in pokemon.c
Browse files Browse the repository at this point in the history
  • Loading branch information
citrusbolt committed Feb 21, 2024
1 parent 17cff72 commit 6f21623
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions payload/src/pokemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ static u16 CalculateBoxMonChecksum(struct BoxPokemon *boxMon)
static inline void EncryptBoxMon(struct BoxPokemon *boxMon)
{
u32 i;

for (i = 0; i < NELEMS(boxMon->secure.raw); i++)
{
boxMon->secure.raw[i] ^= boxMon->personality;
Expand All @@ -130,6 +131,7 @@ static inline void EncryptBoxMon(struct BoxPokemon *boxMon)
static inline void DecryptBoxMon(struct BoxPokemon *boxMon)
{
u32 i;

for (i = 0; i < NELEMS(boxMon->secure.raw); i++)
{
boxMon->secure.raw[i] ^= boxMon->otId;
Expand Down Expand Up @@ -174,6 +176,7 @@ u32 GetBoxMonData(struct BoxPokemon *boxMon, s32 field, u8 *data)
{
u32 language;
u8 text[16];

if (boxMon->isBadEgg)
{
StringCopy(data, gText_BadEgg);
Expand Down Expand Up @@ -429,6 +432,7 @@ u32 GetBoxMonData(struct BoxPokemon *boxMon, s32 field, u8 *data)
break;
case MON_DATA_RIBBON_COUNT:
retVal = 0;

if (substruct0->species && !substruct3->isEgg)
{
retVal += substruct3->coolRibbon;
Expand All @@ -452,6 +456,7 @@ u32 GetBoxMonData(struct BoxPokemon *boxMon, s32 field, u8 *data)
break;
case MON_DATA_RIBBONS:
retVal = 0;

if (substruct0->species && !substruct3->isEgg)
{
retVal = substruct3->championRibbon
Expand Down Expand Up @@ -521,7 +526,6 @@ static inline u32 GetMonDataInline(struct Pokemon *mon, s32 attr, u8 *strbuf)
const struct CompressedSpritePalette *GetBoxMonPalettePtr(u32 partyId)
{
u32 shinyValue = 0;

u16 species = GetMonDataInline(&gPlayerPartyPtr[partyId], MON_DATA_SPECIES_OR_EGG, NULL);
u32 otId = GetMonDataInline(&gPlayerPartyPtr[partyId], MON_DATA_OT_ID, NULL);
u32 personality = GetMonDataInline(&gPlayerPartyPtr[partyId], MON_DATA_PERSONALITY, NULL);
Expand All @@ -530,6 +534,7 @@ const struct CompressedSpritePalette *GetBoxMonPalettePtr(u32 partyId)
return &gAgbPmRomParams->monPaletteTable[SPECIES_NONE];

shinyValue = HIHALF(otId) ^ LOHALF(otId) ^ HIHALF(personality) ^ LOHALF(personality);

if (shinyValue > 7)
return &gAgbPmRomParams->monPaletteTable[species];
else
Expand Down Expand Up @@ -564,7 +569,7 @@ const u32 *BoxMonGetCaughtBallItemSpriteSheet(struct BoxPokemon *boxMon)
case ITEM_POKE_BALL: id = BALL_POKE; break;
case ITEM_SAFARI_BALL: id = BALL_SAFARI; break;
case ITEM_NET_BALL: id = BALL_NET; break;
case ITEM_DIVE_BALL: id = BALL_DIVE; break;
case ITEM_DIVE_BALL: id = BALL_DIVE; break;
case ITEM_NEST_BALL: id = BALL_NEST; break;
case ITEM_REPEAT_BALL: id = BALL_REPEAT; break;
case ITEM_TIMER_BALL: id = BALL_TIMER; break;
Expand All @@ -589,7 +594,7 @@ const u32 *BoxMonGetCaughtBallItemPalette(struct BoxPokemon *boxMon)
case ITEM_POKE_BALL: id = BALL_POKE; break;
case ITEM_SAFARI_BALL: id = BALL_SAFARI; break;
case ITEM_NET_BALL: id = BALL_NET; break;
case ITEM_DIVE_BALL: id = BALL_DIVE; break;
case ITEM_DIVE_BALL: id = BALL_DIVE; break;
case ITEM_NEST_BALL: id = BALL_NEST; break;
case ITEM_REPEAT_BALL: id = BALL_REPEAT; break;
case ITEM_TIMER_BALL: id = BALL_TIMER; break;
Expand All @@ -604,6 +609,7 @@ const u32 *BoxMonGetCaughtBallItemPalette(struct BoxPokemon *boxMon)
u32 GetBoxMonMoveBySlot(struct BoxPokemon *boxMon, s32 slot)
{
u32 move;

switch (slot)
{
case 0: move = GetBoxMonData(boxMon, MON_DATA_MOVE1, NULL); break;
Expand All @@ -618,6 +624,7 @@ u32 GetBoxMonMoveBySlot(struct BoxPokemon *boxMon, s32 slot)
u32 GetBoxMonPPByMoveSlot(struct BoxPokemon *boxMon, u8 slot)
{
u32 pp;

switch (slot)
{
case 0: pp = GetBoxMonData(boxMon, MON_DATA_PP1, NULL); break;
Expand All @@ -632,9 +639,9 @@ u32 GetBoxMonPPByMoveSlot(struct BoxPokemon *boxMon, u8 slot)
u32 CheckPartyPokerus(struct Pokemon *party, u8 selection)
{
u32 retVal;
u32 partyIndex = 0;
u32 curBit = 1;

int partyIndex = 0;
unsigned curBit = 1;
retVal = 0;

if (selection)
Expand Down Expand Up @@ -681,6 +688,7 @@ u32 GetMonStatus(struct Pokemon *mon)
return STATUS_PRIMARY_FAINTED;

statusAilment = GetPrimaryStatus(GetMonDataInline(mon, MON_DATA_STATUS, NULL));

if (statusAilment == STATUS_PRIMARY_NONE)
{
if (!CheckPartyPokerus(mon, 0))
Expand All @@ -695,9 +703,9 @@ u32 GetMonStatus(struct Pokemon *mon)
u32 CheckPartyHasHadPokerus(struct Pokemon *party, u8 selection)
{
u32 retVal;
u32 partyIndex = 0;
u32 curBit = 1;

int partyIndex = 0;
unsigned curBit = 1;
retVal = 0;

if (selection)
Expand All @@ -724,7 +732,8 @@ void DrawSpindasSpots(u16 species, u32 personality, u8 *dest)
{
if (species == SPECIES_SPINDA)
{
int i, j, k, var;
s32 i, j, k;
u32 var;

if (gRomDetection_IsRubySapphire != FALSE)
var = 0;
Expand Down Expand Up @@ -776,7 +785,6 @@ void DrawSpindasSpots(u16 species, u32 personality, u8 *dest)
void SetBoxMonData(struct BoxPokemon *boxMon, s32 field, const void *dataArg)
{
const u8 *data = dataArg;

struct PokemonSubstruct0 *substruct0 = NULL;
struct PokemonSubstruct1 *substruct1 = NULL;
struct PokemonSubstruct2 *substruct2 = NULL;
Expand Down Expand Up @@ -812,6 +820,7 @@ void SetBoxMonData(struct BoxPokemon *boxMon, s32 field, const void *dataArg)
case MON_DATA_NICKNAME:
{
s32 i;

for (i = 0; i < gAgbPmRomParams->pokemonNameLength_1; i++)
boxMon->nickname[i] = data[i];
break;
Expand All @@ -831,6 +840,7 @@ void SetBoxMonData(struct BoxPokemon *boxMon, s32 field, const void *dataArg)
case MON_DATA_OT_NAME:
{
s32 i;

for (i = 0; i < gAgbPmRomParams->playerNameLength; i++)
boxMon->otName[i] = data[i];
break;
Expand Down Expand Up @@ -926,6 +936,7 @@ void SetBoxMonData(struct BoxPokemon *boxMon, s32 field, const void *dataArg)
case MON_DATA_MET_LEVEL:
{
u8 metLevel = *data;

substruct3->metLevel = metLevel;
break;
}
Expand All @@ -935,6 +946,7 @@ void SetBoxMonData(struct BoxPokemon *boxMon, s32 field, const void *dataArg)
case MON_DATA_POKEBALL:
{
u8 pokeball = *data;

substruct3->pokeball = pokeball;
break;
}
Expand All @@ -961,6 +973,7 @@ void SetBoxMonData(struct BoxPokemon *boxMon, s32 field, const void *dataArg)
break;
case MON_DATA_IS_EGG:
SET8(substruct3->isEgg);

if (substruct3->isEgg)
boxMon->isEgg = 1;
else
Expand Down Expand Up @@ -1030,6 +1043,7 @@ void SetBoxMonData(struct BoxPokemon *boxMon, s32 field, const void *dataArg)
#else
u32 ivs = *data; // Bug: Only the HP IV and the lower 3 bits of the Attack IV are read. The rest become 0.
#endif

substruct3->hpIV = ivs & 0x1F;
substruct3->attackIV = (ivs >> 5) & 0x1F;
substruct3->defenseIV = (ivs >> 10) & 0x1F;
Expand All @@ -1052,6 +1066,7 @@ void SetBoxMonData(struct BoxPokemon *boxMon, s32 field, const void *dataArg)
void SetMonData(struct Pokemon *mon, s32 field, const void *dataArg)
{
const u8 *data = dataArg;

switch (field)
{
case MON_DATA_STATUS:
Expand Down Expand Up @@ -1117,6 +1132,7 @@ void GiveGiftRibbonToParty(s32 index_, s32 ribbonId_)
if (index < 11 && ribbonId < 65 && index < 7)
{
gGiftRibbonsPtr[index] = ribbonId;

for (i = 0; i < PARTY_SIZE; i++)
{
if (GetMonDataInline(&gPlayerPartyPtr[i], MON_DATA_SPECIES, NULL) != 0 && GetMonDataInline(&gPlayerPartyPtr[i], MON_DATA_SANITY_IS_EGG, NULL) == 0)
Expand Down Expand Up @@ -1153,6 +1169,7 @@ u8 GetMonGender(struct Pokemon *mon)
const struct SpeciesInfo *speciesInfo = gAgbPmRomParams->baseStats;
u16 species = GetMonDataInline(mon, MON_DATA_SPECIES, NULL);
u32 personality = GetMonDataInline(mon, MON_DATA_PERSONALITY, NULL);

return GetGenderFromSpeciesAndPersonality(species, personality, speciesInfo);
}

Expand All @@ -1164,6 +1181,7 @@ const struct CompressedSpritePalette *GetMonPalettePtrBySpeciesIdPersonality(u16
return &gAgbPmRomParams->monPaletteTable[SPECIES_NONE];

shinyValue = HIHALF(otId) ^ LOHALF(otId) ^ HIHALF(personality) ^ LOHALF(personality);

if (shinyValue <= 7)
return &gAgbPmRomParams->monShinyPaletteTable[species];
else
Expand Down Expand Up @@ -1242,19 +1260,22 @@ u32 GetMonSpritePaletteNumByBaseBlock(u32 id)
const u8 *GetAbilityName(u32 ability)
{
const u8 (*abilityNames)[][ABILITY_NAME_LENGTH + 1] = gAgbPmRomParams->abilityNames;

return (*abilityNames)[ability];
}

const u8 *GetAbilityDescription(u32 ability)
{
const u8 **desriptions = gAgbPmRomParams->abilityDescriptions;

return desriptions[ability];
}

s32 CalculatePPWithBonus(u32 move, s32 ppBonuses, u32 moveIndex)
{
const struct BattleMove *moves = gAgbPmRomParams->battleMoves;
s32 basePP = moves[move].pp;

return basePP + ((basePP * 20 * ((gPPUpReadMasks[moveIndex] & ppBonuses) >> (2 * moveIndex))) / 100);
}

Expand Down

0 comments on commit 6f21623

Please sign in to comment.