diff options
author | GriffinR <griffin.g.richards@gmail.com> | 2020-06-19 19:58:56 -0400 |
---|---|---|
committer | GriffinR <griffin.g.richards@gmail.com> | 2020-06-23 15:48:53 -0400 |
commit | 18d57a38021a7fee9d8f2131f776946d81c83fbe (patch) | |
tree | 6ec3be0259f311b58eb4788e237b9938c5b83e4b /src/overworld.c | |
parent | 46f4a4bbf7239743c333cd32d30b74a7b3176acc (diff) |
Document some overworld and field effects
Diffstat (limited to 'src/overworld.c')
-rw-r--r-- | src/overworld.c | 265 |
1 files changed, 121 insertions, 144 deletions
diff --git a/src/overworld.c b/src/overworld.c index 8937af8f1..530699f83 100644 --- a/src/overworld.c +++ b/src/overworld.c @@ -7,10 +7,11 @@ #include "cable_club.h" #include "clock.h" #include "event_data.h" +#include "event_object_movement.h" +#include "event_scripts.h" #include "field_camera.h" #include "field_control_avatar.h" #include "field_effect.h" -#include "event_object_movement.h" #include "field_message_box.h" #include "field_player_avatar.h" #include "field_screen_effect.h" @@ -22,6 +23,7 @@ #include "fldeff.h" #include "gpu_regs.h" #include "heal_location.h" +#include "io_reg.h" #include "link.h" #include "link_rfu.h" #include "load_save.h" @@ -82,44 +84,22 @@ #define FACING_FORCED_LEFT 9 #define FACING_FORCED_RIGHT 10 -// event scripts -extern const u8 EventScript_WhiteOut[]; -extern const u8 EventScript_ResetMrBriney[]; -extern const u8 EventScript_DoLinkRoomExit[]; -extern const u8 CableClub_EventScript_TooBusyToNotice[]; -extern const u8 CableClub_EventScript_ReadTrainerCard[]; -extern const u8 CableClub_EventScript_ReadTrainerCardColored[]; -extern const u8 EventScript_BattleColosseum_4P_PlayerSpot0[]; -extern const u8 EventScript_BattleColosseum_4P_PlayerSpot1[]; -extern const u8 EventScript_BattleColosseum_4P_PlayerSpot2[]; -extern const u8 EventScript_BattleColosseum_4P_PlayerSpot3[]; -extern const u8 EventScript_RecordCenter_Spot0[]; -extern const u8 EventScript_RecordCenter_Spot1[]; -extern const u8 EventScript_RecordCenter_Spot2[]; -extern const u8 EventScript_RecordCenter_Spot3[]; -extern const u8 EventScript_BattleColosseum_2P_PlayerSpot0[]; -extern const u8 EventScript_BattleColosseum_2P_PlayerSpot1[]; -extern const u8 EventScript_TradeCenter_Chair1[]; -extern const u8 EventScript_TradeCenter_Chair0[]; -extern const u8 EventScript_ConfirmLeaveTradeRoom[]; -extern const u8 EventScript_TerminateLink[]; - extern const struct MapLayout *const gMapLayouts[]; extern const struct MapHeader *const *const gMapGroups[]; -extern const int gMaxFlashLevel; -extern const u16 gOverworldBackgroundLayerFlags[]; static void Overworld_ResetStateAfterWhiteOut(void); -static void c2_80567AC(void); +static void CB2_ReturnToFieldLocal(void); +static void CB2_ReturnToFieldLink(void); +static void CB2_LoadMapOnReturnToFieldCableClub(void); static void CB2_LoadMap2(void); static void VBlankCB_Field(void); static void SpriteCB_LinkPlayer(struct Sprite *sprite); static void ChooseAmbientCrySpecies(void); -static void do_load_map_stuff_loop(u8 *state); -static bool32 map_loading_iteration_3(u8 *state); -static bool32 sub_8086638(u8 *state); -static bool32 load_map_stuff(u8 *state, u32); -static bool32 map_loading_iteration_2_link(u8 *state); +static void DoMapLoadLoop(u8 *state); +static bool32 LoadMapInStepsLink(u8 *state); +static bool32 ReturnToFieldLocal(u8 *state); +static bool32 LoadMapInStepsLocal(u8 *state, bool32); +static bool32 ReturnToFieldLink(u8 *state); static void mli4_mapscripts_and_other(void); static void InitOverworldGraphicsRegisters(void); static u8 GetSpriteForLinkedPlayer(u8); @@ -131,7 +111,7 @@ static void sub_80869DC(void); static void sub_8086B14(void); static void SetCameraToTrackGuestPlayer(void); static void sub_8086988(bool32 arg0); -static void sub_8086A80(void); +static void SetCameraToTrackPlayer(void); static void sub_8086A68(void); static void sub_8086860(void); static void SetCameraToTrackGuestPlayer_2(void); @@ -155,7 +135,7 @@ static void InitLinkPlayerObjectEventPos(struct ObjectEvent *objEvent, s16 x, s1 static void sub_80877DC(u8 linkPlayerId, u8 a2); static void sub_808780C(u8 linkPlayerId); static u8 GetSpriteForLinkedPlayer(u8 linkPlayerId); -static void sub_8087584(void); +static void RunTerminateLinkScript(void); static u32 GetLinkSendQueueLength(void); static void ZeroLinkPlayerObjectEvent(struct LinkPlayerObjectEvent *linkPlayerObjEvent); static const u8 *TryInteractWithPlayer(struct TradeRoomPlayer *a1); @@ -181,14 +161,14 @@ static void CB1_UpdateLinkState(void); static void SetKeyInterceptCallback(u16 (*func)(u32)); static void SetFieldVBlankCallback(void); static void FieldClearVBlankHBlankCallbacks(void); -static void sub_8085810(void); +static void TransitionMapMusic(void); static u8 GetAdjustedInitialTransitionFlags(struct InitialPlayerAvatarState *playerStruct, u16 a2, u8 a3); static u8 GetAdjustedInitialDirection(struct InitialPlayerAvatarState *playerStruct, u8 a2, u16 a3, u8 a4); static u16 GetCenterScreenMetatileBehavior(void); // IWRAM bss vars static void *sUnusedOverworldCallback; -static u8 sPlayerTradingStates[4]; +static u8 sPlayerTradingStates[MAX_LINK_PLAYERS]; // This callback is called with a player's key code. It then returns an // adjusted key code, effectively intercepting the input before anything // can process it. @@ -208,13 +188,13 @@ u8 gLocalLinkPlayerId; // This is our player id in a multiplayer mode. u8 gFieldLinkPlayerCount; // EWRAM vars -EWRAM_DATA static u8 sUnknown_020322D8 = 0; +EWRAM_DATA static u8 sObjectEventLoadFlag = 0; EWRAM_DATA struct WarpData gLastUsedWarp = {0}; EWRAM_DATA static struct WarpData sWarpDestination = {0}; // new warp position -EWRAM_DATA static struct WarpData gFixedDiveWarp = {0}; -EWRAM_DATA static struct WarpData gFixedHoleWarp = {0}; +EWRAM_DATA static struct WarpData sFixedDiveWarp = {0}; +EWRAM_DATA static struct WarpData sFixedHoleWarp = {0}; EWRAM_DATA static u16 sLastMapSectionId = 0; -EWRAM_DATA static struct InitialPlayerAvatarState gInitialPlayerAvatarState = {0}; +EWRAM_DATA static struct InitialPlayerAvatarState sInitialPlayerAvatarState = {0}; EWRAM_DATA static u16 sAmbientCrySpecies = 0; EWRAM_DATA static bool8 sIsAmbientCryWaterMon = FALSE; EWRAM_DATA struct LinkPlayerObjectEvent gLinkPlayerObjectEvents[4] = {0}; @@ -229,16 +209,9 @@ static const struct WarpData sDummyWarpData = .y = -1, }; -static const u8 sUnusedData[] = +static const u32 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, + 1200, 3600, 1200, 2400, 50, 80, -44, 44 }; const struct UCoords32 gDirectionToVectors[] = @@ -549,9 +522,9 @@ void Overworld_SetObjEventTemplateMovementType(u8 localId, u8 movementType) 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.mapLayout); - apply_map_tileset1_tileset2_palette(gMapHeader.mapLayout); + ResetFieldCamera(); + CopyMapTilesetsToVram(gMapHeader.mapLayout); + LoadMapTilesetPalettes(gMapHeader.mapLayout); DrawWholeMapView(); InitTilesetAnimations(); } @@ -568,14 +541,14 @@ void ApplyCurrentWarp(void) { gLastUsedWarp = gSaveBlock1Ptr->location; gSaveBlock1Ptr->location = sWarpDestination; - gFixedDiveWarp = sDummyWarpData; - gFixedHoleWarp = sDummyWarpData; + sFixedDiveWarp = sDummyWarpData; + sFixedHoleWarp = sDummyWarpData; } static void ClearDiveAndHoleWarps(void) { - gFixedDiveWarp = sDummyWarpData; - gFixedHoleWarp = sDummyWarpData; + sFixedDiveWarp = sDummyWarpData; + sFixedHoleWarp = sDummyWarpData; } static void SetWarpData(struct WarpData *warp, s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y) @@ -717,25 +690,25 @@ void SetWarpDestinationToEscapeWarp(void) void SetFixedDiveWarp(s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y) { - SetWarpData(&gFixedDiveWarp, mapGroup, mapNum, warpId, x, y); + SetWarpData(&sFixedDiveWarp, mapGroup, mapNum, warpId, x, y); } static void SetWarpDestinationToDiveWarp(void) { - sWarpDestination = gFixedDiveWarp; + sWarpDestination = sFixedDiveWarp; } void SetFixedHoleWarp(s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y) { - SetWarpData(&gFixedHoleWarp, mapGroup, mapNum, warpId, x, y); + SetWarpData(&sFixedHoleWarp, mapGroup, mapNum, warpId, x, y); } void SetWarpDestinationToFixedHoleWarp(s16 x, s16 y) { - if (IsDummyWarp(&gFixedHoleWarp) == TRUE) + if (IsDummyWarp(&sFixedHoleWarp) == TRUE) sWarpDestination = gLastUsedWarp; else - SetWarpDestination(gFixedHoleWarp.mapGroup, gFixedHoleWarp.mapNum, -1, x, y); + SetWarpDestination(sFixedHoleWarp.mapGroup, sFixedHoleWarp.mapNum, -1, x, y); } static void SetWarpDestinationToContinueGameWarp(void) @@ -787,7 +760,7 @@ static bool8 SetDiveWarp(u8 dir, u16 x, u16 y) else { RunOnDiveWarpMapScript(); - if (IsDummyWarp(&gFixedDiveWarp)) + if (IsDummyWarp(&sFixedDiveWarp)) return FALSE; SetWarpDestinationToDiveWarp(); } @@ -809,8 +782,10 @@ void LoadMapFromCameraTransition(u8 mapGroup, u8 mapNum) s32 paletteIndex; SetWarpDestination(mapGroup, mapNum, -1, -1, -1); - if (gMapHeader.regionMapSectionId != 0x3A) - sub_8085810(); + + // Dont transition map music between BF Outside West/East + if (gMapHeader.regionMapSectionId != MAPSEC_BATTLE_FRONTIER) + TransitionMapMusic(); ApplyCurrentWarp(); LoadCurrentMapData(); @@ -827,8 +802,8 @@ void LoadMapFromCameraTransition(u8 mapGroup, u8 mapNum) Overworld_ClearSavedMusic(); RunOnTransitionMapScript(); InitMap(); - copy_map_tileset2_to_vram_2(gMapHeader.mapLayout); - apply_map_tileset2_palette(gMapHeader.mapLayout); + CopySecondaryTilesetToVramUsingHeap(gMapHeader.mapLayout); + LoadSecondaryTilesetPalette(gMapHeader.mapLayout); for (paletteIndex = 6; paletteIndex < 13; paletteIndex++) ApplyWeatherGammaShiftToPal(paletteIndex); @@ -840,17 +815,18 @@ void LoadMapFromCameraTransition(u8 mapGroup, u8 mapNum) ResetFieldTasksArgs(); RunOnResumeMapScript(); - if (gMapHeader.regionMapSectionId != MAPSEC_BATTLE_FRONTIER || gMapHeader.regionMapSectionId != sLastMapSectionId) + if (gMapHeader.regionMapSectionId != MAPSEC_BATTLE_FRONTIER + || gMapHeader.regionMapSectionId != sLastMapSectionId) ShowMapNamePopup(); } -static void mli0_load_map(u32 a1) +static void LoadMapFromWarp(bool32 a1) { bool8 isOutdoors; bool8 isIndoors; LoadCurrentMapData(); - if (!(sUnknown_020322D8 & 1)) + if (!(sObjectEventLoadFlag & SKIP_OBJECT_EVENT_LOAD)) { if (gMapHeader.mapLayoutId == LAYOUT_BATTLE_FRONTIER_BATTLE_PYRAMID_FLOOR) LoadBattlePyramidObjectEventTemplates(); @@ -869,7 +845,7 @@ static void mli0_load_map(u32 a1) ResetCyclingRoadChallengeData(); RestartWildEncounterImmunitySteps(); TryUpdateRandomTrainerRematches(gSaveBlock1Ptr->location.mapGroup, gSaveBlock1Ptr->location.mapNum); - if (a1 != 1) + if (a1 != TRUE) DoTimeBasedEvents(); SetSav1WeatherFromCurrMapHeader(); ChooseAmbientCrySpecies(); @@ -887,7 +863,7 @@ static void mli0_load_map(u32 a1) else InitMap(); - if (a1 != 1 && isIndoors) + if (a1 != TRUE && isIndoors) { UpdateTVScreensOnMap(gBackupMapLayout.width, gBackupMapLayout.height); InitSecretBaseAppearance(TRUE); @@ -896,24 +872,24 @@ static void mli0_load_map(u32 a1) void ResetInitialPlayerAvatarState(void) { - gInitialPlayerAvatarState.direction = DIR_SOUTH; - gInitialPlayerAvatarState.transitionFlags = PLAYER_AVATAR_FLAG_ON_FOOT; + sInitialPlayerAvatarState.direction = DIR_SOUTH; + sInitialPlayerAvatarState.transitionFlags = PLAYER_AVATAR_FLAG_ON_FOOT; } void StoreInitialPlayerAvatarState(void) { - gInitialPlayerAvatarState.direction = GetPlayerFacingDirection(); + sInitialPlayerAvatarState.direction = GetPlayerFacingDirection(); if (TestPlayerAvatarFlags(PLAYER_AVATAR_FLAG_MACH_BIKE)) - gInitialPlayerAvatarState.transitionFlags = PLAYER_AVATAR_FLAG_MACH_BIKE; + sInitialPlayerAvatarState.transitionFlags = PLAYER_AVATAR_FLAG_MACH_BIKE; else if (TestPlayerAvatarFlags(PLAYER_AVATAR_FLAG_ACRO_BIKE)) - gInitialPlayerAvatarState.transitionFlags = PLAYER_AVATAR_FLAG_ACRO_BIKE; + sInitialPlayerAvatarState.transitionFlags = PLAYER_AVATAR_FLAG_ACRO_BIKE; else if (TestPlayerAvatarFlags(PLAYER_AVATAR_FLAG_SURFING)) - gInitialPlayerAvatarState.transitionFlags = PLAYER_AVATAR_FLAG_SURFING; + sInitialPlayerAvatarState.transitionFlags = PLAYER_AVATAR_FLAG_SURFING; else if (TestPlayerAvatarFlags(PLAYER_AVATAR_FLAG_UNDERWATER)) - gInitialPlayerAvatarState.transitionFlags = PLAYER_AVATAR_FLAG_UNDERWATER; + sInitialPlayerAvatarState.transitionFlags = PLAYER_AVATAR_FLAG_UNDERWATER; else - gInitialPlayerAvatarState.transitionFlags = PLAYER_AVATAR_FLAG_ON_FOOT; + sInitialPlayerAvatarState.transitionFlags = PLAYER_AVATAR_FLAG_ON_FOOT; } static struct InitialPlayerAvatarState *GetInitialPlayerAvatarState(void) @@ -921,11 +897,11 @@ static struct InitialPlayerAvatarState *GetInitialPlayerAvatarState(void) struct InitialPlayerAvatarState playerStruct; u8 mapType = GetCurrentMapType(); u16 metatileBehavior = GetCenterScreenMetatileBehavior(); - u8 transitionFlags = GetAdjustedInitialTransitionFlags(&gInitialPlayerAvatarState, metatileBehavior, mapType); + u8 transitionFlags = GetAdjustedInitialTransitionFlags(&sInitialPlayerAvatarState, metatileBehavior, mapType); playerStruct.transitionFlags = transitionFlags; - playerStruct.direction = GetAdjustedInitialDirection(&gInitialPlayerAvatarState, transitionFlags, metatileBehavior, mapType); - gInitialPlayerAvatarState = playerStruct; - return &gInitialPlayerAvatarState; + playerStruct.direction = GetAdjustedInitialDirection(&sInitialPlayerAvatarState, transitionFlags, metatileBehavior, mapType); + sInitialPlayerAvatarState = playerStruct; + return &sInitialPlayerAvatarState; } static u8 GetAdjustedInitialTransitionFlags(struct InitialPlayerAvatarState *playerStruct, u16 metatileBehavior, u8 mapType) @@ -1012,14 +988,15 @@ void SetCurrentMapLayout(u16 mapLayoutId) gMapHeader.mapLayout = GetMapLayout(); } -void sub_8085540(u8 var) +void SetObjectEventLoadFlag(u8 flag) { - sUnknown_020322D8 = var; + sObjectEventLoadFlag = flag; } -u8 sub_808554C(void) +// Unused, sObjectEventLoadFlag is read directly +static u8 GetObjectEventLoadFlag(void) { - return sUnknown_020322D8; + return sObjectEventLoadFlag; } static bool16 ShouldLegendaryMusicPlayAtLocation(struct WarpData *warp) @@ -1179,10 +1156,10 @@ void Overworld_SetSavedMusic(u16 songNum) void Overworld_ClearSavedMusic(void) { - gSaveBlock1Ptr->savedMusic = 0; + gSaveBlock1Ptr->savedMusic = MUS_DUMMY; } -static void sub_8085810(void) +static void TransitionMapMusic(void) { if (FlagGet(FLAG_DONT_TRANSITION_MUSIC) != TRUE) { @@ -1477,7 +1454,7 @@ static void OverworldBasic(void) BuildOamBuffer(); UpdatePaletteFade(); UpdateTilesetAnimations(); - do_scheduled_bg_tilemap_copies_to_vram(); + DoScheduledBgTilemapCopiesToVram(); } // This CB2 is used when starting @@ -1507,7 +1484,7 @@ void SetUnusedCallback(void *func) sUnusedOverworldCallback = func; } -static bool8 map_post_load_hook_exec(void) +static bool8 RunFieldCallback(void) { if (gFieldCallback2) { @@ -1546,7 +1523,7 @@ void CB2_NewGame(void) ScriptContext2_Disable(); gFieldCallback = ExecuteTruckSequence; gFieldCallback2 = NULL; - do_load_map_stuff_loop(&gMain.state); + DoMapLoadLoop(&gMain.state); SetFieldVBlankCallback(); SetMainCallback1(CB1_Overworld); SetMainCallback2(CB2_Overworld); @@ -1554,7 +1531,7 @@ void CB2_NewGame(void) void CB2_WhiteOut(void) { - u8 val; + u8 state; if (++gMain.state >= 120) { @@ -1566,8 +1543,8 @@ void CB2_WhiteOut(void) ScriptContext1_Init(); ScriptContext2_Disable(); gFieldCallback = FieldCB_WarpExitFadeFromBlack; - val = 0; - do_load_map_stuff_loop(&val); + state = 0; + DoMapLoadLoop(&state); SetFieldVBlankCallback(); SetMainCallback1(CB1_Overworld); SetMainCallback2(CB2_Overworld); @@ -1586,13 +1563,13 @@ void CB2_LoadMap(void) static void CB2_LoadMap2(void) { - do_load_map_stuff_loop(&gMain.state); + DoMapLoadLoop(&gMain.state); SetFieldVBlankCallback(); SetMainCallback1(CB1_Overworld); SetMainCallback2(CB2_Overworld); } -void sub_8086024(void) +void CB2_ReturnToFieldContestHall(void) { if (!gMain.state) { @@ -1601,7 +1578,7 @@ void sub_8086024(void) ScriptContext2_Disable(); SetMainCallback1(NULL); } - if (load_map_stuff(&gMain.state, 1)) + if (LoadMapInStepsLocal(&gMain.state, TRUE)) { SetFieldVBlankCallback(); SetMainCallback1(CB1_Overworld); @@ -1613,12 +1590,12 @@ void CB2_ReturnToFieldCableClub(void) { FieldClearVBlankHBlankCallbacks(); gFieldCallback = FieldCB_ReturnToFieldWirelessLink; - SetMainCallback2(c2_80567AC); + SetMainCallback2(CB2_LoadMapOnReturnToFieldCableClub); } -static void c2_80567AC(void) +static void CB2_LoadMapOnReturnToFieldCableClub(void) { - if (map_loading_iteration_3(&gMain.state)) + if (LoadMapInStepsLink(&gMain.state)) { SetFieldVBlankCallback(); SetMainCallback1(CB1_UpdateLinkState); @@ -1640,18 +1617,18 @@ void CB2_ReturnToField(void) } } -void CB2_ReturnToFieldLocal(void) +static void CB2_ReturnToFieldLocal(void) { - if (sub_8086638(&gMain.state)) + if (ReturnToFieldLocal(&gMain.state)) { SetFieldVBlankCallback(); SetMainCallback2(CB2_Overworld); } } -void CB2_ReturnToFieldLink(void) +static void CB2_ReturnToFieldLink(void) { - if (!sub_8087598() && map_loading_iteration_2_link(&gMain.state)) + if (!sub_8087598() && ReturnToFieldLink(&gMain.state)) SetMainCallback2(CB2_Overworld); } @@ -1812,7 +1789,7 @@ static void InitCurrentFlashLevelScanlineEffect(void) } } -static bool32 map_loading_iteration_3(u8 *state) +static bool32 LoadMapInStepsLink(u8 *state) { switch (*state) { @@ -1825,7 +1802,7 @@ static bool32 map_loading_iteration_3(u8 *state) (*state)++; break; case 1: - mli0_load_map(1); + LoadMapFromWarp(TRUE); (*state)++; break; case 2: @@ -1842,25 +1819,25 @@ static bool32 map_loading_iteration_3(u8 *state) case 4: InitCurrentFlashLevelScanlineEffect(); InitOverworldGraphicsRegisters(); - sub_8197200(); + InitTextBoxGfxAndPrinters(); (*state)++; break; case 5: - move_tilemap_camera_to_upper_left_corner(); + ResetFieldCamera(); (*state)++; break; case 6: - copy_map_tileset1_to_vram(gMapHeader.mapLayout); + CopyPrimaryTilesetToVram(gMapHeader.mapLayout); (*state)++; break; case 7: - copy_map_tileset2_to_vram(gMapHeader.mapLayout); + CopySecondaryTilesetToVram(gMapHeader.mapLayout); (*state)++; break; case 8: if (FreeTempTileDataBuffersIfPossible() != TRUE) { - apply_map_tileset1_tileset2_palette(gMapHeader.mapLayout); + LoadMapTilesetPalettes(gMapHeader.mapLayout); (*state)++; } break; @@ -1881,7 +1858,7 @@ static bool32 map_loading_iteration_3(u8 *state) (*state)++; break; case 12: - if (map_post_load_hook_exec()) + if (RunFieldCallback()) (*state)++; break; case 13: @@ -1891,13 +1868,13 @@ static bool32 map_loading_iteration_3(u8 *state) return FALSE; } -static bool32 load_map_stuff(u8 *state, u32 a2) +static bool32 LoadMapInStepsLocal(u8 *state, bool32 a2) { switch (*state) { case 0: FieldClearVBlankHBlankCallbacks(); - mli0_load_map(a2); + LoadMapFromWarp(a2); (*state)++; break; case 1: @@ -1911,31 +1888,31 @@ static bool32 load_map_stuff(u8 *state, u32 a2) break; case 3: mli4_mapscripts_and_other(); - sub_8086A80(); + SetCameraToTrackPlayer(); (*state)++; break; case 4: InitCurrentFlashLevelScanlineEffect(); InitOverworldGraphicsRegisters(); - sub_8197200(); + InitTextBoxGfxAndPrinters(); (*state)++; break; case 5: - move_tilemap_camera_to_upper_left_corner(); + ResetFieldCamera(); (*state)++; break; case 6: - copy_map_tileset1_to_vram(gMapHeader.mapLayout); + CopyPrimaryTilesetToVram(gMapHeader.mapLayout); (*state)++; break; case 7: - copy_map_tileset2_to_vram(gMapHeader.mapLayout); + CopySecondaryTilesetToVram(gMapHeader.mapLayout); (*state)++; break; case 8: if (FreeTempTileDataBuffersIfPossible() != TRUE) { - apply_map_tileset1_tileset2_palette(gMapHeader.mapLayout); + LoadMapTilesetPalettes(gMapHeader.mapLayout); (*state)++; } break; @@ -1953,7 +1930,7 @@ static bool32 load_map_stuff(u8 *state, u32 a2) (*state)++; break; case 12: - if (map_post_load_hook_exec()) + if (RunFieldCallback()) (*state)++; break; case 13: @@ -1963,16 +1940,16 @@ static bool32 load_map_stuff(u8 *state, u32 a2) return FALSE; } -static bool32 sub_8086638(u8 *state) +static bool32 ReturnToFieldLocal(u8 *state) { switch (*state) { case 0: sub_80867C8(); sub_80867D8(); - sub_8086988(0); + sub_8086988(FALSE); sub_8086A68(); - sub_8086A80(); + SetCameraToTrackPlayer(); (*state)++; break; case 1: @@ -1981,7 +1958,7 @@ static bool32 sub_8086638(u8 *state) (*state)++; break; case 2: - if (map_post_load_hook_exec()) + if (RunFieldCallback()) (*state)++; break; case 3: @@ -1991,7 +1968,7 @@ static bool32 sub_8086638(u8 *state) return FALSE; } -static bool32 map_loading_iteration_2_link(u8 *state) +static bool32 ReturnToFieldLink(u8 *state) { switch (*state) { @@ -2002,7 +1979,7 @@ static bool32 map_loading_iteration_2_link(u8 *state) (*state)++; break; case 1: - sub_8086988(1); + sub_8086988(TRUE); (*state)++; break; case 2: @@ -2014,25 +1991,25 @@ static bool32 map_loading_iteration_2_link(u8 *state) case 3: InitCurrentFlashLevelScanlineEffect(); InitOverworldGraphicsRegisters(); - sub_8197200(); + InitTextBoxGfxAndPrinters(); (*state)++; break; case 4: - move_tilemap_camera_to_upper_left_corner(); + ResetFieldCamera(); (*state)++; break; case 5: - copy_map_tileset1_to_vram(gMapHeader.mapLayout); + CopyPrimaryTilesetToVram(gMapHeader.mapLayout); (*state)++; break; case 6: - copy_map_tileset2_to_vram(gMapHeader.mapLayout); + CopySecondaryTilesetToVram(gMapHeader.mapLayout); (*state)++; break; case 7: if (FreeTempTileDataBuffersIfPossible() != TRUE) { - apply_map_tileset1_tileset2_palette(gMapHeader.mapLayout); + LoadMapTilesetPalettes(gMapHeader.mapLayout); (*state)++; } break; @@ -2053,7 +2030,7 @@ static bool32 map_loading_iteration_2_link(u8 *state) (*state)++; break; case 12: - if (map_post_load_hook_exec()) + if (RunFieldCallback()) (*state)++; break; case 10: @@ -2068,9 +2045,9 @@ static bool32 map_loading_iteration_2_link(u8 *state) return FALSE; } -static void do_load_map_stuff_loop(u8 *state) +static void DoMapLoadLoop(u8 *state) { - while (!load_map_stuff(state, 0)); + while (!LoadMapInStepsLocal(state, FALSE)); } static void sub_80867C8(void) @@ -2094,13 +2071,13 @@ static void sub_8086860(void) { InitCurrentFlashLevelScanlineEffect(); InitOverworldGraphicsRegisters(); - sub_8197200(); + InitTextBoxGfxAndPrinters(); mapdata_load_assets_to_gpu_and_full_redraw(); } static void InitOverworldGraphicsRegisters(void) { - clear_scheduled_bg_copies_to_vram(); + ClearScheduledBgCopiesToVram(); ResetTempTileDataBuffers(); SetGpuReg(REG_OFFSET_MOSAIC, 0); SetGpuReg(REG_OFFSET_WININ, WININ_WIN0_BG_ALL | WININ_WIN0_OBJ | WININ_WIN1_BG_ALL | WININ_WIN1_OBJ); @@ -2133,7 +2110,7 @@ static void InitOverworldGraphicsRegisters(void) InitFieldMessageBox(); } -static void sub_8086988(u32 a1) +static void sub_8086988(bool32 a1) { ResetTasks(); ResetSpriteData(); @@ -2189,9 +2166,9 @@ static void sub_8086A68(void) RunOnReturnToFieldMapScript(); } -static void sub_8086A80(void) +static void SetCameraToTrackPlayer(void) { - gObjectEvents[gPlayerAvatar.objectEventId].trackedByCamera = 1; + gObjectEvents[gPlayerAvatar.objectEventId].trackedByCamera = TRUE; InitCameraUpdateCallback(gPlayerAvatar.spriteId); } @@ -2294,7 +2271,7 @@ static void CheckRfuKeepAliveTimer(void) static void ResetAllTradingStates(void) { s32 i; - for (i = 0; i < 4; i++) + for (i = 0; i < MAX_LINK_PLAYERS; i++) sPlayerTradingStates[i] = PLAYER_TRADING_STATE_IDLE; } @@ -2345,7 +2322,7 @@ static void HandleLinkPlayerKeyInput(u32 playerId, u16 key, struct TradeRoomPlay if (trainer->isLocalPlayer) { SetKeyInterceptCallback(KeyInterCB_DeferToEventScript); - sub_8087584(); + RunTerminateLinkScript(); } return; } @@ -2763,7 +2740,7 @@ static const u8 *TryInteractWithPlayer(struct TradeRoomPlayer *player) otherPlayerPos.height = 0; linkPlayerId = GetLinkPlayerIdAt(otherPlayerPos.x, otherPlayerPos.y); - if (linkPlayerId != 4) + if (linkPlayerId != MAX_LINK_PLAYERS) { if (!player->isLocalPlayer) return CableClub_EventScript_TooBusyToNotice; @@ -2843,7 +2820,7 @@ static void InitMenuBasedScript(const u8 *script) ScriptContext2_Enable(); } -static void sub_8087584(void) +static void RunTerminateLinkScript(void) { ScriptContext1_SetupScript(EventScript_TerminateLink); ScriptContext2_Enable(); |