Skip to content

Commit

Permalink
fixed issue with undefined respawn locations, cleaned up whiteout task
Browse files Browse the repository at this point in the history
  • Loading branch information
cawtds committed Jul 27, 2024
1 parent 6dad6ed commit 410738b
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 51 deletions.
3 changes: 2 additions & 1 deletion include/heal_location.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 4 additions & 0 deletions src/data/heal_locations_pkm_center.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
63 changes: 28 additions & 35 deletions src/field_screen_effect.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -1322,65 +1323,57 @@ 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));
FillWindowPixelBuffer(windowId, PIXEL_FILL(0));
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;
}
Expand All @@ -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;
}
43 changes: 29 additions & 14 deletions src/heal_location.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
Expand All @@ -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;
Expand All @@ -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;
}
}
2 changes: 1 addition & 1 deletion src/overworld.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 410738b

Please sign in to comment.