Document object lock and some trainer approach

This commit is contained in:
GriffinR 2021-01-26 04:41:13 -05:00
parent 0064333e4a
commit 9e59581220
22 changed files with 209 additions and 155 deletions

View File

@ -1565,7 +1565,7 @@
.byte 0xd8
.endm
.macro cmdD9
.macro lockfortrainer
.byte 0xd9
.endm

View File

@ -217,7 +217,7 @@ gScriptCmdTable:: @ 81DB67C
.4byte ScrCmd_freerotatingtilepuzzle @ 0xd6
.4byte ScrCmd_warpmossdeepgym @ 0xd7
.4byte ScrCmd_selectapproachingtrainer @ 0xd8
.4byte ScrCmd_cmdD9 @ 0xd9
.4byte ScrCmd_lockfortrainer @ 0xd9
.4byte ScrCmd_closebraillemessage @ 0xda
.4byte ScrCmd_messageinstant @ 0xdb
.4byte ScrCmd_fadescreenswapbuffers @ 0xdc

View File

@ -1,10 +1,9 @@
EventScript_271354:: @ 8271354
EventScript_StartTrainerApproach:: @ 8271354
selectapproachingtrainer
cmdD9
EventScript_ShowSecondTrainerIntro:: @ 8271356
special SetUpTrainerEncounterMusic
special EndTrainerApproach
lockfortrainer
EventScript_TrainerApproach:: @ 8271356
special PlayTrainerEncounterMusic
special DoTrainerApproach
waitstate
goto EventScript_ShowTrainerIntroMsg
@ -14,11 +13,12 @@ EventScript_TryDoNormalTrainerBattle:: @ 8271362
applymovement VAR_LAST_TALKED, Movement_RevealTrainer
waitmovement 0
specialvar VAR_RESULT, GetTrainerFlag
compare VAR_RESULT, 0
compare VAR_RESULT, FALSE
goto_if_ne EventScript_NoNormalTrainerBattle
special SetUpTrainerEncounterMusic
special SetUpTrainerMovement
special PlayTrainerEncounterMusic
special SetTrainerFacingDirection
goto EventScript_ShowTrainerIntroMsg
EventScript_NoNormalTrainerBattle:: @ 8271389
gotopostbattlescript
@ -27,27 +27,29 @@ EventScript_TryDoDoubleTrainerBattle:: @ 827138A
faceplayer
call EventScript_RevealTrainer
specialvar VAR_RESULT, GetTrainerFlag
compare VAR_RESULT, 0
compare VAR_RESULT, FALSE
goto_if_ne EventScript_NoDoubleTrainerBattle
special HasEnoughMonsForDoubleBattle
compare VAR_RESULT, PLAYER_HAS_TWO_USABLE_MONS
goto_if_ne EventScript_NotEnoughMonsForDoubleBattle
special SetUpTrainerEncounterMusic
special SetUpTrainerMovement
special PlayTrainerEncounterMusic
special SetTrainerFacingDirection
goto EventScript_ShowTrainerIntroMsg
EventScript_NotEnoughMonsForDoubleBattle:: @ 82713BA
special ShowTrainerCantBattleSpeech
waitmessage
waitbuttonpress
release
end
EventScript_NoDoubleTrainerBattle:: @ 82713C1
gotopostbattlescript
EventScript_DoNoIntroTrainerBattle:: @ 82713C2
applymovement VAR_LAST_TALKED, Movement_RevealTrainer
waitmovement 0
special SetUpTrainerEncounterMusic
special PlayTrainerEncounterMusic
trainerbattlebegin
gotopostbattlescript
@ -56,8 +58,8 @@ EventScript_TryDoRematchBattle:: @ 82713D1
specialvar VAR_RESULT, IsTrainerReadyForRematch
compare VAR_RESULT, FALSE
goto_if_eq EventScript_NoRematchTrainerBattle
special SetUpTrainerEncounterMusic
special SetUpTrainerMovement
special PlayTrainerEncounterMusic
special SetTrainerFacingDirection
special ShowTrainerIntroSpeech
waitmessage
waitbuttonpress
@ -65,6 +67,7 @@ EventScript_TryDoRematchBattle:: @ 82713D1
waitstate
releaseall
end
EventScript_NoRematchTrainerBattle:: @ 82713F7
gotopostbattlescript
@ -75,8 +78,8 @@ EventScript_TryDoDoubleRematchBattle:: @ 82713F8
special HasEnoughMonsForDoubleBattle
compare VAR_RESULT, PLAYER_HAS_TWO_USABLE_MONS
goto_if_ne EventScript_NotEnoughMonsForDoubleRematchBattle
special SetUpTrainerEncounterMusic
special SetUpTrainerMovement
special PlayTrainerEncounterMusic
special SetTrainerFacingDirection
special ShowTrainerIntroSpeech
waitmessage
waitbuttonpress
@ -84,8 +87,10 @@ EventScript_TryDoDoubleRematchBattle:: @ 82713F8
waitstate
releaseall
end
EventScript_NoDoubleRematchTrainerBattle:: @ 8271427
gotopostbattlescript
EventScript_NotEnoughMonsForDoubleRematchBattle:: @ 8271428
special ShowTrainerCantBattleSpeech
waitmessage
@ -108,7 +113,7 @@ EventScript_ShowTrainerIntroMsg:: @ 827143C
waitbuttonpress
special TryPrepareSecondApproachingTrainer
compare VAR_RESULT, TRUE
goto_if_eq EventScript_ShowSecondTrainerIntro
goto_if_eq EventScript_TrainerApproach
goto EventScript_DoTrainerBattle
EventScript_DoTrainerBattle:: @ 8271454

View File

@ -66,8 +66,8 @@ gSpecials:: @ 81DBA64
def_special ShowTrainerIntroSpeech
def_special ShowTrainerCantBattleSpeech
def_special GetTrainerFlag
def_special EndTrainerApproach
def_special SetUpTrainerEncounterMusic
def_special DoTrainerApproach
def_special PlayTrainerEncounterMusic
def_special ShouldTryRematchBattle
def_special IsTrainerReadyForRematch
def_special BattleSetup_StartRematchBattle
@ -324,7 +324,7 @@ gSpecials:: @ 81DBA64
def_special StartGroudonKyogreBattle
def_special BattleSetup_StartLegendaryBattle
def_special StartRegiBattle
def_special SetUpTrainerMovement
def_special SetTrainerFacingDirection
def_special DoSealedChamberShakingEffect2
def_special FoundBlackGlasses
def_special StartDroughtWeatherBlend

View File

@ -37,7 +37,7 @@ void ConfigureAndSetUpOneTrainerBattle(u8 trainerObjEventId, const u8 *trainerSc
void ConfigureTwoTrainersBattle(u8 trainerObjEventId, const u8 *trainerScript);
void SetUpTwoTrainersBattle(void);
bool32 GetTrainerFlagFromScriptPointer(const u8 *data);
void SetUpTrainerMovement(void);
void SetTrainerFacingDirection(void);
u8 GetTrainerBattleMode(void);
bool8 GetTrainerFlag(void);
bool8 HasTrainerBeenFought(u16 trainerId);
@ -49,7 +49,7 @@ void ShowTrainerIntroSpeech(void);
const u8 *BattleSetup_GetScriptAddrAfterBattle(void);
const u8 *BattleSetup_GetTrainerPostBattleScript(void);
void ShowTrainerCantBattleSpeech(void);
void SetUpTrainerEncounterMusic(void);
void PlayTrainerEncounterMusic(void);
const u8 *GetTrainerALoseText(void);
const u8 *GetTrainerBLoseText(void);
const u8 *GetTrainerWonSpeech(void);

View File

@ -71,7 +71,7 @@ void MovePlayerOnBike(u8 direction, u16 newKeys, u16 heldKeys);
void Bike_TryAcroBikeHistoryUpdate(u16 newKeys, u16 heldKeys);
bool8 RS_IsRunningDisallowed(u8 tile);
bool8 IsBikingDisallowedByPlayer(void);
bool8 player_should_look_direction_be_enforced_upon_movement(void);
bool8 IsPlayerNotUsingAcroBikeOnBumpySlope(void);
void GetOnOffBike(u8 transitionFlags);
void BikeClearState(int newDirHistory, int newAbStartHistory);
void Bike_UpdateBikeCounterSpeed(u8 counter);

View File

@ -1,12 +1,12 @@
#ifndef GUARD_EVENT_OBJECT_LOCK_H
#define GUARD_EVENT_OBJECT_LOCK_H
bool8 sub_80983C4(void);
bool8 IsFreezePlayerFinished(void);
void ScriptFreezeObjectEvents(void);
bool8 sub_809847C(void);
bool8 IsFreezeSelectedObjectAndPlayerFinished(void);
void LockSelectedObjectEvent(void);
void sub_8098630(void);
bool8 sub_8098734(void);
void FreezeForApproachingTrainers(void);
bool8 IsFreezeObjectAndPlayerFinished(void);
void ScriptUnfreezeObjectEvents(void);
void UnionRoom_UnlockPlayerAndChatPartner(void);

View File

@ -189,7 +189,7 @@ void DestroyExtraMovementTask(u8);
void UnfreezeObjectEvents(void);
void FreezeObjectEventsExceptOne(u8 objectEventId);
void TurnObjectEventSprite(u8, u8);
void sub_8098074(u8 var1, u8 var2);
void FreezeObjectEventsExceptTwo(u8 objectEventId1, u8 objectEventId2);
void FreezeObjectEvents(void);
bool8 FreezeObjectEvent(struct ObjectEvent *objectEvent);
u8 GetMoveDirectionFastAnimNum(u8);

View File

@ -3,7 +3,7 @@
extern const u8 EventScript_TestSignpostMsg[];
extern const u8 EventScript_TryGetTrainerScript[];
extern const u8 EventScript_271354[];
extern const u8 EventScript_StartTrainerApproach[];
extern const u8 EventScript_DoNoIntroTrainerBattle[];
extern const u8 EventScript_TryDoDoubleTrainerBattle[];
extern const u8 EventScript_TryDoNormalTrainerBattle[];

View File

@ -34,7 +34,7 @@ u8 PlayerGetZCoord(void);
void SetPlayerAvatarTransitionFlags(u16 a);
void sub_808BCE8(void);
void InitPlayerAvatar(s16 a, s16 b, u8 c, u8 d);
void sub_808B864(void);
void PlayerFreeze(void);
void sub_808BCF4(void);
void SetSpinStartFacingDir(u8);
void GetXYCoordsOneStepInFrontOfPlayer(s16 *xPtr, s16 *yPtr);

View File

@ -17,8 +17,8 @@ extern bool8 gTrainerApproachedPlayer;
extern u8 gApproachingTrainerId;
bool8 CheckForTrainersWantingBattle(void);
void sub_80B4578(struct ObjectEvent *var);
void EndTrainerApproach(void);
void SetHiddenTrainerMovement(struct ObjectEvent *var);
void DoTrainerApproach(void);
void TryPrepareSecondApproachingTrainer(void);
u8 FldEff_ExclamationMarkIcon(void);
u8 FldEff_QuestionMarkIcon(void);

View File

@ -923,7 +923,7 @@ static void Script_PrintApprenticeMessage(void)
{
ScriptContext2_Enable();
FreezeObjectEvents();
sub_808B864();
PlayerFreeze();
sub_808BCF4();
DrawDialogueFrame(0, 1);
PrintApprenticeMessage();

View File

@ -1197,7 +1197,7 @@ void ConfigureAndSetUpOneTrainerBattle(u8 trainerObjEventId, const u8 *trainerSc
gSelectedObjectEvent = trainerObjEventId;
gSpecialVar_LastTalked = gObjectEvents[trainerObjEventId].localId;
BattleSetup_ConfigureTrainerBattle(trainerScript + 1);
ScriptContext1_SetupScript(EventScript_271354);
ScriptContext1_SetupScript(EventScript_StartTrainerApproach);
ScriptContext2_Enable();
}
@ -1210,7 +1210,7 @@ void ConfigureTwoTrainersBattle(u8 trainerObjEventId, const u8 *trainerScript)
void SetUpTwoTrainersBattle(void)
{
ScriptContext1_SetupScript(EventScript_271354);
ScriptContext1_SetupScript(EventScript_StartTrainerApproach);
ScriptContext2_Enable();
}
@ -1220,10 +1220,12 @@ bool32 GetTrainerFlagFromScriptPointer(const u8 *data)
return FlagGet(TRAINER_FLAGS_START + flag);
}
void SetUpTrainerMovement(void)
// Set trainer's movement type so they stop and remain facing that direction
// Note: Only for trainers who are spoken to directly
// For trainers who spot the player this is handled by PlayerFaceApproachingTrainer
void SetTrainerFacingDirection(void)
{
struct ObjectEvent *objectEvent = &gObjectEvents[gSelectedObjectEvent];
SetTrainerMovementType(objectEvent, GetTrainerFacingDirectionMovementType(objectEvent->facingDirection));
}
@ -1437,7 +1439,7 @@ void ShowTrainerCantBattleSpeech(void)
ShowFieldMessage(GetTrainerCantBattleSpeech());
}
void SetUpTrainerEncounterMusic(void)
void PlayTrainerEncounterMusic(void)
{
u16 trainerId;
u16 music;

View File

@ -963,9 +963,10 @@ bool8 IsBikingDisallowedByPlayer(void)
return TRUE;
}
bool8 player_should_look_direction_be_enforced_upon_movement(void)
bool8 IsPlayerNotUsingAcroBikeOnBumpySlope(void)
{
if (TestPlayerAvatarFlags(PLAYER_AVATAR_FLAG_ACRO_BIKE) != FALSE && MetatileBehavior_IsBumpySlope(gObjectEvents[gPlayerAvatar.objectEventId].currentMetatileBehavior) != FALSE)
if (TestPlayerAvatarFlags(PLAYER_AVATAR_FLAG_ACRO_BIKE)
&& MetatileBehavior_IsBumpySlope(gObjectEvents[gPlayerAvatar.objectEventId].currentMetatileBehavior))
return FALSE;
else
return TRUE;

View File

@ -16,18 +16,19 @@ bool8 IsPlayerStandingStill(void)
return TRUE;
}
static void sub_80983A4(u8 taskId)
// Freeze player once their movement is finished
static void Task_FreezePlayer(u8 taskId)
{
if (IsPlayerStandingStill())
{
sub_808B864();
PlayerFreeze();
DestroyTask(taskId);
}
}
bool8 sub_80983C4(void)
bool8 IsFreezePlayerFinished(void)
{
if (FuncIsActiveTask(sub_80983A4))
if (FuncIsActiveTask(Task_FreezePlayer))
{
return FALSE;
}
@ -42,30 +43,35 @@ bool8 sub_80983C4(void)
void ScriptFreezeObjectEvents(void)
{
FreezeObjectEvents();
CreateTask(sub_80983A4, 80);
CreateTask(Task_FreezePlayer, 80);
}
static void sub_8098400(u8 taskId)
#define tPlayerFrozen data[0]
#define tObjectFrozen data[1]
#define tObjectId data[2]
// Freeze selected object and player once their movement is finished
static void Task_FreezeSelectedObjectAndPlayer(u8 taskId)
{
struct Task *task = &gTasks[taskId];
if (!task->data[0] && IsPlayerStandingStill() == TRUE)
if (!task->tPlayerFrozen && IsPlayerStandingStill() == TRUE)
{
sub_808B864();
task->data[0] = 1;
PlayerFreeze();
task->tPlayerFrozen = TRUE;
}
if (!task->data[1] && !gObjectEvents[gSelectedObjectEvent].singleMovementActive)
if (!task->tObjectFrozen && !gObjectEvents[gSelectedObjectEvent].singleMovementActive)
{
FreezeObjectEvent(&gObjectEvents[gSelectedObjectEvent]);
task->data[1] = 1;
task->tObjectFrozen = TRUE;
}
if (task->data[0] && task->data[1])
if (task->tPlayerFrozen && task->tObjectFrozen)
DestroyTask(taskId);
}
bool8 sub_809847C(void)
bool8 IsFreezeSelectedObjectAndPlayerFinished(void)
{
if (FuncIsActiveTask(sub_8098400))
if (FuncIsActiveTask(Task_FreezeSelectedObjectAndPlayer))
{
return FALSE;
}
@ -80,11 +86,11 @@ void LockSelectedObjectEvent(void)
{
u8 taskId;
FreezeObjectEventsExceptOne(gSelectedObjectEvent);
taskId = CreateTask(sub_8098400, 80);
taskId = CreateTask(Task_FreezeSelectedObjectAndPlayer, 80);
if (!gObjectEvents[gSelectedObjectEvent].singleMovementActive)
{
FreezeObjectEvent(&gObjectEvents[gSelectedObjectEvent]);
gTasks[taskId].data[1] = 1;
gTasks[taskId].tObjectFrozen = TRUE;
}
}
@ -118,64 +124,71 @@ void Script_ClearHeldMovement(void)
ObjectEventClearHeldMovementIfActive(&gObjectEvents[gSelectedObjectEvent]);
}
static void sub_80985BC(u8 taskId)
// Freeze designated object and player once their movement is finished
static void Task_FreezeObjectAndPlayer(u8 taskId)
{
struct Task *task = &gTasks[taskId];
u8 objectEventId = task->data[2];
u8 objectEventId = task->tObjectId;
if (!task->data[0] && IsPlayerStandingStill() == TRUE)
if (!task->tPlayerFrozen && IsPlayerStandingStill() == TRUE)
{
sub_808B864();
task->data[0] = 1;
PlayerFreeze();
task->tPlayerFrozen = TRUE;
}
if (!task->data[1] && !gObjectEvents[objectEventId].singleMovementActive)
if (!task->tObjectFrozen && !gObjectEvents[objectEventId].singleMovementActive)
{
FreezeObjectEvent(&gObjectEvents[objectEventId]);
task->data[1] = 1;
task->tObjectFrozen = TRUE;
}
if (task->data[0] && task->data[1])
if (task->tPlayerFrozen && task->tObjectFrozen)
DestroyTask(taskId);
}
void sub_8098630(void)
void FreezeForApproachingTrainers(void)
{
u8 trainerObjectId1, trainerObjectId2, taskId;
trainerObjectId1 = GetChosenApproachingTrainerObjectEventId(0);
if(gNoOfApproachingTrainers == 2)
if (gNoOfApproachingTrainers == 2)
{
// Get second trainer, freeze all other objects
trainerObjectId2 = GetChosenApproachingTrainerObjectEventId(1);
sub_8098074(trainerObjectId1, trainerObjectId2);
taskId = CreateTask(sub_80985BC, 80);
gTasks[taskId].data[2] = trainerObjectId1;
if(!gObjectEvents[trainerObjectId1].singleMovementActive)
FreezeObjectEventsExceptTwo(trainerObjectId1, trainerObjectId2);
// Start task to freeze trainer 1 (and player) after movement
taskId = CreateTask(Task_FreezeObjectAndPlayer, 80);
gTasks[taskId].tObjectId = trainerObjectId1;
if (!gObjectEvents[trainerObjectId1].singleMovementActive)
{
FreezeObjectEvent(&gObjectEvents[trainerObjectId1]);
gTasks[taskId].data[1] = 1;
gTasks[taskId].tObjectFrozen = TRUE;
}
taskId = CreateTask(sub_80985BC, 81);
gTasks[taskId].data[2] = trainerObjectId2;
if(!gObjectEvents[trainerObjectId2].singleMovementActive)
// Start task to freeze trainer 2 after movement
taskId = CreateTask(Task_FreezeObjectAndPlayer, 81);
gTasks[taskId].tObjectId = trainerObjectId2;
if (!gObjectEvents[trainerObjectId2].singleMovementActive)
{
FreezeObjectEvent(&gObjectEvents[trainerObjectId2]);
gTasks[taskId].data[1] = 1;
gTasks[taskId].tObjectFrozen = TRUE;
}
}
else
{
FreezeObjectEventsExceptOne(trainerObjectId1);
taskId = CreateTask(sub_80985BC, 80);
gTasks[taskId].data[2] = trainerObjectId1;
if(!gObjectEvents[trainerObjectId1].singleMovementActive)
taskId = CreateTask(Task_FreezeObjectAndPlayer, 80);
gTasks[taskId].tObjectId = trainerObjectId1;
if (!gObjectEvents[trainerObjectId1].singleMovementActive)
{
FreezeObjectEvent(&gObjectEvents[trainerObjectId1]);
gTasks[taskId].data[1] = 1;
gTasks[taskId].tObjectFrozen = TRUE;
}
}
}
bool8 sub_8098734(void)
bool8 IsFreezeObjectAndPlayerFinished(void)
{
if (FuncIsActiveTask(sub_80985BC))
if (FuncIsActiveTask(Task_FreezeObjectAndPlayer))
{
return FALSE;
}
@ -185,3 +198,7 @@ bool8 sub_8098734(void)
return TRUE;
}
}
#undef tPlayerFrozen
#undef tObjectFrozen
#undef tObjectId

View File

@ -6579,7 +6579,7 @@ bool8 MovementAction_RevealTrainer_Step0(struct ObjectEvent *objectEvent, struct
{
if (objectEvent->movementType == MOVEMENT_TYPE_HIDDEN)
{
sub_80B4578(objectEvent);
SetHiddenTrainerMovement(objectEvent);
return FALSE;
}
if (objectEvent->movementType != MOVEMENT_TYPE_TREE_DISGUISE && objectEvent->movementType != MOVEMENT_TYPE_MOUNTAIN_DISGUISE)
@ -8971,13 +8971,14 @@ void DestroyExtraMovementTask(u8 taskId)
DestroyTask(taskId);
}
void sub_8098074(u8 var1, u8 var2)
// Used to freeze other objects except two trainers approaching for battle
void FreezeObjectEventsExceptTwo(u8 objectEventId1, u8 objectEventId2)
{
u8 i;
for(i = 0; i < OBJECT_EVENTS_COUNT; i++)
{
if(i != var1 && i != var2 &&
if(i != objectEventId1 && i != objectEventId2 &&
gObjectEvents[i].active && i != gPlayerAvatar.objectEventId)
FreezeObjectEvent(&gObjectEvents[i]);
}

View File

@ -96,7 +96,7 @@ static void PlayerNotOnBikeCollideWithFarawayIslandMew(u8);
static void PlayCollisionSoundIfNotFacingWarp(u8 a);
static void sub_808C280(struct ObjectEvent *);
static void HideShowWarpArrow(struct ObjectEvent *);
static void StartStrengthAnim(u8, u8);
static void Task_PushBoulder(u8 taskId);
@ -323,7 +323,7 @@ void PlayerStep(u8 direction, u16 newKeys, u16 heldKeys)
{
struct ObjectEvent *playerObjEvent = &gObjectEvents[gPlayerAvatar.objectEventId];
sub_808C280(playerObjEvent);
HideShowWarpArrow(playerObjEvent);
if (gPlayerAvatar.preventStep == FALSE)
{
Bike_TryAcroBikeHistoryUpdate(newKeys, heldKeys);
@ -940,9 +940,9 @@ u8 PlayerGetCopyableMovement(void)
return gObjectEvents[gPlayerAvatar.objectEventId].playerCopyableMovement;
}
static void sub_808B6BC(u8 a)
static void PlayerForceSetHeldMovement(u8 movementActionId)
{
ObjectEventForceSetHeldMovement(&gObjectEvents[gPlayerAvatar.objectEventId], a);
ObjectEventForceSetHeldMovement(&gObjectEvents[gPlayerAvatar.objectEventId], movementActionId);
}
void PlayerSetAnimId(u8 movementActionId, u8 copyableMovement)
@ -1020,12 +1020,13 @@ void PlayerJumpLedge(u8 direction)
PlayerSetAnimId(GetJump2MovementAction(direction), 8);
}
void sub_808B864(void)
// Stop player on current facing direction once they're done moving and if they're not currently Acro Biking on bumpy slope
void PlayerFreeze(void)
{
if (gPlayerAvatar.tileTransitionState == T_TILE_CENTER || gPlayerAvatar.tileTransitionState == T_NOT_MOVING)
{
if (player_should_look_direction_be_enforced_upon_movement())
sub_808B6BC(GetFaceDirectionMovementAction(gObjectEvents[gPlayerAvatar.objectEventId].facingDirection));
if (IsPlayerNotUsingAcroBikeOnBumpySlope())
PlayerForceSetHeldMovement(GetFaceDirectionMovementAction(gObjectEvents[gPlayerAvatar.objectEventId].facingDirection));
}
}
@ -1424,7 +1425,7 @@ void SetPlayerAvatarWatering(u8 direction)
StartSpriteAnim(&gSprites[gPlayerAvatar.spriteId], GetFaceDirectionAnimNum(direction));
}
static void sub_808C280(struct ObjectEvent *objectEvent)
static void HideShowWarpArrow(struct ObjectEvent *objectEvent)
{
s16 x;
s16 y;
@ -1435,6 +1436,7 @@ static void sub_808C280(struct ObjectEvent *objectEvent)
{
if (sArrowWarpMetatileBehaviorChecks2[x](metatileBehavior) && direction == objectEvent->movementDirection)
{
// Show warp arrow if applicable
x = objectEvent->currentCoords.x;
y = objectEvent->currentCoords.y;
MoveCoords(direction, &x, &y);

View File

@ -1971,7 +1971,7 @@ bool8 UseRegisteredKeyItemOnField(void)
{
ScriptContext2_Enable();
FreezeObjectEvents();
sub_808B864();
PlayerFreeze();
sub_808BCF4();
gSpecialVar_ItemId = gSaveBlock1Ptr->registeredItem;
taskId = CreateTask(ItemId_GetFieldFunc(gSaveBlock1Ptr->registeredItem), 8);

View File

@ -1114,7 +1114,7 @@ static void StartMatchCall(void)
{
ScriptContext2_Enable();
FreezeObjectEvents();
sub_808B864();
PlayerFreeze();
sub_808BCF4();
}

View File

@ -1212,7 +1212,7 @@ bool8 ScrCmd_lockall(struct ScriptContext *ctx)
else
{
ScriptFreezeObjectEvents();
SetupNativeScript(ctx, sub_80983C4);
SetupNativeScript(ctx, IsFreezePlayerFinished);
return TRUE;
}
}
@ -1228,12 +1228,12 @@ bool8 ScrCmd_lock(struct ScriptContext *ctx)
if (gObjectEvents[gSelectedObjectEvent].active)
{
LockSelectedObjectEvent();
SetupNativeScript(ctx, sub_809847C);
SetupNativeScript(ctx, IsFreezeSelectedObjectAndPlayerFinished);
}
else
{
ScriptFreezeObjectEvents();
SetupNativeScript(ctx, sub_80983C4);
SetupNativeScript(ctx, IsFreezePlayerFinished);
}
return TRUE;
}
@ -2190,7 +2190,7 @@ bool8 ScrCmd_selectapproachingtrainer(struct ScriptContext *ctx)
return FALSE;
}
bool8 ScrCmd_cmdD9(struct ScriptContext *ctx)
bool8 ScrCmd_lockfortrainer(struct ScriptContext *ctx)
{
if (IsUpdateLinkStateCBActive())
{
@ -2200,8 +2200,8 @@ bool8 ScrCmd_cmdD9(struct ScriptContext *ctx)
{
if (gObjectEvents[gSelectedObjectEvent].active)
{
sub_8098630();
SetupNativeScript(ctx, sub_8098734);
FreezeForApproachingTrainers();
SetupNativeScript(ctx, IsFreezeObjectAndPlayerFinished);
}
return TRUE;
}

View File

@ -541,7 +541,7 @@ void ShowStartMenu(void)
if (!IsUpdateLinkStateCBActive())
{
FreezeObjectEvents();
sub_808B864();
PlayerFreeze();
sub_808BCF4();
}
CreateStartMenuTask(Task_ShowStartMenu);

View File

@ -23,9 +23,9 @@
static u8 CheckTrainer(u8 objectEventId);
static u8 GetTrainerApproachDistance(struct ObjectEvent *trainerObj);
static u8 CheckPathBetweenTrainerAndPlayer(struct ObjectEvent *trainerObj, u8 approachDistance, u8 direction);
static void TrainerApproachPlayer(struct ObjectEvent *trainerObj, u8 range);
static void InitTrainerApproachTask(struct ObjectEvent *trainerObj, u8 range);
static void Task_RunTrainerSeeFuncList(u8 taskId);
static void Task_DestroyTrainerApproachTask(u8 taskId);
static void Task_EndTrainerApproach(u8 taskId);
static void SetIconSpriteData(struct Sprite *sprite, u16 fldEffId, u8 spriteAnimNum);
static u8 GetTrainerApproachDistanceSouth(struct ObjectEvent *trainerObj, s16 range, s16 x, s16 y);
@ -33,7 +33,7 @@ static u8 GetTrainerApproachDistanceNorth(struct ObjectEvent *trainerObj, s16 ra
static u8 GetTrainerApproachDistanceWest(struct ObjectEvent *trainerObj, s16 range, s16 x, s16 y);
static u8 GetTrainerApproachDistanceEast(struct ObjectEvent *trainerObj, s16 range, s16 x, s16 y);
static bool8 sub_80B4178(u8 taskId, struct Task *task, struct ObjectEvent *trainerObj);
static bool8 TrainerSeeIdle(u8 taskId, struct Task *task, struct ObjectEvent *trainerObj);
static bool8 TrainerExclamationMark(u8 taskId, struct Task *task, struct ObjectEvent *trainerObj);
static bool8 WaitTrainerExclamationMark(u8 taskId, struct Task *task, struct ObjectEvent *trainerObj);
static bool8 TrainerMoveToPlayer(u8 taskId, struct Task *task, struct ObjectEvent *trainerObj);
@ -71,20 +71,35 @@ static u8 (*const sDirectionalApproachDistanceFuncs[])(struct ObjectEvent *train
GetTrainerApproachDistanceEast,
};
enum {
TRSEE_NONE,
TRSEE_EXCLAMATION,
TRSEE_EXCLAMATION_WAIT,
TRSEE_MOVE_TO_PLAYER,
TRSEE_PLAYER_FACE,
TRSEE_PLAYER_FACE_WAIT,
TRSEE_REVEAL_DISGUISE,
TRSEE_REVEAL_DISGUISE_WAIT,
TRSEE_REVEAL_HIDDEN,
TRSEE_HIDDEN_POP_OUT,
TRSEE_HIDDEN_JUMP,
TRSEE_REVEAL_HIDDEN_WAIT,
};
static bool8 (*const sTrainerSeeFuncList[])(u8 taskId, struct Task *task, struct ObjectEvent *trainerObj) =
{
sub_80B4178,
TrainerExclamationMark,
WaitTrainerExclamationMark,
TrainerMoveToPlayer,
PlayerFaceApproachingTrainer,
WaitPlayerFaceApproachingTrainer,
RevealDisguisedTrainer,
WaitRevealDisguisedTrainer,
RevealHiddenTrainer,
PopOutOfAshHiddenTrainer,
JumpInPlaceHiddenTrainer,
WaitRevealHiddenTrainer,
[TRSEE_NONE] = TrainerSeeIdle,
[TRSEE_EXCLAMATION] = TrainerExclamationMark,
[TRSEE_EXCLAMATION_WAIT] = WaitTrainerExclamationMark,
[TRSEE_MOVE_TO_PLAYER] = TrainerMoveToPlayer,
[TRSEE_PLAYER_FACE] = PlayerFaceApproachingTrainer,
[TRSEE_PLAYER_FACE_WAIT] = WaitPlayerFaceApproachingTrainer,
[TRSEE_REVEAL_DISGUISE] = RevealDisguisedTrainer,
[TRSEE_REVEAL_DISGUISE_WAIT] = WaitRevealDisguisedTrainer,
[TRSEE_REVEAL_HIDDEN] = RevealHiddenTrainer,
[TRSEE_HIDDEN_POP_OUT] = PopOutOfAshHiddenTrainer,
[TRSEE_HIDDEN_JUMP] = JumpInPlaceHiddenTrainer,
[TRSEE_REVEAL_HIDDEN_WAIT] = WaitRevealHiddenTrainer,
};
static bool8 (*const sTrainerSeeFuncList2[])(u8 taskId, struct Task *task, struct ObjectEvent *trainerObj) =
@ -233,7 +248,7 @@ bool8 CheckForTrainersWantingBattle(void)
static u8 CheckTrainer(u8 objectEventId)
{
const u8 *scriptPtr;
u8 ret = 1;
u8 numTrainers = 1;
u8 approachDistance;
if (InTrainerHill() == TRUE)
@ -268,16 +283,16 @@ static u8 CheckTrainer(u8 objectEventId)
if (GetMonsStateToDoubles_2() != 0)
return 0;
ret = 2;
numTrainers = 2;
}
gApproachingTrainers[gNoOfApproachingTrainers].objectEventId = objectEventId;
gApproachingTrainers[gNoOfApproachingTrainers].trainerScriptPtr = scriptPtr;
gApproachingTrainers[gNoOfApproachingTrainers].radius = approachDistance;
TrainerApproachPlayer(&gObjectEvents[objectEventId], approachDistance - 1);
InitTrainerApproachTask(&gObjectEvents[objectEventId], approachDistance - 1);
gNoOfApproachingTrainers++;
return ret;
return numTrainers;
}
return 0;
@ -357,8 +372,7 @@ static u8 GetTrainerApproachDistanceEast(struct ObjectEvent *trainerObj, s16 ran
static u8 CheckPathBetweenTrainerAndPlayer(struct ObjectEvent *trainerObj, u8 approachDistance, u8 direction)
{
s16 x, y;
u8 unk19_temp;
u8 unk19b_temp;
u8 rangeX, rangeY;
u8 i;
u8 collision;
@ -376,17 +390,16 @@ static u8 CheckPathBetweenTrainerAndPlayer(struct ObjectEvent *trainerObj, u8 ap
return 0;
}
// preserve mapobj_unk_19 before clearing.
unk19_temp = trainerObj->rangeX;
unk19b_temp = trainerObj->rangeY;
rangeX = trainerObj->rangeX;
rangeY = trainerObj->rangeY;
trainerObj->rangeX = 0;
trainerObj->rangeY = 0;
collision = GetCollisionAtCoords(trainerObj, x, y, direction);
trainerObj->rangeX = unk19_temp;
trainerObj->rangeY = unk19b_temp;
if (collision == 4)
trainerObj->rangeX = rangeX;
trainerObj->rangeY = rangeY;
if (collision == COLLISION_OBJECT_EVENT)
return approachDistance;
return 0;
@ -397,7 +410,7 @@ static u8 CheckPathBetweenTrainerAndPlayer(struct ObjectEvent *trainerObj, u8 ap
#define tOutOfAshSpriteId data[4]
#define tTrainerObjectEventId data[7]
static void TrainerApproachPlayer(struct ObjectEvent *trainerObj, u8 range)
static void InitTrainerApproachTask(struct ObjectEvent *trainerObj, u8 range)
{
struct Task *task;
@ -407,7 +420,7 @@ static void TrainerApproachPlayer(struct ObjectEvent *trainerObj, u8 range)
task->tTrainerObjectEventId = gApproachingTrainers[gNoOfApproachingTrainers].objectEventId;
}
static void sub_80B40C8(TaskFunc followupFunc)
static void StartTrainerApproach(TaskFunc followupFunc)
{
u8 taskId;
TaskFunc taskFunc;
@ -419,7 +432,7 @@ static void sub_80B40C8(TaskFunc followupFunc)
taskFunc = Task_RunTrainerSeeFuncList;
SetTaskFuncWithFollowupFunc(taskId, taskFunc, followupFunc);
gTasks[taskId].tFuncId = 1;
gTasks[taskId].tFuncId = TRSEE_EXCLAMATION;
taskFunc(taskId);
}
@ -438,11 +451,12 @@ static void Task_RunTrainerSeeFuncList(u8 taskId)
}
}
static bool8 sub_80B4178(u8 taskId, struct Task *task, struct ObjectEvent *trainerObj)
static bool8 TrainerSeeIdle(u8 taskId, struct Task *task, struct ObjectEvent *trainerObj)
{
return FALSE;
}
// TRSEE_EXCLAMATION
static bool8 TrainerExclamationMark(u8 taskId, struct Task *task, struct ObjectEvent *trainerObj)
{
u8 direction;
@ -451,10 +465,11 @@ static bool8 TrainerExclamationMark(u8 taskId, struct Task *task, struct ObjectE
FieldEffectStart(FLDEFF_EXCLAMATION_MARK_ICON);
direction = GetFaceDirectionMovementAction(trainerObj->facingDirection);
ObjectEventSetHeldMovement(trainerObj, direction);
task->tFuncId++;
task->tFuncId++; // TRSEE_EXCLAMATION_WAIT
return TRUE;
}
// TRSEE_EXCLAMATION_WAIT
static bool8 WaitTrainerExclamationMark(u8 taskId, struct Task *task, struct ObjectEvent *trainerObj)
{
if (FieldEffectActiveListContains(FLDEFF_EXCLAMATION_MARK_ICON))
@ -463,15 +478,16 @@ static bool8 WaitTrainerExclamationMark(u8 taskId, struct Task *task, struct Obj
}
else
{
task->tFuncId++;
task->tFuncId++; // TRSEE_MOVE_TO_PLAYER
if (trainerObj->movementType == MOVEMENT_TYPE_TREE_DISGUISE || trainerObj->movementType == MOVEMENT_TYPE_MOUNTAIN_DISGUISE)
task->tFuncId = 6;
task->tFuncId = TRSEE_REVEAL_DISGUISE;
if (trainerObj->movementType == MOVEMENT_TYPE_HIDDEN)
task->tFuncId = 8;
task->tFuncId = TRSEE_REVEAL_HIDDEN;
return TRUE;
}
}
// TRSEE_MOVE_TO_PLAYER
static bool8 TrainerMoveToPlayer(u8 taskId, struct Task *task, struct ObjectEvent *trainerObj)
{
if (!ObjectEventIsMovementOverridden(trainerObj) || ObjectEventClearHeldMovementIfFinished(trainerObj))
@ -484,12 +500,13 @@ static bool8 TrainerMoveToPlayer(u8 taskId, struct Task *task, struct ObjectEven
else
{
ObjectEventSetHeldMovement(trainerObj, MOVEMENT_ACTION_FACE_PLAYER);
task->tFuncId++;
task->tFuncId++; // TRSEE_PLAYER_FACE
}
}
return FALSE;
}
// TRSEE_PLAYER_FACE
static bool8 PlayerFaceApproachingTrainer(u8 taskId, struct Task *task, struct ObjectEvent *trainerObj)
{
struct ObjectEvent *playerObj;
@ -497,6 +514,7 @@ static bool8 PlayerFaceApproachingTrainer(u8 taskId, struct Task *task, struct O
if (ObjectEventIsMovementOverridden(trainerObj) && !ObjectEventClearHeldMovementIfFinished(trainerObj))
return FALSE;
// Set trainer's movement type so they stop and remain facing that direction
SetTrainerMovementType(trainerObj, GetTrainerFacingDirectionMovementType(trainerObj->facingDirection));
TryOverrideTemplateCoordsForObjectEvent(trainerObj, GetTrainerFacingDirectionMovementType(trainerObj->facingDirection));
OverrideTemplateCoordsForObjectEvent(trainerObj);
@ -507,10 +525,11 @@ static bool8 PlayerFaceApproachingTrainer(u8 taskId, struct Task *task, struct O
sub_808BCE8();
ObjectEventSetHeldMovement(&gObjectEvents[gPlayerAvatar.objectEventId], GetFaceDirectionMovementAction(GetOppositeDirection(trainerObj->facingDirection)));
task->tFuncId++;
task->tFuncId++; // TRSEE_PLAYER_FACE_WAIT
return FALSE;
}
// TRSEE_PLAYER_FACE_WAIT
static bool8 WaitPlayerFaceApproachingTrainer(u8 taskId, struct Task *task, struct ObjectEvent *trainerObj)
{
struct ObjectEvent *playerObj = &gObjectEvents[gPlayerAvatar.objectEventId];
@ -521,25 +540,28 @@ static bool8 WaitPlayerFaceApproachingTrainer(u8 taskId, struct Task *task, stru
return FALSE;
}
// TRSEE_REVEAL_DISGUISE
static bool8 RevealDisguisedTrainer(u8 taskId, struct Task *task, struct ObjectEvent *trainerObj)
{
if (!ObjectEventIsMovementOverridden(trainerObj)
|| ObjectEventClearHeldMovementIfFinished(trainerObj))
{
ObjectEventSetHeldMovement(trainerObj, MOVEMENT_ACTION_REVEAL_TRAINER);
task->tFuncId++;
task->tFuncId++; // TRSEE_REVEAL_DISGUISE_WAIT
}
return FALSE;
}
// TRSEE_REVEAL_DISGUISE_WAIT
static bool8 WaitRevealDisguisedTrainer(u8 taskId, struct Task *task, struct ObjectEvent *trainerObj)
{
if (ObjectEventClearHeldMovementIfFinished(trainerObj))
task->tFuncId = 3;
task->tFuncId = TRSEE_MOVE_TO_PLAYER;
return FALSE;
}
// TRSEE_REVEAL_HIDDEN
static bool8 RevealHiddenTrainer(u8 taskId, struct Task *task, struct ObjectEvent *trainerObj)
{
if (!ObjectEventIsMovementOverridden(trainerObj)
@ -551,6 +573,7 @@ static bool8 RevealHiddenTrainer(u8 taskId, struct Task *task, struct ObjectEven
return FALSE;
}
// TRSEE_HIDDEN_POP_OUT
static bool8 PopOutOfAshHiddenTrainer(u8 taskId, struct Task *task, struct ObjectEvent *trainerObj)
{
if (ObjectEventCheckHeldMovementStatus(trainerObj))
@ -565,6 +588,7 @@ static bool8 PopOutOfAshHiddenTrainer(u8 taskId, struct Task *task, struct Objec
return FALSE;
}
// TRSEE_HIDDEN_JUMP
static bool8 JumpInPlaceHiddenTrainer(u8 taskId, struct Task *task, struct ObjectEvent *trainerObj)
{
struct Sprite *sprite;
@ -584,33 +608,34 @@ static bool8 JumpInPlaceHiddenTrainer(u8 taskId, struct Task *task, struct Objec
return FALSE;
}
// TRSEE_REVEAL_HIDDEN_WAIT
static bool8 WaitRevealHiddenTrainer(u8 taskId, struct Task *task, struct ObjectEvent *trainerObj)
{
if (!FieldEffectActiveListContains(FLDEFF_ASH_PUFF))
task->tFuncId = 3;
task->tFuncId = TRSEE_MOVE_TO_PLAYER;
return FALSE;
}
#undef tFuncId
#undef tTrainerRange
#undef tOutOfAshSpriteId
#undef tTrainerObjectEventId
static void sub_80B44C8(u8 taskId)
#define tObjEvent data[1]
static void Task_SetHiddenTrainerMovement(u8 taskId)
{
struct Task *task = &gTasks[taskId];
struct ObjectEvent *objEvent;
// another objEvent loaded into by loadword?
LoadWordFromTwoHalfwords(&task->data[1], (u32 *)&objEvent);
LoadWordFromTwoHalfwords(&task->tObjEvent, (u32 *)&objEvent);
if (!task->data[7])
{
ObjectEventClearHeldMovement(objEvent);
task->data[7]++;
}
sTrainerSeeFuncList2[task->data[0]](taskId, task, objEvent);
if (task->data[0] == 3 && !FieldEffectActiveListContains(FLDEFF_ASH_PUFF))
sTrainerSeeFuncList2[task->tFuncId](taskId, task, objEvent);
if (task->tFuncId == ((int)ARRAY_COUNT(sTrainerSeeFuncList2) - 1) && !FieldEffectActiveListContains(FLDEFF_ASH_PUFF))
{
SetTrainerMovementType(objEvent, GetTrainerFacingDirectionMovementType(objEvent->facingDirection));
TryOverrideTemplateCoordsForObjectEvent(objEvent, GetTrainerFacingDirectionMovementType(objEvent->facingDirection));
@ -622,17 +647,18 @@ static void sub_80B44C8(u8 taskId)
}
}
void sub_80B4578(struct ObjectEvent *var)
// Called when a "buried" trainer has the reveal_trainer movement applied, from direct interaction
void SetHiddenTrainerMovement(struct ObjectEvent *objEvent)
{
StoreWordInTwoHalfwords(&gTasks[CreateTask(sub_80B44C8, 0)].data[1], (u32)var);
StoreWordInTwoHalfwords(&gTasks[CreateTask(Task_SetHiddenTrainerMovement, 0)].tObjEvent, (u32)objEvent);
}
void EndTrainerApproach(void)
void DoTrainerApproach(void)
{
sub_80B40C8(Task_DestroyTrainerApproachTask);
StartTrainerApproach(Task_EndTrainerApproach);
}
static void Task_DestroyTrainerApproachTask(u8 taskId)
static void Task_EndTrainerApproach(u8 taskId)
{
DestroyTask(taskId);
EnableBothScriptContexts();