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] 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)