From 410738b5b4d74e27b90d00681edb4925055a2a61 Mon Sep 17 00:00:00 2001 From: cawtds <38510667+cawtds@users.noreply.github.com> Date: Sat, 27 Jul 2024 20:26:19 +0200 Subject: [PATCH] fixed issue with undefined respawn locations, cleaned up whiteout task --- include/heal_location.h | 3 +- src/data/heal_locations_pkm_center.h | 4 ++ src/field_screen_effect.c | 63 +++++++++++++--------------- src/heal_location.c | 43 ++++++++++++------- src/overworld.c | 2 +- 5 files changed, 64 insertions(+), 51 deletions(-) diff --git a/include/heal_location.h b/include/heal_location.h index 85e7dfad1229..d956ae9e013e 100644 --- a/include/heal_location.h +++ b/include/heal_location.h @@ -10,9 +10,10 @@ struct HealLocation }; u32 GetHealLocationIndexByMap(u16 mapGroup, u16 mapNum); +u32 GetHealLocationIndexByWarpData(struct WarpData *warp); const struct HealLocation *GetHealLocationByMap(u16 mapGroup, u16 mapNum); const struct HealLocation *GetHealLocation(u32 index); -bool32 IsLastHealLocation(u32 healLocation); +bool32 IsLastHealLocationPlayerHouse(); void SetWhiteoutRespawnWarpAndHealerNPC(struct WarpData * warp); bool32 HasHealNPC(u32 healLocationId); diff --git a/src/data/heal_locations_pkm_center.h b/src/data/heal_locations_pkm_center.h index 8df625cad421..de47ccd26aed 100644 --- a/src/data/heal_locations_pkm_center.h +++ b/src/data/heal_locations_pkm_center.h @@ -144,6 +144,10 @@ static const struct HealLocation sHealLocationsPokemonCenter[HEAL_LOCATION_COUNT #undef DEFAULT_POKEMON_CENTER_COORDS +// localIds can be found in the generated events.inc file for the specific heal location map +// e.g. for OldaleTown_PokemonCenter1F/events.inc the following entry gets generated: +// object_event 1, OBJ_EVENT_GFX_NURSE, 7, 2, 3, MOVEMENT_TYPE_FACE_DOWN, 0, 0, TRAINER_TYPE_NONE, 0, OldaleTown_PokemonCenter_1F_EventScript_Nurse, 0 +// In this case the localId is 1. static const u8 sWhiteoutRespawnHealerNpcLocalIds[HEAL_LOCATION_COUNT - 1] = { [HEAL_LOCATION_LITTLEROOT_TOWN_BRENDANS_HOUSE_2F - 1] = 1, diff --git a/src/field_screen_effect.c b/src/field_screen_effect.c index 1790dfed2cb6..08e16479a5e7 100644 --- a/src/field_screen_effect.c +++ b/src/field_screen_effect.c @@ -1293,9 +1293,10 @@ static const struct WindowTemplate sWindowTemplate_WhiteoutText = static const u8 sWhiteoutTextColors[] = { TEXT_COLOR_TRANSPARENT, TEXT_COLOR_WHITE, TEXT_COLOR_DARK_GRAY }; -#define tState data[0] -#define tWindowId data[1] -#define tPrintState data[2] +#define tState data[0] +#define tWindowId data[1] +#define tPrintState data[2] +#define tIsPlayerHouse data[3] static bool8 PrintWhiteOutRecoveryMessage(u8 taskId, const u8 *text, u8 x, u8 y) { @@ -1322,13 +1323,20 @@ static bool8 PrintWhiteOutRecoveryMessage(u8 taskId, const u8 *text, u8 x, u8 y) return FALSE; } +enum { + FRLG_WHITEOUT_ENTER_MSG_SCREEN, + FRLG_WHITEOUT_PRINT_MSG, + FRLG_WHITEOUT_LEAVE_MSG_SCREEN, + FRLG_WHITEOUT_HEAL_SCRIPT, +}; + static void Task_RushInjuredPokemonToCenter(u8 taskId) { u8 windowId; switch (gTasks[taskId].tState) { - case 0: + case FRLG_WHITEOUT_ENTER_MSG_SCREEN: windowId = AddWindow(&sWindowTemplate_WhiteoutText); gTasks[taskId].tWindowId = windowId; Menu_LoadStdPalAt(BG_PLTT_ID(15)); @@ -1336,51 +1344,36 @@ static void Task_RushInjuredPokemonToCenter(u8 taskId) PutWindowTilemap(windowId); CopyWindowToVram(windowId, COPYWIN_FULL); - // Scene changes if last heal location was the player's house - if (IsLastHealLocation(HEAL_LOCATION_LITTLEROOT_TOWN_MAYS_HOUSE) - || IsLastHealLocation(HEAL_LOCATION_LITTLEROOT_TOWN_MAYS_HOUSE_2F) - || IsLastHealLocation(HEAL_LOCATION_LITTLEROOT_TOWN_BRENDANS_HOUSE) - || IsLastHealLocation(HEAL_LOCATION_LITTLEROOT_TOWN_BRENDANS_HOUSE_2F)) - gTasks[taskId].tState = 4; - else - gTasks[taskId].tState = 1; - break; - case 1: - if (PrintWhiteOutRecoveryMessage(taskId, gText_PlayerScurriedToCenter, 2, 8)) - { - ObjectEventTurn(&gObjectEvents[gPlayerAvatar.objectEventId], DIR_NORTH); - gTasks[taskId].tState++; - } + gTasks[taskId].tIsPlayerHouse = IsLastHealLocationPlayerHouse(); + gTasks[taskId].tState = FRLG_WHITEOUT_PRINT_MSG; break; - case 4: - if (PrintWhiteOutRecoveryMessage(taskId, gText_PlayerScurriedBackHome, 2, 8)) + case FRLG_WHITEOUT_PRINT_MSG: + { + const u8 *recoveryMessage = gTasks[taskId].tIsPlayerHouse == TRUE ? gText_PlayerScurriedBackHome : gText_PlayerScurriedToCenter; + if (PrintWhiteOutRecoveryMessage(taskId, recoveryMessage, 2, 8)) { ObjectEventTurn(&gObjectEvents[gPlayerAvatar.objectEventId], DIR_NORTH); - gTasks[taskId].tState++; + gTasks[taskId].tState = FRLG_WHITEOUT_LEAVE_MSG_SCREEN; } break; - case 2: - case 5: + } + case FRLG_WHITEOUT_LEAVE_MSG_SCREEN: windowId = gTasks[taskId].tWindowId; ClearWindowTilemap(windowId); CopyWindowToVram(windowId, COPYWIN_MAP); RemoveWindow(windowId); FillPalBufferBlack(); FadeInFromBlack(); - gTasks[taskId].tState++; + gTasks[taskId].tState = FRLG_WHITEOUT_HEAL_SCRIPT; break; - case 3: + case FRLG_WHITEOUT_HEAL_SCRIPT: if (WaitForWeatherFadeIn() == TRUE) { DestroyTask(taskId); - ScriptContext_SetupScript(EventScript_AfterWhiteOutHeal); - } - break; - case 6: - if (WaitForWeatherFadeIn() == TRUE) - { - DestroyTask(taskId); - ScriptContext_SetupScript(EventScript_AfterWhiteOutMomHeal); + if (gTasks[taskId].tIsPlayerHouse) + ScriptContext_SetupScript(EventScript_AfterWhiteOutMomHeal); + else + ScriptContext_SetupScript(EventScript_AfterWhiteOutHeal); } break; } @@ -1393,5 +1386,5 @@ void FieldCB_RushInjuredPokemonToCenter(void) LockPlayerFieldControls(); FillPalBufferBlack(); taskId = CreateTask(Task_RushInjuredPokemonToCenter, 10); - gTasks[taskId].tState = 0; + gTasks[taskId].tState = FRLG_WHITEOUT_ENTER_MSG_SCREEN; } diff --git a/src/heal_location.c b/src/heal_location.c index 6a4dbc2470de..8cbd1e1a2379 100644 --- a/src/heal_location.c +++ b/src/heal_location.c @@ -29,7 +29,7 @@ const struct HealLocation *GetHealLocationByMap(u16 mapGroup, u16 mapNum) return &sHealLocations[index - 1]; } -static u32 GetHealLocationIndexByWarpData(struct WarpData *warp) +u32 GetHealLocationIndexByWarpData(struct WarpData *warp) { u32 i; for (i = 0; i < ARRAY_COUNT(sHealLocations); i++) @@ -53,7 +53,7 @@ const struct HealLocation *GetHealLocation(u32 index) return &sHealLocations[index - 1]; } -bool32 IsLastHealLocation(u32 healLocation) +static bool32 IsLastHealLocation(u32 healLocation) { const struct HealLocation *loc = GetHealLocation(healLocation); const struct WarpData *warpData = &gSaveBlock1Ptr->lastHealLocation; @@ -65,28 +65,43 @@ bool32 IsLastHealLocation(u32 healLocation) && warpData->y == loc->y; } -static void SetWhiteoutRespawnHealerNPCAsLastTalked(u32 healLocationId) +bool32 IsLastHealLocationPlayerHouse() { - gSpecialVar_LastTalked = sWhiteoutRespawnHealerNpcLocalIds[healLocationId - 1]; + if (IsLastHealLocation(HEAL_LOCATION_LITTLEROOT_TOWN_MAYS_HOUSE) + || IsLastHealLocation(HEAL_LOCATION_LITTLEROOT_TOWN_MAYS_HOUSE_2F) + || IsLastHealLocation(HEAL_LOCATION_LITTLEROOT_TOWN_BRENDANS_HOUSE) + || IsLastHealLocation(HEAL_LOCATION_LITTLEROOT_TOWN_BRENDANS_HOUSE_2F)) + return TRUE; + + return FALSE; } +bool32 HasHealNPC(u32 healLocationId) +{ + if (healLocationId == HEAL_LOCATION_NONE || healLocationId >= HEAL_LOCATION_COUNT) + return FALSE; + + return sWhiteoutRespawnHealerNpcLocalIds[healLocationId - 1] > 0 ? TRUE : FALSE; +} void SetWhiteoutRespawnWarpAndHealerNPC(struct WarpData *warp) { - u32 healLocationId = GetHealLocationIndexByWarpData(&gSaveBlock1Ptr->lastHealLocation); - struct HealLocation pkmCenterHealLocation = sHealLocationsPokemonCenter[healLocationId - 1]; - + u32 healLocationId = GetHealLocationIndexByWarpData(&gSaveBlock1Ptr->lastHealLocation); + struct HealLocation pkmCenterHealLocation; + + if (HasHealNPC(healLocationId)) + { + pkmCenterHealLocation = sHealLocationsPokemonCenter[healLocationId - 1]; warp->mapGroup = pkmCenterHealLocation.group; warp->mapNum = pkmCenterHealLocation.map; warp->warpId = WARP_ID_NONE; warp->x = pkmCenterHealLocation.x; warp->y = pkmCenterHealLocation.y; - SetWhiteoutRespawnHealerNPCAsLastTalked(healLocationId); -} -bool32 HasHealNPC(u32 healLocationId) -{ - if (healLocationId == HEAL_LOCATION_NONE || healLocationId >= HEAL_LOCATION_COUNT) - return FALSE; - return sWhiteoutRespawnHealerNpcLocalIds[healLocationId - 1] > 0; + gSpecialVar_LastTalked = sWhiteoutRespawnHealerNpcLocalIds[healLocationId - 1]; + } + else + { + *(warp) = gSaveBlock1Ptr->lastHealLocation; + } } diff --git a/src/overworld.c b/src/overworld.c index 30d025b8a93c..5b6470e7e144 100644 --- a/src/overworld.c +++ b/src/overworld.c @@ -693,7 +693,7 @@ static bool32 IsFRLGWhiteout(void) { if (!OW_FRLG_WHITEOUT) return FALSE; - return HasHealNPC(GetHealLocationIndexByMap(gSaveBlock1Ptr->lastHealLocation.mapGroup, gSaveBlock1Ptr->lastHealLocation.mapNum)); + return HasHealNPC(GetHealLocationIndexByWarpData(&gSaveBlock1Ptr->lastHealLocation)); } void SetWarpDestinationToLastHealLocation(void)