From a1cc7d2bd69b58f04dd2765bbebc4cfb927876fa Mon Sep 17 00:00:00 2001 From: GriffinR Date: Sun, 19 Jul 2020 14:12:38 -0400 Subject: [PATCH 1/4] Document faraway island --- data/maps/FarawayIsland_Interior/scripts.inc | 52 ++--- data/specials.inc | 4 +- include/faraway_island.h | 2 +- src/event_object_movement.c | 2 +- src/faraway_island.c | 191 ++++++++++--------- 5 files changed, 136 insertions(+), 115 deletions(-) diff --git a/data/maps/FarawayIsland_Interior/scripts.inc b/data/maps/FarawayIsland_Interior/scripts.inc index cad875b65..2a06ffdfa 100644 --- a/data/maps/FarawayIsland_Interior/scripts.inc +++ b/data/maps/FarawayIsland_Interior/scripts.inc @@ -8,24 +8,24 @@ FarawayIsland_Interior_MapScripts:: @ 8267CFA .byte 0 FarawayIsland_Interior_OnReturnToField: @ 8267D0F - call_if_set FLAG_SYS_CTRL_OBJ_DELETE, FarawayIsland_Interior_EventScript_267D19 + call_if_set FLAG_SYS_CTRL_OBJ_DELETE, FarawayIsland_Interior_EventScript_TrySetMewAboveGrass end -FarawayIsland_Interior_EventScript_267D19:: @ 8267D19 +FarawayIsland_Interior_EventScript_TrySetMewAboveGrass:: @ 8267D19 specialvar VAR_RESULT, GetBattleOutcome compare VAR_RESULT, B_OUTCOME_WON - goto_if_eq FarawayIsland_Interior_EventScript_267D4B + goto_if_eq FarawayIsland_Interior_EventScript_SetMewAboveGrass compare VAR_RESULT, B_OUTCOME_RAN - goto_if_eq FarawayIsland_Interior_EventScript_267D4B + goto_if_eq FarawayIsland_Interior_EventScript_SetMewAboveGrass compare VAR_RESULT, B_OUTCOME_PLAYER_TELEPORTED - goto_if_eq FarawayIsland_Interior_EventScript_267D4B + goto_if_eq FarawayIsland_Interior_EventScript_SetMewAboveGrass compare VAR_RESULT, B_OUTCOME_MON_TELEPORTED - goto_if_eq FarawayIsland_Interior_EventScript_267D4B + goto_if_eq FarawayIsland_Interior_EventScript_SetMewAboveGrass return -FarawayIsland_Interior_EventScript_267D4B:: @ 8267D4B +FarawayIsland_Interior_EventScript_SetMewAboveGrass:: @ 8267D4B setvar VAR_0x8004, 1 - special sub_81D4A90 + special SetMewAboveGrass return FarawayIsland_Interior_OnResume: @ 8267D54 @@ -81,7 +81,7 @@ FarawayIsland_Interior_Movement_MewAppear: @ 8267DD4 set_visible step_end -FarawayIsland_Interior_Movement_MewHideDown: @ 8267DD6 +FarawayIsland_Interior_Movement_MewFloatUpNorth: @ 8267DD6 lock_facing_direction walk_fast_up walk_fast_up @@ -90,7 +90,7 @@ FarawayIsland_Interior_Movement_MewHideDown: @ 8267DD6 walk_in_place_down step_end -FarawayIsland_Interior_Movement_MewHideUp: @ 8267DDD +FarawayIsland_Interior_Movement_MewFloatUpSouth: @ 8267DDD lock_facing_direction walk_fast_up walk_fast_up @@ -99,7 +99,7 @@ FarawayIsland_Interior_Movement_MewHideUp: @ 8267DDD walk_in_place_up step_end -FarawayIsland_Interior_Movement_MewHideRight: @ 8267DE4 +FarawayIsland_Interior_Movement_MewFloatUpWest: @ 8267DE4 lock_facing_direction walk_fast_up walk_fast_up @@ -108,7 +108,7 @@ FarawayIsland_Interior_Movement_MewHideRight: @ 8267DE4 walk_in_place_right step_end -FarawayIsland_Interior_Movement_MewHideLeft: @ 8267DEB +FarawayIsland_Interior_Movement_MewFloatUpEast: @ 8267DEB lock_facing_direction walk_fast_up walk_fast_up @@ -123,19 +123,19 @@ FarawayIsland_Interior_EventScript_Mew:: @ 8267DF2 applymovement LOCALID_MEW, FarawayIsland_Interior_Movement_MewAppear waitmovement 0 setvar VAR_0x8004, 0 - special sub_81D4A90 + special SetMewAboveGrass message FarawayIsland_Interior_Text_Mew waitse playmoncry SPECIES_MEW, 2 compare VAR_FACING, DIR_NORTH - call_if_eq FarawayIsland_Interior_EventScript_MewHideDown + call_if_eq FarawayIsland_Interior_EventScript_FoundMewNorth compare VAR_FACING, DIR_SOUTH - call_if_eq FarawayIsland_Interior_EventScript_MewHideUp + call_if_eq FarawayIsland_Interior_EventScript_FoundMewSouth compare VAR_FACING, DIR_WEST - call_if_eq FarawayIsland_Interior_EventScript_MewHideRight + call_if_eq FarawayIsland_Interior_EventScript_FoundMewWest compare VAR_FACING, DIR_EAST - call_if_eq FarawayIsland_Interior_EventScript_MewHideLeft - special sub_81D4BEC + call_if_eq FarawayIsland_Interior_EventScript_FoundMewEast + special DestroyMewEmergingGrassSprite delay 40 waitmoncry setvar VAR_0x8004, SPECIES_MEW @@ -170,23 +170,23 @@ FarawayIsland_Interior_EventScript_PlayerOrMewRan:: @ 8267EA4 goto Common_EventScript_LegendaryFlewAway end -FarawayIsland_Interior_EventScript_MewHideDown:: @ 8267EAF - applymovement LOCALID_MEW, FarawayIsland_Interior_Movement_MewHideDown +FarawayIsland_Interior_EventScript_FoundMewNorth:: @ 8267EAF + applymovement LOCALID_MEW, FarawayIsland_Interior_Movement_MewFloatUpNorth waitmovement 0 return -FarawayIsland_Interior_EventScript_MewHideUp:: @ 8267EBA - applymovement LOCALID_MEW, FarawayIsland_Interior_Movement_MewHideUp +FarawayIsland_Interior_EventScript_FoundMewSouth:: @ 8267EBA + applymovement LOCALID_MEW, FarawayIsland_Interior_Movement_MewFloatUpSouth waitmovement 0 return -FarawayIsland_Interior_EventScript_MewHideRight:: @ 8267EC5 - applymovement LOCALID_MEW, FarawayIsland_Interior_Movement_MewHideRight +FarawayIsland_Interior_EventScript_FoundMewWest:: @ 8267EC5 + applymovement LOCALID_MEW, FarawayIsland_Interior_Movement_MewFloatUpWest waitmovement 0 return -FarawayIsland_Interior_EventScript_MewHideLeft:: @ 8267ED0 - applymovement LOCALID_MEW, FarawayIsland_Interior_Movement_MewHideLeft +FarawayIsland_Interior_EventScript_FoundMewEast:: @ 8267ED0 + applymovement LOCALID_MEW, FarawayIsland_Interior_Movement_MewFloatUpEast waitmovement 0 return diff --git a/data/specials.inc b/data/specials.inc index 0f78f981f..d7d1897d8 100644 --- a/data/specials.inc +++ b/data/specials.inc @@ -511,14 +511,14 @@ gSpecials:: @ 81DBA64 def_special ScriptMenu_CreateLilycoveSSTidalMultichoice def_special GetLilycoveSSTidalSelection def_special TurnOnTVScreen - def_special sub_81D4A90 + def_special SetMewAboveGrass def_special ShouldDistributeEonTicket def_special LinkRetireStatusWithBattleTowerPartner def_special sub_813B534 def_special CallTrainerHillFunction def_special Script_DoRayquazaScene @ Listed twice def_special LoopWingFlapSE - def_special sub_81D4BEC + def_special DestroyMewEmergingGrassSprite def_special ShowBerryCrushRankings def_special TryBufferWaldaPhrase def_special DoWaldaNamingScreen diff --git a/include/faraway_island.h b/include/faraway_island.h index 084b5a277..a5243c6a7 100755 --- a/include/faraway_island.h +++ b/include/faraway_island.h @@ -2,7 +2,7 @@ #define GUARD_FARAWAY_ISLAND_H u32 GetMewMoveDirection(void); -bool8 sub_81D4A58(struct ObjectEvent*); +bool8 ShouldMewShakeGrass(struct ObjectEvent*); void UpdateFarawayIslandStepCounter(void); bool8 ObjectEventIsFarawayIslandMew(struct ObjectEvent *); bool8 IsMewPlayingHideAndSeek(void); diff --git a/src/event_object_movement.c b/src/event_object_movement.c index ad839e006..de5536240 100644 --- a/src/event_object_movement.c +++ b/src/event_object_movement.c @@ -8124,7 +8124,7 @@ static void DoFlaggedGroundEffects(struct ObjectEvent *objEvent, struct Sprite * { u8 i; - if (ObjectEventIsFarawayIslandMew(objEvent) == TRUE && !sub_81D4A58(objEvent)) + if (ObjectEventIsFarawayIslandMew(objEvent) == TRUE && !ShouldMewShakeGrass(objEvent)) return; for (i = 0; i < ARRAY_COUNT(sGroundEffectFuncs); i++, flags >>= 1) diff --git a/src/faraway_island.c b/src/faraway_island.c index 06e47cd21..57d31057f 100755 --- a/src/faraway_island.c +++ b/src/faraway_island.c @@ -9,15 +9,15 @@ #include "constants/maps.h" #include "constants/metatile_behaviors.h" -static u8 sub_81D4890(u8); -static bool8 sub_81D4C14(struct ObjectEvent*, u8); -static u8 sub_81D4C9C(struct ObjectEvent*, u8); -static u8 sub_81D4C58(struct ObjectEvent*, u8); -static u8 sub_81D4CE0(struct ObjectEvent*, u8); -static u8 sub_81D4D24(u8); -static bool8 CanMewWalkToCoords(s16, s16); +static u8 GetValidMewMoveDirection(u8); +static bool8 ShouldMewMoveNorth(struct ObjectEvent*, u8); +static bool8 ShouldMewMoveSouth(struct ObjectEvent*, u8); +static bool8 ShouldMewMoveEast(struct ObjectEvent*, u8); +static bool8 ShouldMewMoveWest(struct ObjectEvent*, u8); +static u8 GetRandomMewDirectionCandidate(u8); +static bool8 CanMewMoveToCoords(s16, s16); -static EWRAM_DATA u8 sUnknown_0203CF50 = 0; +static EWRAM_DATA u8 sGrassSpriteId = 0; static s16 sPlayerToMewDeltaX; static s16 sPlayerToMewDeltaY; @@ -28,10 +28,10 @@ extern const struct SpriteTemplate *const gFieldEffectObjectTemplatePointers[]; static const s16 sFarawayIslandRockCoords[4][2] = { - {21, 16}, - {25, 16}, - {16, 17}, - {20, 20}, + {14 + 7, 9 + 7}, + {18 + 7, 9 + 7}, + { 9 + 7, 10 + 7}, + {13 + 7, 13 + 7}, }; static u8 GetMewObjectEventId(void) @@ -41,10 +41,12 @@ static u8 GetMewObjectEventId(void) return objectEventId; } +// When the player enters Faraway Island interior it begins a "hide and seek" minigame where Mew disappears into the grass +// This function returns the direction Mew will take a step, and is run every time the player takes a step u32 GetMewMoveDirection(void) { u8 i; - int skip; + int mewSafeFromTrap; struct ObjectEvent *mew = &gObjectEvents[GetMewObjectEventId()]; sPlayerToMewDeltaX = gObjectEvents[gPlayerAvatar.objectEventId].previousCoords.x - mew->currentCoords.x; @@ -52,43 +54,47 @@ u32 GetMewMoveDirection(void) for (i = 0; i < ARRAY_COUNT(sMewDirectionCandidates); i++) sMewDirectionCandidates[i] = DIR_NONE; + // Player hasn't moved (just facing new direction), don't move if (gObjectEvents[gPlayerAvatar.objectEventId].previousCoords.x == gObjectEvents[gPlayerAvatar.objectEventId].currentCoords.x && gObjectEvents[gPlayerAvatar.objectEventId].previousCoords.y == gObjectEvents[gPlayerAvatar.objectEventId].currentCoords.y) { return DIR_NONE; } + // Mew is invisible except for every 8th step if (VarGet(VAR_FARAWAY_ISLAND_STEP_COUNTER) % 8 == 0) - mew->invisible = 0; + mew->invisible = FALSE; else - mew->invisible = 1; + mew->invisible = TRUE; + // Mew will stay in place for 1 step after its visible if (VarGet(VAR_FARAWAY_ISLAND_STEP_COUNTER) % 9 == 0) return DIR_NONE; + // Below loop is for Mew to try to avoid getting trapped between the player and a rock for (i = 0; i < ARRAY_COUNT(sFarawayIslandRockCoords); i++) { if (gObjectEvents[gPlayerAvatar.objectEventId].previousCoords.x == sFarawayIslandRockCoords[i][0]) { - skip = 0; + mewSafeFromTrap = FALSE; if (gObjectEvents[gPlayerAvatar.objectEventId].previousCoords.y < sFarawayIslandRockCoords[i][1]) { if (mew->currentCoords.y <= sFarawayIslandRockCoords[i][1]) - skip = 1; + mewSafeFromTrap = TRUE; } else { if (mew->currentCoords.y >= sFarawayIslandRockCoords[i][1]) - skip = 1; + mewSafeFromTrap = TRUE; } - if (!skip) + if (!mewSafeFromTrap) { if (sPlayerToMewDeltaX > 0) { if (mew->currentCoords.x + 1 == gObjectEvents[gPlayerAvatar.objectEventId].previousCoords.x) { - if (CanMewWalkToCoords(mew->currentCoords.x + 1, mew->currentCoords.y)) + if (CanMewMoveToCoords(mew->currentCoords.x + 1, mew->currentCoords.y)) return DIR_EAST; } } @@ -96,7 +102,7 @@ u32 GetMewMoveDirection(void) { if (mew->currentCoords.x - 1 == gObjectEvents[gPlayerAvatar.objectEventId].previousCoords.x) { - if (CanMewWalkToCoords(mew->currentCoords.x - 1, mew->currentCoords.y)) + if (CanMewMoveToCoords(mew->currentCoords.x - 1, mew->currentCoords.y)) return DIR_WEST; } } @@ -105,12 +111,12 @@ u32 GetMewMoveDirection(void) { if (sPlayerToMewDeltaY > 0) { - if (CanMewWalkToCoords(mew->currentCoords.x, mew->currentCoords.y - 1)) + if (CanMewMoveToCoords(mew->currentCoords.x, mew->currentCoords.y - 1)) return DIR_NORTH; } else { - if (CanMewWalkToCoords(mew->currentCoords.x, mew->currentCoords.y + 1)) + if (CanMewMoveToCoords(mew->currentCoords.x, mew->currentCoords.y + 1)) return DIR_SOUTH; } } @@ -119,25 +125,25 @@ u32 GetMewMoveDirection(void) if (gObjectEvents[gPlayerAvatar.objectEventId].previousCoords.y == sFarawayIslandRockCoords[i][1]) { - skip = 0; + mewSafeFromTrap = FALSE; if (gObjectEvents[gPlayerAvatar.objectEventId].previousCoords.x < sFarawayIslandRockCoords[i][0]) { if (mew->currentCoords.x <= sFarawayIslandRockCoords[i][0]) - skip = 1; + mewSafeFromTrap = TRUE; } else { if (mew->currentCoords.x >= sFarawayIslandRockCoords[i][0]) - skip = 1; + mewSafeFromTrap = TRUE; } - if (!skip) + if (!mewSafeFromTrap) { if (sPlayerToMewDeltaY > 0) { if (mew->currentCoords.y + 1 == gObjectEvents[gPlayerAvatar.objectEventId].previousCoords.y) { - if (CanMewWalkToCoords(mew->currentCoords.x, mew->currentCoords.y + 1)) + if (CanMewMoveToCoords(mew->currentCoords.x, mew->currentCoords.y + 1)) return DIR_SOUTH; } } @@ -145,7 +151,7 @@ u32 GetMewMoveDirection(void) { if (mew->currentCoords.y - 1 == gObjectEvents[gPlayerAvatar.objectEventId].previousCoords.y) { - if (CanMewWalkToCoords(mew->currentCoords.x, mew->currentCoords.y - 1)) + if (CanMewMoveToCoords(mew->currentCoords.x, mew->currentCoords.y - 1)) return DIR_NORTH; } } @@ -154,12 +160,12 @@ u32 GetMewMoveDirection(void) { if (sPlayerToMewDeltaX > 0) { - if (CanMewWalkToCoords(mew->currentCoords.x - 1, mew->currentCoords.y)) + if (CanMewMoveToCoords(mew->currentCoords.x - 1, mew->currentCoords.y)) return DIR_WEST; } else { - if (CanMewWalkToCoords(mew->currentCoords.x + 1, mew->currentCoords.y)) + if (CanMewMoveToCoords(mew->currentCoords.x + 1, mew->currentCoords.y)) return DIR_EAST; } } @@ -167,92 +173,101 @@ u32 GetMewMoveDirection(void) } } - if (sub_81D4C14(mew, 0)) + // Check if Mew can move in any direction without getting closer to the player + // If so load into sMewDirectionCandidates + // If Mew can move in two of the checked directions, choose one randomly + if (ShouldMewMoveNorth(mew, 0)) { - if (sub_81D4C58(mew, 1)) - return sub_81D4D24(2); - else if (sub_81D4CE0(mew, 1)) - return sub_81D4D24(2); + if (ShouldMewMoveEast(mew, 1)) + return GetRandomMewDirectionCandidate(2); + else if (ShouldMewMoveWest(mew, 1)) + return GetRandomMewDirectionCandidate(2); else return DIR_NORTH; } - if (sub_81D4C9C(mew, 0)) + if (ShouldMewMoveSouth(mew, 0)) { - if (sub_81D4C58(mew, 1)) - return sub_81D4D24(2); - else if (sub_81D4CE0(mew, 1)) - return sub_81D4D24(2); + if (ShouldMewMoveEast(mew, 1)) + return GetRandomMewDirectionCandidate(2); + else if (ShouldMewMoveWest(mew, 1)) + return GetRandomMewDirectionCandidate(2); else return DIR_SOUTH; } - if (sub_81D4C58(mew, 0)) + if (ShouldMewMoveEast(mew, 0)) { - if (sub_81D4C14(mew, 1)) - return sub_81D4D24(2); - else if (sub_81D4C9C(mew, 1)) - return sub_81D4D24(2); + if (ShouldMewMoveNorth(mew, 1)) + return GetRandomMewDirectionCandidate(2); + else if (ShouldMewMoveSouth(mew, 1)) + return GetRandomMewDirectionCandidate(2); else return DIR_EAST; } - if (sub_81D4CE0(mew, 0)) + if (ShouldMewMoveWest(mew, 0)) { - if (sub_81D4C14(mew, 1)) - return sub_81D4D24(2); - else if (sub_81D4C9C(mew, 1)) - return sub_81D4D24(2); + if (ShouldMewMoveNorth(mew, 1)) + return GetRandomMewDirectionCandidate(2); + else if (ShouldMewMoveSouth(mew, 1)) + return GetRandomMewDirectionCandidate(2); else return DIR_WEST; } + // If this point is reached, Mew cannot move without getting closer to the player + + // Avoid player on same Y, try move North/South if (sPlayerToMewDeltaY == 0) { if (gObjectEvents[gPlayerAvatar.objectEventId].currentCoords.y > mew->currentCoords.y) { - if (CanMewWalkToCoords(mew->currentCoords.x, mew->currentCoords.y - 1)) + if (CanMewMoveToCoords(mew->currentCoords.x, mew->currentCoords.y - 1)) return DIR_NORTH; } if (gObjectEvents[gPlayerAvatar.objectEventId].currentCoords.y < mew->currentCoords.y) { - if (CanMewWalkToCoords(mew->currentCoords.x, mew->currentCoords.y + 1)) + if (CanMewMoveToCoords(mew->currentCoords.x, mew->currentCoords.y + 1)) return DIR_SOUTH; } - if (CanMewWalkToCoords(mew->currentCoords.x, mew->currentCoords.y - 1)) + if (CanMewMoveToCoords(mew->currentCoords.x, mew->currentCoords.y - 1)) return DIR_NORTH; - if (CanMewWalkToCoords(mew->currentCoords.x, mew->currentCoords.y + 1)) + if (CanMewMoveToCoords(mew->currentCoords.x, mew->currentCoords.y + 1)) return DIR_SOUTH; } + // Avoid player on same X, try move West/East if (sPlayerToMewDeltaX == 0) { if (gObjectEvents[gPlayerAvatar.objectEventId].currentCoords.x > mew->currentCoords.x) { - if (CanMewWalkToCoords(mew->currentCoords.x - 1, mew->currentCoords.y)) + if (CanMewMoveToCoords(mew->currentCoords.x - 1, mew->currentCoords.y)) return DIR_WEST; } if (gObjectEvents[gPlayerAvatar.objectEventId].currentCoords.x < mew->currentCoords.x) { - if (CanMewWalkToCoords(mew->currentCoords.x + 1, mew->currentCoords.y)) + if (CanMewMoveToCoords(mew->currentCoords.x + 1, mew->currentCoords.y)) return DIR_EAST; } - if (CanMewWalkToCoords(mew->currentCoords.x + 1, mew->currentCoords.y)) + if (CanMewMoveToCoords(mew->currentCoords.x + 1, mew->currentCoords.y)) return DIR_EAST; - if (CanMewWalkToCoords(mew->currentCoords.x - 1, mew->currentCoords.y)) + if (CanMewMoveToCoords(mew->currentCoords.x - 1, mew->currentCoords.y)) return DIR_WEST; } - return sub_81D4890(DIR_NONE); + // Can't avoid player on axis, move any valid direction + return GetValidMewMoveDirection(DIR_NONE); } -static bool8 CanMewWalkToCoords(s16 x, s16 y) +// Mew can move to any Tall/Long Grass metatile the player isn't currently on +static bool8 CanMewMoveToCoords(s16 x, s16 y) { if (gObjectEvents[gPlayerAvatar.objectEventId].currentCoords.x == x && gObjectEvents[gPlayerAvatar.objectEventId].currentCoords.y == y) @@ -263,7 +278,8 @@ static bool8 CanMewWalkToCoords(s16 x, s16 y) return MetatileBehavior_IsPokeGrass(MapGridGetMetatileBehaviorAt(x, y)); } -static u8 sub_81D4890(u8 ignoredDir) +// Last ditch effort to move, clear move candidates and try all directions again +static u8 GetValidMewMoveDirection(u8 ignoredDir) { u8 i; u8 count = 0; @@ -272,25 +288,25 @@ static u8 sub_81D4890(u8 ignoredDir) for (i = 0; i < ARRAY_COUNT(sMewDirectionCandidates); i++) sMewDirectionCandidates[i] = DIR_NONE; - if (CanMewWalkToCoords(mew->currentCoords.x, mew->currentCoords.y - 1) == TRUE && ignoredDir != DIR_NORTH) + if (CanMewMoveToCoords(mew->currentCoords.x, mew->currentCoords.y - 1) == TRUE && ignoredDir != DIR_NORTH) { sMewDirectionCandidates[count] = DIR_NORTH; count++; } - if (CanMewWalkToCoords(mew->currentCoords.x + 1, mew->currentCoords.y) == TRUE && ignoredDir != DIR_EAST) + if (CanMewMoveToCoords(mew->currentCoords.x + 1, mew->currentCoords.y) == TRUE && ignoredDir != DIR_EAST) { sMewDirectionCandidates[count] = DIR_EAST; count++; } - if (CanMewWalkToCoords(mew->currentCoords.x, mew->currentCoords.y + 1) == TRUE && ignoredDir != DIR_SOUTH) + if (CanMewMoveToCoords(mew->currentCoords.x, mew->currentCoords.y + 1) == TRUE && ignoredDir != DIR_SOUTH) { sMewDirectionCandidates[count] = DIR_SOUTH; count++; } - if (CanMewWalkToCoords(mew->currentCoords.x - 1, mew->currentCoords.y) == TRUE && ignoredDir != DIR_WEST) + if (CanMewMoveToCoords(mew->currentCoords.x - 1, mew->currentCoords.y) == TRUE && ignoredDir != DIR_WEST) { sMewDirectionCandidates[count] = DIR_WEST; count++; @@ -340,7 +356,9 @@ bool8 IsMewPlayingHideAndSeek(void) return FALSE; } -bool8 sub_81D4A58(struct ObjectEvent *objectEvent) +// Every 4th step Mew will shake the grass it steps into +// Otherwise its movement leaves grass undisturbed +bool8 ShouldMewShakeGrass(struct ObjectEvent *objectEvent) { if (VarGet(VAR_FARAWAY_ISLAND_STEP_COUNTER) != 0xFFFF && VarGet(VAR_FARAWAY_ISLAND_STEP_COUNTER) % 4 == 0) @@ -349,22 +367,25 @@ bool8 sub_81D4A58(struct ObjectEvent *objectEvent) return FALSE; } -void sub_81D4A90(void) +void SetMewAboveGrass(void) { s16 x; s16 y; u8 spriteId; struct ObjectEvent *mew = &gObjectEvents[GetMewObjectEventId()]; - mew->invisible = 0; + mew->invisible = FALSE; if (gSpecialVar_0x8004 == 1) { + // For after battle where Mew should still be present (e.g. if ran from battle) mew->fixedPriority = 1; gSprites[mew->spriteId].subspriteMode = SUBSPRITES_IGNORE_PRIORITY; gSprites[mew->spriteId].subpriority = 1; } else { + // Mew emerging from grass when found + // Also do field effect for grass shaking as it emerges VarSet(VAR_FARAWAY_ISLAND_STEP_COUNTER, 0xFFFF); mew->fixedPriority = 1; gSprites[mew->spriteId].subspriteMode = SUBSPRITES_IGNORE_PRIORITY; @@ -377,10 +398,10 @@ void sub_81D4A90(void) x = mew->currentCoords.x; y = mew->currentCoords.y; SetSpritePosToOffsetMapCoords(&x, &y, 8, 8); - sUnknown_0203CF50 = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[15], x, y, gSprites[mew->spriteId].subpriority - 1); - if (sUnknown_0203CF50 != MAX_SPRITES) + sGrassSpriteId = CreateSpriteAtEnd(gFieldEffectObjectTemplatePointers[15], x, y, gSprites[mew->spriteId].subpriority - 1); + if (sGrassSpriteId != MAX_SPRITES) { - struct Sprite *sprite = &gSprites[sUnknown_0203CF50]; + struct Sprite *sprite = &gSprites[sGrassSpriteId]; sprite->coordOffsetEnabled = 1; sprite->oam.priority = 2; sprite->callback = SpriteCallbackDummy; @@ -388,15 +409,15 @@ void sub_81D4A90(void) } } -void sub_81D4BEC(void) +void DestroyMewEmergingGrassSprite(void) { - if (sUnknown_0203CF50 != MAX_SPRITES) - DestroySprite(&gSprites[sUnknown_0203CF50]); + if (sGrassSpriteId != MAX_SPRITES) + DestroySprite(&gSprites[sGrassSpriteId]); } -static bool8 sub_81D4C14(struct ObjectEvent *mew, u8 index) +static bool8 ShouldMewMoveNorth(struct ObjectEvent *mew, u8 index) { - if (sPlayerToMewDeltaY > 0 && CanMewWalkToCoords(mew->currentCoords.x, mew->currentCoords.y - 1)) + if (sPlayerToMewDeltaY > 0 && CanMewMoveToCoords(mew->currentCoords.x, mew->currentCoords.y - 1)) { sMewDirectionCandidates[index] = DIR_NORTH; return TRUE; @@ -405,9 +426,9 @@ static bool8 sub_81D4C14(struct ObjectEvent *mew, u8 index) return FALSE; } -static u8 sub_81D4C58(struct ObjectEvent *mew, u8 index) +static bool8 ShouldMewMoveEast(struct ObjectEvent *mew, u8 index) { - if (sPlayerToMewDeltaX < 0 && CanMewWalkToCoords(mew->currentCoords.x + 1, mew->currentCoords.y)) + if (sPlayerToMewDeltaX < 0 && CanMewMoveToCoords(mew->currentCoords.x + 1, mew->currentCoords.y)) { sMewDirectionCandidates[index] = DIR_EAST; return TRUE; @@ -416,9 +437,9 @@ static u8 sub_81D4C58(struct ObjectEvent *mew, u8 index) return FALSE; } -static u8 sub_81D4C9C(struct ObjectEvent *mew, u8 index) +static bool8 ShouldMewMoveSouth(struct ObjectEvent *mew, u8 index) { - if (sPlayerToMewDeltaY < 0 && CanMewWalkToCoords(mew->currentCoords.x, mew->currentCoords.y + 1)) + if (sPlayerToMewDeltaY < 0 && CanMewMoveToCoords(mew->currentCoords.x, mew->currentCoords.y + 1)) { sMewDirectionCandidates[index] = DIR_SOUTH; return TRUE; @@ -427,9 +448,9 @@ static u8 sub_81D4C9C(struct ObjectEvent *mew, u8 index) return FALSE; } -static u8 sub_81D4CE0(struct ObjectEvent *mew, u8 index) +static bool8 ShouldMewMoveWest(struct ObjectEvent *mew, u8 index) { - if (sPlayerToMewDeltaX > 0 && CanMewWalkToCoords(mew->currentCoords.x - 1, mew->currentCoords.y)) + if (sPlayerToMewDeltaX > 0 && CanMewMoveToCoords(mew->currentCoords.x - 1, mew->currentCoords.y)) { sMewDirectionCandidates[index] = DIR_WEST; return TRUE; @@ -438,7 +459,7 @@ static u8 sub_81D4CE0(struct ObjectEvent *mew, u8 index) return FALSE; } -static u8 sub_81D4D24(u8 mod) +static u8 GetRandomMewDirectionCandidate(u8 numDirections) { - return sMewDirectionCandidates[VarGet(VAR_FARAWAY_ISLAND_STEP_COUNTER) % mod]; + return sMewDirectionCandidates[VarGet(VAR_FARAWAY_ISLAND_STEP_COUNTER) % numDirections]; } From 813f0c724f428ba8f2995447973ac023cf86f890 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Tue, 21 Jul 2020 17:21:01 -0400 Subject: [PATCH 2/4] Sync flags with pokeruby --- data/maps/LavaridgeTown_HerbShop/scripts.inc | 4 +-- include/constants/flags.h | 34 +++++++------------- 2 files changed, 13 insertions(+), 25 deletions(-) diff --git a/data/maps/LavaridgeTown_HerbShop/scripts.inc b/data/maps/LavaridgeTown_HerbShop/scripts.inc index c08d37609..d98d6ef49 100644 --- a/data/maps/LavaridgeTown_HerbShop/scripts.inc +++ b/data/maps/LavaridgeTown_HerbShop/scripts.inc @@ -28,12 +28,12 @@ LavaridgeTown_HerbShop_EventScript_ExpertM:: @ 81FE4FC LavaridgeTown_HerbShop_EventScript_OldMan:: @ 81FE505 lock faceplayer - goto_if_set FLFLAG_RECEIVED_CHARCOAL, LavaridgeTown_HerbShop_EventScript_ExplainCharcoal + goto_if_set FLAG_RECEIVED_CHARCOAL, LavaridgeTown_HerbShop_EventScript_ExplainCharcoal msgbox LavaridgeTown_HerbShop_Text_YouveComeToLookAtHerbalMedicine, MSGBOX_DEFAULT giveitem ITEM_CHARCOAL compare VAR_RESULT, FALSE goto_if_eq Common_EventScript_ShowBagIsFull - setflag FLFLAG_RECEIVED_CHARCOAL + setflag FLAG_RECEIVED_CHARCOAL release end diff --git a/include/constants/flags.h b/include/constants/flags.h index e1a88283a..485dd3058 100644 --- a/include/constants/flags.h +++ b/include/constants/flags.h @@ -275,7 +275,7 @@ #define FLAG_RECEIVED_DURIN_BERRY 0xFB #define FLAG_RECEIVED_BELUE_BERRY 0xFC #define FLAG_ENABLE_RIVAL_MATCH_CALL 0xFD -#define FLFLAG_RECEIVED_CHARCOAL 0xFE +#define FLAG_RECEIVED_CHARCOAL 0xFE #define FLAG_LATIOS_OR_LATIAS_ROAMING 0xFF #define FLAG_RECEIVED_REPEAT_BALL 0x100 #define FLAG_RECEIVED_OLD_ROD 0x101 @@ -1077,9 +1077,7 @@ #define FLAG_ITEM_ROUTE_120_NUGGET 0x406 #define FLAG_ITEM_ROUTE_120_FULL_HEAL 0x407 #define FLAG_ITEM_ROUTE_123_CALCIUM 0x408 - -#define FLAG_UNUSED_0x409 0x409 // Unused Flag - +#define FLAG_ITEM_ROUTE_123_RARE_CANDY 0x409 // Unused Flag, leftover from R/S. In Emerald this is a hidden item and uses a different flag #define FLAG_ITEM_ROUTE_127_ZINC 0x40A #define FLAG_ITEM_ROUTE_127_CARBOS 0x40B #define FLAG_ITEM_ROUTE_132_RARE_CANDY 0x40C @@ -1171,37 +1169,27 @@ #define FLAG_ITEM_NEW_MAUVILLE_FULL_HEAL 0x462 #define FLAG_ITEM_NEW_MAUVILLE_PARALYZE_HEAL 0x463 #define FLAG_ITEM_AQUA_HIDEOUT_B1F_MASTER_BALL 0x464 - -#define FLAG_UNUSED_0x465 0x465 // Unused Flag -#define FLAG_UNUSED_0x466 0x466 // Unused Flag -#define FLAG_UNUSED_0x467 0x467 // Unused Flag +#define FLAG_ITEM_OLD_MAGMA_HIDEOUT_B1F_MASTER_BALL 0x465 // Unused Flag, leftover from the Ruby Magma hideout +#define FLAG_ITEM_OLD_MAGMA_HIDEOUT_B1F_MAX_ELIXIR 0x466 // Unused Flag, leftover from the Ruby Magma hideout +#define FLAG_ITEM_OLD_MAGMA_HIDEOUT_B2F_NEST_BALL 0x467 // Unused Flag, leftover from the Ruby Magma hideout #define FLAG_UNUSED_0x468 0x468 // Unused Flag - #define FLAG_ITEM_MT_PYRE_2F_ULTRA_BALL 0x469 #define FLAG_ITEM_MT_PYRE_4F_SEA_INCENSE 0x46A #define FLAG_ITEM_SAFARI_ZONE_SOUTH_WEST_MAX_REVIVE 0x46B #define FLAG_ITEM_AQUA_HIDEOUT_B1F_NUGGET 0x46C - -#define FLAG_UNUSED_0x46D 0x46D // Unused Flag - +#define FLAG_ITEM_MOSSDEEP_STEVENS_HOUSE_HM08 0x46D // Unused Flag, leftover from R/S. HM08 is given to the player directly in Emerald #define FLAG_ITEM_ROUTE_119_NUGGET 0x46E #define FLAG_ITEM_ROUTE_104_POTION 0x46F - #define FLAG_UNUSED_0x470 0x470 // Unused Flag - #define FLAG_ITEM_ROUTE_103_PP_UP 0x471 - #define FLAG_UNUSED_0x472 0x472 // Unused Flag - #define FLAG_ITEM_ROUTE_108_STAR_PIECE 0x473 #define FLAG_ITEM_ROUTE_109_POTION 0x474 #define FLAG_ITEM_ROUTE_110_ELIXIR 0x475 #define FLAG_ITEM_ROUTE_111_ELIXIR 0x476 #define FLAG_ITEM_ROUTE_113_HYPER_POTION 0x477 #define FLAG_ITEM_ROUTE_115_HEAL_POWDER 0x478 - #define FLAG_UNUSED_0x479 0x479 // Unused Flag - #define FLAG_ITEM_ROUTE_116_POTION 0x47A #define FLAG_ITEM_ROUTE_119_ELIXIR_2 0x47B #define FLAG_ITEM_ROUTE_120_REVIVE 0x47C @@ -1356,7 +1344,7 @@ #define FLAG_SYS_POKEMON_GET (SYSTEM_FLAGS + 0x0) // FLAG_0x860 #define FLAG_SYS_POKEDEX_GET (SYSTEM_FLAGS + 0x1) #define FLAG_SYS_POKENAV_GET (SYSTEM_FLAGS + 0x2) -#define FLAG_UNUSED_0x863 (SYSTEM_FLAGS + 0x3) +#define FLAG_UNUSED_0x863 (SYSTEM_FLAGS + 0x3) // Unused Flag #define FLAG_SYS_GAME_CLEAR (SYSTEM_FLAGS + 0x4) #define FLAG_SYS_CHAT_USED (SYSTEM_FLAGS + 0x5) #define FLAG_SYS_HIPSTER_MEET (SYSTEM_FLAGS + 0x6) @@ -1373,7 +1361,7 @@ #define NUM_BADGES (1 + FLAG_BADGE08_GET - FLAG_BADGE01_GET) // Towns and Cities -#define FLAG_VISITED_LITTLEROOT_TOWN (SYSTEM_FLAGS + 0xF) +#define FLAG_VISITED_LITTLEROOT_TOWN (SYSTEM_FLAGS + 0xF) #define FLAG_VISITED_OLDALE_TOWN (SYSTEM_FLAGS + 0x10) #define FLAG_VISITED_DEWFORD_TOWN (SYSTEM_FLAGS + 0x11) #define FLAG_VISITED_LAVARIDGE_TOWN (SYSTEM_FLAGS + 0x12) @@ -1418,9 +1406,9 @@ #define FLAG_SYS_MIX_RECORD (SYSTEM_FLAGS + 0x34) #define FLAG_SYS_CLOCK_SET (SYSTEM_FLAGS + 0x35) #define FLAG_SYS_NATIONAL_DEX (SYSTEM_FLAGS + 0x36) -#define FLAG_SYS_UNUSED_CAVE_SHIP (SYSTEM_FLAGS + 0x37) // Unused Flag? -#define FLAG_SYS_UNUSED_CAVE_WONDER (SYSTEM_FLAGS + 0x38) // Unused Flag? -#define FLAG_SYS_UNUSED_CAVE_BATTLE (SYSTEM_FLAGS + 0x39) // Unused Flag? +#define FLAG_SYS_CAVE_SHIP (SYSTEM_FLAGS + 0x37) // Unused Flag, leftover from R/S debug, presumably used by Emerald's debug too +#define FLAG_SYS_CAVE_WONDER (SYSTEM_FLAGS + 0x38) // Unused Flag, same as above +#define FLAG_SYS_CAVE_BATTLE (SYSTEM_FLAGS + 0x39) // Unused Flag, same as above #define FLAG_SYS_SHOAL_TIDE (SYSTEM_FLAGS + 0x3A) #define FLAG_SYS_RIBBON_GET (SYSTEM_FLAGS + 0x3B) From f007165c538376fa8357727783ede54884c982e1 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Mon, 27 Jul 2020 12:27:35 +0200 Subject: [PATCH 3/4] Fix undefined behaviour in protect animation gPlttBufferFaded[sprite->data[2] + ++i] = gPlttBufferFaded[sprite->data[2] + i + 1] The above does NOT make it certain that i gets incremented before reading from the right side. Changed it, so the function always increments i first, then reads from pal buffer. --- src/battle_anim_effects_1.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/battle_anim_effects_1.c b/src/battle_anim_effects_1.c index 516c58e55..f93b2a5c4 100644 --- a/src/battle_anim_effects_1.c +++ b/src/battle_anim_effects_1.c @@ -3967,21 +3967,21 @@ static void AnimProtect(struct Sprite* sprite) static void AnimProtect_Step(struct Sprite *sprite) { - int a; - int i; + int i, id, savedPal; sprite->data[5] += 96; sprite->pos2.x = -(sprite->data[5] >> 8); if (++sprite->data[1] > 1) { sprite->data[1] = 0; - a = gPlttBufferFaded[sprite->data[2] + 1]; + savedPal = gPlttBufferFaded[sprite->data[2] + 1]; i = 0; - do + while (i < 6) { - gPlttBufferFaded[sprite->data[2] + ++i] = gPlttBufferFaded[sprite->data[2] + i + 1]; - } while (i < 6); + id = sprite->data[2] + ++i; + gPlttBufferFaded[id] = gPlttBufferFaded[id + 1]; + } - gPlttBufferFaded[sprite->data[2] + 7] = a; + gPlttBufferFaded[sprite->data[2] + 7] = savedPal; } if (sprite->data[7] > 6 && sprite->data[0] >0 && ++sprite->data[6] > 1) From 5f6e7e2279711f9aab5fe861a76b20732551eebb Mon Sep 17 00:00:00 2001 From: PokeCodec <67983839+PokeCodec@users.noreply.github.com> Date: Mon, 27 Jul 2020 14:59:37 -0400 Subject: [PATCH 4/4] Update secret_base.c --- src/secret_base.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/secret_base.c b/src/secret_base.c index 35ac31d4a..3f69e0419 100644 --- a/src/secret_base.c +++ b/src/secret_base.c @@ -964,7 +964,7 @@ static void HandleRegistryMenuInput(u8 taskId) data = gTasks[taskId].data; input = ListMenu_ProcessInput(data[5]); - ListMenuGetScrollAndRow((u8)data[5], (u16 *)&data[2], (u16 *)&data[1]); + ListMenuGetScrollAndRow(data[5], (u16 *)&data[2], (u16 *)&data[1]); switch (input) { case LIST_NOTHING_CHOSEN: