diff options
author | Cameron Hall <camthesaxman@users.noreply.github.com> | 2016-11-11 20:07:15 -0600 |
---|---|---|
committer | YamaArashi <YamaArashi@users.noreply.github.com> | 2016-11-11 18:07:15 -0800 |
commit | 510f104706cb1420b41a0ca8d96cb2b522b38c01 (patch) | |
tree | 94dc7a8da5d3374f3c51cdac2d88dbec2b22509f | |
parent | 52aba81f3498eb2cdccbb2819bf2202cd8b4b755 (diff) |
more cleanup (#98)
-rw-r--r-- | asm/berry_blender.s | 8 | ||||
-rw-r--r-- | asm/rom6.s | 26 | ||||
-rw-r--r-- | asm/rom_800D42C.s | 4 | ||||
-rw-r--r-- | asm/rom_804373C.s | 4 | ||||
-rw-r--r-- | asm/rom_8065394.s | 2 | ||||
-rw-r--r-- | data/data2.s | 5 | ||||
-rw-r--r-- | data/specials.inc | 6 | ||||
-rw-r--r-- | include/abilities.h | 86 | ||||
-rw-r--r-- | include/var.h | 2 | ||||
-rw-r--r-- | include/vars.h | 6 | ||||
-rw-r--r-- | src/battle_setup.c | 18 | ||||
-rw-r--r-- | src/safari_zone.c | 176 | ||||
-rw-r--r-- | src/start_menu.c | 11 | ||||
-rw-r--r-- | src/wild_encounter.c | 660 | ||||
-rw-r--r-- | sym_ewram.txt | 43 |
15 files changed, 505 insertions, 552 deletions
diff --git a/asm/berry_blender.s b/asm/berry_blender.s index f8cde5a8d..affe536ca 100644 --- a/asm/berry_blender.s +++ b/asm/berry_blender.s @@ -7692,7 +7692,7 @@ sub_805201C: @ 805201C adds r6, r1, 0 movs r0, 0xFF strb r0, [r6] - ldr r1, _080520B0 @ =gUnknown_083F7EB8 + ldr r1, _080520B0 @ =gPokeblockNames ldrb r0, [r5] lsls r0, 2 adds r0, r1 @@ -7748,7 +7748,7 @@ sub_805201C: @ 805201C pop {r0} bx r0 .align 2, 0 -_080520B0: .4byte gUnknown_083F7EB8 +_080520B0: .4byte gPokeblockNames _080520B4: .4byte gOtherText_PokeBlockMade _080520B8: .4byte gUnknown_082162C8 _080520BC: .4byte gOtherText_BlockLevelIs @@ -8521,7 +8521,7 @@ _080526EC: ldrb r0, [r1, 0x8] cmp r0, 0 beq _080527A4 - ldr r1, _080527B4 @ =gUnknown_083F7EB8 + ldr r1, _080527B4 @ =gPokeblockNames mov r2, r8 ldrb r0, [r2, 0x8] lsls r0, 2 @@ -8605,7 +8605,7 @@ _080527A4: pop {r0} bx r0 .align 2, 0 -_080527B4: .4byte gUnknown_083F7EB8 +_080527B4: .4byte gPokeblockNames _080527B8: .4byte gUnknown_082165F8 thumb_func_end sub_8052530 diff --git a/asm/rom6.s b/asm/rom6.s index 697769d17..daa43e5bd 100644 --- a/asm/rom6.s +++ b/asm/rom6.s @@ -1133,7 +1133,7 @@ _0810BC08: adds r0, r1 ldrb r0, [r0] lsls r0, 2 - ldr r1, _0810BC7C @ =gUnknown_083F7EB8 + ldr r1, _0810BC7C @ =gPokeblockNames adds r0, r1 ldr r1, [r0] mov r0, r9 @@ -1180,7 +1180,7 @@ _0810BC6C: pop {r0} bx r0 .align 2, 0 -_0810BC7C: .4byte gUnknown_083F7EB8 +_0810BC7C: .4byte gPokeblockNames _0810BC80: .4byte gSaveBlock1 + 0x7F8 thumb_func_end sub_810BB88 @@ -2302,7 +2302,7 @@ sub_810C540: @ 810C540 movs r3, 0xB bl MenuZeroFillWindowRect ldr r0, _0810C5A4 @ =gStringVar1 - ldr r4, _0810C5A8 @ =gUnknown_083F7EB8 + ldr r4, _0810C5A8 @ =gPokeblockNames ldr r3, _0810C5AC @ =gSaveBlock1 ldr r2, _0810C5B0 @ =gUnknown_02039248 ldrb r1, [r2] @@ -2333,7 +2333,7 @@ sub_810C540: @ 810C540 .align 2, 0 _0810C5A0: .4byte gWindowConfig_81E6E50 _0810C5A4: .4byte gStringVar1 -_0810C5A8: .4byte gUnknown_083F7EB8 +_0810C5A8: .4byte gPokeblockNames _0810C5AC: .4byte gSaveBlock1 _0810C5B0: .4byte gUnknown_02039248 _0810C5B4: .4byte gStringVar4 @@ -2587,7 +2587,7 @@ sub_810C788: @ 810C788 lsls r4, 16 lsrs r4, 16 ldr r0, _0810C840 @ =gUnknown_030041C0 - ldr r2, _0810C844 @ =gUnknown_083F7EB8 + ldr r2, _0810C844 @ =gPokeblockNames ldr r1, _0810C848 @ =0xfffff808 adds r5, r1 ldrh r1, [r7] @@ -2655,7 +2655,7 @@ _0810C834: .4byte gEnemyParty _0810C838: .4byte gScriptItemId _0810C83C: .4byte gSaveBlock1 + 0x7F8 _0810C840: .4byte gUnknown_030041C0 -_0810C844: .4byte gUnknown_083F7EB8 +_0810C844: .4byte gPokeblockNames _0810C848: .4byte 0xfffff808 _0810C84C: .4byte gTasks _0810C850: .4byte sub_810C2C8 @@ -2670,9 +2670,9 @@ sub_810C854: @ 810C854 lsrs r5, 24 ldr r4, _0810C8B8 @ =gScriptItemId ldrb r0, [r4] - bl sub_80C8478 + bl SafariZoneActivatePokeblockFeeder ldr r0, _0810C8BC @ =gStringVar1 - ldr r3, _0810C8C0 @ =gUnknown_083F7EB8 + ldr r3, _0810C8C0 @ =gPokeblockNames ldr r2, _0810C8C4 @ =gSaveBlock1 ldrh r1, [r4] lsls r1, 3 @@ -2712,7 +2712,7 @@ sub_810C854: @ 810C854 .align 2, 0 _0810C8B8: .4byte gScriptItemId _0810C8BC: .4byte gStringVar1 -_0810C8C0: .4byte gUnknown_083F7EB8 +_0810C8C0: .4byte gPokeblockNames _0810C8C4: .4byte gSaveBlock1 _0810C8C8: .4byte gScriptResult _0810C8CC: .4byte gTasks @@ -3083,7 +3083,7 @@ sub_810CB44: @ 810CB44 movs r1, 0 bl sub_810CA9C lsls r0, 24 - ldr r1, _0810CB64 @ =gUnknown_083F7EB8 + ldr r1, _0810CB64 @ =gPokeblockNames lsrs r0, 22 adds r0, r1 ldr r1, [r0] @@ -3093,7 +3093,7 @@ sub_810CB44: @ 810CB44 pop {r0} bx r0 .align 2, 0 -_0810CB64: .4byte gUnknown_083F7EB8 +_0810CB64: .4byte gPokeblockNames thumb_func_end sub_810CB44 thumb_func_start sub_810CB68 @@ -3103,7 +3103,7 @@ sub_810CB68: @ 810CB68 lsls r0, 24 lsrs r5, r0, 24 movs r4, 0 - ldr r7, _0810CB98 @ =gUnknown_083F7EB8 + ldr r7, _0810CB98 @ =gPokeblockNames _0810CB74: lsls r1, r4, 3 ldr r0, _0810CB9C @ =gUnknown_083F7F9C @@ -3122,7 +3122,7 @@ _0810CB74: movs r0, 0x1 b _0810CBAC .align 2, 0 -_0810CB98: .4byte gUnknown_083F7EB8 +_0810CB98: .4byte gPokeblockNames _0810CB9C: .4byte gUnknown_083F7F9C _0810CBA0: adds r0, r4, 0x1 diff --git a/asm/rom_800D42C.s b/asm/rom_800D42C.s index 226e5dfde..fdb390563 100644 --- a/asm/rom_800D42C.s +++ b/asm/rom_800D42C.s @@ -14864,7 +14864,7 @@ sub_8014D98: @ 8014D98 strh r1, [r0] ldr r0, _08014DE0 @ =gUnknown_030042A0 strh r1, [r0] - ldr r1, _08014DE4 @ =gUnknown_02038808 + ldr r1, _08014DE4 @ =gNumSafariBalls ldrb r0, [r1] subs r0, 0x1 strb r0, [r1] @@ -14885,7 +14885,7 @@ _08014DD4: .4byte gUnknown_02024A7A _08014DD8: .4byte gUnknown_02024A7E _08014DDC: .4byte gUnknown_030042A4 _08014DE0: .4byte gUnknown_030042A0 -_08014DE4: .4byte gUnknown_02038808 +_08014DE4: .4byte gNumSafariBalls _08014DE8: .4byte gUnknown_02024C04 _08014DEC: .4byte gUnknown_02024C10 _08014DF0: .4byte gUnknown_081D9E48 diff --git a/asm/rom_804373C.s b/asm/rom_804373C.s index 8690ed355..a134237f1 100644 --- a/asm/rom_804373C.s +++ b/asm/rom_804373C.s @@ -4383,7 +4383,7 @@ sub_8045998: @ 8045998 ldr r1, _08045A3C @ =gUnknown_08400DE6 bl StringCopy adds r7, r0, 0 - ldr r0, _08045A40 @ =gUnknown_02038808 + ldr r0, _08045A40 @ =gNumSafariBalls ldrb r1, [r0] adds r0, r7, 0 movs r2, 0xA @@ -4450,7 +4450,7 @@ _08045A06: .align 2, 0 _08045A38: .4byte gUnknown_020238CC _08045A3C: .4byte gUnknown_08400DE6 -_08045A40: .4byte gUnknown_02038808 +_08045A40: .4byte gNumSafariBalls _08045A44: .4byte gUnknown_08400DF0 _08045A48: .4byte gSprites _08045A4C: .4byte 0x02000520 diff --git a/asm/rom_8065394.s b/asm/rom_8065394.s index d439aaf39..fd88d6ece 100644 --- a/asm/rom_8065394.s +++ b/asm/rom_8065394.s @@ -1277,7 +1277,7 @@ _080688B4: .align 2, 0 _080688C8: .4byte Event_EggHatch _080688CC: - bl safari_step + bl SafariZoneTakeStep lsls r0, 24 lsrs r0, 24 cmp r0, 0x1 diff --git a/data/data2.s b/data/data2.s index abc0ff1e3..320dfdf2f 100644 --- a/data/data2.s +++ b/data/data2.s @@ -11192,9 +11192,8 @@ gWildFeebasRoute119Data:: @ 839DBFC .byte 20, 25 @ Min/Max level .2byte SPECIES_FEEBAS -@ Some Feebas tile related data .align 2 -gUnknown_0839DC00:: @ 839DC00 +gRoute119WaterTileData:: @ 839DC00 .2byte 0x0, 0x2D, 0x0 .2byte 0x2E, 0x5B, 0x83 .2byte 0x5C, 0x8B, 0x12A @@ -24244,7 +24243,7 @@ gUnknown_083F7EA8:: @ 83F7EA8 .4byte sub_802E424, c2_exit_to_overworld_2_switch .align 2 -gUnknown_083F7EB8:: @ 83F7EB8 +gPokeblockNames:: @ 83F7EB8 .4byte NULL .4byte ContestStatsText_RedPokeBlock .4byte ContestStatsText_BluePokeBlock diff --git a/data/specials.inc b/data/specials.inc index ead3d5fab..852372ce0 100644 --- a/data/specials.inc +++ b/data/specials.inc @@ -205,9 +205,9 @@ gSpecials:: .4byte sub_80C8080 .4byte SetSSTidalFlag .4byte ResetSSTidalFlag - .4byte sub_80C81B8 - .4byte sub_80C81E4 - .4byte sub_80C82EC + .4byte EnterSafariMode + .4byte ExitSafariMode + .4byte SafariZoneGetPokeblockNameInFeeder .4byte sub_810BAF4 .4byte sub_810D32C .4byte sub_810D378 diff --git a/include/abilities.h b/include/abilities.h new file mode 100644 index 000000000..36a7ab671 --- /dev/null +++ b/include/abilities.h @@ -0,0 +1,86 @@ +#ifndef GUARD_ABILITIES_H +#define GUARD_ABILITIES_H + +enum +{ + ABILITY_NONE, + ABILITY_STENCH, + ABILITY_DRIZZLE, + ABILITY_SPEED_BOOST, + ABILITY_BATTLE_ARMOR, + ABILITY_STURDY, + ABILITY_DAMP, + ABILITY_LIMBER, + ABILITY_SAND_VEIL, + ABILITY_STATIC, + ABILITY_VOLT_ABSORB, + ABILITY_WATER_ABSORB, + ABILITY_OBLIVIOUS, + ABILITY_CLOUD_NINE, + ABILITY_COMPOUND_EYES, + ABILITY_INSOMNIA, + ABILITY_COLOR_CHANGE, + ABILITY_IMMUNITY, + ABILITY_FLASH_FIRE, + ABILITY_SHIELD_DUST, + ABILITY_OWN_TEMPO, + ABILITY_SUCTION_CUPS, + ABILITY_INTIMIDATE, + ABILITY_SHADOW_TAG, + ABILITY_ROUGH_SKIN, + ABILITY_WONDER_GUARD, + ABILITY_LEVITATE, + ABILITY_EFFECT_SPORE, + ABILITY_SYNCHRONIZE, + ABILITY_CLEAR_BODY, + ABILITY_NATURAL_CURE, + ABILITY_LIGHTNING_ROD, + ABILITY_SERENE_GRACE, + ABILITY_SWIFT_SWIM, + ABILITY_CHLOROPHYLL, + ABILITY_ILLUMINATE, + ABILITY_TRACE, + ABILITY_HUGE_POWER, + ABILITY_POISON_POINT, + ABILITY_INNER_FOCUS, + ABILITY_MAGMA_ARMOR, + ABILITY_WATER_VEIL, + ABILITY_MAGNET_PULL, + ABILITY_SOUNDPROOF, + ABILITY_RAIN_DISH, + ABILITY_SAND_STREAM, + ABILITY_PRESSURE, + ABILITY_THICK_FAT, + ABILITY_EARLY_BIRD, + ABILITY_FLAME_BODY, + ABILITY_RUN_AWAY, + ABILITY_KEEN_EYE, + ABILITY_HYPER_CUTTER, + ABILITY_PICKUP, + ABILITY_TRUANT, + ABILITY_HUSTLE, + ABILITY_CUTE_CHARM, + ABILITY_PLUS, + ABILITY_MINUS, + ABILITY_FORECAST, + ABILITY_STICKY_HOLD, + ABILITY_SHED_SKIN, + ABILITY_GUTS, + ABILITY_MARVEL_SCALE, + ABILITY_LIQUID_OOZE, + ABILITY_OVERGROW, + ABILITY_BLAZE, + ABILITY_TORRENT, + ABILITY_SWARM, + ABILITY_ROCK_HEAD, + ABILITY_DROUGHT, + ABILITY_ARENA_TRAP, + ABILITY_VITAL_SPIRIT, + ABILITY_WHITE_SMOKE, + ABILITY_PURE_POWER, + ABILITY_SHELL_ARMOR, + ABILITY_CACOPHONY, + ABILITY_AIR_LOCK +}; + +#endif // GUARD_ABILITIES_H diff --git a/include/var.h b/include/var.h index ada8caf24..c76b8c411 100644 --- a/include/var.h +++ b/include/var.h @@ -1,6 +1,8 @@ #ifndef GUARD_VAR_H #define GUARD_VAR_H +#include "vars.h" + u16 *GetVarPointer(u16 id); u16 VarGet(u16 id); bool8 VarSet(u16 id, u16 value); diff --git a/include/vars.h b/include/vars.h new file mode 100644 index 000000000..db6f097b7 --- /dev/null +++ b/include/vars.h @@ -0,0 +1,6 @@ +#ifndef GUARD_VARS_H +#define GUARD_VARS_H + +#define VAR_REPEL_STEP_COUNT 0x4021 + +#endif // GUARD_VARS_H diff --git a/src/battle_setup.c b/src/battle_setup.c index 869f713ca..15b09645f 100644 --- a/src/battle_setup.c +++ b/src/battle_setup.c @@ -121,15 +121,15 @@ extern struct Pokemon gEnemyParty[]; extern struct Pokemon gPlayerParty[]; extern struct Trainer gTrainers[]; -extern u16 gTrainerBattleMode; -extern u16 gTrainerBattleOpponent; -extern u16 gTrainerMapObjectLocalId; -extern u8 *gTrainerIntroSpeech; -extern u8 *gTrainerDefeatSpeech; -extern u8 *gTrainerVictorySpeech; -extern u8 *gTrainerCannotBattleSpeech; -extern u8 *gTrainerBattleScriptReturnAddress; -extern u8 *gTrainerBattleEndScript; +EWRAM_DATA u16 gTrainerBattleMode = 0; +EWRAM_DATA u16 gTrainerBattleOpponent = 0; +EWRAM_DATA u16 gTrainerMapObjectLocalId = 0; +EWRAM_DATA u8 *gTrainerIntroSpeech = NULL; +EWRAM_DATA u8 *gTrainerDefeatSpeech = NULL; +EWRAM_DATA u8 *gTrainerVictorySpeech = NULL; +EWRAM_DATA u8 *gTrainerCannotBattleSpeech = NULL; +EWRAM_DATA u8 *gTrainerBattleScriptReturnAddress = NULL; +EWRAM_DATA u8 *gTrainerBattleEndScript = NULL; extern struct TrainerEyeTrainer gTrainerEyeTrainers[]; diff --git a/src/safari_zone.c b/src/safari_zone.c index c8e2dd838..600ba95d2 100644 --- a/src/safari_zone.c +++ b/src/safari_zone.c @@ -4,20 +4,19 @@ #include "script.h" #include "string_util.h" -struct UnkSafariZoneStruct +struct PokeblockFeeder { /*0x00*/ s16 x; /*0x02*/ s16 y; /*0x04*/ s8 mapNum; - /*0x05*/ u8 counter; - /*0x06*/ u8 field_4; - /*0x07*/ u8 field_5; + /*0x05*/ u8 stepCounter; /*0x08*/ struct Pokeblock pokeblock; }; +#define NUM_POKEBLOCK_FEEDERS 10 -void ClearEveryUnkSafariZoneStruct(void); -void sub_80C8508(void); +void ClearAllPokeblockFeeders(void); +void DecrementFeederStepCounters(void); extern void c2_exit_to_overworld_2_switch(void); extern void c2_exit_to_overworld_1_continue_scripts_restart_music(void); extern void sub_8080E44(void); @@ -28,10 +27,10 @@ extern void GetXYCoordsOneStepInFrontOfPlayer(void *, void *); extern void PlayerGetDestCoords(u16 *, u16 *); extern u8 gUnknown_02024D26; -extern u8 gUnknown_02038808; -extern u16 gUnknown_0203880A; -extern struct UnkSafariZoneStruct gUnkSafariZoneStructArr[10]; +EWRAM_DATA u8 gNumSafariBalls = 0; +EWRAM_DATA static u16 gSafariZoneStepCounter = 0; +EWRAM_DATA static struct PokeblockFeeder gPokeblockFeeders[NUM_POKEBLOCK_FEEDERS] = {0}; extern void (*gUnknown_0300485C)(void); @@ -39,15 +38,13 @@ extern u8 gUnknown_081C340A; extern u8 gUnknown_081C342D; extern u8 gUnknown_081C3448; extern u8 gUnknown_081C3459; -extern u8 *gUnknown_083F7EB8[]; +extern u8 *gPokeblockNames[]; extern u16 gScriptResult; bool32 GetSafariZoneFlag(void) { - bool8 ret = FlagGet(SYS_SAFARI_MODE); - - return ret; + return FlagGet(SYS_SAFARI_MODE); } void SetSafariZoneFlag(void) @@ -60,51 +57,48 @@ void ResetSafariZoneFlag(void) FlagReset(SYS_SAFARI_MODE); } -void sub_80C81B8(void) +void EnterSafariMode(void) { sav12_xor_increment(0x11); SetSafariZoneFlag(); - ClearEveryUnkSafariZoneStruct(); - - gUnknown_02038808 = 0x1E; - gUnknown_0203880A = 0x1F4; + ClearAllPokeblockFeeders(); + gNumSafariBalls = 30; + gSafariZoneStepCounter = 500; } -void sub_80C81E4(void) +void ExitSafariMode(void) { ResetSafariZoneFlag(); - ClearEveryUnkSafariZoneStruct(); - - gUnknown_02038808 = 0; - gUnknown_0203880A = 0; + ClearAllPokeblockFeeders(); + gNumSafariBalls = 0; + gSafariZoneStepCounter = 0; } -bool8 safari_step(void) +bool8 SafariZoneTakeStep(void) { if (GetSafariZoneFlag() == FALSE) { return FALSE; } - sub_80C8508(); - - if (!(--gUnknown_0203880A)) + DecrementFeederStepCounters(); + gSafariZoneStepCounter--; + if (gSafariZoneStepCounter == 0) { ScriptContext1_SetupScript(&gUnknown_081C3448); return TRUE; } - return FALSE; } -void sub_80C823C(void) +void SafariZoneRetirePrompt(void) { ScriptContext1_SetupScript(&gUnknown_081C342D); } void sub_80C824C(void) { - if (gUnknown_02038808 != 0) + if (gNumSafariBalls != 0) { SetMainCallback2(c2_exit_to_overworld_2_switch); } @@ -123,42 +117,31 @@ void sub_80C824C(void) } } -void ClearSingleUnkSafariZoneStruct(u8 index) +static void ClearPokeblockFeeder(u8 index) { - memset(&gUnkSafariZoneStructArr[index], 0, - sizeof(struct UnkSafariZoneStruct)); + memset(&gPokeblockFeeders[index], 0, sizeof(struct PokeblockFeeder)); } -void ClearEveryUnkSafariZoneStruct(void) +static void ClearAllPokeblockFeeders(void) { - // 10 is the number of struct UnkSafariZoneStruct's in - // gUnkSafariZoneStructArr. It might be a good idea to create a #define - // for it. - memset(gUnkSafariZoneStructArr, 0, sizeof(struct UnkSafariZoneStruct) - * 10); + memset(gPokeblockFeeders, 0, sizeof(gPokeblockFeeders)); } -void sub_80C82EC(void) +void SafariZoneGetPokeblockNameInFeeder(void) { s16 x, y; u16 i; GetXYCoordsOneStepInFrontOfPlayer(&x, &y); - // 10 is the number of struct UnkSafariZoneStruct's in - // gUnkSafariZoneStructArr. It might be a good idea to create a #define - // for it. - for (i = 0; i < 10; i++) + for (i = 0; i < NUM_POKEBLOCK_FEEDERS; i++) { - if (gSaveBlock1.location.mapNum == gUnkSafariZoneStructArr[i].mapNum - && gUnkSafariZoneStructArr[i].x == x - && gUnkSafariZoneStructArr[i].y == y) + if (gSaveBlock1.location.mapNum == gPokeblockFeeders[i].mapNum + && gPokeblockFeeders[i].x == x + && gPokeblockFeeders[i].y == y) { gScriptResult = i; - - StringCopy(gStringVar1, gUnknown_083F7EB8 - [gUnkSafariZoneStructArr[i].pokeblock.color]); - + StringCopy(gStringVar1, gPokeblockNames[gPokeblockFeeders[i].pokeblock.color]); return; } } @@ -166,33 +149,24 @@ void sub_80C82EC(void) gScriptResult = -1; } -void sub_80C837C(void) +static void GetPokeblockFeederWithinRange(void) { s16 x, y; u16 i; PlayerGetDestCoords(&x, &y); - // 10 is the number of struct UnkSafariZoneStruct's in - // gUnkSafariZoneStructArr. It might be a good idea to create a #define - // for it. - for (i = 0; i < 10; i++) + for (i = 0; i < NUM_POKEBLOCK_FEEDERS; i++) { - if (gSaveBlock1.location.mapNum - == gUnkSafariZoneStructArr[i].mapNum) + if (gSaveBlock1.location.mapNum == gPokeblockFeeders[i].mapNum) { - x -= gUnkSafariZoneStructArr[i].x; - y -= gUnkSafariZoneStructArr[i].y; - + //Get absolute value of x and y distance from Pokeblock feeder on current map + x -= gPokeblockFeeders[i].x; + y -= gPokeblockFeeders[i].y; if (x < 0) - { x *= -1; - } if (y < 0) - { y *= -1; - } - if ((x + y) <= 5) { gScriptResult = i; @@ -206,84 +180,68 @@ void sub_80C837C(void) struct Pokeblock *unref_sub_80C8418(void) { - sub_80C82EC(); + SafariZoneGetPokeblockNameInFeeder(); if (gScriptResult == 0xFFFF) - { return NULL; - } - - return &gUnkSafariZoneStructArr[gScriptResult].pokeblock; + else + return &gPokeblockFeeders[gScriptResult].pokeblock; } -struct Pokeblock *sub_80C8448(void) +struct Pokeblock *SafariZoneGetActivePokeblock(void) { - sub_80C837C(); + GetPokeblockFeederWithinRange(); if (gScriptResult == 0xFFFF) - { return NULL; - } - - return &gUnkSafariZoneStructArr[gScriptResult].pokeblock; + else + return &gPokeblockFeeders[gScriptResult].pokeblock; } -void sub_80C8478(u8 pokeblock_index) +void SafariZoneActivatePokeblockFeeder(u8 pokeblock_index) { s16 x, y; u8 i; - // 10 is the number of struct UnkSafariZoneStruct's in - // gUnkSafariZoneStructArr. It might be a good idea to create a #define - // for it. - for (i = 0; i < 10; i++) + for (i = 0; i < NUM_POKEBLOCK_FEEDERS; i++) { - if (gUnkSafariZoneStructArr[i].mapNum == 0 - && gUnkSafariZoneStructArr[i].x == 0 - && gUnkSafariZoneStructArr[i].y == 0) + //Find free entry in gPokeblockFeeders + if (gPokeblockFeeders[i].mapNum == 0 + && gPokeblockFeeders[i].x == 0 + && gPokeblockFeeders[i].y == 0) { + //Initialize Pokeblock feeder GetXYCoordsOneStepInFrontOfPlayer(&x, &y); - - gUnkSafariZoneStructArr[i].mapNum - = gSaveBlock1.location.mapNum; - - gUnkSafariZoneStructArr[i].pokeblock - = gSaveBlock1.pokeblocks[pokeblock_index]; - - gUnkSafariZoneStructArr[i].counter = 0x64; - gUnkSafariZoneStructArr[i].x = x; - gUnkSafariZoneStructArr[i].y = y; + gPokeblockFeeders[i].mapNum = gSaveBlock1.location.mapNum; + gPokeblockFeeders[i].pokeblock = gSaveBlock1.pokeblocks[pokeblock_index]; + gPokeblockFeeders[i].stepCounter = 100; + gPokeblockFeeders[i].x = x; + gPokeblockFeeders[i].y = y; break; } } } -void sub_80C8508(void) +static void DecrementFeederStepCounters(void) { u8 i; - // 10 is the number of struct UnkSafariZoneStruct's in - // gUnkSafariZoneStructArr. It might be a good idea to create a #define - // for it. - for (i = 0; i < 10; i++) + for (i = 0; i < NUM_POKEBLOCK_FEEDERS; i++) { - if (gUnkSafariZoneStructArr[i].counter != 0) + if (gPokeblockFeeders[i].stepCounter != 0) { - gUnkSafariZoneStructArr[i].counter--; - - if (gUnkSafariZoneStructArr[i].counter == 0) - { - ClearSingleUnkSafariZoneStruct(i); - } + gPokeblockFeeders[i].stepCounter--; + if (gPokeblockFeeders[i].stepCounter == 0) + ClearPokeblockFeeder(i); } } } bool8 unref_sub_80C853C(void) { - sub_80C82EC(); + SafariZoneGetPokeblockNameInFeeder(); if (gScriptResult == 0xFFFF) { @@ -291,7 +249,7 @@ bool8 unref_sub_80C853C(void) } ConvertIntToDecimalStringN(gStringVar2, - gUnkSafariZoneStructArr[gScriptResult].counter, + gPokeblockFeeders[gScriptResult].stepCounter, STR_CONV_MODE_LEADING_ZEROS, 3); return TRUE; diff --git a/src/start_menu.c b/src/start_menu.c index 429589a22..c8e77af66 100644 --- a/src/start_menu.c +++ b/src/start_menu.c @@ -26,7 +26,7 @@ extern void save_serialize_map(void); extern void PlayRainSoundEffect(void); extern void sub_8093130(u8, void (*)(void)); extern void sub_805469C(void); -extern void sub_80C823C(void); +extern void SafariZoneRetirePrompt(void); extern void CB2_InitOptionMenu(void); extern void sub_8093110(void (*)(void)); extern void sub_80EBA5C(void); @@ -72,7 +72,7 @@ extern u16 gScriptResult; extern u8 (*gCallback_03004AE8)(void); extern u8 gUnknown_03004860; extern struct MenuItem gStartMenuItems[]; -extern u8 gUnknown_02038808; +extern u8 gNumSafariBalls; EWRAM_DATA static u8 sStartMenuCursorPos = 0; EWRAM_DATA static u8 sNumStartMenuActions = 0; @@ -208,7 +208,7 @@ static void BuildStartMenuActions_Link(void) //Show number of safari balls left static void DisplaySafariBallsWindow(void) { - sub_8072C44(gStringVar1, gUnknown_02038808, 12, 1); + sub_8072C44(gStringVar1, gNumSafariBalls, 12, 1); MenuDrawTextWindow(0, 0, 10, 5); MenuPrint(gOtherText_SafariStock, 1, 1); } @@ -456,7 +456,7 @@ u8 StartMenu_ExitCallback(void) u8 StartMenu_RetireCallback(void) { sub_8071C20(); - sub_80C823C(); + SafariZoneRetirePrompt(); return 1; } @@ -473,7 +473,8 @@ u8 StartMenu_PlayerLinkCallback(void) } //Save dialog status -enum { +enum +{ SAVE_IN_PROGRESS, SAVE_SUCCESS, SAVE_CANCELED, diff --git a/src/wild_encounter.c b/src/wild_encounter.c index 8c7cfe80c..151088cd6 100644 --- a/src/wild_encounter.c +++ b/src/wild_encounter.c @@ -1,4 +1,5 @@ #include "global.h" +#include "abilities.h" #include "fieldmap.h" #include "pokemon.h" #include "rng.h" @@ -6,18 +7,21 @@ #include "flag.h" #include "var.h" -struct WildPokemon { +struct WildPokemon +{ u8 minLevel; u8 maxLevel; u16 species; }; -struct WildPokemonInfo { +struct WildPokemonInfo +{ u8 encounterRate; struct WildPokemon *wildPokemon; }; -struct WildPokemonHeader { +struct WildPokemonHeader +{ u8 mapGroup; u8 mapNum; struct WildPokemonInfo *landMonsInfo; @@ -28,8 +32,7 @@ struct WildPokemonHeader { extern bool8 sub_805759C(u8); extern void GetXYCoordsOneStepInFrontOfPlayer(void *, void *); -extern u32 sub_80C8448(void); -extern s16 sub_810CAE4(u8, u32); +extern s16 sub_810CAE4(u8, struct Pokeblock *); extern bool32 GetSafariZoneFlag(void); extern u8 TestPlayerAvatarFlags(u8); extern u8 MetatileBehavior_IsLandWildEncounter(u8); @@ -41,11 +44,9 @@ extern void PlayerGetDestCoords(u16 *x, u16 *y); extern void sub_80BEA50(u16); extern void sav12_xor_increment(u8); extern int MapGridGetMetatileBehaviorAt(int x, int y); +extern struct Pokeblock *SafariZoneGetActivePokeblock(void); -extern u8 gWildEncountersDisabled; -extern u16 gUnknown_0839DC00[]; -//extern u16 gUnknown_0839DC00[3][3]; -extern u32 gUnknown_0202FF80; //Feebas rng value +extern u16 gRoute119WaterTileData[]; extern struct WildPokemonHeader gWildMonHeaders[]; extern struct Pokemon gEnemyParty[6]; extern struct Pokemon gPlayerParty[6]; @@ -53,220 +54,199 @@ extern u16 gScriptResult; extern struct WildPokemon gWildFeebasRoute119Data; extern u8 Event_RepelWoreOff[]; +EWRAM_DATA static u8 sWildEncountersDisabled = 0; +EWRAM_DATA static u32 sFeebasRngValue = 0; + #define NUM_FEEBAS_SPOTS 6 -u16 sub_8084984(s16 x, s16 y, u8 c); -bool8 CheckFeebas(void); -u16 FeebasRandom(void); -void FeebasSeedRng(u16 seed); -u8 PickWildMon_Grass(void); -u8 PickWildMon_Water(void); -u8 PickWildMon_Fishing(u8 rod); -u8 RandomInRange(struct WildPokemon *wildPokemon); -u16 GetCurrentMapWildMonHeader(void); -u8 PickWildMonNature(void); -void CreateWildMon(u16 species, u8 b); -bool8 GenerateWildMon(struct WildPokemonInfo *a, u8 b, u8 c); -u16 GenerateFishingWildMon(struct WildPokemonInfo *a, u8 rod); -bool8 SetUpMassOutbreakEncounter(u8 a); -bool8 DoMassOutbreakEncounterTest(void); -bool8 DoWildEncounterRateDiceRoll(u16 a); -bool8 DoWildEncounterTest(u32 a, u8 b); -bool8 DoGlobalWildEncounterDiceRoll(void); -bool8 StandardWildEncounter(u16 a, u16 b); -void RockSmashWildEncounter(void); -u8 SweetScentWildEncounter(void); -u8 GetFishingWildMonListHeader(void); -void FishingWildEncounter(u8 rod); -u16 GetLocalWildMon(u8 *a1); -u16 GetMirageIslandMon(void); -bool8 UpdateRepelCounter(void); -bool8 RepelCheck(bool8 level); -void ApplyFluteEncounterRateMod(u32 *a1); -void ApplyCleanseTagEncounterRateMod(u32 *a1); - - -void DisableWildEncounters(bool8 disable) -{ - gWildEncountersDisabled = disable; -} +static u16 FeebasRandom(void); +static void FeebasSeedRng(u16 seed); + +static bool8 RepelCheck(u8 level); +static void ApplyFluteEncounterRateMod(u32 *encRate); +static void ApplyCleanseTagEncounterRateMod(u32 *encRate); -u16 sub_8084984(s16 x, s16 y, u8 c) +void DisableWildEncounters(bool8 disabled) { - //odd, but needed to match - u16 *arr = gUnknown_0839DC00; - u16 *ptr = &arr[c * 3]; - u16 r9 = gUnknown_0839DC00[c * 3 + 1]; - u16 r6 = gUnknown_0839DC00[c * 3 + 2]; - u16 r5 = *ptr; + sWildEncountersDisabled = disabled; +} - while(r5 <= r9) +static u16 GetRoute119WaterTileNum(s16 x, s16 y, u8 section) +{ + u16 xCur; + u16 yCur; + u16 yMin = gRoute119WaterTileData[section * 3 + 0]; + u16 yMax = gRoute119WaterTileData[section * 3 + 1]; + u16 tileNum = gRoute119WaterTileData[section * 3 + 2]; + + for (yCur = yMin; yCur <= yMax; yCur++) { - u16 i; - - for(i = 0; i < gMapHeader.mapData->width; i++) + for (xCur = 0; xCur < gMapHeader.mapData->width; xCur++) { - if(sub_805759C(MapGridGetMetatileBehaviorAt(i + 7, r5 + 7)) == TRUE) + if (sub_805759C(MapGridGetMetatileBehaviorAt(xCur + 7, yCur + 7)) == TRUE) { - r6++; - if(x == i && y == r5) - return r6; + tileNum++; + if (x == xCur && y == yCur) + return tileNum; } - //_08084A14 } - r5++; } - - return r6 + 1; + return tileNum + 1; } -bool8 CheckFeebas(void) +static bool8 CheckFeebas(void) { + u8 i; u16 feebasSpots[6]; s16 x; s16 y; - u8 r7 = 0; - u8 i; - u16 foo; + u8 route119section = 0; + u16 waterTileNum; - if(gSaveBlock1.location.mapGroup == 0 && gSaveBlock1.location.mapNum == 0x22) + if (gSaveBlock1.location.mapGroup == 0 && gSaveBlock1.location.mapNum == 0x22) { GetXYCoordsOneStepInFrontOfPlayer(&x, &y); x -= 7; y -= 7; - - // *sigh* whatever gets the code to match! + +#ifdef NONMATCHING + if (y >= gRoute119WaterTileData[3 * 1 + 0] && y <= gRoute119WaterTileData[3 * 1 + 1]) + route119section = 1; + if (y >= gRoute119WaterTileData[3 * 2 + 0] && y <= gRoute119WaterTileData[3 * 2 + 1]) + route119section = 2; +#else { - register u16 *arr asm("r0"); - if(y >= (arr = gUnknown_0839DC00)[3 * 1 + 0] && y <= arr[3 * 1 + 1]) - r7 = 1; - if(y >= arr[3 * 2 + 0] && y <= arr[3 * 2 + 1]) - r7 = 2; + register u16 *arr asm("r0"); + if (y >= (arr = gRoute119WaterTileData)[3 * 1 + 0] && y <= arr[3 * 1 + 1]) + route119section = 1; + if (y >= arr[3 * 2 + 0] && y <= arr[3 * 2 + 1]) + route119section = 2; } - //_08084A8E - - if(Random() % 100 > 49) //Why not just do (Random() & 1) to get a 50% chance? +#endif + + if (Random() % 100 > 49) //50% chance of encountering Feebas return FALSE; - //_08084AC8 FeebasSeedRng(gSaveBlock1.easyChatPairs[0].unk2); - for(i = 0; i != NUM_FEEBAS_SPOTS;) + for (i = 0; i != NUM_FEEBAS_SPOTS;) { feebasSpots[i] = FeebasRandom() % 447; - if(feebasSpots[i] == 0) + if (feebasSpots[i] == 0) feebasSpots[i] = 447; - if(feebasSpots[i] < 1 || feebasSpots[i] >= 4) + if (feebasSpots[i] < 1 || feebasSpots[i] >= 4) i++; } - foo = sub_8084984(x, y, r7); - for(i = 0; i < NUM_FEEBAS_SPOTS; i++) + waterTileNum = GetRoute119WaterTileNum(x, y, route119section); + for (i = 0; i < NUM_FEEBAS_SPOTS; i++) { - if(foo == feebasSpots[i]) + if (waterTileNum == feebasSpots[i]) return TRUE; } } - //_08084B38 return FALSE; } -u16 FeebasRandom(void) +static u16 FeebasRandom(void) { - gUnknown_0202FF80 = 12345 + 0x41C64E6D * gUnknown_0202FF80; - return gUnknown_0202FF80 >> 16; + sFeebasRngValue = 12345 + 0x41C64E6D * sFeebasRngValue; + return sFeebasRngValue >> 16; } -void FeebasSeedRng(u16 seed) +static void FeebasSeedRng(u16 seed) { - gUnknown_0202FF80 = seed; + sFeebasRngValue = seed; } -u8 PickWildMon_Grass(void) +static u8 ChooseWildMonIndex_Land(void) { - u8 val = Random() % 100; + u8 rand = Random() % 100; - if(val < 20) + if (rand < 20) //20% chance return 0; - if(val >= 20 && val < 40) + if (rand >= 20 && rand < 40) //20% chance return 1; - if(val >= 40 && val < 50) + if (rand >= 40 && rand < 50) //10% chance return 2; - if(val >= 50 && val < 60) + if (rand >= 50 && rand < 60) //10% chance return 3; - if(val >= 60 && val < 70) + if (rand >= 60 && rand < 70) //10% chance return 4; - if(val >= 70 && val < 80) + if (rand >= 70 && rand < 80) //10% chance return 5; - if(val >= 80 && val < 85) + if (rand >= 80 && rand < 85) //5% chance return 6; - if(val >= 85 && val < 90) + if (rand >= 85 && rand < 90) //5% chance return 7; - if(val >= 90 && val < 94) + if (rand >= 90 && rand < 94) //4% chance return 8; - if(val >= 94 && val < 98) + if (rand >= 94 && rand < 98) //4% chance return 9; - if(val == 98) + if (rand == 98) //1% chance return 10; - else + else //1% chance return 11; } -u8 PickWildMon_Water(void) +static u8 ChooseWildMonIndex_Water(void) { - u8 val = Random() % 100; + u8 rand = Random() % 100; - if(val < 60) + if (rand < 60) //60% chance return 0; - if(val >= 60 && val < 90) + if (rand >= 60 && rand < 90) //30% chance return 1; - if(val >= 90 && val < 95) + if (rand >= 90 && rand < 95) //5% chance return 2; - if(val >= 95 && val < 99) - return 3; - else + if (rand >= 95 && rand < 99) //4% chance + return 3; + else //1% chance return 4; } -u8 PickWildMon_Fishing(u8 rod) +enum { - u32 r5 = 0; - u8 val = Random() % 100; + OLD_ROD, + GOOD_ROD, + SUPER_ROD +}; - switch(rod) +static u8 ChooseWildMonIndex_Fishing(u8 rod) +{ + u8 wildMonIndex = 0; + u8 rand = Random() % 100; + + switch (rod) { - case 0: //old rod? - if(val < 70) - r5 = 0; - else - r5 = 1; - return r5; - case 1: //good rod? - if(val < 60) - r5 = 2; - if(val >= 60 && val < 80) - r5 = 3; - if(val >= 80 && val < 100) - r5 = 4; - return r5; - case 2: //super rod? - if(val < 40) - r5 = 5; - if(val >= 40 && val < 80) - r5 = 6; - if(val >= 80 && val < 95) - r5 = 7; - if(val >= 95 && val < 99) - r5 = 8; - if(val == 99) - r5 = 9; - return r5; - default: - return r5; + case OLD_ROD: + if (rand < 70) //70% chance + wildMonIndex = 0; + else //30% chance + wildMonIndex = 1; + break; + case GOOD_ROD: + if (rand < 60) //60% chance + wildMonIndex = 2; + if (rand >= 60 && rand < 80) //20% chance + wildMonIndex = 3; + if (rand >= 80 && rand < 100) //20% chance + wildMonIndex = 4; + break; + case SUPER_ROD: + if (rand < 40) //40% chance + wildMonIndex = 5; + if (rand >= 40 && rand < 80) //40% chance + wildMonIndex = 6; + if (rand >= 80 && rand < 95) //15% chance + wildMonIndex = 7; + if (rand >= 95 && rand < 99) //4% chance + wildMonIndex = 8; + if (rand == 99) //1% chance + wildMonIndex = 9; + break; } - - return r5; + return wildMonIndex; } -//Chooses level of wild Pokemon -u8 RandomInRange(struct WildPokemon *wildPokemon) +static u8 ChooseWildMonLevel(struct WildPokemon *wildPokemon) { u8 min; u8 max; @@ -274,7 +254,7 @@ u8 RandomInRange(struct WildPokemon *wildPokemon) u8 rand; //Make sure minimum level is less than maximum level - if(wildPokemon->maxLevel >= wildPokemon->minLevel) + if (wildPokemon->maxLevel >= wildPokemon->minLevel) { min = wildPokemon->minLevel; max = wildPokemon->maxLevel; @@ -289,180 +269,160 @@ u8 RandomInRange(struct WildPokemon *wildPokemon) return min + rand; } -u16 GetCurrentMapWildMonHeader(void) +static u16 GetCurrentMapWildMonHeader(void) { u16 i; - for(i = 0; gWildMonHeaders[i].mapGroup != 0xFF; i++) + for (i = 0; gWildMonHeaders[i].mapGroup != 0xFF; i++) { - if(gWildMonHeaders[i].mapGroup == gSaveBlock1.location.mapGroup && + if (gWildMonHeaders[i].mapGroup == gSaveBlock1.location.mapGroup && gWildMonHeaders[i].mapNum == gSaveBlock1.location.mapNum) return i; } return -1; } -u8 PickWildMonNature(void) +static u8 PickWildMonNature(void) { - u16 foo; - u32 r7; - u8 arr[25]; + u8 i; + u8 j; + struct Pokeblock *safariPokeblock; + u8 natures[25]; - if(GetSafariZoneFlag() == TRUE && Random() % 100 < 80) + if (GetSafariZoneFlag() == TRUE && Random() % 100 < 80) { - r7 = sub_80C8448(); - - if(r7) + safariPokeblock = SafariZoneGetActivePokeblock(); + if (safariPokeblock != NULL) { - u8 i; - - for(i = 0; i < 25; i++) - arr[i] = i; - //_08084E04 - for(i = 0; i < 24; i++) + for (i = 0; i < 25; i++) + natures[i] = i; + for (i = 0; i < 24; i++) { - u8 j; - - for(j = i + 1; j < 25; j++) + for (j = i + 1; j < 25; j++) { - if(Random() & 1) + if (Random() & 1) { - u8 temp = arr[i]; + u8 temp = natures[i]; - arr[i] = arr[j]; - arr[j] = temp; + natures[i] = natures[j]; + natures[j] = temp; } } } - //_08084E3E - for(i = 0; i < 25; i++) + for (i = 0; i < 25; i++) { - if(sub_810CAE4(arr[i], r7) > 0) - return arr[i]; + if (sub_810CAE4(natures[i], safariPokeblock) > 0) + return natures[i]; } } } - //_08084E5E return Random() % 25; } -void CreateWildMon(u16 species, u8 b) +static void CreateWildMon(u16 species, u8 b) { ZeroEnemyPartyMons(); CreateMonWithNature(&gEnemyParty[0], species, b, 0x20, PickWildMonNature()); } -bool8 GenerateWildMon(struct WildPokemonInfo *a, u8 b, u8 c) +static bool8 GenerateWildMon(struct WildPokemonInfo *wildMonInfo, u8 area, bool8 checkRepel) { - u8 mon = 0; + u8 wildMonIndex = 0; u8 level; - switch(b) - { - case 0: - mon = PickWildMon_Grass(); - break; - case 1: - mon = PickWildMon_Water(); - break; - case 2: - mon = PickWildMon_Water(); - break; - default: - break; - } - - level = RandomInRange(&a->wildPokemon[mon]); - if(c == 1 && RepelCheck(level) == 0) + switch (area) { - return 0; + case 0: + wildMonIndex = ChooseWildMonIndex_Land(); + break; + case 1: + wildMonIndex = ChooseWildMonIndex_Water(); + break; + case 2: + wildMonIndex = ChooseWildMonIndex_Water(); + break; } + level = ChooseWildMonLevel(&wildMonInfo->wildPokemon[wildMonIndex]); + if (checkRepel == TRUE && RepelCheck(level) == FALSE) + return FALSE; else { - CreateWildMon(a->wildPokemon[mon].species, level); - return 1; + CreateWildMon(wildMonInfo->wildPokemon[wildMonIndex].species, level); + return TRUE; } } -u16 GenerateFishingWildMon(struct WildPokemonInfo *a, u8 rod) +static u16 GenerateFishingWildMon(struct WildPokemonInfo *wildMonInfo, u8 rod) { - u8 mon = PickWildMon_Fishing(rod); - u8 level = RandomInRange(&a->wildPokemon[mon]); + u8 wildMonIndex = ChooseWildMonIndex_Fishing(rod); + u8 level = ChooseWildMonLevel(&wildMonInfo->wildPokemon[wildMonIndex]); - CreateWildMon(a->wildPokemon[mon].species, level); - return a->wildPokemon[mon].species; + CreateWildMon(wildMonInfo->wildPokemon[wildMonIndex].species, level); + return wildMonInfo->wildPokemon[wildMonIndex].species; } -bool8 SetUpMassOutbreakEncounter(u8 a) +static bool8 SetUpMassOutbreakEncounter(bool8 checkRepel) { u16 i; - if(a == 1 && RepelCheck(gSaveBlock1.outbreakPokemonLevel) == 0) - { - return 0; - } - //_08084F78 - CreateWildMon(gSaveBlock1.outbreakPokemonSpecies, gSaveBlock1.outbreakPokemonLevel); - for(i = 0; i < 4; i++) + if (checkRepel == TRUE && RepelCheck(gSaveBlock1.outbreakPokemonLevel) == 0) + return FALSE; + else { - SetMonMoveSlot(&gEnemyParty[0], gSaveBlock1.outbreakPokemonMoves[i], i); + CreateWildMon(gSaveBlock1.outbreakPokemonSpecies, gSaveBlock1.outbreakPokemonLevel); + for (i = 0; i < 4; i++) + SetMonMoveSlot(&gEnemyParty[0], gSaveBlock1.outbreakPokemonMoves[i], i); + return TRUE; } - return 1; } -bool8 DoMassOutbreakEncounterTest(void) +static bool8 DoMassOutbreakEncounterTest(void) { - if(gSaveBlock1.outbreakPokemonSpecies && - gSaveBlock1.location.mapNum == gSaveBlock1.outbreakLocationMapNum && - gSaveBlock1.location.mapGroup == gSaveBlock1.outbreakLocationMapGroup) + if (gSaveBlock1.outbreakPokemonSpecies != 0 + && gSaveBlock1.location.mapNum == gSaveBlock1.outbreakLocationMapNum + && gSaveBlock1.location.mapGroup == gSaveBlock1.outbreakLocationMapGroup) { - if(Random() % 100 < gSaveBlock1.outbreakPokemonProbability) - return 1; + if (Random() % 100 < gSaveBlock1.outbreakPokemonProbability) + return TRUE; } - return 0; + return FALSE; } -bool8 DoWildEncounterRateDiceRoll(u16 a) +static bool8 DoWildEncounterRateDiceRoll(u16 encounterRate) { - if(Random() % 2880 < a) + if (Random() % 2880 < encounterRate) return TRUE; else return FALSE; } -bool8 DoWildEncounterTest(u32 encounterRate, u8 b) +static bool8 DoWildEncounterTest(u32 encounterRate, bool8 ignoreAbility) { encounterRate *= 16; - - if(TestPlayerAvatarFlags(6)) - { + if (TestPlayerAvatarFlags(6)) encounterRate = encounterRate * 80 / 100; - } - //_0808507E ApplyFluteEncounterRateMod(&encounterRate); ApplyCleanseTagEncounterRateMod(&encounterRate); - - if(b == 0) + if (!ignoreAbility) { // UB: Too few arguments for function 'GetMonData' - if(!GetMonData(&gPlayerParty[0], MON_DATA_SANITY_BIT3)) + if (!GetMonData(&gPlayerParty[0], MON_DATA_SANITY_BIT3)) { u32 ability = GetMonAbility(&gPlayerParty[0]); - if(ability == 1) + if (ability == ABILITY_STENCH) encounterRate /= 2; - if(ability == 0x23) + if (ability == ABILITY_ILLUMINATE) encounterRate *= 2; } } - //_080850BA - if(encounterRate > 2880) + if (encounterRate > 2880) encounterRate = 2880; return DoWildEncounterRateDiceRoll(encounterRate); } -bool8 DoGlobalWildEncounterDiceRoll(void) +static bool8 DoGlobalWildEncounterDiceRoll(void) { - if(Random() % 100 >= 60) + if (Random() % 100 >= 60) return FALSE; else return TRUE; @@ -470,28 +430,29 @@ bool8 DoGlobalWildEncounterDiceRoll(void) bool8 StandardWildEncounter(u16 a, u16 b) { - u16 unk; + u16 headerNum; struct Roamer *roamer; - if(gWildEncountersDisabled != TRUE) + if (sWildEncountersDisabled == TRUE) + return 0; + else { - unk = GetCurrentMapWildMonHeader(); - - if(unk != 0xFFFF) + headerNum = GetCurrentMapWildMonHeader(); + if (headerNum != 0xFFFF) { - if(MetatileBehavior_IsLandWildEncounter(a) == 1) + if (MetatileBehavior_IsLandWildEncounter(a) == TRUE) { - if(gWildMonHeaders[unk].landMonsInfo) + if (gWildMonHeaders[headerNum].landMonsInfo) { - if(b != a && !DoGlobalWildEncounterDiceRoll()) + if (b != a && !DoGlobalWildEncounterDiceRoll()) return 0; - if(DoWildEncounterTest(gWildMonHeaders[unk].landMonsInfo->encounterRate, 0) == TRUE) + if (DoWildEncounterTest(gWildMonHeaders[headerNum].landMonsInfo->encounterRate, 0) == TRUE) { - if(sub_81344CC() == TRUE) + if (sub_81344CC() == TRUE) { roamer = &gSaveBlock1.roamer; - if(RepelCheck(roamer->level)) + if (RepelCheck(roamer->level)) { sub_8081A5C(); return 1; @@ -499,12 +460,12 @@ bool8 StandardWildEncounter(u16 a, u16 b) } else { - if(DoMassOutbreakEncounterTest() == TRUE && SetUpMassOutbreakEncounter(1) == TRUE) + if (DoMassOutbreakEncounterTest() == TRUE && SetUpMassOutbreakEncounter(1) == TRUE) { CheckForSafariZoneAndProceed(); return 1; } - if (GenerateWildMon(gWildMonHeaders[unk].landMonsInfo, 0, 1) == 1) + if (GenerateWildMon(gWildMonHeaders[headerNum].landMonsInfo, 0, TRUE) == TRUE) { goto label; } @@ -512,37 +473,34 @@ bool8 StandardWildEncounter(u16 a, u16 b) } } } - else + else if (MetatileBehavior_IsWaterWildEncounter(a) == TRUE + || (TestPlayerAvatarFlags(8) && MetatileBehavior_IsBridge(a) == TRUE)) { - //_080851D8 - if(MetatileBehavior_IsWaterWildEncounter(a) == TRUE || TestPlayerAvatarFlags(8) && MetatileBehavior_IsBridge(a) == TRUE) + if (gWildMonHeaders[headerNum].waterMonsInfo) { - if(gWildMonHeaders[unk].waterMonsInfo) - { - if(b != a && !DoGlobalWildEncounterDiceRoll()) - return 0; + if (b != a && !DoGlobalWildEncounterDiceRoll()) + return 0; - if(DoWildEncounterTest(gWildMonHeaders[unk].waterMonsInfo->encounterRate, 0) == TRUE) + if (DoWildEncounterTest(gWildMonHeaders[headerNum].waterMonsInfo->encounterRate, 0) == TRUE) + { + if (sub_81344CC() == TRUE) { - if(sub_81344CC() == TRUE) + roamer = &gSaveBlock1.roamer; + if (RepelCheck(roamer->level)) { - roamer = &gSaveBlock1.roamer; - if(RepelCheck(roamer->level)) - { - sub_8081A5C(); - return 1; - } + sub_8081A5C(); + return 1; } - else + } + else + { + //_08085268 + if (GenerateWildMon(gWildMonHeaders[headerNum].waterMonsInfo, 1, TRUE) == TRUE) { - //_08085268 - if(GenerateWildMon(gWildMonHeaders[unk].waterMonsInfo, 1, 1) == 1) - { - label: - //_0808527A - CheckForSafariZoneAndProceed(); - return 1; - } + label: + //_0808527A + CheckForSafariZoneAndProceed(); + return 1; } } } @@ -557,17 +515,17 @@ void RockSmashWildEncounter(void) { u16 headerNum = GetCurrentMapWildMonHeader(); - if(headerNum != 0xFFFF) + if (headerNum != 0xFFFF) { struct WildPokemonInfo *wildPokemonInfo = gWildMonHeaders[headerNum].rockSmashMonsInfo; - if(wildPokemonInfo == NULL) + if (wildPokemonInfo == NULL) { gScriptResult = 0; return; } - else if(DoWildEncounterTest(wildPokemonInfo->encounterRate, 1) == TRUE && - GenerateWildMon(wildPokemonInfo, 2, 1) == 1) + else if (DoWildEncounterTest(wildPokemonInfo->encounterRate, 1) == TRUE + && GenerateWildMon(wildPokemonInfo, 2, TRUE) == TRUE) { CheckForSafariZoneAndProceed(); gScriptResult = 1; @@ -578,7 +536,7 @@ void RockSmashWildEncounter(void) return; } -u8 SweetScentWildEncounter(void) +bool8 SweetScentWildEncounter(void) { s16 x; s16 y; @@ -586,75 +544,60 @@ u8 SweetScentWildEncounter(void) struct WildPokemonInfo *wildPokemonInfo; PlayerGetDestCoords(&x, &y); - //headerNum = GetCurrentMapWildMonHeader(); - if((headerNum = GetCurrentMapWildMonHeader()) != 0xFFFF) + if ((headerNum = GetCurrentMapWildMonHeader()) != 0xFFFF) { - if(MetatileBehavior_IsLandWildEncounter(MapGridGetMetatileBehaviorAt(x, y)) == 1) + if (MetatileBehavior_IsLandWildEncounter(MapGridGetMetatileBehaviorAt(x, y)) == 1) { wildPokemonInfo = gWildMonHeaders[headerNum].landMonsInfo; - - if(wildPokemonInfo == NULL) - return 0; - - if(sub_81344CC() == 1) + if (wildPokemonInfo == NULL) + return FALSE; + if (sub_81344CC() == TRUE) { - //_080853BC sub_8081A5C(); - return 1; + return TRUE; } - - if(DoMassOutbreakEncounterTest() == 1) + if (DoMassOutbreakEncounterTest() == TRUE) SetUpMassOutbreakEncounter(0); else - //_08085374 - GenerateWildMon(wildPokemonInfo, 0, 0); - //_080853D2 + GenerateWildMon(wildPokemonInfo, 0, FALSE); CheckForSafariZoneAndProceed(); - return 1; + return TRUE; } - //_08085380 - else + else if (MetatileBehavior_IsWaterWildEncounter(MapGridGetMetatileBehaviorAt(x, y)) == 1) { - if(MetatileBehavior_IsWaterWildEncounter(MapGridGetMetatileBehaviorAt(x, y)) == 1) + wildPokemonInfo = gWildMonHeaders[headerNum].waterMonsInfo; + if (wildPokemonInfo == NULL) + return FALSE; + if (sub_81344CC() == TRUE) { - wildPokemonInfo = gWildMonHeaders[headerNum].waterMonsInfo; - - if(wildPokemonInfo == NULL) - return 0; - - if(sub_81344CC() == 1) - { - sub_8081A5C(); - return 1; - } - else - //_080853C8 - GenerateWildMon(wildPokemonInfo, 1, 0); - CheckForSafariZoneAndProceed(); - return 1; + sub_8081A5C(); + return TRUE; } + GenerateWildMon(wildPokemonInfo, 1, FALSE); + CheckForSafariZoneAndProceed(); + return TRUE; } } - return 0; + return FALSE; } -u8 GetFishingWildMonListHeader(void) +bool8 GetFishingWildMonListHeader(void) { u16 headerNum = GetCurrentMapWildMonHeader(); - if(headerNum != 0xFFFF && gWildMonHeaders[headerNum].fishingMonsInfo != NULL) - return 1; + if (headerNum != 0xFFFF && gWildMonHeaders[headerNum].fishingMonsInfo != NULL) + return TRUE; else - return 0; + return FALSE; } void FishingWildEncounter(u8 rod) { u16 species; - if(CheckFeebas() == TRUE) + if (CheckFeebas() == TRUE) { - u8 level = RandomInRange(&gWildFeebasRoute119Data); + u8 level = ChooseWildMonLevel(&gWildFeebasRoute119Data); species = gWildFeebasRoute119Data.species; CreateWildMon(species, level); @@ -678,34 +621,29 @@ u16 GetLocalWildMon(bool8 *isWaterMon) *isWaterMon = FALSE; headerNum = GetCurrentMapWildMonHeader(); - if(headerNum == 0xFFFF) + if (headerNum == 0xFFFF) return 0; - landMonsInfo = gWildMonHeaders[headerNum].landMonsInfo; waterMonsInfo = gWildMonHeaders[headerNum].waterMonsInfo; - - if (!landMonsInfo && !waterMonsInfo) + //Neither + if (landMonsInfo == NULL && waterMonsInfo == NULL) return 0; - - if (landMonsInfo && !waterMonsInfo) - { - return landMonsInfo->wildPokemon[PickWildMon_Grass()].species; - } - - if (!landMonsInfo && waterMonsInfo) + //Land Pokemon + if (landMonsInfo != NULL && waterMonsInfo == NULL) + return landMonsInfo->wildPokemon[ChooseWildMonIndex_Land()].species; + //Water Pokemon + if (landMonsInfo == NULL && waterMonsInfo != NULL) { *isWaterMon = TRUE; - return waterMonsInfo->wildPokemon[PickWildMon_Water()].species; + return waterMonsInfo->wildPokemon[ChooseWildMonIndex_Water()].species; } - + //Either land or water Pokemon if ((Random() % 100) < 80) - { - return landMonsInfo->wildPokemon[PickWildMon_Grass()].species; - } + return landMonsInfo->wildPokemon[ChooseWildMonIndex_Land()].species; else { *isWaterMon = TRUE; - return waterMonsInfo->wildPokemon[PickWildMon_Water()].species; + return waterMonsInfo->wildPokemon[ChooseWildMonIndex_Water()].species; } } @@ -713,25 +651,25 @@ u16 GetMirageIslandMon(void) { u16 headerNum = GetCurrentMapWildMonHeader(); - if(headerNum != 0xFFFF) + if (headerNum != 0xFFFF) { struct WildPokemonInfo *waterMonsInfo = gWildMonHeaders[headerNum].waterMonsInfo; - if(waterMonsInfo) - return waterMonsInfo->wildPokemon[PickWildMon_Water()].species; + if (waterMonsInfo) + return waterMonsInfo->wildPokemon[ChooseWildMonIndex_Water()].species; } return 0; } bool8 UpdateRepelCounter(void) { - u16 steps = VarGet(0x4021); + u16 steps = VarGet(VAR_REPEL_STEP_COUNT); - if(steps != 0) + if (steps != 0) { steps--; - VarSet(0x4021, steps); - if(steps == 0) + VarSet(VAR_REPEL_STEP_COUNT, steps); + if (steps == 0) { ScriptContext1_SetupScript(Event_RepelWoreOff); return TRUE; @@ -741,20 +679,20 @@ bool8 UpdateRepelCounter(void) } //Returns FALSE if Repel prevents wild Pokemon at the specified level from appearing -bool8 RepelCheck(bool8 level) +static bool8 RepelCheck(u8 level) { u8 i; - if(!VarGet(0x4021)) + if (!VarGet(VAR_REPEL_STEP_COUNT)) return TRUE; else { - for(i = 0; i < 6; i++) + for (i = 0; i < 6; i++) { // UB: Too few arguments for function 'GetMonData' - if(GetMonData(&gPlayerParty[i], MON_DATA_HP) && !GetMonData(&gPlayerParty[i], MON_DATA_IS_EGG)) + if (GetMonData(&gPlayerParty[i], MON_DATA_HP) && !GetMonData(&gPlayerParty[i], MON_DATA_IS_EGG)) { - if(level < (u8)GetMonData(&gPlayerParty[i], MON_DATA_LEVEL)) + if (level < (u8)GetMonData(&gPlayerParty[i], MON_DATA_LEVEL)) return FALSE; else return TRUE; @@ -764,17 +702,17 @@ bool8 RepelCheck(bool8 level) } } -void ApplyFluteEncounterRateMod(u32 *a1) +static void ApplyFluteEncounterRateMod(u32 *encRate) { - if(FlagGet(SYS_ENC_UP_ITEM) == 1) - *a1 = *a1 + *a1 / 2; - else if(FlagGet(SYS_ENC_DOWN_ITEM) == 1) - *a1 = *a1 / 2; + if (FlagGet(SYS_ENC_UP_ITEM) == TRUE) + *encRate += *encRate / 2; + else if (FlagGet(SYS_ENC_DOWN_ITEM) == TRUE) + *encRate = *encRate / 2; } -void ApplyCleanseTagEncounterRateMod(u32 *a1) +static void ApplyCleanseTagEncounterRateMod(u32 *encRate) { // UB: Too few arguments for function 'GetMonData' - if(GetMonData(&gPlayerParty[0], MON_DATA_HELD_ITEM) == 0xBE) - *a1 = *a1 * 2 / 3; + if (GetMonData(&gPlayerParty[0], MON_DATA_HELD_ITEM) == 0xBE) + *encRate = *encRate * 2 / 3; } diff --git a/sym_ewram.txt b/sym_ewram.txt index 2978383f5..0a1b8a8f9 100644 --- a/sym_ewram.txt +++ b/sym_ewram.txt @@ -578,38 +578,8 @@ gUnknown_0202FF38: @ 202FF38 gUnknown_0202FF58: @ 202FF58 .space 0x4 -gTrainerBattleMode: @ 202FF5C - .space 0x2 - -gTrainerBattleOpponent: @ 202FF5E - .space 0x2 - -gTrainerMapObjectLocalId: @ 202FF60 - .space 0x4 - -gTrainerIntroSpeech: @ 202FF64 - .space 0x4 - -gTrainerDefeatSpeech: @ 202FF68 - .space 0x4 - -gTrainerVictorySpeech: @ 202FF6C - .space 0x4 - -gTrainerCannotBattleSpeech: @ 202FF70 - .space 0x4 - -gTrainerBattleScriptReturnAddress: @ 202FF74 - .space 0x4 - -gTrainerBattleEndScript: @ 202FF78 - .space 0x4 - -gWildEncountersDisabled: @ 202FF7C - .space 0x4 - -gUnknown_0202FF80: @ 202FF80 - .space 0x4 + .include "src/battle_setup.o" + .include "src/wild_encounter.o" gUnknown_0202FF84: @ 202FF84 .space 0x4 @@ -908,14 +878,7 @@ gUnknown_02038800: @ 2038800 gUnknown_02038804: @ 2038804 .space 0x4 -gUnknown_02038808: @ 2038808 - .space 0x2 - -gUnknown_0203880A: @ 203880A - .space 0x2 - -gUnkSafariZoneStructArr: @ 203880C - .space 0xa0 + .include "src/safari_zone.o" gUnknown_020388AC: @ 20388AC .space 0x4 |