pokeemmo/src/heal_location.c
Bassoonian b372c272f4
Update FRLG whiteouts to new pret system (#7040)
Co-authored-by: cawtds <38510667+cawtds@users.noreply.github.com>
2025-06-08 14:45:14 +02:00

105 lines
3.0 KiB
C

#include "global.h"
#include "event_data.h"
#include "heal_location.h"
#include "constants/event_objects.h"
#include "constants/heal_locations.h"
#include "constants/maps.h"
#include "data/heal_locations.h"
u32 GetHealLocationIndexByMap(u16 mapGroup, u16 mapNum)
{
u32 i;
for (i = 0; i < ARRAY_COUNT(sHealLocations); i++)
{
if (sHealLocations[i].mapGroup == mapGroup && sHealLocations[i].mapNum == mapNum)
return i + 1;
}
return HEAL_LOCATION_NONE;
}
const struct HealLocation *GetHealLocationByMap(u16 mapGroup, u16 mapNum)
{
u32 index = GetHealLocationIndexByMap(mapGroup, mapNum);
if (index == HEAL_LOCATION_NONE)
return NULL;
else
return &sHealLocations[index - 1];
}
u32 GetHealLocationIndexByWarpData(struct WarpData *warp)
{
u32 i;
for (i = 0; i < ARRAY_COUNT(sHealLocations); i++)
{
if (sHealLocations[i].mapGroup == warp->mapGroup
&& sHealLocations[i].mapNum == warp->mapNum
&& sHealLocations[i].x == warp->x
&& sHealLocations[i].y == warp->y)
return i + 1;
}
return HEAL_LOCATION_NONE;
}
const struct HealLocation *GetHealLocation(u32 index)
{
if (index == HEAL_LOCATION_NONE)
return NULL;
else if (index > ARRAY_COUNT(sHealLocations))
return NULL;
else
return &sHealLocations[index - 1];
}
static bool32 IsLastHealLocation(u32 healLocation)
{
const struct HealLocation *loc = GetHealLocation(healLocation);
const struct WarpData *warpData = &gSaveBlock1Ptr->lastHealLocation;
return warpData->mapGroup == loc->mapGroup
&& warpData->mapNum == loc->mapNum
&& warpData->warpId == WARP_ID_NONE
&& warpData->x == loc->x
&& warpData->y == loc->y;
}
bool32 IsLastHealLocationPlayerHouse()
{
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;
}
u32 GetHealNpcLocalId(u32 healLocationId)
{
if (healLocationId == HEAL_LOCATION_NONE || healLocationId >= NUM_HEAL_LOCATIONS)
return 0;
return sWhiteoutRespawnHealerNpcIds[healLocationId - 1];
}
void SetWhiteoutRespawnWarpAndHealerNPC(struct WarpData *warp)
{
u32 healLocationId = GetHealLocationIndexByWarpData(&gSaveBlock1Ptr->lastHealLocation);
u32 healNpcLocalId = GetHealNpcLocalId(healLocationId);
if (!healNpcLocalId)
{
*(warp) = gSaveBlock1Ptr->lastHealLocation;
return;
}
warp->mapGroup = sWhiteoutRespawnHealCenterMapIdxs[healLocationId - 1][0];
warp->mapNum = sWhiteoutRespawnHealCenterMapIdxs[healLocationId - 1][1];
warp->warpId = WARP_ID_NONE;
warp->x = sWhiteoutRespawnHealCenterMapIdxs[healLocationId - 1][2];
warp->y = sWhiteoutRespawnHealCenterMapIdxs[healLocationId - 1][3];
gSpecialVar_LastTalked = healNpcLocalId;
}