diff --git a/arm9/asm/unk_0207550C.s b/arm9/asm/unk_0207550C.s index 9ff8095bf..5aa8ecc85 100644 --- a/arm9/asm/unk_0207550C.s +++ b/arm9/asm/unk_0207550C.s @@ -2562,7 +2562,7 @@ _02076AD4: bl ItemToTMHMId add r1, r0, #0x0 add r0, r6, #0x0 - bl sub_0206A13C + bl Pokemon_CanLearnTMHM cmp r0, #0x0 bne _02076AEA mov r0, #0xff diff --git a/arm9/global.inc b/arm9/global.inc index f62887f0d..f66851285 100644 --- a/arm9/global.inc +++ b/arm9/global.inc @@ -4818,8 +4818,8 @@ .extern Species_LoadLevelUpLearnset .extern sub_02069FB0 .extern sub_0206A014 -.extern sub_0206A094 -.extern sub_0206A13C +.extern Pokemon_GiveWildHeldItem +.extern Pokemon_CanLearnTMHM .extern Species_CanLearnTMHM .extern Pokemon_UpdateAbility .extern sub_0206A23C diff --git a/arm9/overlays/06/asm/overlay_06.s b/arm9/overlays/06/asm/overlay_06.s index c354a7869..2e4c006c1 100644 --- a/arm9/overlays/06/asm/overlay_06.s +++ b/arm9/overlays/06/asm/overlay_06.s @@ -7842,7 +7842,7 @@ _0223D1D8: _0223D1DA: ldr r1, [r7] add r0, r6, #0 - bl sub_0206A094 + bl Pokemon_GiveWildHeldItem mov r4, #0 add r0, r6, #0 mov r1, #5 diff --git a/arm9/src/pokemon.c b/arm9/src/pokemon.c index 03950d108..d2a14b2d6 100644 --- a/arm9/src/pokemon.c +++ b/arm9/src/pokemon.c @@ -1,6 +1,7 @@ #include "global.h" #define IN_POKEMON_C #include "constants/abilities.h" +#include "constants/battle.h" #include "constants/items.h" #include "constants/moves.h" #include "constants/sinnoh_dex.h" @@ -47,8 +48,8 @@ void BoxPokemon_UpdateArceusForm(BoxPokemon *boxMon); void Species_LoadLevelUpLearnset(int species, int form, u16 *levelUpLearnset); void sub_0206A054(BoxPokemon *boxMon, PlayerProfile *a1, u32 pokeball, u32 a3, u32 encounterType, enum HeapID heapID); BOOL Pokemon_HasMove(Pokemon *mon, u16 move); -BOOL BoxPokemon_CanLearnTMHM(BoxPokemon *boxMon, u32 tmHM); -BOOL Species_CanLearnTMHM(u16 species, int form, u32 a2); +BOOL BoxPokemon_CanLearnTMHM(BoxPokemon *boxMon, u8 tmHM); +BOOL Species_CanLearnTMHM(u16 species, int form, u8 tmHM); void BoxPokemon_UpdateAbility(BoxPokemon *boxMon); u32 MaskOfFlagNo(int flagno); void SpeciesData_LoadSpecies(int species, SpeciesData *speciesData); @@ -3137,49 +3138,48 @@ void sub_0206A054(BoxPokemon *boxMon, PlayerProfile *a1, u32 pokeball, u32 a3, u BoxPokemon_SetData(boxMon, MON_DATA_MET_TERRAIN, &encounterType); } -const u16 sItemOdds[2][2] = { - { 45, 95 }, - { 20, 80 }, +static const u16 sHeldItemOdds[][2] = { + { 45, 95 }, // Without CompoundEyes (itemRates == 0) 45% no item, 50% common item, 5% rare item + { 20, 80 }, // With CompoundEyes (itemRates == 1) 20% no item, 60% common item, 20% rare item }; -void sub_0206A094(Pokemon *mon, u32 a1, u32 a2) { - u32 chance; - u16 species; - u16 form; - u16 item1; - u16 item2; - if (!(a1 & 0x81)) { - chance = (u32)(LCRandom() % 100); - species = (u16)Pokemon_GetData(mon, MON_DATA_SPECIES, 0); - form = (u16)Pokemon_GetData(mon, MON_DATA_FORM, 0); - item1 = (u16)Species_GetFormValue(species, form, SPECIES_DATA_HELD_ITEM_COMMON); - item2 = (u16)Species_GetFormValue(species, form, SPECIES_DATA_HELD_ITEM_RARE); - if (item1 == item2 && item1 != ITEM_NONE) { - Pokemon_SetData(mon, MON_DATA_HELD_ITEM, &item1); - } else { - if (chance >= sItemOdds[a2][0]) { - if (chance < sItemOdds[a2][1]) { - Pokemon_SetData(mon, MON_DATA_HELD_ITEM, &item1); - } else { - Pokemon_SetData(mon, MON_DATA_HELD_ITEM, &item2); - } - } - } +void Pokemon_GiveWildHeldItem(Pokemon *mon, u32 battleType, u32 itemRates) { + if (battleType & (BATTLE_TYPE_TRAINER | BATTLE_TYPE_TOWER)) { + return; + } + + u32 rand = LCRandom() % 100; + u16 species = Pokemon_GetData(mon, MON_DATA_SPECIES, NULL); + u16 form = Pokemon_GetData(mon, MON_DATA_FORM, NULL); + u16 item1 = Species_GetFormValue(species, form, SPECIES_DATA_HELD_ITEM_COMMON); + u16 item2 = Species_GetFormValue(species, form, SPECIES_DATA_HELD_ITEM_RARE); + + if (item1 == item2 && item1 != ITEM_NONE) { + Pokemon_SetData(mon, MON_DATA_HELD_ITEM, &item1); + return; + } + + if (rand < sHeldItemOdds[itemRates][0]) { + return; + } else if (rand < sHeldItemOdds[itemRates][1]) { + Pokemon_SetData(mon, MON_DATA_HELD_ITEM, &item1); + } else { + Pokemon_SetData(mon, MON_DATA_HELD_ITEM, &item2); } } -BOOL sub_0206A13C(Pokemon *mon, u32 tmHM) { +BOOL Pokemon_CanLearnTMHM(Pokemon *mon, u8 tmHM) { return BoxPokemon_CanLearnTMHM(&mon->box, tmHM); } -BOOL BoxPokemon_CanLearnTMHM(BoxPokemon *boxMon, u32 tmHM) { +BOOL BoxPokemon_CanLearnTMHM(BoxPokemon *boxMon, u8 tmHM) { u16 species = BoxPokemon_GetData(boxMon, MON_DATA_SPECIES_OR_EGG, NULL); int form = BoxPokemon_GetData(boxMon, MON_DATA_FORM, NULL); return Species_CanLearnTMHM(species, form, tmHM); } -BOOL Species_CanLearnTMHM(u16 species, int form, u32 tmHM) { +BOOL Species_CanLearnTMHM(u16 species, int form, u8 tmHM) { if (species == SPECIES_EGG) { return FALSE; } diff --git a/include/pokemon.h b/include/pokemon.h index 1cb15ecd8..5c47b6a47 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -323,8 +323,8 @@ BOOL Pokemon_IsImmuneToPokerus(Pokemon *mon); void Pokemon_UpdateArceusForm(Pokemon *mon); void sub_02069FB0(struct SaveChatotSoundClip *r7, u32 r5, u16 r4, s32 r6, s32 sp18, u32 sp1C, enum HeapID heapID); void sub_0206A014(Pokemon *mon, PlayerProfile *a1, u32 pokeball, u32 a3, u32 encounterType, enum HeapID heapID); -void sub_0206A094(Pokemon *mon, u32 a1, u32 a2); -BOOL sub_0206A13C(Pokemon *mon, u32 tmHM); +void Pokemon_GiveWildHeldItem(Pokemon *mon, u32 battleType, u32 itemRates); +BOOL Pokemon_CanLearnTMHM(Pokemon *mon, u8 tmHM); void Pokemon_UpdateAbility(Pokemon *mon); void sub_0206A23C(Pokemon *r5, u32 personality); int LowestFlagNo(u32 mask);