From d7a021a914a8813e2cb093e9cea6dfb7d9307082 Mon Sep 17 00:00:00 2001 From: Ariel A <24759293+aarant@users.noreply.github.com> Date: Tue, 15 Mar 2022 19:58:48 -0400 Subject: [PATCH 1/2] fix: Made `Common_Movement_*` 'safe' for followers fixed #31 --- data/scripts/movement.inc | 7 +++++++ include/event_scripts.h | 3 +++ src/scrcmd.c | 7 +++++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/data/scripts/movement.inc b/data/scripts/movement.inc index 383c014130..a5ebc0ae7f 100644 --- a/data/scripts/movement.inc +++ b/data/scripts/movement.inc @@ -1,3 +1,6 @@ +@ Starting from here, these movements are considered +@ 'safe' (won't put follower into a Pokeball) +Common_Movement_FollowerSafeStart:: Common_Movement_QuestionMark: emote_question_mark step_end @@ -68,6 +71,10 @@ Common_Movement_WalkInPlaceRight: walk_in_place_right step_end +@ End of follower-safe movements +Common_Movement_FollowerSafeEnd:: + step_end + Common_Movement_WalkUp6: walk_up walk_up diff --git a/include/event_scripts.h b/include/event_scripts.h index a64b8ffc4c..2fa4468c74 100644 --- a/include/event_scripts.h +++ b/include/event_scripts.h @@ -639,4 +639,7 @@ extern const u8 EventScript_TradeCenter_Chair0[]; extern const u8 EventScript_ConfirmLeaveCableClubRoom[]; extern const u8 EventScript_TerminateLink[]; +extern const u8 Common_Movement_FollowerSafeStart[]; +extern const u8 Common_Movement_FollowerSafeEnd[]; + #endif // GUARD_EVENT_SCRIPTS_H diff --git a/src/scrcmd.c b/src/scrcmd.c index df490518fc..3b4ad9ddd6 100644 --- a/src/scrcmd.c +++ b/src/scrcmd.c @@ -1000,7 +1000,7 @@ bool8 ScrCmd_fadeinbgm(struct ScriptContext *ctx) bool8 ScrCmd_applymovement(struct ScriptContext *ctx) { u16 localId = VarGet(ScriptReadHalfword(ctx)); - const void *movementScript = (const void *)ScriptReadWord(ctx); + const u8 *movementScript = (const u8 *)ScriptReadWord(ctx); struct ObjectEvent *objEvent; // When applying script movements to follower, it may have frozen animation that must be cleared @@ -1011,7 +1011,10 @@ bool8 ScrCmd_applymovement(struct ScriptContext *ctx) ScriptMovement_StartObjectMovementScript(localId, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, movementScript); sMovingNpcId = localId; // Force follower into pokeball - if (localId != OBJ_EVENT_ID_FOLLOWER && !FlagGet(FLAG_SAFE_FOLLOWER_MOVEMENT)) { + if (localId != OBJ_EVENT_ID_FOLLOWER + && !FlagGet(FLAG_SAFE_FOLLOWER_MOVEMENT) + && (movementScript < Common_Movement_FollowerSafeStart || movementScript > Common_Movement_FollowerSafeEnd)) + { objEvent = GetFollowerObject(); // return early if no follower or in shadowing state if (objEvent == NULL || gSprites[objEvent->spriteId].data[1] == 0) From dbc11ad3d2028702c12d9677b74b0946292d7189 Mon Sep 17 00:00:00 2001 From: Ariel A <24759293+aarant@users.noreply.github.com> Date: Sat, 27 Apr 2024 23:15:49 -0400 Subject: [PATCH 2/2] fix: improved follower pokemon `lock` and `applymovement` code fixed #30, fixed #32 --- src/scrcmd.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/scrcmd.c b/src/scrcmd.c index 3b4ad9ddd6..d29df1748d 100644 --- a/src/scrcmd.c +++ b/src/scrcmd.c @@ -1006,20 +1006,20 @@ bool8 ScrCmd_applymovement(struct ScriptContext *ctx) // When applying script movements to follower, it may have frozen animation that must be cleared if (localId == OBJ_EVENT_ID_FOLLOWER && (objEvent = GetFollowerObject()) && objEvent->frozen) { ClearObjectEventMovement(objEvent, &gSprites[objEvent->spriteId]); - gSprites[objEvent->spriteId].animCmdIndex = 0; // Needed to set start frame of animation + gSprites[objEvent->spriteId].animCmdIndex = 0; // Reset start frame of animation } ScriptMovement_StartObjectMovementScript(localId, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, movementScript); sMovingNpcId = localId; + objEvent = GetFollowerObject(); // Force follower into pokeball if (localId != OBJ_EVENT_ID_FOLLOWER && !FlagGet(FLAG_SAFE_FOLLOWER_MOVEMENT) - && (movementScript < Common_Movement_FollowerSafeStart || movementScript > Common_Movement_FollowerSafeEnd)) + && (movementScript < Common_Movement_FollowerSafeStart || movementScript > Common_Movement_FollowerSafeEnd) + && (objEvent = GetFollowerObject()) + && !objEvent->invisible) { - objEvent = GetFollowerObject(); - // return early if no follower or in shadowing state - if (objEvent == NULL || gSprites[objEvent->spriteId].data[1] == 0) - return FALSE; ClearObjectEventMovement(objEvent, &gSprites[objEvent->spriteId]); + gSprites[objEvent->spriteId].animCmdIndex = 0; // Reset start frame of animation ScriptMovement_StartObjectMovementScript(OBJ_EVENT_ID_FOLLOWER, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, EnterPokeballMovement); } return FALSE; @@ -1246,7 +1246,7 @@ bool8 ScrCmd_lockall(struct ScriptContext *ctx) } } -// lock freezes all object events except the player and the selected object immediately. +// lock freezes all object events except the player, follower, and the selected object immediately. // The player and selected object are frozen after waiting for their current movement to finish. bool8 ScrCmd_lock(struct ScriptContext *ctx) { @@ -1256,16 +1256,22 @@ bool8 ScrCmd_lock(struct ScriptContext *ctx) } else { + struct ObjectEvent *followerObj = GetFollowerObject(); if (gObjectEvents[gSelectedObjectEvent].active) { FreezeObjects_WaitForPlayerAndSelected(); SetupNativeScript(ctx, IsFreezeSelectedObjectAndPlayerFinished); + // follower is being talked to; keep it frozen + if (gObjectEvents[gSelectedObjectEvent].localId == OBJ_EVENT_ID_FOLLOWER) + followerObj = NULL; } else { FreezeObjects_WaitForPlayer(); SetupNativeScript(ctx, IsFreezePlayerFinished); } + if (followerObj) // Unfreeze follower object + UnfreezeObjectEvent(followerObj); return TRUE; } }