From fc5b67699bc29cd349fb09085f7c46389e896836 Mon Sep 17 00:00:00 2001 From: wildfire Date: Sun, 10 Sep 2023 15:33:03 +0100 Subject: [PATCH] Misc. renames and cleanup, move data block structs --- include/pokemon.h | 40 +++++-- include/struct_defs/box_pokemon.h | 93 ++++++++++++++- include/struct_defs/pokemon_data_block_a.h | 31 ----- include/struct_defs/pokemon_data_block_b.h | 29 ----- include/struct_defs/pokemon_data_block_c.h | 14 --- include/struct_defs/pokemon_data_block_d.h | 25 ---- src/overlay016/ov16_0225177C.c | 40 +++---- src/pokemon.c | 128 +++++++++++---------- src/unk_0206CCB0.c | 2 +- src/unk_0208C324.c | 2 +- src/unk_02092494.c | 2 +- 11 files changed, 209 insertions(+), 197 deletions(-) delete mode 100644 include/struct_defs/pokemon_data_block_a.h delete mode 100644 include/struct_defs/pokemon_data_block_b.h delete mode 100644 include/struct_defs/pokemon_data_block_c.h delete mode 100644 include/struct_defs/pokemon_data_block_d.h diff --git a/include/pokemon.h b/include/pokemon.h index 454f78aefd..3d0e365a21 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -85,10 +85,6 @@ BOOL DecryptBoxMon(BoxPokemon *boxMon); BOOL EncryptBoxMon(BoxPokemon *boxMon, BOOL encrypt); void sub_02073D80(Pokemon *mon, int monSpecies, int monLevel, int monIVs, BOOL useMonPersonalityParam, u32 monPersonality, int monOTIDSource, u32 monOTID); - -// TODO make this static? -void sub_02073E18(BoxPokemon *boxMon, int monSpecies, int monLevel, int monIVs, BOOL useMonPersonalityParam, u32 monPersonality, int monOTIDSource, u32 monOTID); - void sub_02074044(Pokemon *mon, u16 monSpecies, u8 monLevel, u8 monIVs, u8 monNature); void sub_02074088(Pokemon *mon, u16 monSpecies, u8 monLevel, u8 monIVs, u8 param4, u8 param5, u8 param6); u32 sub_02074128(u16 monSpecies, u8 param1, u8 param2); @@ -385,7 +381,7 @@ u8 GetMonPersonalityShininess(u32 monOTID, u32 monPersonality); u32 sub_02075E64(u32 param0); void sub_02075EF4(UnkStruct_02008A90 *param0, Pokemon *mon, u8 param2); void sub_02075F00(UnkStruct_02008A90 *param0, Pokemon *mon, u8 param2); -void sub_02075F0C(UnkStruct_02008A90 *param0, BoxPokemon *boxMon, u8 param2, int param3); +void sub_02075F0C(UnkStruct_02008A90 *param0, BoxPokemon *boxMon, u8 param2, BOOL param3); void sub_02075FB4(UnkStruct_02008A90 *param0, u16 monSpecies, u8 monGender, u8 param3, u8 monShininess, u8 monForm, u32 monPersonality); /** @@ -399,7 +395,7 @@ u8 SanitizeFormId(u16 monSpecies, u8 monForm); u8 sub_020765AC(Pokemon *mon, u8 param1); u8 sub_020765B8(Pokemon *mon, u8 param1); -u8 sub_020765C4(BoxPokemon *boxMon, u8 param1, int param2); +u8 sub_020765C4(BoxPokemon *boxMon, u8 param1, BOOL param2); u8 sub_02076648(u16 monSpecies, u8 monGender, u8 param2, u8 monForm, u32 monPersonality); void sub_0207697C(UnkStruct_02008A90 *param0, u16 param1); UnkStruct_0200D0F4 *sub_02076994(UnkStruct_0200C6E4 *param0, UnkStruct_0200C704 *param1, UnkStruct_02002F38 *param2, int param3, int param4, int param5, int param6, int param7, int heapID); @@ -443,7 +439,7 @@ u8 GetBoxMonForm(BoxPokemon *boxMon); */ BoxPokemon *GetBoxMon(Pokemon *mon); -u8 sub_02076B14(Pokemon *mon); +BOOL sub_02076B14(Pokemon *mon); u16 sub_02076B94(Party *party, Pokemon *mon, u8 evoTypeList, u16 evoParam, int *evoTypeResult); u16 sub_02076F84(const u16 monSpecies); u16 sub_02076FD4(const u16 monSpecies); @@ -568,9 +564,33 @@ u16 sub_020775C4(u16 param0); void sub_020775EC(Pokemon *src, Pokemon *dest); void sub_02077604(BoxPokemon *src, BoxPokemon *dest); void sub_02077618(Pokemon *src, BoxPokemon *dest); -s8 sub_0207762C(Pokemon *mon, int param1); -s8 sub_02077634(BoxPokemon *boxMon, int param1); -s8 sub_02077648(u32 monPersonality, int param1); + +/** + * @brief Gets the affinitiy of a given Pokemon to a given flavor + * + * @param mon + * @param flavor + * @return 1 if liked flavor, -1 if disliked flavor, else 0 + */ +s8 GetMonFlavorAffinity(Pokemon *mon, int flavor); + +/** + * @brief Gets the affinitiy of a given BoxPokemon to a given flavor + * + * @param boxMon + * @param flavor + * @return 1 if liked flavor, -1 if disliked flavor, else 0 + */ +s8 GetBoxMonFlavorAffinity(BoxPokemon *boxMon, int flavor); + +/** + * @brief Gets the affinitiy of a given Pokemon personality to a given flavor + * + * @param monPersonality + * @param flavor + * @return 1 if liked flavor, -1 if disliked flavor, else 0 + */ +s8 GetMonPersonalityFlavorAffinity(u32 monPersonality, int flavor); /** * @brief Gets all moves that the given pokemon species and form can learn by leveling up diff --git a/include/struct_defs/box_pokemon.h b/include/struct_defs/box_pokemon.h index 2bd1f1b301..de2693ea86 100644 --- a/include/struct_defs/box_pokemon.h +++ b/include/struct_defs/box_pokemon.h @@ -1,10 +1,95 @@ #ifndef POKEPLATINUM_BOX_POKEMON_H #define POKEPLATINUM_BOX_POKEMON_H -#include "struct_defs/pokemon_data_block_b.h" -#include "struct_defs/pokemon_data_block_c.h" -#include "struct_defs/pokemon_data_block_d.h" -#include "struct_defs/pokemon_data_block_a.h" +/** + * @brief Block A of the BoxPokemon data structure + */ +typedef struct PokemonDataBlockA { + u16 species; //!< The pokemons species + u16 heldItem; //!< The pokemons currently held item + u32 otID; //!< The pokemons Original Trainer ID + u32 exp; //!< The pokemons experience points + u8 friendship; //!< The pokemons friendship stat + u8 ability; //!< The pokemons ability + u8 unk_0E; + u8 originLanguage; //!< The language of the game this pokemon was caught in + u8 hpEV; //!< The pokemons HP EVs + u8 atkEV; //!< The pokemons Attack EVs + u8 defEV; //!< The pokemons Defense EVs + u8 speedEV; //!< The pokemons Speed EVs + u8 spAtkEV; //!< The pokemons Special Attack EVs + u8 spDefEV; //!< The pokemons Special Defense EVs + u8 cool; //!< The pokemons Cool contest stat + u8 beauty; //!< The pokemons Beauty contest stat + u8 cute; //!< The pokemons Cute contest stat + u8 smart; //!< The pokemons Smart contest stat + u8 tough; //!< The pokemons Tough contest stat + u8 sheen; //!< The pokemons Sheen + u32 unk_1C; +} PokemonDataBlockA; + +/** + * @brief Block B of the BoxPokemon data structure + */ +typedef struct PokemonDataBlockB { + u16 moves[4]; //!< The ID of each move the pokemon knows + u8 moveCurrentPPs[4]; //!< The current PP of each move + u8 movePPUps[4]; //!< The number of PP Ups used on each move + u32 hpIV : 5; //!< The pokemons HP IVs + u32 atkIV : 5; //!< The pokemons Attack IVs + u32 defIV : 5; //!< The pokemons Defense IVs + u32 speedIV : 5; //!< The pokemons Speed IVs + u32 spAtkIV : 5; //!< The pokemons Special Attack IVs + u32 spDefIV : 5; //!< The pokemons Special Defense IVs + u32 isEgg : 1; //!< Whether this pokemon is an egg or not + u32 unk_10_31 : 1; + u32 unk_14; + u8 fatefulEncounter:1; //!< The pokemons "Fateful Encounter" flag + u8 gender : 2; //!< The pokemons gender + u8 form:5; //!< The pokemons form + u8 unk_19; + u16 unk_1A; + u16 unk_1C; + u16 unk_1E; +} PokemonDataBlockB; + +/** + * @brief Block C of the BoxPokemon data structure + */ +typedef struct PokemonDataBlockC { + u16 unk_00[11]; + u8 unk_16; + u8 originGame; //!< The game this pokemon was caught in + u64 unk_18; +} PokemonDataBlockC; + +/** + * @brief Block D of the BoxPokemon data structure + */ +typedef struct PokemonDataBlockD { + u16 unk_00[8]; + u8 unk_10; + u8 unk_11; + u8 unk_12; + u8 unk_13; + u8 unk_14; + u8 unk_15; + u16 unk_16; + u16 unk_18; + u8 pokerus; //!< The pokemons Pokerus value + u8 pokeball; //!< What pokeball this pokemon was caught in + u8 metLevel : 7; //!< What level this pokemon was originally met at + u8 otGender : 1; //!< The gender of this pokemons Original Trainer + u8 unk_1D; + u16 unk_1E; +} PokemonDataBlockD; + +typedef union { + PokemonDataBlockA blockA; + PokemonDataBlockB blockB; + PokemonDataBlockC blockC; + PokemonDataBlockD blockD; +} PokemonDataBlock; typedef union { PokemonDataBlockA blockA; diff --git a/include/struct_defs/pokemon_data_block_a.h b/include/struct_defs/pokemon_data_block_a.h deleted file mode 100644 index 4ab865b15e..0000000000 --- a/include/struct_defs/pokemon_data_block_a.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef POKEPLATINUM_POKEMON_SUBSTRUCT_0_H -#define POKEPLATINUM_POKEMON_SUBSTRUCT_0_H - -/** - * @brief Block A of the BoxPokemon data structure - */ -typedef struct PokemonDataBlockA { - u16 species; //!< The pokemons species - u16 heldItem; //!< The pokemons currently held item - u32 otID; //!< The pokemons Original Trainer ID - u32 exp; //!< The pokemons experience points - u8 friendship; //!< The pokemons friendship stat - u8 ability; //!< The pokemons ability - u8 unk_0E; - u8 originLanguage; //!< The language of the game this pokemon was caught in - u8 hpEV; //!< The pokemons HP EVs - u8 atkEV; //!< The pokemons Attack EVs - u8 defEV; //!< The pokemons Defense EVs - u8 speedEV; //!< The pokemons Speed EVs - u8 spAtkEV; //!< The pokemons Special Attack EVs - u8 spDefEV; //!< The pokemons Special Defense EVs - u8 cool; //!< The pokemons Cool contest stat - u8 beauty; //!< The pokemons Beauty contest stat - u8 cute; //!< The pokemons Cute contest stat - u8 smart; //!< The pokemons Smart contest stat - u8 tough; //!< The pokemons Tough contest stat - u8 sheen; //!< The pokemons Sheen - u32 unk_1C; -} PokemonDataBlockA; - -#endif // POKEPLATINUM_POKEMON_SUBSTRUCT_0_H diff --git a/include/struct_defs/pokemon_data_block_b.h b/include/struct_defs/pokemon_data_block_b.h deleted file mode 100644 index 356780f0c5..0000000000 --- a/include/struct_defs/pokemon_data_block_b.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef POKEPLATINUM_POKEMON_SUBSTRUCT_1_H -#define POKEPLATINUM_POKEMON_SUBSTRUCT_1_H - -/** - * @brief Block B of the BoxPokemon data structure - */ -typedef struct PokemonDataBlockB { - u16 moves[4]; //!< The ID of each move the pokemon knows - u8 moveCurrentPPs[4]; //!< The current PP of each move - u8 movePPUps[4]; //!< The number of PP Ups used on each move - u32 hpIV : 5; //!< The pokemons HP IVs - u32 atkIV : 5; //!< The pokemons Attack IVs - u32 defIV : 5; //!< The pokemons Defense IVs - u32 speedIV : 5; //!< The pokemons Speed IVs - u32 spAtkIV : 5; //!< The pokemons Special Attack IVs - u32 spDefIV : 5; //!< The pokemons Special Defense IVs - u32 isEgg : 1; //!< Whether this pokemon is an egg or not - u32 unk_10_31 : 1; - u32 unk_14; - u8 fatefulEncounter:1; //!< The pokemons "Fateful Encounter" flag - u8 gender : 2; //!< The pokemons gender - u8 form:5; //!< The pokemons form - u8 unk_19; - u16 unk_1A; - u16 unk_1C; - u16 unk_1E; -} PokemonDataBlockB; - -#endif // POKEPLATINUM_POKEMON_SUBSTRUCT_1_H diff --git a/include/struct_defs/pokemon_data_block_c.h b/include/struct_defs/pokemon_data_block_c.h deleted file mode 100644 index 3d9c7552c4..0000000000 --- a/include/struct_defs/pokemon_data_block_c.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef POKEPLATINUM_POKEMON_SUBSTRUCT_2_H -#define POKEPLATINUM_POKEMON_SUBSTRUCT_2_H - -/** - * @brief Block C of the BoxPokemon data structure - */ -typedef struct PokemonDataBlockC { - u16 unk_00[11]; - u8 unk_16; - u8 originGame; //!< The game this pokemon was caught in - u64 unk_18; -} PokemonDataBlockC; - -#endif // POKEPLATINUM_POKEMON_SUBSTRUCT_2_H diff --git a/include/struct_defs/pokemon_data_block_d.h b/include/struct_defs/pokemon_data_block_d.h deleted file mode 100644 index e3641fa637..0000000000 --- a/include/struct_defs/pokemon_data_block_d.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef POKEPLATINUM_POKEMON_SUBSTRUCT_3_H -#define POKEPLATINUM_POKEMON_SUBSTRUCT_3_H - -/** - * @brief Block D of the BoxPokemon data structure - */ -typedef struct PokemonDataBlockD { - u16 unk_00[8]; - u8 unk_10; - u8 unk_11; - u8 unk_12; - u8 unk_13; - u8 unk_14; - u8 unk_15; - u16 unk_16; - u16 unk_18; - u8 pokerus; //!< The pokemons Pokerus value - u8 pokeball; //!< What pokeball this pokemon was caught in - u8 metLevel : 7; //!< What level this pokemon was originally met at - u8 otGender : 1; //!< The gender of this pokemons Original Trainer - u8 unk_1D; - u16 unk_1E; -} PokemonDataBlockD; - -#endif // POKEPLATINUM_POKEMON_SUBSTRUCT_3_H diff --git a/src/overlay016/ov16_0225177C.c b/src/overlay016/ov16_0225177C.c index 5559957d7d..8059410699 100644 --- a/src/overlay016/ov16_0225177C.c +++ b/src/overlay016/ov16_0225177C.c @@ -4538,7 +4538,7 @@ BOOL ov16_022579A4 (UnkStruct_0207ADB4 * param0, BattleContext * param1, int par param1->hpCalcTemp = ov16_022563F8(param1->battleMons[param2].maxHP, v3); param1->msgTemp = 0; - if (sub_02077648(param1->battleMons[param2].pid, 0) == -1) { + if (GetMonPersonalityFlavorAffinity(param1->battleMons[param2].pid, 0) == -1) { v1 = (0 + 207); } else { v1 = (0 + 198); @@ -4552,7 +4552,7 @@ BOOL ov16_022579A4 (UnkStruct_0207ADB4 * param0, BattleContext * param1, int par param1->hpCalcTemp = ov16_022563F8(param1->battleMons[param2].maxHP, v3); param1->msgTemp = 1; - if (sub_02077648(param1->battleMons[param2].pid, 1) == -1) { + if (GetMonPersonalityFlavorAffinity(param1->battleMons[param2].pid, 1) == -1) { v1 = (0 + 207); } else { v1 = (0 + 198); @@ -4566,7 +4566,7 @@ BOOL ov16_022579A4 (UnkStruct_0207ADB4 * param0, BattleContext * param1, int par param1->hpCalcTemp = ov16_022563F8(param1->battleMons[param2].maxHP, v3); param1->msgTemp = 2; - if (sub_02077648(param1->battleMons[param2].pid, 2) == -1) { + if (GetMonPersonalityFlavorAffinity(param1->battleMons[param2].pid, 2) == -1) { v1 = (0 + 207); } else { v1 = (0 + 198); @@ -4580,7 +4580,7 @@ BOOL ov16_022579A4 (UnkStruct_0207ADB4 * param0, BattleContext * param1, int par param1->hpCalcTemp = ov16_022563F8(param1->battleMons[param2].maxHP, v3); param1->msgTemp = 3; - if (sub_02077648(param1->battleMons[param2].pid, 3) == -1) { + if (GetMonPersonalityFlavorAffinity(param1->battleMons[param2].pid, 3) == -1) { v1 = (0 + 207); } else { v1 = (0 + 198); @@ -4594,7 +4594,7 @@ BOOL ov16_022579A4 (UnkStruct_0207ADB4 * param0, BattleContext * param1, int par param1->hpCalcTemp = ov16_022563F8(param1->battleMons[param2].maxHP, v3); param1->msgTemp = 4; - if (sub_02077648(param1->battleMons[param2].pid, 4) == -1) { + if (GetMonPersonalityFlavorAffinity(param1->battleMons[param2].pid, 4) == -1) { v1 = (0 + 207); } else { v1 = (0 + 198); @@ -4947,7 +4947,7 @@ BOOL ov16_02258104 (UnkStruct_0207ADB4 * param0, BattleContext * param1, int par param1->hpCalcTemp = ov16_022563F8(param1->battleMons[param2].maxHP, v3); param1->msgTemp = 0; - if (sub_02077648(param1->battleMons[param2].pid, 0) == -1) { + if (GetMonPersonalityFlavorAffinity(param1->battleMons[param2].pid, 0) == -1) { param3[0] = (0 + 207); } else { param3[0] = (0 + 198); @@ -4961,7 +4961,7 @@ BOOL ov16_02258104 (UnkStruct_0207ADB4 * param0, BattleContext * param1, int par param1->hpCalcTemp = ov16_022563F8(param1->battleMons[param2].maxHP, v3); param1->msgTemp = 1; - if (sub_02077648(param1->battleMons[param2].pid, 1) == -1) { + if (GetMonPersonalityFlavorAffinity(param1->battleMons[param2].pid, 1) == -1) { param3[0] = (0 + 207); } else { param3[0] = (0 + 198); @@ -4975,7 +4975,7 @@ BOOL ov16_02258104 (UnkStruct_0207ADB4 * param0, BattleContext * param1, int par param1->hpCalcTemp = ov16_022563F8(param1->battleMons[param2].maxHP, v3); param1->msgTemp = 2; - if (sub_02077648(param1->battleMons[param2].pid, 2) == -1) { + if (GetMonPersonalityFlavorAffinity(param1->battleMons[param2].pid, 2) == -1) { param3[0] = (0 + 207); } else { param3[0] = (0 + 198); @@ -4989,7 +4989,7 @@ BOOL ov16_02258104 (UnkStruct_0207ADB4 * param0, BattleContext * param1, int par param1->hpCalcTemp = ov16_022563F8(param1->battleMons[param2].maxHP, v3); param1->msgTemp = 3; - if (sub_02077648(param1->battleMons[param2].pid, 3) == -1) { + if (GetMonPersonalityFlavorAffinity(param1->battleMons[param2].pid, 3) == -1) { param3[0] = (0 + 207); } else { param3[0] = (0 + 198); @@ -5003,7 +5003,7 @@ BOOL ov16_02258104 (UnkStruct_0207ADB4 * param0, BattleContext * param1, int par param1->hpCalcTemp = ov16_022563F8(param1->battleMons[param2].maxHP, v3); param1->msgTemp = 4; - if (sub_02077648(param1->battleMons[param2].pid, 4) == -1) { + if (GetMonPersonalityFlavorAffinity(param1->battleMons[param2].pid, 4) == -1) { param3[0] = (0 + 207); } else { param3[0] = (0 + 198); @@ -5480,7 +5480,7 @@ BOOL ov16_02258CB4 (UnkStruct_0207ADB4 * param0, BattleContext * param1, int par param1->hpCalcTemp = ov16_022563F8(param1->battleMons[param1->attacker].maxHP, v3); param1->msgTemp = 0; - if (sub_02077648(param1->battleMons[param1->attacker].pid, 0) == -1) { + if (GetMonPersonalityFlavorAffinity(param1->battleMons[param1->attacker].pid, 0) == -1) { v1 = (0 + 207); } else { v1 = (0 + 198); @@ -5494,7 +5494,7 @@ BOOL ov16_02258CB4 (UnkStruct_0207ADB4 * param0, BattleContext * param1, int par param1->hpCalcTemp = ov16_022563F8(param1->battleMons[param1->attacker].maxHP, v3); param1->msgTemp = 1; - if (sub_02077648(param1->battleMons[param1->attacker].pid, 1) == -1) { + if (GetMonPersonalityFlavorAffinity(param1->battleMons[param1->attacker].pid, 1) == -1) { v1 = (0 + 207); } else { v1 = (0 + 198); @@ -5508,7 +5508,7 @@ BOOL ov16_02258CB4 (UnkStruct_0207ADB4 * param0, BattleContext * param1, int par param1->hpCalcTemp = ov16_022563F8(param1->battleMons[param1->attacker].maxHP, v3); param1->msgTemp = 2; - if (sub_02077648(param1->battleMons[param1->attacker].pid, 2) == -1) { + if (GetMonPersonalityFlavorAffinity(param1->battleMons[param1->attacker].pid, 2) == -1) { v1 = (0 + 207); } else { v1 = (0 + 198); @@ -5522,7 +5522,7 @@ BOOL ov16_02258CB4 (UnkStruct_0207ADB4 * param0, BattleContext * param1, int par param1->hpCalcTemp = ov16_022563F8(param1->battleMons[param1->attacker].maxHP, v3); param1->msgTemp = 3; - if (sub_02077648(param1->battleMons[param1->attacker].pid, 3) == -1) { + if (GetMonPersonalityFlavorAffinity(param1->battleMons[param1->attacker].pid, 3) == -1) { v1 = (0 + 207); } else { v1 = (0 + 198); @@ -5536,7 +5536,7 @@ BOOL ov16_02258CB4 (UnkStruct_0207ADB4 * param0, BattleContext * param1, int par param1->hpCalcTemp = ov16_022563F8(param1->battleMons[param1->attacker].maxHP, v3); param1->msgTemp = 4; - if (sub_02077648(param1->battleMons[param1->attacker].pid, 4) == -1) { + if (GetMonPersonalityFlavorAffinity(param1->battleMons[param1->attacker].pid, 4) == -1) { v1 = (0 + 207); } else { v1 = (0 + 198); @@ -5759,7 +5759,7 @@ BOOL ov16_02259204 (UnkStruct_0207ADB4 * param0, BattleContext * param1, int par param1->flingTemp = ov16_022563F8(param1->battleMons[param1->defender].maxHP, v2); param1->msgTemp = 0; - if (sub_02077648(param1->battleMons[param1->defender].pid, 0) == -1) { + if (GetMonPersonalityFlavorAffinity(param1->battleMons[param1->defender].pid, 0) == -1) { param1->flingScript = (0 + 207); } else { param1->flingScript = (0 + 198); @@ -5769,7 +5769,7 @@ BOOL ov16_02259204 (UnkStruct_0207ADB4 * param0, BattleContext * param1, int par param1->flingTemp = ov16_022563F8(param1->battleMons[param1->defender].maxHP, v2); param1->msgTemp = 1; - if (sub_02077648(param1->battleMons[param1->defender].pid, 1) == -1) { + if (GetMonPersonalityFlavorAffinity(param1->battleMons[param1->defender].pid, 1) == -1) { param1->flingScript = (0 + 207); } else { param1->flingScript = (0 + 198); @@ -5779,7 +5779,7 @@ BOOL ov16_02259204 (UnkStruct_0207ADB4 * param0, BattleContext * param1, int par param1->flingTemp = ov16_022563F8(param1->battleMons[param1->defender].maxHP, v2); param1->msgTemp = 2; - if (sub_02077648(param1->battleMons[param1->defender].pid, 2) == -1) { + if (GetMonPersonalityFlavorAffinity(param1->battleMons[param1->defender].pid, 2) == -1) { param1->flingScript = (0 + 207); } else { param1->flingScript = (0 + 198); @@ -5789,7 +5789,7 @@ BOOL ov16_02259204 (UnkStruct_0207ADB4 * param0, BattleContext * param1, int par param1->flingTemp = ov16_022563F8(param1->battleMons[param1->defender].maxHP, v2); param1->msgTemp = 3; - if (sub_02077648(param1->battleMons[param1->defender].pid, 3) == -1) { + if (GetMonPersonalityFlavorAffinity(param1->battleMons[param1->defender].pid, 3) == -1) { param1->flingScript = (0 + 207); } else { param1->flingScript = (0 + 198); @@ -5799,7 +5799,7 @@ BOOL ov16_02259204 (UnkStruct_0207ADB4 * param0, BattleContext * param1, int par param1->flingTemp = ov16_022563F8(param1->battleMons[param1->defender].maxHP, v2); param1->msgTemp = 4; - if (sub_02077648(param1->battleMons[param1->defender].pid, 4) == -1) { + if (GetMonPersonalityFlavorAffinity(param1->battleMons[param1->defender].pid, 4) == -1) { param1->flingScript = (0 + 207); } else { param1->flingScript = (0 + 198); diff --git a/src/pokemon.c b/src/pokemon.c index bd60c6900a..2caa5a9c30 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -22,10 +22,6 @@ #include "struct_defs/pokemon.h" #include "struct_defs/box_pokemon.h" #include "struct_defs/party_pokemon.h" -#include "struct_defs/pokemon_data_block_a.h" -#include "struct_defs/pokemon_data_block_b.h" -#include "struct_defs/pokemon_data_block_c.h" -#include "struct_defs/pokemon_data_block_d.h" #include "struct_defs/pokemon_personal_data.h" #include "struct_defs/pokemon_evolution_data.h" #include "struct_defs/struct_020789BC.h" @@ -63,7 +59,9 @@ #include "constants/items.h" #include "constants/moves.h" -static const s8 Unk_020F0695[][5] = { +// Columns: Spicy, Dry, Sweet, Bitter, Sour +// TODO enum here? +static const s8 sNatureFlavorAffinities[][5] = { { 0x0, 0x0, 0x0, 0x0, 0x0 }, { 0x1, 0x0, 0x0, 0x0, -0x1 }, { 0x1, 0x0, -0x1, 0x0, 0x0 }, @@ -91,6 +89,14 @@ static const s8 Unk_020F0695[][5] = { { 0x0, 0x0, 0x0, 0x0, 0x0 }, }; +static enum PokemonDataBlockID { + DATA_BLOCK_A = 0, + DATA_BLOCK_B, + DATA_BLOCK_C, + DATA_BLOCK_D +}; + +static void sub_02073E18(BoxPokemon *boxMon, int monSpecies, int monLevel, int monIVs, BOOL useMonPersonalityParam, u32 monPersonality, int monOTIDSource, u32 monOTID); static u32 GetMonDataAttribute(Pokemon *mon, enum PokemonDataParam param, void *dest); static u32 GetBoxMonDataAttribute(BoxPokemon *boxMon, enum PokemonDataParam param, void *dest); static void SetMonDataAttribute(Pokemon *mon, enum PokemonDataParam param, const void *value); @@ -99,13 +105,14 @@ static void IncreaseMonDataAttribute(Pokemon *mon, enum PokemonDataParam param, static void IncreaseBoxMonDataAttribute(BoxPokemon *boxMon, enum PokemonDataParam param, int value); static u32 GetMonExpRateLevelExp(int monExpRate, int monLevel); static u16 GetNatureAdjustedStatValue(u8 monNature, u16 monStatValue, u8 statType); +static inline BOOL IsMonPersonalityShiny(u32 monOTID, u32 monPersonality); static void LoadMonPersonalData(int monSpecies, PokemonPersonalData *monPersonalData); static void LoadMonFormPersonalData(int monSpecies, int monForm, PokemonPersonalData *monPersonalData); static void LoadMonEvolutionData(int monSpecies, PokemonEvolutionData *monEvolutionData); static void EncryptMonData(void *data, u32 bytes, u32 seed); static void DecryptMonData(void *data, u32 bytes, u32 seed); static u16 GetMonDataChecksum(void *data, u32 bytes); -static void *GetBoxMonDataBlock(BoxPokemon *boxMon, u32 personality, u8 dataBlockID); +static void *GetBoxMonDataBlock(BoxPokemon *boxMon, u32 personality, enum PokemonDataBlockID dataBlockID); static int GetMonFormNarcIndex(int monSpecies, int monForm); static void sub_02076300(UnkStruct_02008A90 *param0, u16 monSpecies, u8 monGender, u8 param3, u8 monShininess, u8 monForm, u32 monPersonality); static u8 sub_020767BC(u16 monSpecies, u8 monGender, u8 param2, u8 monForm, u32 monPersonality); @@ -223,8 +230,7 @@ void sub_02073D80 (Pokemon *mon, int monSpecies, int monLevel, int monIVs, BOOL CalculateMonLevelAndStats(mon); } -// TODO make this static? -void sub_02073E18 (BoxPokemon *boxMon, int monSpecies, int monLevel, int monIVs, BOOL useMonPersonalityParam, u32 monPersonality, int monOTIDSource, u32 monOTID) +static void sub_02073E18 (BoxPokemon *boxMon, int monSpecies, int monLevel, int monIVs, BOOL useMonPersonalityParam, u32 monPersonality, int monOTIDSource, u32 monOTID) { ZeroBoxMonData(boxMon); @@ -240,7 +246,7 @@ void sub_02073E18 (BoxPokemon *boxMon, int monSpecies, int monLevel, int monIVs, if (monOTIDSource == 2) { do { monOTID = (LCRNG_Next() | (LCRNG_Next() << 16)); - } while ((((monOTID & 0xffff0000) >> 16) ^ (monOTID & 0xffff) ^ ((monPersonality & 0xffff0000) >> 16) ^ (monPersonality & 0xffff)) < 8); + } while (IsMonPersonalityShiny(monOTID, monPersonality)); } else if (monOTIDSource != 1) { monOTID = 0; } @@ -580,11 +586,10 @@ static u32 GetBoxMonDataAttribute (BoxPokemon *boxMon, enum PokemonDataParam par { u32 result = 0; - // TODO enum? - PokemonDataBlockA *monDataBlockA = GetBoxMonDataBlock(boxMon, boxMon->personality, 0); - PokemonDataBlockB *monDataBlockB = GetBoxMonDataBlock(boxMon, boxMon->personality, 1); - PokemonDataBlockC *monDataBlockC = GetBoxMonDataBlock(boxMon, boxMon->personality, 2); - PokemonDataBlockD *monDataBlockD = GetBoxMonDataBlock(boxMon, boxMon->personality, 3); + PokemonDataBlockA *monDataBlockA = GetBoxMonDataBlock(boxMon, boxMon->personality, DATA_BLOCK_A); + PokemonDataBlockB *monDataBlockB = GetBoxMonDataBlock(boxMon, boxMon->personality, DATA_BLOCK_B); + PokemonDataBlockC *monDataBlockC = GetBoxMonDataBlock(boxMon, boxMon->personality, DATA_BLOCK_C); + PokemonDataBlockD *monDataBlockD = GetBoxMonDataBlock(boxMon, boxMon->personality, DATA_BLOCK_D); switch (param) { default: @@ -1089,11 +1094,10 @@ static void SetBoxMonDataAttribute (BoxPokemon *boxMon, enum PokemonDataParam pa u16 *u16Value = value; u8 *u8Value = value; - // TODO enum values? - PokemonDataBlockA *monDataBlockA = GetBoxMonDataBlock(boxMon, boxMon->personality, 0); - PokemonDataBlockB *monDataBlockB = GetBoxMonDataBlock(boxMon, boxMon->personality, 1); - PokemonDataBlockC *monDataBlockC = GetBoxMonDataBlock(boxMon, boxMon->personality, 2); - PokemonDataBlockD *monDataBlockD = GetBoxMonDataBlock(boxMon, boxMon->personality, 3); + PokemonDataBlockA *monDataBlockA = GetBoxMonDataBlock(boxMon, boxMon->personality, DATA_BLOCK_A); + PokemonDataBlockB *monDataBlockB = GetBoxMonDataBlock(boxMon, boxMon->personality, DATA_BLOCK_B); + PokemonDataBlockC *monDataBlockC = GetBoxMonDataBlock(boxMon, boxMon->personality, DATA_BLOCK_C); + PokemonDataBlockD *monDataBlockD = GetBoxMonDataBlock(boxMon, boxMon->personality, DATA_BLOCK_D); switch (param) { case MON_DATA_PERSONALITY: @@ -1521,11 +1525,10 @@ static void IncreaseMonDataAttribute (Pokemon *mon, enum PokemonDataParam param, static void IncreaseBoxMonDataAttribute (BoxPokemon *boxMon, enum PokemonDataParam param, int value) { - // TODO enum values? - PokemonDataBlockA *monDataBlockA = GetBoxMonDataBlock(boxMon, boxMon->personality, 0); - PokemonDataBlockB *monDataBlockB = GetBoxMonDataBlock(boxMon, boxMon->personality, 1); - PokemonDataBlockC *monDataBlockC = GetBoxMonDataBlock(boxMon, boxMon->personality, 2); - PokemonDataBlockD *monDataBlockD = GetBoxMonDataBlock(boxMon, boxMon->personality, 3); + PokemonDataBlockA *monDataBlockA = GetBoxMonDataBlock(boxMon, boxMon->personality, DATA_BLOCK_A); + PokemonDataBlockB *monDataBlockB = GetBoxMonDataBlock(boxMon, boxMon->personality, DATA_BLOCK_B); + PokemonDataBlockC *monDataBlockC = GetBoxMonDataBlock(boxMon, boxMon->personality, DATA_BLOCK_C); + PokemonDataBlockD *monDataBlockD = GetBoxMonDataBlock(boxMon, boxMon->personality, DATA_BLOCK_D); // TODO consts for various maximum values? switch (param) { @@ -2283,9 +2286,13 @@ u8 GetBoxMonShininess (BoxPokemon *boxMon) return GetMonPersonalityShininess(monOTID, monPersonality); } +static inline BOOL IsMonPersonalityShiny(u32 monOTID, u32 monPersonality) { + return (((monOTID & 0xffff0000) >> 16) ^ (monOTID & 0xffff) ^ ((monPersonality & 0xffff0000) >> 16) ^ (monPersonality & 0xffff)) < 8; +} + u8 GetMonPersonalityShininess (u32 monOTID, u32 monPersonality) { - return (((monOTID & 0xffff0000) >> 16) ^ (monOTID & 0xffff) ^ ((monPersonality & 0xffff0000) >> 16) ^ (monPersonality & 0xffff)) < 8; + return IsMonPersonalityShiny(monOTID, monPersonality); } u32 sub_02075E64 (u32 param0) @@ -2326,8 +2333,7 @@ void sub_02075F00 (UnkStruct_02008A90 *param0, Pokemon *mon, u8 param2) sub_02075F0C(param0, &mon->box, param2, TRUE); } -// TODO change param3 to BOOL -void sub_02075F0C (UnkStruct_02008A90 *param0, BoxPokemon *boxMon, u8 param2, int param3) +void sub_02075F0C (UnkStruct_02008A90 *param0, BoxPokemon *boxMon, u8 param2, BOOL param3) { BOOL reencrypt = DecryptBoxMon(boxMon); @@ -2648,8 +2654,7 @@ u8 sub_020765B8 (Pokemon *mon, u8 param1) return sub_020765C4(&mon->box, param1, TRUE); } -// TODO change param2 to BOOL -u8 sub_020765C4 (BoxPokemon *boxMon, u8 param1, int param2) +u8 sub_020765C4 (BoxPokemon *boxMon, u8 param1, BOOL param2) { u16 monSpeciesEgg = GetBoxMonData(boxMon, MON_DATA_SPECIES_EGG, NULL); u8 monGender = GetBoxMonGender(boxMon); @@ -2959,8 +2964,7 @@ BoxPokemon *GetBoxMon (Pokemon *mon) return &mon->box; } -// TODO return BOOL -u8 sub_02076B14 (Pokemon *mon) +BOOL sub_02076B14 (Pokemon *mon) { u16 monSpecies = GetMonData(mon, MON_DATA_SPECIES, NULL); u8 monNextLevel = GetMonData(mon, MON_DATA_LEVEL, NULL) + 1; @@ -3574,20 +3578,23 @@ void sub_02077618 (Pokemon *src, BoxPokemon *dest) return; } -s8 sub_0207762C (Pokemon *mon, int param1) +// TODO enums +s8 GetMonFlavorAffinity (Pokemon *mon, int flavor) { - return sub_02077634(&mon->box, param1); + return GetBoxMonFlavorAffinity(&mon->box, flavor); } -s8 sub_02077634 (BoxPokemon *boxMon, int param1) +// TODO enums +s8 GetBoxMonFlavorAffinity (BoxPokemon *boxMon, int flavor) { - return sub_02077648(GetBoxMonData(boxMon, MON_DATA_PERSONALITY, NULL), param1); + return GetMonPersonalityFlavorAffinity(GetBoxMonData(boxMon, MON_DATA_PERSONALITY, NULL), flavor); } -s8 sub_02077648 (u32 monPersonality, int param1) +// TODO enums +s8 GetMonPersonalityFlavorAffinity (u32 monPersonality, int flavor) { u8 monNature = GetNatureFromPersonality(monPersonality); - return Unk_020F0695[monNature][param1]; + return sNatureFlavorAffinities[monNature][flavor]; } int GetMonLevelUpMoveIDs (int monSpecies, int monForm, u16 *monLevelUpMoveIDs) @@ -4236,15 +4243,14 @@ void sub_020780C4 (Pokemon *mon, u32 monPersonality) sub_020775EC(mon, newMon); - // TODO enum values? - PokemonDataBlockA *newMonBlockA = GetBoxMonDataBlock(&newMon->box, mon->box.personality, 0); - PokemonDataBlockB *newMonBlockB = GetBoxMonDataBlock(&newMon->box, mon->box.personality, 1); - PokemonDataBlockC *newMonBlockC = GetBoxMonDataBlock(&newMon->box, mon->box.personality, 2); - PokemonDataBlockD *newMonBlockD = GetBoxMonDataBlock(&newMon->box, mon->box.personality, 3); - PokemonDataBlockA *monBlockA = GetBoxMonDataBlock(&mon->box, monPersonality, 0); - PokemonDataBlockB *monBlockB = GetBoxMonDataBlock(&mon->box, monPersonality, 1); - PokemonDataBlockC *monBlockC = GetBoxMonDataBlock(&mon->box, monPersonality, 2); - PokemonDataBlockD *monBlockD = GetBoxMonDataBlock(&mon->box, monPersonality, 3); + PokemonDataBlockA *newMonBlockA = GetBoxMonDataBlock(&newMon->box, mon->box.personality, DATA_BLOCK_A); + PokemonDataBlockB *newMonBlockB = GetBoxMonDataBlock(&newMon->box, mon->box.personality, DATA_BLOCK_B); + PokemonDataBlockC *newMonBlockC = GetBoxMonDataBlock(&newMon->box, mon->box.personality, DATA_BLOCK_C); + PokemonDataBlockD *newMonBlockD = GetBoxMonDataBlock(&newMon->box, mon->box.personality, DATA_BLOCK_D); + PokemonDataBlockA *monBlockA = GetBoxMonDataBlock(&mon->box, monPersonality, DATA_BLOCK_A); + PokemonDataBlockB *monBlockB = GetBoxMonDataBlock(&mon->box, monPersonality, DATA_BLOCK_B); + PokemonDataBlockC *monBlockC = GetBoxMonDataBlock(&mon->box, monPersonality, DATA_BLOCK_C); + PokemonDataBlockD *monBlockD = GetBoxMonDataBlock(&mon->box, monPersonality, DATA_BLOCK_D); DecryptMonData(&newMon->box.dataBlocks, sizeof(PokemonDataBlock) * 4, newMon->box.checksum); DecryptMonData(&mon->party, sizeof(PartyPokemon), mon->box.personality); @@ -4309,23 +4315,23 @@ static u16 GetMonDataChecksum (void *data, u32 bytes) PokemonDataBlock *dataBlocks = boxMon->dataBlocks; \ switch (dataBlockID) \ { \ - case 0: \ + case DATA_BLOCK_A: \ result = &dataBlocks[v1]; \ break; \ - case 1: \ + case DATA_BLOCK_B: \ result = &dataBlocks[v2]; \ break; \ - case 2: \ + case DATA_BLOCK_C: \ result = &dataBlocks[v3]; \ break; \ - case 3: \ + case DATA_BLOCK_D: \ result = &dataBlocks[v4]; \ break; \ } \ break; \ } -static void *GetBoxMonDataBlock (BoxPokemon *boxMon, u32 personality, u8 dataBlockID) +static void *GetBoxMonDataBlock (BoxPokemon *boxMon, u32 personality, enum PokemonDataBlockID dataBlockID) { personality = (personality & 0x3e000) >> 13; GF_ASSERT(personality <= 31); @@ -4683,11 +4689,11 @@ void sub_02078B40 (Pokemon *mon, UnkStruct_02078B40 *param1) } BoxPokemon *boxMon = GetBoxMon(mon); - // TODO enum values? - PokemonDataBlockA *monDataBlockA = GetBoxMonDataBlock(boxMon, boxMon->personality, 0); - PokemonDataBlockB *monDataBlockB = GetBoxMonDataBlock(boxMon, boxMon->personality, 1); - PokemonDataBlockC *monDataBlockC = GetBoxMonDataBlock(boxMon, boxMon->personality, 2); - PokemonDataBlockD *monDataBlockD = GetBoxMonDataBlock(boxMon, boxMon->personality, 3); + + PokemonDataBlockA *monDataBlockA = GetBoxMonDataBlock(boxMon, boxMon->personality, DATA_BLOCK_A); + PokemonDataBlockB *monDataBlockB = GetBoxMonDataBlock(boxMon, boxMon->personality, DATA_BLOCK_B); + PokemonDataBlockC *monDataBlockC = GetBoxMonDataBlock(boxMon, boxMon->personality, DATA_BLOCK_C); + PokemonDataBlockD *monDataBlockD = GetBoxMonDataBlock(boxMon, boxMon->personality, DATA_BLOCK_D); param1->personality = boxMon->personality; param1->partyDecrypted = FALSE; @@ -4758,11 +4764,11 @@ void sub_02078E0C (UnkStruct_02078B40 *param0, Pokemon *mon) MI_CpuClearFast(mon, sizeof(Pokemon)); BoxPokemon *boxMon = GetBoxMon(mon); - // TODO enum values? - PokemonDataBlockA *monDataBlockA = GetBoxMonDataBlock(boxMon, param0->personality, 0); - PokemonDataBlockB *monDataBlockB = GetBoxMonDataBlock(boxMon, param0->personality, 1); - PokemonDataBlockC *monDataBlockC = GetBoxMonDataBlock(boxMon, param0->personality, 2); - PokemonDataBlockD *monDataBlockD = GetBoxMonDataBlock(boxMon, param0->personality, 3); + + PokemonDataBlockA *monDataBlockA = GetBoxMonDataBlock(boxMon, param0->personality, DATA_BLOCK_A); + PokemonDataBlockB *monDataBlockB = GetBoxMonDataBlock(boxMon, param0->personality, DATA_BLOCK_B); + PokemonDataBlockC *monDataBlockC = GetBoxMonDataBlock(boxMon, param0->personality, DATA_BLOCK_C); + PokemonDataBlockD *monDataBlockD = GetBoxMonDataBlock(boxMon, param0->personality, DATA_BLOCK_D); boxMon->personality = param0->personality; boxMon->partyDecrypted = FALSE; diff --git a/src/unk_0206CCB0.c b/src/unk_0206CCB0.c index 3bf82a76e6..b4c782d4e0 100644 --- a/src/unk_0206CCB0.c +++ b/src/unk_0206CCB0.c @@ -2714,7 +2714,7 @@ static int sub_0206ED14 (UnkStruct_0203CDB0 * param0, UnkStruct_0200B358 * param if ((v0 % 2) == 0) { for (v1 = 0; v1 < 5; v1++) { - if (sub_02077648(v0, v1) == 1) { + if (GetMonPersonalityFlavorAffinity(v0, v1) == 1) { v5 = v1; break; } diff --git a/src/unk_0208C324.c b/src/unk_0208C324.c index 93c5776fcf..4b5330d6f7 100644 --- a/src/unk_0208C324.c +++ b/src/unk_0208C324.c @@ -1095,7 +1095,7 @@ static void sub_0208D200 (UnkStruct_0208D7BC * param0, Pokemon * param1, UnkStru param2->unk_4B = 5; for (v1 = 0; v1 < 5; v1++) { - if (sub_0207762C(param1, v1) == 1) { + if (GetMonFlavorAffinity(param1, v1) == 1) { param2->unk_4B = v1; break; } diff --git a/src/unk_02092494.c b/src/unk_02092494.c index cafdbc375e..30f4c0366b 100644 --- a/src/unk_02092494.c +++ b/src/unk_02092494.c @@ -609,7 +609,7 @@ static void sub_02092E10 (UnkStruct_02090800 * param0) v1 = 0; for (v0 = 0; v0 < 5; v0++) { - if (sub_0207762C(param0->unk_0C, v0) == 1) { + if (GetMonFlavorAffinity(param0->unk_0C, v0) == 1) { v1 = v0 + 1; } }