summaryrefslogtreecommitdiff
path: root/src/overworld.c
diff options
context:
space:
mode:
authorGriffinR <griffin.g.richards@gmail.com>2020-08-16 05:59:10 -0400
committerGriffinR <griffin.g.richards@gmail.com>2020-08-16 05:59:10 -0400
commit65bd2faf9460d4e5986c30e54b283d7674d77c55 (patch)
tree250c345d17b8d8f910d327d98f577afddfb3a64a /src/overworld.c
parent2749948eebe65aa8b55738d820e4a0252dd45c1a (diff)
parent25f45ffa8441b0f0a999355c9755782ccb4809dc (diff)
Merge branch 'master' of https://github.com/pret/pokeemerald into doc-contest
Diffstat (limited to 'src/overworld.c')
-rw-r--r--src/overworld.c335
1 files changed, 156 insertions, 179 deletions
diff --git a/src/overworld.c b/src/overworld.c
index 1d9f70430..2d838fc4d 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,58 +84,36 @@
#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 mli4_mapscripts_and_other(void);
+static void DoMapLoadLoop(u8 *state);
+static bool32 LoadMapInStepsLocal(u8 *state, bool32);
+static bool32 LoadMapInStepsLink(u8 *state);
+static bool32 ReturnToFieldLocal(u8 *state);
+static bool32 ReturnToFieldLink(u8 *state);
+static void InitObjectEventsLink(void);
+static void InitObjectEventsLocal(void);
static void InitOverworldGraphicsRegisters(void);
static u8 GetSpriteForLinkedPlayer(u8);
static u16 KeyInterCB_SendNothing(u32 a1);
-static void sub_80867C8(void);
+static void ResetMirageTowerAndSaveBlockPtrs(void);
static void sub_80867D8(void);
-static void sub_8086AE4(void);
-static void sub_80869DC(void);
-static void sub_8086B14(void);
+static void OffsetCameraFocusByLinkPlayerId(void);
+static void SpawnLinkPlayers(void);
static void SetCameraToTrackGuestPlayer(void);
-static void sub_8086988(bool32 arg0);
-static void sub_8086A80(void);
+static void ResumeMap(bool32 arg0);
+static void SetCameraToTrackPlayer(void);
static void sub_8086A68(void);
-static void sub_8086860(void);
+static void InitViewGraphics(void);
static void SetCameraToTrackGuestPlayer_2(void);
static void CreateLinkPlayerSprites(void);
static void ClearAllPlayerKeys(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[] =
@@ -547,11 +520,11 @@ void Overworld_SetObjEventTemplateMovementType(u8 localId, u8 movementType)
}
}
-static void mapdata_load_assets_to_gpu_and_full_redraw(void)
+static void InitMapView(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)
@@ -963,7 +939,7 @@ static u8 GetAdjustedInitialDirection(struct InitialPlayerAvatarState *playerStr
else if (MetatileBehavior_IsEastArrowWarp(metatileBehavior) == TRUE)
return DIR_WEST;
else if ((playerStruct->transitionFlags == PLAYER_AVATAR_FLAG_UNDERWATER && transitionFlags == PLAYER_AVATAR_FLAG_SURFING)
- || (playerStruct->transitionFlags == PLAYER_AVATAR_FLAG_SURFING && transitionFlags == PLAYER_AVATAR_FLAG_UNDERWATER ))
+ || (playerStruct->transitionFlags == PLAYER_AVATAR_FLAG_SURFING && transitionFlags == PLAYER_AVATAR_FLAG_UNDERWATER))
return playerStruct->direction;
else if (MetatileBehavior_IsLadder(metatileBehavior) == TRUE)
return playerStruct->direction;
@@ -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)
{
@@ -1444,7 +1421,7 @@ static void DoCB1_Overworld(u16 newKeys, u16 heldKeys)
{
struct FieldInput inputStruct;
- sub_808B578();
+ UpdatePlayerAvatarTransitionState();
FieldClearPlayerInput(&inputStruct);
FieldGetPlayerInput(&inputStruct, newKeys, heldKeys);
if (!ScriptContext2_IsEnabled())
@@ -1456,7 +1433,7 @@ static void DoCB1_Overworld(u16 newKeys, u16 heldKeys)
}
else
{
- player_step(inputStruct.dpadDirection, newKeys, heldKeys);
+ PlayerStep(inputStruct.dpadDirection, newKeys, heldKeys);
}
}
}
@@ -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);
}
@@ -1746,12 +1723,12 @@ void CB2_ContinueSavedGame(void)
ClearContinueGameWarpStatus();
SetWarpDestinationToContinueGameWarp();
WarpIntoMap();
- sub_80EDB44();
+ TryPutTodaysRivalTrainerOnAir();
SetMainCallback2(CB2_LoadMap);
}
else
{
- sub_80EDB44();
+ TryPutTodaysRivalTrainerOnAir();
gFieldCallback = sub_8086204;
SetMainCallback1(CB1_Overworld);
CB2_ReturnToField();
@@ -1812,7 +1789,7 @@ static void InitCurrentFlashLevelScanlineEffect(void)
}
}
-static bool32 map_loading_iteration_3(u8 *state)
+static bool32 LoadMapInStepsLink(u8 *state)
{
switch (*state)
{
@@ -1820,47 +1797,47 @@ static bool32 map_loading_iteration_3(u8 *state)
InitOverworldBgs();
ScriptContext1_Init();
ScriptContext2_Disable();
- sub_80867C8();
+ ResetMirageTowerAndSaveBlockPtrs();
sub_80867D8();
(*state)++;
break;
case 1:
- mli0_load_map(1);
+ LoadMapFromWarp(TRUE);
(*state)++;
break;
case 2:
- sub_8086988(TRUE);
+ ResumeMap(TRUE);
(*state)++;
break;
case 3:
- sub_8086AE4();
- sub_80869DC();
- sub_8086B14();
+ OffsetCameraFocusByLinkPlayerId();
+ InitObjectEventsLink();
+ SpawnLinkPlayers();
SetCameraToTrackGuestPlayer();
(*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;
@@ -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,51 +1868,51 @@ 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:
- sub_80867C8();
+ ResetMirageTowerAndSaveBlockPtrs();
sub_80867D8();
(*state)++;
break;
case 2:
- sub_8086988(a2);
+ ResumeMap(a2);
(*state)++;
break;
case 3:
- mli4_mapscripts_and_other();
- sub_8086A80();
+ InitObjectEventsLocal();
+ 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,25 +1940,25 @@ 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();
+ ResetMirageTowerAndSaveBlockPtrs();
sub_80867D8();
- sub_8086988(0);
+ ResumeMap(FALSE);
sub_8086A68();
- sub_8086A80();
+ SetCameraToTrackPlayer();
(*state)++;
break;
case 1:
- sub_8086860();
- sub_81D64C0();
+ InitViewGraphics();
+ TryLoadTrainerHillEReaderPalette();
(*state)++;
break;
case 2:
- if (map_post_load_hook_exec())
+ if (RunFieldCallback())
(*state)++;
break;
case 3:
@@ -1991,18 +1968,18 @@ static bool32 sub_8086638(u8 *state)
return FALSE;
}
-static bool32 map_loading_iteration_2_link(u8 *state)
+static bool32 ReturnToFieldLink(u8 *state)
{
switch (*state)
{
case 0:
FieldClearVBlankHBlankCallbacks();
- sub_80867C8();
+ ResetMirageTowerAndSaveBlockPtrs();
sub_80867D8();
(*state)++;
break;
case 1:
- sub_8086988(1);
+ ResumeMap(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,12 +2045,12 @@ 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)
+static void ResetMirageTowerAndSaveBlockPtrs(void)
{
ClearMirageTowerPulseBlend();
MoveSaveBlocks_ResetHeap();
@@ -2090,17 +2067,17 @@ static void sub_80867D8(void)
LoadOam();
}
-static void sub_8086860(void)
+static void InitViewGraphics(void)
{
InitCurrentFlashLevelScanlineEffect();
InitOverworldGraphicsRegisters();
- sub_8197200();
- mapdata_load_assets_to_gpu_and_full_redraw();
+ InitTextBoxGfxAndPrinters();
+ InitMapView();
}
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 ResumeMap(bool32 a1)
{
ResetTasks();
ResetSpriteData();
@@ -2156,7 +2133,7 @@ static void sub_8086988(u32 a1)
TryStartMirageTowerPulseBlendEffect();
}
-static void sub_80869DC(void)
+static void InitObjectEventsLink(void)
{
gTotalCameraPixelOffsetX = 0;
gTotalCameraPixelOffsetY = 0;
@@ -2165,7 +2142,7 @@ static void sub_80869DC(void)
TryRunOnWarpIntoMapScript();
}
-static void mli4_mapscripts_and_other(void)
+static void InitObjectEventsLocal(void)
{
s16 x, y;
struct InitialPlayerAvatarState *player;
@@ -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);
}
@@ -2206,17 +2183,17 @@ static void SetCameraToTrackGuestPlayer_2(void)
InitCameraUpdateCallback(GetSpriteForLinkedPlayer(gLocalLinkPlayerId));
}
-static void sub_8086AE4(void)
+static void OffsetCameraFocusByLinkPlayerId(void)
{
u16 x, y;
GetCameraFocusCoords(&x, &y);
- // This is a hack of some kind; it's undone in sub_8086B14, which is called
+ // This is a hack of some kind; it's undone in SpawnLinkPlayers, which is called
// soon after this function.
- sub_8088B3C(x + gLocalLinkPlayerId, y);
+ SetCameraFocusCoords(x + gLocalLinkPlayerId, y);
}
-static void sub_8086B14(void)
+static void SpawnLinkPlayers(void)
{
u16 i;
u16 x, y;
@@ -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();
@@ -3212,7 +3189,7 @@ static void SpriteCB_LinkPlayer(struct Sprite *sprite)
SetObjectSubpriorityByZCoord(objEvent->previousElevation, sprite, 1);
sprite->oam.priority = ZCoordToPriority(objEvent->previousElevation);
- if (!linkPlayerObjEvent->movementMode != MOVEMENT_MODE_FREE)
+ if (linkPlayerObjEvent->movementMode == MOVEMENT_MODE_FREE)
StartSpriteAnim(sprite, GetFaceDirectionAnimNum(objEvent->range.as_byte));
else
StartSpriteAnimIfDifferent(sprite, GetMoveDirectionAnimNum(objEvent->range.as_byte));