diff options
author | ProjectRevoTPP <projectrevotpp@hotmail.com> | 2017-09-28 17:13:59 -0400 |
---|---|---|
committer | ProjectRevoTPP <projectrevotpp@hotmail.com> | 2017-09-28 17:13:59 -0400 |
commit | 0cac170dfd3bfa9c2386b0b230655ace9dea7f11 (patch) | |
tree | 482835fe4eb9347f9f365b683cd188ed88d7f1b7 /src | |
parent | eb1da945b499641e0e1eb0283a05a001df0bfd32 (diff) | |
parent | c1c2015f7046676b043641c0d1f9d9e29bc73647 (diff) |
merge
Diffstat (limited to 'src')
86 files changed, 2534 insertions, 2253 deletions
diff --git a/src/battle/battle_2.c b/src/battle/battle_2.c index 106d3333b..3cdea07be 100644 --- a/src/battle/battle_2.c +++ b/src/battle/battle_2.c @@ -181,7 +181,7 @@ extern u8 gHealthboxIDs[]; extern struct UnknownStruct6 gUnknown_03004DE0; //extern u16 gUnknown_03004DE0[][0xA0]; // possibly? extern u16 gBattleTypeFlags; -extern s8 gBattleTerrain; // I'm not sure if this is supposed to be s8 or u8. Regardless, it must have the same type as the return value of GetBattleTerrain. +extern s8 gBattleTerrain; // I'm not sure if this is supposed to be s8 or u8. Regardless, it must have the same type as the return value of BattleSetup_GetTerrain. extern u8 gReservedSpritePaletteCount; extern u16 gTrainerBattleOpponent; extern struct BattleEnigmaBerry gEnigmaBerries[]; @@ -239,7 +239,8 @@ void InitBattle(void) gUnknown_03004DE0.unk0[i] = 0xFF10; gUnknown_03004DE0.unk780[i] = 0xFF10; } - sub_80895F8(gUnknown_081F9674.unk0, gUnknown_081F9674.unk4, gUnknown_081F9674.unk8); + //sub_80895F8(gUnknown_081F9674.unk0, gUnknown_081F9674.unk4, gUnknown_081F9674.unk8); + sub_80895F8(gUnknown_081F9674); SetUpWindowConfig(&gWindowConfig_81E6C58); ResetPaletteFade(); gUnknown_030042A4 = 0; @@ -250,7 +251,7 @@ void InitBattle(void) gUnknown_03004280 = 0; gUnknown_030041B0 = 0; gUnknown_030041B8 = 0; - gBattleTerrain = GetBattleTerrain(); + gBattleTerrain = BattleSetup_GetTerrain(); InitWindowFromConfig(&gUnknown_03004210, &gWindowConfig_81E6C58); InitWindowFromConfig(&gUnknown_030041D0, &gWindowConfig_81E71D0); InitWindowFromConfig(&gUnknown_03004250, &gWindowConfig_81E71EC); diff --git a/src/battle/battle_4.c b/src/battle/battle_4.c index d8141bad1..65ea765cf 100644 --- a/src/battle/battle_4.c +++ b/src/battle/battle_4.c @@ -144,7 +144,7 @@ void sub_802BBD4(u8 r0, u8 r1, u8 r2, u8 r3, u8 sp0); void nullsub_6(void); void ReshowBattleScreenAfterMenu(void); void sub_800F808(void); -void sub_80B79B8(u32* moneySaveblock, u32 to_give); +void AddMoney(u32* moneySaveblock, u32 to_give); void sub_80156DC(void); //set sentpokes value bool8 sub_8014AB8(u8 bank); //can run from battle u8 CountAliveMons(u8 caseID); @@ -154,7 +154,7 @@ u8 GetMoveTarget(u16 move, u8 targetbyte); //get target of move void sub_80153D0(u8 atk); //pressure perish song pp decrement u8 CastformDataTypeChange(u8 bank); void b_push_move_exec(u8* bs_ptr); -u8 sav1_map_get_light_level(void); +u8 Overworld_GetMapTypeOfSaveblockLocation(void); u8 CalculatePlayerPartyCount(void); u16 Sqrt(u32 num); u8 sub_809070C(u16 nationalNum, u32 TiD, u32 PiD); //task prepare poke dex display @@ -11717,7 +11717,7 @@ static void atk5D_getmoneyreward(void) money_to_give = 1 * gTrainerMoney[i * 4 + 1] * money_to_give; } - sub_80B79B8(&gSaveBlock1.money, money_to_give); + AddMoney(&gSaveBlock1.money, money_to_give); gBattleTextBuff1[0] = 0xFD; gBattleTextBuff1[1] = 1; gBattleTextBuff1[2] = 4; @@ -11889,7 +11889,7 @@ _0802413C:\n\ _08024140:\n\ mov r0, r8\n\ adds r1, r4, 0\n\ - bl sub_80B79B8\n\ + bl AddMoney\n\ ldr r1, _0802418C @ =gBattleTextBuff1\n\ movs r0, 0xFD\n\ strb r0, [r1]\n\ @@ -14186,7 +14186,7 @@ static void atk91_givepaydaymoney(void) { if (!(gBattleTypeFlags & BATTLE_TYPE_LINK) && gPaydayMoney) { - sub_80B79B8(&gSaveBlock1.money, gPaydayMoney * BATTLE_STRUCT->moneyMultiplier); + AddMoney(&gSaveBlock1.money, gPaydayMoney * BATTLE_STRUCT->moneyMultiplier); gBattleTextBuff1[0] = 0xFD; gBattleTextBuff1[1] = 1; gBattleTextBuff1[2] = 2; @@ -17570,28 +17570,28 @@ static void atkE4_getsecretpowereffect(void) { switch (gBattleTerrain) { - case 0: + case BATTLE_TERRAIN_GRASS: gBattleCommunication[MOVE_EFFECT_BYTE] = 2; break; - case 1: + case BATTLE_TERRAIN_LONG_GRASS: gBattleCommunication[MOVE_EFFECT_BYTE] = 1; break; - case 2: + case BATTLE_TERRAIN_SAND: gBattleCommunication[MOVE_EFFECT_BYTE] = 27; break; - case 3: + case BATTLE_TERRAIN_UNDERWATER: gBattleCommunication[MOVE_EFFECT_BYTE] = 23; break; - case 4: + case BATTLE_TERRAIN_WATER: gBattleCommunication[MOVE_EFFECT_BYTE] = 22; break; - case 5: + case BATTLE_TERRAIN_POND: gBattleCommunication[MOVE_EFFECT_BYTE] = 24; break; - case 6: + case BATTLE_TERRAIN_MOUNTAIN: gBattleCommunication[MOVE_EFFECT_BYTE] = 7; break; - case 7: + case BATTLE_TERRAIN_CAVE: gBattleCommunication[MOVE_EFFECT_BYTE] = 8; break; default: @@ -17818,7 +17818,7 @@ void atkEF_pokeball_catch_calculation(void) ball_multiplier = 10; break; case ITEM_DIVE_BALL: - if (sav1_map_get_light_level() == 5) + if (Overworld_GetMapTypeOfSaveblockLocation() == 5) ball_multiplier = 35; else ball_multiplier = 10; diff --git a/src/battle/battle_records.c b/src/battle/battle_records.c index 61dc09792..d848a10b8 100644 --- a/src/battle/battle_records.c +++ b/src/battle/battle_records.c @@ -3,7 +3,7 @@ #include "game_stat.h" #include "link.h" #include "menu.h" -#include "rom4.h" +#include "overworld.h" #include "string_util.h" #include "strings2.h" #include "trainer_card.h" diff --git a/src/battle/battle_setup.c b/src/battle/battle_setup.c index 31c127416..59e17e9eb 100644 --- a/src/battle/battle_setup.c +++ b/src/battle/battle_setup.c @@ -18,7 +18,7 @@ #include "opponent_constants.h" #include "palette.h" #include "rng.h" -#include "rom4.h" +#include "overworld.h" #include "safari_zone.h" #include "script.h" #include "script_pokemon_80C4.h" @@ -37,15 +37,15 @@ extern u16 gScriptResult; extern void (*gFieldCallback)(void); -EWRAM_DATA u16 gTrainerBattleMode = 0; +EWRAM_DATA static u16 sTrainerBattleMode = 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; +EWRAM_DATA static u16 sTrainerMapObjectLocalId = 0; +EWRAM_DATA static u8 *sTrainerIntroSpeech = NULL; +EWRAM_DATA static u8 *sTrainerDefeatSpeech = NULL; +EWRAM_DATA static u8 *sTrainerVictorySpeech = NULL; +EWRAM_DATA static u8 *sTrainerCannotBattleSpeech = NULL; +EWRAM_DATA static u8 *sTrainerBattleScriptRetAddr = NULL; +EWRAM_DATA static u8 *sTrainerBattleEndScript = NULL; extern u16 gBattleTypeFlags; extern u16 gScriptLastTalked; @@ -62,80 +62,99 @@ extern u8 gUnknown_0819F8AE[]; extern u8 gUnknown_0819F80B[]; extern u8 gUnknown_081C6C02[]; - +// The first transition is used if the enemy pokemon are lower level than our pokemon. +// Otherwise, the second transition is used. static const u8 gBattleTransitionTable_Wild[][2] = { - {8, 9}, - {5, 10}, - {0, 10}, - {7, 6}, + {B_TRANSITION_SLICE, B_TRANSITION_WHITEFADE}, // Normal + {B_TRANSITION_CLOCKWISE_BLACKFADE, B_TRANSITION_GRID_SQUARES}, // Cave + {B_TRANSITION_BLUR, B_TRANSITION_GRID_SQUARES}, // Cave with flash used + {B_TRANSITION_WAVE, B_TRANSITION_RIPPLE}, // Water }; static const u8 gBattleTransitionTable_Trainer[][2] = { - {4, 11}, - {2, 3}, - {0, 10}, - {1, 6}, + {B_TRANSITION_POKEBALLS_TRAIL, B_TRANSITION_SHARDS}, // Normal + {B_TRANSITION_SHUFFLE, B_TRANSITION_BIG_POKEBALL}, // Cave + {B_TRANSITION_BLUR, B_TRANSITION_GRID_SQUARES}, // Cave with flash used + {B_TRANSITION_SWIRL, B_TRANSITION_RIPPLE}, // Water +}; + +enum +{ + TRAINER_PARAM_LOAD_VAL_8BIT, + TRAINER_PARAM_LOAD_VAL_16BIT, + TRAINER_PARAM_LOAD_VAL_32BIT, + TRAINER_PARAM_CLEAR_VAL_8BIT, + TRAINER_PARAM_CLEAR_VAL_16BIT, + TRAINER_PARAM_CLEAR_VAL_32BIT, + TRAINER_PARAM_LOAD_SCRIPT_RET_ADDR, +}; + +struct TrainerBattleParameter +{ + void *varPtr; + u8 ptrType; }; -static const struct TrainerBattleSpec gTrainerBattleSpecs_0[] = -{ - {&gTrainerBattleMode, 0}, - {&gTrainerBattleOpponent, 1}, - {&gTrainerMapObjectLocalId, 1}, - {&gTrainerIntroSpeech, 2}, - {&gTrainerDefeatSpeech, 2}, - {&gTrainerVictorySpeech, 5}, - {&gTrainerCannotBattleSpeech, 5}, - {&gTrainerBattleEndScript, 5}, - {&gTrainerBattleScriptReturnAddress, 6}, + +static const struct TrainerBattleParameter gTrainerBattleSpecs_0[] = +{ + {&sTrainerBattleMode, TRAINER_PARAM_LOAD_VAL_8BIT}, + {&gTrainerBattleOpponent, TRAINER_PARAM_LOAD_VAL_16BIT}, + {&sTrainerMapObjectLocalId, TRAINER_PARAM_LOAD_VAL_16BIT}, + {&sTrainerIntroSpeech, TRAINER_PARAM_LOAD_VAL_32BIT}, + {&sTrainerDefeatSpeech, TRAINER_PARAM_LOAD_VAL_32BIT}, + {&sTrainerVictorySpeech, TRAINER_PARAM_CLEAR_VAL_32BIT}, + {&sTrainerCannotBattleSpeech, TRAINER_PARAM_CLEAR_VAL_32BIT}, + {&sTrainerBattleEndScript, TRAINER_PARAM_CLEAR_VAL_32BIT}, + {&sTrainerBattleScriptRetAddr, TRAINER_PARAM_LOAD_SCRIPT_RET_ADDR}, }; -static const struct TrainerBattleSpec gTrainerBattleSpecs_1[] = -{ - {&gTrainerBattleMode, 0}, - {&gTrainerBattleOpponent, 1}, - {&gTrainerMapObjectLocalId, 1}, - {&gTrainerIntroSpeech, 2}, - {&gTrainerDefeatSpeech, 2}, - {&gTrainerVictorySpeech, 5}, - {&gTrainerCannotBattleSpeech, 5}, - {&gTrainerBattleEndScript, 2}, - {&gTrainerBattleScriptReturnAddress, 6}, +static const struct TrainerBattleParameter gTrainerBattleSpecs_1[] = +{ + {&sTrainerBattleMode, TRAINER_PARAM_LOAD_VAL_8BIT}, + {&gTrainerBattleOpponent, TRAINER_PARAM_LOAD_VAL_16BIT}, + {&sTrainerMapObjectLocalId, TRAINER_PARAM_LOAD_VAL_16BIT}, + {&sTrainerIntroSpeech, TRAINER_PARAM_LOAD_VAL_32BIT}, + {&sTrainerDefeatSpeech, TRAINER_PARAM_LOAD_VAL_32BIT}, + {&sTrainerVictorySpeech, TRAINER_PARAM_CLEAR_VAL_32BIT}, + {&sTrainerCannotBattleSpeech, TRAINER_PARAM_CLEAR_VAL_32BIT}, + {&sTrainerBattleEndScript, TRAINER_PARAM_LOAD_VAL_32BIT}, + {&sTrainerBattleScriptRetAddr, TRAINER_PARAM_LOAD_SCRIPT_RET_ADDR}, }; -static const struct TrainerBattleSpec gTrainerBattleSpecs_2[] = -{ - {&gTrainerBattleMode, 0}, - {&gTrainerBattleOpponent, 1}, - {&gTrainerMapObjectLocalId, 1}, - {&gTrainerIntroSpeech, 2}, - {&gTrainerDefeatSpeech, 2}, - {&gTrainerVictorySpeech, 5}, - {&gTrainerCannotBattleSpeech, 2}, - {&gTrainerBattleEndScript, 5}, - {&gTrainerBattleScriptReturnAddress, 6}, +static const struct TrainerBattleParameter gTrainerBattleSpecs_2[] = +{ + {&sTrainerBattleMode, TRAINER_PARAM_LOAD_VAL_8BIT}, + {&gTrainerBattleOpponent, TRAINER_PARAM_LOAD_VAL_16BIT}, + {&sTrainerMapObjectLocalId, TRAINER_PARAM_LOAD_VAL_16BIT}, + {&sTrainerIntroSpeech, TRAINER_PARAM_LOAD_VAL_32BIT}, + {&sTrainerDefeatSpeech, TRAINER_PARAM_LOAD_VAL_32BIT}, + {&sTrainerVictorySpeech, TRAINER_PARAM_CLEAR_VAL_32BIT}, + {&sTrainerCannotBattleSpeech, TRAINER_PARAM_LOAD_VAL_32BIT}, + {&sTrainerBattleEndScript, TRAINER_PARAM_CLEAR_VAL_32BIT}, + {&sTrainerBattleScriptRetAddr, TRAINER_PARAM_LOAD_SCRIPT_RET_ADDR}, }; -static const struct TrainerBattleSpec gTrainerBattleSpecs_3[] = -{ - {&gTrainerBattleMode, 0}, - {&gTrainerBattleOpponent, 1}, - {&gTrainerMapObjectLocalId, 1}, - {&gTrainerIntroSpeech, 5}, - {&gTrainerDefeatSpeech, 2}, - {&gTrainerVictorySpeech, 5}, - {&gTrainerCannotBattleSpeech, 5}, - {&gTrainerBattleEndScript, 5}, - {&gTrainerBattleScriptReturnAddress, 6}, +static const struct TrainerBattleParameter gTrainerBattleSpecs_3[] = +{ + {&sTrainerBattleMode, TRAINER_PARAM_LOAD_VAL_8BIT}, + {&gTrainerBattleOpponent, TRAINER_PARAM_LOAD_VAL_16BIT}, + {&sTrainerMapObjectLocalId, TRAINER_PARAM_LOAD_VAL_16BIT}, + {&sTrainerIntroSpeech, TRAINER_PARAM_CLEAR_VAL_32BIT}, + {&sTrainerDefeatSpeech, TRAINER_PARAM_LOAD_VAL_32BIT}, + {&sTrainerVictorySpeech, TRAINER_PARAM_CLEAR_VAL_32BIT}, + {&sTrainerCannotBattleSpeech, TRAINER_PARAM_CLEAR_VAL_32BIT}, + {&sTrainerBattleEndScript, TRAINER_PARAM_CLEAR_VAL_32BIT}, + {&sTrainerBattleScriptRetAddr, TRAINER_PARAM_LOAD_SCRIPT_RET_ADDR}, }; -static const struct TrainerBattleSpec gTrainerBattleSpecs_4[] = -{ - {&gTrainerBattleMode, 0}, - {&gTrainerBattleOpponent, 1}, - {&gTrainerMapObjectLocalId, 1}, - {&gTrainerIntroSpeech, 2}, - {&gTrainerDefeatSpeech, 2}, - {&gTrainerVictorySpeech, 5}, - {&gTrainerCannotBattleSpeech, 2}, - {&gTrainerBattleEndScript, 2}, - {&gTrainerBattleScriptReturnAddress, 6}, +static const struct TrainerBattleParameter gTrainerBattleSpecs_4[] = +{ + {&sTrainerBattleMode, TRAINER_PARAM_LOAD_VAL_8BIT}, + {&gTrainerBattleOpponent, TRAINER_PARAM_LOAD_VAL_16BIT}, + {&sTrainerMapObjectLocalId, TRAINER_PARAM_LOAD_VAL_16BIT}, + {&sTrainerIntroSpeech, TRAINER_PARAM_LOAD_VAL_32BIT}, + {&sTrainerDefeatSpeech, TRAINER_PARAM_LOAD_VAL_32BIT}, + {&sTrainerVictorySpeech, TRAINER_PARAM_CLEAR_VAL_32BIT}, + {&sTrainerCannotBattleSpeech, TRAINER_PARAM_LOAD_VAL_32BIT}, + {&sTrainerBattleEndScript, TRAINER_PARAM_LOAD_VAL_32BIT}, + {&sTrainerBattleScriptRetAddr, TRAINER_PARAM_LOAD_SCRIPT_RET_ADDR}, }; const struct TrainerEyeTrainer gTrainerEyeTrainers[] = @@ -424,17 +443,32 @@ const struct TrainerEyeTrainer gTrainerEyeTrainers[] = static const u16 sBadgeFlags[] = {BADGE01_GET, BADGE02_GET, BADGE03_GET, BADGE04_GET, BADGE05_GET, BADGE06_GET, BADGE07_GET, BADGE08_GET}; -void task01_battle_start(u8 taskId) +static void DoStandardWildBattle(void); +static void DoSafariBattle(void); +static void SetTrainerFlagsAfterTrainerEyeRematch(void); +static void CB2_EndWildBattle(void); +static void CB2_EndScriptedWildBattle(void); +static u8 GetWildBattleTransition(void); +static u8 GetTrainerBattleTransition(void); +static void CB2_GiveStarter(void); +static void CB2_StartFirstBattle(void); +static void CB2_EndFirstBattle(void); +static bool32 IsPlayerDefeated(u32 a1); + +#define tState data[0] +#define tTransition data[1] + +static void Task_BattleStart(u8 taskId) { s16 *data = gTasks[taskId].data; - switch (data[0]) + switch (tState) { case 0: if (!FieldPoisonEffectIsRunning()) // is poison not active? { - sub_811AABC(data[1]); - data[0]++; // go to case 1. + BattleTransition_StartOnField(tTransition); + tState++; // go to case 1. } break; case 1: @@ -449,132 +483,135 @@ void task01_battle_start(u8 taskId) } } -void task_add_01_battle_start(u8 transition, u16 song) +static void CreateBattleStartTask(u8 transition, u16 song) { - u8 taskId = CreateTask(task01_battle_start, 1); + u8 taskId = CreateTask(Task_BattleStart, 1); - gTasks[taskId].data[1] = transition; + gTasks[taskId].tTransition = transition; current_map_music_set__default_for_battle(song); } -void CheckForSafariZoneAndProceed(void) +#undef tState +#undef tTransition + +void BattleSetup_StartWildBattle(void) { if (GetSafariZoneFlag()) - StartBattle_Safari(); + DoSafariBattle(); else - StartBattle_StandardWild(); + DoStandardWildBattle(); } -void StartBattle_StandardWild(void) +static void DoStandardWildBattle(void) { ScriptContext2_Enable(); FreezeMapObjects(); sub_80597F4(); - gMain.savedCallback = HandleWildBattleEnd; + gMain.savedCallback = CB2_EndWildBattle; gBattleTypeFlags = 0; - task_add_01_battle_start(GetWildBattleTransition(), 0); + CreateBattleStartTask(GetWildBattleTransition(), 0); IncrementGameStat(7); IncrementGameStat(8); } -void StartBattle_Roamer(void) +void BattleSetup_StartRoamerBattle(void) { ScriptContext2_Enable(); FreezeMapObjects(); sub_80597F4(); - gMain.savedCallback = HandleWildBattleEnd; + gMain.savedCallback = CB2_EndWildBattle; gBattleTypeFlags = BATTLE_TYPE_ROAMER; - task_add_01_battle_start(GetWildBattleTransition(), 0); + CreateBattleStartTask(GetWildBattleTransition(), 0); IncrementGameStat(7); IncrementGameStat(8); } -void StartBattle_Safari(void) +static void DoSafariBattle(void) { ScriptContext2_Enable(); FreezeMapObjects(); sub_80597F4(); gMain.savedCallback = sub_80C824C; gBattleTypeFlags = BATTLE_TYPE_SAFARI; - task_add_01_battle_start(GetWildBattleTransition(), 0); + CreateBattleStartTask(GetWildBattleTransition(), 0); } -void task_add_01_battle_start_with_music_and_stats(void) +static void StartTheBattle(void) { - task_add_01_battle_start(GetTrainerBattleTransition(), 0); + CreateBattleStartTask(GetTrainerBattleTransition(), 0); IncrementGameStat(7); IncrementGameStat(9); } //Initiates battle where Wally catches Ralts -void StartBattle_WallyTutorial(void) +void ScrSpecial_StartWallyTutorialBattle(void) { CreateMaleMon(&gEnemyParty[0], SPECIES_RALTS, 5); ScriptContext2_Enable(); gMain.savedCallback = c2_exit_to_overworld_1_continue_scripts_restart_music; gBattleTypeFlags = BATTLE_TYPE_WALLY_TUTORIAL; - task_add_01_battle_start(8, 0); + CreateBattleStartTask(B_TRANSITION_SLICE, 0); } -void StartBattle_ScriptedWild(void) +void BattleSetup_StartScriptedWildBattle(void) { ScriptContext2_Enable(); - gMain.savedCallback = HandleScriptedWildBattleEnd; + gMain.savedCallback = CB2_EndScriptedWildBattle; gBattleTypeFlags = 0; - task_add_01_battle_start(GetWildBattleTransition(), 0); + CreateBattleStartTask(GetWildBattleTransition(), 0); IncrementGameStat(7); IncrementGameStat(8); } -void StartBattle_SouthernIsland(void) +void ScrSpecial_StartSouthernIslandBattle(void) { ScriptContext2_Enable(); - gMain.savedCallback = HandleScriptedWildBattleEnd; + gMain.savedCallback = CB2_EndScriptedWildBattle; gBattleTypeFlags = BATTLE_TYPE_LEGENDARY; - task_add_01_battle_start(GetWildBattleTransition(), 0); + CreateBattleStartTask(GetWildBattleTransition(), 0); IncrementGameStat(7); IncrementGameStat(8); } -void StartBattle_Rayquaza(void) +void ScrSpecial_StartRayquazaBattle(void) { ScriptContext2_Enable(); - gMain.savedCallback = HandleScriptedWildBattleEnd; + gMain.savedCallback = CB2_EndScriptedWildBattle; gBattleTypeFlags = BATTLE_TYPE_LEGENDARY; - task_add_01_battle_start(0, BGM_BATTLE34); + CreateBattleStartTask(B_TRANSITION_BLUR, BGM_BATTLE34); IncrementGameStat(7); IncrementGameStat(8); } -void StartBattle_GroudonKyogre(void) +void ScrSpecial_StartGroudonKyogreBattle(void) { ScriptContext2_Enable(); - gMain.savedCallback = HandleScriptedWildBattleEnd; + gMain.savedCallback = CB2_EndScriptedWildBattle; gBattleTypeFlags = BATTLE_TYPE_LEGENDARY | BATTLE_TYPE_KYOGRE_GROUDON; - if (gGameVersion == 2) - task_add_01_battle_start(0xB, BGM_BATTLE34); // KYOGRE + if (gGameVersion == VERSION_RUBY) + CreateBattleStartTask(B_TRANSITION_SHARDS, BGM_BATTLE34); // GROUDON else - task_add_01_battle_start(0x6, BGM_BATTLE34); // GROUDON + CreateBattleStartTask(B_TRANSITION_RIPPLE, BGM_BATTLE34); // KYOGRE IncrementGameStat(7); IncrementGameStat(8); } -void StartBattle_Regi(void) +void ScrSpecial_StartRegiBattle(void) { ScriptContext2_Enable(); - gMain.savedCallback = HandleScriptedWildBattleEnd; + gMain.savedCallback = CB2_EndScriptedWildBattle; gBattleTypeFlags = BATTLE_TYPE_LEGENDARY | BATTLE_TYPE_REGI; - task_add_01_battle_start(0xA, BGM_BATTLE36); + CreateBattleStartTask(B_TRANSITION_GRID_SQUARES, BGM_BATTLE36); IncrementGameStat(7); IncrementGameStat(8); } -void HandleWildBattleEnd(void) +static void CB2_EndWildBattle(void) { CpuFill16(0, (void *)BG_PLTT, BG_PLTT_SIZE); ResetOamRange(0, 128); - if (battle_exit_is_player_defeat(gBattleOutcome) == TRUE) + if (IsPlayerDefeated(gBattleOutcome) == TRUE) { SetMainCallback2(CB2_WhiteOut); } @@ -585,18 +622,18 @@ void HandleWildBattleEnd(void) } } -void HandleScriptedWildBattleEnd(void) +void CB2_EndScriptedWildBattle(void) { CpuFill16(0, (void *)BG_PLTT, BG_PLTT_SIZE); ResetOamRange(0, 128); - if (battle_exit_is_player_defeat(gBattleOutcome) == TRUE) + if (IsPlayerDefeated(gBattleOutcome) == TRUE) SetMainCallback2(CB2_WhiteOut); else SetMainCallback2(c2_exit_to_overworld_1_continue_scripts_restart_music); } -s8 GetBattleTerrain(void) +s8 BattleSetup_GetTerrain(void) { u16 tileBehavior; s16 x, y; @@ -605,11 +642,11 @@ s8 GetBattleTerrain(void) tileBehavior = MapGridGetMetatileBehaviorAt(x, y); if (MetatileBehavior_IsTallGrass(tileBehavior)) - return 0; + return BATTLE_TERRAIN_GRASS; if (MetatileBehavior_IsLongGrass(tileBehavior)) - return 1; + return BATTLE_TERRAIN_LONG_GRASS; if (MetatileBehavior_IsSandOrDeepSand(tileBehavior)) - return 2; + return BATTLE_TERRAIN_SAND; switch (gMapHeader.mapType) { case MAP_TYPE_TOWN: @@ -618,54 +655,49 @@ s8 GetBattleTerrain(void) break; case MAP_TYPE_UNDERGROUND: if (sub_80574C4(tileBehavior)) - return 8; + return BATTLE_TERRAIN_BUILDING; if (MetatileBehavior_IsSurfableWaterOrUnderwater(tileBehavior)) - return 5; - return 7; + return BATTLE_TERRAIN_POND; + return BATTLE_TERRAIN_CAVE; case MAP_TYPE_INDOOR: case MAP_TYPE_SECRET_BASE: - return 8; + return BATTLE_TERRAIN_BUILDING; case MAP_TYPE_UNDERWATER: - return 3; + return BATTLE_TERRAIN_UNDERWATER; case MAP_TYPE_6: if (MetatileBehavior_IsSurfableWaterOrUnderwater(tileBehavior)) - return 4; - return 9; + return BATTLE_TERRAIN_WATER; + return BATTLE_TERRAIN_PLAIN; } if (sub_8057568(tileBehavior)) - return 4; + return BATTLE_TERRAIN_WATER; if (MetatileBehavior_IsSurfableWaterOrUnderwater(tileBehavior)) - return 5; + return BATTLE_TERRAIN_POND; if (sub_80574D8(tileBehavior)) - return 6; + return BATTLE_TERRAIN_MOUNTAIN; if (TestPlayerAvatarFlags(PLAYER_AVATAR_FLAG_SURFING)) { if (sub_8057450(tileBehavior)) - return 5; + return BATTLE_TERRAIN_POND; if (MetatileBehavior_IsBridge(tileBehavior) == TRUE) - return 4; + return BATTLE_TERRAIN_WATER; } - if (gSaveBlock1.location.mapGroup == 0 && gSaveBlock1.location.mapNum == 28) - return 2; + if (gSaveBlock1.location.mapGroup == MAP_GROUP_ROUTE113 && gSaveBlock1.location.mapNum == MAP_ID_ROUTE113) + return BATTLE_TERRAIN_SAND; if (GetSav1Weather() == 8) - return 2; - return 9; + return BATTLE_TERRAIN_SAND; + return BATTLE_TERRAIN_PLAIN; } -s8 GetBattleTransitionTypeByMap(void) +static s8 GetBattleTransitionTypeByMap(void) { - u8 flashUsed; u16 tileBehavior; s16 x, y; PlayerGetDestCoords(&x, &y); tileBehavior = MapGridGetMetatileBehaviorAt(x, y); - - flashUsed = sav1_get_flash_used_on_map(); - - if (flashUsed) + if (Overworld_GetFlashLevel()) return 2; - if (!MetatileBehavior_IsSurfableWaterOrUnderwater(tileBehavior)) { switch (gMapHeader.mapType) @@ -681,7 +713,7 @@ s8 GetBattleTransitionTypeByMap(void) return 3; } -u16 GetSumOfPartyMonLevel(u8 numMons) +static u16 GetSumOfPlayerPartyLevel(u8 numMons) { u8 sum = 0; int i; @@ -701,37 +733,37 @@ u16 GetSumOfPartyMonLevel(u8 numMons) return sum; } -u8 GetSumOfEnemyPartyLevel(u16 trainerNum, u8 numMons) +static u8 GetSumOfEnemyPartyLevel(u16 opponentId, u8 numMons) { u8 i; u8 sum; u32 count = numMons; void *party; - if (gTrainers[trainerNum].partySize < count) - count = gTrainers[trainerNum].partySize; + if (gTrainers[opponentId].partySize < count) + count = gTrainers[opponentId].partySize; sum = 0; - switch (gTrainers[trainerNum].partyFlags) + switch (gTrainers[opponentId].partyFlags) { case 0: - party = gTrainers[trainerNum].party; + party = gTrainers[opponentId].party; for (i = 0; i < count; i++) sum += ((struct TrainerPartyMember0 *)party)[i].level; break; case 1: - party = gTrainers[trainerNum].party; + party = gTrainers[opponentId].party; for (i = 0; i < count; i++) sum += ((struct TrainerPartyMember1 *)party)[i].level; break; case 2: - party = gTrainers[trainerNum].party; + party = gTrainers[opponentId].party; for (i = 0; i < count; i++) sum += ((struct TrainerPartyMember2 *)party)[i].level; break; case 3: - party = gTrainers[trainerNum].party; + party = gTrainers[opponentId].party; for (i = 0; i < count; i++) sum += ((struct TrainerPartyMember3 *)party)[i].level; break; @@ -740,76 +772,79 @@ u8 GetSumOfEnemyPartyLevel(u16 trainerNum, u8 numMons) return sum; } -u8 GetWildBattleTransition(void) +static u8 GetWildBattleTransition(void) { - u8 flashVar = GetBattleTransitionTypeByMap(); - u8 level = GetMonData(&gEnemyParty[0], MON_DATA_LEVEL); + u8 transitionType = GetBattleTransitionTypeByMap(); + u8 enemyLevel = GetMonData(&gEnemyParty[0], MON_DATA_LEVEL); + u8 playerLevel = GetSumOfPlayerPartyLevel(1); - if (level < (u8)GetSumOfPartyMonLevel(1)) // is wild mon level than the player's mon level? - return gBattleTransitionTable_Wild[flashVar][0]; + if (enemyLevel < playerLevel) + return gBattleTransitionTable_Wild[transitionType][0]; else - return gBattleTransitionTable_Wild[flashVar][1]; // use a white fade in instead of normal transition. + return gBattleTransitionTable_Wild[transitionType][1]; } -u8 GetTrainerBattleTransition(void) +static u8 GetTrainerBattleTransition(void) { const struct Trainer *trainer; u8 minPartyCount; - u8 flashVar; - u8 level; + u8 transitionType; + u8 enemyLevel; + u8 playerLevel; if (gTrainerBattleOpponent == 1024) // link battle? - return 16; + return B_TRANSITION_STEVEN; trainer = gTrainers; if (trainer[gTrainerBattleOpponent].trainerClass == 24) // league? { if (gTrainerBattleOpponent == 261) - return 12; + return B_TRANSITION_SYDNEY; if (gTrainerBattleOpponent == 262) - return 13; + return B_TRANSITION_PHOEBE; if (gTrainerBattleOpponent == 263) - return 14; + return B_TRANSITION_GLACIA; if (gTrainerBattleOpponent == 264) - return 15; - return 16; + return B_TRANSITION_DRAKE; + return B_TRANSITION_STEVEN; } if (trainer[gTrainerBattleOpponent].trainerClass == 32) // team leader? - return 16; + return B_TRANSITION_STEVEN; if (trainer[gTrainerBattleOpponent].doubleBattle == TRUE) minPartyCount = 2; // double battles always at least have 2 pokemon. else minPartyCount = 1; - flashVar = GetBattleTransitionTypeByMap(); - level = GetSumOfEnemyPartyLevel(gTrainerBattleOpponent, minPartyCount); - - if (level < (u8)GetSumOfPartyMonLevel(minPartyCount)) // is wild mon level than the player's mon level? - return gBattleTransitionTable_Trainer[flashVar][0]; + transitionType = GetBattleTransitionTypeByMap(); + enemyLevel = GetSumOfEnemyPartyLevel(gTrainerBattleOpponent, minPartyCount); + playerLevel = GetSumOfPlayerPartyLevel(minPartyCount); + if (enemyLevel < playerLevel) // is wild mon level than the player's mon level? + return gBattleTransitionTable_Trainer[transitionType][0]; else - return gBattleTransitionTable_Trainer[flashVar][1]; + return gBattleTransitionTable_Trainer[transitionType][1]; } -u8 GetBattleTowerBattleTransition(void) +u8 BattleSetup_GetBattleTowerBattleTransition(void) { - u8 monData = GetMonData(&gEnemyParty[0], MON_DATA_LEVEL); + u8 enemyLevel = GetMonData(&gEnemyParty[0], MON_DATA_LEVEL); + u8 playerLevel = GetSumOfPlayerPartyLevel(1); - if (monData < (u8)GetSumOfPartyMonLevel(1)) - return 4; + if (enemyLevel < playerLevel) + return B_TRANSITION_POKEBALLS_TRAIL; else - return 3; + return B_TRANSITION_BIG_POKEBALL; } -void ChooseStarter(void) +void ScrSpecial_ChooseStarter(void) { SetMainCallback2(CB2_ChooseStarter); gMain.savedCallback = CB2_GiveStarter; } -void CB2_GiveStarter(void) +static void CB2_GiveStarter(void) { u16 starterPoke; @@ -819,10 +854,10 @@ void CB2_GiveStarter(void) ResetTasks(); sub_80408BC(); SetMainCallback2(CB2_StartFirstBattle); - sub_811AAD8(0); + BattleTransition_Start(0); } -void CB2_StartFirstBattle(void) +static void CB2_StartFirstBattle(void) { UpdatePaletteFade(); RunTasks(); @@ -830,7 +865,7 @@ void CB2_StartFirstBattle(void) if (IsBattleTransitionDone() == TRUE) { gBattleTypeFlags = BATTLE_TYPE_FIRST_BATTLE; - gMain.savedCallback = HandleFirstBattleEnd; + gMain.savedCallback = CB2_EndFirstBattle; SetMainCallback2(sub_800E7C4); prev_quest_postbuffer_cursor_backup_reset(); overworld_poison_timer_set(); @@ -839,35 +874,35 @@ void CB2_StartFirstBattle(void) } } -void HandleFirstBattleEnd(void) +static void CB2_EndFirstBattle(void) { sav1_reset_battle_music_maybe(); SetMainCallback2(c2_exit_to_overworld_1_continue_scripts_restart_music); } -u32 TrainerBattleLoadArg32(const u8 *ptr) +static u32 TrainerBattleLoadArg32(const u8 *ptr) { return ptr[0] | (ptr[1] << 8) | (ptr[2] << 16) | (ptr[3] << 24); } -u16 TrainerBattleLoadArg16(const u8 *ptr) +static u16 TrainerBattleLoadArg16(const u8 *ptr) { return ptr[0] | (ptr[1] << 8); } -u8 TrainerBattleLoadArg8(const u8 *ptr) +static u8 TrainerBattleLoadArg8(const u8 *ptr) { return ptr[0]; } -u16 trainerflag_opponent(void) +static u16 CurrentOpponentTrainerFlag(void) { return TRAINER_FLAG_START + gTrainerBattleOpponent; } -bool32 battle_exit_is_player_defeat(u32 a1) +static bool32 IsPlayerDefeated(u32 battleOutcome) { - switch (a1) + switch (battleOutcome) { case 2: case 3: @@ -882,69 +917,69 @@ bool32 battle_exit_is_player_defeat(u32 a1) return FALSE; } -void sub_80822BC(void) +static void sub_80822BC(void) { - gTrainerBattleMode = 0; + sTrainerBattleMode = 0; gTrainerBattleOpponent = 0; - gTrainerMapObjectLocalId = 0; - gTrainerIntroSpeech = 0; - gTrainerDefeatSpeech = 0; - gTrainerVictorySpeech = 0; - gTrainerCannotBattleSpeech = 0; - gTrainerBattleScriptReturnAddress = 0; - gTrainerBattleEndScript = 0; + sTrainerMapObjectLocalId = 0; + sTrainerIntroSpeech = 0; + sTrainerDefeatSpeech = 0; + sTrainerVictorySpeech = 0; + sTrainerCannotBattleSpeech = 0; + sTrainerBattleScriptRetAddr = 0; + sTrainerBattleEndScript = 0; } -void TrainerBattleLoadArgs(const struct TrainerBattleSpec *specs, const u8 *data) +static void TrainerBattleLoadArgs(const struct TrainerBattleParameter *specs, const u8 *data) { while (1) { switch (specs->ptrType) { - case 0: - *(u8 *)specs->ptr = TrainerBattleLoadArg8(data); - data++; + case TRAINER_PARAM_LOAD_VAL_8BIT: + *(u8 *)specs->varPtr = TrainerBattleLoadArg8(data); + data += 1; break; - case 1: - *(u16 *)specs->ptr = TrainerBattleLoadArg16(data); + case TRAINER_PARAM_LOAD_VAL_16BIT: + *(u16 *)specs->varPtr = TrainerBattleLoadArg16(data); data += 2; break; - case 2: - *(u32 *)specs->ptr = TrainerBattleLoadArg32(data); + case TRAINER_PARAM_LOAD_VAL_32BIT: + *(u32 *)specs->varPtr = TrainerBattleLoadArg32(data); data += 4; break; - case 3: - *(u8 *)specs->ptr = 0; + case TRAINER_PARAM_CLEAR_VAL_8BIT: + *(u8 *)specs->varPtr = 0; break; - case 4: - *(u16 *)specs->ptr = 0; + case TRAINER_PARAM_CLEAR_VAL_16BIT: + *(u16 *)specs->varPtr = 0; break; - case 5: - *(u32 *)specs->ptr = 0; + case TRAINER_PARAM_CLEAR_VAL_32BIT: + *(u32 *)specs->varPtr = 0; break; - case 6: - *(const u8 **)specs->ptr = data; + case TRAINER_PARAM_LOAD_SCRIPT_RET_ADDR: + *(const u8 **)specs->varPtr = data; return; } specs++; } } -void battle_80801F0(void) +static void battle_80801F0(void) { - if (gTrainerMapObjectLocalId) + if (sTrainerMapObjectLocalId) { - gScriptLastTalked = gTrainerMapObjectLocalId; - gSelectedMapObject = GetFieldObjectIdByLocalIdAndMap(gTrainerMapObjectLocalId, gSaveBlock1.location.mapNum, gSaveBlock1.location.mapGroup); + gScriptLastTalked = sTrainerMapObjectLocalId; + gSelectedMapObject = GetFieldObjectIdByLocalIdAndMap(sTrainerMapObjectLocalId, gSaveBlock1.location.mapNum, gSaveBlock1.location.mapGroup); } } -u8 *TrainerBattleConfigure(const u8 *data) +u8 *BattleSetup_ConfigureTrainerBattle(const u8 *data) { sub_80822BC(); - gTrainerBattleMode = TrainerBattleLoadArg8(data); + sTrainerBattleMode = TrainerBattleLoadArg8(data); - switch (gTrainerBattleMode) + switch (sTrainerBattleMode) { case 3: TrainerBattleLoadArgs(gTrainerBattleSpecs_3, data); @@ -984,7 +1019,7 @@ void TrainerWantsBattle(u8 trainerMapObjId, u8 *trainerScript) { gSelectedMapObject = trainerMapObjId; gScriptLastTalked = gMapObjects[trainerMapObjId].localId; - TrainerBattleConfigure(trainerScript + 1); + BattleSetup_ConfigureTrainerBattle(trainerScript + 1); ScriptContext1_SetupScript(gUnknown_0819F80B); ScriptContext2_Enable(); } @@ -1002,27 +1037,27 @@ void sub_8082524(void) npc_set_running_behaviour_etc(mapObject, npc_running_behaviour_by_direction(mapObject->mapobj_unk_18)); } -u8 sub_8082558(void) +u8 ScrSpecial_GetTrainerBattleMode(void) { - return gTrainerBattleMode; + return sTrainerBattleMode; } -u8 sub_8082564(void) +u8 ScrSpecial_HasTrainerBeenFought(void) { - return FlagGet(trainerflag_opponent()); + return FlagGet(CurrentOpponentTrainerFlag()); } -void sub_808257C(void) +void SetCurrentTrainerBattledFlag(void) { - FlagSet(trainerflag_opponent()); + FlagSet(CurrentOpponentTrainerFlag()); } void unref_sub_8082590(void) { - FlagSet(trainerflag_opponent()); // duplicate function + FlagSet(CurrentOpponentTrainerFlag()); // duplicate function } -u8 trainer_flag_check(u16 flag) +u8 HasTrainerAlreadyBeenFought(u16 flag) { return FlagGet(TRAINER_FLAG_START + flag); } @@ -1034,14 +1069,14 @@ void trainer_flag_set(u16 flag) void trainer_flag_clear(u16 flag) { - FlagReset(TRAINER_FLAG_START + flag); + FlagClear(TRAINER_FLAG_START + flag); } -void sub_80825E4(void) +void BattleSetup_StartTrainerBattle(void) { gBattleTypeFlags = BATTLE_TYPE_TRAINER; gMain.savedCallback = sub_808260C; - task_add_01_battle_start_with_music_and_stats(); + StartTheBattle(); ScriptContext1_Stop(); } @@ -1051,74 +1086,77 @@ void sub_808260C(void) { SetMainCallback2(c2_exit_to_overworld_1_continue_scripts_restart_music); // link battle? } - else if (battle_exit_is_player_defeat(gBattleOutcome) == TRUE) + else if (IsPlayerDefeated(gBattleOutcome) == TRUE) { SetMainCallback2(CB2_WhiteOut); } else { SetMainCallback2(c2_exit_to_overworld_1_continue_scripts_restart_music); - sub_808257C(); + SetCurrentTrainerBattledFlag(); } } -void do_choose_name_or_words_screen(void) +void CB2_EndTrainerEyeRematchBattle(void) { if (gTrainerBattleOpponent == 1024) { SetMainCallback2(c2_exit_to_overworld_1_continue_scripts_restart_music); // link battle? } - else if (battle_exit_is_player_defeat(gBattleOutcome) == TRUE) + else if (IsPlayerDefeated(gBattleOutcome) == TRUE) { SetMainCallback2(CB2_WhiteOut); } else { SetMainCallback2(c2_exit_to_overworld_1_continue_scripts_restart_music); - sub_808257C(); - sub_8082CB8(); + SetCurrentTrainerBattledFlag(); + SetTrainerFlagsAfterTrainerEyeRematch(); } } -void sub_80826B0(void) +void ScrSpecial_StartTrainerEyeRematch(void) { gBattleTypeFlags = BATTLE_TYPE_TRAINER; - gMain.savedCallback = do_choose_name_or_words_screen; - task_add_01_battle_start_with_music_and_stats(); + gMain.savedCallback = CB2_EndTrainerEyeRematchBattle; + StartTheBattle(); ScriptContext1_Stop(); } -void sub_80826D8(void) +static u8 *GetTrainerIntroSpeech(void); +static u8 *GetTrainerNonBattlingSpeech(void); + +void ScrSpecial_ShowTrainerIntroSpeech(void) { - ShowFieldMessage(sub_808281C()); + ShowFieldMessage(GetTrainerIntroSpeech()); } -u8 *sub_80826E8(void) +u8 *BattleSetup_GetScriptAddrAfterBattle(void) { - if (gTrainerBattleScriptReturnAddress) - return gTrainerBattleScriptReturnAddress; + if (sTrainerBattleScriptRetAddr) + return sTrainerBattleScriptRetAddr; else return gUnknown_081C6C02; } -u8 *sub_8082700(void) +u8 *BattleSetup_GetTrainerPostBattleScript(void) { - if (gTrainerBattleEndScript) - return gTrainerBattleEndScript; + if (sTrainerBattleEndScript) + return sTrainerBattleEndScript; else return gUnknown_081C6C02; } -void sub_8082718(void) +void ScrSpecial_ShowTrainerNonBattlingSpeech(void) { - ShowFieldMessage(sub_8082880()); + ShowFieldMessage(GetTrainerNonBattlingSpeech()); } void PlayTrainerEncounterMusic(void) { u16 music; - if (gTrainerBattleMode != 1 && gTrainerBattleMode != 8) + if (sTrainerBattleMode != 1 && sTrainerBattleMode != 8) { switch (sub_803FC58(gTrainerBattleOpponent)) { @@ -1169,7 +1207,7 @@ void PlayTrainerEncounterMusic(void) } //Returns an empty string if a null pointer was passed, otherwise returns str -u8 *SanitizeString(const u8 *str) +static u8 *SanitizeString(const u8 *str) { if (str) return (u8 *) str; @@ -1177,9 +1215,9 @@ u8 *SanitizeString(const u8 *str) return (u8 *) gOtherText_CancelWithTerminator; } -u8 *sub_808281C(void) +static u8 *GetTrainerIntroSpeech(void) { - return SanitizeString(gTrainerIntroSpeech); + return SanitizeString(sTrainerIntroSpeech); } u8 *sub_8082830(void) @@ -1189,7 +1227,7 @@ u8 *sub_8082830(void) if (gTrainerBattleOpponent == 1024) str = sub_80BCCE8(); else - str = gTrainerDefeatSpeech; + str = sTrainerDefeatSpeech; StringExpandPlaceholders(gStringVar4, SanitizeString(str)); return gStringVar4; @@ -1197,43 +1235,43 @@ u8 *sub_8082830(void) u8 *unref_sub_808286C(void) { - return SanitizeString(gTrainerVictorySpeech); + return SanitizeString(sTrainerVictorySpeech); } -u8 *sub_8082880(void) +static u8 *GetTrainerNonBattlingSpeech(void) { - return SanitizeString(gTrainerCannotBattleSpeech); + return SanitizeString(sTrainerCannotBattleSpeech); } -s32 sub_8082894(const struct TrainerEyeTrainer *trainers, u16 trainerNum) +s32 sub_8082894(const struct TrainerEyeTrainer *trainers, u16 opponentId) { s32 i; for (i = 0; i < NUM_TRAINER_EYE_TRAINERS; i++) { - if (trainers[i].trainerNums[0] == trainerNum) + if (trainers[i].opponentIDs[0] == opponentId) return i; } return -1; } -s32 sub_80828B8(const struct TrainerEyeTrainer *trainers, u16 trainerNum) +s32 sub_80828B8(const struct TrainerEyeTrainer *trainers, u16 opponentId) { s32 i; s32 j; for (i = 0; i < NUM_TRAINER_EYE_TRAINERS; i++) { - for (j = 0; j < 5 && trainers[i].trainerNums[j] != 0; j++) + for (j = 0; j < 5 && trainers[i].opponentIDs[j] != 0; j++) { - if (trainers[i].trainerNums[j] == trainerNum) + if (trainers[i].opponentIDs[j] == opponentId) return i; } } return -1; } -bool32 sub_80828FC(const struct TrainerEyeTrainer *trainers, u16 mapGroup, u16 mapNum) +bool32 UpdateRandomTrainerEyeRematches(const struct TrainerEyeTrainer *trainers, u16 mapGroup, u16 mapNum) { int i; bool32 ret = FALSE; @@ -1243,14 +1281,19 @@ bool32 sub_80828FC(const struct TrainerEyeTrainer *trainers, u16 mapGroup, u16 m if (trainers[i].mapGroup == mapGroup && trainers[i].mapNum == mapNum) { if (gSaveBlock1.trainerRematches[i] != 0) + { + // Trainer already wants rematch. Don't bother updating it ret = TRUE; - else if (trainer_flag_check(trainers[i].trainerNums[0]) == TRUE && (Random() % 100) <= 30) + } + else if (HasTrainerAlreadyBeenFought(trainers[i].opponentIDs[0]) == TRUE + && (Random() % 100) <= 30) // 31% chance of getting a rematch { - int j = 1; + int rematches = 1; - while (j < 5 && trainers[i].trainerNums[j] != 0 && trainer_flag_check(trainers[i].trainerNums[j])) - j++; - gSaveBlock1.trainerRematches[i] = j; + while (rematches < 5 && trainers[i].opponentIDs[rematches] != 0 + && HasTrainerAlreadyBeenFought(trainers[i].opponentIDs[rematches])) + rematches++; + gSaveBlock1.trainerRematches[i] = rematches; ret = TRUE; } } @@ -1282,9 +1325,9 @@ s32 sub_80829E8(const struct TrainerEyeTrainer *trainers, u16 mapGroup, u16 mapN return 0; } -bool8 sub_8082A18(const struct TrainerEyeTrainer *trainers, u16 trainerNum) +bool8 sub_8082A18(const struct TrainerEyeTrainer *trainers, u16 opponentId) { - s32 trainerEyeIndex = sub_8082894(trainers, trainerNum); + s32 trainerEyeIndex = sub_8082894(trainers, opponentId); if (trainerEyeIndex != -1 && trainerEyeIndex < 100 && gSaveBlock1.trainerRematches[trainerEyeIndex]) return TRUE; @@ -1292,9 +1335,9 @@ bool8 sub_8082A18(const struct TrainerEyeTrainer *trainers, u16 trainerNum) return FALSE; } -bool8 sub_8082A54(const struct TrainerEyeTrainer *trainers, u16 trainerNum) +bool8 GetTrainerEyeRematchFlag(const struct TrainerEyeTrainer *trainers, u16 opponentId) { - s32 trainerEyeIndex = sub_80828B8(trainers, trainerNum); + s32 trainerEyeIndex = sub_80828B8(trainers, opponentId); if (trainerEyeIndex != -1 && trainerEyeIndex < 100 && gSaveBlock1.trainerRematches[trainerEyeIndex]) return TRUE; @@ -1302,38 +1345,38 @@ bool8 sub_8082A54(const struct TrainerEyeTrainer *trainers, u16 trainerNum) return FALSE; } -u16 sub_8082A90(const struct TrainerEyeTrainer *trainers, u16 trainerNum) +u16 sub_8082A90(const struct TrainerEyeTrainer *trainers, u16 opponentId) { int i; const struct TrainerEyeTrainer *trainer; - s32 trainerEyeIndex = sub_8082894(trainers, trainerNum); + s32 trainerEyeIndex = sub_8082894(trainers, opponentId); if (trainerEyeIndex == -1) return 0; trainer = &trainers[trainerEyeIndex]; for (i = 1; i < 5; i++) { - if (!trainer->trainerNums[i]) - return trainer->trainerNums[i - 1]; - if (!trainer_flag_check(trainer->trainerNums[i])) - return trainer->trainerNums[i]; + if (!trainer->opponentIDs[i]) + return trainer->opponentIDs[i - 1]; + if (!HasTrainerAlreadyBeenFought(trainer->opponentIDs[i])) + return trainer->opponentIDs[i]; } - return trainer->trainerNums[4]; + return trainer->opponentIDs[4]; } -void sub_8082AE4(const struct TrainerEyeTrainer *trainers, u16 trainerNum) +void ClearTrainerEyeRematchFlag(const struct TrainerEyeTrainer *trainers, u16 opponentId) { - s32 trainerEyeIndex = sub_80828B8(trainers, trainerNum); + s32 trainerEyeIndex = sub_80828B8(trainers, opponentId); if (trainerEyeIndex != -1) gSaveBlock1.trainerRematches[trainerEyeIndex] = 0; } -bool8 sub_8082B10(const struct TrainerEyeTrainer *trainers, u16 trainerNum) +bool8 sub_8082B10(const struct TrainerEyeTrainer *trainers, u16 opponentId) { - s32 trainerEyeIndex = sub_8082894(trainers, trainerNum); + s32 trainerEyeIndex = sub_8082894(trainers, opponentId); - if (trainerEyeIndex != -1 && trainer_flag_check(trainers[trainerEyeIndex].trainerNums[1])) + if (trainerEyeIndex != -1 && HasTrainerAlreadyBeenFought(trainers[trainerEyeIndex].opponentIDs[1])) return TRUE; else return FALSE; @@ -1377,7 +1420,7 @@ bool32 sub_8082BA4(void) void sub_8082BD0(u16 mapGroup, u16 mapNum) { - if (sub_8082BA4() && sub_80828FC(gTrainerEyeTrainers, mapGroup, mapNum) == TRUE) + if (sub_8082BA4() && UpdateRandomTrainerEyeRematches(gTrainerEyeTrainers, mapGroup, mapNum) == TRUE) gSaveBlock1.trainerRematchStepCounter = 0; } @@ -1391,9 +1434,9 @@ s32 unref_sub_8082C2C(u16 mapGroup, u16 mapNum) return sub_80829E8(gTrainerEyeTrainers, mapGroup, mapNum); } -u16 sub_8082C4C(u16 trainerNum) +u16 sub_8082C4C(u16 opponentId) { - return sub_8082A90(gTrainerEyeTrainers, trainerNum); + return sub_8082A90(gTrainerEyeTrainers, opponentId); } s32 sub_8082C68(void) @@ -1404,13 +1447,13 @@ s32 sub_8082C68(void) return sub_8082B10(gTrainerEyeTrainers, gTrainerBattleOpponent); } -u8 sub_8082C9C(void) +u8 ScrSpecial_GetTrainerEyeRematchFlag(void) { - return sub_8082A54(gTrainerEyeTrainers, gTrainerBattleOpponent); + return GetTrainerEyeRematchFlag(gTrainerEyeTrainers, gTrainerBattleOpponent); } -void sub_8082CB8(void) +void SetTrainerFlagsAfterTrainerEyeRematch(void) { - sub_8082AE4(gTrainerEyeTrainers, gTrainerBattleOpponent); - sub_808257C(); + ClearTrainerEyeRematchFlag(gTrainerEyeTrainers, gTrainerBattleOpponent); + SetCurrentTrainerBattledFlag(); } diff --git a/src/battle/battle_transition.c b/src/battle/battle_transition.c index 1cacb8857..53d32d03a 100644 --- a/src/battle/battle_transition.c +++ b/src/battle/battle_transition.c @@ -1,7 +1,7 @@ #include "global.h" #include "battle_transition.h" #include "main.h" -#include "rom4.h" +#include "overworld.h" #include "task.h" #include "palette.h" #include "trig.h" @@ -530,13 +530,13 @@ static const u16 sMugshotsTilemap[] = INCBIN_U16("graphics/battle_transitions/el // actual code starts here -void sub_811AABC(u8 transitionID) +void BattleTransition_StartOnField(u8 transitionID) { - gMain.callback2 = sub_8054398; + gMain.callback2 = CB2_OverworldBasic; LaunchBattleTransitionTask(transitionID); } -void sub_811AAD8(u8 transitionID) +void BattleTransition_Start(u8 transitionID) { LaunchBattleTransitionTask(transitionID); } @@ -994,10 +994,10 @@ static bool8 Phase2_Transition_PokeballsTrail_Func2(struct Task* task) rand = Random() & 1; for (i = 0; i <= 4; i++, rand ^= 1) { - gUnknown_0202FF84[0] = arr0[rand]; // x - gUnknown_0202FF84[1] = (i * 32) + 16; // y - gUnknown_0202FF84[2] = rand; - gUnknown_0202FF84[3] = arr1[i]; + gFieldEffectArguments[0] = arr0[rand]; // x + gFieldEffectArguments[1] = (i * 32) + 16; // y + gFieldEffectArguments[2] = rand; + gFieldEffectArguments[3] = arr1[i]; FieldEffectStart(FLDEFF_POKEBALL); } @@ -1017,14 +1017,14 @@ static bool8 Phase2_Transition_PokeballsTrail_Func3(struct Task* task) bool8 FldEff_Pokeball(void) { - u8 spriteID = CreateSpriteAtEnd(&sSpriteTemplate_83FD98C, gUnknown_0202FF84[0], gUnknown_0202FF84[1], 0); + u8 spriteID = CreateSpriteAtEnd(&sSpriteTemplate_83FD98C, gFieldEffectArguments[0], gFieldEffectArguments[1], 0); gSprites[spriteID].oam.priority = 0; gSprites[spriteID].oam.affineMode = 1; - gSprites[spriteID].data0 = gUnknown_0202FF84[2]; - gSprites[spriteID].data1 = gUnknown_0202FF84[3]; + gSprites[spriteID].data0 = gFieldEffectArguments[2]; + gSprites[spriteID].data1 = gFieldEffectArguments[3]; gSprites[spriteID].data2 = -1; InitSpriteAffineAnim(&gSprites[spriteID]); - StartSpriteAffineAnim(&gSprites[spriteID], gUnknown_0202FF84[2]); + StartSpriteAffineAnim(&gSprites[spriteID], gFieldEffectArguments[2]); return FALSE; } diff --git a/src/battle/post_battle_event_funcs.c b/src/battle/post_battle_event_funcs.c index 8d85705c8..27d7022fe 100644 --- a/src/battle/post_battle_event_funcs.c +++ b/src/battle/post_battle_event_funcs.c @@ -4,7 +4,7 @@ #include "load_save.h" #include "main.h" #include "pokemon.h" -#include "rom4.h" +#include "overworld.h" #include "script_pokemon_80C4.h" extern u8 gUnknown_02039324; @@ -14,7 +14,7 @@ int GameClear(void) int i; bool32 ribbonGet; - HealPlayerParty(); + ScrSpecial_HealPlayerParty(); if (FlagGet(SYS_GAME_CLEAR) == TRUE) { diff --git a/src/debug/matsuda_debug_menu.c b/src/debug/matsuda_debug_menu.c index 3665cabd8..c7d81f502 100644 --- a/src/debug/matsuda_debug_menu.c +++ b/src/debug/matsuda_debug_menu.c @@ -8,7 +8,7 @@ #include "main.h" #include "menu.h" #include "palette.h" -#include "rom4.h" +#include "overworld.h" #include "sprite.h" #include "start_menu.h" #include "string_util.h" diff --git a/src/engine/cable_club.c b/src/engine/cable_club.c index b81905cc5..7a85f2b6c 100644 --- a/src/engine/cable_club.c +++ b/src/engine/cable_club.c @@ -11,7 +11,7 @@ #include "menu.h" #include "palette.h" #include "record_mixing.h" -#include "rom4.h" +#include "overworld.h" #include "script.h" #include "script_pokemon_80C4.h" #include "songs.h" @@ -647,7 +647,7 @@ static void sub_80837EC(u8 taskId) void sub_8083820(void) { - InitSaveDialog(); + ScrSpecial_DoSaveDialog(); } static void sub_808382C(u8 taskId) diff --git a/src/engine/clock.c b/src/engine/clock.c index 1f2aac9fd..9635514d2 100644 --- a/src/engine/clock.c +++ b/src/engine/clock.c @@ -7,7 +7,7 @@ #include "field_weather.h" #include "lottery_corner.h" #include "main.h" -#include "rom4.h" +#include "overworld.h" #include "rtc.h" #include "time_events.h" #include "tv.h" diff --git a/src/engine/load_save.c b/src/engine/load_save.c index 730aea2b8..8424b1121 100644 --- a/src/engine/load_save.c +++ b/src/engine/load_save.c @@ -3,7 +3,7 @@ #include "load_save.h" #include "main.h" #include "pokemon.h" -#include "rom4.h" +#include "overworld.h" extern u8 gPlayerPartyCount; diff --git a/src/engine/main.c b/src/engine/main.c index afaa0e77a..d7c11b6c8 100644 --- a/src/engine/main.c +++ b/src/engine/main.c @@ -9,7 +9,7 @@ #include "play_time.h" #include "rng.h" #include "rom3.h" -#include "rom4.h" +#include "overworld.h" #include "rtc.h" #include "siirtc.h" #include "sound.h" diff --git a/src/engine/main_menu.c b/src/engine/main_menu.c index 3b616065b..e0af86f3d 100644 --- a/src/engine/main_menu.c +++ b/src/engine/main_menu.c @@ -10,7 +10,7 @@ #include "option_menu.h" #include "palette.h" #include "pokeball.h" -#include "rom4.h" +#include "overworld.h" #include "rtc.h" #include "save_menu_util.h" #include "songs.h" @@ -56,32 +56,14 @@ extern const union AffineAnimCmd *const gSpriteAffineAnimTable_81E79AC[]; extern u8 unk_2000000[]; -//Task data -enum { - TD_MENULAYOUT, - TD_SELECTEDMENUITEM, -}; - //Menu layouts -enum { +enum +{ HAS_NO_SAVED_GAME, //NEW GAME, OPTION HAS_SAVED_GAME, //CONTINUE, NEW GAME, OPTION HAS_MYSTERY_GIFT, //CONTINUE, NEW GAME, MYSTERY EVENTS, OPTION }; -//Task data -enum { - TD_TRAINER_SPRITE_ID = 2, //Trainer sprite being displayed during gender menu - TD_BGHOFS = 4, //Used to set REG_BG1HOFS and slide the platform around - TD_SUBTASK_DONE, //Set to true if the spawned task has finished - TD_GENDER_SELECTION, - TD_COUNTER, - TD_BIRCH_SPRITE_ID, - TD_AZURILL_SPRITE_ID, - TD_BRENDAN_SPRITE_ID, - TD_MAY_SPRITE_ID -}; - static void CB2_MainMenu(void); static void VBlankCB_MainMenu(void); static void CB2_InitMainMenuFromOptions(void); @@ -180,6 +162,9 @@ static void CB2_InitMainMenuFromOptions(void) InitMainMenu(TRUE); } +#define tMenuLayout data[0] +#define tMenuSelection data[1] + u32 InitMainMenu(u8 a1) { u16 savedIme; @@ -239,7 +224,7 @@ u32 InitMainMenu(u8 a1) | DISPCNT_WIN0_ON; taskId = CreateTask(Task_MainMenuCheckSave, 0); - gTasks[taskId].data[TD_SELECTEDMENUITEM] = 0; + gTasks[taskId].tMenuSelection = 0; return 0; } @@ -261,9 +246,9 @@ void Task_MainMenuCheckSave(u8 taskId) { case 1: if (IsMysteryGiftEnabled() == TRUE) - gTasks[taskId].data[TD_MENULAYOUT] = HAS_MYSTERY_GIFT; + gTasks[taskId].tMenuLayout = HAS_MYSTERY_GIFT; else - gTasks[taskId].data[TD_MENULAYOUT] = HAS_SAVED_GAME; + gTasks[taskId].tMenuLayout = HAS_SAVED_GAME; gTasks[taskId].func = Task_MainMenuCheckRtc; break; @@ -272,7 +257,7 @@ void Task_MainMenuCheckSave(u8 taskId) MenuPrintMessage(gSaveFileDeletedMessage, 3, 15); REG_WIN0H = WIN_RANGE(17, 223); REG_WIN0V = WIN_RANGE(113, 159); - gTasks[taskId].data[TD_MENULAYOUT] = HAS_NO_SAVED_GAME; + gTasks[taskId].tMenuLayout = HAS_NO_SAVED_GAME; gTasks[taskId].func = Task_MainMenuWaitForSaveErrorAck; break; case 255: @@ -280,17 +265,17 @@ void Task_MainMenuCheckSave(u8 taskId) MenuPrintMessage(gSaveFileCorruptMessage, 3, 15); REG_WIN0H = WIN_RANGE(17, 223); REG_WIN0V = WIN_RANGE(113, 159); - gTasks[taskId].data[TD_MENULAYOUT] = HAS_SAVED_GAME; + gTasks[taskId].tMenuLayout = HAS_SAVED_GAME; gTasks[taskId].func = Task_MainMenuWaitForSaveErrorAck; if (IsMysteryGiftEnabled() == TRUE) - gTasks[taskId].data[TD_MENULAYOUT] = HAS_MYSTERY_GIFT; + gTasks[taskId].tMenuLayout = HAS_MYSTERY_GIFT; else - gTasks[taskId].data[TD_MENULAYOUT] = HAS_SAVED_GAME; + gTasks[taskId].tMenuLayout = HAS_SAVED_GAME; break; case 0: default: - gTasks[taskId].data[TD_MENULAYOUT] = HAS_NO_SAVED_GAME; + gTasks[taskId].tMenuLayout = HAS_NO_SAVED_GAME; gTasks[taskId].func = Task_MainMenuCheckRtc; break; case 4: @@ -298,7 +283,7 @@ void Task_MainMenuCheckSave(u8 taskId) MenuPrintMessage(gBoardNotInstalledMessage, 3, 15); REG_WIN0H = WIN_RANGE(17, 223); REG_WIN0V = WIN_RANGE(113, 159); - gTasks[taskId].data[TD_MENULAYOUT] = HAS_NO_SAVED_GAME; + gTasks[taskId].tMenuLayout = HAS_NO_SAVED_GAME; gTasks[taskId].func = Task_MainMenuWaitForSaveErrorAck; return; } @@ -383,7 +368,7 @@ void Task_MainMenuDraw(u8 taskId) LoadPalette(&palette, 241, 2); } - switch (gTasks[taskId].data[TD_MENULAYOUT]) + switch (gTasks[taskId].tMenuLayout) { case HAS_NO_SAVED_GAME: default: @@ -420,7 +405,7 @@ void Task_MainMenuDraw(u8 taskId) void Task_MainMenuHighlight(u8 taskId) { - HighlightCurrentMenuItem(gTasks[taskId].data[TD_MENULAYOUT], gTasks[taskId].data[TD_SELECTEDMENUITEM]); + HighlightCurrentMenuItem(gTasks[taskId].tMenuLayout, gTasks[taskId].tMenuSelection); gTasks[taskId].func = Task_MainMenuProcessKeyInput; } @@ -444,7 +429,7 @@ bool8 MainMenuProcessKeyInput(u8 taskId) { s32 menuItemCount; - switch (gTasks[taskId].data[TD_MENULAYOUT]) + switch (gTasks[taskId].tMenuLayout) { case HAS_NO_SAVED_GAME: default: @@ -460,17 +445,17 @@ bool8 MainMenuProcessKeyInput(u8 taskId) if (gMain.newKeys & DPAD_UP) { - if (gTasks[taskId].data[TD_SELECTEDMENUITEM] > 0) + if (gTasks[taskId].tMenuSelection > 0) { - gTasks[taskId].data[TD_SELECTEDMENUITEM]--; + gTasks[taskId].tMenuSelection--; return TRUE; } } if (gMain.newKeys & DPAD_DOWN) { - if (gTasks[taskId].data[TD_SELECTEDMENUITEM] < menuItemCount - 1) + if (gTasks[taskId].tMenuSelection < menuItemCount - 1) { - gTasks[taskId].data[TD_SELECTEDMENUITEM]++; + gTasks[taskId].tMenuSelection++; return TRUE; } } @@ -499,11 +484,11 @@ void Task_MainMenuPressedA(u8 taskId) if (gPaletteFade.active) return; - switch (gTasks[taskId].data[TD_MENULAYOUT]) + switch (gTasks[taskId].tMenuLayout) { case HAS_NO_SAVED_GAME: default: - switch (gTasks[taskId].data[TD_SELECTEDMENUITEM]) + switch (gTasks[taskId].tMenuSelection) { case 0: default: @@ -515,7 +500,7 @@ void Task_MainMenuPressedA(u8 taskId) } break; case HAS_SAVED_GAME: - switch (gTasks[taskId].data[TD_SELECTEDMENUITEM]) + switch (gTasks[taskId].tMenuSelection) { case 0: default: @@ -530,7 +515,7 @@ void Task_MainMenuPressedA(u8 taskId) } break; case HAS_MYSTERY_GIFT: - switch (gTasks[taskId].data[TD_SELECTEDMENUITEM]) + switch (gTasks[taskId].tMenuSelection) { case 0: default: @@ -584,6 +569,9 @@ void Task_MainMenuPressedB(u8 taskId) } } +#undef tMenuLayout +#undef tMenuSelection + void HighlightCurrentMenuItem(u8 layout, u8 menuItem) { REG_WIN0H = WIN_RANGE(9, 231); @@ -710,6 +698,16 @@ void PrintBadgeCount(void) MenuPrint_PixelCoords(buffer, 205, 40, 1); } +#define tTrainerSpriteId data[2] +#define tBGhofs data[4] +#define tSubtaskIsDone data[5] +#define tGenderSelection data[6] +#define tFrameCounter data[7] +#define tBirchSpriteId data[8] +#define tAzurillSpriteId data[9] +#define tBrendanSpriteId data[10] +#define tMaySpriteId data[11] + static void Task_NewGameSpeech1(u8 taskId) { SetUpWindowConfig(&gWindowConfig_81E6C3C); @@ -732,25 +730,25 @@ static void Task_NewGameSpeech1(u8 taskId) BeginNormalPaletteFade(-1, 0, 0x10, 0, 0); REG_BG1CNT = BGCNT_PRIORITY(3) | BGCNT_CHARBASE(0) | BGCNT_SCREENBASE(7) | BGCNT_16COLOR | BGCNT_TXT256x256; REG_DISPCNT = DISPCNT_MODE_0 | DISPCNT_BG0_ON | DISPCNT_BG1_ON | DISPCNT_OBJ_ON | DISPCNT_OBJ_1D_MAP; - gTasks[taskId].data[TD_BGHOFS] = 0; + gTasks[taskId].tBGhofs = 0; gTasks[taskId].func = Task_NewGameSpeech2; - gTasks[taskId].data[TD_TRAINER_SPRITE_ID] = 0xFF; + gTasks[taskId].tTrainerSpriteId = 0xFF; gTasks[taskId].data[3] = 0xFF; - gTasks[taskId].data[TD_COUNTER] = 216; //Wait 3.6 seconds (216 frames) before starting speech + gTasks[taskId].tFrameCounter = 216; //Wait 3.6 seconds (216 frames) before starting speech PlayBGM(BGM_DOORO_X4); } static void Task_NewGameSpeech2(u8 taskId) { - if (gTasks[taskId].data[TD_COUNTER] != 0) + if (gTasks[taskId].tFrameCounter != 0) { - gTasks[taskId].data[TD_COUNTER]--; + gTasks[taskId].tFrameCounter--; } else { //Initialize Birch sprite - u8 spriteId = gTasks[taskId].data[TD_BIRCH_SPRITE_ID]; + u8 spriteId = gTasks[taskId].tBirchSpriteId; gSprites[spriteId].pos1.x = 136; gSprites[spriteId].pos1.y = 60; @@ -758,19 +756,19 @@ static void Task_NewGameSpeech2(u8 taskId) gSprites[spriteId].oam.objMode = ST_OAM_OBJ_BLEND; StartSpriteFadeIn(taskId, 10); StartBackgroundFadeIn(taskId, 20); - gTasks[taskId].data[TD_COUNTER] = 80; + gTasks[taskId].tFrameCounter = 80; gTasks[taskId].func = Task_NewGameSpeech3; } } static void Task_NewGameSpeech3(u8 taskId) { - if (gTasks[taskId].data[TD_SUBTASK_DONE] != FALSE) + if (gTasks[taskId].tSubtaskIsDone) { - gSprites[gTasks[taskId].data[TD_BIRCH_SPRITE_ID]].oam.objMode = ST_OAM_OBJ_NORMAL; - if (gTasks[taskId].data[TD_COUNTER]) + gSprites[gTasks[taskId].tBirchSpriteId].oam.objMode = ST_OAM_OBJ_NORMAL; + if (gTasks[taskId].tFrameCounter) { - gTasks[taskId].data[TD_COUNTER]--; + gTasks[taskId].tFrameCounter--; } else { @@ -801,7 +799,7 @@ static void Task_NewGameSpeech5(u8 taskId) static void Task_NewGameSpeech6(u8 taskId) { - u8 spriteId = gTasks[taskId].data[TD_AZURILL_SPRITE_ID]; + u8 spriteId = gTasks[taskId].tAzurillSpriteId; gSprites[spriteId].pos1.x = 104; gSprites[spriteId].pos1.y = 72; @@ -809,7 +807,7 @@ static void Task_NewGameSpeech6(u8 taskId) gSprites[spriteId].data0 = 0; CreatePokeballSprite(spriteId, gSprites[spriteId].oam.paletteNum, 0x70, 0x3A, 0, 0, 0x20, 0x0000FFFF); gTasks[taskId].func = Task_NewGameSpeech7; - gTasks[taskId].data[TD_COUNTER] = 0; + gTasks[taskId].tFrameCounter = 0; } static void Task_NewGameSpeech7(u8 taskId) @@ -817,18 +815,18 @@ static void Task_NewGameSpeech7(u8 taskId) if (IsCryFinished()) { //Go on to next sentence after frame 95 - if (gTasks[taskId].data[TD_COUNTER] > 95) + if (gTasks[taskId].tFrameCounter > 95) { MenuSetText(gSystemText_NewPara); gTasks[taskId].func = Task_NewGameSpeech8; } } - if (gTasks[taskId].data[TD_COUNTER] < 16384) + if (gTasks[taskId].tFrameCounter < 16384) { - gTasks[taskId].data[TD_COUNTER]++; + gTasks[taskId].tFrameCounter++; //Play Azurill cry at frame 32 - if (gTasks[taskId].data[TD_COUNTER] == 32) + if (gTasks[taskId].tFrameCounter == 32) PlayCry1(SPECIES_AZURILL, 0); } } @@ -859,11 +857,11 @@ static void Task_NewGameSpeech10(u8 taskId) { if (BirchSpeechUpdateWindowText()) { - gSprites[gTasks[taskId].data[TD_BIRCH_SPRITE_ID]].oam.objMode = ST_OAM_OBJ_BLEND; - gSprites[gTasks[taskId].data[TD_AZURILL_SPRITE_ID]].oam.objMode = ST_OAM_OBJ_BLEND; + gSprites[gTasks[taskId].tBirchSpriteId].oam.objMode = ST_OAM_OBJ_BLEND; + gSprites[gTasks[taskId].tAzurillSpriteId].oam.objMode = ST_OAM_OBJ_BLEND; StartSpriteFadeOut(taskId, 2); StartBackgroundFadeOut(taskId, 1); - gTasks[taskId].data[TD_COUNTER] = 64; + gTasks[taskId].tFrameCounter = 64; gTasks[taskId].func = Task_NewGameSpeech11; } } @@ -871,41 +869,41 @@ static void Task_NewGameSpeech10(u8 taskId) //Slide platform away to the right static void Task_NewGameSpeech11(u8 taskId) { - if (gTasks[taskId].data[TD_BGHOFS] != -60) + if (gTasks[taskId].tBGhofs != -60) { - gTasks[taskId].data[TD_BGHOFS] -= 2; - REG_BG1HOFS = gTasks[taskId].data[TD_BGHOFS]; + gTasks[taskId].tBGhofs -= 2; + REG_BG1HOFS = gTasks[taskId].tBGhofs; } else { - gTasks[taskId].data[TD_BGHOFS] = -60; + gTasks[taskId].tBGhofs = -60; gTasks[taskId].func = Task_NewGameSpeech12; } } static void Task_NewGameSpeech12(u8 taskId) { - if (gTasks[taskId].data[TD_SUBTASK_DONE]) + if (gTasks[taskId].tSubtaskIsDone) { //Hide Birch and Azurill - gSprites[gTasks[taskId].data[TD_BIRCH_SPRITE_ID]].invisible = TRUE; - gSprites[gTasks[taskId].data[TD_AZURILL_SPRITE_ID]].invisible = TRUE; + gSprites[gTasks[taskId].tBirchSpriteId].invisible = TRUE; + gSprites[gTasks[taskId].tAzurillSpriteId].invisible = TRUE; - if (gTasks[taskId].data[TD_COUNTER]) + if (gTasks[taskId].tFrameCounter) { - gTasks[taskId].data[TD_COUNTER]--; + gTasks[taskId].tFrameCounter--; } else { //Initialize Brendan sprite - u8 spriteId = gTasks[taskId].data[TD_BRENDAN_SPRITE_ID]; + u8 spriteId = gTasks[taskId].tBrendanSpriteId; gSprites[spriteId].pos1.x = 180; gSprites[spriteId].pos1.y = 60; gSprites[spriteId].invisible = FALSE; gSprites[spriteId].oam.objMode = ST_OAM_OBJ_BLEND; - gTasks[taskId].data[TD_TRAINER_SPRITE_ID] = spriteId; - gTasks[taskId].data[TD_GENDER_SELECTION] = 0; + gTasks[taskId].tTrainerSpriteId = spriteId; + gTasks[taskId].tGenderSelection = 0; StartSpriteFadeIn(taskId, 2); StartBackgroundFadeIn(taskId, 1); gTasks[taskId].func = Task_NewGameSpeech13; @@ -915,9 +913,9 @@ static void Task_NewGameSpeech12(u8 taskId) static void Task_NewGameSpeech13(u8 taskId) { - if (gTasks[taskId].data[TD_SUBTASK_DONE]) + if (gTasks[taskId].tSubtaskIsDone) { - gSprites[gTasks[taskId].data[TD_TRAINER_SPRITE_ID]].oam.objMode = ST_OAM_OBJ_NORMAL; + gSprites[gTasks[taskId].tTrainerSpriteId].oam.objMode = ST_OAM_OBJ_NORMAL; gTasks[taskId].func = Task_NewGameSpeech14; } } @@ -964,11 +962,11 @@ static void Task_NewGameSpeech16(u8 taskId) cursorPos = GetMenuCursorPos(); - if (cursorPos != gTasks[taskId].data[TD_GENDER_SELECTION]) + if (cursorPos != gTasks[taskId].tGenderSelection) { //Menu selection changed. Slide Brendan or May out and slide the other in - gTasks[taskId].data[TD_GENDER_SELECTION] = cursorPos; - gSprites[gTasks[taskId].data[TD_TRAINER_SPRITE_ID]].oam.objMode = ST_OAM_OBJ_BLEND; + gTasks[taskId].tGenderSelection = cursorPos; + gSprites[gTasks[taskId].tTrainerSpriteId].oam.objMode = ST_OAM_OBJ_BLEND; StartSpriteFadeOut(taskId, 0); gTasks[taskId].func = Task_NewGameSpeech17; } @@ -977,9 +975,9 @@ static void Task_NewGameSpeech16(u8 taskId) //Slide old trainer sprite off right of screen static void Task_NewGameSpeech17(u8 taskId) { - u8 spriteId = gTasks[taskId].data[TD_TRAINER_SPRITE_ID]; + u8 spriteId = gTasks[taskId].tTrainerSpriteId; - if (gTasks[taskId].data[TD_SUBTASK_DONE] == FALSE) + if (gTasks[taskId].tSubtaskIsDone == FALSE) { gSprites[spriteId].pos1.x += 4; //Move sprite right } @@ -988,14 +986,14 @@ static void Task_NewGameSpeech17(u8 taskId) gSprites[spriteId].invisible = TRUE; //Set up new trainer sprite - if (gTasks[taskId].data[TD_GENDER_SELECTION]) - spriteId = gTasks[taskId].data[TD_MAY_SPRITE_ID]; + if (gTasks[taskId].tGenderSelection) + spriteId = gTasks[taskId].tMaySpriteId; else - spriteId = gTasks[taskId].data[TD_BRENDAN_SPRITE_ID]; + spriteId = gTasks[taskId].tBrendanSpriteId; gSprites[spriteId].pos1.x = 240; gSprites[spriteId].pos1.y = 60; gSprites[spriteId].invisible = FALSE; - gTasks[taskId].data[TD_TRAINER_SPRITE_ID] = spriteId; + gTasks[taskId].tTrainerSpriteId = spriteId; gSprites[spriteId].oam.objMode = ST_OAM_OBJ_BLEND; StartSpriteFadeIn(taskId, 0); gTasks[taskId].func = Task_NewGameSpeech18; @@ -1005,7 +1003,7 @@ static void Task_NewGameSpeech17(u8 taskId) //Slide new trainer sprite from right of screen static void Task_NewGameSpeech18(u8 taskId) { - u8 spriteId = gTasks[taskId].data[TD_TRAINER_SPRITE_ID]; + u8 spriteId = gTasks[taskId].tTrainerSpriteId; if (gSprites[spriteId].pos1.x > 180) { @@ -1014,7 +1012,7 @@ static void Task_NewGameSpeech18(u8 taskId) else { gSprites[spriteId].pos1.x = 180; - if (gTasks[taskId].data[TD_SUBTASK_DONE]) + if (gTasks[taskId].tSubtaskIsDone) { gSprites[spriteId].oam.objMode = ST_OAM_OBJ_NORMAL; gTasks[taskId].func = Task_NewGameSpeech16; //Go back to gender menu @@ -1106,7 +1104,7 @@ static void Task_NewGameSpeech25(u8 taskId) case 0: //YES PlaySE(SE_SELECT); MenuZeroFillWindowRect(2, 1, 8, 7); - gSprites[gTasks[taskId].data[TD_TRAINER_SPRITE_ID]].oam.objMode = ST_OAM_OBJ_BLEND; + gSprites[gTasks[taskId].tTrainerSpriteId].oam.objMode = ST_OAM_OBJ_BLEND; StartSpriteFadeOut(taskId, 2); StartBackgroundFadeOut(taskId, 1); gTasks[taskId].func = Task_NewGameSpeech26; //Continue @@ -1122,10 +1120,10 @@ static void Task_NewGameSpeech25(u8 taskId) static void Task_NewGameSpeech26(u8 taskId) { - if (gTasks[taskId].data[TD_BGHOFS]) + if (gTasks[taskId].tBGhofs) { - gTasks[taskId].data[TD_BGHOFS] += 2; - REG_BG1HOFS = gTasks[taskId].data[TD_BGHOFS]; + gTasks[taskId].tBGhofs += 2; + REG_BG1HOFS = gTasks[taskId].tBGhofs; } else { @@ -1135,23 +1133,23 @@ static void Task_NewGameSpeech26(u8 taskId) static void Task_NewGameSpeech27(u8 taskId) { - if (gTasks[taskId].data[TD_SUBTASK_DONE]) + if (gTasks[taskId].tSubtaskIsDone) { s16 spriteId; //Hide Brendan and May sprites - spriteId = gTasks[taskId].data[TD_BRENDAN_SPRITE_ID]; + spriteId = gTasks[taskId].tBrendanSpriteId; gSprites[spriteId].invisible = TRUE; - spriteId = gTasks[taskId].data[TD_MAY_SPRITE_ID]; + spriteId = gTasks[taskId].tMaySpriteId; gSprites[spriteId].invisible = TRUE; //Fade in Birch and Azurill - spriteId = (u8)gTasks[taskId].data[TD_BIRCH_SPRITE_ID]; + spriteId = (u8)gTasks[taskId].tBirchSpriteId; gSprites[spriteId].pos1.x = 136; gSprites[spriteId].pos1.y = 64; gSprites[spriteId].invisible = FALSE; gSprites[spriteId].oam.objMode = ST_OAM_OBJ_BLEND; - spriteId = (u8)gTasks[taskId].data[TD_AZURILL_SPRITE_ID]; + spriteId = (u8)gTasks[taskId].tAzurillSpriteId; gSprites[spriteId].pos1.x = 104; gSprites[spriteId].pos1.y = 72; gSprites[spriteId].invisible = FALSE; @@ -1170,27 +1168,27 @@ static void Task_NewGameSpeech27(u8 taskId) static void Task_NewGameSpeech28(u8 taskId) { - if (gTasks[taskId].data[TD_SUBTASK_DONE]) + if (gTasks[taskId].tSubtaskIsDone) { s16 spriteId; - spriteId = gTasks[taskId].data[TD_BIRCH_SPRITE_ID]; + spriteId = gTasks[taskId].tBirchSpriteId; gSprites[spriteId].oam.objMode = ST_OAM_OBJ_NORMAL; - spriteId = gTasks[taskId].data[TD_AZURILL_SPRITE_ID]; + spriteId = gTasks[taskId].tAzurillSpriteId; gSprites[spriteId].oam.objMode = ST_OAM_OBJ_NORMAL; if (BirchSpeechUpdateWindowText()) { //Fade out Birch and Azurill - spriteId = gTasks[taskId].data[TD_BIRCH_SPRITE_ID]; + spriteId = gTasks[taskId].tBirchSpriteId; gSprites[spriteId].oam.objMode = ST_OAM_OBJ_BLEND; - spriteId = gTasks[taskId].data[TD_AZURILL_SPRITE_ID]; + spriteId = gTasks[taskId].tAzurillSpriteId; gSprites[spriteId].oam.objMode = ST_OAM_OBJ_BLEND; StartSpriteFadeOut(taskId, 2); StartBackgroundFadeOut(taskId, 1); - gTasks[taskId].data[TD_COUNTER] = 64; + gTasks[taskId].tFrameCounter = 64; gTasks[taskId].func = Task_NewGameSpeech29; } } @@ -1198,19 +1196,19 @@ static void Task_NewGameSpeech28(u8 taskId) static void Task_NewGameSpeech29(u8 taskId) { - if (gTasks[taskId].data[TD_SUBTASK_DONE]) + if (gTasks[taskId].tSubtaskIsDone) { s16 spriteId; //Hide Birch and Azurill - spriteId = gTasks[taskId].data[TD_BIRCH_SPRITE_ID]; + spriteId = gTasks[taskId].tBirchSpriteId; gSprites[spriteId].invisible = TRUE; - spriteId = gTasks[taskId].data[TD_AZURILL_SPRITE_ID]; + spriteId = gTasks[taskId].tAzurillSpriteId; gSprites[spriteId].invisible = TRUE; - if (gTasks[taskId].data[TD_COUNTER]) + if (gTasks[taskId].tFrameCounter) { - gTasks[taskId].data[TD_COUNTER]--; + gTasks[taskId].tFrameCounter--; } else { @@ -1218,14 +1216,14 @@ static void Task_NewGameSpeech29(u8 taskId) //Fade in trainer and background if (gSaveBlock2.playerGender) - spriteId = (u8)gTasks[taskId].data[TD_MAY_SPRITE_ID]; + spriteId = (u8)gTasks[taskId].tMaySpriteId; else - spriteId = (u8)gTasks[taskId].data[TD_BRENDAN_SPRITE_ID]; + spriteId = (u8)gTasks[taskId].tBrendanSpriteId; gSprites[spriteId].pos1.x = 120; gSprites[spriteId].pos1.y = 60; gSprites[spriteId].invisible = FALSE; gSprites[spriteId].oam.objMode = ST_OAM_OBJ_BLEND; - gTasks[taskId].data[TD_TRAINER_SPRITE_ID] = spriteId; + gTasks[taskId].tTrainerSpriteId = spriteId; StartSpriteFadeIn(taskId, 2); StartBackgroundFadeIn(taskId, 1); @@ -1238,18 +1236,18 @@ static void Task_NewGameSpeech29(u8 taskId) static void Task_NewGameSpeech30(u8 taskId) { - if (gTasks[taskId].data[TD_SUBTASK_DONE]) + if (gTasks[taskId].tSubtaskIsDone) { s16 spriteId; - spriteId = gTasks[taskId].data[TD_TRAINER_SPRITE_ID]; + spriteId = gTasks[taskId].tTrainerSpriteId; gSprites[spriteId].oam.objMode = ST_OAM_OBJ_NORMAL; if (BirchSpeechUpdateWindowText()) { u8 spriteId; - spriteId = gTasks[taskId].data[TD_TRAINER_SPRITE_ID]; + spriteId = gTasks[taskId].tTrainerSpriteId; gSprites[spriteId].oam.affineMode = 1; gSprites[spriteId].affineAnims = gSpriteAffineAnimTable_81E79AC; InitSpriteAffineAnim(&gSprites[spriteId]); @@ -1264,7 +1262,7 @@ static void Task_NewGameSpeech30(u8 taskId) static void Task_NewGameSpeech31(u8 taskId) { - u8 spriteId = gTasks[taskId].data[TD_TRAINER_SPRITE_ID]; + u8 spriteId = gTasks[taskId].tTrainerSpriteId; if (gSprites[spriteId].affineAnimEnded) gTasks[taskId].func = Task_NewGameSpeech32; @@ -1274,7 +1272,7 @@ static void Task_NewGameSpeech32(u8 taskId) { if (!gPaletteFade.active) { - u8 spriteId = gTasks[taskId].data[TD_TRAINER_SPRITE_ID]; + u8 spriteId = gTasks[taskId].tTrainerSpriteId; gSprites[spriteId].callback = nullsub_34; REG_DISPCNT = DISPCNT_MODE_0 | DISPCNT_OBJ_1D_MAP | DISPCNT_OBJ_ON; BeginNormalPaletteFade(0xFFFF0000, 0, 0, 0x10, 0xFFFF); @@ -1328,7 +1326,7 @@ void CB_ContinueNewGameSpeechPart2() taskId = CreateTask(Task_NewGameSpeech23, 0); - gTasks[taskId].data[TD_BGHOFS] = -60; + gTasks[taskId].tBGhofs = -60; remove_some_task(); ResetSpriteData(); @@ -1340,20 +1338,20 @@ void CB_ContinueNewGameSpeechPart2() if (gSaveBlock2.playerGender != MALE) { - gTasks[taskId].data[TD_GENDER_SELECTION] = FEMALE; - spriteId = gTasks[taskId].data[TD_MAY_SPRITE_ID]; + gTasks[taskId].tGenderSelection = FEMALE; + spriteId = gTasks[taskId].tMaySpriteId; } else { - gTasks[taskId].data[TD_GENDER_SELECTION] = MALE; - spriteId = gTasks[taskId].data[TD_BRENDAN_SPRITE_ID]; + gTasks[taskId].tGenderSelection = MALE; + spriteId = gTasks[taskId].tBrendanSpriteId; } gSprites[spriteId].pos1.x = 180; gSprites[spriteId].pos1.y = 60; gSprites[spriteId].invisible = FALSE; - gTasks[taskId].data[TD_TRAINER_SPRITE_ID] = spriteId; + gTasks[taskId].tTrainerSpriteId = spriteId; REG_BG1HOFS = -60; @@ -1412,56 +1410,67 @@ void AddBirchSpeechObjects(u8 taskId) gSprites[spriteId].callback = nullsub_34; gSprites[spriteId].oam.priority = 0; gSprites[spriteId].invisible = 1; - gTasks[taskId].data[TD_BIRCH_SPRITE_ID] = spriteId; + gTasks[taskId].tBirchSpriteId = spriteId; spriteId = CreateAzurillSprite(0x68, 0x48); gSprites[spriteId].callback = nullsub_34; gSprites[spriteId].oam.priority = 0; gSprites[spriteId].invisible = 1; - gTasks[taskId].data[TD_AZURILL_SPRITE_ID] = spriteId; + gTasks[taskId].tAzurillSpriteId = spriteId; //Create Brendan sprite spriteId = CreateTrainerSprite(0, 120, 60, 0, unk_2000000); gSprites[spriteId].callback = nullsub_34; gSprites[spriteId].invisible = 1; gSprites[spriteId].oam.priority = 0; - gTasks[taskId].data[TD_BRENDAN_SPRITE_ID] = spriteId; + gTasks[taskId].tBrendanSpriteId = spriteId; //Create May sprite spriteId = CreateTrainerSprite(1, 120, 60, 0, unk_2000000 + 0x800); gSprites[spriteId].callback = nullsub_34; gSprites[spriteId].invisible = 1; gSprites[spriteId].oam.priority = 0; - gTasks[taskId].data[TD_MAY_SPRITE_ID] = spriteId; + gTasks[taskId].tMaySpriteId = spriteId; } -enum { - TD_PARENT_TASK_ID, - TD_EVA, //EVA coefficient of REG_BLDALPHA - TD_EVB, //EVB coefficient of REG_BLDALPHA - TD_INTERVAL, - TD_FRAMECOUNTER -}; +#undef tTrainerSpriteId +#undef tBGhofs +//#undef tSubtaskIsDone +#undef tGenderSelection +#undef tFrameCounter +#undef tBirchSpriteId +#undef tAzurillSpriteId +#undef tBrendanSpriteId +#undef tMaySpriteId + + +// Sprite Fade task + +#define tMainTaskId data[0] +#define tBlendEVA data[1] +#define tBlendEVB data[2] +#define tUpdateInterval data[3] +#define tFrameCounter data[4] static void Task_SpriteFadeOut(u8 taskId) { - if (gTasks[taskId].data[TD_EVA] == 0) + if (gTasks[taskId].tBlendEVA == 0) { - gTasks[gTasks[taskId].data[TD_PARENT_TASK_ID]].data[TD_SUBTASK_DONE] = TRUE; + gTasks[gTasks[taskId].tMainTaskId].tSubtaskIsDone = TRUE; DestroyTask(taskId); } else { - if (gTasks[taskId].data[TD_FRAMECOUNTER]) + if (gTasks[taskId].tFrameCounter) { - gTasks[taskId].data[TD_FRAMECOUNTER]--; + gTasks[taskId].tFrameCounter--; } else { - gTasks[taskId].data[TD_FRAMECOUNTER] = gTasks[taskId].data[TD_INTERVAL]; - gTasks[taskId].data[TD_EVA]--; - gTasks[taskId].data[TD_EVB]++; - REG_BLDALPHA = gTasks[taskId].data[TD_EVA] + (gTasks[taskId].data[TD_EVB] * 256); + gTasks[taskId].tFrameCounter = gTasks[taskId].tUpdateInterval; + gTasks[taskId].tBlendEVA--; + gTasks[taskId].tBlendEVB++; + REG_BLDALPHA = gTasks[taskId].tBlendEVA + (gTasks[taskId].tBlendEVB * 256); } } } @@ -1474,33 +1483,33 @@ static void StartSpriteFadeOut(u8 taskId, u8 interval) REG_BLDCNT = 592; REG_BLDALPHA = 16; REG_BLDY = 0; - gTasks[taskId].data[TD_SUBTASK_DONE] = FALSE; + gTasks[taskId].tSubtaskIsDone = FALSE; newTaskId = CreateTask(Task_SpriteFadeOut, 0); - gTasks[newTaskId].data[TD_PARENT_TASK_ID] = taskId; - gTasks[newTaskId].data[TD_EVA] = 16; - gTasks[newTaskId].data[TD_EVB] = 0; - gTasks[newTaskId].data[TD_INTERVAL] = interval; - gTasks[newTaskId].data[TD_FRAMECOUNTER] = interval; + gTasks[newTaskId].tMainTaskId = taskId; + gTasks[newTaskId].tBlendEVA = 16; + gTasks[newTaskId].tBlendEVB = 0; + gTasks[newTaskId].tUpdateInterval = interval; + gTasks[newTaskId].tFrameCounter = interval; } static void Task_SpriteFadeIn(u8 taskId) { - if (gTasks[taskId].data[TD_EVA] == 16) + if (gTasks[taskId].tBlendEVA == 16) { - gTasks[gTasks[taskId].data[TD_PARENT_TASK_ID]].data[TD_SUBTASK_DONE] = TRUE; + gTasks[gTasks[taskId].tMainTaskId].tSubtaskIsDone = TRUE; DestroyTask(taskId); } - else if (gTasks[taskId].data[TD_FRAMECOUNTER]) + else if (gTasks[taskId].tFrameCounter) { - gTasks[taskId].data[TD_FRAMECOUNTER]--; + gTasks[taskId].tFrameCounter--; } else { - gTasks[taskId].data[TD_FRAMECOUNTER] = gTasks[taskId].data[TD_INTERVAL]; - gTasks[taskId].data[TD_EVA]++; - gTasks[taskId].data[TD_EVB]--; - REG_BLDALPHA = gTasks[taskId].data[TD_EVA] + (gTasks[taskId].data[TD_EVB] * 256); + gTasks[taskId].tFrameCounter = gTasks[taskId].tUpdateInterval; + gTasks[taskId].tBlendEVA++; + gTasks[taskId].tBlendEVB--; + REG_BLDALPHA = gTasks[taskId].tBlendEVA + (gTasks[taskId].tBlendEVB * 256); } } @@ -1512,36 +1521,49 @@ static void StartSpriteFadeIn(u8 taskId, u8 interval) REG_BLDCNT = 592; REG_BLDALPHA = 4096; REG_BLDY = 0; - gTasks[taskId].data[TD_SUBTASK_DONE] = FALSE; + gTasks[taskId].tSubtaskIsDone = FALSE; newTaskId = CreateTask(Task_SpriteFadeIn, 0); - gTasks[newTaskId].data[TD_PARENT_TASK_ID] = taskId; - gTasks[newTaskId].data[TD_EVA] = 0; - gTasks[newTaskId].data[TD_EVB] = 16; - gTasks[newTaskId].data[TD_INTERVAL] = interval; - gTasks[newTaskId].data[TD_FRAMECOUNTER] = interval; + gTasks[newTaskId].tMainTaskId = taskId; + gTasks[newTaskId].tBlendEVA = 0; + gTasks[newTaskId].tBlendEVB = 16; + gTasks[newTaskId].tUpdateInterval = interval; + gTasks[newTaskId].tFrameCounter = interval; } -enum { - TD_FADELEVEL = 1, - TD_DELAY, -}; +#undef tMainTaskId +#undef tBlendEVA +#undef tBlendEVB +#undef tUpdateInterval +#undef tFrameCounter + + +// Background fade task + +#define tMainTaskId data[0] +#define tFadeLevel data[1] +#define tDelay data[2] +#define tUpdateInterval data[3] +#define tFrameCounter data[4] static void HandleFloorShadowFadeOut(u8 taskId) { - if (gTasks[taskId].data[TD_DELAY]) - gTasks[taskId].data[TD_DELAY]--; + if (gTasks[taskId].tDelay) + gTasks[taskId].tDelay--; else { - if (gTasks[taskId].data[TD_FADELEVEL] == 8) + if (gTasks[taskId].tFadeLevel == 8) DestroyTask(taskId); - else if (gTasks[taskId].data[TD_FRAMECOUNTER]) - gTasks[taskId].data[TD_FRAMECOUNTER]--; else { - gTasks[taskId].data[TD_FRAMECOUNTER] = gTasks[taskId].data[TD_INTERVAL]; - gTasks[taskId].data[TD_FADELEVEL]++; - LoadPalette(&gUnknown_081E795C[gTasks[taskId].data[TD_FADELEVEL]], 1, 0x10); + if (gTasks[taskId].tFrameCounter) + gTasks[taskId].tFrameCounter--; + else + { + gTasks[taskId].tFrameCounter = gTasks[taskId].tUpdateInterval; + gTasks[taskId].tFadeLevel++; + LoadPalette(&gUnknown_081E795C[gTasks[taskId].tFadeLevel], 1, 0x10); + } } } } @@ -1550,30 +1572,30 @@ static void HandleFloorShadowFadeOut(u8 taskId) static void StartBackgroundFadeOut(u8 taskId, u8 interval) { u8 newTaskId = CreateTask(HandleFloorShadowFadeOut, 0); - gTasks[newTaskId].data[TD_PARENT_TASK_ID] = taskId; - gTasks[newTaskId].data[TD_FADELEVEL] = 0; - gTasks[newTaskId].data[TD_DELAY] = 8; - gTasks[newTaskId].data[TD_INTERVAL] = interval; - gTasks[newTaskId].data[TD_FRAMECOUNTER] = interval; + gTasks[newTaskId].tMainTaskId = taskId; + gTasks[newTaskId].tFadeLevel = 0; + gTasks[newTaskId].tDelay = 8; + gTasks[newTaskId].tUpdateInterval = interval; + gTasks[newTaskId].tFrameCounter = interval; } static void HandleFloorShadowFadeIn(u8 taskId) { - if (gTasks[taskId].data[TD_DELAY]) - gTasks[taskId].data[TD_DELAY]--; + if (gTasks[taskId].tDelay) + gTasks[taskId].tDelay--; else { - if (gTasks[taskId].data[TD_FADELEVEL] == 0) + if (gTasks[taskId].tFadeLevel == 0) DestroyTask(taskId); else { - if (gTasks[taskId].data[TD_FRAMECOUNTER]) - gTasks[taskId].data[TD_FRAMECOUNTER]--; + if (gTasks[taskId].tFrameCounter) + gTasks[taskId].tFrameCounter--; else { - gTasks[taskId].data[TD_FRAMECOUNTER] = gTasks[taskId].data[TD_INTERVAL]; - gTasks[taskId].data[TD_FADELEVEL]--; - LoadPalette(&gUnknown_081E795C[gTasks[taskId].data[TD_FADELEVEL]], 1, 0x10); + gTasks[taskId].tFrameCounter = gTasks[taskId].tUpdateInterval; + gTasks[taskId].tFadeLevel--; + LoadPalette(&gUnknown_081E795C[gTasks[taskId].tFadeLevel], 1, 0x10); } } } @@ -1583,12 +1605,18 @@ static void HandleFloorShadowFadeIn(u8 taskId) static void StartBackgroundFadeIn(u8 taskId, u8 interval) { u8 newTaskId = CreateTask(HandleFloorShadowFadeIn, 0); - gTasks[newTaskId].data[TD_PARENT_TASK_ID] = taskId; - gTasks[newTaskId].data[TD_FADELEVEL] = 8; - gTasks[newTaskId].data[TD_DELAY] = 8; - gTasks[newTaskId].data[TD_INTERVAL] = interval; - gTasks[newTaskId].data[TD_FRAMECOUNTER] = interval; -} + gTasks[newTaskId].tMainTaskId = taskId; + gTasks[newTaskId].tFadeLevel = 8; + gTasks[newTaskId].tDelay = 8; + gTasks[newTaskId].tUpdateInterval = interval; + gTasks[newTaskId].tFrameCounter = interval; +} + +#undef tMainTaskId +#undef tFadeLevel +#undef tDelay +#undef tUpdateInterval +#undef tFrameCounter static void CreateGenderMenu(u8 left, u8 top) { diff --git a/src/engine/menu.c b/src/engine/menu.c index 1096fa0bd..a9c4aaa43 100644 --- a/src/engine/menu.c +++ b/src/engine/menu.c @@ -154,9 +154,9 @@ void MenuPrint(const u8 *str, u8 left, u8 top) sub_8003460(gMenuWindowPtr, str, gMenuTextTileOffset, left, top); } -void MenuZeroFillWindowRect(u8 a1, u8 a2, u8 a3, u8 a4) +void MenuZeroFillWindowRect(u8 left, u8 top, u8 right, u8 bottom) { - ZeroFillWindowRect(gMenuWindowPtr, a1, a2, a3, a4); + ZeroFillWindowRect(gMenuWindowPtr, left, top, right, bottom); } void MenuFillWindowRectWithBlankTile(u8 left, u8 top, u8 right, u8 bottom) @@ -205,7 +205,7 @@ void MenuPrintMessage(const u8 *str, u8 left, u8 top) sub_8002EB0(gMenuWindowPtr, str, gMenuTextTileOffset, left, top); } -void sub_8072044(const u8 *str) +void MenuPrintMessageDefaultCoords(const u8 *str) { sub_8002EB0(gMenuWindowPtr, str, gMenuTextTileOffset, 2, 15); } @@ -571,7 +571,7 @@ void PrintMenuItems(u8 left, u8 top, u8 menuItemCount, const struct MenuAction m MenuPrint(menuItems[i].text, left, top + 2 * i); } -void PrintMenuItemsReordered(u8 left, u8 top, u8 menuItemCount, const struct MenuAction menuItems[], const u8 *order) +void PrintMenuItemsReordered(u8 left, u8 top, u8 menuItemCount, const struct MenuAction2 menuItems[], const u8 *order) { u8 i; diff --git a/src/engine/mystery_event_menu.c b/src/engine/mystery_event_menu.c index 46b76fd88..0e48dc177 100644 --- a/src/engine/mystery_event_menu.c +++ b/src/engine/mystery_event_menu.c @@ -94,7 +94,7 @@ static void CB2_MysteryEventMenu(void) case 1: if (gPaletteFade.active) break; - sub_8072044(gSystemText_LinkStandby); + MenuPrintMessageDefaultCoords(gSystemText_LinkStandby); gMain.state++; break; case 2: @@ -109,7 +109,7 @@ static void CB2_MysteryEventMenu(void) if ((gLinkStatus & 0x20) && (gLinkStatus & 0x1C) > 4) { PlaySE(SE_PIN); - sub_8072044(gSystemText_LoadEventPressA); + MenuPrintMessageDefaultCoords(gSystemText_LoadEventPressA); gMain.state++; } if (gMain.newKeys & B_BUTTON) @@ -128,7 +128,7 @@ static void CB2_MysteryEventMenu(void) if (GetLinkPlayerCount_2() != 2) { GetEventLoadMessage(gStringVar4, 1); - sub_8072044(gStringVar4); + MenuPrintMessageDefaultCoords(gStringVar4); gMain.state = 13; break; } @@ -158,13 +158,13 @@ static void CB2_MysteryEventMenu(void) sub_800832C(); MenuZeroFillWindowRect(6, 5, 23, 8); GetEventLoadMessage(gStringVar4, 1); - sub_8072044(gStringVar4); + MenuPrintMessageDefaultCoords(gStringVar4); gMain.state = 13; break; } else if (CheckLanguageMatch()) { - sub_8072044(gSystemText_DontCutLink); + MenuPrintMessageDefaultCoords(gSystemText_DontCutLink); gMain.state++; break; } @@ -173,7 +173,7 @@ static void CB2_MysteryEventMenu(void) CloseLink(); MenuZeroFillWindowRect(6, 5, 23, 8); GetEventLoadMessage(gStringVar4, 1); - sub_8072044(gStringVar4); + MenuPrintMessageDefaultCoords(gStringVar4); gMain.state = 13; break; } @@ -222,7 +222,7 @@ static void CB2_MysteryEventMenu(void) sub_800832C(); MenuZeroFillWindowRect(6, 5, 23, 8); GetEventLoadMessage(gStringVar4, 1); - sub_8072044(gStringVar4); + MenuPrintMessageDefaultCoords(gStringVar4); ptr = (u8 *)&gMain; offset1 = offsetof(struct Main, state); asm("" ::: "r1"); @@ -234,7 +234,7 @@ static void CB2_MysteryEventMenu(void) register u8 *ptr2 asm("r1"); register int offset3 asm("r0"); register int dummy asm("r2"); - sub_8072044(gSystemText_DontCutLink); + MenuPrintMessageDefaultCoords(gSystemText_DontCutLink); ptr2 = (u8 *)&gMain; offset3 = offsetof(struct Main, state); if (dummy) @@ -249,7 +249,7 @@ static void CB2_MysteryEventMenu(void) MenuZeroFillWindowRect(6, 5, 23, 8); label: GetEventLoadMessage(gStringVar4, 1); - sub_8072044(gStringVar4); + MenuPrintMessageDefaultCoords(gStringVar4); ptr = (u8 *)&gMain; offset2 = offsetof(struct Main, state); ptr += offset2; @@ -294,7 +294,7 @@ static void CB2_MysteryEventMenu(void) gMain.state++; break; case 12: - sub_8072044(gStringVar4); + MenuPrintMessageDefaultCoords(gStringVar4); gMain.state++; break; case 13: @@ -329,7 +329,7 @@ static void CB2_MysteryEventMenu(void) CloseLink(); MenuZeroFillWindowRect(6, 5, 23, 8); GetEventLoadMessage(gStringVar4, 1); - sub_8072044(gStringVar4); + MenuPrintMessageDefaultCoords(gStringVar4); gMain.state = 13; } } diff --git a/src/engine/naming_screen.c b/src/engine/naming_screen.c index 6c107f022..3f8417e6d 100644 --- a/src/engine/naming_screen.c +++ b/src/engine/naming_screen.c @@ -1618,7 +1618,7 @@ static void DisplaySentToPCMessage(void) StringExpandPlaceholders(gStringVar4, gOtherText_SentToPC); BasicInitMenuWindow(&gWindowConfig_81E6E88); MenuDisplayMessageBox(); - sub_8072044(gStringVar4); + MenuPrintMessageDefaultCoords(gStringVar4); } static void sub_80B753C(void) diff --git a/src/engine/record_mixing.c b/src/engine/record_mixing.c index 30bcb29d1..d02d89467 100644 --- a/src/engine/record_mixing.c +++ b/src/engine/record_mixing.c @@ -14,7 +14,7 @@ #include "menu.h" #include "mystery_event_script.h" #include "rng.h" -#include "rom4.h" +#include "overworld.h" #include "save.h" #include "script.h" #include "secret_base.h" diff --git a/src/engine/save.c b/src/engine/save.c index adf39268e..eae3f4470 100644 --- a/src/engine/save.c +++ b/src/engine/save.c @@ -3,7 +3,7 @@ #include "gba/flash_internal.h" #include "save.h" #include "load_save.h" -#include "rom4.h" +#include "overworld.h" #include "save_failed_screen.h" #define GETVALIDSTATUSBITFIELD ((1 << ARRAY_COUNT(gSaveSectionLocations)) - 1) diff --git a/src/engine/script.c b/src/engine/script.c index 8f12da437..f049b96fc 100644 --- a/src/engine/script.c +++ b/src/engine/script.c @@ -40,7 +40,7 @@ u8 SetupBytecodeScript(struct ScriptContext *ctx, const u8 *ptr) return 1; } -void SetupNativeScript(struct ScriptContext *ctx, void *ptr) +void SetupNativeScript(struct ScriptContext *ctx, bool8 (*ptr)(void)) { ctx->mode = 2; ctx->nativePtr = ptr; @@ -64,7 +64,7 @@ u8 RunScriptCommand(struct ScriptContext *ctx) case 2: if (ctx->nativePtr) { - if (ctx->nativePtr() == 1) + if (ctx->nativePtr() == TRUE) ctx->mode = 1; return 1; } @@ -228,16 +228,16 @@ void ScriptContext2_RunNewScript(const u8 *ptr) ; } -u8 *mapheader_get_tagged_pointer(u8 tag) +static u8 *mapheader_get_tagged_pointer(u8 tag) { u8 *mapScripts = gMapHeader.mapScripts; - if (!mapScripts) + if (mapScripts == NULL) return NULL; while (1) { - if (!*mapScripts) + if (*mapScripts == 0) return NULL; if (*mapScripts == tag) { @@ -248,14 +248,14 @@ u8 *mapheader_get_tagged_pointer(u8 tag) } } -void mapheader_run_script_by_tag(u8 tag) +static void mapheader_run_script_by_tag(u8 tag) { u8 *ptr = mapheader_get_tagged_pointer(tag); if (ptr) ScriptContext2_RunNewScript(ptr); } -u8 *mapheader_get_first_match_from_tagged_ptr_list(u8 tag) +static u8 *mapheader_get_first_match_from_tagged_ptr_list(u8 tag) { u8 *ptr = mapheader_get_tagged_pointer(tag); @@ -316,7 +316,7 @@ void mapheader_run_first_tag4_script_list_match(void) ScriptContext2_RunNewScript(ptr); } -u32 CalculateRamScriptChecksum(void) +static u32 CalculateRamScriptChecksum(void) { u32 i; u32 sum = 0; diff --git a/src/engine/time_events.c b/src/engine/time_events.c index e1b9a2e9e..accb03db8 100644 --- a/src/engine/time_events.c +++ b/src/engine/time_events.c @@ -4,7 +4,7 @@ #include "field_weather.h" #include "pokemon.h" #include "rng.h" -#include "rom4.h" +#include "overworld.h" #include "rtc.h" #include "script.h" #include "task.h" @@ -81,13 +81,13 @@ void UpdateShoalTideFlag(void) 1, }; - if (is_light_level_1_2_3_5_or_6(get_map_light_from_warp0())) + if (is_map_type_1_2_3_5_or_6(get_map_type_from_warp0())) { RtcCalcLocalTime(); if (tide[gLocalTime.hours]) FlagSet(SYS_SHOAL_TIDE); else - FlagReset(SYS_SHOAL_TIDE); + FlagClear(SYS_SHOAL_TIDE); } } diff --git a/src/engine/trainer_card.c b/src/engine/trainer_card.c index e64ec1c86..bcb62ede6 100644 --- a/src/engine/trainer_card.c +++ b/src/engine/trainer_card.c @@ -10,7 +10,7 @@ #include "money.h" #include "palette.h" #include "pokedex.h" -#include "rom4.h" +#include "overworld.h" #include "script_pokemon_80C4.h" #include "songs.h" #include "sound.h" diff --git a/src/field/berry.c b/src/field/berry.c index fa15672e7..d82eab2a6 100644 --- a/src/field/berry.c +++ b/src/field/berry.c @@ -974,7 +974,7 @@ const struct Berry gBerries[] = const struct BerryTree gBlankBerryTree = {0}; -extern u8 BerryTreeScript; +extern u8 S_BerryTree[]; extern u16 gScriptLastTalked; extern u16 gSpecialVar_0x8004; extern u16 gSpecialVar_0x8005; @@ -1078,7 +1078,7 @@ bool32 FieldObjectInteractionWaterBerryTree(void) bool8 IsPlayerFacingPlantedBerryTree(void) { - if (GetFieldObjectScriptPointerForComparison() == &BerryTreeScript + if (GetFieldObjectScriptPointerForComparison() == S_BerryTree && GetStageByBerryTreeId(FieldObjectGetBerryTreeId(gSelectedMapObject)) == 0) return TRUE; else @@ -1087,7 +1087,7 @@ bool8 IsPlayerFacingPlantedBerryTree(void) bool8 TryToWaterBerryTree(void) { - if (GetFieldObjectScriptPointerForComparison() != &BerryTreeScript) + if (GetFieldObjectScriptPointerForComparison() != S_BerryTree) return FALSE; else return FieldObjectInteractionWaterBerryTree(); diff --git a/src/field/berry_tag_screen.c b/src/field/berry_tag_screen.c index a965f386c..1413a02ca 100644 --- a/src/field/berry_tag_screen.c +++ b/src/field/berry_tag_screen.c @@ -10,7 +10,7 @@ #include "menu.h" #include "menu_helpers.h" #include "palette.h" -#include "rom4.h" +#include "overworld.h" #include "songs.h" #include "sound.h" #include "sprite.h" diff --git a/src/field/bike.c b/src/field/bike.c index 58a4f38f4..80cab0850 100644 --- a/src/field/bike.c +++ b/src/field/bike.c @@ -6,7 +6,7 @@ #include "flags.h" #include "global.fieldmap.h" #include "metatile_behavior.h" -#include "rom4.h" +#include "overworld.h" #include "songs.h" #include "sound.h" @@ -944,7 +944,7 @@ void GetOnOffBike(u8 var) { SetPlayerAvatarTransitionFlags(var); sav1_set_battle_music_maybe(BGM_CYCLING); - sub_8053FB0(BGM_CYCLING); + Overworld_ChangeMusicTo(BGM_CYCLING); } } diff --git a/src/field/braille_puzzles.c b/src/field/braille_puzzles.c index b8d7cd386..b11b1ff3a 100644 --- a/src/field/braille_puzzles.c +++ b/src/field/braille_puzzles.c @@ -6,6 +6,7 @@ #include "fieldmap.h" #include "flags.h" #include "main.h" +#include "map_constants.h" #include "map_obj_lock.h" #include "menu.h" #include "rom6.h" @@ -19,11 +20,13 @@ extern u8 gPlayerPartyCount; extern u8 gLastFieldPokeMenuOpened; -extern u8 gIslandCave_EventScript_OpenRegiiceChamber[]; // regiice event script +extern u8 S_OpenRegiceChamber[]; // regiice event script bool8 ShouldDoBrailleDigEffect(void) { - if (!FlagGet(SYS_BRAILLE_DIG) && (gSaveBlock1.location.mapGroup == 0x18 && gSaveBlock1.location.mapNum == 0x47)) + if (!FlagGet(SYS_BRAILLE_DIG) + && (gSaveBlock1.location.mapGroup == MAP_GROUP_SEALED_CHAMBER_OUTER_ROOM + && gSaveBlock1.location.mapNum == MAP_ID_SEALED_CHAMBER_OUTER_ROOM)) { if (gSaveBlock1.pos.x == 10 && gSaveBlock1.pos.y == 3) return TRUE; @@ -52,10 +55,11 @@ void DoBrailleDigEffect(void) bool8 CheckRelicanthWailord(void) { + // First comes Relicanth. if (GetMonData(&gPlayerParty, MON_DATA_SPECIES2, 0) == SPECIES_RELICANTH) { CalculatePlayerPartyCount(); - + // Last comes Wailord if (GetMonData(&gPlayerParty[gPlayerPartyCount - 1], MON_DATA_SPECIES2, 0) == SPECIES_WAILORD) return TRUE; } @@ -64,7 +68,7 @@ bool8 CheckRelicanthWailord(void) bool8 ShouldDoBrailleStrengthEffect(void) { - if (!FlagGet(SYS_BRAILLE_STRENGTH) && (gSaveBlock1.location.mapGroup == 0x18 && gSaveBlock1.location.mapNum == 0x6)) + if (!FlagGet(SYS_BRAILLE_STRENGTH) && (gSaveBlock1.location.mapGroup == MAP_GROUP_DESERT_RUINS && gSaveBlock1.location.mapNum == MAP_ID_DESERT_RUINS)) { if (gSaveBlock1.pos.x == 10 && gSaveBlock1.pos.y == 23) return TRUE; @@ -94,7 +98,7 @@ void DoBrailleStrengthEffect(void) bool8 ShouldDoBrailleFlyEffect(void) { - if (!FlagGet(SYS_BRAILLE_FLY) && (gSaveBlock1.location.mapGroup == 0x18 && gSaveBlock1.location.mapNum == 0x44)) + if (!FlagGet(SYS_BRAILLE_FLY) && (gSaveBlock1.location.mapGroup == MAP_GROUP_ANCIENT_TOMB && gSaveBlock1.location.mapNum == MAP_ID_ANCIENT_TOMB)) { if (gSaveBlock1.pos.x == 8 && gSaveBlock1.pos.y == 25) return TRUE; @@ -105,8 +109,8 @@ bool8 ShouldDoBrailleFlyEffect(void) void DoBrailleFlyEffect(void) { - gUnknown_0202FF84[0] = gLastFieldPokeMenuOpened; - FieldEffectStart(0x3C); + gFieldEffectArguments[0] = gLastFieldPokeMenuOpened; + FieldEffectStart(FLDEFF_USE_FLY_ANCIENT_TOMB); } bool8 FldEff_UseFlyAncientTomb(void) @@ -120,7 +124,7 @@ bool8 FldEff_UseFlyAncientTomb(void) void UseFlyAncientTomb_Callback(void) { - FieldEffectActiveListRemove(0x3C); + FieldEffectActiveListRemove(FLDEFF_USE_FLY_ANCIENT_TOMB); UseFlyAncientTomb_Finish(); } @@ -158,7 +162,7 @@ void Task_BrailleWait(u8 taskId) if (BrailleWait_CheckButtonPress() != FALSE) { MenuZeroFillScreen(); - PlaySE(5); + PlaySE(SE_SELECT); data[0] = 2; } else @@ -191,7 +195,7 @@ void Task_BrailleWait(u8 taskId) break; case 4: sub_8064E2C(); - ScriptContext1_SetupScript(gIslandCave_EventScript_OpenRegiiceChamber); + ScriptContext1_SetupScript(S_OpenRegiceChamber); DestroyTask(taskId); break; } @@ -199,14 +203,14 @@ void Task_BrailleWait(u8 taskId) bool32 BrailleWait_CheckButtonPress(void) { - u16 var = 0xFF; + u16 keyMask = A_BUTTON | B_BUTTON | START_BUTTON | SELECT_BUTTON | DPAD_ANY; - if (gSaveBlock2.optionsButtonMode == 1) - var |= 0x300; - if (gSaveBlock2.optionsButtonMode == 2) - var |= 0x200; + if (gSaveBlock2.optionsButtonMode == OPTIONS_BUTTON_MODE_LR) + keyMask |= L_BUTTON | R_BUTTON; + if (gSaveBlock2.optionsButtonMode == OPTIONS_BUTTON_MODE_L_EQUALS_A) + keyMask |= L_BUTTON; - if ((var & gMain.newKeys) != FALSE) + if (gMain.newKeys & keyMask) return TRUE; else return FALSE; diff --git a/src/field/choose_party.c b/src/field/choose_party.c index 27181cf74..9cdf63fc8 100644 --- a/src/field/choose_party.c +++ b/src/field/choose_party.c @@ -9,7 +9,7 @@ #include "pokemon_menu.h" #include "pokemon.h" #include "pokemon_summary_screen.h" -#include "rom4.h" +#include "overworld.h" #include "script.h" #include "songs.h" #include "sound.h" diff --git a/src/field/decoration.c b/src/field/decoration.c index dde364069..065afbfb6 100644 --- a/src/field/decoration.c +++ b/src/field/decoration.c @@ -1,7 +1,7 @@ #include "global.h" #include "main.h" #include "map_object_constants.h" -#include "rom4.h" +#include "overworld.h" #include "sound.h" #include "songs.h" #include "string_util.h" @@ -2322,7 +2322,7 @@ void sub_80FF474(void) { if (FlagGet(i + 0xae) == 1) { - FlagReset(i + 0xae); + FlagClear(i + 0xae); for (j=0; j<gMapHeader.events->mapObjectCount; j++) { if (gMapHeader.events->mapObjects[j].flagId == i + 0xae) diff --git a/src/field/diploma.c b/src/field/diploma.c index ba7de58aa..27601404c 100644 --- a/src/field/diploma.c +++ b/src/field/diploma.c @@ -4,7 +4,7 @@ #include "menu.h" #include "palette.h" #include "pokedex.h" -#include "rom4.h" +#include "overworld.h" #include "sprite.h" #include "string_util.h" #include "strings2.h" @@ -35,7 +35,7 @@ static void VBlankCB(void) TransferPlttBuffer(); } -void sub_8145D88(void) +void CB2_ShowDiploma(void) { u32 savedIme; diff --git a/src/field/event_data.c b/src/field/event_data.c index 0484bae02..ee475343f 100644 --- a/src/field/event_data.c +++ b/src/field/event_data.c @@ -36,10 +36,10 @@ void ClearTempFieldEventData(void) { memset(gSaveBlock1.flags, 0, TEMP_FLAGS_SIZE); memset(gSaveBlock1.vars, 0, TEMP_VARS_SIZE); - FlagReset(SYS_ENC_UP_ITEM); - FlagReset(SYS_ENC_DOWN_ITEM); - FlagReset(SYS_USE_STRENGTH); - FlagReset(SYS_CTRL_OBJ_DELETE); + FlagClear(SYS_ENC_UP_ITEM); + FlagClear(SYS_ENC_DOWN_ITEM); + FlagClear(SYS_USE_STRENGTH); + FlagClear(SYS_CTRL_OBJ_DELETE); } // probably had different flag splits at one point. @@ -53,7 +53,7 @@ void DisableNationalPokedex(void) u16 *nationalDexVar = GetVarPointer(VAR_NATIONAL_DEX); gSaveBlock2.pokedex.nationalMagic = 0; *nationalDexVar = 0; - FlagReset(SYS_NATIONAL_DEX); + FlagClear(SYS_NATIONAL_DEX); } void EnableNationalPokedex(void) @@ -77,7 +77,7 @@ bool32 IsNationalPokedexEnabled(void) void DisableMysteryGift(void) { - FlagReset(SYS_EXDATA_ENABLE); + FlagClear(SYS_EXDATA_ENABLE); } void EnableMysteryGift(void) @@ -93,7 +93,7 @@ bool32 IsMysteryGiftEnabled(void) void DisableResetRTC(void) { VarSet(VAR_RESET_RTC_ENABLE, 0); - FlagReset(SYS_RESET_RTC_ENABLE); + FlagClear(SYS_RESET_RTC_ENABLE); } void EnableResetRTC(void) @@ -162,7 +162,7 @@ u8 FlagSet(u16 id) return 0; } -u8 FlagReset(u16 id) +u8 FlagClear(u16 id) { u8 *ptr = GetFlagPointer(id); if (ptr) diff --git a/src/field/field_control_avatar.c b/src/field/field_control_avatar.c index a8f6b6b9b..ff8e8504c 100644 --- a/src/field/field_control_avatar.c +++ b/src/field/field_control_avatar.c @@ -13,7 +13,7 @@ #include "flags.h" #include "item_menu.h" #include "metatile_behavior.h" -#include "rom4.h" +#include "overworld.h" #include "safari_zone.h" #include "script.h" #include "secret_base.h" @@ -57,7 +57,7 @@ extern u8 gUnknown_081A4363[]; extern u8 gUnknown_081C346A[]; extern u8 gUnknown_081616E1[]; extern u8 Event_WorldMap[]; -extern u8 Event_RunningShoesManual[]; +extern u8 S_RunningShoesManual[]; extern u8 PictureBookShelfScript[]; extern u8 BookshelfScript[]; extern u8 PokemonCenterBookshelfScript[]; @@ -70,13 +70,13 @@ extern u8 gUnknown_0815F43A[]; extern u8 gUnknown_0815F523[]; extern u8 gUnknown_0815F528[]; extern u8 UseSurfScript[]; -extern u8 UseWaterfallScript[]; -extern u8 CannotUseWaterfallScript[]; +extern u8 S_UseWaterfall[]; +extern u8 S_CannotUseWaterfall[]; extern u8 UseDiveScript[]; -extern u8 UnderwaterUseDiveScript[]; -extern u8 GraniteCave_B1F_EventScript_1C6BC5[]; +extern u8 S_UseDiveUnderwater[]; +extern u8 S_FallDownHole[]; extern u8 gUnknown_081A14B8[]; -extern u8 Event_EggHatch[]; +extern u8 S_EggHatch[]; extern u8 gUnknown_0815FD0D[]; extern u8 gUnknown_081C6BDE[]; @@ -391,7 +391,7 @@ static u8 *sub_8068500(struct MapPosition *position, u8 b, u8 c) if (MetatileBehavior_IsRegionMap(b) == TRUE) return Event_WorldMap; if (sub_805791C(b) == TRUE) - return Event_RunningShoesManual; + return S_RunningShoesManual; if (MetatileBehavior_IsPictureBookShelf(b) == TRUE) return PictureBookShelfScript; if (MetatileBehavior_IsBookShelf(b) == TRUE) @@ -428,9 +428,9 @@ static u8 *TryGetFieldMoveScript(struct MapPosition *unused1, u8 b, u8 unused2) if (MetatileBehavior_IsWaterfall(b) == TRUE) { if (FlagGet(BADGE08_GET) == TRUE && IsPlayerSurfingNorth() == TRUE) - return UseWaterfallScript; + return S_UseWaterfall; else - return CannotUseWaterfallScript; + return S_CannotUseWaterfall; } return NULL; } @@ -447,9 +447,9 @@ static bool32 sub_8068770(void) static bool32 sub_80687A4(void) { - if (FlagGet(BADGE07_GET) && gMapHeader.mapType == 5 && sub_8068F18() == 1) + if (FlagGet(BADGE07_GET) && gMapHeader.mapType == MAP_TYPE_UNDERWATER && sub_8068F18() == 1) { - ScriptContext1_SetupScript(UnderwaterUseDiveScript); + ScriptContext1_SetupScript(S_UseDiveUnderwater); return TRUE; } return FALSE; @@ -485,7 +485,7 @@ bool8 sub_8068870(u16 a) { if (MetatileBehavior_IsCrackedFloorHole(a)) { - ScriptContext1_SetupScript(GraniteCave_B1F_EventScript_1C6BC5); + ScriptContext1_SetupScript(S_FallDownHole); return TRUE; } return FALSE; @@ -503,7 +503,7 @@ bool8 sub_8068894(void) if (sub_80422A0()) { IncrementGameStat(13); - ScriptContext1_SetupScript(Event_EggHatch); + ScriptContext1_SetupScript(S_EggHatch); return TRUE; } if (SafariZoneTakeStep() == TRUE) @@ -549,14 +549,14 @@ static bool8 overworld_poison_step(void) { u16 *ptr; - if (gMapHeader.mapType != 9) + if (gMapHeader.mapType != MAP_TYPE_SECRET_BASE) { ptr = GetVarPointer(VAR_POISON_STEP_COUNTER); (*ptr)++; (*ptr) %= 4; if (*ptr == 0) { - switch (overworld_poison()) + switch (DoPoisonFieldEffect()) { case 0: return FALSE; @@ -698,7 +698,7 @@ static void sub_8068C30(struct MapHeader *unused, s8 b, struct MapPosition *posi warp1_set_2(warpEvent->unk7, warpEvent->mapNum, warpEvent->mapGroup); sub_80535C4(position->x, position->y); - mapHeader = get_mapheader_by_bank_and_number(warpEvent->unk7, warpEvent->mapNum); + mapHeader = Overworld_GetMapHeaderByGroupAndId(warpEvent->unk7, warpEvent->mapNum); if (mapHeader->events->warps[warpEvent->mapGroup].mapNum == 0x7F) saved_warp2_set(mapHeader->events->warps[b].mapGroup, gSaveBlock1.location.mapGroup, gSaveBlock1.location.mapNum, b); } @@ -730,7 +730,7 @@ static bool8 map_warp_consider_2_to_inside(struct MapPosition *position, u16 b, return FALSE; } -static s8 map_warp_check(struct MapHeader *mapHeader, u16 b, u16 c, u8 d) +static s8 map_warp_check(struct MapHeader *mapHeader, u16 x, u16 y, u8 warpId) { s32 i; struct WarpEvent *warpEvent = mapHeader->events->warps; @@ -738,9 +738,9 @@ static s8 map_warp_check(struct MapHeader *mapHeader, u16 b, u16 c, u8 d) for (i = 0; i < warpCount; i++, warpEvent++) { - if ((u16)warpEvent->x == b && (u16)warpEvent->y == c) + if ((u16)warpEvent->x == x && (u16)warpEvent->y == y) { - if ((u8)warpEvent->warpId == d || (u8)warpEvent->warpId == 0) + if ((u8)warpEvent->warpId == warpId || (u8)warpEvent->warpId == 0) return i; } } @@ -767,7 +767,7 @@ static u8 *trigger_activate(struct CoordEvent *coordEvent) return NULL; } -static u8 *mapheader_trigger_activate_at(struct MapHeader *mapHeader, u16 b, u16 c, u8 d) +static u8 *mapheader_trigger_activate_at(struct MapHeader *mapHeader, u16 x, u16 y, u8 d) { s32 i; struct CoordEvent *coordEvents = mapHeader->events->coordEvents; @@ -776,7 +776,7 @@ static u8 *mapheader_trigger_activate_at(struct MapHeader *mapHeader, u16 b, u16 for (i = 0; i < coordEventCount; i++) { - if ((u16)coordEvents[i].x == b && (u16)coordEvents[i].y == c) + if ((u16)coordEvents[i].x == x && (u16)coordEvents[i].y == y) { if (coordEvents[i].unk4 == d || coordEvents[i].unk4 == 0) { @@ -813,7 +813,7 @@ static struct BgEvent *FindInvisibleMapObjectByPosition(struct MapHeader *mapHea int dive_warp(struct MapPosition *position, u16 b) { - if (gMapHeader.mapType == 5 && sub_805750C(b) == 0) + if (gMapHeader.mapType == MAP_TYPE_UNDERWATER && sub_805750C(b) == 0) { if (sub_80538B0(position->x - 7, position->y - 7)) { @@ -843,7 +843,7 @@ u8 sub_8068F18(void) PlayerGetDestCoords(&x, &y); r5 = MapGridGetMetatileBehaviorAt(x, y); - if (gMapHeader.mapType == 5 && sub_805750C(r5) == 0) + if (gMapHeader.mapType == MAP_TYPE_UNDERWATER && sub_805750C(r5) == 0) { if (sub_80538B0(x - 7, y - 7) == TRUE) return 1; diff --git a/src/field/field_door.c b/src/field/field_door.c index 791ed4c94..ab46f0696 100644 --- a/src/field/field_door.c +++ b/src/field/field_door.c @@ -3,6 +3,7 @@ #include "field_camera.h" #include "fieldmap.h" #include "metatile_behavior.h" +#include "songs.h" #include "task.h" extern struct DoorAnimFrame gDoorOpenAnimFrames[]; @@ -212,10 +213,10 @@ bool8 FieldIsDoorAnimationRunning(void) return FuncIsActiveTask(Task_AnimateDoor); } -u32 sub_8058790(u32 x, u32 y) +u32 GetDoorSoundEffect(u32 x, u32 y) { if (cur_mapdata_get_door_x2_at(gDoorAnimGraphicsTable, x, y) == 0) - return 8; + return SE_DOOR; else - return 18; + return SE_JIDO_DOA; } diff --git a/src/field/field_effect.c b/src/field/field_effect.c index cffed2614..0625e9d18 100644 --- a/src/field/field_effect.c +++ b/src/field/field_effect.c @@ -9,7 +9,7 @@ #include "menu.h" #include "palette.h" #include "text.h" -#include "rom4.h" +#include "overworld.h" #include "task.h" #include "sound.h" #include "songs.h" @@ -28,7 +28,7 @@ #define subsprite_table(ptr) {.subsprites = ptr, .subspriteCount = (sizeof ptr) / (sizeof(struct Subsprite))} -EWRAM_DATA u32 gUnknown_0202FF84[8] = {0}; +EWRAM_DATA u32 gFieldEffectArguments[8] = {0}; const u32 gSpriteImage_839DC14[] = INCBIN_U32("graphics/birch_speech/birch.4bpp"); const u16 gBirchPalette[16] = INCBIN_U16("graphics/birch_speech/birch.gbapal"); @@ -1203,10 +1203,10 @@ void task00_8084310(u8 taskId) { return; } - gUnknown_0202FF84[0] = gLastFieldPokeMenuOpened; - if ((int)gUnknown_0202FF84[0] > 5) + gFieldEffectArguments[0] = gLastFieldPokeMenuOpened; + if ((int)gFieldEffectArguments[0] > 5) { - gUnknown_0202FF84[0] = 0; + gFieldEffectArguments[0] = 0; } FieldEffectStart(FLDEFF_USE_FLY); task->data[0]++; @@ -1665,7 +1665,7 @@ bool8 FldEff_UseWaterfall(void) { u8 taskId; taskId = CreateTask(sub_8086F64, 0xff); - gTasks[taskId].data[1] = gUnknown_0202FF84[0]; + gTasks[taskId].data[1] = gFieldEffectArguments[0]; sub_8086F64(taskId); return FALSE; } @@ -1689,7 +1689,7 @@ bool8 waterfall_1_do_anim_probably(struct Task *task, struct MapObject *mapObjec if (!FieldObjectIsSpecialAnimOrDirectionSequenceAnimActive(mapObject)) { FieldObjectClearAnimIfSpecialAnimFinished(mapObject); - gUnknown_0202FF84[0] = task->data[1]; + gFieldEffectArguments[0] = task->data[1]; FieldEffectStart(FLDEFF_FIELD_MOVE_SHOW_MON_INIT); task->data[0]++; } @@ -1738,8 +1738,8 @@ bool8 FldEff_UseDive(void) { u8 taskId; taskId = CreateTask(Task_Dive, 0xff); - gTasks[taskId].data[15] = gUnknown_0202FF84[0]; - gTasks[taskId].data[14] = gUnknown_0202FF84[1]; + gTasks[taskId].data[15] = gFieldEffectArguments[0]; + gTasks[taskId].data[14] = gFieldEffectArguments[1]; Task_Dive(taskId); return FALSE; } @@ -1759,7 +1759,7 @@ bool8 sub_8087124(struct Task *task) bool8 dive_2_unknown(struct Task *task) { ScriptContext2_Enable(); - gUnknown_0202FF84[0] = task->data[15]; + gFieldEffectArguments[0] = task->data[15]; FieldEffectStart(FLDEFF_FIELD_MOVE_SHOW_MON_INIT); task->data[0]++; return FALSE; @@ -1820,10 +1820,10 @@ bool8 sub_8087298(struct Task *task, struct MapObject *mapObject, struct Sprite { sprite->pos2.y = 0; task->data[3] = 1; - gUnknown_0202FF84[0] = mapObject->coords2.x; - gUnknown_0202FF84[1] = mapObject->coords2.y; - gUnknown_0202FF84[2] = sprite->subpriority - 1; - gUnknown_0202FF84[3] = sprite->oam.priority; + gFieldEffectArguments[0] = mapObject->coords2.x; + gFieldEffectArguments[1] = mapObject->coords2.y; + gFieldEffectArguments[2] = sprite->subpriority - 1; + gFieldEffectArguments[3] = sprite->oam.priority; FieldEffectStart(FLDEFF_LAVARIDGE_GYM_WARP); PlaySE(SE_W153); task->data[0]++; @@ -1924,10 +1924,10 @@ bool8 sub_80874FC(struct Task *task, struct MapObject *mapObject, struct Sprite { if (sub_807D770()) { - gUnknown_0202FF84[0] = mapObject->coords2.x; - gUnknown_0202FF84[1] = mapObject->coords2.y; - gUnknown_0202FF84[2] = sprite->subpriority - 1; - gUnknown_0202FF84[3] = sprite->oam.priority; + gFieldEffectArguments[0] = mapObject->coords2.x; + gFieldEffectArguments[1] = mapObject->coords2.y; + gFieldEffectArguments[2] = sprite->subpriority - 1; + gFieldEffectArguments[3] = sprite->oam.priority; task->data[1] = FieldEffectStart(FLDEFF_POP_OUT_OF_ASH); task->data[0]++; } @@ -1966,9 +1966,9 @@ extern const struct SpriteTemplate *const gFieldEffectObjectTemplatePointers[36] u8 FldEff_LavaridgeGymWarp(void) { u8 spriteId; - sub_8060470((s16 *)&gUnknown_0202FF84[0], (s16 *)&gUnknown_0202FF84[1], 8, 8); - spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[33], gUnknown_0202FF84[0], gUnknown_0202FF84[1], gUnknown_0202FF84[2]); - gSprites[spriteId].oam.priority = gUnknown_0202FF84[3]; + sub_8060470((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 8); + spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[33], gFieldEffectArguments[0], gFieldEffectArguments[1], gFieldEffectArguments[2]); + gSprites[spriteId].oam.priority = gFieldEffectArguments[3]; gSprites[spriteId].coordOffsetEnabled = 1; return spriteId; } @@ -2009,10 +2009,10 @@ bool8 sub_80876F8(struct Task *task, struct MapObject *mapObject, struct Sprite { if (task->data[1] > 3) { - gUnknown_0202FF84[0] = mapObject->coords2.x; - gUnknown_0202FF84[1] = mapObject->coords2.y; - gUnknown_0202FF84[2] = sprite->subpriority - 1; - gUnknown_0202FF84[3] = sprite->oam.priority; + gFieldEffectArguments[0] = mapObject->coords2.x; + gFieldEffectArguments[1] = mapObject->coords2.y; + gFieldEffectArguments[2] = sprite->subpriority - 1; + gFieldEffectArguments[3] = sprite->oam.priority; task->data[1] = FieldEffectStart(FLDEFF_POP_OUT_OF_ASH); task->data[0]++; } else @@ -2064,9 +2064,9 @@ bool8 sub_80877D4(struct Task *task, struct MapObject *mapObject, struct Sprite u8 FldEff_PopOutOfAsh(void) { u8 spriteId; - sub_8060470((s16 *)&gUnknown_0202FF84[0], (s16 *)&gUnknown_0202FF84[1], 8, 8); - spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[32], gUnknown_0202FF84[0], gUnknown_0202FF84[1], gUnknown_0202FF84[2]); - gSprites[spriteId].oam.priority = gUnknown_0202FF84[3]; + sub_8060470((s16 *)&gFieldEffectArguments[0], (s16 *)&gFieldEffectArguments[1], 8, 8); + spriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[32], gFieldEffectArguments[0], gFieldEffectArguments[1], gFieldEffectArguments[2]); + gSprites[spriteId].oam.priority = gFieldEffectArguments[3]; gSprites[spriteId].coordOffsetEnabled = 1; return spriteId; } @@ -2385,26 +2385,26 @@ void sub_8088890(struct Sprite *); bool8 FldEff_FieldMoveShowMon(void) { u8 taskId; - if (is_light_level_1_2_3_5_or_6(sav1_map_get_light_level()) == TRUE) + if (is_map_type_1_2_3_5_or_6(Overworld_GetMapTypeOfSaveblockLocation()) == TRUE) { taskId = CreateTask(sub_8088120, 0xff); } else { taskId = CreateTask(sub_808847C, 0xff); } - gTasks[taskId].data[15] = sub_8088830(gUnknown_0202FF84[0], gUnknown_0202FF84[1], gUnknown_0202FF84[2]); + gTasks[taskId].data[15] = sub_8088830(gFieldEffectArguments[0], gFieldEffectArguments[1], gFieldEffectArguments[2]); return FALSE; } bool8 FldEff_FieldMoveShowMonInit(void) { struct Pokemon *pokemon; - u32 flag = gUnknown_0202FF84[0] & 0x80000000; - pokemon = &gPlayerParty[(u8)gUnknown_0202FF84[0]]; - gUnknown_0202FF84[0] = GetMonData(pokemon, MON_DATA_SPECIES); - gUnknown_0202FF84[1] = GetMonData(pokemon, MON_DATA_OT_ID); - gUnknown_0202FF84[2] = GetMonData(pokemon, MON_DATA_PERSONALITY); - gUnknown_0202FF84[0] |= flag; + u32 flag = gFieldEffectArguments[0] & 0x80000000; + pokemon = &gPlayerParty[(u8)gFieldEffectArguments[0]]; + gFieldEffectArguments[0] = GetMonData(pokemon, MON_DATA_SPECIES); + gFieldEffectArguments[1] = GetMonData(pokemon, MON_DATA_OT_ID); + gFieldEffectArguments[2] = GetMonData(pokemon, MON_DATA_PERSONALITY); + gFieldEffectArguments[0] |= flag; FieldEffectStart(FLDEFF_FIELD_MOVE_SHOW_MON); FieldEffectActiveListRemove(FLDEFF_FIELD_MOVE_SHOW_MON_INIT); return FALSE; @@ -2879,9 +2879,9 @@ u8 FldEff_UseSurf(void) { u8 taskId; taskId = CreateTask(sub_8088954, 0xff); - gTasks[taskId].data[15] = gUnknown_0202FF84[0]; + gTasks[taskId].data[15] = gFieldEffectArguments[0]; sav1_reset_battle_music_maybe(); - sub_8053FB0(0x016d); + Overworld_ChangeMusicTo(0x016d); return FALSE; } @@ -2919,7 +2919,7 @@ void sub_8088A30(struct Task *task) mapObject = &gMapObjects[gPlayerAvatar.mapObjectId]; if (FieldObjectCheckIfSpecialAnimFinishedOrInactive(mapObject)) { - gUnknown_0202FF84[0] = task->data[15] | 0x80000000; + gFieldEffectArguments[0] = task->data[15] | 0x80000000; FieldEffectStart(FLDEFF_FIELD_MOVE_SHOW_MON_INIT); task->data[0]++; } @@ -2934,9 +2934,9 @@ void sub_8088A78(struct Task *task) sub_805B980(mapObject, GetPlayerAvatarGraphicsIdByStateId(3)); FieldObjectClearAnimIfSpecialAnimFinished(mapObject); FieldObjectSetSpecialAnim(mapObject, sub_80608D0(mapObject->placeholder18)); - gUnknown_0202FF84[0] = task->data[1]; - gUnknown_0202FF84[1] = task->data[2]; - gUnknown_0202FF84[2] = gPlayerAvatar.mapObjectId; + gFieldEffectArguments[0] = task->data[1]; + gFieldEffectArguments[1] = task->data[2]; + gFieldEffectArguments[2] = gPlayerAvatar.mapObjectId; mapObject->mapobj_unk_1A = FieldEffectStart(FLDEFF_SURF_BLOB); task->data[0]++; } @@ -2970,7 +2970,7 @@ u8 FldEff_NPCFlyOut(void) sprite->oam.paletteNum = 0; sprite->oam.priority = 1; sprite->callback = sub_8088BC4; - sprite->data1 = gUnknown_0202FF84[0]; + sprite->data1 = gFieldEffectArguments[0]; PlaySE(SE_W019); return spriteId; } @@ -3009,7 +3009,7 @@ u8 FldEff_UseFly(void) { u8 taskId; taskId = CreateTask(sub_8088C70, 0xfe); - gTasks[taskId].data[1] = gUnknown_0202FF84[0]; + gTasks[taskId].data[1] = gFieldEffectArguments[0]; return 0; } @@ -3040,7 +3040,7 @@ void sub_8088CF8(struct Task *task) if (FieldObjectClearAnimIfSpecialAnimFinished(mapObject)) { task->data[0]++; - gUnknown_0202FF84[0] = task->data[1]; + gFieldEffectArguments[0] = task->data[1]; FieldEffectStart(FLDEFF_FIELD_MOVE_SHOW_MON_INIT); } } diff --git a/src/field/field_fadetransition.c b/src/field/field_fadetransition.c index e614d899a..d95177821 100644 --- a/src/field/field_fadetransition.c +++ b/src/field/field_fadetransition.c @@ -15,7 +15,7 @@ #include "map_obj_lock.h" #include "metatile_behavior.h" #include "palette.h" -#include "rom4.h" +#include "overworld.h" #include "script.h" #include "songs.h" #include "sound.h" @@ -40,8 +40,8 @@ void palette_bg_fill_black(void) void pal_fill_for_map_transition(void) { - u8 map_light = get_map_light_from_warp0(); - switch (fade_type_for_given_maplight_pair(map_light, sav1_map_get_light_level())) + u8 map_light = get_map_type_from_warp0(); + switch (fade_type_for_given_maplight_pair(map_light, Overworld_GetMapTypeOfSaveblockLocation())) { case 0: fade_screen(0, 0); @@ -61,7 +61,7 @@ void pal_fill_black(void) void fade_8080918(void) { - u8 light_level = sav1_map_get_light_level(); + u8 light_level = Overworld_GetMapTypeOfSaveblockLocation(); switch (sub_810CDB8(light_level, warp1_get_mapheader()->mapType)) { case 0: @@ -547,7 +547,7 @@ void sub_808115C(u8 taskId) case 0: FreezeMapObjects(); PlayerGetDestCoords(x, y); - PlaySE(sub_8058790(*x, *y - 1)); + PlaySE(GetDoorSoundEffect(*x, *y - 1)); task->data[1] = FieldAnimateDoorOpen(*x, *y - 1); task->data[0] = 1; break; diff --git a/src/field/field_ground_effect.c b/src/field/field_ground_effect.c index b9935463b..2a398ba22 100644 --- a/src/field/field_ground_effect.c +++ b/src/field/field_ground_effect.c @@ -460,18 +460,18 @@ void GroundEffect_SpawnOnTallGrass(struct MapObject *mapObj, struct Sprite *spri { u8 *ptr; - gUnknown_0202FF84[0] = mapObj->coords2.x; - gUnknown_0202FF84[1] = mapObj->coords2.y; - gUnknown_0202FF84[2] = mapObj->elevation; - gUnknown_0202FF84[3] = 2; - gUnknown_0202FF84[4] = (mapObj->localId << 8) | mapObj->mapNum; - gUnknown_0202FF84[5] = mapObj->mapGroup; + gFieldEffectArguments[0] = mapObj->coords2.x; + gFieldEffectArguments[1] = mapObj->coords2.y; + gFieldEffectArguments[2] = mapObj->elevation; + gFieldEffectArguments[3] = 2; + gFieldEffectArguments[4] = (mapObj->localId << 8) | mapObj->mapNum; + gFieldEffectArguments[5] = mapObj->mapGroup; ptr = (u8 *)&gSaveBlock1; - gUnknown_0202FF84[6] = ((u8)gSaveBlock1.location.mapNum << 8) + gFieldEffectArguments[6] = ((u8)gSaveBlock1.location.mapNum << 8) | (u8)gSaveBlock1.location.mapGroup; - gUnknown_0202FF84[7] = 1; + gFieldEffectArguments[7] = 1; FieldEffectStart(4); } @@ -479,18 +479,18 @@ void sub_8063E94(struct MapObject *mapObj, struct Sprite *sprite) { u8 *ptr; - gUnknown_0202FF84[0] = mapObj->coords2.x; - gUnknown_0202FF84[1] = mapObj->coords2.y; - gUnknown_0202FF84[2] = mapObj->elevation; - gUnknown_0202FF84[3] = 2; - gUnknown_0202FF84[4] = (mapObj->localId << 8) | mapObj->mapNum; - gUnknown_0202FF84[5] = mapObj->mapGroup; + gFieldEffectArguments[0] = mapObj->coords2.x; + gFieldEffectArguments[1] = mapObj->coords2.y; + gFieldEffectArguments[2] = mapObj->elevation; + gFieldEffectArguments[3] = 2; + gFieldEffectArguments[4] = (mapObj->localId << 8) | mapObj->mapNum; + gFieldEffectArguments[5] = mapObj->mapGroup; ptr = (u8 *)&gSaveBlock1; - gUnknown_0202FF84[6] = ((u8)gSaveBlock1.location.mapNum << 8) + gFieldEffectArguments[6] = ((u8)gSaveBlock1.location.mapNum << 8) | (u8)gSaveBlock1.location.mapGroup; - gUnknown_0202FF84[7] = 0; + gFieldEffectArguments[7] = 0; FieldEffectStart(4); } @@ -498,18 +498,18 @@ void sub_8063EE0(struct MapObject *mapObj, struct Sprite *sprite) { u8 *ptr; - gUnknown_0202FF84[0] = mapObj->coords2.x; - gUnknown_0202FF84[1] = mapObj->coords2.y; - gUnknown_0202FF84[2] = mapObj->elevation; - gUnknown_0202FF84[3] = 2; - gUnknown_0202FF84[4] = (mapObj->localId << 8) | mapObj->mapNum; - gUnknown_0202FF84[5] = mapObj->mapGroup; + gFieldEffectArguments[0] = mapObj->coords2.x; + gFieldEffectArguments[1] = mapObj->coords2.y; + gFieldEffectArguments[2] = mapObj->elevation; + gFieldEffectArguments[3] = 2; + gFieldEffectArguments[4] = (mapObj->localId << 8) | mapObj->mapNum; + gFieldEffectArguments[5] = mapObj->mapGroup; ptr = (u8 *)&gSaveBlock1; - gUnknown_0202FF84[6] = ((u8)gSaveBlock1.location.mapNum << 8) + gFieldEffectArguments[6] = ((u8)gSaveBlock1.location.mapNum << 8) | (u8)gSaveBlock1.location.mapGroup; - gUnknown_0202FF84[7] = 1; + gFieldEffectArguments[7] = 1; FieldEffectStart(17); } @@ -517,18 +517,18 @@ void sub_8063F2C(struct MapObject *mapObj, struct Sprite *sprite) { u8 *ptr; - gUnknown_0202FF84[0] = mapObj->coords2.x; - gUnknown_0202FF84[1] = mapObj->coords2.y; - gUnknown_0202FF84[2] = mapObj->elevation; - gUnknown_0202FF84[3] = 2; - gUnknown_0202FF84[4] = (mapObj->localId << 8) | mapObj->mapNum; - gUnknown_0202FF84[5] = mapObj->mapGroup; + gFieldEffectArguments[0] = mapObj->coords2.x; + gFieldEffectArguments[1] = mapObj->coords2.y; + gFieldEffectArguments[2] = mapObj->elevation; + gFieldEffectArguments[3] = 2; + gFieldEffectArguments[4] = (mapObj->localId << 8) | mapObj->mapNum; + gFieldEffectArguments[5] = mapObj->mapGroup; ptr = (u8 *)&gSaveBlock1; - gUnknown_0202FF84[6] = ((u8)gSaveBlock1.location.mapNum << 8) + gFieldEffectArguments[6] = ((u8)gSaveBlock1.location.mapNum << 8) | (u8)gSaveBlock1.location.mapGroup; - gUnknown_0202FF84[7] = 0; + gFieldEffectArguments[7] = 0; FieldEffectStart(17); } @@ -572,11 +572,11 @@ static void DoTracksGroundEffect_Footprints(struct MapObject *mapObj, struct Spr // First half-word is a Field Effect script id. (gFieldEffectScriptPointers) u16 sandFootprints_FieldEffectData[2] = { 0xD, 0x18 }; - gUnknown_0202FF84[0] = mapObj->coords3.x; - gUnknown_0202FF84[1] = mapObj->coords3.y; - gUnknown_0202FF84[2] = 149; - gUnknown_0202FF84[3] = 2; - gUnknown_0202FF84[4] = mapObj->mapobj_unk_18; + gFieldEffectArguments[0] = mapObj->coords3.x; + gFieldEffectArguments[1] = mapObj->coords3.y; + gFieldEffectArguments[2] = 149; + gFieldEffectArguments[3] = 2; + gFieldEffectArguments[4] = mapObj->mapobj_unk_18; FieldEffectStart(sandFootprints_FieldEffectData[a]); } @@ -598,11 +598,11 @@ static void DoTracksGroundEffect_BikeTireTracks( if (mapObj->coords2.x != mapObj->coords3.x || mapObj->coords2.y != mapObj->coords3.y) { - gUnknown_0202FF84[0] = mapObj->coords3.x; - gUnknown_0202FF84[1] = mapObj->coords3.y; - gUnknown_0202FF84[2] = 149; - gUnknown_0202FF84[3] = 2; - gUnknown_0202FF84[4] = + gFieldEffectArguments[0] = mapObj->coords3.x; + gFieldEffectArguments[1] = mapObj->coords3.y; + gFieldEffectArguments[2] = 149; + gFieldEffectArguments[3] = 2; + gFieldEffectArguments[4] = bikeTireTracks_Transitions[mapObj->mapobj_unk_20][mapObj->mapobj_unk_18 - 5]; FieldEffectStart(FLDEFF_BIKE_TIRE_TRACKS); } @@ -627,10 +627,10 @@ void GroundEffect_JumpOnTallGrass(struct MapObject *mapObj, struct Sprite *sprit { u8 spriteId; - gUnknown_0202FF84[0] = mapObj->coords2.x; - gUnknown_0202FF84[1] = mapObj->coords2.y; - gUnknown_0202FF84[2] = mapObj->elevation; - gUnknown_0202FF84[3] = 2; + gFieldEffectArguments[0] = mapObj->coords2.x; + gFieldEffectArguments[1] = mapObj->coords2.y; + gFieldEffectArguments[2] = mapObj->elevation; + gFieldEffectArguments[3] = 2; FieldEffectStart(FLDEFF_JUMP_TALL_GRASS); spriteId = sub_8126FF0( @@ -642,37 +642,37 @@ void GroundEffect_JumpOnTallGrass(struct MapObject *mapObj, struct Sprite *sprit void GroundEffect_JumpOnLongGrass(struct MapObject *mapObj, struct Sprite *sprite) { - gUnknown_0202FF84[0] = mapObj->coords2.x; - gUnknown_0202FF84[1] = mapObj->coords2.y; - gUnknown_0202FF84[2] = mapObj->elevation; - gUnknown_0202FF84[3] = 2; + gFieldEffectArguments[0] = mapObj->coords2.x; + gFieldEffectArguments[1] = mapObj->coords2.y; + gFieldEffectArguments[2] = mapObj->elevation; + gFieldEffectArguments[3] = 2; FieldEffectStart(FLDEFF_JUMP_LONG_GRASS); } void GroundEffect_JumpOnShallowWater(struct MapObject *mapObj, struct Sprite *sprite) { - gUnknown_0202FF84[0] = mapObj->coords2.x; - gUnknown_0202FF84[1] = mapObj->coords2.y; - gUnknown_0202FF84[2] = mapObj->elevation; - gUnknown_0202FF84[3] = sprite->oam.priority; + gFieldEffectArguments[0] = mapObj->coords2.x; + gFieldEffectArguments[1] = mapObj->coords2.y; + gFieldEffectArguments[2] = mapObj->elevation; + gFieldEffectArguments[3] = sprite->oam.priority; FieldEffectStart(FLDEFF_JUMP_SMALL_SPLASH); } void GroundEffect_JumpOnWater(struct MapObject *mapObj, struct Sprite *sprite) { - gUnknown_0202FF84[0] = mapObj->coords2.x; - gUnknown_0202FF84[1] = mapObj->coords2.y; - gUnknown_0202FF84[2] = mapObj->elevation; - gUnknown_0202FF84[3] = sprite->oam.priority; + gFieldEffectArguments[0] = mapObj->coords2.x; + gFieldEffectArguments[1] = mapObj->coords2.y; + gFieldEffectArguments[2] = mapObj->elevation; + gFieldEffectArguments[3] = sprite->oam.priority; FieldEffectStart(FLDEFF_JUMP_BIG_SPLASH); } void GroundEffect_JumpLandingDust(struct MapObject *mapObj, struct Sprite *sprite) { - gUnknown_0202FF84[0] = mapObj->coords2.x; - gUnknown_0202FF84[1] = mapObj->coords2.y; - gUnknown_0202FF84[2] = mapObj->elevation; - gUnknown_0202FF84[3] = sprite->oam.priority; + gFieldEffectArguments[0] = mapObj->coords2.x; + gFieldEffectArguments[1] = mapObj->coords2.y; + gFieldEffectArguments[2] = mapObj->elevation; + gFieldEffectArguments[3] = sprite->oam.priority; FieldEffectStart(FLDEFF_DUST); } @@ -688,8 +688,8 @@ void GroundEffect_HotSprings(struct MapObject *mapObj, struct Sprite *sprite) void GroundEffect_Seaweed(struct MapObject *mapObj, struct Sprite *sprite) { - gUnknown_0202FF84[0] = mapObj->coords2.x; - gUnknown_0202FF84[1] = mapObj->coords2.y; + gFieldEffectArguments[0] = mapObj->coords2.x; + gFieldEffectArguments[1] = mapObj->coords2.y; FieldEffectStart(FLDEFF_BUBBLES); } diff --git a/src/field/field_map_obj.c b/src/field/field_map_obj.c index f60b1b233..0e7cd7896 100644 --- a/src/field/field_map_obj.c +++ b/src/field/field_map_obj.c @@ -11,7 +11,7 @@ #include "fieldmap.h" #include "palette.h" #include "rng.h" -#include "rom4.h" +#include "overworld.h" #include "sprite.h" #include "metatile_behavior.h" #include "map_constants.h" @@ -3244,7 +3244,7 @@ struct MapObjectTemplate *GetFieldObjectTemplateByLocalIdAndMap(u8 localId, u8 m return FindFieldObjectTemplateInArrayByLocalId(localId, gSaveBlock1.mapObjectTemplates, gMapHeader.events->mapObjectCount); else { - struct MapHeader *mapHeader = get_mapheader_by_bank_and_number(mapGroup, mapNum); + struct MapHeader *mapHeader = Overworld_GetMapHeaderByGroupAndId(mapGroup, mapNum); return FindFieldObjectTemplateInArrayByLocalId(localId, mapHeader->events->mapObjects, mapHeader->events->mapObjectCount); } @@ -3895,11 +3895,11 @@ u8 do_berry_tree_growth_sparkle_1(struct MapObject *mapObject, struct Sprite *sp { if (!(sprite->data7 & 4) && sprite->animNum == 4) { - gUnknown_0202FF84[0] = mapObject->coords2.x; - gUnknown_0202FF84[1] = mapObject->coords2.y; - gUnknown_0202FF84[2] = sprite->subpriority - 1; - gUnknown_0202FF84[3] = sprite->oam.priority; - FieldEffectStart(0x17); + gFieldEffectArguments[0] = mapObject->coords2.x; + gFieldEffectArguments[1] = mapObject->coords2.y; + gFieldEffectArguments[2] = sprite->subpriority - 1; + gFieldEffectArguments[3] = sprite->oam.priority; + FieldEffectStart(FLDEFF_BERRY_TREE_GROWTH_SPARKLE); sprite->animNum = 0; } return 0; @@ -3934,11 +3934,11 @@ u8 do_berry_tree_growth_sparkle_2(struct MapObject *mapObject, struct Sprite *sp sprite->data1 = 3; sprite->data2 = 0; sprite->data7 |= 2; - gUnknown_0202FF84[0] = mapObject->coords2.x; - gUnknown_0202FF84[1] = mapObject->coords2.y; - gUnknown_0202FF84[2] = sprite->subpriority - 1; - gUnknown_0202FF84[3] = sprite->oam.priority; - FieldEffectStart(0x17); + gFieldEffectArguments[0] = mapObject->coords2.x; + gFieldEffectArguments[1] = mapObject->coords2.y; + gFieldEffectArguments[2] = sprite->subpriority - 1; + gFieldEffectArguments[3] = sprite->oam.priority; + FieldEffectStart(FLDEFF_BERRY_TREE_GROWTH_SPARKLE); return 1; } @@ -5086,8 +5086,8 @@ void FieldObjectCB_TreeDisguise(struct Sprite *sprite) mapObject = &gMapObjects[sprite->data0]; if (mapObject->mapobj_unk_21 == 0 || (mapObject->mapobj_unk_21 == 1 && sprite->data7 == 0)) { - FieldObjectGetLocalIdAndMap(mapObject, (u8 *)&gUnknown_0202FF84[0], (u8 *)&gUnknown_0202FF84[1], (u8 *)&gUnknown_0202FF84[2]); - mapObject->mapobj_unk_1A = FieldEffectStart(0x1c); + FieldObjectGetLocalIdAndMap(mapObject, (u8 *)&gFieldEffectArguments[0], (u8 *)&gFieldEffectArguments[1], (u8 *)&gFieldEffectArguments[2]); + mapObject->mapobj_unk_1A = FieldEffectStart(FLDEFF_TREE_DISGUISE); mapObject->mapobj_unk_21 = 1; sprite->data7 ++; } @@ -5106,8 +5106,8 @@ void FieldObjectCB_MountainDisguise(struct Sprite *sprite) mapObject = &gMapObjects[sprite->data0]; if (mapObject->mapobj_unk_21 == 0 || (mapObject->mapobj_unk_21 == 1 && sprite->data7 == 0)) { - FieldObjectGetLocalIdAndMap(mapObject, (u8 *)&gUnknown_0202FF84[0], (u8 *)&gUnknown_0202FF84[1], (u8 *)&gUnknown_0202FF84[2]); - mapObject->mapobj_unk_1A = FieldEffectStart(0x1d); + FieldObjectGetLocalIdAndMap(mapObject, (u8 *)&gFieldEffectArguments[0], (u8 *)&gFieldEffectArguments[1], (u8 *)&gFieldEffectArguments[2]); + mapObject->mapobj_unk_1A = FieldEffectStart(FLDEFF_MOUNTAIN_DISGUISE); mapObject->mapobj_unk_21 = 1; sprite->data7 ++; } @@ -5364,53 +5364,36 @@ u8 sub_805FF20(struct MapObject *mapObject, u8 direction) } bool8 IsCoordOutsideFieldObjectMovementRect(struct MapObject2 *mapObject, s16 x, s16 y); -bool8 CheckForCollisionBetweenFieldObjects(struct MapObject *mapObject, s16 x, s16 y); +static bool8 DoesObjectCollideWithObjectAt(struct MapObject *mapObject, s16 x, s16 y); bool8 IsMetatileDirectionallyImpassable(struct MapObject *mapObject, s16 x, s16 y, u8 direction); u8 npc_block_way(struct MapObject *mapObject, s16 x, s16 y, u8 direction) { if (IsCoordOutsideFieldObjectMovementRect((struct MapObject2 *)mapObject, x, y)) - { return 1; - } - if (MapGridIsImpassableAt(x, y) || GetMapBorderIdAt(x, y) == -1 || IsMetatileDirectionallyImpassable(mapObject, x, y, direction)) - { + else if (MapGridIsImpassableAt(x, y) || GetMapBorderIdAt(x, y) == -1 || IsMetatileDirectionallyImpassable(mapObject, x, y, direction)) return 2; - } else if (mapObject->mapobj_bit_15 && !CanCameraMoveInDirection(direction)) - { + else if (mapObject->mapobj_bit_15 && !CanCameraMoveInDirection(direction)) return 2; - } - if (IsZCoordMismatchAt(mapObject->mapobj_unk_0B_0, x, y)) - { + else if (IsZCoordMismatchAt(mapObject->mapobj_unk_0B_0, x, y)) return 3; - } - if (CheckForCollisionBetweenFieldObjects(mapObject, x, y)) - { + else if (DoesObjectCollideWithObjectAt(mapObject, x, y)) return 4; - } return 0; } u8 sub_8060024(struct MapObject *mapObject, s16 x, s16 y, u8 direction) { - u8 flags; - flags = 0; + u8 flags = 0; + if (IsCoordOutsideFieldObjectMovementRect((struct MapObject2 *)mapObject, x, y)) - { flags |= 1; - } if (MapGridIsImpassableAt(x, y) || GetMapBorderIdAt(x, y) == -1 || IsMetatileDirectionallyImpassable(mapObject, x, y, direction) || (mapObject->mapobj_bit_15 && !CanCameraMoveInDirection(direction))) - { flags |= 2; - } if (IsZCoordMismatchAt(mapObject->mapobj_unk_0B_0, x, y)) - { flags |= 4; - } - if (CheckForCollisionBetweenFieldObjects(mapObject, x, y)) - { + if (DoesObjectCollideWithObjectAt(mapObject, x, y)) flags |= 8; - } return flags; } @@ -5418,25 +5401,22 @@ bool8 IsCoordOutsideFieldObjectMovementRect(struct MapObject2 *mapObject, s16 x, { s16 minv; s16 maxv; + if (mapObject->mapobj_unk_19 != 0) { minv = mapObject->coords1.x - (mapObject->mapobj_unk_19); maxv = mapObject->coords1.x + (mapObject->mapobj_unk_19); if (minv > x || maxv < x) - { - return 1; - } + return TRUE; } if (mapObject->mapobj_unk_19b != 0) { minv = mapObject->coords1.y - (mapObject->mapobj_unk_19b); maxv = mapObject->coords1.y + (mapObject->mapobj_unk_19b); if (minv > y || maxv < y) - { - return 1; - } + return TRUE; } - return 0; + return FALSE; } bool8 IsMetatileDirectionallyImpassable(struct MapObject *mapObject, s16 x, s16 y, u8 direction) @@ -5448,23 +5428,19 @@ bool8 IsMetatileDirectionallyImpassable(struct MapObject *mapObject, s16 x, s16 return 0; } -bool8 CheckForCollisionBetweenFieldObjects(struct MapObject *mapObject, s16 x, s16 y) +static bool8 DoesObjectCollideWithObjectAt(struct MapObject *mapObject, s16 x, s16 y) { - struct MapObject *mapObject2; u8 i; - for (i=0; i<16; i++) + + for (i = 0; i < 16; i++) { - mapObject2 = &gMapObjects[i]; + struct MapObject *mapObject2 = &gMapObjects[i]; + if (mapObject2->active && mapObject2 != mapObject) { - if ((mapObject2->coords2.x != x || mapObject2->coords2.y != y) && (mapObject2->coords3.x != x || mapObject2->coords3.y != y)) - { - continue; - } - if (AreZCoordsCompatible(mapObject->mapobj_unk_0B_0, mapObject2->mapobj_unk_0B_0)) - { - return 1; - } + if (((mapObject2->coords2.x == x && mapObject2->coords2.y == y) || (mapObject2->coords3.x == x && mapObject2->coords3.y == y)) + && AreZCoordsCompatible(mapObject->mapobj_unk_0B_0, mapObject2->mapobj_unk_0B_0)) + return TRUE; } } return 0; @@ -7490,24 +7466,24 @@ bool8 sub_8062644(struct MapObject *mapObject, struct Sprite *sprite) bool8 do_exclamation_mark_bubble_1(struct MapObject *mapObject, struct Sprite *sprite) { - FieldObjectGetLocalIdAndMap(mapObject, (u8 *)&gUnknown_0202FF84[0], (u8 *)&gUnknown_0202FF84[1], (u8 *)&gUnknown_0202FF84[2]); - FieldEffectStart(0x0); + FieldObjectGetLocalIdAndMap(mapObject, (u8 *)&gFieldEffectArguments[0], (u8 *)&gFieldEffectArguments[1], (u8 *)&gFieldEffectArguments[2]); + FieldEffectStart(FLDEFF_EXCLAMATION_MARK_ICON_1); sprite->data2 = 1; return TRUE; } bool8 do_exclamation_mark_bubble_2(struct MapObject *mapObject, struct Sprite *sprite) { - FieldObjectGetLocalIdAndMap(mapObject, (u8 *)&gUnknown_0202FF84[0], (u8 *)&gUnknown_0202FF84[1], (u8 *)&gUnknown_0202FF84[2]); - FieldEffectStart(0x21); + FieldObjectGetLocalIdAndMap(mapObject, (u8 *)&gFieldEffectArguments[0], (u8 *)&gFieldEffectArguments[1], (u8 *)&gFieldEffectArguments[2]); + FieldEffectStart(FLDEFF_EXCLAMATION_MARK_ICON_2); sprite->data2 = 1; return TRUE; } bool8 do_heart_bubble(struct MapObject *mapObject, struct Sprite *sprite) { - FieldObjectGetLocalIdAndMap(mapObject, (u8 *)&gUnknown_0202FF84[0], (u8 *)&gUnknown_0202FF84[1], (u8 *)&gUnknown_0202FF84[2]); - FieldEffectStart(0x2e); + FieldObjectGetLocalIdAndMap(mapObject, (u8 *)&gFieldEffectArguments[0], (u8 *)&gFieldEffectArguments[1], (u8 *)&gFieldEffectArguments[2]); + FieldEffectStart(FLDEFF_HEART_ICON); sprite->data2 = 1; return TRUE; } @@ -8303,12 +8279,12 @@ void sub_80634A0(struct MapObject *mapObject, struct Sprite *sprite) } void sub_80634E8(struct MapObject *, struct Sprite *); -void npc_update_obj_anim_flag(struct MapObject *, struct Sprite *); +static void UpdateMapObjSpriteVisibility(struct MapObject *, struct Sprite *); void sub_80634D0(struct MapObject *mapObject, struct Sprite *sprite) { sub_80634E8(mapObject, sprite); - npc_update_obj_anim_flag(mapObject, sprite); + UpdateMapObjSpriteVisibility(mapObject, sprite); } #ifdef NONMATCHING @@ -8464,7 +8440,7 @@ _080635C0:\n\ } #endif -void npc_update_obj_anim_flag(struct MapObject *mapObject, struct Sprite *sprite) +void UpdateMapObjSpriteVisibility(struct MapObject *mapObject, struct Sprite *sprite) { sprite->invisible = 0; if (mapObject->mapobj_bit_13 || mapObject->mapobj_bit_14) diff --git a/src/field/field_map_obj_helpers.c b/src/field/field_map_obj_helpers.c index 87be8e011..93cd57557 100644 --- a/src/field/field_map_obj_helpers.c +++ b/src/field/field_map_obj_helpers.c @@ -294,7 +294,7 @@ void sub_8064990(u8 a1, u8 dir) u32 oe_exec_and_other_stuff(u8 fieldEffectId, struct MapObject *mapObject) { - FieldObjectGetLocalIdAndMap(mapObject, (u8 *)&gUnknown_0202FF84[0], (u8 *)&gUnknown_0202FF84[1], (u8 *)&gUnknown_0202FF84[2]); + FieldObjectGetLocalIdAndMap(mapObject, (u8 *)&gFieldEffectArguments[0], (u8 *)&gFieldEffectArguments[1], (u8 *)&gFieldEffectArguments[2]); return FieldEffectStart(fieldEffectId); } @@ -310,9 +310,9 @@ void DoShadowFieldEffect(struct MapObject *mapObject) void DoRippleFieldEffect(struct MapObject *mapObject, struct Sprite *sprite) { const struct MapObjectGraphicsInfo *gfxInfo = GetFieldObjectGraphicsInfo(mapObject->graphicsId); - gUnknown_0202FF84[0] = sprite->pos1.x; - gUnknown_0202FF84[1] = sprite->pos1.y + (gfxInfo->height >> 1) - 2; - gUnknown_0202FF84[2] = 151; - gUnknown_0202FF84[3] = 3; - FieldEffectStart(5); + gFieldEffectArguments[0] = sprite->pos1.x; + gFieldEffectArguments[1] = sprite->pos1.y + (gfxInfo->height >> 1) - 2; + gFieldEffectArguments[2] = 151; + gFieldEffectArguments[3] = 3; + FieldEffectStart(FLDEFF_RIPPLE); } diff --git a/src/field/field_player_avatar.c b/src/field/field_player_avatar.c index 2a7b2f3e0..c8099a73d 100644 --- a/src/field/field_player_avatar.c +++ b/src/field/field_player_avatar.c @@ -14,7 +14,7 @@ #include "metatile_behavior.h" #include "party_menu.h" #include "rng.h" -#include "rom4.h" +#include "overworld.h" #include "rotating_gate.h" #include "script.h" #include "songs.h" @@ -666,10 +666,10 @@ void PlayerAvatarTransition_Surfing(struct MapObject *a) sub_805B980(a, GetPlayerAvatarGraphicsIdByStateId(3)); FieldObjectTurn(a, a->placeholder18); SetPlayerAvatarStateMask(8); - gUnknown_0202FF84[0] = a->coords2.x; - gUnknown_0202FF84[1] = a->coords2.y; - gUnknown_0202FF84[2] = gPlayerAvatar.mapObjectId; - unk = FieldEffectStart(8); + gFieldEffectArguments[0] = a->coords2.x; + gFieldEffectArguments[1] = a->coords2.y; + gFieldEffectArguments[2] = gPlayerAvatar.mapObjectId; + unk = FieldEffectStart(FLDEFF_SURF_BLOB); a->mapobj_unk_1A = unk; sub_8127ED0(unk, 1); } @@ -1226,11 +1226,11 @@ u8 sub_8059EA4(struct Task *task, struct MapObject *b, struct MapObject *c) FieldObjectClearAnimIfSpecialAnimFinished(c); FieldObjectSetSpecialAnim(b, GetStepInPlaceDelay16AnimId(task->data[2])); FieldObjectSetSpecialAnim(c, GetSimpleGoAnimId(task->data[2])); - gUnknown_0202FF84[0] = c->coords2.x; - gUnknown_0202FF84[1] = c->coords2.y; - gUnknown_0202FF84[2] = c->elevation; - gUnknown_0202FF84[3] = gSprites[c->spriteId].oam.priority; - FieldEffectStart(10); + gFieldEffectArguments[0] = c->coords2.x; + gFieldEffectArguments[1] = c->coords2.y; + gFieldEffectArguments[2] = c->elevation; + gFieldEffectArguments[3] = gSprites[c->spriteId].oam.priority; + FieldEffectStart(FLDEFF_DUST); PlaySE(SE_W070); task->data[0]++; } @@ -1406,7 +1406,7 @@ static void sub_805A2D0(u8 taskId) /* Fishing */ -static u8 (*const gUnknown_0830FCB4[])(struct Task *) = +static u8 (*const sFishingStateFuncs[])(struct Task *) = { Fishing1, Fishing2, @@ -1429,17 +1429,33 @@ static u8 (*const gUnknown_0830FCB4[])(struct Task *) = static void Task_Fishing(u8 taskId); static void sub_805A954(void); -void StartFishing(u8 a) +#define tStep data[0] +#define tFrameCounter data[1] +#define tNumDots data[2] +#define tDotsRequired data[3] +#define tRoundsPlayed data[12] +#define tMinRoundsRequired data[13] +#define tPlayerGfxId data[14] +#define tFishingRod data[15] + +#define FISHING_START_ROUND 3 +#define FISHING_GOT_BITE 6 +#define FISHING_ON_HOOK 9 +#define FISHING_NO_BITE 11 +#define FISHING_GOT_AWAY 12 +#define FISHING_SHOW_RESULT 13 + +void StartFishing(u8 rod) { u8 taskId = CreateTask(Task_Fishing, 0xFF); - gTasks[taskId].data[15] = a; + gTasks[taskId].tFishingRod = rod; Task_Fishing(taskId); } static void Task_Fishing(u8 taskId) { - while (gUnknown_0830FCB4[gTasks[taskId].data[0]](&gTasks[taskId])) + while (sFishingStateFuncs[gTasks[taskId].tStep](&gTasks[taskId])) ; } @@ -1447,7 +1463,7 @@ u8 Fishing1(struct Task *task) { ScriptContext2_Enable(); gPlayerAvatar.unk6 = 1; - task->data[0]++; + task->tStep++; return 0; } @@ -1457,23 +1473,25 @@ u8 Fishing2(struct Task *task) const s16 arr1[] = {1, 1, 1}; const s16 arr2[] = {1, 3, 6}; - task->data[12] = 0; - task->data[13] = arr1[task->data[15]] + (Random() % arr2[task->data[15]]); - task->data[14] = gMapObjects[gPlayerAvatar.mapObjectId].graphicsId; + task->tRoundsPlayed = 0; + task->tMinRoundsRequired = arr1[task->tFishingRod] + (Random() % arr2[task->tFishingRod]); + task->tPlayerGfxId = gMapObjects[gPlayerAvatar.mapObjectId].graphicsId; playerMapObj = &gMapObjects[gPlayerAvatar.mapObjectId]; FieldObjectClearAnimIfSpecialAnimActive(playerMapObj); playerMapObj->mapobj_bit_11 = 1; sub_8059C3C(playerMapObj->mapobj_unk_18); - task->data[0]++; + task->tStep++; return 0; } u8 Fishing3(struct Task *task) { sub_805A954(); - task->data[1]++; - if (task->data[1] > 0x3B) - task->data[0]++; + + // Wait one second before starting dot game + task->tFrameCounter++; + if (task->tFrameCounter >= 60) + task->tStep++; return 0; } @@ -1482,87 +1500,92 @@ u8 Fishing4(struct Task *task) u32 randVal; MenuDisplayMessageBox(); - task->data[0]++; - task->data[1] = 0; - task->data[2] = 0; + task->tStep++; + task->tFrameCounter = 0; + task->tNumDots = 0; randVal = Random(); randVal %= 10; - task->data[3] = randVal + 1; - if (task->data[12] == 0) - task->data[3] = randVal + 4; - if (task->data[3] > 9) - task->data[3] = 10; + task->tDotsRequired = randVal + 1; + if (task->tRoundsPlayed == 0) + task->tDotsRequired = randVal + 4; + if (task->tDotsRequired >= 10) + task->tDotsRequired = 10; return 1; } +// Play a round of the dot game u8 Fishing5(struct Task *task) { const u8 dot[] = _("·"); sub_805A954(); - task->data[1]++; + task->tFrameCounter++; if (gMain.newKeys & A_BUTTON) { - task->data[0] = 11; - if (task->data[12] != 0) - task->data[0] = 12; + task->tStep = FISHING_NO_BITE; + if (task->tRoundsPlayed != 0) + task->tStep = FISHING_GOT_AWAY; return 1; } else { - if (task->data[1] > 0x13) + if (task->tFrameCounter >= 20) { - task->data[1] = 0; - if (task->data[2] >= task->data[3]) + task->tFrameCounter = 0; + if (task->tNumDots >= task->tDotsRequired) { - task->data[0]++; - if (task->data[12] != 0) - task->data[0]++; - task->data[12]++; + task->tStep++; + if (task->tRoundsPlayed != 0) + task->tStep++; + task->tRoundsPlayed++; } else { - MenuPrint(dot, task->data[2] + 4, 15); - task->data[2]++; + MenuPrint(dot, task->tNumDots + 4, 15); + task->tNumDots++; } } return 0; } } +// Determine if fish bites u8 Fishing6(struct Task *task) { sub_805A954(); - task->data[0]++; - if (!GetFishingWildMonListHeader() || (Random() & 1)) - task->data[0] = 11; + task->tStep++; + if (!DoesCurrentMapHaveFishingMons() || (Random() & 1)) + task->tStep = FISHING_NO_BITE; else StartSpriteAnim(&gSprites[gPlayerAvatar.spriteId], sub_805FE08(player_get_direction_lower_nybble())); return 1; } +// Oh! A Bite! u8 Fishing7(struct Task *task) { sub_805A954(); MenuPrint(gOtherText_OhABite, 4, 17); - task->data[0]++; - task->data[1] = 0; + task->tStep++; + task->tFrameCounter = 0; return 0; } +// We have a bite. Now, wait for the player to press A, or the timer to expire. u8 Fishing8(struct Task *task) { - const s16 arr[3] = {36, 33, 30}; + const s16 reelTimeouts[3] = {36, 33, 30}; sub_805A954(); - task->data[1]++; - if (task->data[1] >= arr[task->data[15]]) - task->data[0] = 12; + task->tFrameCounter++; + if (task->tFrameCounter >= reelTimeouts[task->tFishingRod]) + task->tStep = FISHING_GOT_AWAY; else if (gMain.newKeys & A_BUTTON) - task->data[0]++; + task->tStep++; return 0; } +// Determine if we're going to play the dot game again u8 Fishing9(struct Task *task) { const s16 arr[][2] = @@ -1573,17 +1596,18 @@ u8 Fishing9(struct Task *task) }; sub_805A954(); - task->data[0]++; - if (task->data[12] < task->data[13]) + task->tStep++; + if (task->tRoundsPlayed < task->tMinRoundsRequired) { - task->data[0] = 3; + task->tStep = FISHING_START_ROUND; } - else if (task->data[12] < 2) + else if (task->tRoundsPlayed < 2) { - s16 randVal = Random() % 100; + // probability of having to play another round + s16 probability = Random() % 100; - if (arr[task->data[15]][task->data[12]] > randVal) - task->data[0] = 3; + if (arr[task->tFishingRod][task->tRoundsPlayed] > probability) + task->tStep = FISHING_START_ROUND; } return 0; } @@ -1591,72 +1615,73 @@ u8 Fishing9(struct Task *task) u8 Fishing10(struct Task *task) { sub_805A954(); - sub_8072044(gOtherText_PokeOnHook); + MenuPrintMessageDefaultCoords(gOtherText_PokeOnHook); MenuDisplayMessageBox(); - task->data[0]++; - task->data[1] = 0; + task->tStep++; + task->tFrameCounter = 0; return 0; } u8 Fishing11(struct Task *task) { - if (task->data[1] == 0) - { + if (task->tFrameCounter == 0) sub_805A954(); - if (task->data[1] == 0) + + if (task->tFrameCounter == 0) + { + if (MenuUpdateWindowText()) { - if (MenuUpdateWindowText()) - { - struct MapObject *playerMapObj = &gMapObjects[gPlayerAvatar.mapObjectId]; - - sub_805B980(playerMapObj, task->data[14]); - FieldObjectTurn(playerMapObj, playerMapObj->placeholder18); - if (gPlayerAvatar.flags & PLAYER_AVATAR_FLAG_SURFING) - sub_8127F28(gMapObjects[gPlayerAvatar.mapObjectId].mapobj_unk_1A, 0, 0); - gSprites[gPlayerAvatar.spriteId].pos2.x = 0; - gSprites[gPlayerAvatar.spriteId].pos2.y = 0; - MenuZeroFillScreen(); - task->data[1]++; - return 0; - } - else - { - if (task->data[1] == 0) - return 0; - } + struct MapObject *playerMapObj = &gMapObjects[gPlayerAvatar.mapObjectId]; + + sub_805B980(playerMapObj, task->tPlayerGfxId); + FieldObjectTurn(playerMapObj, playerMapObj->placeholder18); + if (gPlayerAvatar.flags & PLAYER_AVATAR_FLAG_SURFING) + sub_8127F28(gMapObjects[gPlayerAvatar.mapObjectId].mapobj_unk_1A, 0, 0); + gSprites[gPlayerAvatar.spriteId].pos2.x = 0; + gSprites[gPlayerAvatar.spriteId].pos2.y = 0; + MenuZeroFillScreen(); + task->tFrameCounter++; + return 0; } } - gPlayerAvatar.unk6 = 0; - ScriptContext2_Disable(); - FishingWildEncounter(task->data[15]); - sub_80BE97C(1); - DestroyTask(FindTaskIdByFunc(Task_Fishing)); + + if (task->tFrameCounter != 0) + { + gPlayerAvatar.unk6 = 0; + ScriptContext2_Disable(); + FishingWildEncounter(task->tFishingRod); + sub_80BE97C(1); + DestroyTask(FindTaskIdByFunc(Task_Fishing)); + } return 0; } +// Not even a nibble u8 Fishing12(struct Task *task) { sub_805A954(); StartSpriteAnim(&gSprites[gPlayerAvatar.spriteId], sub_805FDF8(player_get_direction_lower_nybble())); - sub_8072044(gOtherText_NotEvenANibble); - task->data[0] = 13; + MenuPrintMessageDefaultCoords(gOtherText_NotEvenANibble); + task->tStep = FISHING_SHOW_RESULT; return 1; } +// It got away u8 Fishing13(struct Task *task) { sub_805A954(); StartSpriteAnim(&gSprites[gPlayerAvatar.spriteId], sub_805FDF8(player_get_direction_lower_nybble())); - sub_8072044(gOtherText_ItGotAway); - task->data[0]++; + MenuPrintMessageDefaultCoords(gOtherText_ItGotAway); + task->tStep++; return 1; } +// Display the message u8 Fishing14(struct Task *task) { sub_805A954(); MenuDisplayMessageBox(); - task->data[0]++; + task->tStep++; return 0; } @@ -1667,13 +1692,13 @@ u8 Fishing15(struct Task *task) { struct MapObject *playerMapObj = &gMapObjects[gPlayerAvatar.mapObjectId]; - sub_805B980(playerMapObj, task->data[14]); + sub_805B980(playerMapObj, task->tPlayerGfxId); FieldObjectTurn(playerMapObj, playerMapObj->placeholder18); if (gPlayerAvatar.flags & PLAYER_AVATAR_FLAG_SURFING) sub_8127F28(gMapObjects[gPlayerAvatar.mapObjectId].mapobj_unk_1A, 0, 0); gSprites[gPlayerAvatar.spriteId].pos2.x = 0; gSprites[gPlayerAvatar.spriteId].pos2.y = 0; - task->data[0]++; + task->tStep++; } return 0; } @@ -1692,6 +1717,10 @@ u8 Fishing16(struct Task *task) return 0; } +#undef tStep +#undef tFrameCounter +#undef tFishingRod + static void sub_805A954(void) { struct Sprite *playerSprite = &gSprites[gPlayerAvatar.spriteId]; diff --git a/src/field/field_poison.c b/src/field/field_poison.c index 8c9e029e1..1244b9c62 100644 --- a/src/field/field_poison.c +++ b/src/field/field_poison.c @@ -108,7 +108,7 @@ void ExecuteWhiteOut(void) ScriptContext1_Stop(); } -s32 overworld_poison(void) +s32 DoPoisonFieldEffect(void) { struct Pokemon *pkmn = &gPlayerParty[0]; u32 numPoisoned = 0; diff --git a/src/field/field_screen_effect.c b/src/field/field_screen_effect.c index 79913e1c5..1464a99b1 100644 --- a/src/field/field_screen_effect.c +++ b/src/field/field_screen_effect.c @@ -3,7 +3,7 @@ #include "field_camera.h" #include "menu.h" #include "palette.h" -#include "rom4.h" +#include "overworld.h" #include "script.h" #include "task.h" #include "text.h" @@ -21,11 +21,11 @@ extern u16 gUnknown_03004DE0[][0x3C0]; const static u16 gUnknown_0839ACDC[] = { 0xC8, 0x48, 0x38, 0x28, 0x18, 0x0 }; -const s32 gUnknown_0839ACE8 = 4; +const s32 gMaxFlashLevel = 4; -const static u32 gUnknown_0839ACEC[3] = +const static struct UnknownTaskStruct gUnknown_0839ACEC = { - REG_ADDR_WIN0H, + (void *)REG_ADDR_WIN0H, ((DMA_ENABLE | DMA_START_HBLANK | DMA_REPEAT | DMA_DEST_RELOAD) << 16) | 1, 1 }; @@ -137,11 +137,11 @@ static u8 sub_8081534(s32 a1, s32 a2, s32 a3, s32 a4, s32 a5, u8 a6) void sub_8081594(u8 a1) { - u8 index = sav1_get_flash_used_on_map(); + u8 flashLevel = Overworld_GetFlashLevel(); u8 value = 0; if (!a1) value = 1; - sub_8081534(120, 80, gUnknown_0839ACDC[index], gUnknown_0839ACDC[a1], value, 1); + sub_8081534(120, 80, gUnknown_0839ACDC[flashLevel], gUnknown_0839ACDC[a1], value, 1); sub_8081510(); ScriptContext2_Enable(); } @@ -220,7 +220,8 @@ static void sub_80816A8(u8 taskId) REG_WINOUT = 30; sub_8081398(&gUnknown_03004DE0[0][0], data[2], data[3], 1); CpuFastSet(&gUnknown_03004DE0[0], &gUnknown_03004DE0[1], 480); - sub_80895F8(gUnknown_0839ACEC[0], gUnknown_0839ACEC[1], gUnknown_0839ACEC[2]); + //sub_80895F8(gUnknown_0839ACEC[0], gUnknown_0839ACEC[1], gUnknown_0839ACEC[2]); + sub_80895F8(gUnknown_0839ACEC); data[0] = 1; break; case 1: diff --git a/src/field/field_special_scene.c b/src/field/field_special_scene.c index 82a7a13e3..38c076c51 100644 --- a/src/field/field_special_scene.c +++ b/src/field/field_special_scene.c @@ -8,7 +8,7 @@ #include "fieldmap.h" #include "main.h" #include "palette.h" -#include "rom4.h" +#include "overworld.h" #include "script.h" #include "script_movement.h" #include "songs.h" @@ -273,7 +273,7 @@ void Task_HandlePorthole(u8 taskId) case IDLE_CHECK: // idle and move. if (gMain.newKeys & A_BUTTON) data[1] = 1; - if (!sub_80A212C(0xFF, location->mapNum, location->mapGroup)) + if (!ScriptMovement_IsObjectMovementFinished(0xFF, location->mapNum, location->mapGroup)) return; if (CountSSTidalStep(1) == TRUE) { @@ -294,18 +294,18 @@ void Task_HandlePorthole(u8 taskId) // run this once. if (*var == 2) // which direction? { - exec_movement(0xFF, location->mapNum, location->mapGroup, gUnknown_083D295F); + ScriptMovement_StartObjectMovementScript(0xFF, location->mapNum, location->mapGroup, gUnknown_083D295F); data[0] = IDLE_CHECK; // run case 1. } else { - exec_movement(0xFF, location->mapNum, location->mapGroup, gUnknown_083D2961); + ScriptMovement_StartObjectMovementScript(0xFF, location->mapNum, location->mapGroup, gUnknown_083D2961); data[0] = IDLE_CHECK; // run case 1. } break; case EXIT_PORTHOLE: // exit porthole. - FlagReset(0x4001); - FlagReset(0x4000); + FlagClear(0x4001); + FlagClear(0x4000); copy_saved_warp2_bank_and_enter_x_to_warp1(0); sp13E_warp_to_last_warp(); DestroyTask(taskId); diff --git a/src/field/field_specials.c b/src/field/field_specials.c index 454bd8d96..c23ea2ddc 100644 --- a/src/field/field_specials.c +++ b/src/field/field_specials.c @@ -12,7 +12,7 @@ #include "field_player_avatar.h" #include "main.h" #include "map_constants.h" -#include "rom4.h" +#include "overworld.h" #include "script.h" #include "songs.h" #include "string_util.h" @@ -61,44 +61,44 @@ static void RecordCyclingRoadResults(u32, u8); static struct ElevatorMenu gUnknown_03000760[20]; -void sub_810D6A4(void) { - SetMainCallback2(sub_8145D88); +void ScrSpecial_ShowDiploma(void) +{ + SetMainCallback2(CB2_ShowDiploma); ScriptContext2_Enable(); } -void sub_810D6B8(void) { +void ScrSpecial_ViewWallClock(void) +{ gMain.savedCallback = c2_exit_to_overworld_2_switch; SetMainCallback2(CB2_ViewWallClock); ScriptContext2_Enable(); } -void ResetCyclingRoadChallengeData(void) { +void ResetCyclingRoadChallengeData(void) +{ gUnknown_02039250 = 0; gUnknown_02039251 = 0; gUnknown_02039254 = 0; } -void BeginCyclingRoadChallenge(void) { +void ScrSpecial_BeginCyclingRoadChallenge(void) +{ gUnknown_02039250 = 1; gUnknown_02039251 = 0; gUnknown_02039254 = gMain.vblankCounter1; } -u16 GetPlayerAvatarBike(void) { +u16 GetPlayerAvatarBike(void) +{ if (TestPlayerAvatarFlags(PLAYER_AVATAR_FLAG_ACRO_BIKE)) - { return 1; - } - if (TestPlayerAvatarFlags(PLAYER_AVATAR_FLAG_MACH_BIKE)) - { return 2; - } - return 0; } -void DetermineCyclingRoadResults(u32 arg0, u8 arg1) { +static void DetermineCyclingRoadResults(u32 arg0, u8 arg1) +{ u8 result; if (arg1 <= 99) @@ -225,7 +225,7 @@ void SetSSTidalFlag(void) void ResetSSTidalFlag(void) { - FlagReset(SYS_CRUISE_MODE); + FlagClear(SYS_CRUISE_MODE); } bool32 CountSSTidalStep(u16 delta) @@ -1453,7 +1453,7 @@ void ResetTrickHouseEndRoomFlag(void) u16 *specVar = &gSpecialVar_0x8004; u16 flag = 0x259; *specVar = flag; - FlagReset(flag); + FlagClear(flag); } bool8 CheckLeadMonCool(void) @@ -1868,7 +1868,7 @@ void GivLeadMonEffortRibbon(void) SetMonData(&gPlayerParty[GetLeadMonIndex()], MON_DATA_EFFORT_RIBBON, &ribbonSet); } -bool8 GetLeadMonEVCount(void) +bool8 ScrSpecial_AreLeadMonEVsMaxedOut(void) { if (GetMonEVCount(&gPlayerParty[GetLeadMonIndex()]) >= 510) { @@ -1919,7 +1919,7 @@ bool8 IsStarterInParty(void) u8 i; u16 starter = GetStarterPokemon(VarGet(VAR_FIRST_POKE)); u8 partyCount = CalculatePlayerPartyCount(); - for (i=0; i<partyCount; i++) + for (i = 0; i < partyCount; i++) { if (GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2, NULL) == starter) { @@ -2005,7 +2005,7 @@ bool8 sub_810F828(void) void SetRoute119Weather(void) { - if (is_light_level_1_2_3_5_or_6(get_map_light_from_warp0()) != TRUE) + if (is_map_type_1_2_3_5_or_6(get_map_type_from_warp0()) != TRUE) { SetSav1Weather(0x14); } @@ -2013,7 +2013,7 @@ void SetRoute119Weather(void) void SetRoute123Weather(void) { - if (is_light_level_1_2_3_5_or_6(get_map_light_from_warp0()) != TRUE) + if (is_map_type_1_2_3_5_or_6(get_map_type_from_warp0()) != TRUE) { SetSav1Weather(0x15); } @@ -2140,10 +2140,10 @@ void sub_810FAA0(void) sub_810FF48(); sub_810FD80(); gSaveBlock1.vars[0x42] = gSaveBlock2.playTimeHours; - FlagReset(0x315); - FlagReset(0x316); - FlagReset(0x317); - FlagReset(0x318); + FlagClear(0x315); + FlagClear(0x316); + FlagClear(0x317); + FlagClear(0x318); VarSet(VAR_0x4095, 1); } } diff --git a/src/field/field_tasks.c b/src/field/field_tasks.c index caf2ce6b9..2be54f923 100644 --- a/src/field/field_tasks.c +++ b/src/field/field_tasks.c @@ -10,7 +10,7 @@ #include "item.h" #include "items.h" #include "event_data.h" -#include "rom4.h" +#include "overworld.h" #include "clock.h" #include "script.h" #include "field_special_scene.h" @@ -48,21 +48,25 @@ void Task_RunPerStepCallback(u8 taskId) gUnknown_08376364[idx](taskId); } -static void RunTimeBasedEvents(s16 *taskData) +#define tState data[0] +#define tAmbientCryState data[1] +#define tAmbientCryDelay data[2] + +static void RunTimeBasedEvents(s16 *data) { - switch (*taskData) + switch (tState) { case 0: if (gMain.vblankCounter1 & 0x1000) { DoTimeBasedEvents(); - (*taskData)++; + tState++; } break; case 1: if (!(gMain.vblankCounter1 & 0x1000)) { - (*taskData)--; + tState--; } break; } @@ -70,14 +74,19 @@ static void RunTimeBasedEvents(s16 *taskData) void Task_RunTimeBasedEvents(u8 taskId) { - s16 *taskData = gTasks[taskId].data; + s16 *data = gTasks[taskId].data; + if (!ScriptContext2_IsEnabled()) { - RunTimeBasedEvents(taskData); - sub_80540D0(taskData + 1, taskData + 2); + RunTimeBasedEvents(data); + UpdateAmbientCry(&tAmbientCryState, &tAmbientCryDelay); } } +#undef tState +#undef tAmbientCryState +#undef tAmbientCryDelay + void Task_MuddySlope(u8); void SetUpFieldTasks(void) diff --git a/src/field/fieldmap.c b/src/field/fieldmap.c index 0e0ec246c..3ad190a4b 100644 --- a/src/field/fieldmap.c +++ b/src/field/fieldmap.c @@ -1,7 +1,7 @@ #include "global.h" #include "fieldmap.h" #include "palette.h" -#include "rom4.h" +#include "overworld.h" #include "script.h" #include "secret_base.h" #include "tv.h" @@ -31,7 +31,7 @@ static const struct ConnectionFlags sDummyConnectionFlags = {0}; struct MapHeader *mapconnection_get_mapheader(struct MapConnection *connection) { - return get_mapheader_by_bank_and_number(connection->mapGroup, connection->mapNum); + return Overworld_GetMapHeaderByGroupAndId(connection->mapGroup, connection->mapNum); } void not_trainer_hill_battle_pyramid(void) diff --git a/src/field/fldeff_cut.c b/src/field/fldeff_cut.c index b394d1e4c..00643a979 100644 --- a/src/field/fldeff_cut.c +++ b/src/field/fldeff_cut.c @@ -8,7 +8,7 @@ #include "metatile_behavior.h" #include "metatile_behaviors.h" #include "pokemon_menu.h" -#include "rom4.h" +#include "overworld.h" #include "rom6.h" #include "script.h" #include "songs.h" @@ -28,7 +28,7 @@ extern struct MapPosition gUnknown_0203923C; extern u8 gLastFieldPokeMenuOpened; -extern u8 UseCutScript; +extern u8 S_UseCut[]; bool8 SetUpFieldMove_Cut(void) { @@ -38,7 +38,7 @@ bool8 SetUpFieldMove_Cut(void) if(npc_before_player_of_type(0x52) == TRUE) // is in front of tree? { - gFieldCallback = sub_808AB90; + gFieldCallback = FieldCallback_Teleport; gUnknown_03005CE4 = sub_80A2634; return TRUE; } @@ -57,7 +57,7 @@ bool8 SetUpFieldMove_Cut(void) if(MetatileBehavior_IsPokeGrass(tileBehavior) == TRUE || MetatileBehavior_IsAshGrass(tileBehavior) == TRUE) { - gFieldCallback = sub_808AB90; + gFieldCallback = FieldCallback_Teleport; gUnknown_03005CE4 = sub_80A25E8; return TRUE; } @@ -70,8 +70,8 @@ bool8 SetUpFieldMove_Cut(void) void sub_80A25E8(void) { - FieldEffectStart(1); - gUnknown_0202FF84[0] = gLastFieldPokeMenuOpened; + FieldEffectStart(FLDEFF_USE_CUT_ON_GRASS); + gFieldEffectArguments[0] = gLastFieldPokeMenuOpened; } bool8 FldEff_UseCutOnGrass(void) @@ -86,8 +86,8 @@ bool8 FldEff_UseCutOnGrass(void) void sub_80A2634(void) { - gUnknown_0202FF84[0] = gLastFieldPokeMenuOpened; - ScriptContext1_SetupScript(&UseCutScript); + gFieldEffectArguments[0] = gLastFieldPokeMenuOpened; + ScriptContext1_SetupScript(S_UseCut); } bool8 FldEff_UseCutOnTree(void) @@ -102,8 +102,8 @@ bool8 FldEff_UseCutOnTree(void) void sub_80A2684(void) { - FieldEffectActiveListRemove(1); - FieldEffectStart(0x3A); + FieldEffectActiveListRemove(FLDEFF_USE_CUT_ON_GRASS); + FieldEffectStart(FLDEFF_CUT_GRASS); } bool8 FldEff_CutGrass(void) @@ -272,19 +272,16 @@ void sub_80A2AB8(void) { u8 i; - for(i = 1; i < 8; i++) - { + for (i = 1; i < 8; i++) DestroySprite(&gSprites[gCutGrassSpriteArray[i]]); - } - - FieldEffectStop(&gSprites[gCutGrassSpriteArray[0]], 0x3A); + FieldEffectStop(&gSprites[gCutGrassSpriteArray[0]], FLDEFF_CUT_GRASS); sub_8064E2C(); ScriptContext2_Disable(); } void sub_80A2B00(void) { - PlaySE(0x80); - FieldEffectActiveListRemove(2); + PlaySE(SE_W015); + FieldEffectActiveListRemove(FLDEFF_USE_CUT_ON_TREE); EnableBothScriptContexts(); } diff --git a/src/field/fldeff_flash.c b/src/field/fldeff_flash.c index 6c2633567..1ee8a8f05 100644 --- a/src/field/fldeff_flash.c +++ b/src/field/fldeff_flash.c @@ -4,7 +4,7 @@ #include "main.h" #include "palette.h" #include "pokemon_menu.h" -#include "rom4.h" +#include "overworld.h" #include "rom6.h" #include "script.h" #include "songs.h" @@ -51,7 +51,7 @@ bool8 SetUpFieldMove_Flash(void) { if (gMapHeader.cave == TRUE && !FlagGet(SYS_USE_FLASH)) { - gFieldCallback = sub_808AB90; + gFieldCallback = FieldCallback_Teleport; gUnknown_03005CE4 = sub_810CBFC; return TRUE; } @@ -62,7 +62,7 @@ bool8 SetUpFieldMove_Flash(void) void sub_810CBFC(void) { u8 taskId = oei_task_add(); - gUnknown_0202FF84[0] = gLastFieldPokeMenuOpened; + gFieldEffectArguments[0] = gLastFieldPokeMenuOpened; gTasks[taskId].data[8] = (uintptr_t)sub_810CC34 >> 16; gTasks[taskId].data[9] = (uintptr_t)sub_810CC34; } @@ -123,8 +123,8 @@ void sub_810CC80(void) bool8 sub_810CD5C(void) { u8 i; - u8 v0 = get_map_light_from_warp0(); - u8 v1 = sav1_map_get_light_level(); + u8 v0 = get_map_type_from_warp0(); + u8 v1 = Overworld_GetMapTypeOfSaveblockLocation(); for (i = 0; gUnknown_083F7FC4[i].unk0; i++) { diff --git a/src/field/fldeff_strength.c b/src/field/fldeff_strength.c index 81f4f63c6..d9603d094 100644 --- a/src/field/fldeff_strength.c +++ b/src/field/fldeff_strength.c @@ -18,14 +18,14 @@ extern u16 gScriptResult; extern void (*gFieldCallback)(void); extern void (*gUnknown_03005CE4)(void); -extern u8 UseStrengthScript[]; +extern u8 S_UseStrength[]; bool8 SetUpFieldMove_Strength(void) { if (ShouldDoBrailleStrengthEffect()) { gScriptResult = gLastFieldPokeMenuOpened; - gFieldCallback = sub_808AB90; + gFieldCallback = FieldCallback_Teleport; gUnknown_03005CE4 = sub_811AA38; } else @@ -33,7 +33,7 @@ bool8 SetUpFieldMove_Strength(void) if (npc_before_player_of_type(87) != TRUE) return 0; gScriptResult = gLastFieldPokeMenuOpened; - gFieldCallback = sub_808AB90; + gFieldCallback = FieldCallback_Teleport; gUnknown_03005CE4 = sub_811AA18; } @@ -42,14 +42,14 @@ bool8 SetUpFieldMove_Strength(void) static void sub_811AA18(void) { - gUnknown_0202FF84[0] = gLastFieldPokeMenuOpened; - ScriptContext1_SetupScript(UseStrengthScript); + gFieldEffectArguments[0] = gLastFieldPokeMenuOpened; + ScriptContext1_SetupScript(S_UseStrength); } static void sub_811AA38(void) { - gUnknown_0202FF84[0] = gLastFieldPokeMenuOpened; - FieldEffectStart(40); + gFieldEffectArguments[0] = gLastFieldPokeMenuOpened; + FieldEffectStart(FLDEFF_USE_STRENGTH); } bool8 FldEff_UseStrength(void) @@ -58,7 +58,7 @@ bool8 FldEff_UseStrength(void) gTasks[taskId].data[8] = (u32)sub_811AA9C >> 16; gTasks[taskId].data[9] = (u32)sub_811AA9C; - GetMonNickname(&gPlayerParty[gUnknown_0202FF84[0]], gStringVar1); + GetMonNickname(&gPlayerParty[gFieldEffectArguments[0]], gStringVar1); return FALSE; } diff --git a/src/field/fldeff_sweetscent.c b/src/field/fldeff_sweetscent.c index 4c3e6bf4a..b9dbf619d 100644 --- a/src/field/fldeff_sweetscent.c +++ b/src/field/fldeff_sweetscent.c @@ -23,15 +23,15 @@ extern u8 SweetScentNothingHereScript[]; bool8 SetUpFieldMove_SweetScent(void) { - gFieldCallback = sub_808AB90; + gFieldCallback = FieldCallback_Teleport; gUnknown_03005CE4 = sub_812BFD4; return TRUE; } static void sub_812BFD4(void) { - FieldEffectStart(51); - gUnknown_0202FF84[0] = gLastFieldPokeMenuOpened; + FieldEffectStart(FLDEFF_SWEET_SCENT); + gFieldEffectArguments[0] = gLastFieldPokeMenuOpened; } bool8 FldEff_SweetScent() @@ -51,7 +51,7 @@ static void sub_812C01C(void) BeginNormalPaletteFade(~(1 << (gSprites[GetPlayerAvatarObjectId()].oam.paletteNum + 16)), 4, 0, 8, 0x1F); taskId = CreateTask(sub_812C084, 0); gTasks[taskId].data[0] = 0; - FieldEffectActiveListRemove(51); + FieldEffectActiveListRemove(FLDEFF_SWEET_SCENT); } static void sub_812C084(u8 taskId) diff --git a/src/field/fldeff_teleport.c b/src/field/fldeff_teleport.c index 74e68df06..af48fb414 100644 --- a/src/field/fldeff_teleport.c +++ b/src/field/fldeff_teleport.c @@ -3,7 +3,7 @@ #include "field_effect.h" #include "field_player_avatar.h" #include "pokemon_menu.h" -#include "rom4.h" +#include "overworld.h" #include "rom6.h" #include "task.h" @@ -13,9 +13,9 @@ extern void (*gUnknown_03005CE4)(void); bool8 SetUpFieldMove_Teleport(void) { - if (is_light_level_1_2_3_or_6(gMapHeader.mapType) == TRUE) + if (Overworld_MapTypeAllowsTeleportAndFly(gMapHeader.mapType) == TRUE) { - gFieldCallback = sub_808AB90; + gFieldCallback = FieldCallback_Teleport; gUnknown_03005CE4 = hm_teleport_run_dp02scr; return TRUE; } @@ -25,9 +25,9 @@ bool8 SetUpFieldMove_Teleport(void) void hm_teleport_run_dp02scr(void) { - new_game(); - FieldEffectStart(63); - gUnknown_0202FF84[0] = gLastFieldPokeMenuOpened; + Overworld_ResetStateAfterTeleport(); + FieldEffectStart(FLDEFF_USE_TELEPORT); + gFieldEffectArguments[0] = gLastFieldPokeMenuOpened; } bool8 FldEff_UseTeleport(void) @@ -41,6 +41,6 @@ bool8 FldEff_UseTeleport(void) void sub_814A404(void) { - FieldEffectActiveListRemove(63); + FieldEffectActiveListRemove(FLDEFF_USE_TELEPORT); sub_8087BA8(); } diff --git a/src/field/hof_pc.c b/src/field/hof_pc.c index 4646d171c..aeeb7fe17 100644 --- a/src/field/hof_pc.c +++ b/src/field/hof_pc.c @@ -2,7 +2,7 @@ #include "hall_of_fame.h" #include "main.h" #include "palette.h" -#include "rom4.h" +#include "overworld.h" #include "script.h" #include "script_menu.h" #include "task.h" @@ -30,8 +30,8 @@ static void ReshowPCMenuAfterHallOfFamePC(void) ScriptContext2_Enable(); sub_8053E90(); BeginNormalPaletteFade(0xFFFFFFFF, 0, 0x10, 0, 0); - TryCreatePCMenu(); - sub_80B5838(); + ScrSpecial_CreatePCMenu(); + ScriptMenu_DisplayPCStartupPrompt(); CreateTask(Task_WaitForPaletteFade, 10); } diff --git a/src/field/item_menu.c b/src/field/item_menu.c index 4436bdfbe..891eb135f 100644 --- a/src/field/item_menu.c +++ b/src/field/item_menu.c @@ -23,7 +23,7 @@ #include "party_menu.h" #include "player_pc.h" #include "pokemon_menu.h" -#include "rom4.h" +#include "overworld.h" #include "script.h" #include "songs.h" #include "sound.h" @@ -3115,7 +3115,7 @@ static void sub_80A6760(u8 taskId) static void BuyMenuPrintItemQuantityAndPrice(u8 taskId) { sub_80A36B8(gBGTilemapBuffers[1], 0, 0, 31, 31); - RemoveMoneyLabelObject(0, 0); + CloseMoneyWindow(0, 0); MenuZeroFillWindowRect(0, 4, 13, 13); MenuZeroFillWindowRect(0, 14, 29, 19); gTasks[taskId].func = sub_80A6760; @@ -3123,20 +3123,20 @@ static void BuyMenuPrintItemQuantityAndPrice(u8 taskId) static void BuyMenuDisplayMessage(u16 itemId, u16 quantity) { - sub_80B7A94(ItemId_GetPrice(itemId) / 2 * quantity, 6, 6, 11); + PrintMoneyAmount(ItemId_GetPrice(itemId) / 2 * quantity, 6, 6, 11); ConvertIntToDecimalStringN(gStringVar1, ItemId_GetPrice(itemId) / 2 * quantity, STR_CONV_MODE_LEFT_ALIGN, 6); } static void sub_80A683C(void) { - sub_80B7C14(gSaveBlock1.money, 0, 0); + OpenMoneyWindow(gSaveBlock1.money, 0, 0); sub_80A4008(gBGTilemapBuffers[1], 1, 1, 12, 2); } static void sub_80A6870(u16 itemId, u8 quantity) { - sub_80B79B8(&gSaveBlock1.money, ItemId_GetPrice(itemId) / 2 * quantity); - sub_80B7BEC(gSaveBlock1.money, 0, 0); + AddMoney(&gSaveBlock1.money, ItemId_GetPrice(itemId) / 2 * quantity); + UpdateMoneyWindow(gSaveBlock1.money, 0, 0); } static void sub_80A68A4(void) diff --git a/src/field/item_use.c b/src/field/item_use.c index 1750c1584..8bc83bdc6 100644 --- a/src/field/item_use.c +++ b/src/field/item_use.c @@ -26,7 +26,7 @@ #include "pokeblock.h" #include "pokemon_item_effect.h" #include "pokemon_menu.h" -#include "rom4.h" +#include "overworld.h" #include "rom_8094928.h" #include "script.h" #include "songs.h" @@ -36,10 +36,10 @@ #include "task.h" #include "vars.h" -extern void (* gUnknown_03005D00)(u8); -extern void (* gFieldCallback)(void); -extern void (* gUnknown_0300485C)(void); -extern void (* gUnknown_03004AE4)(u8, u16, TaskFunc); +extern void (*gUnknown_03005D00)(u8); +extern void (*gFieldCallback)(void); +extern void (*gUnknown_0300485C)(void); +extern void (*gUnknown_03004AE4)(u8, u16, TaskFunc); extern u8 gUnknown_02038561; extern u8 gLastFieldPokeMenuOpened; @@ -185,7 +185,7 @@ void ItemUseOutOfBattle_Bike(u8 taskId) } else { - if (IsBikingAllowedByMap() == TRUE && IsBikingDisallowedByPlayer() == FALSE) + if (Overworld_IsBikeAllowedOnCurrentMap() == TRUE && IsBikingDisallowedByPlayer() == FALSE) { gUnknown_03005D00 = (void *)ItemUseOnFieldCB_Bike; SetUpItemUseOnFieldCallback(taskId); @@ -342,7 +342,7 @@ bool8 ItemfinderCheckForHiddenItems(struct MapEvents *events, u8 taskId) sub_80C9720(taskId); // hidden item detected? - if(gTasks[taskId].data[2] == TRUE) + if (gTasks[taskId].data[2] == TRUE) return TRUE; else return FALSE; @@ -354,11 +354,11 @@ bool8 HiddenItemAtPos(struct MapEvents *events, s16 x, s16 y) struct BgEvent *bgEvent = events->bgEvents; int i; - for(i = 0; i < bgEventCount; i++) + for (i = 0; i < bgEventCount; i++) { - if(bgEvent[i].kind == 7 && x == (u16)bgEvent[i].x && y == (u16)bgEvent[i].y) // hidden item and coordinates matches x and y passed? + if (bgEvent[i].kind == 7 && x == (u16)bgEvent[i].x && y == (u16)bgEvent[i].y) // hidden item and coordinates matches x and y passed? { - if(!FlagGet(bgEvent[i].bgUnion.hiddenItem.hiddenItemId + 600)) + if (!FlagGet(bgEvent[i].bgUnion.hiddenItem.hiddenItemId + 600)) return TRUE; else return FALSE; @@ -376,7 +376,7 @@ bool8 sub_80C9688(struct MapConnection *connection, int x, int y) mapHeader = mapconnection_get_mapheader(connection); - switch(connection->direction) + switch (connection->direction) { // same weird temp variable behavior seen in HiddenItemAtPos case 2: @@ -592,7 +592,7 @@ void sub_80C9838(u8 taskId, s16 x, s16 y) s16 *data = gTasks[taskId].data; s16 var1, var2, var3, var4; - if(data[2] == FALSE) + if (data[2] == FALSE) { data[0] = x; data[1] = y; @@ -602,34 +602,34 @@ void sub_80C9838(u8 taskId, s16 x, s16 y) { // data[0] and data[1] contain the player's coordinates. // x and y contain the item's coordinates. - if(data[0] < 0) + if (data[0] < 0) var1 = data[0] * -1; // item is to the left else var1 = data[0]; // item is to the right - if(data[1] < 0) + if (data[1] < 0) var2 = data[1] * -1; // item is to the north else var2 = data[1]; // item is to the south - if(x < 0) + if (x < 0) var3 = x * -1; else var3 = x; - if(y < 0) + if (y < 0) var4 = y * -1; else var4 = y; - if(var1 + var2 > var3 + var4) + if (var1 + var2 > var3 + var4) { data[0] = x; data[1] = y; } else { - if(var1 + var2 == var3 + var4 && (var2 > var4 || (var2 == var4 && data[1] < y))) + if (var1 + var2 == var3 + var4 && (var2 > var4 || (var2 == var4 && data[1] < y))) { data[0] = x; data[1] = y; @@ -642,40 +642,40 @@ u8 GetPlayerDirectionTowardsHiddenItem(s16 itemX, s16 itemY) { s16 abX, abY; - if(itemX == 0 && itemY == 0) + if (itemX == 0 && itemY == 0) return DIR_NONE; // player is standing on the item. // get absolute X distance. - if(itemX < 0) + if (itemX < 0) abX = itemX * -1; else abX = itemX; // get absolute Y distance. - if(itemY < 0) + if (itemY < 0) abY = itemY * -1; else abY = itemY; - if(abX > abY) + if (abX > abY) { - if(itemX < 0) + if (itemX < 0) return DIR_EAST; else return DIR_NORTH; } else { - if(abX < abY) + if (abX < abY) { - if(itemY < 0) + if (itemY < 0) return DIR_SOUTH; else return DIR_WEST; } - if(abX == abY) + if (abX == abY) { - if(itemY < 0) + if (itemY < 0) return DIR_SOUTH; else return DIR_WEST; @@ -694,7 +694,7 @@ void SetPlayerDirectionTowardsItem(u8 direction) void DisplayItemRespondingMessageAndExitItemfinder(u8 taskId) { - if(FieldObjectCheckIfSpecialAnimFinishedOrInactive(&gMapObjects[GetFieldObjectIdByLocalIdAndMap(0xFF, 0, 0)]) == TRUE) + if (FieldObjectCheckIfSpecialAnimFinishedOrInactive(&gMapObjects[GetFieldObjectIdByLocalIdAndMap(0xFF, 0, 0)]) == TRUE) DisplayItemMessageOnField(taskId, gOtherText_ItemfinderResponding, ExitItemfinder, 0); } @@ -702,7 +702,7 @@ void RotatePlayerAndExitItemfinder(u8 taskId) { s16 *data = gTasks[taskId].data; - if(FieldObjectCheckIfSpecialAnimFinishedOrInactive(&gMapObjects[GetFieldObjectIdByLocalIdAndMap(0xFF, 0, 0)]) == TRUE + if (FieldObjectCheckIfSpecialAnimFinishedOrInactive(&gMapObjects[GetFieldObjectIdByLocalIdAndMap(0xFF, 0, 0)]) == TRUE || data[2] == FALSE) { SetPlayerDirectionTowardsItem(gItemFinderDirections[data[5]]); @@ -710,18 +710,18 @@ void RotatePlayerAndExitItemfinder(u8 taskId) data[5] = (data[5] + 1) & 3; data[3]++; - if(data[3] == 4) + if (data[3] == 4) DisplayItemMessageOnField(taskId, gOtherText_ItemfinderItemUnderfoot, ExitItemfinder, 0); } } void ItemUseOutOfBattle_PokeblockCase(u8 taskId) { - if(sub_80F9344() == TRUE) + if (sub_80F9344() == TRUE) { DisplayDadsAdviceCannotUseItemMessage(taskId, gTasks[taskId].data[2]); } - else if(gTasks[taskId].data[2] != TRUE) + else if (gTasks[taskId].data[2] != TRUE) { sub_810BA7C(0); ItemMenu_ConfirmNormalFade(taskId); @@ -739,7 +739,7 @@ void ItemUseOutOfBattle_CoinCase(u8 taskId) ConvertIntToDecimalStringN(gStringVar1, GetCoins(), 0, 4); StringExpandPlaceholders(gStringVar4, gOtherText_Coins3); - if(!gTasks[taskId].data[2]) + if (!gTasks[taskId].data[2]) { MenuZeroFillWindowRect(0, 0xD, 0xD, 0x14); DisplayItemMessageOnField(taskId, gStringVar4, CleanUpItemMenuMessage, 1); @@ -752,20 +752,20 @@ void ItemUseOutOfBattle_CoinCase(u8 taskId) void sub_80C9BB8(u8 var) { - if(gMain.newKeys & A_BUTTON) + if (gMain.newKeys & A_BUTTON) CleanUpItemMenuMessage(var); } void sub_80C9BD8(u8 var) { - if(gMain.newKeys & A_BUTTON) + if (gMain.newKeys & A_BUTTON) CleanUpOverworldMessage(var); } // unused void ItemUseOutOfBattle_SSTicket(u8 taskId) { - if(gTasks[taskId].data[2] == 0) + if (gTasks[taskId].data[2] == 0) { MenuZeroFillWindowRect(0, 0xD, 0xD, 0x14); DisplayItemMessageOnField(taskId, gUnknown_083D61DC[ItemId_GetSecondaryId(gScriptItemId)], sub_80C9BB8, 1); @@ -778,7 +778,7 @@ void ItemUseOutOfBattle_SSTicket(u8 taskId) void sub_80C9C7C(u8 taskId) { - if(IsPlayerFacingPlantedBerryTree() == TRUE) + if (IsPlayerFacingPlantedBerryTree() == TRUE) { gUnknown_03005D00 = sub_80C9D00; gFieldCallback = ExecuteItemUseFromBlackPalette; @@ -803,7 +803,7 @@ void sub_80C9D00(u8 taskId) void ItemUseOutOfBattle_WailmerPail(u8 taskId) { - if(TryToWaterBerryTree() == TRUE) + if (TryToWaterBerryTree() == TRUE) { gUnknown_03005D00 = sub_80C9D74; SetUpItemUseOnFieldCallback(taskId); @@ -839,9 +839,9 @@ void ItemUseOutOfBattle_SacredAsh(u8 taskId) gLastFieldPokeMenuOpened = 0; - for(i = 0; i < 6; i++) + for (i = 0; i < 6; i++) { - if(GetMonData(&gPlayerParty[i], MON_DATA_SPECIES) != 0 && GetMonData(&gPlayerParty[i], MON_DATA_HP) == 0) + if (GetMonData(&gPlayerParty[i], MON_DATA_SPECIES) != 0 && GetMonData(&gPlayerParty[i], MON_DATA_HP) == 0) { gLastFieldPokeMenuOpened = i; break; @@ -874,7 +874,7 @@ void ItemUseOutOfBattle_TMHM(u8 taskId) { MenuZeroFillWindowRect(0, 0xD, 0xD, 0x14); - if(gScriptItemId >= ITEM_HM01) + if (gScriptItemId >= ITEM_HM01) DisplayItemMessageOnField(taskId, gOtherText_BootedHM, sub_80C9EE4, 1); // HM else DisplayItemMessageOnField(taskId, gOtherText_BootedTM, sub_80C9EE4, 1); // TM @@ -882,13 +882,13 @@ void ItemUseOutOfBattle_TMHM(u8 taskId) void sub_80C9EE4(u8 taskId) { - PlaySE(2); + PlaySE(SE_PC_LOGON); gTasks[taskId].func = sub_80C9F10; } void sub_80C9F10(u8 taskId) { - if(gMain.newKeys & A_BUTTON || gMain.newKeys & B_BUTTON) + if (gMain.newKeys & A_BUTTON || gMain.newKeys & B_BUTTON) { StringCopy(gStringVar1, gMoveNames[ItemIdToBattleMoveId(gScriptItemId)]); StringExpandPlaceholders(gStringVar4, gOtherText_ContainsMove); @@ -919,7 +919,7 @@ void sub_80C9FDC(void) void ItemUseOutOfBattle_Repel(u8 var) { - if(VarGet(VAR_REPEL_STEP_COUNT) == FALSE) + if (VarGet(VAR_REPEL_STEP_COUNT) == FALSE) { VarSet(VAR_REPEL_STEP_COUNT, ItemId_GetHoldEffectParam(gScriptItemId)); sub_80C9FDC(); @@ -941,26 +941,26 @@ void sub_80CA098(u8 taskId) { if(++gTasks[taskId].data[15] > 7) { - PlaySE(0x75); + PlaySE(SE_BIDORO); DisplayItemMessageOnField(taskId, gStringVar4, CleanUpItemMenuMessage, 1); } } void ItemUseOutOfBattle_BlackWhiteFlute(u8 taskId) { - if(gScriptItemId == 43) + if (gScriptItemId == ITEM_WHITE_FLUTE) { FlagSet(SYS_ENC_UP_ITEM); - FlagReset(SYS_ENC_DOWN_ITEM); + FlagClear(SYS_ENC_DOWN_ITEM); sub_80CA07C(); StringExpandPlaceholders(gStringVar4, gOtherText_UsedFlute); gTasks[taskId].func = sub_80CA098; gTasks[taskId].data[15] = 0; } - else if(gScriptItemId == 42) + else if (gScriptItemId == ITEM_BLACK_FLUTE) { FlagSet(SYS_ENC_DOWN_ITEM); - FlagReset(SYS_ENC_UP_ITEM); + FlagClear(SYS_ENC_UP_ITEM); sub_80CA07C(); StringExpandPlaceholders(gStringVar4, gOtherText_UsedRepel); gTasks[taskId].func = sub_80CA098; @@ -983,9 +983,9 @@ void sub_80CA18C(u8 taskId) DisplayItemMessageOnField(taskId, gStringVar4, task08_080A1C44, 0); } -bool8 sub_80CA1C8(void) +bool8 CanUseEscapeRopeOnCurrMap(void) { - if(gMapHeader.mapType == MAP_TYPE_UNDERGROUND) + if (gMapHeader.mapType == MAP_TYPE_UNDERGROUND) return TRUE; else return FALSE; @@ -993,7 +993,7 @@ bool8 sub_80CA1C8(void) void ItemUseOutOfBattle_EscapeRope(u8 taskId) { - if(sub_80CA1C8() == TRUE) // is map type an area you can use escape rope? + if (CanUseEscapeRopeOnCurrMap() == TRUE) { gUnknown_03005D00 = sub_80CA18C; SetUpItemUseOnFieldCallback(taskId); @@ -1012,7 +1012,7 @@ void ItemUseOutOfBattle_EvolutionStone(u8 var) void ItemUseInBattle_PokeBall(u8 var) { - if(PlayerPartyAndPokemonStorageFull() == FALSE) // have room for mon? + if (PlayerPartyAndPokemonStorageFull() == FALSE) // have room for mon? { RemoveBagItem(gScriptItemId, 1); sub_80A7094(var); @@ -1026,7 +1026,7 @@ void ItemUseInBattle_PokeBall(u8 var) void sub_80CA294(u8 var) { - if(gMain.newKeys & A_BUTTON || gMain.newKeys & B_BUTTON) + if (gMain.newKeys & A_BUTTON || gMain.newKeys & B_BUTTON) sub_80A7094(var); } @@ -1034,7 +1034,7 @@ void sub_80CA2BC(u8 taskId) { if(++gTasks[taskId].data[15] > 7) { - PlaySE(1); + PlaySE(SE_KAIFUKU); RemoveBagItem(gScriptItemId, 1); DisplayItemMessageOnField(taskId, sub_803F378(gScriptItemId), sub_80CA294, 1); } @@ -1046,7 +1046,7 @@ void ItemUseInBattle_StatIncrease(u8 taskId) MenuZeroFillWindowRect(0, 0xD, 0xD, 0x14); - if(ExecuteTableBasedItemEffect_(&gPlayerParty[partyId], gScriptItemId, partyId, 0) != FALSE) + if (ExecuteTableBasedItemEffect_(&gPlayerParty[partyId], gScriptItemId, partyId, 0) != FALSE) { DisplayItemMessageOnField(taskId, gOtherText_WontHaveAnyEffect, CleanUpItemMenuMessage, 1); } @@ -1059,7 +1059,7 @@ void ItemUseInBattle_StatIncrease(u8 taskId) void sub_80CA394(u8 taskId) { - if(!gPaletteFade.active) + if (!gPaletteFade.active) { sub_8094E4C(); gpu_pal_allocator_reset__manage_upper_four(); @@ -1095,7 +1095,7 @@ void unref_sub_80CA448(u8 var) { MenuZeroFillWindowRect(0, 0xD, 0xD, 0x14); - if(ExecuteTableBasedItemEffect__(0, gScriptItemId, 0) == FALSE) + if (ExecuteTableBasedItemEffect__(0, gScriptItemId, 0) == FALSE) { RemoveBagItem(gScriptItemId, 1); GetMonNickname(&gPlayerParty[0], gStringVar1); @@ -1125,7 +1125,7 @@ void ItemUseInBattle_Escape(u8 taskId) void ItemUseOutOfBattle_EnigmaBerry(u8 taskId) { - switch(GetItemEffectType(gScriptItemId) - 1) + switch (GetItemEffectType(gScriptItemId) - 1) { case 1: case 2: @@ -1168,7 +1168,7 @@ void ItemUseOutOfBattle_EnigmaBerry(u8 taskId) void ItemUseInBattle_EnigmaBerry(u8 taskId) { - switch(GetItemEffectType(gScriptItemId)) + switch (GetItemEffectType(gScriptItemId)) { case 0: ItemUseInBattle_StatIncrease(taskId); diff --git a/src/field/map_obj_lock.c b/src/field/map_obj_lock.c index bd40bcacc..2856320b8 100644 --- a/src/field/map_obj_lock.c +++ b/src/field/map_obj_lock.c @@ -75,7 +75,7 @@ bool8 sub_8064DB4(void) } } -void sub_8064DD8(void) +void LockSelectedMapObject(void) { u8 taskId; FreezeMapObjectsExceptOne(gSelectedMapObject); diff --git a/src/field/mauville_man.c b/src/field/mauville_man.c index 4a77717f1..33bc39648 100644 --- a/src/field/mauville_man.c +++ b/src/field/mauville_man.c @@ -6,7 +6,7 @@ #include "field_message_box.h" #include "m4a.h" #include "menu.h" -#include "rom4.h" +#include "overworld.h" #include "rng.h" #include "script.h" #include "songs.h" diff --git a/src/field/menu_helpers.c b/src/field/menu_helpers.c index 9915d67ac..14e823355 100644 --- a/src/field/menu_helpers.c +++ b/src/field/menu_helpers.c @@ -7,7 +7,7 @@ #include "map_constants.h" #include "menu.h" #include "menu_helpers.h" -#include "rom4.h" +#include "overworld.h" #include "songs.h" #include "sound.h" #include "sprite.h" @@ -140,7 +140,7 @@ static void PrintMessage(const u8 *str, u16 tile) { sub_80A3FA0(&gBGTilemapBuffers[1][0], 2, 15, 26, 4, tile); } - sub_8072044(str); + MenuPrintMessageDefaultCoords(str); } static void sub_80F9090(u8 taskId) diff --git a/src/field/money.c b/src/field/money.c index 67b7eb03f..5d0f0ae8d 100644 --- a/src/field/money.c +++ b/src/field/money.c @@ -25,7 +25,7 @@ bool8 IsEnoughMoney(u32 budget, u32 cost) return FALSE; } -void sub_80B79B8(u32 *arg0, u32 arg1) +void AddMoney(u32 *arg0, u32 arg1) { if (*arg0 > *arg0 + arg1) { @@ -40,7 +40,7 @@ void sub_80B79B8(u32 *arg0, u32 arg1) } } -void sub_80B79E0(u32 *arg0, u32 arg1) +void RemoveMoney(u32 *arg0, u32 arg1) { if (*arg0 < arg1) { @@ -52,39 +52,25 @@ void sub_80B79E0(u32 *arg0, u32 arg1) } } -void sub_80B79F8(u8 *buffer, u32 arg1, u8 arg2) +void GetMoneyAmountText(u8 *buffer, u32 amount, u8 arg2) { u8 width; u8 i; - if (arg1 > 999999) - { + if (amount > 999999) width = 7; - } - else if (arg1 > 99999) - { + else if (amount > 99999) width = 6; - } - else if (arg1 > 10000) - { + else if (amount > 10000) width = 5; - } - else if (arg1 > 999) - { + else if (amount > 999) width = 4; - } - else if (arg1 > 99) - { + else if (amount > 99) width = 3; - } - else if (arg1 > 9) - { + else if (amount > 9) width = 2; - } else - { width = 1; - } buffer[0] = EXT_CTRL_CODE_BEGIN; buffer[1] = 0x14; @@ -100,7 +86,7 @@ void sub_80B79F8(u8 *buffer, u32 arg1, u8 arg2) buffer[0] = CHAR_CURRENCY; buffer += 1; - buffer = ConvertIntToDecimalString(buffer, arg1); + buffer = ConvertIntToDecimalString(buffer, amount); buffer[0] = EXT_CTRL_CODE_BEGIN; buffer[1] = 0x14; @@ -108,16 +94,18 @@ void sub_80B79F8(u8 *buffer, u32 arg1, u8 arg2) buffer[3] = EOS; } -void sub_80B7A94(u32 arg0, u8 size, u8 x, u8 y) +void PrintMoneyAmount(u32 amount, u8 size, u8 x, u8 y) { u8 buffer[16]; u8 stringWidth; - sub_80B79F8(buffer, arg0, size); + GetMoneyAmountText(buffer, amount, size); stringWidth = sub_8072CA4(buffer); if (stringWidth >= (size + 1) * 8) + { MenuPrint(buffer, x, y); + } else { int xPlusOne = x + 1; @@ -241,15 +229,15 @@ _080B7BE8: .4byte 0x0600f840\n\ .syntax divided\n"); } -void sub_80B7BEC(u32 arg0, u8 x, u8 y) +void UpdateMoneyWindow(u32 amount, u8 x, u8 y) { - sub_80B7A94(arg0, 6, x + 6, y + 1); + PrintMoneyAmount(amount, 6, x + 6, y + 1); } -void sub_80B7C14(u32 arg0, u8 x, u8 y) +void OpenMoneyWindow(u32 amount, u8 x, u8 y) { MenuDrawTextWindow(x, y, x + 13, y + 3); - sub_80B7BEC(arg0, x, y); + UpdateMoneyWindow(amount, x, y); LoadCompressedObjectPic(&gUnknown_083CF584); LoadCompressedObjectPalette(&gUnknown_083CF58C); @@ -257,7 +245,7 @@ void sub_80B7C14(u32 arg0, u8 x, u8 y) gUnknown_02038734 = CreateSprite(&gSpriteTemplate_83CF56C, x * 8 + 19, y * 8 + 11, 0); } -void RemoveMoneyLabelObject(u8 x, u8 y) +void CloseMoneyWindow(u8 x, u8 y) { DestroySpriteAndFreeResources(&gSprites[gUnknown_02038734]); FreeSpritePaletteByTag(SPRITE_TAG_MONEY); @@ -271,5 +259,5 @@ bool8 sub_80B7CE8(void) void sub_80B7D0C(void) { - sub_80B79E0(&gSaveBlock1.money, gSpecialVar_0x8005); + RemoveMoney(&gSaveBlock1.money, gSpecialVar_0x8005); } diff --git a/src/misc/rom4.c b/src/field/overworld.c index f9006efba..9b41a262d 100644 --- a/src/misc/rom4.c +++ b/src/field/overworld.c @@ -1,5 +1,5 @@ #include "global.h" -#include "rom4.h" +#include "overworld.h" #include "battle_setup.h" #include "berry.h" #include "cable_club.h" @@ -25,6 +25,7 @@ #include "link.h" #include "load_save.h" #include "main.h" +#include "map_constants.h" #include "map_name_popup.h" #include "menu.h" #include "metatile_behavior.h" @@ -40,6 +41,7 @@ #include "secret_base.h" #include "songs.h" #include "sound.h" +#include "species.h" #include "start_menu.h" #include "task.h" #include "tileset_anim.h" @@ -60,28 +62,10 @@ struct UnkTVStruct u32 tv_field_4; }; -EWRAM_DATA struct WarpData gUnknown_020297F0 = {0}; -EWRAM_DATA struct WarpData gUnknown_020297F8 = {0}; -EWRAM_DATA struct WarpData gUnknown_02029800 = {0}; -EWRAM_DATA struct WarpData gUnknown_02029808 = {0}; -EWRAM_DATA struct UnkPlayerStruct gUnknown_02029810 = {0}; -EWRAM_DATA u16 gUnknown_02029814 = 0; -EWRAM_DATA bool8 gUnknown_02029816 = FALSE; -EWRAM_DATA struct LinkPlayerMapObject gLinkPlayerMapObjects[4] = {0}; - -static u8 gUnknown_03000580[4]; -static u16 (*gUnknown_03000584)(u32); -static u8 gUnknown_03000588; - -u16 word_3004858; -void (*gFieldCallback)(void); -u8 gUnknown_03004860; -u8 gFieldLinkPlayerCount; - extern u16 gUnknown_03004898; extern u16 gUnknown_0300489C; -extern u8 EventScript_LeagueWhiteOut[]; +extern u8 S_WhiteOut[]; extern u8 gUnknown_0819FC9F[]; extern u8 SingleBattleColosseum_EventScript_1A436F[]; extern u8 SingleBattleColosseum_EventScript_1A4379[]; @@ -102,21 +86,115 @@ extern u8 TradeRoom_PromptToCancelLink[]; extern u8 TradeRoom_TerminateLink[]; extern u8 gUnknown_081A4508[]; -extern u8 (*gUnknown_082166A0[])(struct LinkPlayerMapObject *, struct MapObject *, u8); -extern u8 (*gUnknown_082166AC[])(struct LinkPlayerMapObject *, struct MapObject *, u8); -extern void (*gUnknown_082166D8[])(struct LinkPlayerMapObject *, struct MapObject *); - extern struct MapData * const gMapAttributes[]; extern struct MapHeader * const * const gMapGroups[]; -extern const struct WarpData gDummyWarpData; -extern s32 gUnknown_0839ACE8; -extern u32 gUnknown_08216694[]; +extern s32 gMaxFlashLevel; + +EWRAM_DATA struct WarpData gUnknown_020297F0 = {0}; +EWRAM_DATA struct WarpData gUnknown_020297F8 = {0}; +EWRAM_DATA struct WarpData gUnknown_02029800 = {0}; +EWRAM_DATA struct WarpData gUnknown_02029808 = {0}; +EWRAM_DATA struct UnkPlayerStruct gUnknown_02029810 = {0}; +EWRAM_DATA static u16 sAmbientCrySpecies = 0; +EWRAM_DATA static bool8 sIsAmbientCryWaterMon = FALSE; +EWRAM_DATA struct LinkPlayerMapObject gLinkPlayerMapObjects[4] = {0}; + +static u8 gUnknown_03000580[4]; +static u16 (*gUnknown_03000584)(u32); +static u8 gUnknown_03000588; + +u16 word_3004858; +void (*gFieldCallback)(void); +u8 gUnknown_03004860; +u8 gFieldLinkPlayerCount; + +static const struct WarpData sDummyWarpData = +{ + .mapGroup = -1, + .mapNum = -1, + .warpId = -1, + .x = -1, + .y = -1, +}; + +static const u8 sUnusedData[] = +{ + 0xB0, 0x04, 0x00, 0x00, + 0x10, 0x0E, 0x00, 0x00, + 0xB0, 0x04, 0x00, 0x00, + 0x60, 0x09, 0x00, 0x00, + 0x32, 0x00, 0x00, 0x00, + 0x50, 0x00, 0x00, 0x00, + 0xD4, 0xFF, 0xFF, 0xFF, + 0x2C, 0x00, 0x00, 0x00, +}; + +const struct UCoords32 gUnknown_0821664C[] = +{ + { 0, 0}, + { 0, 1}, + { 0, -1}, + {-1, 0}, + { 1, 0}, + {-1, 1}, + { 1, 1}, + {-1, -1}, + { 1, -1}, +}; + +const struct UnknownTaskStruct gUnknown_08216694 = +{ + (void *)REG_ADDR_WIN0H, + ((DMA_ENABLE | DMA_START_HBLANK | DMA_REPEAT | DMA_DEST_RELOAD) << 16) | 1, + 1, + 0, +}; + +static u8 sub_8055C68(struct LinkPlayerMapObject *, struct MapObject *, u8); +static u8 sub_8055C88(struct LinkPlayerMapObject *, struct MapObject *, u8); +static u8 sub_8055C8C(struct LinkPlayerMapObject *, struct MapObject *, u8); + +static u8 (*const gUnknown_082166A0[])(struct LinkPlayerMapObject *, struct MapObject *, u8) = +{ + sub_8055C68, + sub_8055C88, + sub_8055C8C, +}; + +static u8 sub_8055CAC(struct LinkPlayerMapObject *, struct MapObject *, u8); +static u8 sub_8055CB0(struct LinkPlayerMapObject *, struct MapObject *, u8); +static u8 sub_8055D18(struct LinkPlayerMapObject *, struct MapObject *, u8); + +static u8 (*const gUnknown_082166AC[])(struct LinkPlayerMapObject *, struct MapObject *, u8) = +{ + sub_8055CAC, + sub_8055CB0, + sub_8055CB0, + sub_8055CB0, + sub_8055CB0, + sub_8055CAC, + sub_8055CAC, + sub_8055D18, + sub_8055D18, + sub_8055D18, + sub_8055D18, +}; -void DoWhiteOut(void) +static void sub_8055D30(struct LinkPlayerMapObject *, struct MapObject *); +static void sub_8055D38(struct LinkPlayerMapObject *, struct MapObject *); + +static void (*const gUnknown_082166D8[])(struct LinkPlayerMapObject *, struct MapObject *) = +{ + sub_8055D30, + sub_8055D38, +}; + + +static void DoWhiteOut(void) { - ScriptContext2_RunNewScript(EventScript_LeagueWhiteOut); + ScriptContext2_RunNewScript(S_WhiteOut); gSaveBlock1.money /= 2; - HealPlayerParty(); + ScrSpecial_HealPlayerParty(); sub_8053050(); sub_8053570(); warp_in(); @@ -125,48 +203,48 @@ void DoWhiteOut(void) void flag_var_implications_of_teleport_(void) { player_avatar_init_params_reset(); - FlagReset(SYS_CYCLING_ROAD); - FlagReset(SYS_CRUISE_MODE); - FlagReset(SYS_SAFARI_MODE); - FlagReset(SYS_USE_STRENGTH); - FlagReset(SYS_USE_FLASH); + FlagClear(SYS_CYCLING_ROAD); + FlagClear(SYS_CRUISE_MODE); + FlagClear(SYS_SAFARI_MODE); + FlagClear(SYS_USE_STRENGTH); + FlagClear(SYS_USE_FLASH); } -void new_game(void) +void Overworld_ResetStateAfterTeleport(void) { player_avatar_init_params_reset(); - FlagReset(SYS_CYCLING_ROAD); - FlagReset(SYS_CRUISE_MODE); - FlagReset(SYS_SAFARI_MODE); - FlagReset(SYS_USE_STRENGTH); - FlagReset(SYS_USE_FLASH); + FlagClear(SYS_CYCLING_ROAD); + FlagClear(SYS_CRUISE_MODE); + FlagClear(SYS_SAFARI_MODE); + FlagClear(SYS_USE_STRENGTH); + FlagClear(SYS_USE_FLASH); ScriptContext2_RunNewScript(gUnknown_0819FC9F); } void sub_8053014(void) { player_avatar_init_params_reset(); - FlagReset(SYS_CYCLING_ROAD); - FlagReset(SYS_CRUISE_MODE); - FlagReset(SYS_SAFARI_MODE); - FlagReset(SYS_USE_STRENGTH); - FlagReset(SYS_USE_FLASH); + FlagClear(SYS_CYCLING_ROAD); + FlagClear(SYS_CRUISE_MODE); + FlagClear(SYS_SAFARI_MODE); + FlagClear(SYS_USE_STRENGTH); + FlagClear(SYS_USE_FLASH); } void sub_8053050(void) { player_avatar_init_params_reset(); - FlagReset(SYS_CYCLING_ROAD); - FlagReset(SYS_CRUISE_MODE); - FlagReset(SYS_SAFARI_MODE); - FlagReset(SYS_USE_STRENGTH); - FlagReset(SYS_USE_FLASH); + FlagClear(SYS_CYCLING_ROAD); + FlagClear(SYS_CRUISE_MODE); + FlagClear(SYS_SAFARI_MODE); + FlagClear(SYS_USE_STRENGTH); + FlagClear(SYS_USE_FLASH); } void sub_805308C(void) { - FlagReset(SYS_SAFARI_MODE); - sub_8054164(); + FlagClear(SYS_SAFARI_MODE); + ChooseAmbientCrySpecies(); ResetCyclingRoadChallengeData(); UpdateLocationHistoryForRoamer(); RoamerMoveToOtherLocationSet(); @@ -213,15 +291,16 @@ void sub_8053154(void) gMapHeader.events->mapObjectCount * sizeof(struct MapObjectTemplate)); } -void sub_8053198(void) +static void LoadSaveblockMapObjScripts(void) { struct MapObjectTemplate *mapObjectTemplates = gSaveBlock1.mapObjectTemplates; s32 i; + for (i = 0; i < 64; i++) mapObjectTemplates[i].script = gMapHeader.events->mapObjects[i].script; } -void update_saveblock1_field_object_coords(u8 localId, s16 x, s16 y) +void Overworld_SaveMapObjCoords(u8 localId, s16 x, s16 y) { s32 i; for (i = 0; i < 64; i++) @@ -231,28 +310,26 @@ void update_saveblock1_field_object_coords(u8 localId, s16 x, s16 y) { mapObjectTemplate->x = x; mapObjectTemplate->y = y; - break; + return; } } } -void update_saveblock1_field_object_movement_behavior(u8 localId, u8 movementType) +void Overworld_SaveMapObjMovementType(u8 localId, u8 movementType) { - s32 i = 0; - struct MapObjectTemplate *mapObjectTemplate = gSaveBlock1.mapObjectTemplates; - do + s32 i; + for (i = 0; i < 64; i++) { + struct MapObjectTemplate *mapObjectTemplate = &gSaveBlock1.mapObjectTemplates[i]; if (mapObjectTemplate->localId == localId) { mapObjectTemplate->movementType = movementType; - break; + return; } - mapObjectTemplate++; - i++; - } while (i < 64); + } } -void mapdata_load_assets_to_gpu_and_full_redraw(void) +static void mapdata_load_assets_to_gpu_and_full_redraw(void) { move_tilemap_camera_to_upper_left_corner(); copy_map_tileset1_tileset2_to_vram(gMapHeader.mapData); @@ -261,7 +338,7 @@ void mapdata_load_assets_to_gpu_and_full_redraw(void) cur_mapheader_run_tileset_funcs_after_some_cpuset(); } -struct MapData *get_mapdata_header(void) +static struct MapData *get_mapdata_header(void) { u16 mapDataId = gSaveBlock1.mapDataId; if (mapDataId) @@ -269,15 +346,15 @@ struct MapData *get_mapdata_header(void) return NULL; } -void warp_shift(void) +static void warp_shift(void) { gUnknown_020297F0 = gSaveBlock1.location; gSaveBlock1.location = gUnknown_020297F8; - gUnknown_02029800 = gDummyWarpData; - gUnknown_02029808 = gDummyWarpData; + gUnknown_02029800 = sDummyWarpData; + gUnknown_02029808 = sDummyWarpData; } -void warp_set(struct WarpData *warp, s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y) +static void warp_set(struct WarpData *warp, s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y) { warp->mapGroup = mapGroup; warp->mapNum = mapNum; @@ -286,7 +363,7 @@ void warp_set(struct WarpData *warp, s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 warp->y = y; } -bool32 warp_data_is_not_neg_1(struct WarpData *warp) +static bool32 warp_data_is_not_neg_1(struct WarpData *warp) { if (warp->mapGroup != -1) return FALSE; @@ -301,31 +378,27 @@ bool32 warp_data_is_not_neg_1(struct WarpData *warp) return TRUE; } -struct MapHeader * const get_mapheader_by_bank_and_number(u16 mapGroup, u16 mapNum) +struct MapHeader *const Overworld_GetMapHeaderByGroupAndId(u16 mapGroup, u16 mapNum) { return gMapGroups[mapGroup][mapNum]; } -struct MapHeader * const warp1_get_mapheader(void) +struct MapHeader *const warp1_get_mapheader(void) { - return get_mapheader_by_bank_and_number(gUnknown_020297F8.mapGroup, gUnknown_020297F8.mapNum); + return Overworld_GetMapHeaderByGroupAndId(gUnknown_020297F8.mapGroup, gUnknown_020297F8.mapNum); } -void set_current_map_header_from_sav1_save_old_name(void) +static void set_current_map_header_from_sav1_save_old_name(void) { - struct MapHeader *dest = &gMapHeader; - struct MapHeader *src = get_mapheader_by_bank_and_number(gSaveBlock1.location.mapGroup, gSaveBlock1.location.mapNum); - *dest = *src; - gSaveBlock1.mapDataId = dest->mapDataId; - dest->mapData = get_mapdata_header(); + gMapHeader = *Overworld_GetMapHeaderByGroupAndId(gSaveBlock1.location.mapGroup, gSaveBlock1.location.mapNum); + gSaveBlock1.mapDataId = gMapHeader.mapDataId; + gMapHeader.mapData = get_mapdata_header(); } -void sub_805338C(void) +static void LoadSaveblockMapHeader(void) { - struct MapHeader *dest = &gMapHeader; - struct MapHeader *src = get_mapheader_by_bank_and_number(gSaveBlock1.location.mapGroup, gSaveBlock1.location.mapNum); - *dest = *src; - dest->mapData = get_mapdata_header(); + gMapHeader = *Overworld_GetMapHeaderByGroupAndId(gSaveBlock1.location.mapGroup, gSaveBlock1.location.mapNum); + gMapHeader.mapData = get_mapdata_header(); } void sub_80533CC(void) @@ -382,6 +455,7 @@ void copy_saved_warp2_bank_and_enter_x_to_warp1(u8 unused) void sub_8053538(u8 a1) { const struct HealLocation *warp = GetHealLocation(a1); + if (warp) warp1_set(warp->group, warp->map, -1, warp->x, warp->y); } @@ -400,9 +474,9 @@ void sub_8053588(u8 a1) void sub_80535C4(s16 a1, s16 a2) { - u8 v4 = sav1_map_get_light_level(); - u8 v5 = get_map_light_level_by_bank_and_number(gUnknown_020297F8.mapGroup, gUnknown_020297F8.mapNum); - if (is_light_level_1_2_3_5_or_6(v4) && is_light_level_1_2_3_5_or_6(v5) != TRUE) + u8 v4 = Overworld_GetMapTypeOfSaveblockLocation(); + u8 v5 = GetMapTypeByGroupAndId(gUnknown_020297F8.mapGroup, gUnknown_020297F8.mapNum); + if (is_map_type_1_2_3_5_or_6(v4) && is_map_type_1_2_3_5_or_6(v5) != TRUE) sub_805363C(gSaveBlock1.location.mapGroup, gSaveBlock1.location.mapNum, -1, a1 - 7, a2 - 6); } @@ -484,7 +558,7 @@ struct MapConnection *sub_8053818(u8 dir) bool8 sub_8053850(u8 dir, u16 x, u16 y) { struct MapConnection *connection = sub_8053818(dir); - if (connection) + if (connection != NULL) { warp1_set(connection->mapGroup, connection->mapNum, -1, x, y); } @@ -523,8 +597,8 @@ void sub_80538F0(u8 mapGroup, u8 mapNum) sub_8082BD0(mapGroup, mapNum); DoTimeBasedEvents(); sub_80806E4(); - sub_8054164(); - sub_8053C98(); + ChooseAmbientCrySpecies(); + SetDefaultFlashLevel(); sav1_reset_battle_music_maybe(); mapheader_run_script_with_tag_x3(); not_trainer_hill_battle_pyramid(); @@ -550,8 +624,8 @@ void sub_8053994(u32 a1) set_current_map_header_from_sav1_save_old_name(); sub_8053154(); - v2 = is_light_level_1_2_3_5_or_6(gMapHeader.mapType); - v3 = is_light_level_8_or_9(gMapHeader.mapType); + v2 = is_map_type_1_2_3_5_or_6(gMapHeader.mapType); + v3 = Overworld_MapTypeIsIndoors(gMapHeader.mapType); ClearTempFieldEventData(); ResetCyclingRoadChallengeData(); prev_quest_postbuffer_cursor_backup_reset(); @@ -559,10 +633,10 @@ void sub_8053994(u32 a1) if (a1 != 1) DoTimeBasedEvents(); sub_80806E4(); - sub_8054164(); + ChooseAmbientCrySpecies(); if (v2) - FlagReset(SYS_USE_FLASH); - sub_8053C98(); + FlagClear(SYS_USE_FLASH); + SetDefaultFlashLevel(); sav1_reset_battle_music_maybe(); mapheader_run_script_with_tag_x3(); UpdateLocationHistoryForRoamer(); @@ -600,11 +674,11 @@ void walkrun_find_lowest_active_bit_in_bitfield(void) struct UnkPlayerStruct *sub_8053AA8(void) { struct UnkPlayerStruct playerStruct; - u8 light = sav1_map_get_light_level(); + u8 mapType = Overworld_GetMapTypeOfSaveblockLocation(); u16 v2 = cur_mapdata_block_role_at_screen_center_acc_to_sav1(); - u8 v4 = sub_8053B00(&gUnknown_02029810, v2, light); + u8 v4 = sub_8053B00(&gUnknown_02029810, v2, mapType); playerStruct.player_field_0 = v4; - playerStruct.player_field_1 = sub_8053B60(&gUnknown_02029810, v4, v2, light); + playerStruct.player_field_1 = sub_8053B60(&gUnknown_02029810, v4, v2, mapType); gUnknown_02029810 = playerStruct; return &gUnknown_02029810; } @@ -617,7 +691,7 @@ u8 sub_8053B00(struct UnkPlayerStruct *playerStruct, u16 a2, u8 a3) return 16; if (MetatileBehavior_IsSurfableWaterOrUnderwater(a2) == 1) return 8; - if (IsBikingAllowedByMap() != TRUE) + if (Overworld_IsBikeAllowedOnCurrentMap() != TRUE) return 1; if (playerStruct->player_field_0 == 2) return 2; @@ -655,10 +729,12 @@ u16 cur_mapdata_block_role_at_screen_center_acc_to_sav1(void) return MapGridGetMetatileBehaviorAt(gSaveBlock1.pos.x + 7, gSaveBlock1.pos.y + 7); } -bool32 IsBikingAllowedByMap(void) +bool32 Overworld_IsBikeAllowedOnCurrentMap(void) { // is player in cycling road entrance? - if (gSaveBlock1.location.mapGroup == 29 && (gSaveBlock1.location.mapNum == 11 || gSaveBlock1.location.mapNum == 12)) + if (gSaveBlock1.location.mapGroup == MAP_GROUP_ROUTE110_SEASIDE_CYCLING_ROAD_SOUTH_ENTRANCE + && (gSaveBlock1.location.mapNum == MAP_ID_ROUTE110_SEASIDE_CYCLING_ROAD_SOUTH_ENTRANCE + || gSaveBlock1.location.mapNum == MAP_ID_ROUTE110_SEASIDE_CYCLING_ROAD_NORTH_ENTRANCE)) return TRUE; // is player indoor, in a secret base, or underwater? @@ -669,37 +745,37 @@ bool32 IsBikingAllowedByMap(void) if (gMapHeader.mapType == MAP_TYPE_UNDERWATER) return FALSE; - // is player in SeafloorCavern_Room9? - if (gSaveBlock1.location.mapGroup == 24 && gSaveBlock1.location.mapNum == 36) + // Thou shalt not bike on the sacred resting grounds of Kyogre/Groudon. + if (gSaveBlock1.location.mapGroup == MAP_GROUP_SEAFLOOR_CAVERN_ROOM9 + && gSaveBlock1.location.mapNum == MAP_ID_SEAFLOOR_CAVERN_ROOM9) return FALSE; - - // is player in CaveOfOrigin_B4F? - if (gSaveBlock1.location.mapGroup == 24 && gSaveBlock1.location.mapNum == 42) + if (gSaveBlock1.location.mapGroup == MAP_GROUP_CAVE_OF_ORIGIN_B4F + && gSaveBlock1.location.mapNum == MAP_ID_CAVE_OF_ORIGIN_B4F) return FALSE; return TRUE; } -void sub_8053C98(void) +void SetDefaultFlashLevel(void) { if (!gMapHeader.cave) - gSaveBlock1.flashUsed = 0; + gSaveBlock1.flashLevel = 0; else if (FlagGet(SYS_USE_FLASH)) - gSaveBlock1.flashUsed = 1; + gSaveBlock1.flashLevel = 1; else - gSaveBlock1.flashUsed = gUnknown_0839ACE8; + gSaveBlock1.flashLevel = gMaxFlashLevel; } -void sub_8053CE4(s32 a1) +void Overworld_SetFlashLevel(s32 flashLevel) { - if (a1 < 0 || a1 > gUnknown_0839ACE8) - a1 = 0; - gSaveBlock1.flashUsed = a1; + if (flashLevel < 0 || flashLevel > gMaxFlashLevel) + flashLevel = 0; + gSaveBlock1.flashLevel = flashLevel; } -u8 sav1_get_flash_used_on_map(void) +u8 Overworld_GetFlashLevel(void) { - return gSaveBlock1.flashUsed; + return gSaveBlock1.flashLevel; } void sub_8053D14(u16 mapDataId) @@ -708,60 +784,62 @@ void sub_8053D14(u16 mapDataId) gMapHeader.mapData = get_mapdata_header(); } -bool16 sub_8053D30(struct WarpData *warp) +static bool16 ShouldLegendaryMusicPlayAtLocation(struct WarpData *warp) { if (!FlagGet(SYS_WEATHER_CTRL)) return FALSE; - if (warp->mapGroup != 0) - return FALSE; - switch (warp->mapNum) + if (warp->mapGroup == 0) { - case 5: - case 6: - case 7: - case 8: - return TRUE; - case 39: - case 40: - case 41: - case 42: - case 43: - return TRUE; + switch (warp->mapNum) + { + case MAP_ID_LILYCOVE_CITY: + case MAP_ID_MOSSDEEP_CITY: + case MAP_ID_SOOTOPOLIS_CITY: + case MAP_ID_EVER_GRANDE_CITY: + return TRUE; + case MAP_ID_ROUTE124: + case MAP_ID_ROUTE125: + case MAP_ID_ROUTE126: + case MAP_ID_ROUTE127: + case MAP_ID_ROUTE128: + return TRUE; + } } return FALSE; } -bool16 sub_8053D6C(struct WarpData *warp) +static bool16 IsInfiltratedWeatherInstitute(struct WarpData *warp) { - if (VarGet(0x40B3)) + if (VarGet(VAR_WEATHER_INSTITUTE_CLEARED)) return FALSE; - if (warp->mapGroup != 32) + if (warp->mapGroup != MAP_GROUP_ROUTE119_WEATHER_INSTITUTE_1F) return FALSE; - if (warp->mapNum == 0 || warp->mapNum == 1) + if (warp->mapNum == MAP_ID_ROUTE119_WEATHER_INSTITUTE_1F + || warp->mapNum == MAP_ID_ROUTE119_WEATHER_INSTITUTE_2F) return TRUE; return FALSE; } -u16 sub_8053D9C(struct WarpData *warp) +static u16 GetLocationMusic(struct WarpData *warp) { - if (sub_8053D30(warp) == TRUE) + if (ShouldLegendaryMusicPlayAtLocation(warp) == TRUE) return LEGENDARY_MUSIC; - else if (sub_8053D6C(warp) == TRUE) + else if (IsInfiltratedWeatherInstitute(warp) == TRUE) return BGM_TOZAN; else - return get_mapheader_by_bank_and_number(warp->mapGroup, warp->mapNum)->music; + return Overworld_GetMapHeaderByGroupAndId(warp->mapGroup, warp->mapNum)->music; } u16 sav1_map_get_music(void) { u16 music; - if (gSaveBlock1.location.mapGroup == 0 - && gSaveBlock1.location.mapNum == 26 + if (gSaveBlock1.location.mapGroup == MAP_GROUP_ROUTE111 + && gSaveBlock1.location.mapNum == MAP_ID_ROUTE111 && GetSav1Weather() == 8) return BGM_ASHROAD; - music = sub_8053D9C(&gSaveBlock1.location); + music = GetLocationMusic(&gSaveBlock1.location); if (music != 0x7FFF) { return music; @@ -777,14 +855,15 @@ u16 sav1_map_get_music(void) u16 warp1_target_get_music(void) { - u16 music = sub_8053D9C(&gUnknown_020297F8); + u16 music = GetLocationMusic(&gUnknown_020297F8); if (music != 0x7FFF) { return music; } else { - if (gSaveBlock1.location.mapGroup == 0 && gSaveBlock1.location.mapNum == 2) + if (gSaveBlock1.location.mapGroup == MAP_GROUP_MAUVILLE_CITY + && gSaveBlock1.location.mapNum == MAP_ID_MAUVILLE_CITY) return BGM_DOORO_X1; else return BGM_GRANROAD; @@ -804,7 +883,7 @@ void sub_8053E90(void) { if (gSaveBlock1.battleMusic) music = gSaveBlock1.battleMusic; - else if (sav1_map_get_light_level() == 5) + else if (Overworld_GetMapTypeOfSaveblockLocation() == MAP_TYPE_UNDERWATER) music = BGM_DEEPDEEP; else if (TestPlayerAvatarFlags(PLAYER_AVATAR_FLAG_SURFING)) music = BGM_NAMINORI; @@ -854,17 +933,17 @@ void sub_8053F84(void) FadeOutAndPlayNewMapMusic(sav1_map_get_music(), 8); } -void sub_8053FB0(u16 music) +void Overworld_ChangeMusicTo(u16 newMusic) { u16 currentMusic = GetCurrentMapMusic(); - if (currentMusic != music && currentMusic != LEGENDARY_MUSIC) - FadeOutAndPlayNewMapMusic(music, 8); + if (currentMusic != newMusic && currentMusic != LEGENDARY_MUSIC) + FadeOutAndPlayNewMapMusic(newMusic, 8); } -u8 is_warp1_light_level_8_or_9(void) +u8 GetMapMusicFadeoutSpeed(void) { struct MapHeader *mapHeader = warp1_get_mapheader(); - if (is_light_level_8_or_9(mapHeader->mapType) == TRUE) + if (Overworld_MapTypeIsIndoors(mapHeader->mapType) == TRUE) return 2; else return 4; @@ -875,7 +954,7 @@ void sub_8053FF8(void) u16 music = warp1_target_get_music(); if (FlagGet(SPECIAL_FLAG_1) != TRUE && music != GetCurrentMapMusic()) { - u8 speed = is_warp1_light_level_8_or_9(); + u8 speed = GetMapMusicFadeoutSpeed(); FadeOutMapMusic(speed); } } @@ -890,43 +969,43 @@ void sub_8054044(void) FadeOutMapMusic(4); } -void sub_8054050(void) +static void PlayAmbientCry(void) { s16 x, y; - PlayerGetDestCoords((u16 *)&x, (u16 *)&y); - if (gUnknown_02029816 != TRUE + PlayerGetDestCoords(&x, &y); + if (sIsAmbientCryWaterMon != TRUE || MetatileBehavior_IsSurfableWaterOrUnderwater(MapGridGetMetatileBehaviorAt(x, y))) { s8 pan = (Random() % 88) + 212; s8 volume = (Random() % 30) + 50; - PlayCry2(gUnknown_02029814, pan, volume, 1); + PlayCry2(sAmbientCrySpecies, pan, volume, 1); } } -void sub_80540D0(s16 *a1, u16 *a2) +void UpdateAmbientCry(s16 *state, u16 *delayCounter) { - switch (*a1) + switch (*state) { case 0: - if (!gUnknown_02029814) - *a1 = 4; + if (sAmbientCrySpecies == SPECIES_NONE) + *state = 4; else - *a1 = 1; + *state = 1; break; case 1: - *a2 = (Random() % 2400) + 1200; - *a1 = 3; + *delayCounter = (Random() % 2400) + 1200; + *state = 3; break; case 2: - *a2 = (Random() % 1200) + 1200; - *a1 = 3; + *delayCounter = (Random() % 1200) + 1200; + *state = 3; break; case 3: - (*a2)--; - if (*a2 == 0) + (*delayCounter)--; + if (*delayCounter == 0) { - sub_8054050(); - *a1 = 2; + PlayAmbientCry(); + *state = 2; } break; case 4: @@ -934,58 +1013,70 @@ void sub_80540D0(s16 *a1, u16 *a2) } } -void sub_8054164(void) +void ChooseAmbientCrySpecies(void) { - if ((gSaveBlock1.location.mapGroup == 0 && gSaveBlock1.location.mapNum == 45) && !IsMirageIslandPresent()) + if ((gSaveBlock1.location.mapGroup == MAP_GROUP_ROUTE130 + && gSaveBlock1.location.mapNum == MAP_ID_ROUTE130) + && !IsMirageIslandPresent()) { - gUnknown_02029816 = TRUE; - gUnknown_02029814 = GetMirageIslandMon(); + // Only play water pokemon cries on this route + // when Mirage Island is not present + sIsAmbientCryWaterMon = TRUE; + sAmbientCrySpecies = GetLocalWaterMon(); } else { - gUnknown_02029814 = GetLocalWildMon(&gUnknown_02029816); + sAmbientCrySpecies = GetLocalWildMon(&sIsAmbientCryWaterMon); } } -u8 get_map_light_level_by_bank_and_number(s8 mapGroup, s8 mapNum) +u8 GetMapTypeByGroupAndId(s8 mapGroup, s8 mapNum) { - return get_mapheader_by_bank_and_number(mapGroup, mapNum)->mapType; + return Overworld_GetMapHeaderByGroupAndId(mapGroup, mapNum)->mapType; } -u8 get_map_light_level_from_warp(struct WarpData *warp) +u8 GetMapTypeByWarpData(struct WarpData *warp) { - return get_map_light_level_by_bank_and_number(warp->mapGroup, warp->mapNum); + return GetMapTypeByGroupAndId(warp->mapGroup, warp->mapNum); } -u8 sav1_map_get_light_level(void) +u8 Overworld_GetMapTypeOfSaveblockLocation(void) { - return get_map_light_level_from_warp(&gSaveBlock1.location); + return GetMapTypeByWarpData(&gSaveBlock1.location); } -u8 get_map_light_from_warp0(void) +u8 get_map_type_from_warp0(void) { - return get_map_light_level_from_warp(&gUnknown_020297F0); + return GetMapTypeByWarpData(&gUnknown_020297F0); } -bool8 is_light_level_1_2_3_5_or_6(u8 a1) +bool8 is_map_type_1_2_3_5_or_6(u8 mapType) { - if (a1 == 3 || a1 == 1 || a1 == 5 || a1 == 2 || a1 == 6) + if (mapType == MAP_TYPE_ROUTE + || mapType == MAP_TYPE_TOWN + || mapType == MAP_TYPE_UNDERWATER + || mapType == MAP_TYPE_CITY + || mapType == MAP_TYPE_6) return TRUE; else return FALSE; } -bool8 is_light_level_1_2_3_or_6(u8 a1) +bool8 Overworld_MapTypeAllowsTeleportAndFly(u8 mapType) { - if (a1 == 3 || a1 == 1 || a1 == 6 || a1 == 2) + if (mapType == MAP_TYPE_ROUTE + || mapType == MAP_TYPE_TOWN + || mapType == MAP_TYPE_6 + || mapType == MAP_TYPE_CITY) return TRUE; else return FALSE; } -bool8 is_light_level_8_or_9(u8 a1) +bool8 Overworld_MapTypeIsIndoors(u8 mapType) { - if (a1 == 8 || a1 == 9) + if (mapType == MAP_TYPE_INDOOR + || mapType == MAP_TYPE_SECRET_BASE) return TRUE; else return FALSE; @@ -993,17 +1084,17 @@ bool8 is_light_level_8_or_9(u8 a1) u8 unref_sub_8054260(void) { - return get_mapheader_by_bank_and_number(gSaveBlock1.warp2.mapGroup, gSaveBlock1.warp2.mapNum)->regionMapSectionId; + return Overworld_GetMapHeaderByGroupAndId(gSaveBlock1.warp2.mapGroup, gSaveBlock1.warp2.mapNum)->regionMapSectionId; } u8 sav1_map_get_name(void) { - return get_mapheader_by_bank_and_number(gSaveBlock1.location.mapGroup, gSaveBlock1.location.mapNum)->regionMapSectionId; + return Overworld_GetMapHeaderByGroupAndId(gSaveBlock1.location.mapGroup, gSaveBlock1.location.mapNum)->regionMapSectionId; } u8 sav1_map_get_battletype(void) { - return get_mapheader_by_bank_and_number(gSaveBlock1.location.mapGroup, gSaveBlock1.location.mapNum)->battleType; + return Overworld_GetMapHeaderByGroupAndId(gSaveBlock1.location.mapGroup, gSaveBlock1.location.mapNum)->battleType; } void ResetSafariZoneFlag_(void) @@ -1046,7 +1137,7 @@ void c1_overworld(void) c1_overworld_normal(gMain.newKeys, gMain.heldKeys); } -void c2_overworld_basic(void) +void OverworldBasic(void) { ScriptContext2_RunScript(); RunTasks(); @@ -1058,9 +1149,9 @@ void c2_overworld_basic(void) sub_8072EDC(); } -void sub_8054398(void) +void CB2_OverworldBasic(void) { - c2_overworld_basic(); + OverworldBasic(); } void c2_overworld(void) @@ -1068,7 +1159,7 @@ void c2_overworld(void) int fading = (gPaletteFade.active != 0); if (fading) SetVBlankCallback(NULL); - c2_overworld_basic(); + OverworldBasic(); if (fading) SetFieldVBlankCallback(); } @@ -1265,8 +1356,8 @@ void CB2_ContinueSavedGame(void) FieldClearVBlankHBlankCallbacks(); StopMapMusic(); ResetSafariZoneFlag_(); - sub_805338C(); - sub_8053198(); + LoadSaveblockMapHeader(); + LoadSaveblockMapObjScripts(); UnfreezeMapObjects(); DoTimeBasedEvents(); sub_805308C(); @@ -1317,11 +1408,11 @@ void VBlankCB_Field(void) void sub_8054814(void) { - u8 val = sav1_get_flash_used_on_map(); + u8 val = Overworld_GetFlashLevel(); if (val) { sub_80815E0(val); - sub_80895F8(gUnknown_08216694[0], gUnknown_08216694[1], gUnknown_08216694[2]); + sub_80895F8(gUnknown_08216694); } } @@ -2434,27 +2525,27 @@ void sub_8055BFC(u8 linkPlayerId, u8 a2) } } -u8 sub_8055C68(struct LinkPlayerMapObject *linkPlayerMapObj, struct MapObject *mapObj, u8 a3) +static u8 sub_8055C68(struct LinkPlayerMapObject *linkPlayerMapObj, struct MapObject *mapObj, u8 a3) { return gUnknown_082166AC[a3](linkPlayerMapObj, mapObj, a3); } -u8 sub_8055C88(struct LinkPlayerMapObject *linkPlayerMapObj, struct MapObject *mapObj, u8 a3) +static u8 sub_8055C88(struct LinkPlayerMapObject *linkPlayerMapObj, struct MapObject *mapObj, u8 a3) { return 1; } -u8 sub_8055C8C(struct LinkPlayerMapObject *linkPlayerMapObj, struct MapObject *mapObj, u8 a3) +static u8 sub_8055C8C(struct LinkPlayerMapObject *linkPlayerMapObj, struct MapObject *mapObj, u8 a3) { return gUnknown_082166AC[a3](linkPlayerMapObj, mapObj, a3); } -u8 sub_8055CAC(struct LinkPlayerMapObject *linkPlayerMapObj, struct MapObject *mapObj, u8 a3) +static u8 sub_8055CAC(struct LinkPlayerMapObject *linkPlayerMapObj, struct MapObject *mapObj, u8 a3) { return 0; } -u8 sub_8055CB0(struct LinkPlayerMapObject *linkPlayerMapObj, struct MapObject *mapObj, u8 a3) +static u8 sub_8055CB0(struct LinkPlayerMapObject *linkPlayerMapObj, struct MapObject *mapObj, u8 a3) { s16 x, y; @@ -2474,18 +2565,18 @@ u8 sub_8055CB0(struct LinkPlayerMapObject *linkPlayerMapObj, struct MapObject *m } } -u8 sub_8055D18(struct LinkPlayerMapObject *linkPlayerMapObj, struct MapObject *mapObj, u8 a3) +static u8 sub_8055D18(struct LinkPlayerMapObject *linkPlayerMapObj, struct MapObject *mapObj, u8 a3) { mapObj->mapobj_unk_19 = npc_something3(a3, mapObj->mapobj_unk_19); return 0; } -void sub_8055D30(struct LinkPlayerMapObject *linkPlayerMapObj, struct MapObject *mapObj) +static void sub_8055D30(struct LinkPlayerMapObject *linkPlayerMapObj, struct MapObject *mapObj) { linkPlayerMapObj->mode = 0; } -void sub_8055D38(struct LinkPlayerMapObject *linkPlayerMapObj, struct MapObject *mapObj) +static void sub_8055D38(struct LinkPlayerMapObject *linkPlayerMapObj, struct MapObject *mapObj) { mapObj->mapobj_unk_21--; linkPlayerMapObj->mode = 1; diff --git a/src/field/player_pc.c b/src/field/player_pc.c index 6d52c560a..83e6dd221 100644 --- a/src/field/player_pc.c +++ b/src/field/player_pc.c @@ -18,7 +18,7 @@ #include "songs.h" #include "name_string_util.h" #include "mail.h" -#include "rom4.h" +#include "overworld.h" #include "player_pc.h" extern void DisplayItemMessageOnField(u8, const u8*, TaskFunc, u16); @@ -106,7 +106,7 @@ static const u8 *const gPCText_OptionDescList[] = gMenuText_GoBackToPrev }; -static const struct MenuAction2 gPCText_PlayerPCOptionsText[] = +static const struct MenuAction2 sPlayerPCMenuActions[] = { { SecretBaseText_ItemStorage, PlayerPC_ItemStorage }, { gPCText_Mailbox, PlayerPC_Mailbox }, @@ -226,7 +226,7 @@ void PlayerPC(void) static void InitPlayerPCMenu(u8 taskId) { MenuDrawTextWindow(0, 0, 10, gPcItemMenuOptionsNum * 2 + 1); - PrintMenuItemsReordered(1, 1, gPcItemMenuOptionsNum, (struct MenuAction *)gPCText_PlayerPCOptionsText, gPcItemMenuOptionOrder); + PrintMenuItemsReordered(1, 1, gPcItemMenuOptionsNum, sPlayerPCMenuActions, gPcItemMenuOptionOrder); InitMenu(0, 1, 1, gPcItemMenuOptionsNum, 0, 9); TASK.FUNC = PlayerPCProcessMenuInput; } @@ -247,13 +247,13 @@ static void PlayerPCProcessMenuInput(u8 taskId) { HandleDestroyMenuCursors(); PlaySE(SE_SELECT); - gPCText_PlayerPCOptionsText[gPcItemMenuOptionOrder[GetMenuCursorPos()]].func(taskId); + sPlayerPCMenuActions[gPcItemMenuOptionOrder[GetMenuCursorPos()]].func(taskId); } else if (gMain.newKeys & B_BUTTON) { HandleDestroyMenuCursors(); PlaySE(SE_SELECT); - gPCText_PlayerPCOptionsText[gPcItemMenuOptionsNum[gPcItemMenuOptionOrder - 1]].func(taskId); // run EXIT. + sPlayerPCMenuActions[gPcItemMenuOptionsNum[gPcItemMenuOptionOrder - 1]].func(taskId); // run EXIT. } } diff --git a/src/field/pokeblock.c b/src/field/pokeblock.c index 029bb066f..d69c41639 100644 --- a/src/field/pokeblock.c +++ b/src/field/pokeblock.c @@ -3,7 +3,7 @@ // #include "global.h" -#include "rom4.h" +#include "overworld.h" #include "sprite.h" #include "script.h" #include "strings.h" @@ -816,7 +816,7 @@ static void sub_810C368(u8 taskId) sub_80F98A4(1); BasicInitMenuWindow(&gWindowConfig_81E6E50); MenuDrawTextWindow(7, v0 + 4, 13, 11); - PrintMenuItemsReordered(8, v0 + 5, gUnknown_0203924C, (const struct MenuAction *)gUnknown_083F7EF4, gUnknown_03000758); + PrintMenuItemsReordered(8, v0 + 5, gUnknown_0203924C, gUnknown_083F7EF4, gUnknown_03000758); InitMenu(0, 8, v0 + 5, gUnknown_0203924C, 0, 5); gScriptItemId = gUnknown_02039248.unk0 + gUnknown_02039248.unk1; gTasks[taskId].func = sub_810C40C; diff --git a/src/field/region_map.c b/src/field/region_map.c index 7ca7e809f..bfd2729c2 100644 --- a/src/field/region_map.c +++ b/src/field/region_map.c @@ -9,7 +9,7 @@ #include "palette.h" #include "pokemon_menu.h" #include "region_map.h" -#include "rom4.h" +#include "overworld.h" #include "secret_base.h" #include "songs.h" #include "sprite.h" @@ -714,7 +714,7 @@ static void InitializeCursorPosition(void) return; } - switch (get_map_light_level_by_bank_and_number(gSaveBlock1.location.mapGroup, gSaveBlock1.location.mapNum) - 1) + switch (GetMapTypeByGroupAndId(gSaveBlock1.location.mapGroup, gSaveBlock1.location.mapNum) - 1) { default: case 0: @@ -733,7 +733,7 @@ static void InitializeCursorPosition(void) break; case 3: case 6: - mapHeader = get_mapheader_by_bank_and_number(gSaveBlock1.warp4.mapGroup, gSaveBlock1.warp4.mapNum); + mapHeader = Overworld_GetMapHeaderByGroupAndId(gSaveBlock1.warp4.mapGroup, gSaveBlock1.warp4.mapNum); gRegionMap->mapSecId = mapHeader->regionMapSectionId; gRegionMap->playerIsInCave = TRUE; mapWidth = mapHeader->mapData->width; @@ -742,7 +742,7 @@ static void InitializeCursorPosition(void) y = gSaveBlock1.warp4.y; break; case 8: - mapHeader = get_mapheader_by_bank_and_number(gSaveBlock1.warp2.mapGroup, gSaveBlock1.warp2.mapNum); + mapHeader = Overworld_GetMapHeaderByGroupAndId(gSaveBlock1.warp2.mapGroup, gSaveBlock1.warp2.mapNum); gRegionMap->mapSecId = mapHeader->regionMapSectionId; gRegionMap->playerIsInCave = TRUE; mapWidth = mapHeader->mapData->width; @@ -758,12 +758,12 @@ static void InitializeCursorPosition(void) if (gRegionMap->mapSecId != MAPSEC_UNK_0x57) { r4 = &gSaveBlock1.warp4; - mapHeader = get_mapheader_by_bank_and_number(r4->mapGroup, r4->mapNum); + mapHeader = Overworld_GetMapHeaderByGroupAndId(r4->mapGroup, r4->mapNum); } else { r4 = &gSaveBlock1.warp2; - mapHeader = get_mapheader_by_bank_and_number(r4->mapGroup, r4->mapNum); + mapHeader = Overworld_GetMapHeaderByGroupAndId(r4->mapGroup, r4->mapNum); gRegionMap->mapSecId = mapHeader->regionMapSectionId; } gRegionMap->playerIsInCave = FALSE; @@ -850,7 +850,7 @@ static void sub_80FB600(void) default: case 0: { - struct MapHeader *mapHeader = get_mapheader_by_bank_and_number(mapGroup, mapNum); + struct MapHeader *mapHeader = Overworld_GetMapHeaderByGroupAndId(mapGroup, mapNum); u16 r1; gRegionMap->mapSecId = mapHeader->regionMapSectionId; diff --git a/src/field/safari_zone.c b/src/field/safari_zone.c index a47c8e951..14fd1ddc4 100644 --- a/src/field/safari_zone.c +++ b/src/field/safari_zone.c @@ -4,7 +4,7 @@ #include "field_fadetransition.h" #include "field_player_avatar.h" #include "main.h" -#include "rom4.h" +#include "overworld.h" #include "script.h" #include "string_util.h" #include "text.h" @@ -51,7 +51,7 @@ void SetSafariZoneFlag(void) void ResetSafariZoneFlag(void) { - FlagReset(SYS_SAFARI_MODE); + FlagClear(SYS_SAFARI_MODE); } void EnterSafariMode(void) diff --git a/src/field/scrcmd.c b/src/field/scrcmd.c index 66578f350..31a90158a 100644 --- a/src/field/scrcmd.c +++ b/src/field/scrcmd.c @@ -31,7 +31,7 @@ #include "party_menu.h" #include "pokemon.h" #include "rng.h" -#include "rom4.h" +#include "overworld.h" #include "rtc.h" #include "script.h" #include "script_menu.h" @@ -50,11 +50,11 @@ typedef void (*NativeFunc)(void); extern u32 gUnknown_0202E8AC; static EWRAM_DATA u32 gUnknown_0202E8B0 = 0; -static EWRAM_DATA u16 gUnknown_0202E8B4 = 0; -static EWRAM_DATA u16 gUnknown_0202E8B6 = 0; -static EWRAM_DATA u16 gUnknown_0202E8B8 = 0; -static EWRAM_DATA u16 gUnknown_0202E8BA = 0; -static EWRAM_DATA u16 gUnknown_0202E8BC = 0; +static EWRAM_DATA u16 sPauseCounter = 0; +static EWRAM_DATA u16 sMovingNpcId = 0; +static EWRAM_DATA u16 sMovingNpcMapBank = 0; +static EWRAM_DATA u16 sMovingNpcMapId = 0; +static EWRAM_DATA u16 sFieldEffectScriptId = 0; extern u16 gSpecialVar_0x8000; extern u16 gSpecialVar_0x8001; @@ -109,8 +109,8 @@ bool8 ScrCmd_end(struct ScriptContext *ctx) bool8 ScrCmd_jumpasm(struct ScriptContext *ctx) { - u32 addr = ScriptReadWord(ctx); - SetupNativeScript(ctx, (void *)addr); + bool8 (*addr)(void) = (bool8 (*)(void))ScriptReadWord(ctx); + SetupNativeScript(ctx, addr); return TRUE; } @@ -542,7 +542,7 @@ bool8 ScrCmd_setflag(struct ScriptContext *ctx) bool8 ScrCmd_clearflag(struct ScriptContext *ctx) { - FlagReset(ScriptReadHalfword(ctx)); + FlagClear(ScriptReadHalfword(ctx)); return FALSE; } @@ -567,8 +567,8 @@ bool8 ScrCmd_lighten(struct ScriptContext *ctx) bool8 ScrCmd_darken(struct ScriptContext *ctx) { - u16 value = VarGet(ScriptReadHalfword(ctx)); - sub_8053CE4(value); + u16 flashLevel = VarGet(ScriptReadHalfword(ctx)); + Overworld_SetFlashLevel(flashLevel); return FALSE; } @@ -598,9 +598,9 @@ bool8 ScrCmd_fadescreendelay(struct ScriptContext *ctx) bool8 s28_pause_asm() { - gUnknown_0202E8B4--; + sPauseCounter--; - if (gUnknown_0202E8B4 == 0) + if (sPauseCounter == 0) return TRUE; else return FALSE; @@ -608,7 +608,7 @@ bool8 s28_pause_asm() bool8 ScrCmd_pause(struct ScriptContext *ctx) { - gUnknown_0202E8B4 = ScriptReadHalfword(ctx); + sPauseCounter = ScriptReadHalfword(ctx); SetupNativeScript(ctx, s28_pause_asm); return TRUE; } @@ -815,7 +815,7 @@ bool8 ScrCmd_playsfx(struct ScriptContext *ctx) return FALSE; } -bool8 s30_music_check_asm() +static bool8 WaitForSoundEffectFinish() { if (!IsSEPlaying()) return TRUE; @@ -825,7 +825,7 @@ bool8 s30_music_check_asm() bool8 ScrCmd_checksound(struct ScriptContext *ctx) { - SetupNativeScript(ctx, s30_music_check_asm); + SetupNativeScript(ctx, WaitForSoundEffectFinish); return TRUE; } @@ -835,14 +835,14 @@ bool8 ScrCmd_fanfare(struct ScriptContext *ctx) return FALSE; } -bool8 s32_fanfare_wait_asm() +static bool8 WaitForFanfareFinish() { return IsFanfareTaskInactive(); } bool8 ScrCmd_waitfanfare(struct ScriptContext *ctx) { - SetupNativeScript(ctx, s32_fanfare_wait_asm); + SetupNativeScript(ctx, WaitForFanfareFinish); return TRUE; } @@ -870,15 +870,15 @@ bool8 ScrCmd_fadedefault(struct ScriptContext *ctx) bool8 ScrCmd_fademusic(struct ScriptContext *ctx) { - sub_8053FB0(ScriptReadHalfword(ctx)); + Overworld_ChangeMusicTo(ScriptReadHalfword(ctx)); return FALSE; } bool8 ScrCmd_fadeout(struct ScriptContext *ctx) { - u8 val = ScriptReadByte(ctx); - if (val) - FadeOutBGMTemporarily(4 * val); + u8 speed = ScriptReadByte(ctx); + if (speed != 0) + FadeOutBGMTemporarily(4 * speed); else FadeOutBGMTemporarily(4); SetupNativeScript(ctx, IsBGMPausedOrStopped); @@ -887,9 +887,9 @@ bool8 ScrCmd_fadeout(struct ScriptContext *ctx) bool8 ScrCmd_fadein(struct ScriptContext *ctx) { - u8 val = ScriptReadByte(ctx); - if (val) - FadeInBGM(4 * val); + u8 speed = ScriptReadByte(ctx); + if (speed != 0) + FadeInBGM(4 * speed); else FadeInBGM(4); return FALSE; @@ -897,54 +897,56 @@ bool8 ScrCmd_fadein(struct ScriptContext *ctx) bool8 ScrCmd_move(struct ScriptContext *ctx) { - u16 v1 = VarGet(ScriptReadHalfword(ctx)); - void *v2 = (void *)ScriptReadWord(ctx); - exec_movement(v1, gSaveBlock1.location.mapNum, gSaveBlock1.location.mapGroup, v2); - gUnknown_0202E8B6 = v1; + u16 localId = VarGet(ScriptReadHalfword(ctx)); + void *movementScript = (void *)ScriptReadWord(ctx); + + ScriptMovement_StartObjectMovementScript(localId, gSaveBlock1.location.mapNum, gSaveBlock1.location.mapGroup, movementScript); + sMovingNpcId = localId; return FALSE; } bool8 ScrCmd_movecoords(struct ScriptContext *ctx) { - u16 v1 = VarGet(ScriptReadHalfword(ctx)); - void *v2 = (void *)ScriptReadWord(ctx); - u8 v3 = ScriptReadByte(ctx); - u8 v4 = ScriptReadByte(ctx); - exec_movement(v1, v4, v3, v2); - gUnknown_0202E8B6 = v1; + u16 localId = VarGet(ScriptReadHalfword(ctx)); + void *movementScript = (void *)ScriptReadWord(ctx); + u8 mapGroup = ScriptReadByte(ctx); + u8 mapNum = ScriptReadByte(ctx); + + ScriptMovement_StartObjectMovementScript(localId, mapNum, mapGroup, movementScript); + sMovingNpcId = localId; return FALSE; } -bool8 s51a_0806B288(void) +static bool8 WaitForMovementFinish(void) { - return sub_80A212C(gUnknown_0202E8B6, gUnknown_0202E8BA, gUnknown_0202E8B8); + return ScriptMovement_IsObjectMovementFinished(sMovingNpcId, sMovingNpcMapId, sMovingNpcMapBank); } bool8 ScrCmd_waitmove(struct ScriptContext *ctx) { - u16 v1 = VarGet(ScriptReadHalfword(ctx)); - if (v1) - gUnknown_0202E8B6 = v1; - gUnknown_0202E8B8 = gSaveBlock1.location.mapGroup; - gUnknown_0202E8BA = gSaveBlock1.location.mapNum; - SetupNativeScript(ctx, s51a_0806B288); + u16 localId = VarGet(ScriptReadHalfword(ctx)); + + if (localId != 0) + sMovingNpcId = localId; + sMovingNpcMapBank = gSaveBlock1.location.mapGroup; + sMovingNpcMapId = gSaveBlock1.location.mapNum; + SetupNativeScript(ctx, WaitForMovementFinish); return TRUE; } bool8 ScrCmd_waitmovexy(struct ScriptContext *ctx) { - u16 v1 = VarGet(ScriptReadHalfword(ctx)); - u8 v2; - u8 v3; - - if (v1) - gUnknown_0202E8B6 = v1; - - v2 = ScriptReadByte(ctx); - v3 = ScriptReadByte(ctx); - gUnknown_0202E8B8 = v2; - gUnknown_0202E8BA = v3; - SetupNativeScript(ctx, s51a_0806B288); + u16 localId = VarGet(ScriptReadHalfword(ctx)); + u8 mapBank; + u8 mapId; + + if (localId != 0) + sMovingNpcId = localId; + mapBank = ScriptReadByte(ctx); + mapId = ScriptReadByte(ctx); + sMovingNpcMapBank = mapBank; + sMovingNpcMapId = mapId; + SetupNativeScript(ctx, WaitForMovementFinish); return TRUE; } @@ -994,7 +996,7 @@ bool8 ScrCmd_movespriteperm(struct ScriptContext *ctx) u16 v1 = VarGet(ScriptReadHalfword(ctx)); u16 v2 = VarGet(ScriptReadHalfword(ctx)); u32 v3 = VarGet(ScriptReadHalfword(ctx)); - update_saveblock1_field_object_coords(v1, v2, v3); + Overworld_SaveMapObjCoords(v1, v2, v3); return FALSE; } @@ -1054,9 +1056,9 @@ bool8 ScrCmd_faceplayer(struct ScriptContext *ctx) bool8 ScrCmd_spriteface(struct ScriptContext *ctx) { - u16 v1 = VarGet(ScriptReadHalfword(ctx)); - u8 v2 = ScriptReadByte(ctx); - FieldObjectTurnByLocalIdAndMap(v1, gSaveBlock1.location.mapNum, gSaveBlock1.location.mapGroup, v2); + u16 localId = VarGet(ScriptReadHalfword(ctx)); + u8 direction = ScriptReadByte(ctx); + FieldObjectTurnByLocalIdAndMap(localId, gSaveBlock1.location.mapNum, gSaveBlock1.location.mapGroup, direction); return FALSE; } @@ -1064,7 +1066,7 @@ bool8 ScrCmd_spritebehave(struct ScriptContext *ctx) { u16 v1 = VarGet(ScriptReadHalfword(ctx)); u8 v2 = ScriptReadByte(ctx); - update_saveblock1_field_object_movement_behavior(v1, v2); + Overworld_SaveMapObjMovementType(v1, v2); return FALSE; } @@ -1112,7 +1114,7 @@ bool8 ScrCmd_lock(struct ScriptContext *ctx) { if (gMapObjects[gSelectedMapObject].active) { - sub_8064DD8(); + LockSelectedMapObject(); SetupNativeScript(ctx, sub_8064DB4); } else @@ -1198,9 +1200,9 @@ bool8 ScrCmd_waitbutton(struct ScriptContext *ctx) bool8 ScrCmd_yesnobox(struct ScriptContext *ctx) { - u8 v1 = ScriptReadByte(ctx); - u8 v2 = ScriptReadByte(ctx); - if (yes_no_box(v1, v2) == 1) + u8 left = ScriptReadByte(ctx); + u8 top = ScriptReadByte(ctx); + if (ScriptMenu_YesNo(left, top) == TRUE) { ScriptContext1_Stop(); return TRUE; @@ -1213,11 +1215,11 @@ bool8 ScrCmd_yesnobox(struct ScriptContext *ctx) bool8 ScrCmd_multichoice(struct ScriptContext *ctx) { - u8 v1 = ScriptReadByte(ctx); - u8 v2 = ScriptReadByte(ctx); - u8 v3 = ScriptReadByte(ctx); - u8 v4 = ScriptReadByte(ctx); - if (sub_80B5054(v1, v2, v3, v4) == 1) + u8 left = ScriptReadByte(ctx); + u8 top = ScriptReadByte(ctx); + u8 multichoiceId = ScriptReadByte(ctx); + u8 ignoreBPress = ScriptReadByte(ctx); + if (ScriptMenu_Multichoice(left, top, multichoiceId, ignoreBPress) == TRUE) { ScriptContext1_Stop(); return TRUE; @@ -1230,12 +1232,12 @@ bool8 ScrCmd_multichoice(struct ScriptContext *ctx) bool8 ScrCmd_multichoicedef(struct ScriptContext *ctx) { - u8 v1 = ScriptReadByte(ctx); - u8 v2 = ScriptReadByte(ctx); - u8 v3 = ScriptReadByte(ctx); - u8 v4 = ScriptReadByte(ctx); - u8 v5 = ScriptReadByte(ctx); - if (sub_80B50B0(v1, v2, v3, v5, v4) == 1) + u8 left = ScriptReadByte(ctx); + u8 top = ScriptReadByte(ctx); + u8 multichoiceId = ScriptReadByte(ctx); + u8 defaultChoice = ScriptReadByte(ctx); + u8 ignoreBPress = ScriptReadByte(ctx); + if (ScriptMenu_MultichoiceWithDefault(left, top, multichoiceId, ignoreBPress, defaultChoice) == TRUE) { ScriptContext1_Stop(); return TRUE; @@ -1248,22 +1250,22 @@ bool8 ScrCmd_multichoicedef(struct ScriptContext *ctx) bool8 ScrCmd_showbox(struct ScriptContext *ctx) { - u8 v1 = ScriptReadByte(ctx); - u8 v2 = ScriptReadByte(ctx); - u8 v3 = ScriptReadByte(ctx); - u8 v4 = ScriptReadByte(ctx); - MenuDrawTextWindow(v1, v2, v3, v4); + u8 left = ScriptReadByte(ctx); + u8 top = ScriptReadByte(ctx); + u8 right = ScriptReadByte(ctx); + u8 bottom = ScriptReadByte(ctx); + MenuDrawTextWindow(left, top, right, bottom); return FALSE; } bool8 ScrCmd_multichoicerow(struct ScriptContext *ctx) { - u8 v1 = ScriptReadByte(ctx); - u8 v2 = ScriptReadByte(ctx); - u8 v3 = ScriptReadByte(ctx); - u8 v4 = ScriptReadByte(ctx); - u8 v5 = ScriptReadByte(ctx); - if (sub_80B5578(v1, v2, v3, v5, v4) == 1) + u8 left = ScriptReadByte(ctx); + u8 top = ScriptReadByte(ctx); + u8 multichoiceId = ScriptReadByte(ctx); + u8 numColumns = ScriptReadByte(ctx); + u8 ignoreBPress = ScriptReadByte(ctx); + if (ScriptMenu_MultichoiceGrid(left, top, multichoiceId, ignoreBPress, numColumns) == TRUE) { ScriptContext1_Stop(); return TRUE; @@ -1276,21 +1278,22 @@ bool8 ScrCmd_multichoicerow(struct ScriptContext *ctx) bool8 ScrCmd_hidebox(struct ScriptContext *ctx) { - u8 v1 = ScriptReadByte(ctx); - u8 v2 = ScriptReadByte(ctx); - u8 v3 = ScriptReadByte(ctx); - u8 v4 = ScriptReadByte(ctx); - MenuZeroFillWindowRect(v1, v2, v3, v4); + u8 left = ScriptReadByte(ctx); + u8 top = ScriptReadByte(ctx); + u8 right = ScriptReadByte(ctx); + u8 bottom = ScriptReadByte(ctx); + MenuZeroFillWindowRect(left, top, right, bottom); return FALSE; } +// unused bool8 ScrCmd_clearbox(struct ScriptContext *ctx) { - u8 v1 = ScriptReadByte(ctx); - u8 v2 = ScriptReadByte(ctx); - u8 v3 = ScriptReadByte(ctx); - u8 v4 = ScriptReadByte(ctx); - if (Multichoice(v1, v2, v3, v4) == 1) + u8 left = ScriptReadByte(ctx); + u8 top = ScriptReadByte(ctx); + u8 multichoiceId = ScriptReadByte(ctx); + u8 ignoreBPress = ScriptReadByte(ctx); + if (Multichoice(left, top, multichoiceId, ignoreBPress) == TRUE) { ScriptContext1_Stop(); return TRUE; @@ -1303,19 +1306,19 @@ bool8 ScrCmd_clearbox(struct ScriptContext *ctx) bool8 ScrCmd_showpokepic(struct ScriptContext *ctx) { - u16 v1 = VarGet(ScriptReadHalfword(ctx)); - u8 v2 = ScriptReadByte(ctx); - u8 v3 = ScriptReadByte(ctx); - sub_80B58C4(v1, v2, v3); + u16 species = VarGet(ScriptReadHalfword(ctx)); + u8 x = ScriptReadByte(ctx); + u8 y = ScriptReadByte(ctx); + ScriptMenu_ShowPokemonPic(species, x, y); return FALSE; } bool8 ScrCmd_hidepokepic(struct ScriptContext *ctx) { - void *func = picbox_close(); - if (!func) - return FALSE; + bool8 (*func)(void) = ScriptMenu_GetPicboxWaitFunc(); + if (func == NULL) + return FALSE; SetupNativeScript(ctx, func); return TRUE; } @@ -1447,29 +1450,29 @@ bool8 ScrCmd_vbuffer(struct ScriptContext *ctx) bool8 ScrCmd_givepokemon(struct ScriptContext *ctx) { - u16 v3 = VarGet(ScriptReadHalfword(ctx)); - u8 v5 = ScriptReadByte(ctx); - u16 v7 = VarGet(ScriptReadHalfword(ctx)); - u32 v8 = ScriptReadWord(ctx); - u32 v9 = ScriptReadWord(ctx); - u8 v10 = ScriptReadByte(ctx); - gScriptResult = ScriptGiveMon(v3, v5, v7, v8, v9, v10); + u16 species = VarGet(ScriptReadHalfword(ctx)); + u8 level = ScriptReadByte(ctx); + u16 item = VarGet(ScriptReadHalfword(ctx)); + u32 unkParam1 = ScriptReadWord(ctx); + u32 unkParam2 = ScriptReadWord(ctx); + u8 unkParam3 = ScriptReadByte(ctx); + gScriptResult = ScriptGiveMon(species, level, item, unkParam1, unkParam2, unkParam3); return FALSE; } bool8 ScrCmd_giveegg(struct ScriptContext *ctx) { - u16 value = VarGet(ScriptReadHalfword(ctx)); - gScriptResult = ScriptGiveEgg(value); + u16 species = VarGet(ScriptReadHalfword(ctx)); + gScriptResult = ScriptGiveEgg(species); return FALSE; } bool8 ScrCmd_setpokemove(struct ScriptContext *ctx) { - u8 v2 = ScriptReadByte(ctx); - u8 v3 = ScriptReadByte(ctx); - u16 v4 = ScriptReadHalfword(ctx); - ScriptSetMonMoveSlot(v2, v4, v3); + u8 partyIndex = ScriptReadByte(ctx); + u8 slot = ScriptReadByte(ctx); + u16 move = ScriptReadHalfword(ctx); + ScriptSetMonMoveSlot(partyIndex, move, slot); return FALSE; } @@ -1499,7 +1502,7 @@ bool8 ScrCmd_givemoney(struct ScriptContext *ctx) u32 amount = ScriptReadWord(ctx); u8 ignore = ScriptReadByte(ctx); if (!ignore) - sub_80B79B8(&gSaveBlock1.money, amount); + AddMoney(&gSaveBlock1.money, amount); return FALSE; } @@ -1508,7 +1511,7 @@ bool8 ScrCmd_paymoney(struct ScriptContext *ctx) u32 amount = ScriptReadWord(ctx); u8 ignore = ScriptReadByte(ctx); if (!ignore) - sub_80B79E0(&gSaveBlock1.money, amount); + RemoveMoney(&gSaveBlock1.money, amount); return FALSE; } @@ -1523,19 +1526,19 @@ bool8 ScrCmd_checkmoney(struct ScriptContext *ctx) bool8 ScrCmd_showmoney(struct ScriptContext *ctx) { - u8 v2 = ScriptReadByte(ctx); - u8 v3 = ScriptReadByte(ctx); + u8 x = ScriptReadByte(ctx); + u8 y = ScriptReadByte(ctx); u8 ignore = ScriptReadByte(ctx); if (!ignore) - sub_80B7C14(gSaveBlock1.money, v2, v3); + OpenMoneyWindow(gSaveBlock1.money, x, y); return FALSE; } bool8 ScrCmd_hidemoney(struct ScriptContext *ctx) { - u8 v2 = ScriptReadByte(ctx); - u8 v3 = ScriptReadByte(ctx); - RemoveMoneyLabelObject(v2, v3); + u8 x = ScriptReadByte(ctx); + u8 y = ScriptReadByte(ctx); + CloseMoneyWindow(x, y); return FALSE; } @@ -1545,7 +1548,7 @@ bool8 ScrCmd_updatemoney(struct ScriptContext *ctx) u8 v3 = ScriptReadByte(ctx); u8 ignore = ScriptReadByte(ctx); if (!ignore) - sub_80B7BEC(gSaveBlock1.money, v2, v3); + UpdateMoneyWindow(gSaveBlock1.money, v2, v3); return FALSE; } @@ -1575,32 +1578,32 @@ bool8 ScrCmd_updatecoins(struct ScriptContext *ctx) bool8 ScrCmd_trainerbattle(struct ScriptContext *ctx) { - ctx->scriptPtr = TrainerBattleConfigure(ctx->scriptPtr); + ctx->scriptPtr = BattleSetup_ConfigureTrainerBattle(ctx->scriptPtr); return FALSE; } bool8 ScrCmd_reptrainerbattle(struct ScriptContext *ctx) { - sub_80825E4(); + BattleSetup_StartTrainerBattle(); return TRUE; } bool8 ScrCmd_endtrainerbattle(struct ScriptContext *ctx) { - ctx->scriptPtr = sub_80826E8(); + ctx->scriptPtr = BattleSetup_GetScriptAddrAfterBattle(); return FALSE; } bool8 ScrCmd_endtrainerbattle2(struct ScriptContext *ctx) { - ctx->scriptPtr = sub_8082700(); + ctx->scriptPtr = BattleSetup_GetTrainerPostBattleScript(); return FALSE; } bool8 ScrCmd_checktrainerflag(struct ScriptContext *ctx) { u16 index = VarGet(ScriptReadHalfword(ctx)); - ctx->comparisonResult = trainer_flag_check(index); + ctx->comparisonResult = HasTrainerAlreadyBeenFought(index); return FALSE; } @@ -1620,16 +1623,16 @@ bool8 ScrCmd_settrainerflag(struct ScriptContext *ctx) bool8 ScrCmd_setwildbattle(struct ScriptContext *ctx) { - u16 v2 = ScriptReadHalfword(ctx); - u8 v4 = ScriptReadByte(ctx); - u16 v5 = ScriptReadHalfword(ctx); - ScriptWildBattle(v2, v4, v5); + u16 species = ScriptReadHalfword(ctx); + u8 level = ScriptReadByte(ctx); + u16 item = ScriptReadHalfword(ctx); + CreateScriptedWildMon(species, level, item); return FALSE; } bool8 ScrCmd_dowildbattle(struct ScriptContext *ctx) { - StartBattle_ScriptedWild(); + BattleSetup_StartScriptedWildBattle(); ScriptContext1_Stop(); return TRUE; } @@ -1668,13 +1671,13 @@ bool8 ScrCmd_pokecasino(struct ScriptContext *ctx) bool8 ScrCmd_event_8a(struct ScriptContext *ctx) { - u8 v2 = ScriptReadByte(ctx); - u8 v3 = ScriptReadByte(ctx); - u8 v4 = ScriptReadByte(ctx); - if (!v3) - PlantBerryTree(v2, 0, v4, FALSE); + u8 treeId = ScriptReadByte(ctx); + u8 berry = ScriptReadByte(ctx); + u8 growthStage = ScriptReadByte(ctx); + if (berry == 0) + PlantBerryTree(treeId, 0, growthStage, FALSE); else - PlantBerryTree(v2, v3, v4, FALSE); + PlantBerryTree(treeId, berry, growthStage, FALSE); return FALSE; } @@ -1716,21 +1719,21 @@ bool8 ScrCmd_contestlinktransfer(struct ScriptContext *ctx) bool8 ScrCmd_doanimation(struct ScriptContext *ctx) { u16 effectId = VarGet(ScriptReadHalfword(ctx)); - gUnknown_0202E8BC = effectId; - FieldEffectStart(gUnknown_0202E8BC); + sFieldEffectScriptId = effectId; + FieldEffectStart(sFieldEffectScriptId); return FALSE; } bool8 ScrCmd_setanimation(struct ScriptContext *ctx) { - u8 v2 = ScriptReadByte(ctx); - gUnknown_0202FF84[v2] = (s16)VarGet(ScriptReadHalfword(ctx)); + u8 argNum = ScriptReadByte(ctx); + gFieldEffectArguments[argNum] = (s16)VarGet(ScriptReadHalfword(ctx)); return FALSE; } static bool8 sub_8067B48() { - if (!FieldEffectActiveListContains(gUnknown_0202E8BC)) + if (!FieldEffectActiveListContains(sFieldEffectScriptId)) return TRUE; else return FALSE; @@ -1738,7 +1741,7 @@ static bool8 sub_8067B48() bool8 ScrCmd_checkanimation(struct ScriptContext *ctx) { - gUnknown_0202E8BC = VarGet(ScriptReadHalfword(ctx)); + sFieldEffectScriptId = VarGet(ScriptReadHalfword(ctx)); SetupNativeScript(ctx, sub_8067B48); return TRUE; } @@ -1758,9 +1761,9 @@ bool8 ScrCmd_checkgender(struct ScriptContext *ctx) bool8 ScrCmd_pokecry(struct ScriptContext *ctx) { - u16 v3 = VarGet(ScriptReadHalfword(ctx)); - u16 v5 = VarGet(ScriptReadHalfword(ctx)); - PlayCry5(v3, v5); + u16 species = VarGet(ScriptReadHalfword(ctx)); + u16 mode = VarGet(ScriptReadHalfword(ctx)); + PlayCry5(species, mode); return FALSE; } @@ -1772,16 +1775,16 @@ bool8 ScrCmd_waitpokecry(struct ScriptContext *ctx) bool8 ScrCmd_setmaptile(struct ScriptContext *ctx) { - u16 v3 = VarGet(ScriptReadHalfword(ctx)); - u16 v5 = VarGet(ScriptReadHalfword(ctx)); - u16 v7 = VarGet(ScriptReadHalfword(ctx)); + u16 x = VarGet(ScriptReadHalfword(ctx)); + u16 y = VarGet(ScriptReadHalfword(ctx)); + u16 tileId = VarGet(ScriptReadHalfword(ctx)); u16 v8 = VarGet(ScriptReadHalfword(ctx)); - v3 += 7; - v5 += 7; + x += 7; + y += 7; if (!v8) - MapGridSetMetatileIdAt(v3, v5, v7); + MapGridSetMetatileIdAt(x, y, tileId); else - MapGridSetMetatileIdAt(v3, v5, v7 | 0xC00); + MapGridSetMetatileIdAt(x, y, tileId | 0xC00); return FALSE; } @@ -1791,7 +1794,7 @@ bool8 ScrCmd_setdooropened(struct ScriptContext *ctx) u16 y = VarGet(ScriptReadHalfword(ctx)); x += 7; y += 7; - PlaySE(sub_8058790(x, y)); + PlaySE(GetDoorSoundEffect(x, y)); FieldAnimateDoorOpen(x, y); return FALSE; } diff --git a/src/field/script_menu.c b/src/field/script_menu.c index 6e1a12a60..e25e74d8c 100644 --- a/src/field/script_menu.c +++ b/src/field/script_menu.c @@ -1,10 +1,12 @@ #include "global.h" +#include "script.h" #include "script_menu.h" #include "event_data.h" #include "field_effect.h" #include "menu.h" #include "palette.h" #include "script.h" +#include "songs.h" #include "sound.h" #include "sprite.h" #include "strings.h" @@ -13,538 +15,544 @@ // multichoice lists const struct MenuAction MultichoiceList_00[] = { - {(u8 *)OtherText_Petalburg, 0}, - {(u8 *)OtherText_Slateport, 0}, - {(u8 *)gOtherText_CancelNoTerminator, 0}, + {OtherText_Petalburg, NULL}, + {OtherText_Slateport, NULL}, + {gOtherText_CancelNoTerminator, NULL}, }; const struct MenuAction MultichoiceList_02[] = { - {(u8 *)OtherText_Enter, 0}, - {(u8 *)OtherText_Info3, 0}, - {(u8 *)gOtherText_CancelNoTerminator, 0}, + {OtherText_Enter, NULL}, + {OtherText_Info3, NULL}, + {gOtherText_CancelNoTerminator, NULL}, }; const struct MenuAction MultichoiceList_03[] = { - {(u8 *)OtherText_WhatsAContest, 0}, - {(u8 *)OtherText_TypesOfContest, 0}, - {(u8 *)OtherText_Ranks, 0}, - {(u8 *)gOtherText_CancelNoTerminator, 0}, + {OtherText_WhatsAContest, NULL}, + {OtherText_TypesOfContest, NULL}, + {OtherText_Ranks, NULL}, + {gOtherText_CancelNoTerminator, NULL}, }; const struct MenuAction MultichoiceList_04[] = { - {(u8 *)OtherText_CoolContest, 0}, - {(u8 *)OtherText_BeautyContest, 0}, - {(u8 *)OtherText_CuteContest, 0}, - {(u8 *)OtherText_SmartContest, 0}, - {(u8 *)OtherText_ToughContest, 0}, - {(u8 *)gOtherText_CancelNoTerminator, 0}, + {OtherText_CoolContest, NULL}, + {OtherText_BeautyContest, NULL}, + {OtherText_CuteContest, NULL}, + {OtherText_SmartContest, NULL}, + {OtherText_ToughContest, NULL}, + {gOtherText_CancelNoTerminator, NULL}, }; const struct MenuAction MultichoiceList_06[] = { - {(u8 *)OtherText_Decoration, 0}, - {(u8 *)OtherText_PackUp, 0}, - {(u8 *)OtherText_Registry, 0}, - {(u8 *)gOtherText_CancelNoTerminator, 0}, + {OtherText_Decoration, NULL}, + {OtherText_PackUp, NULL}, + {OtherText_Registry, NULL}, + {gOtherText_CancelNoTerminator, NULL}, }; const struct MenuAction MultichoiceList_05[] = { - {(u8 *)OtherText_Decoration, 0}, - {(u8 *)OtherText_PackUp, 0}, - {(u8 *)gOtherText_CancelNoTerminator, 0}, + {OtherText_Decoration, NULL}, + {OtherText_PackUp, NULL}, + {gOtherText_CancelNoTerminator, NULL}, }; const struct MenuAction MultichoiceList_07[] = { - {(u8 *)OtherText_Register, 0}, - {(u8 *)OtherText_Registry, 0}, - {(u8 *)OtherText_Information, 0}, - {(u8 *)gOtherText_CancelNoTerminator, 0}, + {OtherText_Register, NULL}, + {OtherText_Registry, NULL}, + {OtherText_Information, NULL}, + {gOtherText_CancelNoTerminator, NULL}, }; const struct MenuAction MultichoiceList_12[] = { - {(u8 *)OtherText_Mach, 0}, - {(u8 *)OtherText_Acro, 0}, + {OtherText_Mach, NULL}, + {OtherText_Acro, NULL}, }; const struct MenuAction MultichoiceList_13[] = { - {(u8 *)OtherText_Poison, 0}, - {(u8 *)OtherText_Paralysis, 0}, - {(u8 *)OtherText_Sleep, 0}, - {(u8 *)OtherText_Burn, 0}, - {(u8 *)OtherText_Frozen, 0}, - {(u8 *)gOtherText_CancelNoTerminator, 0}, + {OtherText_Poison, NULL}, + {OtherText_Paralysis, NULL}, + {OtherText_Sleep, NULL}, + {OtherText_Burn, NULL}, + {OtherText_Frozen, NULL}, + {gOtherText_CancelNoTerminator, NULL}, }; const struct MenuAction MultichoiceList_14[] = { - {(u8 *)OtherText_Dewford, 0}, - {(u8 *)gOtherText_CancelNoTerminator, 0}, + {OtherText_Dewford, NULL}, + {gOtherText_CancelNoTerminator, NULL}, }; const struct MenuAction MultichoiceList_16[] = { - {(u8 *)OtherText_SawIt, 0}, - {(u8 *)OtherText_NotYet, 0}, + {OtherText_SawIt, NULL}, + {OtherText_NotYet, NULL}, }; const struct MenuAction MultichoiceList_17[] = { - {(u8 *)OtherText_Yes, 0}, - {(u8 *)OtherText_No, 0}, - {(u8 *)OtherText_Info3, 0}, + {OtherText_Yes, NULL}, + {OtherText_No, NULL}, + {OtherText_Info3, NULL}, }; const struct MenuAction MultichoiceList_18[] = { - {(u8 *)OtherText_SingleBattle, 0}, - {(u8 *)OtherText_DoubleBattle, 0}, - {(u8 *)OtherText_MultiBattle, 0}, - {(u8 *)gOtherText_CancelNoTerminator, 0}, + {OtherText_SingleBattle, NULL}, + {OtherText_DoubleBattle, NULL}, + {OtherText_MultiBattle, NULL}, + {gOtherText_CancelNoTerminator, NULL}, }; const struct MenuAction MultichoiceList_19[] = { - {(u8 *)OtherText_Littleroot, 0}, - {(u8 *)OtherText_Slateport, 0}, - {(u8 *)OtherText_Lilycove, 0}, + {OtherText_Littleroot, NULL}, + {OtherText_Slateport, NULL}, + {OtherText_Lilycove, NULL}, }; const struct MenuAction MultichoiceList_20[] = { - {(u8 *)OtherText_Yes, 0}, - {(u8 *)OtherText_No, 0}, - {(u8 *)OtherText_Info3, 0}, + {OtherText_Yes, NULL}, + {OtherText_No, NULL}, + {OtherText_Info3, NULL}, }; const struct MenuAction MultichoiceList_23[] = { - {(u8 *)OtherText_MakeAChallenge, 0}, - {(u8 *)OtherText_ObtainInformation, 0}, - {(u8 *)gOtherText_CancelNoTerminator, 0}, + {OtherText_MakeAChallenge, NULL}, + {OtherText_ObtainInformation, NULL}, + {gOtherText_CancelNoTerminator, NULL}, }; const struct MenuAction MultichoiceList_24[] = { - {(u8 *)OtherText_Lv50_2, 0}, - {(u8 *)OtherText_Lv100_2, 0}, - {(u8 *)gOtherText_CancelNoTerminator, 0}, + {OtherText_Lv50_2, NULL}, + {OtherText_Lv100_2, NULL}, + {gOtherText_CancelNoTerminator, NULL}, }; const struct MenuAction MultichoiceList_25[] = { - {(u8 *)OtherText_Zigzagoon, 0}, - {(u8 *)OtherText_Nincada, 0}, - {(u8 *)OtherText_Poochyena, 0}, + {OtherText_Zigzagoon, NULL}, + {OtherText_Nincada, NULL}, + {OtherText_Poochyena, NULL}, }; const struct MenuAction MultichoiceList_26[] = { - {(u8 *)OtherText_Nincada2, 0}, - {(u8 *)OtherText_Lotad, 0}, - {(u8 *)OtherText_Roselia, 0}, + {OtherText_Nincada2, NULL}, + {OtherText_Lotad, NULL}, + {OtherText_Roselia, NULL}, }; const struct MenuAction MultichoiceList_27[] = { - {(u8 *)OtherText_Shroomish, 0}, - {(u8 *)OtherText_Nincada3, 0}, - {(u8 *)OtherText_Surskit, 0}, + {OtherText_Shroomish, NULL}, + {OtherText_Nincada3, NULL}, + {OtherText_Surskit, NULL}, }; const struct MenuAction MultichoiceList_28[] = { - {(u8 *)OtherText_Treecko, 0}, - {(u8 *)OtherText_Torchic, 0}, - {(u8 *)OtherText_Mudkip, 0}, + {OtherText_Treecko, NULL}, + {OtherText_Torchic, NULL}, + {OtherText_Mudkip, NULL}, }; const struct MenuAction MultichoiceList_29[] = { - {(u8 *)OtherText_Seedot, 0}, - {(u8 *)OtherText_Shroomish2, 0}, - {(u8 *)OtherText_Spinda, 0}, + {OtherText_Seedot, NULL}, + {OtherText_Shroomish2, NULL}, + {OtherText_Spinda, NULL}, }; const struct MenuAction MultichoiceList_30[] = { - {(u8 *)OtherText_Shroomish3, 0}, - {(u8 *)OtherText_Zigzagoon2, 0}, - {(u8 *)OtherText_Wurmple, 0}, + {OtherText_Shroomish3, NULL}, + {OtherText_Zigzagoon2, NULL}, + {OtherText_Wurmple, NULL}, }; const struct MenuAction MultichoiceList_31[] = { - {(u8 *)OtherText_PokeBall, 0}, - {(u8 *)OtherText_SuperPotion, 0}, - {(u8 *)OtherText_SamePrice, 0}, + {OtherText_PokeBall, NULL}, + {OtherText_SuperPotion, NULL}, + {OtherText_SamePrice, NULL}, }; const struct MenuAction MultichoiceList_32[] = { - {(u8 *)OtherText_Yen135, 0}, - {(u8 *)OtherText_Yen155, 0}, - {(u8 *)OtherText_Yen175, 0}, + {OtherText_Yen135, NULL}, + {OtherText_Yen155, NULL}, + {OtherText_Yen175, NULL}, }; const struct MenuAction MultichoiceList_33[] = { - {(u8 *)OtherText_CostMore, 0}, - {(u8 *)OtherText_CostLess, 0}, - {(u8 *)OtherText_SamePrice2, 0}, + {OtherText_CostMore, NULL}, + {OtherText_CostLess, NULL}, + {OtherText_SamePrice2, NULL}, }; const struct MenuAction MultichoiceList_34[] = { - {(u8 *)OtherText_MaleSymbol, 0}, - {(u8 *)OtherText_FemaleSymbol, 0}, - {(u8 *)OtherText_Neither, 0}, + {OtherText_MaleSymbol, NULL}, + {OtherText_FemaleSymbol, NULL}, + {OtherText_Neither, NULL}, }; const struct MenuAction MultichoiceList_35[] = { - {(u8 *)OtherText_Males, 0}, - {(u8 *)OtherText_Females, 0}, - {(u8 *)OtherText_SameNumber, 0}, + {OtherText_Males, NULL}, + {OtherText_Females, NULL}, + {OtherText_SameNumber, NULL}, }; const struct MenuAction MultichoiceList_36[] = { - {(u8 *)OtherText_Male, 0}, - {(u8 *)OtherText_Female, 0}, - {(u8 *)OtherText_ItDepends, 0}, + {OtherText_Male, NULL}, + {OtherText_Female, NULL}, + {OtherText_ItDepends, NULL}, }; const struct MenuAction MultichoiceList_37[] = { - {(u8 *)OtherText_Six2, 0}, - {(u8 *)OtherText_Eight2, 0}, - {(u8 *)OtherText_Ten, 0}, + {OtherText_Six2, NULL}, + {OtherText_Eight2, NULL}, + {OtherText_Ten, NULL}, }; const struct MenuAction MultichoiceList_38[] = { - {(u8 *)OtherText_One, 0}, - {(u8 *)OtherText_Two, 0}, - {(u8 *)OtherText_Three, 0}, + {OtherText_One, NULL}, + {OtherText_Two, NULL}, + {OtherText_Three, NULL}, }; const struct MenuAction MultichoiceList_39[] = { - {(u8 *)OtherText_Six, 0}, - {(u8 *)OtherText_Seven, 0}, - {(u8 *)OtherText_Eight, 0}, + {OtherText_Six, NULL}, + {OtherText_Seven, NULL}, + {OtherText_Eight, NULL}, }; const struct MenuAction MultichoiceList_42[] = { - {(u8 *)OtherText_FreshWater, 0}, - {(u8 *)OtherText_SodaPop, 0}, - {(u8 *)OtherText_Lemonade, 0}, - {(u8 *)gOtherText_CancelNoTerminator, 0}, + {OtherText_FreshWater, NULL}, + {OtherText_SodaPop, NULL}, + {OtherText_Lemonade, NULL}, + {gOtherText_CancelNoTerminator, NULL}, }; const struct MenuAction MultichoiceList_43[] = { - {(u8 *)OtherText_HowToRide, 0}, - {(u8 *)OtherText_HowToTurn, 0}, - {(u8 *)OtherText_SandySlopes, 0}, - {(u8 *)gOtherText_CancelNoTerminator, 0}, + {OtherText_HowToRide, NULL}, + {OtherText_HowToTurn, NULL}, + {OtherText_SandySlopes, NULL}, + {gOtherText_CancelNoTerminator, NULL}, }; const struct MenuAction MultichoiceList_44[] = { - {(u8 *)OtherText_Wheelies, 0}, - {(u8 *)OtherText_BunnyHops, 0}, - {(u8 *)OtherText_Jumping, 0}, - {(u8 *)gOtherText_CancelNoTerminator, 0}, + {OtherText_Wheelies, NULL}, + {OtherText_BunnyHops, NULL}, + {OtherText_Jumping, NULL}, + {gOtherText_CancelNoTerminator, NULL}, }; const struct MenuAction MultichoiceList_45[] = { - {(u8 *)OtherText_Satisfied, 0}, - {(u8 *)OtherText_Dissatisfied, 0}, + {OtherText_Satisfied, NULL}, + {OtherText_Dissatisfied, NULL}, }; const struct MenuAction MultichoiceList_46[] = { - {(u8 *)OtherText_Deepseatooth, 0}, - {(u8 *)OtherText_Deepseascale, 0}, - {(u8 *)gOtherText_CancelNoTerminator, 0}, + {OtherText_Deepseatooth, NULL}, + {OtherText_Deepseascale, NULL}, + {gOtherText_CancelNoTerminator, NULL}, }; const struct MenuAction MultichoiceList_47[] = { - {(u8 *)OtherText_BlueFlute2, 0}, - {(u8 *)OtherText_YellowFlute2, 0}, - {(u8 *)OtherText_RedFlute2, 0}, - {(u8 *)OtherText_WhiteFlute2, 0}, - {(u8 *)OtherText_BlackFlute2, 0}, - {(u8 *)OtherText_GlassChair, 0}, - {(u8 *)OtherText_GlassDesk, 0}, - {(u8 *)gOtherText_CancelNoTerminator, 0}, + {OtherText_BlueFlute2, NULL}, + {OtherText_YellowFlute2, NULL}, + {OtherText_RedFlute2, NULL}, + {OtherText_WhiteFlute2, NULL}, + {OtherText_BlackFlute2, NULL}, + {OtherText_GlassChair, NULL}, + {OtherText_GlassDesk, NULL}, + {gOtherText_CancelNoTerminator, NULL}, }; const struct MenuAction MultichoiceList_48[] = { - {(u8 *)OtherText_TreeckoDoll, 0}, - {(u8 *)OtherText_TorchicDoll, 0}, - {(u8 *)OtherText_MudkipDoll, 0}, - {(u8 *)gOtherText_CancelNoTerminator, 0}, + {OtherText_TreeckoDoll, NULL}, + {OtherText_TorchicDoll, NULL}, + {OtherText_MudkipDoll, NULL}, + {gOtherText_CancelNoTerminator, NULL}, }; const struct MenuAction MultichoiceList_55[] = { - {(u8 *)OtherText_TM32, 0}, - {(u8 *)OtherText_TM29, 0}, - {(u8 *)OtherText_TM35, 0}, - {(u8 *)OtherText_TM24, 0}, - {(u8 *)OtherText_TM13, 0}, - {(u8 *)gOtherText_CancelNoTerminator, 0}, + {OtherText_TM32, NULL}, + {OtherText_TM29, NULL}, + {OtherText_TM35, NULL}, + {OtherText_TM24, NULL}, + {OtherText_TM13, NULL}, + {gOtherText_CancelNoTerminator, NULL}, }; const struct MenuAction MultichoiceList_49[] = { - {(u8 *)OtherText_50Coins, 0}, - {(u8 *)OtherText_500Coins, 0}, - {(u8 *)gOtherText_CancelNoTerminator, 0}, + {OtherText_50Coins, NULL}, + {OtherText_500Coins, NULL}, + {gOtherText_CancelNoTerminator, NULL}, }; const struct MenuAction MultichoiceList_50[] = { - {(u8 *)OtherText_Excellent, 0}, - {(u8 *)OtherText_NotSoHot, 0}, + {OtherText_Excellent, NULL}, + {OtherText_NotSoHot, NULL}, }; const struct MenuAction MultichoiceList_52[] = { - {(u8 *)OtherText_Lilycove, 0}, - {(u8 *)OtherText_BattleTower, 0}, - {(u8 *)gOtherText_CancelNoTerminator, 0}, + {OtherText_Lilycove, NULL}, + {OtherText_BattleTower, NULL}, + {gOtherText_CancelNoTerminator, NULL}, }; const struct MenuAction MultichoiceList_53[] = { - {(u8 *)OtherText_Slateport, 0}, - {(u8 *)OtherText_Lilycove, 0}, - {(u8 *)gOtherText_CancelNoTerminator, 0}, + {OtherText_Slateport, NULL}, + {OtherText_Lilycove, NULL}, + {gOtherText_CancelNoTerminator, NULL}, }; const struct MenuAction MultichoiceList_54[] = { - {(u8 *)OtherText_Right, 0}, - {(u8 *)OtherText_Left, 0}, + {OtherText_Right, NULL}, + {OtherText_Left, NULL}, }; const struct MenuAction MultichoiceList_56[] = { - {(u8 *)OtherText_Slateport, 0}, - {(u8 *)OtherText_BattleTower, 0}, - {(u8 *)gOtherText_CancelNoTerminator, 0}, + {OtherText_Slateport, NULL}, + {OtherText_BattleTower, NULL}, + {gOtherText_CancelNoTerminator, NULL}, }; const struct MenuAction MultichoiceList_57[] = { - {(u8 *)OtherText_1F_2, 0}, - {(u8 *)OtherText_2F_2, 0}, - {(u8 *)OtherText_3F_2, 0}, - {(u8 *)OtherText_4F_2, 0}, - {(u8 *)OtherText_5F_2, 0}, + {OtherText_1F_2, NULL}, + {OtherText_2F_2, NULL}, + {OtherText_3F_2, NULL}, + {OtherText_4F_2, NULL}, + {OtherText_5F_2, NULL}, }; const struct MenuAction MultichoiceList_58[] = { - {(u8 *)OtherText_RedShard, 0}, - {(u8 *)gOtherText_CancelNoTerminator, 0}, + {OtherText_RedShard, NULL}, + {gOtherText_CancelNoTerminator, NULL}, }; const struct MenuAction MultichoiceList_59[] = { - {(u8 *)OtherText_YellowShard, 0}, - {(u8 *)gOtherText_CancelNoTerminator, 0}, + {OtherText_YellowShard, NULL}, + {gOtherText_CancelNoTerminator, NULL}, }; const struct MenuAction MultichoiceList_60[] = { - {(u8 *)OtherText_RedShard, 0}, - {(u8 *)OtherText_YellowShard, 0}, - {(u8 *)gOtherText_CancelNoTerminator, 0}, + {OtherText_RedShard, NULL}, + {OtherText_YellowShard, NULL}, + {gOtherText_CancelNoTerminator, NULL}, }; const struct MenuAction MultichoiceList_61[] = { - {(u8 *)OtherText_BlueShard, 0}, - {(u8 *)gOtherText_CancelNoTerminator, 0}, + {OtherText_BlueShard, NULL}, + {gOtherText_CancelNoTerminator, NULL}, }; const struct MenuAction MultichoiceList_62[] = { - {(u8 *)OtherText_RedShard, 0}, - {(u8 *)OtherText_BlueShard, 0}, - {(u8 *)gOtherText_CancelNoTerminator, 0}, + {OtherText_RedShard, NULL}, + {OtherText_BlueShard, NULL}, + {gOtherText_CancelNoTerminator, NULL}, }; const struct MenuAction MultichoiceList_63[] = { - {(u8 *)OtherText_YellowShard, 0}, - {(u8 *)OtherText_BlueShard, 0}, - {(u8 *)gOtherText_CancelNoTerminator, 0}, + {OtherText_YellowShard, NULL}, + {OtherText_BlueShard, NULL}, + {gOtherText_CancelNoTerminator, NULL}, }; const struct MenuAction MultichoiceList_64[] = { - {(u8 *)OtherText_RedShard, 0}, - {(u8 *)OtherText_YellowShard, 0}, - {(u8 *)OtherText_BlueShard, 0}, - {(u8 *)gOtherText_CancelNoTerminator, 0}, + {OtherText_RedShard, NULL}, + {OtherText_YellowShard, NULL}, + {OtherText_BlueShard, NULL}, + {gOtherText_CancelNoTerminator, NULL}, }; const struct MenuAction MultichoiceList_65[] = { - {(u8 *)OtherText_GreenShard, 0}, - {(u8 *)gOtherText_CancelNoTerminator, 0}, + {OtherText_GreenShard, NULL}, + {gOtherText_CancelNoTerminator, NULL}, }; const struct MenuAction MultichoiceList_66[] = { - {(u8 *)OtherText_RedShard, 0}, - {(u8 *)OtherText_GreenShard, 0}, - {(u8 *)gOtherText_CancelNoTerminator, 0}, + {OtherText_RedShard, NULL}, + {OtherText_GreenShard, NULL}, + {gOtherText_CancelNoTerminator, NULL}, }; const struct MenuAction MultichoiceList_67[] = { - {(u8 *)OtherText_YellowShard, 0}, - {(u8 *)OtherText_GreenShard, 0}, - {(u8 *)gOtherText_CancelNoTerminator, 0}, + {OtherText_YellowShard, NULL}, + {OtherText_GreenShard, NULL}, + {gOtherText_CancelNoTerminator, NULL}, }; const struct MenuAction MultichoiceList_68[] = { - {(u8 *)OtherText_RedShard, 0}, - {(u8 *)OtherText_YellowShard, 0}, - {(u8 *)OtherText_GreenShard, 0}, - {(u8 *)gOtherText_CancelNoTerminator, 0}, + {OtherText_RedShard, NULL}, + {OtherText_YellowShard, NULL}, + {OtherText_GreenShard, NULL}, + {gOtherText_CancelNoTerminator, NULL}, }; const struct MenuAction MultichoiceList_69[] = { - {(u8 *)OtherText_BlueShard, 0}, - {(u8 *)OtherText_GreenShard, 0}, - {(u8 *)gOtherText_CancelNoTerminator, 0}, + {OtherText_BlueShard, NULL}, + {OtherText_GreenShard, NULL}, + {gOtherText_CancelNoTerminator, NULL}, }; const struct MenuAction MultichoiceList_70[] = { - {(u8 *)OtherText_RedShard, 0}, - {(u8 *)OtherText_BlueShard, 0}, - {(u8 *)OtherText_GreenShard, 0}, - {(u8 *)gOtherText_CancelNoTerminator, 0}, + {OtherText_RedShard, NULL}, + {OtherText_BlueShard, NULL}, + {OtherText_GreenShard, NULL}, + {gOtherText_CancelNoTerminator, NULL}, }; const struct MenuAction MultichoiceList_71[] = { - {(u8 *)OtherText_YellowShard, 0}, - {(u8 *)OtherText_BlueShard, 0}, - {(u8 *)OtherText_GreenShard, 0}, - {(u8 *)gOtherText_CancelNoTerminator, 0}, + {OtherText_YellowShard, NULL}, + {OtherText_BlueShard, NULL}, + {OtherText_GreenShard, NULL}, + {gOtherText_CancelNoTerminator, NULL}, }; const struct MenuAction MultichoiceList_72[] = { - {(u8 *)OtherText_RedShard, 0}, - {(u8 *)OtherText_YellowShard, 0}, - {(u8 *)OtherText_BlueShard, 0}, - {(u8 *)OtherText_GreenShard, 0}, - {(u8 *)gOtherText_CancelNoTerminator, 0}, + {OtherText_RedShard, NULL}, + {OtherText_YellowShard, NULL}, + {OtherText_BlueShard, NULL}, + {OtherText_GreenShard, NULL}, + {gOtherText_CancelNoTerminator, NULL}, }; const struct MenuAction MultichoiceList_01[] = { - {(u8 *)gOtherText_CancelNoTerminator, 0}, + {gOtherText_CancelNoTerminator, NULL}, +}; + +struct MultichoiceListStruct +{ + const struct MenuAction *list; + u8 count; }; const struct MultichoiceListStruct gMultichoiceLists[] = { - {(struct MenuAction *)MultichoiceList_00, 3}, - {(struct MenuAction *)MultichoiceList_01, 1}, - {(struct MenuAction *)MultichoiceList_02, 3}, - {(struct MenuAction *)MultichoiceList_03, 4}, - {(struct MenuAction *)MultichoiceList_04, 6}, - {(struct MenuAction *)MultichoiceList_05, 3}, - {(struct MenuAction *)MultichoiceList_06, 4}, - {(struct MenuAction *)MultichoiceList_07, 4}, - {(struct MenuAction *)MultichoiceList_01, 1}, - {(struct MenuAction *)MultichoiceList_01, 1}, - {(struct MenuAction *)MultichoiceList_01, 1}, - {(struct MenuAction *)MultichoiceList_01, 1}, - {(struct MenuAction *)MultichoiceList_12, 2}, - {(struct MenuAction *)MultichoiceList_13, 6}, - {(struct MenuAction *)MultichoiceList_14, 2}, - {(struct MenuAction *)MultichoiceList_01, 1}, - {(struct MenuAction *)MultichoiceList_16, 2}, - {(struct MenuAction *)MultichoiceList_17, 3}, - {(struct MenuAction *)MultichoiceList_18, 4}, - {(struct MenuAction *)MultichoiceList_19, 3}, - {(struct MenuAction *)MultichoiceList_20, 3}, - {(struct MenuAction *)MultichoiceList_01, 1}, - {(struct MenuAction *)MultichoiceList_01, 1}, - {(struct MenuAction *)MultichoiceList_23, 3}, - {(struct MenuAction *)MultichoiceList_24, 3}, - {(struct MenuAction *)MultichoiceList_25, 3}, - {(struct MenuAction *)MultichoiceList_26, 3}, - {(struct MenuAction *)MultichoiceList_27, 3}, - {(struct MenuAction *)MultichoiceList_28, 3}, - {(struct MenuAction *)MultichoiceList_29, 3}, - {(struct MenuAction *)MultichoiceList_30, 3}, - {(struct MenuAction *)MultichoiceList_31, 3}, - {(struct MenuAction *)MultichoiceList_32, 3}, - {(struct MenuAction *)MultichoiceList_33, 3}, - {(struct MenuAction *)MultichoiceList_34, 3}, - {(struct MenuAction *)MultichoiceList_35, 3}, - {(struct MenuAction *)MultichoiceList_36, 3}, - {(struct MenuAction *)MultichoiceList_37, 3}, - {(struct MenuAction *)MultichoiceList_38, 3}, - {(struct MenuAction *)MultichoiceList_39, 3}, - {(struct MenuAction *)MultichoiceList_01, 1}, - {(struct MenuAction *)MultichoiceList_01, 1}, - {(struct MenuAction *)MultichoiceList_42, 4}, - {(struct MenuAction *)MultichoiceList_43, 4}, - {(struct MenuAction *)MultichoiceList_44, 4}, - {(struct MenuAction *)MultichoiceList_45, 2}, - {(struct MenuAction *)MultichoiceList_46, 3}, - {(struct MenuAction *)MultichoiceList_47, 8}, - {(struct MenuAction *)MultichoiceList_48, 4}, - {(struct MenuAction *)MultichoiceList_49, 3}, - {(struct MenuAction *)MultichoiceList_50, 2}, - {(struct MenuAction *)MultichoiceList_01, 1}, - {(struct MenuAction *)MultichoiceList_52, 3}, - {(struct MenuAction *)MultichoiceList_53, 3}, - {(struct MenuAction *)MultichoiceList_54, 2}, - {(struct MenuAction *)MultichoiceList_55, 6}, - {(struct MenuAction *)MultichoiceList_56, 3}, - {(struct MenuAction *)MultichoiceList_57, 5}, - {(struct MenuAction *)MultichoiceList_58, 2}, - {(struct MenuAction *)MultichoiceList_59, 2}, - {(struct MenuAction *)MultichoiceList_60, 3}, - {(struct MenuAction *)MultichoiceList_61, 2}, - {(struct MenuAction *)MultichoiceList_62, 3}, - {(struct MenuAction *)MultichoiceList_63, 3}, - {(struct MenuAction *)MultichoiceList_64, 4}, - {(struct MenuAction *)MultichoiceList_65, 2}, - {(struct MenuAction *)MultichoiceList_66, 3}, - {(struct MenuAction *)MultichoiceList_67, 3}, - {(struct MenuAction *)MultichoiceList_68, 4}, - {(struct MenuAction *)MultichoiceList_69, 3}, - {(struct MenuAction *)MultichoiceList_70, 4}, - {(struct MenuAction *)MultichoiceList_71, 4}, - {(struct MenuAction *)MultichoiceList_72, 5} + {MultichoiceList_00, ARRAY_COUNT(MultichoiceList_00)}, + {MultichoiceList_01, ARRAY_COUNT(MultichoiceList_01)}, + {MultichoiceList_02, ARRAY_COUNT(MultichoiceList_02)}, + {MultichoiceList_03, ARRAY_COUNT(MultichoiceList_03)}, + {MultichoiceList_04, ARRAY_COUNT(MultichoiceList_04)}, + {MultichoiceList_05, ARRAY_COUNT(MultichoiceList_05)}, + {MultichoiceList_06, ARRAY_COUNT(MultichoiceList_06)}, + {MultichoiceList_07, ARRAY_COUNT(MultichoiceList_07)}, + {MultichoiceList_01, ARRAY_COUNT(MultichoiceList_01)}, + {MultichoiceList_01, ARRAY_COUNT(MultichoiceList_01)}, + {MultichoiceList_01, ARRAY_COUNT(MultichoiceList_01)}, + {MultichoiceList_01, ARRAY_COUNT(MultichoiceList_01)}, + {MultichoiceList_12, ARRAY_COUNT(MultichoiceList_12)}, + {MultichoiceList_13, ARRAY_COUNT(MultichoiceList_13)}, + {MultichoiceList_14, ARRAY_COUNT(MultichoiceList_14)}, + {MultichoiceList_01, ARRAY_COUNT(MultichoiceList_01)}, + {MultichoiceList_16, ARRAY_COUNT(MultichoiceList_16)}, + {MultichoiceList_17, ARRAY_COUNT(MultichoiceList_17)}, + {MultichoiceList_18, ARRAY_COUNT(MultichoiceList_18)}, + {MultichoiceList_19, ARRAY_COUNT(MultichoiceList_19)}, + {MultichoiceList_20, ARRAY_COUNT(MultichoiceList_20)}, + {MultichoiceList_01, ARRAY_COUNT(MultichoiceList_01)}, + {MultichoiceList_01, ARRAY_COUNT(MultichoiceList_01)}, + {MultichoiceList_23, ARRAY_COUNT(MultichoiceList_23)}, + {MultichoiceList_24, ARRAY_COUNT(MultichoiceList_24)}, + {MultichoiceList_25, ARRAY_COUNT(MultichoiceList_25)}, + {MultichoiceList_26, ARRAY_COUNT(MultichoiceList_26)}, + {MultichoiceList_27, ARRAY_COUNT(MultichoiceList_27)}, + {MultichoiceList_28, ARRAY_COUNT(MultichoiceList_28)}, + {MultichoiceList_29, ARRAY_COUNT(MultichoiceList_29)}, + {MultichoiceList_30, ARRAY_COUNT(MultichoiceList_30)}, + {MultichoiceList_31, ARRAY_COUNT(MultichoiceList_31)}, + {MultichoiceList_32, ARRAY_COUNT(MultichoiceList_32)}, + {MultichoiceList_33, ARRAY_COUNT(MultichoiceList_33)}, + {MultichoiceList_34, ARRAY_COUNT(MultichoiceList_34)}, + {MultichoiceList_35, ARRAY_COUNT(MultichoiceList_35)}, + {MultichoiceList_36, ARRAY_COUNT(MultichoiceList_36)}, + {MultichoiceList_37, ARRAY_COUNT(MultichoiceList_37)}, + {MultichoiceList_38, ARRAY_COUNT(MultichoiceList_38)}, + {MultichoiceList_39, ARRAY_COUNT(MultichoiceList_39)}, + {MultichoiceList_01, ARRAY_COUNT(MultichoiceList_01)}, + {MultichoiceList_01, ARRAY_COUNT(MultichoiceList_01)}, + {MultichoiceList_42, ARRAY_COUNT(MultichoiceList_42)}, + {MultichoiceList_43, ARRAY_COUNT(MultichoiceList_43)}, + {MultichoiceList_44, ARRAY_COUNT(MultichoiceList_44)}, + {MultichoiceList_45, ARRAY_COUNT(MultichoiceList_45)}, + {MultichoiceList_46, ARRAY_COUNT(MultichoiceList_46)}, + {MultichoiceList_47, ARRAY_COUNT(MultichoiceList_47)}, + {MultichoiceList_48, ARRAY_COUNT(MultichoiceList_48)}, + {MultichoiceList_49, ARRAY_COUNT(MultichoiceList_49)}, + {MultichoiceList_50, ARRAY_COUNT(MultichoiceList_50)}, + {MultichoiceList_01, ARRAY_COUNT(MultichoiceList_01)}, + {MultichoiceList_52, ARRAY_COUNT(MultichoiceList_52)}, + {MultichoiceList_53, ARRAY_COUNT(MultichoiceList_53)}, + {MultichoiceList_54, ARRAY_COUNT(MultichoiceList_54)}, + {MultichoiceList_55, ARRAY_COUNT(MultichoiceList_55)}, + {MultichoiceList_56, ARRAY_COUNT(MultichoiceList_56)}, + {MultichoiceList_57, ARRAY_COUNT(MultichoiceList_57)}, + {MultichoiceList_58, ARRAY_COUNT(MultichoiceList_58)}, + {MultichoiceList_59, ARRAY_COUNT(MultichoiceList_59)}, + {MultichoiceList_60, ARRAY_COUNT(MultichoiceList_60)}, + {MultichoiceList_61, ARRAY_COUNT(MultichoiceList_61)}, + {MultichoiceList_62, ARRAY_COUNT(MultichoiceList_62)}, + {MultichoiceList_63, ARRAY_COUNT(MultichoiceList_63)}, + {MultichoiceList_64, ARRAY_COUNT(MultichoiceList_64)}, + {MultichoiceList_65, ARRAY_COUNT(MultichoiceList_65)}, + {MultichoiceList_66, ARRAY_COUNT(MultichoiceList_66)}, + {MultichoiceList_67, ARRAY_COUNT(MultichoiceList_67)}, + {MultichoiceList_68, ARRAY_COUNT(MultichoiceList_68)}, + {MultichoiceList_69, ARRAY_COUNT(MultichoiceList_69)}, + {MultichoiceList_70, ARRAY_COUNT(MultichoiceList_70)}, + {MultichoiceList_71, ARRAY_COUNT(MultichoiceList_71)}, + {MultichoiceList_72, ARRAY_COUNT(MultichoiceList_72)}, }; const u8 *const gUnknown_083CE048[] = @@ -574,37 +582,50 @@ extern u8 gPCText_WhichPCShouldBeAccessed[]; extern u16 gScriptResult; -bool8 sub_80B5054(u8 left, u8 top, u8 var3, u8 var4) +static void Task_HandleMultichoiceInput(u8); +static void Task_HandleYesNoInput(u8); +static void Task_HandleMultichoiceGridInput(u8); +static u16 GetStringWidthInTilesForScriptMenu(const u8 *str); +static void DrawMultichoiceMenu(u8, u8, u8, const struct MenuAction *list, u8, u8); +static void StartScriptMenuTask(u8, u8, u8, u8, u8, u8); +static void sub_80B53B4(u8, u8, u8, const struct MenuAction *list, u8); +static bool8 IsPicboxClosed(void); + +bool8 ScriptMenu_Multichoice(u8 left, u8 top, u8 multichoiceId, u8 ignoreBPress) { - if (FuncIsActiveTask(sub_80B52B4) == 1) + if (FuncIsActiveTask(Task_HandleMultichoiceInput) == TRUE) + { return FALSE; + } else { gScriptResult = 0xFF; - DrawMultichoiceMenu(left, top, gMultichoiceLists[var3].count, gMultichoiceLists[var3].list, var4, 0); + DrawMultichoiceMenu(left, top, gMultichoiceLists[multichoiceId].count, gMultichoiceLists[multichoiceId].list, ignoreBPress, 0); return TRUE; } } -bool8 sub_80B50B0(u8 left, u8 top, u8 var3, u8 var4, u8 var5) +bool8 ScriptMenu_MultichoiceWithDefault(u8 left, u8 top, u8 multichoiceId, u8 ignoreBPress, u8 defaultChoice) { - if (FuncIsActiveTask(sub_80B52B4) == 1) + if (FuncIsActiveTask(Task_HandleMultichoiceInput) == TRUE) + { return FALSE; + } else { gScriptResult = 0xFF; - DrawMultichoiceMenu(left, top, gMultichoiceLists[var3].count, gMultichoiceLists[var3].list, var4, var5); + DrawMultichoiceMenu(left, top, gMultichoiceLists[multichoiceId].count, gMultichoiceLists[multichoiceId].list, ignoreBPress, defaultChoice); return TRUE; } } -u16 GetStringWidthInTilesForScriptMenu(const u8 *str) +static u16 GetStringWidthInTilesForScriptMenu(const u8 *str) { // each tile on screen is 8x8, so it needs the number of tiles and not pixels, hence the division by 8. return (GetStringWidthGivenWindowConfig((struct WindowConfig *)&gWindowConfig_81E6CE4, str) + 7) / 8; } -void DrawMultichoiceMenu(u8 left, u8 top, u8 count, struct MenuAction *list, u8 var4, u8 cursorPos) +static void DrawMultichoiceMenu(u8 left, u8 top, u8 count, const struct MenuAction *list, u8 ignoreBPress, u8 cursorPos) { u16 width = GetStringWidthInTilesForScriptMenu(list[0].text); u16 newWidth; @@ -633,75 +654,79 @@ void DrawMultichoiceMenu(u8 left, u8 top, u8 count, struct MenuAction *list, u8 MenuDrawTextWindow(left, top, right, bottom); PrintMenuItems(left + 1, top + 1, count, list); InitMenu(0, left + 1, top + 1, count, cursorPos, right - left - 1); - sub_80B5230(left, top, right, bottom, var4, count); + StartScriptMenuTask(left, top, right, bottom, ignoreBPress, count); } -void sub_80B5230(u8 left, u8 top, u8 right, u8 bottom, u8 unkVar, u8 count) +#define tLeft data[0] +#define tTop data[1] +#define tRight data[2] +#define tBottom data[3] +#define tIgnoreBPress data[4] +#define tDoWrap data[5] + +static void StartScriptMenuTask(u8 left, u8 top, u8 right, u8 bottom, u8 ignoreBPress, u8 count) { - u8 taskId = CreateTask(sub_80B52B4, 80); + u8 taskId = CreateTask(Task_HandleMultichoiceInput, 80); - gTasks[taskId].data[0] = left; - gTasks[taskId].data[1] = top; - gTasks[taskId].data[2] = right; - gTasks[taskId].data[3] = bottom; - gTasks[taskId].data[4] = unkVar; + gTasks[taskId].tLeft = left; + gTasks[taskId].tTop = top; + gTasks[taskId].tRight = right; + gTasks[taskId].tBottom = bottom; + gTasks[taskId].tIgnoreBPress = ignoreBPress; if (count > 3) - gTasks[taskId].data[5] = TRUE; + gTasks[taskId].tDoWrap = TRUE; else - gTasks[taskId].data[5] = FALSE; + gTasks[taskId].tDoWrap = FALSE; } -void sub_80B52B4(u8 taskId) +static void Task_HandleMultichoiceInput(u8 taskId) { - s8 var; + s8 selection; if (!gPaletteFade.active) { - if (!gTasks[taskId].data[5]) - var = ProcessMenuInputNoWrap(); + if (!gTasks[taskId].tDoWrap) + selection = ProcessMenuInputNoWrap(); else - var = ProcessMenuInput(); + selection = ProcessMenuInput(); - if (var != -2) + if (selection != -2) { - if (var == -1) + if (selection == -1) { - if (!gTasks[taskId].data[4]) - { - PlaySE(5); - gScriptResult = 127; - } - else - { + if (gTasks[taskId].tIgnoreBPress) return; - } + PlaySE(SE_SELECT); + gScriptResult = 127; } else { - gScriptResult = var; + gScriptResult = selection; } HandleDestroyMenuCursors(); - MenuZeroFillWindowRect(gTasks[taskId].data[0], gTasks[taskId].data[1], gTasks[taskId].data[2], gTasks[taskId].data[3]); + MenuZeroFillWindowRect(gTasks[taskId].tLeft, gTasks[taskId].tTop, gTasks[taskId].tRight, gTasks[taskId].tBottom); DestroyTask(taskId); EnableBothScriptContexts(); } } } -bool8 Multichoice(u8 var1, u8 var2, u8 var3, u8 var4) +bool8 Multichoice(u8 left, u8 top, u8 multichoiceId, u8 ignoreBPress) { - if (FuncIsActiveTask(sub_80B52B4) == 1) + if (FuncIsActiveTask(Task_HandleMultichoiceInput) == TRUE) + { return FALSE; + } else { gScriptResult = 0xFF; - sub_80B53B4(var1, var2, gMultichoiceLists[var3].count, gMultichoiceLists[var3].list, var4); + sub_80B53B4(left, top, gMultichoiceLists[multichoiceId].count, gMultichoiceLists[multichoiceId].list, ignoreBPress); return TRUE; } } -void sub_80B53B4(u8 left, u8 top, u8 count, struct MenuAction *list, u8 var4) +static void sub_80B53B4(u8 left, u8 top, u8 count, const struct MenuAction *list, u8 ignoreBPress) { u16 width = GetStringWidthInTilesForScriptMenu(list[0].text); u16 newWidth; @@ -722,22 +747,24 @@ void sub_80B53B4(u8 left, u8 top, u8 count, struct MenuAction *list, u8 var4) PrintMenuItems(left, top, count, list); InitMenu(0, left, top, count, 0, right - left - 1); - sub_80B5230(left, top, right, bottom, var4, count); + StartScriptMenuTask(left, top, right, bottom, ignoreBPress, count); } -bool8 yes_no_box(u8 var1, u8 var2) +bool8 ScriptMenu_YesNo(u8 left, u8 top) { u8 taskId; - if (FuncIsActiveTask(task_yes_no_maybe) == 1) + if (FuncIsActiveTask(Task_HandleYesNoInput) == TRUE) + { return FALSE; + } else { gScriptResult = 0xFF; - DisplayYesNoMenu(var1, var2, 1); - taskId = CreateTask(task_yes_no_maybe, 0x50); - gTasks[taskId].data[0] = var1; - gTasks[taskId].data[1] = var2; + DisplayYesNoMenu(left, top, 1); + taskId = CreateTask(Task_HandleYesNoInput, 0x50); + gTasks[taskId].tLeft = left; + gTasks[taskId].tTop = top; return TRUE; } } @@ -751,13 +778,13 @@ bool8 IsScriptActive(void) return TRUE; } -void task_yes_no_maybe(u8 taskId) +static void Task_HandleYesNoInput(u8 taskId) { u8 left, top; - if (gTasks[taskId].data[2] < 5) + if (gTasks[taskId].tRight < 5) { - gTasks[taskId].data[2]++; + gTasks[taskId].tRight++; return; } @@ -767,7 +794,7 @@ void task_yes_no_maybe(u8 taskId) return; case -1: case 1: - PlaySE(5); + PlaySE(SE_SELECT); gScriptResult = 0; break; case 0: @@ -775,19 +802,19 @@ void task_yes_no_maybe(u8 taskId) break; } - left = gTasks[taskId].data[0]; - top = gTasks[taskId].data[1]; + left = gTasks[taskId].tLeft; + top = gTasks[taskId].tTop; MenuZeroFillWindowRect(left, top, left + 6, top + 5); DestroyTask(taskId); EnableBothScriptContexts(); } -bool8 sub_80B5578(u8 left, u8 top, u8 multichoiceId, u8 a4, u8 columnCount) +bool8 ScriptMenu_MultichoiceGrid(u8 left, u8 top, u8 multichoiceId, u8 ignoreBPress, u8 columnCount) { u8 bottom = 0; - if (FuncIsActiveTask(sub_80B5684) == TRUE) + if (FuncIsActiveTask(Task_HandleMultichoiceGridInput) == TRUE) { return FALSE; } @@ -800,7 +827,7 @@ bool8 sub_80B5578(u8 left, u8 top, u8 multichoiceId, u8 a4, u8 columnCount) sub_807274C(left, top, gMultichoiceLists[multichoiceId].count, 0, gMultichoiceLists[multichoiceId].list, columnCount, 0); - taskId = CreateTask(sub_80B5684, 80); + taskId = CreateTask(Task_HandleMultichoiceGridInput, 80); if (!((gMultichoiceLists[multichoiceId].count >> 1) < columnCount || (gMultichoiceLists[multichoiceId].count & 1)) || columnCount == 1 || gMultichoiceLists[multichoiceId].count == columnCount) @@ -813,58 +840,62 @@ bool8 sub_80B5578(u8 left, u8 top, u8 multichoiceId, u8 a4, u8 columnCount) } width = sub_807288C(columnCount); - gTasks[taskId].data[0] = left; - gTasks[taskId].data[1] = top; - gTasks[taskId].data[2] = width + left + 2; - gTasks[taskId].data[3] = bottom; - gTasks[taskId].data[4] = a4; + gTasks[taskId].tLeft = left; + gTasks[taskId].tTop = top; + gTasks[taskId].tRight = width + left + 2; + gTasks[taskId].tBottom = bottom; + gTasks[taskId].tIgnoreBPress = ignoreBPress; return TRUE; } } -void sub_80B5684(u8 taskId) +static void Task_HandleMultichoiceGridInput(u8 taskId) { - s8 var = sub_80727CC(); + s8 selection = sub_80727CC(); - if (var != -2) + if (selection != -2) { - if (var == -1) + if (selection == -1) { - if (!gTasks[taskId].data[4]) - { - PlaySE(5); - gScriptResult = 127; - } - else - { + if (gTasks[taskId].tIgnoreBPress) return; - } + PlaySE(SE_SELECT); + gScriptResult = 127; } else { - gScriptResult = var; + gScriptResult = selection; } HandleDestroyMenuCursors(); - MenuZeroFillWindowRect(gTasks[taskId].data[0], gTasks[taskId].data[1], gTasks[taskId].data[2], gTasks[taskId].data[3]); + MenuZeroFillWindowRect(gTasks[taskId].tLeft, gTasks[taskId].tTop, gTasks[taskId].tRight, gTasks[taskId].tBottom); DestroyTask(taskId); EnableBothScriptContexts(); } } -bool8 TryCreatePCMenu(void) +#undef tLeft +#undef tTop +#undef tRight +#undef tBottom +#undef tIgnoreBPress +#undef tDoWrap + +bool8 ScrSpecial_CreatePCMenu(void) { - if (FuncIsActiveTask(sub_80B52B4) == 1) + if (FuncIsActiveTask(Task_HandleMultichoiceInput) == TRUE) + { return FALSE; + } else { gScriptResult = 0xFF; - CreatePCMenu(); + ScriptMenu_CreatePCMenu(); return TRUE; } } #if ENGLISH -void CreatePCMenu(void) +void ScriptMenu_CreatePCMenu(void) { u16 playersPCWidth = GetStringWidthInTilesForScriptMenu(gPCText_PlayersPC); u8 width; @@ -896,11 +927,11 @@ void CreatePCMenu(void) MenuPrint(gPCText_PlayersPC, 1, 3); InitMenu(0, 1, 1, numChoices, 0, width + 1); - sub_80B5230(0, 0, width + 2, 2 * numChoices + 1, 0, numChoices); + StartScriptMenuTask(0, 0, width + 2, 2 * numChoices + 1, 0, numChoices); } #elif GERMAN __attribute__((naked)) -void CreatePCMenu(void) { +void ScriptMenu_CreatePCMenu(void) { asm(".syntax unified\n\ push {r4-r7,lr}\n\ sub sp, 0x18\n\ @@ -1051,7 +1082,7 @@ _080B584A:\n\ str r7, [sp, 0x4]\n\ movs r0, 0\n\ movs r1, 0\n\ - bl sub_80B5230\n\ + bl StartScriptMenuTask\n\ add sp, 0x18\n\ pop {r4-r7}\n\ pop {r0}\n\ @@ -1063,72 +1094,85 @@ _080B588C: .4byte gPCText_PlayersPC\n\ } #endif -void sub_80B5838(void) +void ScriptMenu_DisplayPCStartupPrompt(void) { MenuDisplayMessageBox(); MenuPrint(gPCText_WhichPCShouldBeAccessed, 2, 15); } -void task_picbox(u8 taskId) +#define tState data[0] +#define tMonSpecies data[1] +#define tMonSpriteId data[2] +#define tWindowX data[3] +#define tWindowY data[4] + +static void Task_PokemonPicWindow(u8 taskId) { struct Task *task = &gTasks[taskId]; - switch (task->data[0]) + switch (task->tState) { case 0: - task->data[0]++; + task->tState++; break; case 1: break; case 2: - FreeResourcesAndDestroySprite(&gSprites[task->data[2]]); - task->data[0]++; + FreeResourcesAndDestroySprite(&gSprites[task->tMonSpriteId]); + task->tState++; break; case 3: - MenuZeroFillWindowRect(task->data[3], task->data[4], task->data[3] + 9, task->data[4] + 10); + MenuZeroFillWindowRect(task->tWindowX, task->tWindowY, task->tWindowX + 9, task->tWindowY + 10); DestroyTask(taskId); break; } } -bool8 sub_80B58C4(u16 var1, u8 var2, u8 var3) +bool8 ScriptMenu_ShowPokemonPic(u16 species, u8 x, u8 y) { u8 taskId; - u8 var; + u8 spriteId; - if (FindTaskIdByFunc(task_picbox) != 0xFF) + if (FindTaskIdByFunc(Task_PokemonPicWindow) != 0xFF) + { return FALSE; + } else { - MenuDrawTextWindow(var2, var3, var2 + 9, var3 + 10); - taskId = CreateTask(task_picbox, 0x50); - gTasks[taskId].data[0] = 0; - gTasks[taskId].data[1] = var1; - var = CreateMonSprite_PicBox(var1, var2 * 8 + 40, var3 * 8 + 40, 0); - gTasks[taskId].data[2] = var; - gTasks[taskId].data[3] = var2; - gTasks[taskId].data[4] = var3; - gSprites[var].callback = SpriteCallbackDummy; - gSprites[var].oam.priority = 0; + MenuDrawTextWindow(x, y, x + 9, y + 10); + taskId = CreateTask(Task_PokemonPicWindow, 0x50); + gTasks[taskId].tState = 0; + gTasks[taskId].tMonSpecies = species; + spriteId = CreateMonSprite_PicBox(species, x * 8 + 40, y * 8 + 40, 0); + gTasks[taskId].tMonSpriteId = spriteId; + gTasks[taskId].tWindowX = x; + gTasks[taskId].tWindowY = y; + gSprites[spriteId].callback = SpriteCallbackDummy; + gSprites[spriteId].oam.priority = 0; return TRUE; } -} +} -void *picbox_close(void) +bool8 (*ScriptMenu_GetPicboxWaitFunc(void))(void) { - u8 taskId = FindTaskIdByFunc(task_picbox); + u8 taskId = FindTaskIdByFunc(Task_PokemonPicWindow); if (taskId == 0xFF) return NULL; - - gTasks[taskId].data[0]++; - return (void *)sub_80B59AC; + gTasks[taskId].tState++; + return IsPicboxClosed; } -bool8 sub_80B59AC(void) +static bool8 IsPicboxClosed(void) { - if (FindTaskIdByFunc(task_picbox) == 0xFF) + if (FindTaskIdByFunc(Task_PokemonPicWindow) == 0xFF) return TRUE; else return FALSE; } + +#undef tState +#undef tMonSpecies +#undef tMonSpriteId +#undef tWindowX +#undef tWindowY diff --git a/src/field/script_movement.c b/src/field/script_movement.c index e25b60a3c..30e10b451 100644 --- a/src/field/script_movement.c +++ b/src/field/script_movement.c @@ -13,33 +13,33 @@ static bool8 sub_80A21F4(u8, u8, u8 *); static u8 sub_80A2260(u8, u8); static bool8 sub_80A2370(u8, u8); static void sub_80A23C8(u8, u8, u8, u8 *); -static void sub_80A2408(u8); +static void UnfreezeObjects(u8); static void Task_80A244C(u8); static void sub_80A2490(u8, u8, u8, u8 *); -bool8 exec_movement(u8 a, u8 b, u8 c, u8 *d) +bool8 ScriptMovement_StartObjectMovementScript(u8 localId, u8 mapNum, u8 mapGroup, u8 *movementScript) { u8 mapObjId; - if (TryGetFieldObjectIdByLocalIdAndMap(a, b, c, &mapObjId)) + if (TryGetFieldObjectIdByLocalIdAndMap(localId, mapNum, mapGroup, &mapObjId)) return TRUE; if (!FuncIsActiveTask(Task_80A244C)) sub_80A2198(50); - return sub_80A21F4(sub_80A21E0(), mapObjId, d); + return sub_80A21F4(sub_80A21E0(), mapObjId, movementScript); } -bool8 sub_80A212C(u8 a, u8 b, u8 c) +bool8 ScriptMovement_IsObjectMovementFinished(u8 localId, u8 mapNum, u8 mapBank) { u8 mapObjId; u8 r4; u8 r1; - if (TryGetFieldObjectIdByLocalIdAndMap(a, b, c, &mapObjId)) - return 1; + if (TryGetFieldObjectIdByLocalIdAndMap(localId, mapNum, mapBank, &mapObjId)) + return TRUE; r4 = sub_80A21E0(); r1 = sub_80A2260(r4, mapObjId); if (r1 == 16) - return 1; + return TRUE; return sub_80A2370(r4, r1); } @@ -50,7 +50,7 @@ void sub_80A2178(void) taskId = sub_80A21E0(); if (taskId != 0xFF) { - sub_80A2408(taskId); + UnfreezeObjects(taskId); DestroyTask(taskId); } } @@ -70,27 +70,31 @@ static u8 sub_80A21E0(void) return FindTaskIdByFunc(Task_80A244C); } -static bool8 sub_80A21F4(u8 taskId, u8 b, u8 *c) +static bool8 sub_80A21F4(u8 taskId, u8 mapObjId, u8 *movementScript) { u8 r4; - r4 = sub_80A2260(taskId, b); + r4 = sub_80A2260(taskId, mapObjId); if (r4 != 16) { if (sub_80A2370(taskId, r4) == 0) + { return TRUE; + } else { - sub_80A23C8(taskId, r4, b, c); + sub_80A23C8(taskId, r4, mapObjId, movementScript); return FALSE; } } r4 = sub_80A2260(taskId, 0xFF); if (r4 == 16) + { return TRUE; + } else { - sub_80A23C8(taskId, r4, b, c); + sub_80A23C8(taskId, r4, mapObjId, movementScript); return FALSE; } } @@ -156,9 +160,9 @@ static bool8 sub_80A2370(u8 taskId, u8 b) return FALSE; } -static void npc_obj_offscreen_culling_and_flag_update(u8 a, u8 *b) +static void npc_obj_offscreen_culling_and_flag_update(u8 a, u8 *movementScript) { - gUnknown_020384F8[a] = b; + gUnknown_020384F8[a] = movementScript; } static u8 *sub_80A23B8(u8 a) @@ -166,23 +170,23 @@ static u8 *sub_80A23B8(u8 a) return gUnknown_020384F8[a]; } -static void sub_80A23C8(u8 taskId, u8 b, u8 c, u8 *d) +static void sub_80A23C8(u8 taskId, u8 b, u8 mapObjId, u8 *movementScript) { sub_80A2318(taskId, b); - npc_obj_offscreen_culling_and_flag_update(b, d); - sub_80A22D0(taskId, b, c); + npc_obj_offscreen_culling_and_flag_update(b, movementScript); + sub_80A22D0(taskId, b, mapObjId); } -static void sub_80A2408(u8 a) +static void UnfreezeObjects(u8 taskId) { - u8 *ptr; + u8 *pMapObjId; u8 i; - ptr = (u8 *)&gTasks[a].data[1]; - for (i = 0; i < 16; i++, ptr++) + pMapObjId = (u8 *)&gTasks[taskId].data[1]; + for (i = 0; i < 16; i++, pMapObjId++) { - if (*ptr != 0xFF) - UnfreezeMapObject(&gMapObjects[*ptr]); + if (*pMapObjId != 0xFF) + UnfreezeMapObject(&gMapObjects[*pMapObjId]); } } @@ -199,23 +203,23 @@ static void Task_80A244C(u8 taskId) } } -static void sub_80A2490(u8 taskId, u8 b, u8 c, u8 *d) +static void sub_80A2490(u8 taskId, u8 b, u8 mapObjId, u8 *d) { u8 var; - if (FieldObjectIsSpecialAnimActive(&gMapObjects[c]) - && !FieldObjectClearAnimIfSpecialAnimFinished(&gMapObjects[c])) + if (FieldObjectIsSpecialAnimActive(&gMapObjects[mapObjId]) + && !FieldObjectClearAnimIfSpecialAnimFinished(&gMapObjects[mapObjId])) return; var = *d; if (var == 0xFE) { sub_80A2348(taskId, b); - FreezeMapObject(&gMapObjects[c]); + FreezeMapObject(&gMapObjects[mapObjId]); } else { - if (!FieldObjectSetSpecialAnim(&gMapObjects[c], var)) + if (!FieldObjectSetSpecialAnim(&gMapObjects[mapObjId], var)) { d++; npc_obj_offscreen_culling_and_flag_update(b, d); diff --git a/src/field/secret_base.c b/src/field/secret_base.c index 4e8331f5c..b2cd1f094 100644 --- a/src/field/secret_base.c +++ b/src/field/secret_base.c @@ -14,7 +14,7 @@ #include "metatile_behavior.h" #include "palette.h" #include "pokemon.h" -#include "rom4.h" +#include "overworld.h" #include "script.h" #include "string_util.h" #include "strings.h" @@ -270,7 +270,7 @@ void sub_80BBAF0(void) bool8 sub_80BBB24(void) { - if (gMapHeader.mapType == 9 && VarGet(VAR_0x4097) == 0) + if (gMapHeader.mapType == MAP_TYPE_SECRET_BASE && VarGet(VAR_0x4097) == 0) return FALSE; return TRUE; } @@ -380,7 +380,7 @@ void sub_80BBDD0(void) gScriptResult = gMapHeader.events->mapObjects[objid].graphicsId + 0x3f20; VarSet(gScriptResult, gDecorations[roomdecor[decidx]].tiles[0]); gScriptResult = gMapHeader.events->mapObjects[objid].localId; - FlagReset(gSpecialVar_0x8004 + 0xAE); + FlagClear(gSpecialVar_0x8004 + 0xAE); show_sprite(gScriptResult, gSaveBlock1.location.mapNum, gSaveBlock1.location.mapGroup); sub_805C0F8(gScriptResult, gSaveBlock1.location.mapNum, gSaveBlock1.location.mapGroup, gSpecialVar_0x8006, gSpecialVar_0x8007); sub_805C78C(gScriptResult, gSaveBlock1.location.mapNum, gSaveBlock1.location.mapGroup); @@ -690,7 +690,7 @@ _080BBEDA:\n\ adds r0, 0xAE\n\ lsls r0, 16\n\ lsrs r0, 16\n\ - bl FlagReset\n\ + bl FlagClear\n\ ldr r3, _080BBF9C @ =gScriptResult\n\ ldrb r0, [r3]\n\ mov r4, r10\n\ diff --git a/src/field/shop.c b/src/field/shop.c index 6a88f1394..22250b1c4 100644 --- a/src/field/shop.c +++ b/src/field/shop.c @@ -23,7 +23,7 @@ #include "decoration.h" #include "items.h" #include "songs.h" -#include "rom4.h" +#include "overworld.h" #include "decoration_inventory.h" #include "field_camera.h" @@ -60,7 +60,7 @@ EWRAM_DATA u8 gUnknown_02038730 = 0; EWRAM_DATA u8 gUnknown_02038731 = 0; // rodata -static const struct MenuAction2 gUnknown_083CC6D0[] = +static const struct MenuAction2 sBuySellQuitMenuActions[] = { { MartText_Buy, sub_80B2EFC }, { MartText_Sell, sub_80B2F30 }, @@ -88,13 +88,13 @@ u8 CreateShopMenu(u8 martType) { gMartInfo.numChoices = 2; MenuDrawTextWindow(0, 0, 10, 7); - PrintMenuItemsReordered(1, 1, 3, (struct MenuAction *)gUnknown_083CC6D0, (u8 *)gUnknown_083CC6E8); + PrintMenuItemsReordered(1, 1, 3, sBuySellQuitMenuActions, gUnknown_083CC6E8); } else { gMartInfo.numChoices = 1; MenuDrawTextWindow(0, 0, 10, 5); - PrintMenuItemsReordered(1, 1, 2, (struct MenuAction *)gUnknown_083CC6D0, (u8 *)gUnknown_083CC6EB); + PrintMenuItemsReordered(1, 1, 2, sBuySellQuitMenuActions, gUnknown_083CC6EB); } InitMenu(0, 1, 1, gMartInfo.numChoices + 1, 0, 9); // add 1 for cancel @@ -145,11 +145,11 @@ void sub_80B2E38(u8 var) PlaySE(SE_SELECT); if (gMartInfo.martType == MART_TYPE_0) { - gUnknown_083CC6D0[gUnknown_083CC6E8[gMartInfo.cursor]].func(local); + sBuySellQuitMenuActions[gUnknown_083CC6E8[gMartInfo.cursor]].func(local); } else { - gUnknown_083CC6D0[gUnknown_083CC6EB[gMartInfo.cursor]].func(local); + sBuySellQuitMenuActions[gUnknown_083CC6EB[gMartInfo.cursor]].func(local); } } else if (gMain.newKeys & B_BUTTON) @@ -294,7 +294,7 @@ void BuyMenuDrawGraphics(void) gMartInfo.cursor = zero; gMartInfo.choicesAbove = zero2; MenuZeroFillWindowRect(0, 0, 0x20, 0x20); - sub_80B7C14(gSaveBlock1.money, 0, 0); + OpenMoneyWindow(gSaveBlock1.money, 0, 0); sub_80B3764(0, 7); sub_80B37EC(); sub_80B3270(); @@ -530,7 +530,7 @@ void sub_80B37F8(u8 taskId) u16 itemId = gMartInfo.itemList[itemListIndex]; u32 price = (ItemId_GetPrice(itemId) >> GetPriceReduction(1)); - sub_80B7A94(gTasks[taskId].data[1] * price, 6, 6, 11); + PrintMoneyAmount(gTasks[taskId].data[1] * price, 6, 6, 11); gStringVar1[0] = EXT_CTRL_CODE_BEGIN; gStringVar1[1] = 0x14; gStringVar1[2] = 0x6; @@ -559,7 +559,7 @@ void sub_80B389C(u16 itemId, u8 var2, bool32 hasControlCode) if (hasControlCode != FALSE) stringPtr = &gStringVar1[3]; - sub_80B79F8(stringPtr, (ItemId_GetPrice(itemId) >> GetPriceReduction(1)), 0x4); + GetMoneyAmountText(stringPtr, (ItemId_GetPrice(itemId) >> GetPriceReduction(1)), 0x4); MenuPrint_PixelCoords(&gStringVar1[0], 0xCA, var2 << 3, 1); } @@ -588,7 +588,7 @@ void sub_80B3930(u16 itemId, u8 var2, bool32 hasControlCode) } else { - sub_80B79F8(stringPtr, gDecorations[itemId].price, 0x4); + GetMoneyAmountText(stringPtr, gDecorations[itemId].price, 0x4); MenuPrint_PixelCoords(&gStringVar1[0], 0xCA, var2 << 3, 0x1); } } @@ -648,9 +648,9 @@ void sub_80B3AEC(u8 taskId) void sub_80B3B80(u8 taskId) { IncrementGameStat(0x26); - sub_80B79E0(&gSaveBlock1.money, gMartTotalCost); + RemoveMoney(&gSaveBlock1.money, gMartTotalCost); PlaySE(SE_REGI); - sub_80B7BEC(gSaveBlock1.money, 0, 0); + UpdateMoneyWindow(gSaveBlock1.money, 0, 0); gTasks[taskId].func = sub_80B3AEC; } @@ -1165,7 +1165,7 @@ void Task_ExitBuyMenu(u8 taskId) { if (!gPaletteFade.active) { - RemoveMoneyLabelObject(0, 0); + CloseMoneyWindow(0, 0); BuyMenuFreeMemory(); SetMainCallback2(c2_exit_to_overworld_2_switch); DestroyTask(taskId); diff --git a/src/field/start_menu.c b/src/field/start_menu.c index 411690aff..6e44090df 100644 --- a/src/field/start_menu.c +++ b/src/field/start_menu.c @@ -15,7 +15,7 @@ #include "pokedex.h" #include "pokemon_menu.h" #include "pokenav.h" -#include "rom4.h" +#include "overworld.h" #include "safari_zone.h" #include "save.h" #include "save_menu_util.h" @@ -505,7 +505,7 @@ static u8 RunSaveDialogCallback(void) return saveDialogCallback(); } -void InitSaveDialog(void) +void ScrSpecial_DoSaveDialog(void) { sub_807160C(); CreateTask(Task_SaveDialog, 0x50); @@ -515,7 +515,7 @@ static void DisplaySaveMessageWithCallback(const u8 *ptr, u8 (*func)(void)) { StringExpandPlaceholders(gStringVar4, ptr); MenuDisplayMessageBox(); - sub_8072044(gStringVar4); + MenuPrintMessageDefaultCoords(gStringVar4); savingComplete = TRUE; saveDialogCallback = func; } diff --git a/src/field/trainer_see.c b/src/field/trainer_see.c index feb35c67c..5a8ebbafc 100644 --- a/src/field/trainer_see.c +++ b/src/field/trainer_see.c @@ -9,113 +9,132 @@ #include "task.h" #include "util.h" -extern bool8 (*gIsTrainerInRange[])(struct MapObject *, u16, s16, s16); -extern bool8 (*gTrainerSeeFuncList[])(u8, struct Task *, struct MapObject *); -extern bool8 (*gTrainerSeeFuncList2[])(u8, struct Task *, struct MapObject *); +const u8 gSpriteImage_839B308[] = INCBIN_U8("graphics/unknown_sprites/839B4E0/0.4bpp"); +const u8 gSpriteImage_839B388[] = INCBIN_U8("graphics/unknown_sprites/839B4E0/1.4bpp"); +const u8 gSpriteImage_839B408[] = INCBIN_U8("graphics/unknown_sprites/839B408.4bpp"); + +u8 GetTrainerApproachDistanceSouth(struct MapObject *trainerObj, s16 range, s16 x, s16 y); +u8 GetTrainerApproachDistanceNorth(struct MapObject *trainerObj, s16 range, s16 x, s16 y); +u8 GetTrainerApproachDistanceWest(struct MapObject *trainerObj, s16 range, s16 x, s16 y); +u8 GetTrainerApproachDistanceEast(struct MapObject *trainerObj, s16 range, s16 x, s16 y); + +static u8 (*const sDirectionalApproachDistanceFuncs[])(struct MapObject *, s16, s16, s16) = +{ + GetTrainerApproachDistanceSouth, + GetTrainerApproachDistanceNorth, + GetTrainerApproachDistanceWest, + GetTrainerApproachDistanceEast, +}; extern struct SpriteTemplate gSpriteTemplate_839B510; extern struct SpriteTemplate gSpriteTemplate_839B528; bool8 CheckTrainers(void) { - u8 i; + u8 mapObjId; - for (i = 0; i < 16; i++) + for (mapObjId = 0; mapObjId < 16; mapObjId++) { - if ( gMapObjects[i].active ) - if ( gMapObjects[i].trainerType == 1 || gMapObjects[i].trainerType == 3 ) - if ( CheckTrainer(i) ) - return TRUE; + if (gMapObjects[mapObjId].active + && (gMapObjects[mapObjId].trainerType == 1 || gMapObjects[mapObjId].trainerType == 3) + && CheckTrainer(mapObjId)) + return TRUE; } return FALSE; } -bool8 CheckTrainer(u8 trainer) +bool8 CheckTrainer(u8 mapObjId) { - u8 *scriptPtr = GetFieldObjectScriptPointerByFieldObjectId(trainer); + u8 *scriptPtr = GetFieldObjectScriptPointerByFieldObjectId(mapObjId); - if (GetTrainerFlagFromScriptPointer(scriptPtr)) - return FALSE; - else - { - struct MapObject *trainerObj = &gMapObjects[trainer]; - u8 canApproach = TrainerCanApproachPlayer(trainerObj); + if (GetTrainerFlagFromScriptPointer(scriptPtr)) + { + return FALSE; + } + else + { + struct MapObject *trainerObj = &gMapObjects[mapObjId]; + bool8 canApproach = TrainerCanApproachPlayer(trainerObj); - if (canApproach != 0) + if (canApproach) { - TrainerWantsBattle(trainer, scriptPtr); - sub_80842C8(trainerObj, (canApproach - 1)); - return TRUE; + TrainerWantsBattle(mapObjId, scriptPtr); + sub_80842C8(trainerObj, (canApproach - 1)); + return TRUE; } - else - { - return FALSE; - } - } + else + { + return FALSE; + } + } } bool8 TrainerCanApproachPlayer(struct MapObject *trainerObj) { s16 x, y; u8 i; - u8 playerCoord; + u8 approachDistance; PlayerGetDestCoords(&x, &y); - if ( trainerObj->trainerType == 1 ) // trainers that don't spin + if (trainerObj->trainerType == 1) // can only see in one direction { - playerCoord = gIsTrainerInRange[trainerObj->mapobj_unk_18 - 1](trainerObj, trainerObj->trainerRange_berryTreeId, x, y); - return CheckPathBetweenTrainerAndPlayer((struct MapObject2 *)trainerObj, playerCoord, trainerObj->mapobj_unk_18); + approachDistance = sDirectionalApproachDistanceFuncs[trainerObj->mapobj_unk_18 - 1](trainerObj, trainerObj->trainerRange_berryTreeId, x, y); + return CheckPathBetweenTrainerAndPlayer((struct MapObject2 *)trainerObj, approachDistance, trainerObj->mapobj_unk_18); } - else // spinners + else // can see in all directions { for (i = 0; i < 4; i++) { - playerCoord = gIsTrainerInRange[i](trainerObj, trainerObj->trainerRange_berryTreeId, x, y); - if ( CheckPathBetweenTrainerAndPlayer((struct MapObject2 *)trainerObj, playerCoord, i + 1) ) // directions are 1-4 instead of 0-3. south north west east - return playerCoord; + approachDistance = sDirectionalApproachDistanceFuncs[i](trainerObj, trainerObj->trainerRange_berryTreeId, x, y); + if (CheckPathBetweenTrainerAndPlayer((struct MapObject2 *)trainerObj, approachDistance, i + 1)) // directions are 1-4 instead of 0-3. south north west east + return approachDistance; } - return FALSE; } + return FALSE; } -bool8 IsTrainerInRangeSouth(struct MapObject *trainerObj, s16 vision, s16 x, s16 y) +// Returns how far south the player is from trainer. 0 if out of trainer's sight. +u8 GetTrainerApproachDistanceSouth(struct MapObject *trainerObj, s16 range, s16 x, s16 y) { - if ( trainerObj->coords2.x == x - && y > trainerObj->coords2.y - && y <= trainerObj->coords2.y + vision ) + if (trainerObj->coords2.x == x + && y > trainerObj->coords2.y + && y <= trainerObj->coords2.y + range) return (y - trainerObj->coords2.y); else - return FALSE; + return 0; } -bool8 IsTrainerInRangeNorth(struct MapObject *trainerObj, s16 vision, s16 x, s16 y) +// Returns how far north the player is from trainer. 0 if out of trainer's sight. +u8 GetTrainerApproachDistanceNorth(struct MapObject *trainerObj, s16 range, s16 x, s16 y) { - if ( trainerObj->coords2.x == x - && y < trainerObj->coords2.y - && y >= trainerObj->coords2.y - vision ) + if (trainerObj->coords2.x == x + && y < trainerObj->coords2.y + && y >= trainerObj->coords2.y - range) return (trainerObj->coords2.y - y); else - return FALSE; + return 0; } -bool8 IsTrainerInRangeWest(struct MapObject *trainerObj, s16 vision, s16 x, s16 y) +// Returns how far west the player is from trainer. 0 if out of trainer's sight. +u8 GetTrainerApproachDistanceWest(struct MapObject *trainerObj, s16 range, s16 x, s16 y) { - if ( trainerObj->coords2.y == y - && x < trainerObj->coords2.x - && x >= trainerObj->coords2.x - vision ) + if (trainerObj->coords2.y == y + && x < trainerObj->coords2.x + && x >= trainerObj->coords2.x - range) return (trainerObj->coords2.x - x); else - return FALSE; + return 0; } -bool8 IsTrainerInRangeEast(struct MapObject *trainerObj, s16 vision, s16 x, s16 y) +// Returns how far east the player is from trainer. 0 if out of trainer's sight. +u8 GetTrainerApproachDistanceEast(struct MapObject *trainerObj, s16 range, s16 x, s16 y) { - if ( trainerObj->coords2.y == y - && x > trainerObj->coords2.x - && x <= trainerObj->coords2.x + vision ) + if (trainerObj->coords2.y == y + && x > trainerObj->coords2.x + && x <= trainerObj->coords2.x + range) return (x - trainerObj->coords2.x); else - return FALSE; + return 0; } #ifdef BUGFIX_TRAINERAPPROACH @@ -124,25 +143,24 @@ bool8 IsTrainerInRangeEast(struct MapObject *trainerObj, s16 vision, s16 x, s16 #define COLLISION_MASK 1 #endif -bool8 CheckPathBetweenTrainerAndPlayer(struct MapObject2 *trainerObj, u8 playerCoord, u8 direction) +bool8 CheckPathBetweenTrainerAndPlayer(struct MapObject2 *trainerObj, u8 approachDistance, u8 direction) { s16 x, y; u8 unk19_temp; u8 unk19b_temp; u8 i; - u8 var; + u8 collision; - if (!playerCoord) + if (approachDistance == 0) return FALSE; x = trainerObj->coords2.x; y = trainerObj->coords2.y; - for (i = 0; i <= playerCoord - 1; i++, MoveCoords(direction, &x, &y)) + for (i = 0; i <= approachDistance - 1; i++, MoveCoords(direction, &x, &y)) { - var = sub_8060024((struct MapObject *)trainerObj, x, y, direction); - - if (var && (var & COLLISION_MASK)) + collision = sub_8060024((struct MapObject *)trainerObj, x, y, direction); + if (collision != 0 && (collision & COLLISION_MASK)) return FALSE; } @@ -152,176 +170,212 @@ bool8 CheckPathBetweenTrainerAndPlayer(struct MapObject2 *trainerObj, u8 playerC trainerObj->mapobj_unk_19 = 0; trainerObj->mapobj_unk_19b = 0; - var = npc_block_way((struct MapObject *)trainerObj, x, y, direction); + collision = npc_block_way((struct MapObject *)trainerObj, x, y, direction); trainerObj->mapobj_unk_19 = unk19_temp; trainerObj->mapobj_unk_19b = unk19b_temp; - if (var == 4) - return playerCoord; + if (collision == 4) + return approachDistance; return FALSE; } -void sub_80842C8(struct MapObject *trainerObj, u8 taskId) +#define tTrainerObjHi data[1] +#define tTrainerObjLo data[2] + +void sub_80842C8(struct MapObject *trainerObj, u8 b) { - struct Task *task = &gTasks[CreateTask(RunTrainerSeeFuncList, 0x50)]; + u8 taskId = CreateTask(RunTrainerSeeFuncList, 0x50); + struct Task *task = &gTasks[taskId]; - task->data[1] = (u32)(trainerObj) >> 16; - task->data[2] = (u32)(trainerObj); - task->data[3] = taskId; + task->tTrainerObjHi = (u32)(trainerObj) >> 16; + task->tTrainerObjLo = (u32)(trainerObj); + task->data[3] = b; } -void sub_80842FC(TaskFunc func) +void sub_80842FC(TaskFunc followupFunc) { - TaskFunc func2 = RunTrainerSeeFuncList; - u8 taskId = FindTaskIdByFunc(func2); + TaskFunc taskFunc = RunTrainerSeeFuncList; + u8 taskId = FindTaskIdByFunc(taskFunc); - SetTaskFuncWithFollowupFunc(taskId, RunTrainerSeeFuncList, func); + SetTaskFuncWithFollowupFunc(taskId, taskFunc, followupFunc); gTasks[taskId].data[0] = 1; - func2(taskId); -} + taskFunc(taskId); +} + +static bool8 sub_8084394(u8 taskId, struct Task *task, struct MapObject *trainerObj); +static bool8 sub_8084398(u8 taskId, struct Task *task, struct MapObject *trainerObj); +static bool8 sub_80843DC(u8 taskId, struct Task *task, struct MapObject *trainerObj); +static bool8 sub_808441C(u8 taskId, struct Task *task, struct MapObject *trainerObj); +static bool8 sub_8084478(u8 taskId, struct Task *task, struct MapObject *trainerObj); +static bool8 sub_8084534(u8 taskId, struct Task *task, struct MapObject *trainerObj); +static bool8 sub_8084578(u8 taskId, struct Task *task, struct MapObject *trainerObj); +static bool8 sub_80845AC(u8 taskId, struct Task *task, struct MapObject *trainerObj); +static bool8 sub_80845C8(u8 taskId, struct Task *task, struct MapObject *trainerObj); +static bool8 sub_80845FC(u8 taskId, struct Task *task, struct MapObject *trainerObj); +static bool8 sub_8084654(u8 taskId, struct Task *task, struct MapObject *trainerObj); +static bool8 sub_80846C8(u8 taskId, struct Task *task, struct MapObject *trainerObj); + +static bool8 (*const gTrainerSeeFuncList[])(u8 taskId, struct Task *task, struct MapObject *trainerObj) = +{ + sub_8084394, + sub_8084398, + sub_80843DC, + sub_808441C, + sub_8084478, + sub_8084534, + sub_8084578, + sub_80845AC, + sub_80845C8, + sub_80845FC, + sub_8084654, + sub_80846C8, +}; void RunTrainerSeeFuncList(u8 taskId) { struct Task *task = &gTasks[taskId]; - struct MapObject *trainerObj = (struct MapObject *)((task->data[1] << 16) | (task->data[2])); + struct MapObject *trainerObj = (struct MapObject *)((task->tTrainerObjHi << 16) | (task->tTrainerObjLo)); if (!trainerObj->active) + { SwitchTaskToFollowupFunc(taskId); + } else - while (gTrainerSeeFuncList[task->data[0]](taskId, task, trainerObj)); + { + while (gTrainerSeeFuncList[task->data[0]](taskId, task, trainerObj)) + ; + } } -u8 sub_8084394() // cant be void because it is called with RunTrainerSeeFuncList with arguments. +static bool8 sub_8084394(u8 taskId, struct Task *task, struct MapObject *trainerObj) // cant be void because it is called with RunTrainerSeeFuncList with arguments. { - return 0; + return FALSE; } -s8 sub_8084398(u8 taskId, struct Task *task, struct MapObject *trainerObj) +static bool8 sub_8084398(u8 taskId, struct Task *task, struct MapObject *trainerObj) { u8 direction; - FieldObjectGetLocalIdAndMap(trainerObj, (u8 *)&gUnknown_0202FF84[0], (u8 *)&gUnknown_0202FF84[1], (u8 *)&gUnknown_0202FF84[2]); - FieldEffectStart(0); - + FieldObjectGetLocalIdAndMap(trainerObj, (u8 *)&gFieldEffectArguments[0], (u8 *)&gFieldEffectArguments[1], (u8 *)&gFieldEffectArguments[2]); + FieldEffectStart(FLDEFF_EXCLAMATION_MARK_ICON_1); direction = GetFaceDirectionAnimId(trainerObj->mapobj_unk_18); - FieldObjectSetSpecialAnim(trainerObj, direction); task->data[0]++; - return 1; + return TRUE; } -s8 sub_80843DC(u8 taskId, struct Task *task, struct MapObject *trainerObj) +static bool8 sub_80843DC(u8 taskId, struct Task *task, struct MapObject *trainerObj) { if (FieldEffectActiveListContains(0)) - return 0; + { + return FALSE; + } else { task->data[0]++; - if ((u8)(trainerObj->animPattern - 57) <= 1) + if (trainerObj->animPattern == 57 || trainerObj->animPattern == 58) task->data[0] = 6; if (trainerObj->animPattern == 63) task->data[0] = 8; - return 1; + return TRUE; } } -s8 sub_808441C(u8 taskId, struct Task *task, struct MapObject *trainerObj) +static bool8 sub_808441C(u8 taskId, struct Task *task, struct MapObject *trainerObj) { if (!(FieldObjectIsSpecialAnimOrDirectionSequenceAnimActive(trainerObj)) || FieldObjectClearAnimIfSpecialAnimFinished(trainerObj)) { - if (task->data[3]) - { - FieldObjectSetSpecialAnim(trainerObj, GetGoSpeed0AnimId(trainerObj->mapobj_unk_18)); - task->data[3]--; - } - else - { - FieldObjectSetSpecialAnim(trainerObj, 0x3E); - task->data[0]++; - } + if (task->data[3]) + { + FieldObjectSetSpecialAnim(trainerObj, GetGoSpeed0AnimId(trainerObj->mapobj_unk_18)); + task->data[3]--; + } + else + { + FieldObjectSetSpecialAnim(trainerObj, 0x3E); + task->data[0]++; + } } - return 0; + return FALSE; } -s8 sub_8084478(u8 taskId, struct Task *task, struct MapObject *trainerObj) +static bool8 sub_8084478(u8 taskId, struct Task *task, struct MapObject *trainerObj) { struct MapObject *playerObj; if (FieldObjectIsSpecialAnimOrDirectionSequenceAnimActive(trainerObj) && !FieldObjectClearAnimIfSpecialAnimFinished(trainerObj)) - return 0; + return FALSE; npc_set_running_behaviour_etc(trainerObj, npc_running_behaviour_by_direction(trainerObj->mapobj_unk_18)); sub_805C774(trainerObj, npc_running_behaviour_by_direction(trainerObj->mapobj_unk_18)); sub_805C754(trainerObj); playerObj = &gMapObjects[gPlayerAvatar.mapObjectId]; - if (FieldObjectIsSpecialAnimOrDirectionSequenceAnimActive(playerObj) - && !FieldObjectClearAnimIfSpecialAnimFinished(playerObj)) - return 0; + if (FieldObjectIsSpecialAnimOrDirectionSequenceAnimActive(playerObj) && !FieldObjectClearAnimIfSpecialAnimFinished(playerObj)) + return FALSE; sub_80597E8(); FieldObjectSetSpecialAnim(&gMapObjects[gPlayerAvatar.mapObjectId], GetFaceDirectionAnimId(GetOppositeDirection(trainerObj->mapobj_unk_18))); task->data[0]++; - return 0; + return FALSE; } -s8 sub_8084534(u8 taskId, struct Task *task, struct MapObject *trainerObj) // technically only 1 parameter, but needs all 3 for TrainerSeeFuncList call. +static bool8 sub_8084534(u8 taskId, struct Task *task, struct MapObject *trainerObj) // technically only 1 parameter, but needs all 3 for TrainerSeeFuncList call. { struct MapObject *playerObj = &gMapObjects[gPlayerAvatar.mapObjectId]; - if ( !FieldObjectIsSpecialAnimOrDirectionSequenceAnimActive(playerObj) - || FieldObjectClearAnimIfSpecialAnimFinished(playerObj) ) - SwitchTaskToFollowupFunc(taskId); - - return 0; + if (!FieldObjectIsSpecialAnimOrDirectionSequenceAnimActive(playerObj) + || FieldObjectClearAnimIfSpecialAnimFinished(playerObj)) + SwitchTaskToFollowupFunc(taskId); + return FALSE; } -s8 sub_8084578(u8 taskId, struct Task *task, struct MapObject *trainerObj) +static bool8 sub_8084578(u8 taskId, struct Task *task, struct MapObject *trainerObj) { if (!FieldObjectIsSpecialAnimOrDirectionSequenceAnimActive(trainerObj) - || FieldObjectClearAnimIfSpecialAnimFinished(trainerObj)) + || FieldObjectClearAnimIfSpecialAnimFinished(trainerObj)) { FieldObjectSetSpecialAnim(trainerObj, 0x59); task->data[0]++; } - return 0; + return FALSE; } -s8 sub_80845AC(u8 taskId, struct Task *task, struct MapObject *trainerObj) +static bool8 sub_80845AC(u8 taskId, struct Task *task, struct MapObject *trainerObj) { - if ( FieldObjectClearAnimIfSpecialAnimFinished(trainerObj) ) + if (FieldObjectClearAnimIfSpecialAnimFinished(trainerObj)) task->data[0] = 3; - return 0; + return FALSE; } -s8 sub_80845C8(u8 taskId, struct Task *task, struct MapObject *trainerObj) +static bool8 sub_80845C8(u8 taskId, struct Task *task, struct MapObject *trainerObj) { if (!FieldObjectIsSpecialAnimOrDirectionSequenceAnimActive(trainerObj) - || FieldObjectClearAnimIfSpecialAnimFinished(trainerObj)) + || FieldObjectClearAnimIfSpecialAnimFinished(trainerObj)) { FieldObjectSetSpecialAnim(trainerObj, 0x3E); task->data[0]++; } - return 0; + return FALSE; } -s8 sub_80845FC(u8 taskId, struct Task *task, struct MapObject *trainerObj) +static bool8 sub_80845FC(u8 taskId, struct Task *task, struct MapObject *trainerObj) { if (FieldObjectCheckIfSpecialAnimFinishedOrInactive(trainerObj)) { - gUnknown_0202FF84[0] = trainerObj->coords2.x; - gUnknown_0202FF84[1] = trainerObj->coords2.y; - gUnknown_0202FF84[2] = gSprites[trainerObj->spriteId].subpriority - 1; - gUnknown_0202FF84[3] = 2; - task->data[4] = FieldEffectStart(49); + gFieldEffectArguments[0] = trainerObj->coords2.x; + gFieldEffectArguments[1] = trainerObj->coords2.y; + gFieldEffectArguments[2] = gSprites[trainerObj->spriteId].subpriority - 1; + gFieldEffectArguments[3] = 2; + task->data[4] = FieldEffectStart(FLDEFF_POP_OUT_OF_ASH); task->data[0]++; } - return 0; + return FALSE; } -s8 sub_8084654(u8 taskId, struct Task *task, struct MapObject *trainerObj) +static bool8 sub_8084654(u8 taskId, struct Task *task, struct MapObject *trainerObj) { struct Sprite *sprite; @@ -336,17 +390,25 @@ s8 sub_8084654(u8 taskId, struct Task *task, struct MapObject *trainerObj) FieldObjectSetSpecialAnim(trainerObj, sub_806084C(trainerObj->mapobj_unk_18)); task->data[0]++; } - return 0; + return FALSE; } -s8 sub_80846C8(u8 taskId, struct Task *task, struct MapObject *trainerObj) +static bool8 sub_80846C8(u8 taskId, struct Task *task, struct MapObject *trainerObj) { if (!FieldEffectActiveListContains(49)) task->data[0] = 3; - return 0; + return FALSE; } +static bool8 (*const gTrainerSeeFuncList2[])(u8, struct Task *, struct MapObject *) = +{ + sub_80845C8, + sub_80845FC, + sub_8084654, + sub_80846C8, +}; + void sub_80846E4(u8 taskId) { struct Task *task = &gTasks[taskId]; @@ -375,12 +437,14 @@ void sub_8084794(struct MapObject *var) StoreWordInTwoHalfwords(&gTasks[CreateTask(sub_80846E4, 0)].data[1], (u32)var); } -void sub_80847C8(void) +static void Task_DestroyTrainerApproachTask(u8); + +void ScrSpecial_EndTrainerApproach(void) { - sub_80842FC(sub_80847D8); + sub_80842FC(Task_DestroyTrainerApproachTask); } -void sub_80847D8(u8 taskId) +static void Task_DestroyTrainerApproachTask(u8 taskId) { DestroyTask(taskId); EnableBothScriptContexts(); @@ -421,9 +485,9 @@ void sub_8084894(struct Sprite *sprite, u16 a2, u8 a3) sprite->oam.priority = 1; sprite->coordOffsetEnabled = 1; - sprite->data0 = gUnknown_0202FF84[0]; - sprite->data1 = gUnknown_0202FF84[1]; - sprite->data2 = gUnknown_0202FF84[2]; + sprite->data0 = gFieldEffectArguments[0]; + sprite->data1 = gFieldEffectArguments[1]; + sprite->data2 = gFieldEffectArguments[2]; sprite->data3 = -5; sprite->data7 = a2; diff --git a/src/field/tv.c b/src/field/tv.c index 996709209..734cbad6f 100644 --- a/src/field/tv.c +++ b/src/field/tv.c @@ -15,7 +15,7 @@ #include "species.h" #include "pokedex.h" #include "naming_screen.h" -#include "rom4.h" +#include "overworld.h" #include "map_constants.h" #include "strings.h" #include "battle.h" @@ -31,7 +31,7 @@ #include "pokedex.h" #include "region_map.h" #include "rng.h" -#include "rom4.h" +#include "overworld.h" #include "rtc.h" #include "script_menu.h" #include "species.h" @@ -235,7 +235,7 @@ void UpdateTVScreensOnMap(int width, int height) } else if (FlagGet(SYS_TV_START) && (sub_80BD8B8() != 0xff || sub_80BECA0() != 0xff || IsTVShowInSearchOfTrainersAiring())) { - FlagReset(SYS_TV_WATCH); + FlagClear(SYS_TV_WATCH); SetTVMetatilesOnMap(width, height, 0x3); } break; @@ -942,7 +942,6 @@ void sub_80BE97C(bool8 flag) void sub_80BE9D4(void) { - //TVShow *show; gUnknown_03005D38.var0 = sub_80BF74C(gSaveBlock1.tvShows); if (gUnknown_03005D38.var0 != -1 && sub_80BF1B4(TVSHOW_FISHING_ADVICE) != 1) { diff --git a/src/field/use_pokeblock.c b/src/field/use_pokeblock.c index 0c8f59959..be3003680 100644 --- a/src/field/use_pokeblock.c +++ b/src/field/use_pokeblock.c @@ -5,7 +5,7 @@ #include "global.h" #include "main.h" -#include "rom4.h" +#include "overworld.h" #include "string_util.h" #include "strings.h" #include "sprite.h" diff --git a/src/field/wild_encounter.c b/src/field/wild_encounter.c index 7001c2eaa..390898917 100644 --- a/src/field/wild_encounter.c +++ b/src/field/wild_encounter.c @@ -5,11 +5,12 @@ #include "event_data.h" #include "field_player_avatar.h" #include "fieldmap.h" +#include "map_constants.h" #include "metatile_behavior.h" #include "pokeblock.h" #include "rng.h" #include "roamer.h" -#include "rom4.h" +#include "overworld.h" #include "safari_zone.h" #include "script.h" #include "species.h" @@ -2901,7 +2902,7 @@ const struct WildPokemonInfo Underwater2_WaterMonsInfo = {4, Underwater2_WaterMo extern u16 gRoute119WaterTileData[]; extern u16 gScriptResult; extern struct WildPokemon gWildFeebasRoute119Data; -extern u8 Event_RepelWoreOff[]; +extern u8 S_RepelWoreOff[]; EWRAM_DATA static u8 sWildEncountersDisabled = 0; EWRAM_DATA static u32 sFeebasRngValue = 0; @@ -2911,7 +2912,7 @@ EWRAM_DATA static u32 sFeebasRngValue = 0; static u16 FeebasRandom(void); static void FeebasSeedRng(u16 seed); -static bool8 RepelCheck(u8 level); +static bool8 IsWildLevelAllowedByRepel(u8 level); static void ApplyFluteEncounterRateMod(u32 *encRate); static void ApplyCleanseTagEncounterRateMod(u32 *encRate); @@ -2952,7 +2953,8 @@ static bool8 CheckFeebas(void) u8 route119section = 0; u16 waterTileNum; - if (gSaveBlock1.location.mapGroup == 0 && gSaveBlock1.location.mapNum == 0x22) + if (gSaveBlock1.location.mapGroup == MAP_GROUP_ROUTE119 + && gSaveBlock1.location.mapNum == MAP_ID_ROUTE119) { GetXYCoordsOneStepInFrontOfPlayer(&x, &y); x -= 7; @@ -3193,7 +3195,7 @@ static bool8 GenerateWildMon(struct WildPokemonInfo *wildMonInfo, u8 area, bool8 break; } level = ChooseWildMonLevel(&wildMonInfo->wildPokemon[wildMonIndex]); - if (checkRepel == TRUE && RepelCheck(level) == FALSE) + if (checkRepel == TRUE && IsWildLevelAllowedByRepel(level) == FALSE) return FALSE; else { @@ -3215,7 +3217,7 @@ static bool8 SetUpMassOutbreakEncounter(bool8 checkRepel) { u16 i; - if (checkRepel == TRUE && RepelCheck(gSaveBlock1.outbreakPokemonLevel) == 0) + if (checkRepel == TRUE && IsWildLevelAllowedByRepel(gSaveBlock1.outbreakPokemonLevel) == FALSE) return FALSE; else { @@ -3302,9 +3304,9 @@ bool8 StandardWildEncounter(u16 a, u16 b) if (TryStartRoamerEncounter() == TRUE) { roamer = &gSaveBlock1.roamer; - if (RepelCheck(roamer->level)) + if (IsWildLevelAllowedByRepel(roamer->level)) { - StartBattle_Roamer(); + BattleSetup_StartRoamerBattle(); return 1; } } @@ -3312,7 +3314,7 @@ bool8 StandardWildEncounter(u16 a, u16 b) { if (DoMassOutbreakEncounterTest() == TRUE && SetUpMassOutbreakEncounter(1) == TRUE) { - CheckForSafariZoneAndProceed(); + BattleSetup_StartWildBattle(); return 1; } if (GenerateWildMon(gWildMonHeaders[headerNum].landMonsInfo, 0, TRUE) == TRUE) @@ -3336,9 +3338,9 @@ bool8 StandardWildEncounter(u16 a, u16 b) if (TryStartRoamerEncounter() == TRUE) { roamer = &gSaveBlock1.roamer; - if (RepelCheck(roamer->level)) + if (IsWildLevelAllowedByRepel(roamer->level)) { - StartBattle_Roamer(); + BattleSetup_StartRoamerBattle(); return 1; } } @@ -3349,7 +3351,7 @@ bool8 StandardWildEncounter(u16 a, u16 b) { label: //_0808527A - CheckForSafariZoneAndProceed(); + BattleSetup_StartWildBattle(); return 1; } } @@ -3361,7 +3363,7 @@ bool8 StandardWildEncounter(u16 a, u16 b) return 0; } -void RockSmashWildEncounter(void) +void ScrSpecial_RockSmashWildEncounter(void) { u16 headerNum = GetCurrentMapWildMonHeader(); @@ -3377,7 +3379,7 @@ void RockSmashWildEncounter(void) else if (DoWildEncounterTest(wildPokemonInfo->encounterRate, 1) == TRUE && GenerateWildMon(wildPokemonInfo, 2, TRUE) == TRUE) { - CheckForSafariZoneAndProceed(); + BattleSetup_StartWildBattle(); gScriptResult = 1; return; } @@ -3403,14 +3405,14 @@ bool8 SweetScentWildEncounter(void) return FALSE; if (TryStartRoamerEncounter() == TRUE) { - StartBattle_Roamer(); + BattleSetup_StartRoamerBattle(); return TRUE; } if (DoMassOutbreakEncounterTest() == TRUE) - SetUpMassOutbreakEncounter(0); + SetUpMassOutbreakEncounter(FALSE); else GenerateWildMon(wildPokemonInfo, 0, FALSE); - CheckForSafariZoneAndProceed(); + BattleSetup_StartWildBattle(); return TRUE; } else if (MetatileBehavior_IsWaterWildEncounter(MapGridGetMetatileBehaviorAt(x, y)) == 1) @@ -3420,18 +3422,18 @@ bool8 SweetScentWildEncounter(void) return FALSE; if (TryStartRoamerEncounter() == TRUE) { - StartBattle_Roamer(); + BattleSetup_StartRoamerBattle(); return TRUE; } GenerateWildMon(wildPokemonInfo, 1, FALSE); - CheckForSafariZoneAndProceed(); + BattleSetup_StartWildBattle(); return TRUE; } } return FALSE; } -bool8 GetFishingWildMonListHeader(void) +bool8 DoesCurrentMapHaveFishingMons(void) { u16 headerNum = GetCurrentMapWildMonHeader(); @@ -3460,7 +3462,7 @@ void FishingWildEncounter(u8 rod) } IncrementGameStat(12); sub_80BEA50(species); - CheckForSafariZoneAndProceed(); + BattleSetup_StartWildBattle(); } u16 GetLocalWildMon(bool8 *isWaterMon) @@ -3497,7 +3499,7 @@ u16 GetLocalWildMon(bool8 *isWaterMon) } } -u16 GetMirageIslandMon(void) +u16 GetLocalWaterMon(void) { u16 headerNum = GetCurrentMapWildMonHeader(); @@ -3521,20 +3523,21 @@ bool8 UpdateRepelCounter(void) VarSet(VAR_REPEL_STEP_COUNT, steps); if (steps == 0) { - ScriptContext1_SetupScript(Event_RepelWoreOff); + ScriptContext1_SetupScript(S_RepelWoreOff); return TRUE; } } return FALSE; } -//Returns FALSE if Repel prevents wild Pokemon at the specified level from appearing -static bool8 RepelCheck(u8 level) +static bool8 IsWildLevelAllowedByRepel(u8 wildLevel) { u8 i; if (!VarGet(VAR_REPEL_STEP_COUNT)) + { return TRUE; + } else { for (i = 0; i < 6; i++) @@ -3542,7 +3545,9 @@ static bool8 RepelCheck(u8 level) // UB: Too few arguments for function 'GetMonData' if (GetMonData(&gPlayerParty[i], MON_DATA_HP) && !GetMonData(&gPlayerParty[i], MON_DATA_IS_EGG)) { - if (level < (u8)GetMonData(&gPlayerParty[i], MON_DATA_LEVEL)) + u8 ourLevel = GetMonData(&gPlayerParty[i], MON_DATA_LEVEL); + + if (wildLevel < ourLevel) return FALSE; else return TRUE; diff --git a/src/misc/rom3.c b/src/misc/rom3.c index 3b4b6a941..3f4860ecc 100644 --- a/src/misc/rom3.c +++ b/src/misc/rom3.c @@ -1081,10 +1081,10 @@ void EmitFaintingCry(u8 a) PrepareBufferDataTransfer(a, gBattleBuffersTransferData, 4); } -void EmitIntroSlide(u8 a, u8 b) +void EmitIntroSlide(u8 a, u8 battleTerrain) { gBattleBuffersTransferData[0] = 46; - gBattleBuffersTransferData[1] = b; + gBattleBuffersTransferData[1] = battleTerrain; PrepareBufferDataTransfer(a, gBattleBuffersTransferData, 2); } diff --git a/src/misc/rom6.c b/src/misc/rom6.c index ff032b6c2..3a5071034 100644 --- a/src/misc/rom6.c +++ b/src/misc/rom6.c @@ -6,7 +6,7 @@ #include "field_player_avatar.h" #include "item_use.h" #include "pokemon_menu.h" -#include "rom4.h" +#include "overworld.h" #include "script.h" #include "songs.h" #include "sound.h" @@ -17,7 +17,7 @@ extern u16 gScriptLastTalked; extern void (*gFieldCallback)(void); extern u8 gLastFieldPokeMenuOpened; extern void (*gUnknown_03005CE4)(void); -extern u8 UseRockSmashScript[]; +extern u8 S_UseRockSmash[]; EWRAM_DATA struct MapPosition gUnknown_0203923C = {0}; @@ -64,9 +64,9 @@ static void task08_080C9820(u8 taskId) if (!FieldObjectIsSpecialAnimOrDirectionSequenceAnimActive(&gMapObjects[mapObjId]) || FieldObjectClearAnimIfSpecialAnimFinished(&gMapObjects[mapObjId])) { - if (gMapHeader.mapType == 5) + if (gMapHeader.mapType == MAP_TYPE_UNDERWATER) { - FieldEffectStart(0x3B); + FieldEffectStart(FLDEFF_FIELD_MOVE_SHOW_MON_INIT); gTasks[taskId].func = sub_810B428; } else @@ -82,7 +82,7 @@ static void sub_810B3DC(u8 taskId) { if (FieldObjectCheckIfSpecialAnimFinishedOrInactive(&gMapObjects[gPlayerAvatar.mapObjectId]) == TRUE) { - FieldEffectStart(0x3B); + FieldEffectStart(FLDEFF_FIELD_MOVE_SHOW_MON_INIT); gTasks[taskId].func = sub_810B428; } } @@ -91,17 +91,17 @@ static void sub_810B428(u8 taskId) { if (!FieldEffectActiveListContains(6)) { - gUnknown_0202FF84[1] = player_get_direction_lower_nybble(); - if (gUnknown_0202FF84[1] == 1) - gUnknown_0202FF84[2] = 0; - if (gUnknown_0202FF84[1] == 2) - gUnknown_0202FF84[2] = 1; - if (gUnknown_0202FF84[1] == 3) - gUnknown_0202FF84[2] = 2; - if (gUnknown_0202FF84[1] == 4) - gUnknown_0202FF84[2] = 3; + gFieldEffectArguments[1] = player_get_direction_lower_nybble(); + if (gFieldEffectArguments[1] == 1) + gFieldEffectArguments[2] = 0; + if (gFieldEffectArguments[1] == 2) + gFieldEffectArguments[2] = 1; + if (gFieldEffectArguments[1] == 3) + gFieldEffectArguments[2] = 2; + if (gFieldEffectArguments[1] == 4) + gFieldEffectArguments[2] = 3; sub_805B980(&gMapObjects[gPlayerAvatar.mapObjectId], GetPlayerAvatarGraphicsIdByCurrentState()); - StartSpriteAnim(&gSprites[gPlayerAvatar.spriteId], gUnknown_0202FF84[2]); + StartSpriteAnim(&gSprites[gPlayerAvatar.spriteId], gFieldEffectArguments[2]); FieldEffectActiveListRemove(6); gTasks[taskId].func = sub_810B4CC; } @@ -120,7 +120,7 @@ bool8 SetUpFieldMove_RockSmash(void) { if (npc_before_player_of_type(0x56) == TRUE) { - gFieldCallback = sub_808AB90; + gFieldCallback = FieldCallback_Teleport; gUnknown_03005CE4 = sub_810B53C; return TRUE; } @@ -132,8 +132,8 @@ bool8 SetUpFieldMove_RockSmash(void) static void sub_810B53C(void) { - gUnknown_0202FF84[0] = gLastFieldPokeMenuOpened; - ScriptContext1_SetupScript(UseRockSmashScript); + gFieldEffectArguments[0] = gLastFieldPokeMenuOpened; + ScriptContext1_SetupScript(S_UseRockSmash); } int FldEff_RockSmash(void) @@ -149,15 +149,15 @@ int FldEff_RockSmash(void) static void sub_810B58C(void) { PlaySE(SE_W088); - FieldEffectActiveListRemove(0x25); + FieldEffectActiveListRemove(FLDEFF_USE_ROCK_SMASH); EnableBothScriptContexts(); } int SetUpFieldMove_Dig(void) { - if (sub_80CA1C8() == TRUE) + if (CanUseEscapeRopeOnCurrMap() == TRUE) { - gFieldCallback = sub_808AB90; + gFieldCallback = FieldCallback_Teleport; gUnknown_03005CE4 = sub_810B5D8; return TRUE; } @@ -170,8 +170,8 @@ int SetUpFieldMove_Dig(void) static void sub_810B5D8(void) { sub_8053014(); - FieldEffectStart(0x26); - gUnknown_0202FF84[0] = gLastFieldPokeMenuOpened; + FieldEffectStart(FLDEFF_USE_DIG); + gFieldEffectArguments[0] = gLastFieldPokeMenuOpened; } int FldEff_UseDig(void) @@ -189,7 +189,7 @@ static void sub_810B634(void) { u8 taskId; - FieldEffectActiveListRemove(0x26); + FieldEffectActiveListRemove(FLDEFF_USE_DIG); if (ShouldDoBrailleDigEffect()) { DoBrailleDigEffect(); diff --git a/src/misc/script_pokemon_util_80C4BF0.c b/src/misc/script_pokemon_util_80C4BF0.c index cbca07011..323df991a 100644 --- a/src/misc/script_pokemon_util_80C4BF0.c +++ b/src/misc/script_pokemon_util_80C4BF0.c @@ -18,7 +18,7 @@ #include "pokedex.h" #include "pokemon.h" #include "rng.h" -#include "rom4.h" +#include "overworld.h" #include "script_pokemon_80C4.h" #include "species.h" #include "task.h" @@ -511,7 +511,7 @@ void ScriptRandom(void) *scriptPtr = random % *scriptPtr; } -void HealPlayerParty(void) +void ScrSpecial_HealPlayerParty(void) { u8 i, j; u8 ppBonuses; @@ -542,41 +542,39 @@ void HealPlayerParty(void) } } -u8 ScriptGiveMon(u16 species, u8 var, u16 item, u32 var3, u32 var4, u8 var5) +u8 ScriptGiveMon(u16 species, u8 level, u16 item, u32 unused1, u32 unused2, u8 unused3) { - u16 nationalSpecies; + u16 nationalDexNum; int sentToPc; - u8 array[2]; + u8 heldItem[2]; struct Pokemon mon; - CreateMon(&mon, species, var, 32, 0, 0, 0, 0); - array[0] = item; - array[1] = item >> 8; - SetMonData(&mon, MON_DATA_HELD_ITEM, array); + CreateMon(&mon, species, level, 32, 0, 0, 0, 0); + heldItem[0] = item; + heldItem[1] = item >> 8; + SetMonData(&mon, MON_DATA_HELD_ITEM, heldItem); sentToPc = GiveMonToPlayer(&mon); - nationalSpecies = SpeciesToNationalPokedexNum(species); + nationalDexNum = SpeciesToNationalPokedexNum(species); - // nested if check to fool compiler switch(sentToPc) { - case 0: - case 1: - GetNationalPokedexFlag(nationalSpecies, 2); - GetNationalPokedexFlag(nationalSpecies, 3); - return sentToPc; - default: - return sentToPc; + case 0: + case 1: + GetNationalPokedexFlag(nationalDexNum, 2); + GetNationalPokedexFlag(nationalDexNum, 3); + break; } + return sentToPc; } -u8 ScriptGiveEgg(u16 value) +u8 ScriptGiveEgg(u16 species) { struct Pokemon mon; - u8 data; + u8 isEgg; - sub_8042044(&mon, value, 1); - data = 1; - SetMonData(&mon, MON_DATA_IS_EGG, &data); + sub_8042044(&mon, species, 1); + isEgg = TRUE; + SetMonData(&mon, MON_DATA_IS_EGG, &isEgg); return GiveMonToPlayer(&mon); } @@ -622,18 +620,18 @@ bool8 GetNameOfEnigmaBerryInPlayerParty(void) return hasItem; } -void ScriptWildBattle(u16 species, u8 level, u16 item) +void CreateScriptedWildMon(u16 species, u8 level, u16 item) { - u8 data[2]; + u8 heldItem[2]; ZeroEnemyPartyMons(); CreateMon(&gEnemyParty[0], species, level, 0x20, 0, 0, 0, 0); if(item) { - data[0] = item; - data[1] = item >> 8; - SetMonData(&gEnemyParty[0], MON_DATA_HELD_ITEM, data); + heldItem[0] = item; + heldItem[1] = item >> 8; + SetMonData(&gEnemyParty[0], MON_DATA_HELD_ITEM, heldItem); } } diff --git a/src/misc/script_pokemon_util_80F99CC.c b/src/misc/script_pokemon_util_80F99CC.c index 2b48cc0d8..f930df8e2 100644 --- a/src/misc/script_pokemon_util_80F99CC.c +++ b/src/misc/script_pokemon_util_80F99CC.c @@ -9,16 +9,15 @@ #include "party_menu.h" #include "pokemon.h" #include "pokemon_summary_screen.h" -#include "rom4.h" +#include "overworld.h" #include "script.h" #include "script_pokemon_80F9.h" +#include "songs.h" #include "sound.h" #include "string_util.h" #include "task.h" #include "text.h" - - extern u8 gPlayerPartyCount; extern u16 gSpecialVar_0x8004; extern u16 gSpecialVar_0x8005; @@ -59,7 +58,7 @@ void sub_80F9A4C(void) void sub_80F9A8C(u8 taskId) { - if(!gPaletteFade.active) + if (!gPaletteFade.active) { gPaletteFade.bufferTransferDisabled = 1; OpenPartyMenu((u8) gTasks[taskId].data[0], 0); @@ -69,10 +68,10 @@ void sub_80F9A8C(u8 taskId) bool8 sub_80F9ACC(void) { - switch(EWRAM_1B000.unk264) + switch (EWRAM_1B000.unk264) { case 0: - if(EWRAM_1B000.unk266 < gPlayerPartyCount) + if (EWRAM_1B000.unk266 < gPlayerPartyCount) { TryCreatePartyMenuMonIcon(EWRAM_1B000.unk260, EWRAM_1B000.unk266, &gPlayerParty[EWRAM_1B000.unk266]); EWRAM_1B000.unk266++; @@ -92,7 +91,7 @@ bool8 sub_80F9ACC(void) EWRAM_1B000.unk264++; break; case 3: - if(sub_806BD58(EWRAM_1B000.unk260, EWRAM_1B000.unk266) != 1) + if (sub_806BD58(EWRAM_1B000.unk260, EWRAM_1B000.unk266) != 1) { EWRAM_1B000.unk266++; break; @@ -116,7 +115,7 @@ bool8 sub_80F9ACC(void) EWRAM_1B000.unk264++; break; case 7: // the only case that can return true. - if(sub_806B58C(EWRAM_1B000.unk266) != 1) + if (sub_806B58C(EWRAM_1B000.unk266) != 1) { EWRAM_1B000.unk266++; break; @@ -135,9 +134,9 @@ void sub_80F9C00(void) { u8 i; - for(i = 0; i < gPlayerPartyCount; i++) + for (i = 0; i < gPlayerPartyCount; i++) { - switch(sub_80AE47C(&gPlayerParty[i])) + switch (sub_80AE47C(&gPlayerParty[i])) { case 0: case 3: @@ -154,18 +153,18 @@ void sub_80F9C00(void) void sub_80F9C6C(u8 var) { - if(!gPaletteFade.active) + if (!gPaletteFade.active) { - switch(sub_806BD80(var)) + switch (sub_806BD80(var)) { case 1: - PlaySE(5); + PlaySE(SE_SELECT); gUnknown_02038694 = sub_806CA38(var); gSpecialVar_0x8004 = gUnknown_02038694; sub_8123138(var); break; case 2: - PlaySE(5); + PlaySE(SE_SELECT); gUnknown_02038694 = 0xFF; gSpecialVar_0x8004 = 0xFF; sub_8123138(var); @@ -176,10 +175,10 @@ void sub_80F9C6C(u8 var) bool8 sub_80F9CE8(void) // this is the same function as sub_80F9ACC except case 6 calls a different function. why { - switch(EWRAM_1B000.unk264) + switch (EWRAM_1B000.unk264) { case 0: - if(EWRAM_1B000.unk266 < gPlayerPartyCount) + if (EWRAM_1B000.unk266 < gPlayerPartyCount) { TryCreatePartyMenuMonIcon(EWRAM_1B000.unk260, EWRAM_1B000.unk266, &gPlayerParty[EWRAM_1B000.unk266]); EWRAM_1B000.unk266++; @@ -199,7 +198,7 @@ bool8 sub_80F9CE8(void) // this is the same function as sub_80F9ACC except case EWRAM_1B000.unk264++; break; case 3: - if(sub_806BD58(EWRAM_1B000.unk260, EWRAM_1B000.unk266) != 1) + if (sub_806BD58(EWRAM_1B000.unk260, EWRAM_1B000.unk266) != 1) { EWRAM_1B000.unk266++; break; @@ -223,7 +222,7 @@ bool8 sub_80F9CE8(void) // this is the same function as sub_80F9ACC except case EWRAM_1B000.unk264++; break; case 7: // the only case that can return true. - if(sub_806B58C(EWRAM_1B000.unk266) != 1) + if (sub_806B58C(EWRAM_1B000.unk266) != 1) { EWRAM_1B000.unk266++; break; @@ -242,9 +241,9 @@ void sub_80F9E1C(void) { u8 i; - for(i = 0; i < gPlayerPartyCount; i++) + for (i = 0; i < gPlayerPartyCount; i++) { - if(!sub_8040574(&gPlayerParty[i])) + if (!sub_8040574(&gPlayerParty[i])) sub_806BC3C(i, 0x9A); else sub_806BC3C(i, 0x8C); @@ -253,18 +252,18 @@ void sub_80F9E1C(void) void sub_80F9E64(u8 var) { - if(!gPaletteFade.active) + if (!gPaletteFade.active) { - switch(sub_806BD80(var)) + switch (sub_806BD80(var)) { case 1: - PlaySE(5); + PlaySE(SE_SELECT); gSpecialVar_0x8004 = sub_806CA38(var); gSpecialVar_0x8005 = sub_8040574(&gPlayerParty[gSpecialVar_0x8004]); sub_8123138(var); break; case 2: - PlaySE(5); + PlaySE(SE_SELECT); gSpecialVar_0x8004 = 0xFF; sub_8123138(var); } @@ -278,23 +277,23 @@ void sub_80F9EEC(void) gFieldCallback = sub_8080990; } -void sub_80F9F3C(void) // count pokemon moves +void ScrSpecial_CountPokemonMoves(void) // count pokemon moves { u8 i; gScriptResult = 0; - for(i = 0; i < 4; i++) // checks MOVE1-MOVE4 - if(GetMonData(&gPlayerParty[gSpecialVar_0x8004], i + 13)) + for (i = 0; i < 4; i++) // checks MOVE1-MOVE4 + if (GetMonData(&gPlayerParty[gSpecialVar_0x8004], MON_DATA_MOVE1 + i)) gScriptResult++; } -void sub_80F9F84(void) +void ScrSpecial_GetPokemonNicknameAndMoveName(void) { - struct Pokemon *party = &gPlayerParty[gSpecialVar_0x8004]; - u16 data = GetMonData(party, gSpecialVar_0x8005 + 13); + struct Pokemon *pkmn = &gPlayerParty[gSpecialVar_0x8004]; + u16 data = GetMonData(pkmn, MON_DATA_MOVE1 + gSpecialVar_0x8005); - GetMonNickname(party, gStringVar1); + GetMonNickname(pkmn, gStringVar1); StringCopy(gStringVar2, gMoveNames[data]); } @@ -431,7 +430,7 @@ void sub_80FA0DC(void) SetMonMoveSlot(&gPlayerParty[gSpecialVar_0x8004], 0, gSpecialVar_0x8005); RemoveMonPPBonus(&gPlayerParty[gSpecialVar_0x8004], gSpecialVar_0x8005); - for(i = gSpecialVar_0x8005; i < 3; i++) + for (i = gSpecialVar_0x8005; i < 3; i++) sub_80F9FDC(&gPlayerParty[gSpecialVar_0x8004], i, i + 1); } @@ -440,6 +439,6 @@ void sub_80FA148(void) struct Pokemon *party = &gPlayerParty[gSpecialVar_0x8004]; gScriptResult = 0; - if(GetMonData(party, MON_DATA_IS_EGG)) + if (GetMonData(party, MON_DATA_IS_EGG)) gScriptResult = 1; } diff --git a/src/misc/unknown_task.c b/src/misc/unknown_task.c index 81b89ef92..5ec7fa6bc 100644 --- a/src/misc/unknown_task.c +++ b/src/misc/unknown_task.c @@ -2,11 +2,12 @@ #include "data2.h" #include "task.h" #include "trig.h" +#include "unknown_task.h" struct UnknownStruct1 { void *src[2]; - void *dest; + volatile void *dest; u32 unkC; void (*unk10)(void); u8 srcBank; @@ -17,14 +18,6 @@ struct UnknownStruct1 u8 filler19[0x7]; }; -struct UnknownStruct2 -{ - void *dest; - u32 control; - u8 unk8; - u8 unk9; -}; - static void sub_80896F4(void); static void sub_8089714(void); @@ -68,7 +61,7 @@ void dp12_8087EA4(void) gUnknown_03004DC0.taskId = 0xFF; } -void sub_80895F8(struct UnknownStruct2 unk) +void sub_80895F8(struct UnknownTaskStruct unk) { if (unk.control == (((DMA_ENABLE | DMA_START_HBLANK | DMA_REPEAT | DMA_DEST_RELOAD) << 16) | 1)) { @@ -214,7 +207,7 @@ u8 sub_8089944(u8 a1, u8 a2, u8 a3, u8 a4, u8 a5, u8 a6, u8 a7) { int i; int offset; - struct UnknownStruct2 unk; + struct UnknownTaskStruct unk; u8 taskId; dp12_8087EA4(); diff --git a/src/pokemon/learn_move.c b/src/pokemon/learn_move.c index 51de68171..33252c66b 100644 --- a/src/pokemon/learn_move.c +++ b/src/pokemon/learn_move.c @@ -6,7 +6,7 @@ #include "menu_cursor.h" #include "palette.h" #include "pokemon.h" -#include "rom4.h" +#include "overworld.h" #include "script.h" #include "songs.h" #include "sound.h" diff --git a/src/pokemon/mail.c b/src/pokemon/mail.c index fb9251a5d..c5dd119e3 100644 --- a/src/pokemon/mail.c +++ b/src/pokemon/mail.c @@ -8,7 +8,7 @@ #include "name_string_util.h" #include "palette.h" #include "pokemon_icon.h" -#include "rom4.h" +#include "overworld.h" #include "sprite.h" #include "string_util.h" #include "strings2.h" diff --git a/src/pokemon/pokeblock_feed.c b/src/pokemon/pokeblock_feed.c index db4db55a7..ccbb391af 100644 --- a/src/pokemon/pokeblock_feed.c +++ b/src/pokemon/pokeblock_feed.c @@ -6,7 +6,7 @@ #include "text.h" #include "text_window.h" #include "menu.h" -#include "rom4.h" +#include "overworld.h" #include "decompress.h" #include "data2.h" #include "sprite.h" diff --git a/src/pokemon/pokedex.c b/src/pokemon/pokedex.c index 6a17a89e0..ffb7f7e95 100644 --- a/src/pokemon/pokedex.c +++ b/src/pokemon/pokedex.c @@ -16,7 +16,7 @@ #include "pokedex_cry_screen.h" #include "pokemon.h" #include "rng.h" -#include "rom4.h" +#include "overworld.h" #include "songs.h" #include "sound.h" #include "species.h" diff --git a/src/pokemon/pokemon_1.c b/src/pokemon/pokemon_1.c index 9c46e54d5..fd7916ee6 100644 --- a/src/pokemon/pokemon_1.c +++ b/src/pokemon/pokemon_1.c @@ -4,7 +4,7 @@ #include "main.h" #include "pokemon.h" #include "rng.h" -#include "rom4.h" +#include "overworld.h" #include "species.h" #include "sprite.h" #include "string_util.h" @@ -69,6 +69,7 @@ void ZeroEnemyPartyMons(void) void CreateMon(struct Pokemon *mon, u16 species, u8 level, u8 fixedIV, u8 hasFixedPersonality, u32 fixedPersonality, u8 otIdType, u32 fixedOtId) { u32 arg; + ZeroMonData(mon); CreateBoxMon(&mon->box, species, level, fixedIV, hasFixedPersonality, fixedPersonality, otIdType, fixedOtId); SetMonData(mon, MON_DATA_LEVEL, &level); diff --git a/src/pokemon/pokemon_3.c b/src/pokemon/pokemon_3.c index 4f7655a34..e51d3187b 100644 --- a/src/pokemon/pokemon_3.c +++ b/src/pokemon/pokemon_3.c @@ -11,7 +11,7 @@ #include "main.h" #include "pokemon.h" #include "rng.h" -#include "rom4.h" +#include "overworld.h" #include "rom_8077ABC.h" #include "rom_8094928.h" #include "rtc.h" diff --git a/src/pokemon/pokemon_menu.c b/src/pokemon/pokemon_menu.c index 821101569..bc5150a16 100644 --- a/src/pokemon/pokemon_menu.c +++ b/src/pokemon/pokemon_menu.c @@ -8,7 +8,7 @@ #include "songs.h" #include "sound.h" #include "main.h" -#include "rom4.h" +#include "overworld.h" #include "menu_helpers.h" #include "pokemon_summary_screen.h" #include "moves.h" @@ -121,32 +121,32 @@ void (*gUnknown_03005CE4)(void); // const data -static const struct MenuAction sPokemonMenuActions[] = -{ - {OtherText_Summary, (void*) PokemonMenu_Summary}, - {OtherText_Switch2, (void*) PokemonMenu_Switch}, - {OtherText_Item, (void*) PokemonMenu_Item}, - {gOtherText_CancelNoTerminator, (void*) PokemonMenu_Cancel}, - {OtherText_Give2, (void*) PokemonMenu_GiveItem}, - {OtherText_Take2, (void*) PokemonMenu_TakeItem}, - {OtherText_Take, (void*) PokemonMenu_TakeMail}, - {OtherText_Mail, (void*) PokemonMenu_Mail}, - {OtherText_Read2, (void*) PokemonMenu_ReadMail}, - {gOtherText_CancelNoTerminator, (void*) PokemonMenu_CancelSubmenu}, - {gMoveNames[MOVE_CUT], (void*) PokemonMenu_FieldMove}, - {gMoveNames[MOVE_FLASH], (void*) PokemonMenu_FieldMove}, - {gMoveNames[MOVE_ROCK_SMASH], (void*) PokemonMenu_FieldMove}, - {gMoveNames[MOVE_STRENGTH], (void*) PokemonMenu_FieldMove}, - {gMoveNames[MOVE_SURF], (void*) PokemonMenu_FieldMove}, - {gMoveNames[MOVE_FLY], (void*) PokemonMenu_FieldMove}, - {gMoveNames[MOVE_DIVE], (void*) PokemonMenu_FieldMove}, - {gMoveNames[MOVE_WATERFALL], (void*) PokemonMenu_FieldMove}, - {gMoveNames[MOVE_TELEPORT], (void*) PokemonMenu_FieldMove}, - {gMoveNames[MOVE_DIG], (void*) PokemonMenu_FieldMove}, - {gMoveNames[MOVE_SECRET_POWER], (void*) PokemonMenu_FieldMove}, - {gMoveNames[MOVE_MILK_DRINK], (void*) PokemonMenu_FieldMove}, - {gMoveNames[MOVE_SOFT_BOILED], (void*) PokemonMenu_FieldMove}, - {gMoveNames[MOVE_SWEET_SCENT], (void*) PokemonMenu_FieldMove}, +static const struct MenuAction2 sPokemonMenuActions[] = +{ + {OtherText_Summary, PokemonMenu_Summary}, + {OtherText_Switch2, PokemonMenu_Switch}, + {OtherText_Item, PokemonMenu_Item}, + {gOtherText_CancelNoTerminator, PokemonMenu_Cancel}, + {OtherText_Give2, PokemonMenu_GiveItem}, + {OtherText_Take2, PokemonMenu_TakeItem}, + {OtherText_Take, PokemonMenu_TakeMail}, + {OtherText_Mail, PokemonMenu_Mail}, + {OtherText_Read2, PokemonMenu_ReadMail}, + {gOtherText_CancelNoTerminator, PokemonMenu_CancelSubmenu}, + {gMoveNames[MOVE_CUT], PokemonMenu_FieldMove}, + {gMoveNames[MOVE_FLASH], PokemonMenu_FieldMove}, + {gMoveNames[MOVE_ROCK_SMASH], PokemonMenu_FieldMove}, + {gMoveNames[MOVE_STRENGTH], PokemonMenu_FieldMove}, + {gMoveNames[MOVE_SURF], PokemonMenu_FieldMove}, + {gMoveNames[MOVE_FLY], PokemonMenu_FieldMove}, + {gMoveNames[MOVE_DIVE], PokemonMenu_FieldMove}, + {gMoveNames[MOVE_WATERFALL], PokemonMenu_FieldMove}, + {gMoveNames[MOVE_TELEPORT], PokemonMenu_FieldMove}, + {gMoveNames[MOVE_DIG], PokemonMenu_FieldMove}, + {gMoveNames[MOVE_SECRET_POWER], PokemonMenu_FieldMove}, + {gMoveNames[MOVE_MILK_DRINK], PokemonMenu_FieldMove}, + {gMoveNames[MOVE_SOFT_BOILED], PokemonMenu_FieldMove}, + {gMoveNames[MOVE_SWEET_SCENT], PokemonMenu_FieldMove}, }; static const u16 sPokeMenuFieldMoves[] = @@ -227,14 +227,14 @@ static void sub_8089A8C(void) } } -static void sub_8089BDC(u8 arg0, u8 arg1, u8 arg2, u8 noOfOptions, const struct MenuAction* menuActions, const u8* order, u8 arg6) +static void sub_8089BDC(u8 arg0, u8 arg1, u8 arg2, u8 noOfOptions, const struct MenuAction2 *menuActions, const u8 *order, u8 arg6) { sub_806D538(5, arg6); MenuDrawTextWindow(arg0, arg1, arg0 + arg2, (noOfOptions * 2) + arg1 + 1); PrintMenuItemsReordered(arg0 + 1, arg1 + 1, noOfOptions, menuActions, order); } -void sub_8089C50(u8 arg0, u8 arg1, u8 arg2, u8 noOfOptions, const struct MenuAction* menuActions, const u8* order) +void sub_8089C50(u8 arg0, u8 arg1, u8 arg2, u8 noOfOptions, const struct MenuAction2 *menuActions, const u8 *order) { sub_8089BDC(arg0, arg1, arg2, noOfOptions, menuActions, order, 1); } @@ -390,7 +390,7 @@ static void sub_808A060(u8 taskID) if (gMain.newKeys & A_BUTTON) { PlaySE(SE_SELECT); - PartyMenuGetPopupMenuFunc(0, &sUnknown_0839F578, (void*) sPokemonMenuActions, sPokeMenuCursorPos)(taskID); + PartyMenuGetPopupMenuFunc(0, &sUnknown_0839F578, (void *)sPokemonMenuActions, sPokeMenuCursorPos)(taskID); } else if (gMain.newKeys & B_BUTTON) { @@ -706,23 +706,24 @@ static void PokemonMenu_CancelSubmenu(u8 taskID) #define IS_SURF(ID)((ID == (POKEMENU_SURF - POKEMENU_FIRST_FIELD_MOVE_ID))) #define IS_FLY(ID)((ID == (POKEMENU_FLY - POKEMENU_FIRST_FIELD_MOVE_ID))) -#define TASK_FIELD_MOVE_ID 11 +#define tFieldMoveId data[11] static void PokemonMenu_FieldMove(u8 taskID) { - s16* taskData = gTasks[taskID].data; + s16* data = gTasks[taskID].data; + HandleDestroyMenuCursors(); - taskData[TASK_FIELD_MOVE_ID] = sPokeMenuOptionsOrder[sPokeMenuCursorPos] - POKEMENU_FIRST_FIELD_MOVE_ID; + tFieldMoveId = sPokeMenuOptionsOrder[sPokeMenuCursorPos] - POKEMENU_FIRST_FIELD_MOVE_ID; if (sub_80F9344() == TRUE) { MenuZeroFillWindowRect(19, 0, 29, 19); - if (IS_SOFTBOILED_MILKDRINK(taskData[TASK_FIELD_MOVE_ID])) + if (IS_SOFTBOILED_MILKDRINK(tFieldMoveId)) sub_806D538(9, 0); else - sub_806D538(sFieldMoveFuncs[taskData[TASK_FIELD_MOVE_ID]].field_1, 0); + sub_806D538(sFieldMoveFuncs[tFieldMoveId].field_1, 0); gTasks[taskID].func = sub_808ABF4; } - else if (taskData[TASK_FIELD_MOVE_ID] <= 7 && FlagGet(BADGE01_GET + taskData[TASK_FIELD_MOVE_ID]) != TRUE) + else if (tFieldMoveId <= 7 && FlagGet(BADGE01_GET + tFieldMoveId) != TRUE) { // can't use a field HM move without a proper badge MenuZeroFillWindowRect(19, 0, 29, 19); @@ -732,10 +733,10 @@ static void PokemonMenu_FieldMove(u8 taskID) } else { - if (sFieldMoveFuncs[taskData[TASK_FIELD_MOVE_ID]].func() == TRUE) + if (sFieldMoveFuncs[tFieldMoveId].func() == TRUE) { sPokeMenuCursorPos = 0; - if (!IS_SOFTBOILED_MILKDRINK(taskData[TASK_FIELD_MOVE_ID])) + if (!IS_SOFTBOILED_MILKDRINK(tFieldMoveId)) { gTasks[taskID].func = sub_808AB34; BeginNormalPaletteFade(-1, 0, 0, 0x10, 0); @@ -746,10 +747,10 @@ static void PokemonMenu_FieldMove(u8 taskID) else { MenuZeroFillWindowRect(19, 0, 29, 19); - if (IS_SURF(taskData[TASK_FIELD_MOVE_ID]) && TestPlayerAvatarFlags(8)) + if (IS_SURF(tFieldMoveId) && TestPlayerAvatarFlags(8)) sub_806D538(8, 0); else - sub_806D538(sFieldMoveFuncs[taskData[TASK_FIELD_MOVE_ID]].field_1, 0); + sub_806D538(sFieldMoveFuncs[tFieldMoveId].field_1, 0); gTasks[taskID].func = sub_808ABF4; } } @@ -768,7 +769,7 @@ static void sub_808AB34(u8 taskID) { if (!gPaletteFade.active) { - if (!IS_FLY(gTasks[taskID].data[TASK_FIELD_MOVE_ID]) || ShouldDoBrailleFlyEffect()) + if (!IS_FLY(gTasks[taskID].tFieldMoveId) || ShouldDoBrailleFlyEffect()) SetMainCallback2(c2_exit_to_overworld_2_switch); else SetMainCallback2(CB2_InitFlyRegionMap); @@ -776,7 +777,9 @@ static void sub_808AB34(u8 taskID) } } -void sub_808AB90(void) +#undef tFieldMoveId + +void FieldCallback_Teleport(void) { pal_fill_black(); CreateTask(sub_808ABA8, 8); @@ -786,7 +789,7 @@ static void sub_808ABA8(u8 taskID) { if (sub_807D770() == TRUE) { - gUnknown_0202FF84[0] = GetMonData(&gPlayerParty[gLastFieldPokeMenuOpened], MON_DATA_SPECIES); + gFieldEffectArguments[0] = GetMonData(&gPlayerParty[gLastFieldPokeMenuOpened], MON_DATA_SPECIES); gUnknown_03005CE4(); DestroyTask(taskID); } @@ -803,7 +806,7 @@ static void sub_808ABF4(u8 taskID) static void sub_808AC2C(void) { - gUnknown_0202FF84[0] = gLastFieldPokeMenuOpened; + gFieldEffectArguments[0] = gLastFieldPokeMenuOpened; FieldEffectStart(FLDEFF_USE_SURF); } @@ -811,7 +814,7 @@ static bool8 SetUpFieldMove_Surf(void) { if (PartyHasMonWithSurf() == TRUE && IsPlayerFacingSurfableFishableWater() == TRUE) { - gFieldCallback = sub_808AB90; + gFieldCallback = FieldCallback_Teleport; gUnknown_03005CE4 = sub_808AC2C; return TRUE; } @@ -821,7 +824,7 @@ static bool8 SetUpFieldMove_Surf(void) static void sub_808AC8C(void) { - gUnknown_0202FF84[0] = gLastFieldPokeMenuOpened; + gFieldEffectArguments[0] = gLastFieldPokeMenuOpened; FieldEffectStart(FLDEFF_USE_FLY); } @@ -829,13 +832,13 @@ static bool8 SetUpFieldMove_Fly(void) { if (ShouldDoBrailleFlyEffect()) { - gFieldCallback = sub_808AB90; + gFieldCallback = FieldCallback_Teleport; gUnknown_03005CE4 = DoBrailleFlyEffect; return TRUE; } - if (is_light_level_1_2_3_or_6(gMapHeader.mapType) == 1) + if (Overworld_MapTypeAllowsTeleportAndFly(gMapHeader.mapType) == TRUE) { - gFieldCallback = sub_808AB90; + gFieldCallback = FieldCallback_Teleport; gUnknown_03005CE4 = sub_808AC8C; return TRUE; } @@ -872,16 +875,16 @@ u16 unref_sub_808AD88(void) static void sub_808ADAC(void) { - gUnknown_0202FF84[0] = gLastFieldPokeMenuOpened; + gFieldEffectArguments[0] = gLastFieldPokeMenuOpened; FieldEffectStart(FLDEFF_USE_DIVE); } static bool8 SetUpFieldMove_Dive(void) { - gUnknown_0202FF84[1] = sub_8068F18(); - if (gUnknown_0202FF84[1]) + gFieldEffectArguments[1] = sub_8068F18(); + if (gFieldEffectArguments[1]) { - gFieldCallback = sub_808AB90; + gFieldCallback = FieldCallback_Teleport; gUnknown_03005CE4 = sub_808ADAC; return TRUE; } @@ -891,7 +894,7 @@ static bool8 SetUpFieldMove_Dive(void) static void sub_808AE08(void) { - gUnknown_0202FF84[0] = gLastFieldPokeMenuOpened; + gFieldEffectArguments[0] = gLastFieldPokeMenuOpened; FieldEffectStart(FLDEFF_USE_WATERFALL); } @@ -902,7 +905,7 @@ static bool8 SetUpFieldMove_Waterfall(void) if (MetatileBehavior_IsWaterfall(MapGridGetMetatileBehaviorAt(x, y)) == TRUE && IsPlayerSurfingNorth() == TRUE) { - gFieldCallback = sub_808AB90; + gFieldCallback = FieldCallback_Teleport; gUnknown_03005CE4 = sub_808AE08; return TRUE; } diff --git a/src/scene/berry_blender.c b/src/scene/berry_blender.c index 029d352df..455aabc45 100644 --- a/src/scene/berry_blender.c +++ b/src/scene/berry_blender.c @@ -12,7 +12,7 @@ #include "string_util.h" #include "link.h" #include "task.h" -#include "rom4.h" +#include "overworld.h" #include "item.h" #include "items.h" #include "rng.h" diff --git a/src/scene/egg_hatch.c b/src/scene/egg_hatch.c index aa3d45250..90d1ee039 100644 --- a/src/scene/egg_hatch.c +++ b/src/scene/egg_hatch.c @@ -6,7 +6,7 @@ #include "task.h" #include "script.h" #include "palette.h" -#include "rom4.h" +#include "overworld.h" #include "main.h" #include "event_data.h" #include "sound.h" diff --git a/src/scene/evolution_scene.c b/src/scene/evolution_scene.c index eeeb04f56..e312b081f 100644 --- a/src/scene/evolution_scene.c +++ b/src/scene/evolution_scene.c @@ -19,7 +19,7 @@ #include "species.h" #include "sound.h" #include "songs.h" -#include "rom4.h" +#include "overworld.h" #include "battle_message.h" #include "pokemon_summary_screen.h" #include "menu_cursor.h" @@ -212,7 +212,7 @@ void EvolutionScene(struct Pokemon* mon, u16 speciesToEvolve, bool8 canStopEvo, gUnknown_030041B8 = 0; InitWindowFromConfig(&gUnknown_03004210, &gWindowConfig_81E6C58); - gBattleTerrain = 9; + gBattleTerrain = BATTLE_TERRAIN_PLAIN; sub_800D6D4(); sub_800DAB8(); @@ -320,7 +320,7 @@ static void CB2_EvolutionSceneLoadGraphics(void) gUnknown_030041B8 = 0; InitWindowFromConfig(&gUnknown_03004210, &gWindowConfig_81E6C58); - gBattleTerrain = 9; + gBattleTerrain = BATTLE_TERRAIN_PLAIN; sub_800D6D4(); sub_800DAB8(); diff --git a/src/scene/hall_of_fame.c b/src/scene/hall_of_fame.c index 78909e289..10c999ef3 100644 --- a/src/scene/hall_of_fame.c +++ b/src/scene/hall_of_fame.c @@ -11,7 +11,7 @@ #include "menu.h" #include "save.h" #include "species.h" -#include "rom4.h" +#include "overworld.h" #include "m4a.h" #include "data2.h" #include "decompress.h" diff --git a/src/scene/new_game.c b/src/scene/new_game.c index 46df14acd..3f9e9f5a1 100644 --- a/src/scene/new_game.c +++ b/src/scene/new_game.c @@ -20,7 +20,7 @@ #include "pokemon_storage_system.h" #include "rng.h" #include "roamer.h" -#include "rom4.h" +#include "overworld.h" #include "rtc.h" #include "script.h" #include "secret_base.h" |