From 88575795199f65b4554a39019dd34a032518ac07 Mon Sep 17 00:00:00 2001 From: Evan Date: Mon, 20 Jul 2020 12:20:25 -0600 Subject: [PATCH 01/11] add stair warps --- include/constants/metatile_behaviors.h | 8 +- include/field_screen_effect.h | 2 + include/global.fieldmap.h | 1 + include/metatile_behavior.h | 5 + src/field_control_avatar.c | 28 +++- src/field_player_avatar.c | 8 + src/field_screen_effect.c | 211 +++++++++++++++++++++++++ src/metatile_behavior.c | 48 +++++- src/overworld.c | 4 + 9 files changed, 302 insertions(+), 13 deletions(-) diff --git a/include/constants/metatile_behaviors.h b/include/constants/metatile_behaviors.h index 94cb0ffcaa..59ed97d079 100755 --- a/include/constants/metatile_behaviors.h +++ b/include/constants/metatile_behaviors.h @@ -236,10 +236,10 @@ #define MB_WIRELESS_BOX_RESULTS 0xE8 #define MB_TRAINER_HILL_TIMER 0xE9 #define MB_SKY_PILLAR_CLOSED_DOOR 0xEA -#define MB_UNUSED_EB 0xEB -#define MB_UNUSED_EC 0xEC -#define MB_UNUSED_ED 0xED -#define MB_UNUSED_EE 0xEE +#define MB_UP_RIGHT_STAIR_WARP 0xEB +#define MB_UP_LEFT_STAIR_WARP 0xEC +#define MB_DOWN_RIGHT_STAIR_WARP 0xED +#define MB_DOWN_LEFT_STAIR_WARP 0xEE #define MB_UNUSED_EF 0xEF #endif // GUARD_METATILE_BEHAVIORS diff --git a/include/field_screen_effect.h b/include/field_screen_effect.h index e05e30378a..0f97bdc3f3 100644 --- a/include/field_screen_effect.h +++ b/include/field_screen_effect.h @@ -40,5 +40,7 @@ void FadeOutOrbEffect(void); void sub_80B05B4(void); void WriteFlashScanlineEffectBuffer(u8 flashLevel); bool8 IsPlayerStandingStill(void); +void DoStairWarp(u16 metatileBehavior, u16 delay); +bool8 IsDirectionalStairWarpMetatileBehavior(u16 metatileBehavior, u8 playerDirection); #endif // GUARD_FIELD_SCREEN_EFFECT_H diff --git a/include/global.fieldmap.h b/include/global.fieldmap.h index 59610f9adb..a3ef192b77 100644 --- a/include/global.fieldmap.h +++ b/include/global.fieldmap.h @@ -283,6 +283,7 @@ enum COLLISION_ISOLATED_HORIZONTAL_RAIL, COLLISION_VERTICAL_RAIL, COLLISION_HORIZONTAL_RAIL, + COLLISION_STAIR_WARP, }; // player running states diff --git a/include/metatile_behavior.h b/include/metatile_behavior.h index b5dae6de09..a801d8b27b 100644 --- a/include/metatile_behavior.h +++ b/include/metatile_behavior.h @@ -145,5 +145,10 @@ bool8 MetatileBehavior_IsQuestionnaire(u8); bool8 MetatileBehavior_IsLongGrass_Duplicate(u8); bool8 MetatileBehavior_IsLongGrassSouthEdge(u8); bool8 MetatileBehavior_IsTrainerHillTimer(u8); +bool8 MetatileBehavior_IsDirectionalUpRightStairWarp(u8 metatileBehavior); +bool8 MetatileBehavior_IsDirectionalUpLeftStairWarp(u8 metatileBehavior); +bool8 MetatileBehavior_IsDirectionalDownRightStairWarp(u8 metatileBehavior); +bool8 MetatileBehavior_IsDirectionalDownLeftStairWarp(u8 metatileBehavior); +bool8 MetatileBehavior_IsDirectionalStairWarp(u8 metatileBehavior); #endif // GUARD_METATILE_BEHAVIOR diff --git a/src/field_control_avatar.c b/src/field_control_avatar.c index e41b5a69a5..a5beff0930 100644 --- a/src/field_control_avatar.c +++ b/src/field_control_avatar.c @@ -689,13 +689,31 @@ static bool8 CheckStandardWildEncounter(u16 metatileBehavior) static bool8 TryArrowWarp(struct MapPosition *position, u16 metatileBehavior, u8 direction) { s8 warpEventId = GetWarpEventAtMapPosition(&gMapHeader, position); + u16 delay; - if (IsArrowWarpMetatileBehavior(metatileBehavior, direction) == TRUE && warpEventId != -1) + if (warpEventId != -1) { - StoreInitialPlayerAvatarState(); - SetupWarp(&gMapHeader, warpEventId, position); - DoWarp(); - return TRUE; + if (IsArrowWarpMetatileBehavior(metatileBehavior, direction) == TRUE) + { + StoreInitialPlayerAvatarState(); + SetupWarp(&gMapHeader, warpEventId, position); + DoWarp(); + return TRUE; + } + else if (IsDirectionalStairWarpMetatileBehavior(metatileBehavior, direction) == TRUE) + { + delay = 0; + if (gPlayerAvatar.flags & (PLAYER_AVATAR_FLAG_MACH_BIKE | PLAYER_AVATAR_FLAG_ACRO_BIKE)) + { + SetPlayerAvatarTransitionFlags(PLAYER_AVATAR_FLAG_ON_FOOT); + delay = 12; + } + + StoreInitialPlayerAvatarState(); + SetupWarp(&gMapHeader, warpEventId, position); + DoStairWarp(metatileBehavior, delay); + return TRUE; + } } return FALSE; } diff --git a/src/field_player_avatar.c b/src/field_player_avatar.c index f5f6e99f7d..dae437d629 100644 --- a/src/field_player_avatar.c +++ b/src/field_player_avatar.c @@ -6,6 +6,7 @@ #include "field_camera.h" #include "field_effect.h" #include "field_effect_helpers.h" +#include "field_screen_effect.h" #include "field_player_avatar.h" #include "fieldmap.h" #include "menu.h" @@ -625,6 +626,10 @@ static void PlayerNotOnBikeMoving(u8 direction, u16 heldKeys) PlayerNotOnBikeCollideWithFarawayIslandMew(direction); return; } + else if (collision == COLLISION_STAIR_WARP) + { + PlayerFaceDirection(direction); + } else { u8 adjustedCollision = collision - COLLISION_STOP_SURFING; @@ -661,6 +666,9 @@ static u8 CheckForPlayerAvatarCollision(u8 direction) x = playerObjEvent->currentCoords.x; y = playerObjEvent->currentCoords.y; + if (IsDirectionalStairWarpMetatileBehavior(MapGridGetMetatileBehaviorAt(x, y), direction)) + return COLLISION_STAIR_WARP; + MoveCoords(direction, &x, &y); return CheckForObjectEventCollision(playerObjEvent, x, y, direction, MapGridGetMetatileBehaviorAt(x, y)); } diff --git a/src/field_screen_effect.c b/src/field_screen_effect.c index 53057fc31d..6d9269915e 100644 --- a/src/field_screen_effect.c +++ b/src/field_screen_effect.c @@ -49,6 +49,7 @@ static void task0A_mpl_807E31C(u8 taskId); static void Task_WarpAndLoadMap(u8 taskId); static void Task_DoDoorWarp(u8 taskId); static void Task_EnableScriptAfterMusicFade(u8 taskId); +static void Task_ExitStairs(u8 taskId); // const static const u16 sFlashLevelPixelRadii[] = { 200, 72, 64, 56, 48, 40, 32, 24, 0 }; @@ -266,6 +267,8 @@ static void SetUpWarpExitTask(void) behavior = MapGridGetMetatileBehaviorAt(x, y); if (MetatileBehavior_IsDoor(behavior) == TRUE) func = Task_ExitDoor; + else if (MetatileBehavior_IsDirectionalStairWarp(behavior) == TRUE) + func = Task_ExitStairs; else if (MetatileBehavior_IsNonAnimDoor(behavior) == TRUE) func = Task_ExitNonAnimDoor; else @@ -1267,3 +1270,211 @@ static void Task_EnableScriptAfterMusicFade(u8 taskId) EnableBothScriptContexts(); } } + +//stair warps +static void GetStairsMovementDirection(u8 a0, s16 *a1, s16 *a2) +{ + if (MetatileBehavior_IsDirectionalUpRightStairWarp(a0)) + { + *a1 = 16; + *a2 = -10; + } + else if (MetatileBehavior_IsDirectionalUpLeftStairWarp(a0)) + { + *a1 = -17; + *a2 = -10; + } + else if (MetatileBehavior_IsDirectionalDownRightStairWarp(a0)) + { + *a1 = 17; + *a2 = 3; + } + else if (MetatileBehavior_IsDirectionalDownLeftStairWarp(a0)) + { + *a1 = -17; + *a2 = 3; + } + else + { + *a1 = 0; + *a2 = 0; + } +} + +static bool8 WaitStairExitMovementFinished(s16 *a0, s16 *a1, s16 *a2, s16 *a3, s16 *a4) +{ + struct Sprite *sprite; + sprite = &gSprites[gPlayerAvatar.spriteId]; + if (*a4 != 0) + { + *a2 += *a0; + *a3 += *a1; + sprite->pos2.x = *a2 >> 5; + sprite->pos2.y = *a3 >> 5; + (*a4)--; + return TRUE; + } + else + { + sprite->pos2.x = 0; + sprite->pos2.y = 0; + return FALSE; + } +} + +static void ExitStairsMovement(s16 *a0, s16 *a1, s16 *a2, s16 *a3, s16 *a4) +{ + s16 x, y; + u8 behavior; + s32 r1; + struct Sprite *sprite; + + PlayerGetDestCoords(&x, &y); + behavior = MapGridGetMetatileBehaviorAt(x, y); + if (MetatileBehavior_IsDirectionalDownRightStairWarp(behavior) || MetatileBehavior_IsDirectionalUpRightStairWarp(behavior)) + r1 = 3; + else + r1 = 4; + + ObjectEventForceSetHeldMovement(&gObjectEvents[gPlayerAvatar.objectEventId], GetWalkInPlaceSlowMovementAction(r1)); + GetStairsMovementDirection(behavior, a0, a1); + *a2 = *a0 * 16; + *a3 = *a1 * 16; + *a4 = 16; + sprite = &gSprites[gPlayerAvatar.spriteId]; + sprite->pos2.x = *a2 >> 5; + sprite->pos2.y = *a3 >> 5; + *a0 *= -1; + *a1 *= -1; +} + +static void Task_ExitStairs(u8 taskId) +{ + s16 * data = gTasks[taskId].data; + switch (data[0]) + { + default: + if (WaitForWeatherFadeIn() == TRUE) + { + CameraObjectReset1(); + ScriptContext2_Disable(); + DestroyTask(taskId); + } + break; + case 0: + Overworld_PlaySpecialMapMusic(); + WarpFadeInScreen(); + ScriptContext2_Enable(); + ExitStairsMovement(&data[1], &data[2], &data[3], &data[4], &data[5]); + data[0]++; + break; + case 1: + if (!WaitStairExitMovementFinished(&data[1], &data[2], &data[3], &data[4], &data[5])) + data[0]++; + break; + } +} + +bool8 IsDirectionalStairWarpMetatileBehavior(u16 metatileBehavior, u8 playerDirection) +{ + switch (playerDirection) + { + case DIR_WEST: + if (MetatileBehavior_IsDirectionalUpLeftStairWarp(metatileBehavior)) + return TRUE; + if (MetatileBehavior_IsDirectionalDownLeftStairWarp(metatileBehavior)) + return TRUE; + break; + case DIR_EAST: + if (MetatileBehavior_IsDirectionalUpRightStairWarp(metatileBehavior)) + return TRUE; + if (MetatileBehavior_IsDirectionalDownRightStairWarp(metatileBehavior)) + return TRUE; + break; + } + return FALSE; +} + +static void ForceStairsMovement(u16 a0, s16 *a1, s16 *a2) +{ + ObjectEventForceSetHeldMovement(&gObjectEvents[gPlayerAvatar.objectEventId], GetWalkInPlaceNormalMovementAction(GetPlayerFacingDirection())); + GetStairsMovementDirection(a0, a1, a2); +} + +static void UpdateStairsMovement(s16 a0, s16 a1, s16 *a2, s16 *a3, s16 *a4) +{ + struct Sprite *playerSpr = &gSprites[gPlayerAvatar.spriteId]; + struct ObjectEvent *playerObj = &gObjectEvents[gPlayerAvatar.objectEventId]; + + if (a1 > 0 || *a4 > 6) + *a3 += a1; + + *a2 += a0; + (*a4)++; + playerSpr->pos2.x = *a2 >> 5; + playerSpr->pos2.y = *a3 >> 5; + if (playerObj->heldMovementFinished) + ObjectEventForceSetHeldMovement(playerObj, GetWalkInPlaceNormalMovementAction(GetPlayerFacingDirection())); +} + +static void Task_StairWarp(u8 taskId) +{ + s16 * data = gTasks[taskId].data; + struct ObjectEvent *playerObj = &gObjectEvents[gPlayerAvatar.objectEventId]; + struct Sprite *playerSpr = &gSprites[gPlayerAvatar.spriteId]; + + switch (data[0]) + { + case 0: + ScriptContext2_Enable(); + FreezeObjectEvents(); + CameraObjectReset2(); + data[0]++; + break; + case 1: + if (!ObjectEventIsMovementOverridden(playerObj) || ObjectEventClearHeldMovementIfFinished(playerObj)) + { + if (data[15] != 0) + data[15]--; + else + { + TryFadeOutOldMapMusic(); + PlayRainStoppingSoundEffect(); + playerSpr->oam.priority = 1; + ForceStairsMovement(data[1], &data[2], &data[3]); + PlaySE(SE_KAIDAN); + data[0]++; + } + } + break; + case 2: + UpdateStairsMovement(data[2], data[3], &data[4], &data[5], &data[6]); + data[15]++; + if (data[15] >= 12) + { + WarpFadeOutScreen(); + data[0]++; + } + break; + case 3: + UpdateStairsMovement(data[2], data[3], &data[4], &data[5], &data[6]); + if (!PaletteFadeActive() && BGMusicStopped()) + data[0]++; + break; + default: + gFieldCallback = FieldCB_DefaultWarpExit; + WarpIntoMap(); + SetMainCallback2(CB2_LoadMap); + DestroyTask(taskId); + break; + } +} + +void DoStairWarp(u16 metatileBehavior, u16 delay) +{ + u8 taskId = CreateTask(Task_StairWarp, 10); + gTasks[taskId].data[1] = metatileBehavior; + gTasks[taskId].data[15] = delay; + Task_StairWarp(taskId); +} + diff --git a/src/metatile_behavior.c b/src/metatile_behavior.c index 435ad72336..782a49e36c 100644 --- a/src/metatile_behavior.c +++ b/src/metatile_behavior.c @@ -245,10 +245,10 @@ static const u8 sTileBitAttributes[] = [MB_WIRELESS_BOX_RESULTS] = TILE_ATTRIBUTES(FALSE, FALSE, FALSE), [MB_TRAINER_HILL_TIMER] = TILE_ATTRIBUTES(FALSE, FALSE, FALSE), [MB_SKY_PILLAR_CLOSED_DOOR] = TILE_ATTRIBUTES(FALSE, FALSE, FALSE), - [MB_UNUSED_EB] = TILE_ATTRIBUTES(FALSE, FALSE, FALSE), - [MB_UNUSED_EC] = TILE_ATTRIBUTES(FALSE, FALSE, FALSE), - [MB_UNUSED_ED] = TILE_ATTRIBUTES(FALSE, FALSE, FALSE), - [MB_UNUSED_EE] = TILE_ATTRIBUTES(FALSE, FALSE, FALSE), + [MB_UP_RIGHT_STAIR_WARP] = TILE_ATTRIBUTES(FALSE, FALSE, FALSE), + [MB_UP_LEFT_STAIR_WARP] = TILE_ATTRIBUTES(FALSE, FALSE, FALSE), + [MB_DOWN_RIGHT_STAIR_WARP] = TILE_ATTRIBUTES(FALSE, FALSE, FALSE), + [MB_DOWN_LEFT_STAIR_WARP] = TILE_ATTRIBUTES(FALSE, FALSE, FALSE), [MB_UNUSED_EF] = TILE_ATTRIBUTES(FALSE, FALSE, FALSE), }; @@ -1488,3 +1488,43 @@ bool8 MetatileBehavior_IsTrainerHillTimer(u8 metatileBehavior) else return FALSE; } + +bool8 MetatileBehavior_IsDirectionalUpRightStairWarp(u8 metatileBehavior) +{ + if(metatileBehavior == MB_UP_RIGHT_STAIR_WARP) + return TRUE; + else + return FALSE; +} + +bool8 MetatileBehavior_IsDirectionalUpLeftStairWarp(u8 metatileBehavior) +{ + if (metatileBehavior == MB_UP_LEFT_STAIR_WARP) + return TRUE; + else + return FALSE; +} + +bool8 MetatileBehavior_IsDirectionalDownRightStairWarp(u8 metatileBehavior) +{ + if (metatileBehavior == MB_DOWN_RIGHT_STAIR_WARP) + return TRUE; + else + return FALSE; +} + +bool8 MetatileBehavior_IsDirectionalDownLeftStairWarp(u8 metatileBehavior) +{ + if (metatileBehavior == MB_DOWN_LEFT_STAIR_WARP) + return TRUE; + else + return FALSE; +} + +bool8 MetatileBehavior_IsDirectionalStairWarp(u8 metatileBehavior) +{ + if (metatileBehavior >= MB_UP_RIGHT_STAIR_WARP && metatileBehavior <= MB_DOWN_LEFT_STAIR_WARP) + return TRUE; + else + return FALSE; +} diff --git a/src/overworld.c b/src/overworld.c index ea0d633bcf..dcf30af89f 100644 --- a/src/overworld.c +++ b/src/overworld.c @@ -962,6 +962,10 @@ static u8 GetAdjustedInitialDirection(struct InitialPlayerAvatarState *playerStr return DIR_EAST; else if (MetatileBehavior_IsEastArrowWarp(metatileBehavior) == TRUE) return DIR_WEST; + else if (MetatileBehavior_IsDirectionalUpRightStairWarp(metatileBehavior) == TRUE || MetatileBehavior_IsDirectionalDownRightStairWarp(metatileBehavior) == TRUE) + return DIR_WEST; + else if (MetatileBehavior_IsDirectionalUpLeftStairWarp(metatileBehavior) == TRUE || MetatileBehavior_IsDirectionalDownLeftStairWarp(metatileBehavior) == TRUE) + return DIR_EAST; else if ((playerStruct->transitionFlags == PLAYER_AVATAR_FLAG_UNDERWATER && transitionFlags == PLAYER_AVATAR_FLAG_SURFING) || (playerStruct->transitionFlags == PLAYER_AVATAR_FLAG_SURFING && transitionFlags == PLAYER_AVATAR_FLAG_UNDERWATER )) return playerStruct->direction; From 11828238685cac8b2056902d50399fd082905141 Mon Sep 17 00:00:00 2001 From: Evan Date: Wed, 23 Sep 2020 13:46:04 -0600 Subject: [PATCH 02/11] update stair warp SE --- src/field_screen_effect.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/field_screen_effect.c b/src/field_screen_effect.c index eccf9dc9d6..7c47075141 100644 --- a/src/field_screen_effect.c +++ b/src/field_screen_effect.c @@ -1444,7 +1444,7 @@ static void Task_StairWarp(u8 taskId) PlayRainStoppingSoundEffect(); playerSpr->oam.priority = 1; ForceStairsMovement(data[1], &data[2], &data[3]); - PlaySE(SE_KAIDAN); + PlaySE(SE_EXIT); data[0]++; } } From bed5472014cdd7d746a9b4e9fffc952ee9978a8e Mon Sep 17 00:00:00 2001 From: ghoulslash Date: Fri, 29 Jul 2022 11:18:03 -0400 Subject: [PATCH 03/11] fix pos2 to x2,y2 --- src/field_screen_effect.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/field_screen_effect.c b/src/field_screen_effect.c index 82aee41755..ee7887a1f3 100644 --- a/src/field_screen_effect.c +++ b/src/field_screen_effect.c @@ -1308,15 +1308,15 @@ static bool8 WaitStairExitMovementFinished(s16 *a0, s16 *a1, s16 *a2, s16 *a3, s { *a2 += *a0; *a3 += *a1; - sprite->pos2.x = *a2 >> 5; - sprite->pos2.y = *a3 >> 5; + sprite->x2 = *a2 >> 5; + sprite->y2 = *a3 >> 5; (*a4)--; return TRUE; } else { - sprite->pos2.x = 0; - sprite->pos2.y = 0; + sprite->x2 = 0; + sprite->y2 = 0; return FALSE; } } @@ -1341,8 +1341,8 @@ static void ExitStairsMovement(s16 *a0, s16 *a1, s16 *a2, s16 *a3, s16 *a4) *a3 = *a1 * 16; *a4 = 16; sprite = &gSprites[gPlayerAvatar.spriteId]; - sprite->pos2.x = *a2 >> 5; - sprite->pos2.y = *a3 >> 5; + sprite->x2 = *a2 >> 5; + sprite->y2 = *a3 >> 5; *a0 *= -1; *a1 *= -1; } @@ -1410,8 +1410,8 @@ static void UpdateStairsMovement(s16 a0, s16 a1, s16 *a2, s16 *a3, s16 *a4) *a2 += a0; (*a4)++; - playerSpr->pos2.x = *a2 >> 5; - playerSpr->pos2.y = *a3 >> 5; + playerSpr->x2 = *a2 >> 5; + playerSpr->y2 = *a3 >> 5; if (playerObj->heldMovementFinished) ObjectEventForceSetHeldMovement(playerObj, GetWalkInPlaceNormalMovementAction(GetPlayerFacingDirection())); } From 906622f04dc3a977f379196af295158c9d5324d2 Mon Sep 17 00:00:00 2001 From: ghoulslash Date: Fri, 29 Jul 2022 11:26:21 -0400 Subject: [PATCH 04/11] add gExitStairsMovementDisabled --- include/overworld.h | 1 + src/field_screen_effect.c | 4 +++- src/overworld.c | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/overworld.h b/include/overworld.h index adaa6aad04..e24b8e4d9c 100644 --- a/include/overworld.h +++ b/include/overworld.h @@ -51,6 +51,7 @@ extern void (*gFieldCallback)(void); extern bool8 (*gFieldCallback2)(void); extern u8 gLocalLinkPlayerId; extern u8 gFieldLinkPlayerCount; +extern bool8 gExitStairsMovementDisabled; extern const struct UCoords32 gDirectionToVectors[]; diff --git a/src/field_screen_effect.c b/src/field_screen_effect.c index ee7887a1f3..7f775aefdc 100644 --- a/src/field_screen_effect.c +++ b/src/field_screen_effect.c @@ -264,12 +264,14 @@ static void SetUpWarpExitTask(void) behavior = MapGridGetMetatileBehaviorAt(x, y); if (MetatileBehavior_IsDoor(behavior) == TRUE) func = Task_ExitDoor; - else if (MetatileBehavior_IsDirectionalStairWarp(behavior) == TRUE) + else if (MetatileBehavior_IsDirectionalStairWarp(behavior) == TRUE && !gExitStairsMovementDisabled) func = Task_ExitStairs; else if (MetatileBehavior_IsNonAnimDoor(behavior) == TRUE) func = Task_ExitNonAnimDoor; else func = Task_ExitNonDoor; + + gExitStairsMovementDisabled = FALSE; CreateTask(func, 10); } diff --git a/src/overworld.c b/src/overworld.c index 383f10ffe1..108a646cfb 100644 --- a/src/overworld.c +++ b/src/overworld.c @@ -202,6 +202,7 @@ 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}; +EWRAM_DATA bool8 gExitStairsMovementDisabled = FALSE; static const struct WarpData sDummyWarpData = { @@ -1729,6 +1730,7 @@ void CB2_ContinueSavedGame(void) PlayTimeCounter_Start(); ScriptContext1_Init(); ScriptContext2_Disable(); + gExitStairsMovementDisabled = TRUE; InitMatchCallCounters(); if (UseContinueGameWarp() == TRUE) { @@ -1814,6 +1816,7 @@ static bool32 LoadMapInStepsLink(u8 *state) (*state)++; break; case 1: + gExitStairsMovementDisabled = FALSE; LoadMapFromWarp(TRUE); (*state)++; break; From 9bf64085ba959c4c494eec9d8ae74d958f2781ed Mon Sep 17 00:00:00 2001 From: ghoulslash Date: Sun, 21 May 2023 12:56:15 -0400 Subject: [PATCH 05/11] fix script context func names --- src/field_screen_effect.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/field_screen_effect.c b/src/field_screen_effect.c index e006db412f..fd6ac119d5 100644 --- a/src/field_screen_effect.c +++ b/src/field_screen_effect.c @@ -1356,14 +1356,14 @@ static void Task_ExitStairs(u8 taskId) if (WaitForWeatherFadeIn() == TRUE) { CameraObjectReset1(); - ScriptContext2_Disable(); + UnlockPlayerFieldControls(); DestroyTask(taskId); } break; case 0: Overworld_PlaySpecialMapMusic(); WarpFadeInScreen(); - ScriptContext2_Enable(); + LockPlayerFieldControls(); ExitStairsMovement(&data[1], &data[2], &data[3], &data[4], &data[5]); data[0]++; break; @@ -1425,7 +1425,7 @@ static void Task_StairWarp(u8 taskId) switch (data[0]) { case 0: - ScriptContext2_Enable(); + LockPlayerFieldControls(); FreezeObjectEvents(); CameraObjectReset2(); data[0]++; From 04faf370e6875807c659cd1436783f7009a71fd9 Mon Sep 17 00:00:00 2001 From: pkmnsnfrn Date: Sun, 25 Aug 2024 17:37:15 -0700 Subject: [PATCH 06/11] Cleaned up and reordered functions --- include/field_screen_effect.h | 2 +- src/field_control_avatar.c | 48 ++-- src/field_screen_effect.c | 400 ++++++++++++++++++---------------- src/metatile_behavior.c | 5 +- 4 files changed, 248 insertions(+), 207 deletions(-) diff --git a/include/field_screen_effect.h b/include/field_screen_effect.h index b9a2ef9d5b..3f120ffdeb 100644 --- a/include/field_screen_effect.h +++ b/include/field_screen_effect.h @@ -43,6 +43,6 @@ void FadeOutOrbEffect(void); void WriteFlashScanlineEffectBuffer(u8 flashLevel); bool8 IsPlayerStandingStill(void); void DoStairWarp(u16 metatileBehavior, u16 delay); -bool8 IsDirectionalStairWarpMetatileBehavior(u16 metatileBehavior, u8 playerDirection); +bool32 IsDirectionalStairWarpMetatileBehavior(u16 metatileBehavior, u8 playerDirection); #endif // GUARD_FIELD_SCREEN_EFFECT_H diff --git a/src/field_control_avatar.c b/src/field_control_avatar.c index 58afd16310..c1d2455ff7 100644 --- a/src/field_control_avatar.c +++ b/src/field_control_avatar.c @@ -727,34 +727,38 @@ static bool8 CheckStandardWildEncounter(u16 metatileBehavior) return FALSE; } +static void StorePlayerStateAndSetupWarp(struct MapPosition *position, s32 warpEventId) +{ + StoreInitialPlayerAvatarState(); + SetupWarp(&gMapHeader, warpEventId, position); +} + static bool8 TryArrowWarp(struct MapPosition *position, u16 metatileBehavior, u8 direction) { - s8 warpEventId = GetWarpEventAtMapPosition(&gMapHeader, position); - u16 delay; + s32 warpEventId = GetWarpEventAtMapPosition(&gMapHeader, position); + u32 delay; - if (warpEventId != WARP_ID_NONE) + if (warpEventId == WARP_ID_NONE) + return FALSE; + + if (IsArrowWarpMetatileBehavior(metatileBehavior, direction) == TRUE) { - if (IsArrowWarpMetatileBehavior(metatileBehavior, direction) == TRUE) + StorePlayerStateAndSetupWarp(position, warpEventId); + DoWarp(); + return TRUE; + } + else if (IsDirectionalStairWarpMetatileBehavior(metatileBehavior, direction) == TRUE) + { + delay = 0; + if (gPlayerAvatar.flags & PLAYER_AVATAR_FLAG_BIKE) { - StoreInitialPlayerAvatarState(); - SetupWarp(&gMapHeader, warpEventId, position); - DoWarp(); - return TRUE; - } - else if (IsDirectionalStairWarpMetatileBehavior(metatileBehavior, direction) == TRUE) - { - delay = 0; - if (gPlayerAvatar.flags & (PLAYER_AVATAR_FLAG_MACH_BIKE | PLAYER_AVATAR_FLAG_ACRO_BIKE)) - { - SetPlayerAvatarTransitionFlags(PLAYER_AVATAR_FLAG_ON_FOOT); - delay = 12; - } - - StoreInitialPlayerAvatarState(); - SetupWarp(&gMapHeader, warpEventId, position); - DoStairWarp(metatileBehavior, delay); - return TRUE; + SetPlayerAvatarTransitionFlags(PLAYER_AVATAR_FLAG_ON_FOOT); + delay = 12; } + + StorePlayerStateAndSetupWarp(position, warpEventId); + DoStairWarp(metatileBehavior, delay); + return TRUE; } return FALSE; } diff --git a/src/field_screen_effect.c b/src/field_screen_effect.c index 0cce757f56..0839dc6bb2 100644 --- a/src/field_screen_effect.c +++ b/src/field_screen_effect.c @@ -50,7 +50,14 @@ static void Task_SpinEnterWarp(u8 taskId); static void Task_WarpAndLoadMap(u8 taskId); static void Task_DoDoorWarp(u8 taskId); static void Task_EnableScriptAfterMusicFade(u8 taskId); -static void Task_ExitStairs(u8 taskId); + +static void ExitStairsMovement(s16*, s16*, s16*, s16*, s16*); +static void GetStairsMovementDirection(u32, s16*, s16*); +static void Task_ExitStairs(u8); +static bool8 WaitStairExitMovementFinished(s16*, s16*, s16*, s16*, s16*); +static void UpdateStairsMovement(s16, s16, s16*, s16*, s16*); +static void Task_StairWarp(u8); +static void ForceStairsMovement(u32, s16*, s16*); // data[0] is used universally by tasks in this file as a state for switches #define tState data[0] @@ -1328,129 +1335,6 @@ static bool32 PrintWhiteOutRecoveryMessage(u8 taskId, const u8 *text, u32 x, u32 return FALSE; } -static void GetStairsMovementDirection(u8 a0, s16 *a1, s16 *a2) -{ - if (MetatileBehavior_IsDirectionalUpRightStairWarp(a0)) - { - *a1 = 16; - *a2 = -10; - } - else if (MetatileBehavior_IsDirectionalUpLeftStairWarp(a0)) - { - *a1 = -17; - *a2 = -10; - } - else if (MetatileBehavior_IsDirectionalDownRightStairWarp(a0)) - { - *a1 = 17; - *a2 = 3; - } - else if (MetatileBehavior_IsDirectionalDownLeftStairWarp(a0)) - { - *a1 = -17; - *a2 = 3; - } - else - { - *a1 = 0; - *a2 = 0; - } -} - -static bool8 WaitStairExitMovementFinished(s16 *a0, s16 *a1, s16 *a2, s16 *a3, s16 *a4) -{ - struct Sprite *sprite; - sprite = &gSprites[gPlayerAvatar.spriteId]; - if (*a4 != 0) - { - *a2 += *a0; - *a3 += *a1; - sprite->x2 = *a2 >> 5; - sprite->y2 = *a3 >> 5; - (*a4)--; - return TRUE; - } - else - { - sprite->x2 = 0; - sprite->y2 = 0; - return FALSE; - } -} - -static void ExitStairsMovement(s16 *a0, s16 *a1, s16 *a2, s16 *a3, s16 *a4) -{ - s16 x, y; - u8 behavior; - s32 r1; - struct Sprite *sprite; - - PlayerGetDestCoords(&x, &y); - behavior = MapGridGetMetatileBehaviorAt(x, y); - if (MetatileBehavior_IsDirectionalDownRightStairWarp(behavior) || MetatileBehavior_IsDirectionalUpRightStairWarp(behavior)) - r1 = 3; - else - r1 = 4; - - ObjectEventForceSetHeldMovement(&gObjectEvents[gPlayerAvatar.objectEventId], GetWalkInPlaceSlowMovementAction(r1)); - GetStairsMovementDirection(behavior, a0, a1); - *a2 = *a0 * 16; - *a3 = *a1 * 16; - *a4 = 16; - sprite = &gSprites[gPlayerAvatar.spriteId]; - sprite->x2 = *a2 >> 5; - sprite->y2 = *a3 >> 5; - *a0 *= -1; - *a1 *= -1; -} - -static void Task_ExitStairs(u8 taskId) -{ - s16 * data = gTasks[taskId].data; - switch (data[0]) - { - default: - if (WaitForWeatherFadeIn() == TRUE) - { - CameraObjectReset(); - UnlockPlayerFieldControls(); - DestroyTask(taskId); - } - break; - case 0: - Overworld_PlaySpecialMapMusic(); - WarpFadeInScreen(); - LockPlayerFieldControls(); - ExitStairsMovement(&data[1], &data[2], &data[3], &data[4], &data[5]); - data[0]++; - break; - case 1: - if (!WaitStairExitMovementFinished(&data[1], &data[2], &data[3], &data[4], &data[5])) - data[0]++; - break; - } -} - -bool8 IsDirectionalStairWarpMetatileBehavior(u16 metatileBehavior, u8 playerDirection) -{ - switch (playerDirection) - { - case DIR_WEST: - if (MetatileBehavior_IsDirectionalUpLeftStairWarp(metatileBehavior)) - return TRUE; - if (MetatileBehavior_IsDirectionalDownLeftStairWarp(metatileBehavior)) - return TRUE; - break; - case DIR_EAST: - if (MetatileBehavior_IsDirectionalUpRightStairWarp(metatileBehavior)) - return TRUE; - if (MetatileBehavior_IsDirectionalDownRightStairWarp(metatileBehavior)) - return TRUE; - break; - } - return FALSE; -} - enum { FRLG_WHITEOUT_ENTER_MSG_SCREEN, FRLG_WHITEOUT_PRINT_MSG, @@ -1517,86 +1401,236 @@ void FieldCB_RushInjuredPokemonToCenter(void) gTasks[taskId].tState = FRLG_WHITEOUT_ENTER_MSG_SCREEN; } -static void ForceStairsMovement(u16 a0, s16 *a1, s16 *a2) +static void GetStairsMovementDirection(u32 metatileBehavior, s16 *speedX, s16 *speedY) { - ObjectEventForceSetHeldMovement(&gObjectEvents[gPlayerAvatar.objectEventId], GetWalkInPlaceNormalMovementAction(GetPlayerFacingDirection())); - GetStairsMovementDirection(a0, a1, a2); + if (MetatileBehavior_IsDirectionalUpRightStairWarp(metatileBehavior)) + { + *speedX = 16; + *speedY = -10; + } + else if (MetatileBehavior_IsDirectionalUpLeftStairWarp(metatileBehavior)) + { + *speedX = -17; + *speedY = -10; + } + else if (MetatileBehavior_IsDirectionalDownRightStairWarp(metatileBehavior)) + { + *speedX = 17; + *speedY = 3; + } + else if (MetatileBehavior_IsDirectionalDownLeftStairWarp(metatileBehavior)) + { + *speedX = -17; + *speedY = 3; + } + else + { + *speedX = 0; + *speedY = 0; + } } -static void UpdateStairsMovement(s16 a0, s16 a1, s16 *a2, s16 *a3, s16 *a4) +static bool8 WaitStairExitMovementFinished(s16 *speedX, s16 *speedY, s16 *offsetX, s16 *offsetY, s16 *timer) { - struct Sprite *playerSpr = &gSprites[gPlayerAvatar.spriteId]; - struct ObjectEvent *playerObj = &gObjectEvents[gPlayerAvatar.objectEventId]; + struct Sprite *sprite; + sprite = &gSprites[gPlayerAvatar.spriteId]; + if (*timer != 0) + { + *offsetX += *speedX; + *offsetY += *speedY; + sprite->x2 = *offsetX >> 5; + sprite->y2 = *offsetY >> 5; + (*timer)--; + return TRUE; + } + else + { + sprite->x2 = 0; + sprite->y2 = 0; + return FALSE; + } +} - if (a1 > 0 || *a4 > 6) - *a3 += a1; +static void ExitStairsMovement(s16 *speedX, s16 *speedY, s16 *offsetX, s16 *offsetY, s16 *timer) +{ + s16 x, y; + u32 metatileBehavior; + s32 direction; + struct Sprite *sprite; - *a2 += a0; - (*a4)++; - playerSpr->x2 = *a2 >> 5; - playerSpr->y2 = *a3 >> 5; - if (playerObj->heldMovementFinished) - ObjectEventForceSetHeldMovement(playerObj, GetWalkInPlaceNormalMovementAction(GetPlayerFacingDirection())); + PlayerGetDestCoords(&x, &y); + metatileBehavior = MapGridGetMetatileBehaviorAt(x, y); + if (MetatileBehavior_IsDirectionalDownRightStairWarp(metatileBehavior) || MetatileBehavior_IsDirectionalUpRightStairWarp(metatileBehavior)) + direction = DIR_WEST; + else + direction = DIR_EAST; + + ObjectEventForceSetHeldMovement(&gObjectEvents[gPlayerAvatar.objectEventId], GetWalkInPlaceSlowMovementAction(direction)); + GetStairsMovementDirection(metatileBehavior, speedX, speedY); + *offsetX = *speedX * 16; + *offsetY = *speedY * 16; + *timer = 16; + sprite = &gSprites[gPlayerAvatar.spriteId]; + sprite->x2 = *offsetX >> 5; + sprite->y2 = *offsetY >> 5; + *speedX *= -1; + *speedY *= -1; +} + +#define tState data[0] +#define tSpeedX data[1] +#define tSpeedY data[2] +#define tOffsetX data[3] +#define tOffsetY data[4] +#define tTimer data[5] + +static void Task_ExitStairs(u8 taskId) +{ + s16 * data = gTasks[taskId].data; + switch (tState) + { + default: + if (WaitForWeatherFadeIn() == TRUE) + { + CameraObjectReset(); + UnlockPlayerFieldControls(); + DestroyTask(taskId); + } + break; + case 0: + Overworld_PlaySpecialMapMusic(); + WarpFadeInScreen(); + LockPlayerFieldControls(); + ExitStairsMovement(&tSpeedX, &tSpeedY, &tOffsetX, &tOffsetY, &tTimer); + tState++; + break; + case 1: + if (!WaitStairExitMovementFinished(&tSpeedX, &tSpeedY, &tOffsetX, &tOffsetY, &tTimer)) + tState++; + break; + } +} + +static void ForceStairsMovement(u32 metatileBehavior, s16 *speedX, s16 *speedY) +{ + ObjectEventForceSetHeldMovement(&gObjectEvents[gPlayerAvatar.objectEventId], GetWalkInPlaceNormalMovementAction(GetPlayerFacingDirection())); + GetStairsMovementDirection(metatileBehavior, speedX, speedY); +} +#undef tSpeedX +#undef tSpeedY +#undef tOffsetX +#undef tOffsetY +#undef tTimer + +#define tMetatileBehavior data[1] +#define tSpeedX data[2] +#define tSpeedY data[3] +#define tOffsetX data[4] +#define tOffsetY data[5] +#define tTimer data[6] +#define tDelay data[15] + +static void UpdateStairsMovement(s16 speedX, s16 speedY, s16 *offsetX, s16 *offsetY, s16 *timer) +{ + struct Sprite *playerSprite = &gSprites[gPlayerAvatar.spriteId]; + struct ObjectEvent *playerObjectEvent = &gObjectEvents[gPlayerAvatar.objectEventId]; + + if (speedY > 0 || *timer > 6) + *offsetY += speedY; + + *offsetX += speedX; + (*timer)++; + playerSprite->x2 = *offsetX >> 5; + playerSprite->y2 = *offsetY >> 5; + if (playerObjectEvent->heldMovementFinished) + ObjectEventForceSetHeldMovement(playerObjectEvent, GetWalkInPlaceNormalMovementAction(GetPlayerFacingDirection())); } static void Task_StairWarp(u8 taskId) { s16 * data = gTasks[taskId].data; - struct ObjectEvent *playerObj = &gObjectEvents[gPlayerAvatar.objectEventId]; - struct Sprite *playerSpr = &gSprites[gPlayerAvatar.spriteId]; + struct ObjectEvent *playerObjectEvent = &gObjectEvents[gPlayerAvatar.objectEventId]; + struct Sprite *playerSprite = &gSprites[gPlayerAvatar.spriteId]; - switch (data[0]) + switch (tState) { - case 0: - LockPlayerFieldControls(); - FreezeObjectEvents(); - CameraObjectFreeze(); - data[0]++; - break; - case 1: - if (!ObjectEventIsMovementOverridden(playerObj) || ObjectEventClearHeldMovementIfFinished(playerObj)) - { - if (data[15] != 0) - data[15]--; - else + case 0: + LockPlayerFieldControls(); + FreezeObjectEvents(); + CameraObjectFreeze(); + tState++; + break; + case 1: + if (!ObjectEventIsMovementOverridden(playerObjectEvent) || ObjectEventClearHeldMovementIfFinished(playerObjectEvent)) { - TryFadeOutOldMapMusic(); - PlayRainStoppingSoundEffect(); - playerSpr->oam.priority = 1; - ForceStairsMovement(data[1], &data[2], &data[3]); - PlaySE(SE_EXIT); - data[0]++; + if (tDelay != 0) + tDelay--; + else + { + TryFadeOutOldMapMusic(); + PlayRainStoppingSoundEffect(); + playerSprite->oam.priority = 1; + ForceStairsMovement(tMetatileBehavior, &tSpeedX, &tSpeedY); + PlaySE(SE_EXIT); + tState++; + } } - } - break; - case 2: - UpdateStairsMovement(data[2], data[3], &data[4], &data[5], &data[6]); - data[15]++; - if (data[15] >= 12) - { - WarpFadeOutScreen(); - data[0]++; - } - break; - case 3: - UpdateStairsMovement(data[2], data[3], &data[4], &data[5], &data[6]); - if (!PaletteFadeActive() && BGMusicStopped()) - data[0]++; - break; - default: - gFieldCallback = FieldCB_DefaultWarpExit; - WarpIntoMap(); - SetMainCallback2(CB2_LoadMap); - DestroyTask(taskId); - break; + break; + case 2: + UpdateStairsMovement(tSpeedX, tSpeedY, &tOffsetX, &tOffsetY, &tTimer); + tDelay++; + if (tDelay >= 12) + { + WarpFadeOutScreen(); + tState++; + } + break; + case 3: + UpdateStairsMovement(tSpeedX, tSpeedY, &tOffsetX, &tOffsetY, &tTimer); + if (!PaletteFadeActive() && BGMusicStopped()) + tState++; + break; + default: + gFieldCallback = FieldCB_DefaultWarpExit; + WarpIntoMap(); + SetMainCallback2(CB2_LoadMap); + DestroyTask(taskId); + break; } } void DoStairWarp(u16 metatileBehavior, u16 delay) { u8 taskId = CreateTask(Task_StairWarp, 10); - gTasks[taskId].data[1] = metatileBehavior; - gTasks[taskId].data[15] = delay; + gTasks[taskId].tMetatileBehavior = metatileBehavior; + gTasks[taskId].tDelay = delay; Task_StairWarp(taskId); } +#undef tMetatileBehavior +#undef tSpeedX +#undef tSpeedY +#undef tOffsetX +#undef tOffsetY +#undef tTimer +#undef tDelay + +bool32 IsDirectionalStairWarpMetatileBehavior(u16 metatileBehavior, u8 playerDirection) +{ + switch (playerDirection) + { + case DIR_WEST: + if (MetatileBehavior_IsDirectionalUpLeftStairWarp(metatileBehavior)) + return TRUE; + if (MetatileBehavior_IsDirectionalDownLeftStairWarp(metatileBehavior)) + return TRUE; + break; + case DIR_EAST: + if (MetatileBehavior_IsDirectionalUpRightStairWarp(metatileBehavior)) + return TRUE; + if (MetatileBehavior_IsDirectionalDownRightStairWarp(metatileBehavior)) + return TRUE; + break; + } + return FALSE; +} diff --git a/src/metatile_behavior.c b/src/metatile_behavior.c index f5e438042a..d165d702ab 100644 --- a/src/metatile_behavior.c +++ b/src/metatile_behavior.c @@ -1435,7 +1435,10 @@ bool8 MetatileBehavior_IsDirectionalDownLeftStairWarp(u8 metatileBehavior) bool8 MetatileBehavior_IsDirectionalStairWarp(u8 metatileBehavior) { - if (metatileBehavior >= MB_UP_RIGHT_STAIR_WARP && metatileBehavior <= MB_DOWN_LEFT_STAIR_WARP) + if (metatileBehavior == MB_UP_RIGHT_STAIR_WARP + || metatileBehavior == MB_UP_LEFT_STAIR_WARP + || metatileBehavior == MB_DOWN_RIGHT_STAIR_WARP + || metatileBehavior == MB_DOWN_LEFT_STAIR_WARP) return TRUE; else return FALSE; From cf2f85bdd71588b0c6fc25b299295b3c87edfd64 Mon Sep 17 00:00:00 2001 From: pkmnsnfrn Date: Fri, 27 Sep 2024 17:08:24 -0700 Subject: [PATCH 07/11] Fixed identation per https://github.com/rh-hideout/pokeemerald-expansion/pull/5278\#discussion_r1779192846 https://github.com/rh-hideout/pokeemerald-expansion/pull/5278#discussion_r1779195689 https://github.com/rh-hideout/pokeemerald-expansion/pull/5278#discussion_r1779196484 --- src/field_screen_effect.c | 148 +++++++++++++++++++------------------- 1 file changed, 74 insertions(+), 74 deletions(-) diff --git a/src/field_screen_effect.c b/src/field_screen_effect.c index 0839dc6bb2..cd1dfdf032 100644 --- a/src/field_screen_effect.c +++ b/src/field_screen_effect.c @@ -1316,21 +1316,21 @@ static bool32 PrintWhiteOutRecoveryMessage(u8 taskId, const u8 *text, u32 x, u32 switch (gTasks[taskId].tPrintState) { - case 0: - FillWindowPixelBuffer(windowId, PIXEL_FILL(0)); - StringExpandPlaceholders(gStringVar4, text); - AddTextPrinterParameterized4(windowId, FONT_NORMAL, x, y, 1, 0, sWhiteoutTextColors, 1, gStringVar4); - gTextFlags.canABSpeedUpPrint = FALSE; - gTasks[taskId].tPrintState = 1; - break; - case 1: - RunTextPrinters(); - if (!IsTextPrinterActive(windowId)) - { - gTasks[taskId].tPrintState = 0; - return TRUE; - } - break; + case 0: + FillWindowPixelBuffer(windowId, PIXEL_FILL(0)); + StringExpandPlaceholders(gStringVar4, text); + AddTextPrinterParameterized4(windowId, FONT_NORMAL, x, y, 1, 0, sWhiteoutTextColors, 1, gStringVar4); + gTextFlags.canABSpeedUpPrint = FALSE; + gTasks[taskId].tPrintState = 1; + break; + case 1: + RunTextPrinters(); + if (!IsTextPrinterActive(windowId)) + { + gTasks[taskId].tPrintState = 0; + return TRUE; + } + break; } return FALSE; } @@ -1489,25 +1489,25 @@ static void Task_ExitStairs(u8 taskId) s16 * data = gTasks[taskId].data; switch (tState) { - default: - if (WaitForWeatherFadeIn() == TRUE) - { - CameraObjectReset(); - UnlockPlayerFieldControls(); - DestroyTask(taskId); - } - break; - case 0: - Overworld_PlaySpecialMapMusic(); - WarpFadeInScreen(); - LockPlayerFieldControls(); - ExitStairsMovement(&tSpeedX, &tSpeedY, &tOffsetX, &tOffsetY, &tTimer); + default: + if (WaitForWeatherFadeIn() == TRUE) + { + CameraObjectReset(); + UnlockPlayerFieldControls(); + DestroyTask(taskId); + } + break; + case 0: + Overworld_PlaySpecialMapMusic(); + WarpFadeInScreen(); + LockPlayerFieldControls(); + ExitStairsMovement(&tSpeedX, &tSpeedY, &tOffsetX, &tOffsetY, &tTimer); + tState++; + break; + case 1: + if (!WaitStairExitMovementFinished(&tSpeedX, &tSpeedY, &tOffsetX, &tOffsetY, &tTimer)) tState++; - break; - case 1: - if (!WaitStairExitMovementFinished(&tSpeedX, &tSpeedY, &tOffsetX, &tOffsetY, &tTimer)) - tState++; - break; + break; } } @@ -1554,48 +1554,48 @@ static void Task_StairWarp(u8 taskId) switch (tState) { - case 0: - LockPlayerFieldControls(); - FreezeObjectEvents(); - CameraObjectFreeze(); + case 0: + LockPlayerFieldControls(); + FreezeObjectEvents(); + CameraObjectFreeze(); + tState++; + break; + case 1: + if (!ObjectEventIsMovementOverridden(playerObjectEvent) || ObjectEventClearHeldMovementIfFinished(playerObjectEvent)) + { + if (tDelay != 0) + tDelay--; + else + { + TryFadeOutOldMapMusic(); + PlayRainStoppingSoundEffect(); + playerSprite->oam.priority = 1; + ForceStairsMovement(tMetatileBehavior, &tSpeedX, &tSpeedY); + PlaySE(SE_EXIT); + tState++; + } + } + break; + case 2: + UpdateStairsMovement(tSpeedX, tSpeedY, &tOffsetX, &tOffsetY, &tTimer); + tDelay++; + if (tDelay >= 12) + { + WarpFadeOutScreen(); tState++; - break; - case 1: - if (!ObjectEventIsMovementOverridden(playerObjectEvent) || ObjectEventClearHeldMovementIfFinished(playerObjectEvent)) - { - if (tDelay != 0) - tDelay--; - else - { - TryFadeOutOldMapMusic(); - PlayRainStoppingSoundEffect(); - playerSprite->oam.priority = 1; - ForceStairsMovement(tMetatileBehavior, &tSpeedX, &tSpeedY); - PlaySE(SE_EXIT); - tState++; - } - } - break; - case 2: - UpdateStairsMovement(tSpeedX, tSpeedY, &tOffsetX, &tOffsetY, &tTimer); - tDelay++; - if (tDelay >= 12) - { - WarpFadeOutScreen(); - tState++; - } - break; - case 3: - UpdateStairsMovement(tSpeedX, tSpeedY, &tOffsetX, &tOffsetY, &tTimer); - if (!PaletteFadeActive() && BGMusicStopped()) - tState++; - break; - default: - gFieldCallback = FieldCB_DefaultWarpExit; - WarpIntoMap(); - SetMainCallback2(CB2_LoadMap); - DestroyTask(taskId); - break; + } + break; + case 3: + UpdateStairsMovement(tSpeedX, tSpeedY, &tOffsetX, &tOffsetY, &tTimer); + if (!PaletteFadeActive() && BGMusicStopped()) + tState++; + break; + default: + gFieldCallback = FieldCB_DefaultWarpExit; + WarpIntoMap(); + SetMainCallback2(CB2_LoadMap); + DestroyTask(taskId); + break; } } From 796a5985497985d54ae9720f81e6907c51677f73 Mon Sep 17 00:00:00 2001 From: pkmnsnfrn Date: Fri, 27 Sep 2024 17:10:38 -0700 Subject: [PATCH 08/11] Combined lines per https://github.com/rh-hideout/pokeemerald-expansion/pull/5278\#discussion_r1779193552 --- src/field_screen_effect.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/field_screen_effect.c b/src/field_screen_effect.c index cd1dfdf032..bb49519820 100644 --- a/src/field_screen_effect.c +++ b/src/field_screen_effect.c @@ -1432,8 +1432,7 @@ static void GetStairsMovementDirection(u32 metatileBehavior, s16 *speedX, s16 *s static bool8 WaitStairExitMovementFinished(s16 *speedX, s16 *speedY, s16 *offsetX, s16 *offsetY, s16 *timer) { - struct Sprite *sprite; - sprite = &gSprites[gPlayerAvatar.spriteId]; + struct Sprite *sprite = &gSprites[gPlayerAvatar.spriteId]; if (*timer != 0) { *offsetX += *speedX; From eb1469af1dfd0c0c83aab862a6322bd44256d17e Mon Sep 17 00:00:00 2001 From: pkmnsnfrn Date: Fri, 27 Sep 2024 17:15:05 -0700 Subject: [PATCH 09/11] added curly braces per https://github.com/rh-hideout/pokeemerald-expansion/pull/5278\#discussion_r1779196726 --- src/field_screen_effect.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/field_screen_effect.c b/src/field_screen_effect.c index bb49519820..cd7f51b3da 100644 --- a/src/field_screen_effect.c +++ b/src/field_screen_effect.c @@ -1563,7 +1563,9 @@ static void Task_StairWarp(u8 taskId) if (!ObjectEventIsMovementOverridden(playerObjectEvent) || ObjectEventClearHeldMovementIfFinished(playerObjectEvent)) { if (tDelay != 0) + { tDelay--; + } else { TryFadeOutOldMapMusic(); From 874d4d047002a7651a4767e145c8b71a98996a84 Mon Sep 17 00:00:00 2001 From: pkmnsnfrn Date: Fri, 27 Sep 2024 17:19:58 -0700 Subject: [PATCH 10/11] Removed switch case per https://github.com/rh-hideout/pokeemerald-expansion/pull/5278\#discussion_r1779197182 --- src/field_screen_effect.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/field_screen_effect.c b/src/field_screen_effect.c index cd7f51b3da..073c92f3e0 100644 --- a/src/field_screen_effect.c +++ b/src/field_screen_effect.c @@ -1618,20 +1618,19 @@ void DoStairWarp(u16 metatileBehavior, u16 delay) bool32 IsDirectionalStairWarpMetatileBehavior(u16 metatileBehavior, u8 playerDirection) { - switch (playerDirection) + if (playerDirection == DIR_WEST) { - case DIR_WEST: - if (MetatileBehavior_IsDirectionalUpLeftStairWarp(metatileBehavior)) - return TRUE; - if (MetatileBehavior_IsDirectionalDownLeftStairWarp(metatileBehavior)) - return TRUE; - break; - case DIR_EAST: - if (MetatileBehavior_IsDirectionalUpRightStairWarp(metatileBehavior)) - return TRUE; - if (MetatileBehavior_IsDirectionalDownRightStairWarp(metatileBehavior)) - return TRUE; - break; + if (MetatileBehavior_IsDirectionalUpLeftStairWarp(metatileBehavior)) + return TRUE; + if (MetatileBehavior_IsDirectionalDownLeftStairWarp(metatileBehavior)) + return TRUE; + } + else if (playerDirection == DIR_EAST) + { + if (MetatileBehavior_IsDirectionalUpRightStairWarp(metatileBehavior)) + return TRUE; + if (MetatileBehavior_IsDirectionalDownRightStairWarp(metatileBehavior)) + return TRUE; } return FALSE; } From 580b9e3b84db7a02d58d5ca722f5df5f568059b4 Mon Sep 17 00:00:00 2001 From: Bassoonian Date: Sat, 28 Sep 2024 15:02:51 +0200 Subject: [PATCH 11/11] Update src/metatile_behavior.c --- src/metatile_behavior.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/metatile_behavior.c b/src/metatile_behavior.c index 9d96fc4a64..ef349be7cf 100644 --- a/src/metatile_behavior.c +++ b/src/metatile_behavior.c @@ -1406,7 +1406,7 @@ bool8 MetatileBehavior_IsTrainerHillTimer(u8 metatileBehavior) bool8 MetatileBehavior_IsDirectionalUpRightStairWarp(u8 metatileBehavior) { - if(metatileBehavior == MB_UP_RIGHT_STAIR_WARP) + if (metatileBehavior == MB_UP_RIGHT_STAIR_WARP) return TRUE; else return FALSE;