Document remaining overworld

This commit is contained in:
GriffinR 2021-04-06 16:55:33 -04:00
parent 86a9d94ce1
commit 4a1cfbead2
10 changed files with 203 additions and 196 deletions

View File

@ -889,7 +889,7 @@ RecordCorner_EventScript_AlreadyMixed:: @ 82774E0
closemessage
end
EventScript_ConfirmLeaveTradeRoom:: @ 82774EF
EventScript_ConfirmLeaveCableClubRoom:: @ 82774EF
msgbox Text_TerminateLinkConfirmation, MSGBOX_YESNO
compare VAR_RESULT, YES
goto_if_eq EventScript_TerminateLink

View File

@ -2,6 +2,7 @@
#define GUARD_CABLE_CLUB_H
#include "task.h"
#include "constants/cable_club.h"
void CreateTask_EnterCableClubSeat(TaskFunc taskFunc);
u8 CreateTask_ReestablishCableClubLink(void);

View File

@ -28,4 +28,8 @@
#define LINKUP_FAILED_BATTLE_TOWER 11
#define LINKUP_FOREIGN_GAME 12
#define CABLE_SEAT_WAITING 0
#define CABLE_SEAT_SUCCESS 1
#define CABLE_SEAT_FAILED 2
#endif //GUARD_CONSTANTS_CABLE_CLUB_H

View File

@ -607,7 +607,7 @@ 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_ConfirmLeaveCableClubRoom[];
extern const u8 EventScript_TerminateLink[];
#endif // GUARD_EVENT_SCRIPTS_H

View File

@ -1055,14 +1055,4 @@ struct MapPosition
s8 height;
};
struct TradeRoomPlayer
{
u8 playerId;
u8 isLocalPlayer;
u8 c;
u8 facing;
struct MapPosition pos;
u16 field_C;
};
#endif // GUARD_GLOBAL_H

View File

@ -7,17 +7,17 @@
#define LINK_KEY_CODE_DPAD_UP 0x13
#define LINK_KEY_CODE_DPAD_LEFT 0x14
#define LINK_KEY_CODE_DPAD_RIGHT 0x15
#define LINK_KEY_CODE_UNK_2 0x16
#define LINK_KEY_CODE_READY 0x16
#define LINK_KEY_CODE_EXIT_ROOM 0x17
#define LINK_KEY_CODE_START_BUTTON 0x18
#define LINK_KEY_CODE_A_BUTTON 0x19
#define LINK_KEY_CODE_UNK_4 0x1A // I'd guess this is the B button?
#define LINK_KEY_CODE_IDLE 0x1A
// These two are a hack to stop user input until link stuff can be
// resolved.
#define LINK_KEY_CODE_HANDLE_RECV_QUEUE 0x1B
#define LINK_KEY_CODE_HANDLE_SEND_QUEUE 0x1C
#define LINK_KEY_CODE_UNK_7 0x1D
#define LINK_KEY_CODE_EXIT_SEAT 0x1D
#define LINK_KEY_CODE_UNK_8 0x1E
#define MOVEMENT_MODE_FREE 0
@ -143,15 +143,14 @@ void CB2_ReturnToFieldFromMultiplayer(void);
void CB2_ReturnToFieldWithOpenMenu(void);
void CB2_ReturnToFieldContinueScript(void);
void CB2_ReturnToFieldContinueScriptPlayMapMusic(void);
void sub_80861E8(void);
void CB2_ReturnToFieldFadeFromBlack(void);
void CB2_ContinueSavedGame(void);
void ResetAllMultiplayerState(void);
u32 sub_8087214(void);
bool32 sub_808727C(void);
u16 sub_8087288(void);
u16 sub_808729C(void);
u32 GetCableClubPartnersReady(void);
u16 SetInCableClubSeat(void);
u16 SetLinkWaitingForScript(void);
u16 QueueExitLinkRoomKey(void);
u16 sub_80872C4(void);
u16 SetStartedCableClubActivity(void);
bool32 Overworld_LinkRecvQueueLengthMoreThan2(void);
bool32 Overworld_RecvKeysFromLinkIsRunning(void);
bool32 Overworld_SendKeysToLinkIsRunning(void);

View File

@ -1053,29 +1053,31 @@ static void Task_EnterCableClubSeat(u8 taskId)
case 1:
if (IsFieldMessageBoxHidden())
{
sub_8087288();
SetInCableClubSeat();
SetLocalLinkPlayerId(gSpecialVar_0x8005);
task->tState = 2;
}
break;
case 2:
switch (sub_8087214())
switch (GetCableClubPartnersReady())
{
case 0:
case CABLE_SEAT_WAITING:
break;
case 1:
case CABLE_SEAT_SUCCESS:
// Partners linked and ready, switch to relevant link function
HideFieldMessageBox();
task->tState = 0;
sub_80872C4();
SetStartedCableClubActivity();
SwitchTaskToFollowupFunc(taskId);
break;
case 2:
case CABLE_SEAT_FAILED:
task->tState = 3;
break;
}
break;
case 3:
sub_808729C();
// Exit, failure
SetLinkWaitingForScript();
sub_8197AE8(TRUE);
DestroyTask(taskId);
EnableBothScriptContexts();

View File

@ -121,7 +121,7 @@ static void Task_DiplomaFadeOut(u8 taskId)
Free(sDiplomaTilemapPtr);
FreeAllWindowBuffers();
DestroyTask(taskId);
SetMainCallback2(sub_80861E8);
SetMainCallback2(CB2_ReturnToFieldFadeFromBlack);
}
}

View File

@ -68,10 +68,20 @@
#include "constants/trainer_hill.h"
#include "constants/weather.h"
#define PLAYER_TRADING_STATE_IDLE 0x80
#define PLAYER_TRADING_STATE_BUSY 0x81
#define PLAYER_TRADING_STATE_UNK_2 0x82
#define PLAYER_TRADING_STATE_EXITING_ROOM 0x83
struct CableClubPlayer
{
u8 playerId;
u8 isLocalPlayer;
u8 movementMode;
u8 facing;
struct MapPosition pos;
u16 metatileBehavior;
};
#define PLAYER_LINK_STATE_IDLE 0x80
#define PLAYER_LINK_STATE_BUSY 0x81
#define PLAYER_LINK_STATE_READY 0x82
#define PLAYER_LINK_STATE_EXITING_ROOM 0x83
#define FACING_NONE 0
#define FACING_UP 1
@ -92,82 +102,82 @@ 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 SpriteCB_LinkPlayer(struct Sprite *);
static void ChooseAmbientCrySpecies(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 DoMapLoadLoop(u8 *);
static bool32 LoadMapInStepsLocal(u8 *, bool32);
static bool32 LoadMapInStepsLink(u8 *);
static bool32 ReturnToFieldLocal(u8 *);
static bool32 ReturnToFieldLink(u8 *);
static void InitObjectEventsLink(void);
static void InitObjectEventsLocal(void);
static void InitOverworldGraphicsRegisters(void);
static u8 GetSpriteForLinkedPlayer(u8);
static u16 KeyInterCB_SendNothing(u32 a1);
static u16 KeyInterCB_SendNothing(u32);
static void ResetMirageTowerAndSaveBlockPtrs(void);
static void sub_80867D8(void);
static void ResetScreenForMapLoad(void);
static void OffsetCameraFocusByLinkPlayerId(void);
static void SpawnLinkPlayers(void);
static void SetCameraToTrackGuestPlayer(void);
static void ResumeMap(bool32 arg0);
static void ResumeMap(bool32);
static void SetCameraToTrackPlayer(void);
static void InitObjectEventsReturnToField(void);
static void InitViewGraphics(void);
static void SetCameraToTrackGuestPlayer_2(void);
static void CreateLinkPlayerSprites(void);
static void ClearAllPlayerKeys(void);
static void ResetAllTradingStates(void);
static void ResetAllPlayerLinkStates(void);
static void UpdateHeldKeyCode(u16);
static void UpdateAllLinkPlayers(u16*, s32);
static u8 FlipVerticalAndClearForced(u8 a1, u8 a2);
static u8 LinkPlayerDetectCollision(u8 selfObjEventId, u8 a2, s16 x, s16 y);
static void CreateLinkPlayerSprite(u8 linkPlayerId, u8 gameVersion);
static void GetLinkPlayerCoords(u8 linkPlayerId, u16 *x, u16 *y);
static u8 GetLinkPlayerFacingDirection(u8 linkPlayerId);
static u8 GetLinkPlayerElevation(u8 linkPlayerId);
static s32 GetLinkPlayerObjectStepTimer(u8 linkPlayerId);
static u8 GetLinkPlayerIdAt(s16 x, s16 y);
static void SetPlayerFacingDirection(u8 linkPlayerId, u8 a2);
static void ZeroObjectEvent(struct ObjectEvent *objEvent);
static void SpawnLinkPlayerObjectEvent(u8 linkPlayerId, s16 x, s16 y, u8 a4);
static void InitLinkPlayerObjectEventPos(struct ObjectEvent *objEvent, s16 x, s16 y);
static void SetLinkPlayerObjectRange(u8 linkPlayerId, u8 a2);
static void DestroyLinkPlayerObject(u8 linkPlayerId);
static u8 GetSpriteForLinkedPlayer(u8 linkPlayerId);
static u8 FlipVerticalAndClearForced(u8, u8);
static u8 LinkPlayerDetectCollision(u8, u8, s16, s16);
static void CreateLinkPlayerSprite(u8, u8);
static void GetLinkPlayerCoords(u8, u16 *, u16 *);
static u8 GetLinkPlayerFacingDirection(u8);
static u8 GetLinkPlayerElevation(u8);
static s32 GetLinkPlayerObjectStepTimer(u8);
static u8 GetLinkPlayerIdAt(s16, s16);
static void SetPlayerFacingDirection(u8, u8);
static void ZeroObjectEvent(struct ObjectEvent *);
static void SpawnLinkPlayerObjectEvent(u8, s16, s16, u8);
static void InitLinkPlayerObjectEventPos(struct ObjectEvent *, s16, s16);
static void SetLinkPlayerObjectRange(u8, u8);
static void DestroyLinkPlayerObject(u8);
static u8 GetSpriteForLinkedPlayer(u8);
static void RunTerminateLinkScript(void);
static u32 GetLinkSendQueueLength(void);
static void ZeroLinkPlayerObjectEvent(struct LinkPlayerObjectEvent *linkPlayerObjEvent);
static const u8 *TryInteractWithPlayer(struct TradeRoomPlayer *a1);
static u16 GetDirectionForEventScript(const u8 *script);
static void sub_8087510(void);
static void ZeroLinkPlayerObjectEvent(struct LinkPlayerObjectEvent *);
static const u8 *TryInteractWithPlayer(struct CableClubPlayer *);
static u16 GetDirectionForEventScript(const u8 *);
static void InitLinkPlayerQueueScript(void);
static void InitLinkRoomStartMenuScript(void);
static void sub_8087530(const u8 *script);
static void CreateConfirmLeaveTradeRoomPrompt(void);
static void InitMenuBasedScript(const u8 *script);
static void LoadTradeRoomPlayer(s32 linkPlayerId, s32 a2, struct TradeRoomPlayer *a3);
static bool32 sub_8087340(struct TradeRoomPlayer *a1);
static bool32 sub_8087340_2(struct TradeRoomPlayer *a1);
static u8 *TryGetTileEventScript(struct TradeRoomPlayer *a1);
static bool32 PlayerIsAtSouthExit(struct TradeRoomPlayer *a1);
static const u8 *TryInteractWithPlayer(struct TradeRoomPlayer *a1);
static void RunInteractLocalPlayerScript(const u8 *);
static void RunConfirmLeaveCableClubScript(void);
static void InitMenuBasedScript(const u8 *);
static void LoadCableClubPlayer(s32, s32, struct CableClubPlayer *);
static bool32 IsCableClubPlayerUnfrozen(struct CableClubPlayer *);
static bool32 CanCableClubPlayerPressStart(struct CableClubPlayer *);
static u8 *TryGetTileEventScript(struct CableClubPlayer *);
static bool32 PlayerIsAtSouthExit(struct CableClubPlayer *);
static const u8 *TryInteractWithPlayer(struct CableClubPlayer *);
static u16 KeyInterCB_DeferToRecvQueue(u32);
static u16 KeyInterCB_DeferToSendQueue(u32);
static void ResetPlayerHeldKeys(u16 *a1);
static u16 KeyInterCB_SelfIdle(u32 a1);
static u16 KeyInterCB_DeferToEventScript(u32 a1);
static u16 GetDirectionForDpadKey(u16 a1);
static void ResetPlayerHeldKeys(u16 *);
static u16 KeyInterCB_SelfIdle(u32);
static u16 KeyInterCB_DeferToEventScript(u32);
static u16 GetDirectionForDpadKey(u16);
static void CB1_UpdateLinkState(void);
static void SetKeyInterceptCallback(u16 (*func)(u32));
static void SetFieldVBlankCallback(void);
static void FieldClearVBlankHBlankCallbacks(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 u8 GetAdjustedInitialTransitionFlags(struct InitialPlayerAvatarState *, u16, u8);
static u8 GetAdjustedInitialDirection(struct InitialPlayerAvatarState *, u8, u16, u8);
static u16 GetCenterScreenMetatileBehavior(void);
// IWRAM bss vars
static void *sUnusedOverworldCallback;
static u8 sPlayerTradingStates[MAX_LINK_PLAYERS];
static u8 sPlayerLinkStates[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.
@ -311,13 +321,13 @@ static const struct ScanlineEffectParams sFlashEffectParams =
static u8 MovementEventModeCB_Normal(struct LinkPlayerObjectEvent *, struct ObjectEvent *, u8);
static u8 MovementEventModeCB_Ignored(struct LinkPlayerObjectEvent *, struct ObjectEvent *, u8);
static u8 MovementEventModeCB_Normal_2(struct LinkPlayerObjectEvent *, struct ObjectEvent *, u8);
static u8 MovementEventModeCB_Scripted(struct LinkPlayerObjectEvent *, struct ObjectEvent *, u8);
static u8 (*const gLinkPlayerMovementModes[])(struct LinkPlayerObjectEvent *, struct ObjectEvent *, u8) =
{
MovementEventModeCB_Normal, // MOVEMENT_MODE_FREE
MovementEventModeCB_Ignored, // MOVEMENT_MODE_FROZEN
MovementEventModeCB_Normal_2, // MOVEMENT_MODE_SCRIPTED
[MOVEMENT_MODE_FREE] = MovementEventModeCB_Normal,
[MOVEMENT_MODE_FROZEN] = MovementEventModeCB_Ignored,
[MOVEMENT_MODE_SCRIPTED] = MovementEventModeCB_Scripted,
};
static u8 FacingHandler_DoNothing(struct LinkPlayerObjectEvent *, struct ObjectEvent *, u8);
@ -411,7 +421,7 @@ static void Overworld_ResetStateAfterWhiteOut(void)
}
}
static void sub_8084788(void)
static void UpdateMiscOverworldStates(void)
{
FlagClear(FLAG_SYS_SAFARI_MODE);
ChooseAmbientCrySpecies();
@ -1668,14 +1678,14 @@ void CB2_ReturnToFieldContinueScriptPlayMapMusic(void)
CB2_ReturnToField();
}
void sub_80861E8(void)
void CB2_ReturnToFieldFadeFromBlack(void)
{
FieldClearVBlankHBlankCallbacks();
gFieldCallback = FieldCB_WarpExitFadeFromBlack;
CB2_ReturnToField();
}
static void sub_8086204(void)
static void FieldCB_FadeTryShowMapPopup(void)
{
if (SHOW_MAP_NAME_ENABLED && SecretBaseMapPopupEnabled() == TRUE)
ShowMapNamePopup();
@ -1704,7 +1714,7 @@ void CB2_ContinueSavedGame(void)
UnfreezeObjectEvents();
DoTimeBasedEvents();
sub_8084788();
UpdateMiscOverworldStates();
if (gMapHeader.mapLayoutId == LAYOUT_BATTLE_FRONTIER_BATTLE_PYRAMID_FLOOR)
InitBattlePyramidMap(TRUE);
else if (trainerHillMapId != 0)
@ -1727,7 +1737,7 @@ void CB2_ContinueSavedGame(void)
else
{
TryPutTodaysRivalTrainerOnAir();
gFieldCallback = sub_8086204;
gFieldCallback = FieldCB_FadeTryShowMapPopup;
SetMainCallback1(CB1_Overworld);
CB2_ReturnToField();
}
@ -1796,7 +1806,7 @@ static bool32 LoadMapInStepsLink(u8 *state)
ScriptContext1_Init();
ScriptContext2_Disable();
ResetMirageTowerAndSaveBlockPtrs();
sub_80867D8();
ResetScreenForMapLoad();
(*state)++;
break;
case 1:
@ -1877,7 +1887,7 @@ static bool32 LoadMapInStepsLocal(u8 *state, bool32 a2)
break;
case 1:
ResetMirageTowerAndSaveBlockPtrs();
sub_80867D8();
ResetScreenForMapLoad();
(*state)++;
break;
case 2:
@ -1944,7 +1954,7 @@ static bool32 ReturnToFieldLocal(u8 *state)
{
case 0:
ResetMirageTowerAndSaveBlockPtrs();
sub_80867D8();
ResetScreenForMapLoad();
ResumeMap(FALSE);
InitObjectEventsReturnToField();
SetCameraToTrackPlayer();
@ -1973,7 +1983,7 @@ static bool32 ReturnToFieldLink(u8 *state)
case 0:
FieldClearVBlankHBlankCallbacks();
ResetMirageTowerAndSaveBlockPtrs();
sub_80867D8();
ResetScreenForMapLoad();
(*state)++;
break;
case 1:
@ -2054,7 +2064,7 @@ static void ResetMirageTowerAndSaveBlockPtrs(void)
MoveSaveBlocks_ResetHeap();
}
static void sub_80867D8(void)
static void ResetScreenForMapLoad(void)
{
SetGpuReg(REG_OFFSET_DISPCNT, 0);
ScanlineEffect_Stop();
@ -2241,7 +2251,7 @@ static void CB1_UpdateLinkState(void)
void ResetAllMultiplayerState(void)
{
ResetAllTradingStates();
ResetAllPlayerLinkStates();
SetKeyInterceptCallback(KeyInterCB_SelfIdle);
}
@ -2266,57 +2276,57 @@ static void CheckRfuKeepAliveTimer(void)
LinkRfu_FatalError();
}
static void ResetAllTradingStates(void)
static void ResetAllPlayerLinkStates(void)
{
s32 i;
for (i = 0; i < MAX_LINK_PLAYERS; i++)
sPlayerTradingStates[i] = PLAYER_TRADING_STATE_IDLE;
sPlayerLinkStates[i] = PLAYER_LINK_STATE_IDLE;
}
// Returns true if all connected players are in tradingState.
static bool32 AreAllPlayersInTradingState(u16 tradingState)
// Returns true if all connected players are in state.
static bool32 AreAllPlayersInLinkState(u16 state)
{
s32 i;
s32 count = gFieldLinkPlayerCount;
for (i = 0; i < count; i++)
if (sPlayerTradingStates[i] != tradingState)
if (sPlayerLinkStates[i] != state)
return FALSE;
return TRUE;
}
static bool32 IsAnyPlayerInTradingState(u16 tradingState)
static bool32 IsAnyPlayerInLinkState(u16 state)
{
s32 i;
s32 count = gFieldLinkPlayerCount;
for (i = 0; i < count; i++)
if (sPlayerTradingStates[i] == tradingState)
if (sPlayerLinkStates[i] == state)
return TRUE;
return FALSE;
}
static void HandleLinkPlayerKeyInput(u32 playerId, u16 key, struct TradeRoomPlayer *trainer, u16 *forceFacing)
static void HandleLinkPlayerKeyInput(u32 playerId, u16 key, struct CableClubPlayer *trainer, u16 *forceFacing)
{
const u8 *script;
if (sPlayerTradingStates[playerId] == PLAYER_TRADING_STATE_IDLE)
if (sPlayerLinkStates[playerId] == PLAYER_LINK_STATE_IDLE)
{
script = TryGetTileEventScript(trainer);
if (script)
{
*forceFacing = GetDirectionForEventScript(script);
sPlayerTradingStates[playerId] = PLAYER_TRADING_STATE_BUSY;
sPlayerLinkStates[playerId] = PLAYER_LINK_STATE_BUSY;
if (trainer->isLocalPlayer)
{
SetKeyInterceptCallback(KeyInterCB_DeferToEventScript);
sub_8087530(script);
RunInteractLocalPlayerScript(script);
}
return;
}
if (IsAnyPlayerInTradingState(PLAYER_TRADING_STATE_EXITING_ROOM) == TRUE)
if (IsAnyPlayerInLinkState(PLAYER_LINK_STATE_EXITING_ROOM) == TRUE)
{
sPlayerTradingStates[playerId] = PLAYER_TRADING_STATE_BUSY;
sPlayerLinkStates[playerId] = PLAYER_LINK_STATE_BUSY;
if (trainer->isLocalPlayer)
{
SetKeyInterceptCallback(KeyInterCB_DeferToEventScript);
@ -2328,9 +2338,9 @@ static void HandleLinkPlayerKeyInput(u32 playerId, u16 key, struct TradeRoomPlay
switch (key)
{
case LINK_KEY_CODE_START_BUTTON:
if (sub_8087340_2(trainer))
if (CanCableClubPlayerPressStart(trainer))
{
sPlayerTradingStates[playerId] = PLAYER_TRADING_STATE_BUSY;
sPlayerLinkStates[playerId] = PLAYER_LINK_STATE_BUSY;
if (trainer->isLocalPlayer)
{
SetKeyInterceptCallback(KeyInterCB_DeferToEventScript);
@ -2341,11 +2351,11 @@ static void HandleLinkPlayerKeyInput(u32 playerId, u16 key, struct TradeRoomPlay
case LINK_KEY_CODE_DPAD_DOWN:
if (PlayerIsAtSouthExit(trainer) == TRUE)
{
sPlayerTradingStates[playerId] = PLAYER_TRADING_STATE_BUSY;
sPlayerLinkStates[playerId] = PLAYER_LINK_STATE_BUSY;
if (trainer->isLocalPlayer)
{
SetKeyInterceptCallback(KeyInterCB_DeferToEventScript);
CreateConfirmLeaveTradeRoomPrompt();
RunConfirmLeaveCableClubScript();
}
}
break;
@ -2353,7 +2363,7 @@ static void HandleLinkPlayerKeyInput(u32 playerId, u16 key, struct TradeRoomPlay
script = TryInteractWithPlayer(trainer);
if (script)
{
sPlayerTradingStates[playerId] = PLAYER_TRADING_STATE_BUSY;
sPlayerLinkStates[playerId] = PLAYER_LINK_STATE_BUSY;
if (trainer->isLocalPlayer)
{
SetKeyInterceptCallback(KeyInterCB_DeferToEventScript);
@ -2362,24 +2372,24 @@ static void HandleLinkPlayerKeyInput(u32 playerId, u16 key, struct TradeRoomPlay
}
break;
case LINK_KEY_CODE_HANDLE_RECV_QUEUE:
if (sub_8087340(trainer))
if (IsCableClubPlayerUnfrozen(trainer))
{
sPlayerTradingStates[playerId] = PLAYER_TRADING_STATE_BUSY;
sPlayerLinkStates[playerId] = PLAYER_LINK_STATE_BUSY;
if (trainer->isLocalPlayer)
{
SetKeyInterceptCallback(KeyInterCB_DeferToRecvQueue);
sub_8087510();
InitLinkPlayerQueueScript();
}
}
break;
case LINK_KEY_CODE_HANDLE_SEND_QUEUE:
if (sub_8087340(trainer))
if (IsCableClubPlayerUnfrozen(trainer))
{
sPlayerTradingStates[playerId] = PLAYER_TRADING_STATE_BUSY;
sPlayerLinkStates[playerId] = PLAYER_LINK_STATE_BUSY;
if (trainer->isLocalPlayer)
{
SetKeyInterceptCallback(KeyInterCB_DeferToSendQueue);
sub_8087510();
InitLinkPlayerQueueScript();
}
}
break;
@ -2389,35 +2399,35 @@ static void HandleLinkPlayerKeyInput(u32 playerId, u16 key, struct TradeRoomPlay
switch (key)
{
case LINK_KEY_CODE_EXIT_ROOM:
sPlayerTradingStates[playerId] = PLAYER_TRADING_STATE_EXITING_ROOM;
sPlayerLinkStates[playerId] = PLAYER_LINK_STATE_EXITING_ROOM;
break;
case LINK_KEY_CODE_UNK_2:
sPlayerTradingStates[playerId] = PLAYER_TRADING_STATE_UNK_2;
case LINK_KEY_CODE_READY:
sPlayerLinkStates[playerId] = PLAYER_LINK_STATE_READY;
break;
case LINK_KEY_CODE_UNK_4:
sPlayerTradingStates[playerId] = PLAYER_TRADING_STATE_IDLE;
case LINK_KEY_CODE_IDLE:
sPlayerLinkStates[playerId] = PLAYER_LINK_STATE_IDLE;
if (trainer->isLocalPlayer)
SetKeyInterceptCallback(KeyInterCB_SelfIdle);
break;
case LINK_KEY_CODE_UNK_7:
if (sPlayerTradingStates[playerId] == PLAYER_TRADING_STATE_UNK_2)
sPlayerTradingStates[playerId] = PLAYER_TRADING_STATE_BUSY;
case LINK_KEY_CODE_EXIT_SEAT:
if (sPlayerLinkStates[playerId] == PLAYER_LINK_STATE_READY)
sPlayerLinkStates[playerId] = PLAYER_LINK_STATE_BUSY;
break;
}
}
static void UpdateAllLinkPlayers(u16 *keys, s32 selfId)
{
struct TradeRoomPlayer trainer;
struct CableClubPlayer trainer;
s32 i;
for (i = 0; i < MAX_LINK_PLAYERS; i++)
{
u8 key = keys[i];
u16 setFacing = FACING_NONE;
LoadTradeRoomPlayer(i, selfId, &trainer);
LoadCableClubPlayer(i, selfId, &trainer);
HandleLinkPlayerKeyInput(i, key, &trainer, &setFacing);
if (sPlayerTradingStates[i] == PLAYER_TRADING_STATE_IDLE)
if (sPlayerLinkStates[i] == PLAYER_LINK_STATE_IDLE)
setFacing = GetDirectionForDpadKey(key);
SetPlayerFacingDirection(i, setFacing);
}
@ -2504,7 +2514,7 @@ static u16 KeyInterCB_SelfIdle(u32 key)
return LINK_KEY_CODE_HANDLE_SEND_QUEUE;
}
static u16 sub_80870EC(u32 key)
static u16 KeyInterCB_Idle(u32 key)
{
CheckRfuKeepAliveTimer();
return LINK_KEY_CODE_EMPTY;
@ -2521,8 +2531,8 @@ static u16 KeyInterCB_DeferToEventScript(u32 key)
}
else
{
retVal = LINK_KEY_CODE_UNK_4;
SetKeyInterceptCallback(sub_80870EC);
retVal = LINK_KEY_CODE_IDLE;
SetKeyInterceptCallback(KeyInterCB_Idle);
}
return retVal;
}
@ -2537,9 +2547,9 @@ static u16 KeyInterCB_DeferToRecvQueue(u32 key)
}
else
{
retVal = LINK_KEY_CODE_UNK_4;
retVal = LINK_KEY_CODE_IDLE;
ScriptContext2_Disable();
SetKeyInterceptCallback(sub_80870EC);
SetKeyInterceptCallback(KeyInterCB_Idle);
}
return retVal;
}
@ -2554,27 +2564,27 @@ static u16 KeyInterCB_DeferToSendQueue(u32 key)
}
else
{
retVal = LINK_KEY_CODE_UNK_4;
retVal = LINK_KEY_CODE_IDLE;
ScriptContext2_Disable();
SetKeyInterceptCallback(sub_80870EC);
SetKeyInterceptCallback(KeyInterCB_Idle);
}
return retVal;
}
static u16 KeyInterCB_DoNothingAndKeepAlive(u32 key)
static u16 KeyInterCB_ExitingSeat(u32 key)
{
CheckRfuKeepAliveTimer();
return LINK_KEY_CODE_EMPTY;
}
static u16 sub_8087170(u32 keyOrPlayerId)
static u16 KeyInterCB_Ready(u32 keyOrPlayerId)
{
if (sPlayerTradingStates[keyOrPlayerId] == PLAYER_TRADING_STATE_UNK_2)
if (sPlayerLinkStates[keyOrPlayerId] == PLAYER_LINK_STATE_READY)
{
if (JOY_NEW(B_BUTTON))
{
SetKeyInterceptCallback(KeyInterCB_DoNothingAndKeepAlive);
return LINK_KEY_CODE_UNK_7;
SetKeyInterceptCallback(KeyInterCB_ExitingSeat);
return LINK_KEY_CODE_EXIT_SEAT;
}
else
{
@ -2588,10 +2598,10 @@ static u16 sub_8087170(u32 keyOrPlayerId)
}
}
static u16 sub_80871AC(u32 a1)
static u16 KeyInterCB_SetReady(u32 a1)
{
SetKeyInterceptCallback(sub_8087170);
return LINK_KEY_CODE_UNK_2;
SetKeyInterceptCallback(KeyInterCB_Ready);
return LINK_KEY_CODE_READY;
}
static u16 KeyInterCB_SendNothing(u32 key)
@ -2604,9 +2614,9 @@ static u16 KeyInterCB_WaitForPlayersToExit(u32 keyOrPlayerId)
// keyOrPlayerId could be any keycode. This callback does no sanity checking
// on the size of the key. It's assuming that it is being called from
// CB1_UpdateLinkState.
if (sPlayerTradingStates[keyOrPlayerId] != PLAYER_TRADING_STATE_EXITING_ROOM)
if (sPlayerLinkStates[keyOrPlayerId] != PLAYER_LINK_STATE_EXITING_ROOM)
CheckRfuKeepAliveTimer();
if (AreAllPlayersInTradingState(PLAYER_TRADING_STATE_EXITING_ROOM) == TRUE)
if (AreAllPlayersInLinkState(PLAYER_LINK_STATE_EXITING_ROOM) == TRUE)
{
ScriptContext1_SetupScript(EventScript_DoLinkRoomExit);
SetKeyInterceptCallback(KeyInterCB_SendNothing);
@ -2620,37 +2630,38 @@ static u16 KeyInterCB_SendExitRoomKey(u32 key)
return LINK_KEY_CODE_EXIT_ROOM;
}
// Duplicate function.
static u16 KeyInterCB_SendNothing_2(u32 key)
// Identical to KeyInterCB_SendNothing
static u16 KeyInterCB_InLinkActivity(u32 key)
{
return LINK_KEY_CODE_EMPTY;
}
u32 sub_8087214(void)
u32 GetCableClubPartnersReady(void)
{
if (IsAnyPlayerInTradingState(PLAYER_TRADING_STATE_EXITING_ROOM) == TRUE)
return 2;
if (sPlayerKeyInterceptCallback == sub_8087170 && sPlayerTradingStates[gLocalLinkPlayerId] != PLAYER_TRADING_STATE_UNK_2)
return 0;
if (sPlayerKeyInterceptCallback == KeyInterCB_DoNothingAndKeepAlive && sPlayerTradingStates[gLocalLinkPlayerId] == PLAYER_TRADING_STATE_BUSY)
return 2;
if (AreAllPlayersInTradingState(PLAYER_TRADING_STATE_UNK_2) != FALSE)
return 1;
if (IsAnyPlayerInLinkState(PLAYER_LINK_STATE_EXITING_ROOM) == TRUE)
return CABLE_SEAT_FAILED;
if (sPlayerKeyInterceptCallback == KeyInterCB_Ready && sPlayerLinkStates[gLocalLinkPlayerId] != PLAYER_LINK_STATE_READY)
return CABLE_SEAT_WAITING;
if (sPlayerKeyInterceptCallback == KeyInterCB_ExitingSeat && sPlayerLinkStates[gLocalLinkPlayerId] == PLAYER_LINK_STATE_BUSY)
return CABLE_SEAT_FAILED;
if (AreAllPlayersInLinkState(PLAYER_LINK_STATE_READY))
return CABLE_SEAT_SUCCESS;
return CABLE_SEAT_WAITING;
}
// Unused
static bool32 IsAnyPlayerExitingCableClub(void)
{
return IsAnyPlayerInLinkState(PLAYER_LINK_STATE_EXITING_ROOM);
}
u16 SetInCableClubSeat(void)
{
SetKeyInterceptCallback(KeyInterCB_SetReady);
return 0;
}
bool32 sub_808727C(void)
{
return IsAnyPlayerInTradingState(PLAYER_TRADING_STATE_EXITING_ROOM);
}
u16 sub_8087288(void)
{
SetKeyInterceptCallback(sub_80871AC);
return 0;
}
u16 sub_808729C(void)
u16 SetLinkWaitingForScript(void)
{
SetKeyInterceptCallback(KeyInterCB_DeferToEventScript);
return 0;
@ -2664,58 +2675,58 @@ u16 QueueExitLinkRoomKey(void)
return 0;
}
u16 sub_80872C4(void)
u16 SetStartedCableClubActivity(void)
{
SetKeyInterceptCallback(KeyInterCB_SendNothing_2);
SetKeyInterceptCallback(KeyInterCB_InLinkActivity);
return 0;
}
static void LoadTradeRoomPlayer(s32 linkPlayerId, s32 myPlayerId, struct TradeRoomPlayer *trainer)
static void LoadCableClubPlayer(s32 linkPlayerId, s32 myPlayerId, struct CableClubPlayer *trainer)
{
s16 x, y;
trainer->playerId = linkPlayerId;
trainer->isLocalPlayer = (linkPlayerId == myPlayerId) ? 1 : 0;
trainer->c = gLinkPlayerObjectEvents[linkPlayerId].movementMode;
trainer->movementMode = gLinkPlayerObjectEvents[linkPlayerId].movementMode;
trainer->facing = GetLinkPlayerFacingDirection(linkPlayerId);
GetLinkPlayerCoords(linkPlayerId, &x, &y);
trainer->pos.x = x;
trainer->pos.y = y;
trainer->pos.height = GetLinkPlayerElevation(linkPlayerId);
trainer->field_C = MapGridGetMetatileBehaviorAt(x, y);
trainer->metatileBehavior = MapGridGetMetatileBehaviorAt(x, y);
}
static bool32 sub_8087340(struct TradeRoomPlayer *player)
static bool32 IsCableClubPlayerUnfrozen(struct CableClubPlayer *player)
{
u8 v1 = player->c;
if (v1 == MOVEMENT_MODE_SCRIPTED || v1 == MOVEMENT_MODE_FREE)
u8 mode = player->movementMode;
if (mode == MOVEMENT_MODE_SCRIPTED || mode == MOVEMENT_MODE_FREE)
return TRUE;
else
return FALSE;
}
// Duplicate function.
static bool32 sub_8087340_2(struct TradeRoomPlayer *player)
// Identical to IsCableClubPlayerUnfrozen
static bool32 CanCableClubPlayerPressStart(struct CableClubPlayer *player)
{
u8 v1 = player->c;
if (v1 == MOVEMENT_MODE_SCRIPTED || v1 == MOVEMENT_MODE_FREE)
u8 mode = player->movementMode;
if (mode == MOVEMENT_MODE_SCRIPTED || mode == MOVEMENT_MODE_FREE)
return TRUE;
else
return FALSE;
}
static u8 *TryGetTileEventScript(struct TradeRoomPlayer *player)
static u8 *TryGetTileEventScript(struct CableClubPlayer *player)
{
if (player->c != MOVEMENT_MODE_SCRIPTED)
if (player->movementMode != MOVEMENT_MODE_SCRIPTED)
return FACING_NONE;
return GetCoordEventScriptAtMapPosition(&player->pos);
}
static bool32 PlayerIsAtSouthExit(struct TradeRoomPlayer *player)
static bool32 PlayerIsAtSouthExit(struct CableClubPlayer *player)
{
if (player->c != MOVEMENT_MODE_SCRIPTED && player->c != MOVEMENT_MODE_FREE)
if (player->movementMode != MOVEMENT_MODE_SCRIPTED && player->movementMode != MOVEMENT_MODE_FREE)
return FALSE;
else if (!MetatileBehavior_IsSouthArrowWarp(player->field_C))
else if (!MetatileBehavior_IsSouthArrowWarp(player->metatileBehavior))
return FALSE;
else if (player->facing != DIR_SOUTH)
return FALSE;
@ -2723,12 +2734,12 @@ static bool32 PlayerIsAtSouthExit(struct TradeRoomPlayer *player)
return TRUE;
}
static const u8 *TryInteractWithPlayer(struct TradeRoomPlayer *player)
static const u8 *TryInteractWithPlayer(struct CableClubPlayer *player)
{
struct MapPosition otherPlayerPos;
u8 linkPlayerId;
if (player->c != MOVEMENT_MODE_FREE && player->c != MOVEMENT_MODE_SCRIPTED)
if (player->movementMode != MOVEMENT_MODE_FREE && player->movementMode != MOVEMENT_MODE_SCRIPTED)
return FACING_NONE;
otherPlayerPos = player->pos;
@ -2741,7 +2752,7 @@ static const u8 *TryInteractWithPlayer(struct TradeRoomPlayer *player)
{
if (!player->isLocalPlayer)
return CableClub_EventScript_TooBusyToNotice;
else if (sPlayerTradingStates[linkPlayerId] != PLAYER_TRADING_STATE_IDLE)
else if (sPlayerLinkStates[linkPlayerId] != PLAYER_LINK_STATE_IDLE)
return CableClub_EventScript_TooBusyToNotice;
else if (!GetLinkTrainerCardColor(linkPlayerId))
return CableClub_EventScript_ReadTrainerCard;
@ -2749,7 +2760,7 @@ static const u8 *TryInteractWithPlayer(struct TradeRoomPlayer *player)
return CableClub_EventScript_ReadTrainerCardColored;
}
return GetInteractedLinkPlayerScript(&otherPlayerPos, player->field_C, player->facing);
return GetInteractedLinkPlayerScript(&otherPlayerPos, player->metatileBehavior, player->facing);
}
// This returns which direction to force the player to look when one of
@ -2784,7 +2795,7 @@ static u16 GetDirectionForEventScript(const u8 *script)
return FACING_NONE;
}
static void sub_8087510(void)
static void InitLinkPlayerQueueScript(void)
{
ScriptContext2_Enable();
}
@ -2796,17 +2807,17 @@ static void InitLinkRoomStartMenuScript(void)
ScriptContext2_Enable();
}
static void sub_8087530(const u8 *script)
static void RunInteractLocalPlayerScript(const u8 *script)
{
PlaySE(SE_SELECT);
ScriptContext1_SetupScript(script);
ScriptContext2_Enable();
}
static void CreateConfirmLeaveTradeRoomPrompt(void)
static void RunConfirmLeaveCableClubScript(void)
{
PlaySE(SE_WIN_OPEN);
ScriptContext1_SetupScript(EventScript_ConfirmLeaveTradeRoom);
ScriptContext1_SetupScript(EventScript_ConfirmLeaveCableClubRoom);
ScriptContext2_Enable();
}
@ -3058,8 +3069,8 @@ static u8 MovementEventModeCB_Ignored(struct LinkPlayerObjectEvent *linkPlayerOb
return FACING_UP;
}
// Duplicate Function
static u8 MovementEventModeCB_Normal_2(struct LinkPlayerObjectEvent *linkPlayerObjEvent, struct ObjectEvent *objEvent, u8 dir)
// Identical to MovementEventModeCB_Normal
static u8 MovementEventModeCB_Scripted(struct LinkPlayerObjectEvent *linkPlayerObjEvent, struct ObjectEvent *objEvent, u8 dir)
{
return gLinkPlayerFacingHandlers[dir](linkPlayerObjEvent, objEvent, dir);
}

View File

@ -363,7 +363,7 @@ static void Task_RecordMixing_Main(u8 taskId)
{
free(sReceivedRecords);
free(sSentRecord);
sub_808729C();
SetLinkWaitingForScript();
if (gWirelessCommType != 0)
{
CreateTask(Task_ReturnToFieldRecordMixing, 10);