forked from rh-hideout/pokeemerald-expansion
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathheal_location.c
106 lines (90 loc) · 2.98 KB
/
heal_location.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include "global.h"
#include "event_data.h"
#include "heal_location.h"
#include "constants/heal_locations.h"
#include "constants/maps.h"
#include "data/heal_locations.h"
#include "data/heal_locations_pkm_center.h"
u32 GetHealLocationIndexByMap(u16 mapGroup, u16 mapNum)
{
u32 i;
for (i = 0; i < ARRAY_COUNT(sHealLocations); i++)
{
if (sHealLocations[i].group == mapGroup && sHealLocations[i].map == 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].group == warp->mapGroup
&& sHealLocations[i].map == 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->group
&& warpData->mapNum == loc->map
&& 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 >= HEAL_LOCATION_COUNT)
return 0;
return sHealNpcLocalId[healLocationId - 1];
}
void SetWhiteoutRespawnWarpAndHealerNPC(struct WarpData *warp)
{
u32 healLocationId = GetHealLocationIndexByWarpData(&gSaveBlock1Ptr->lastHealLocation);
u32 healNpcLocalId = GetHealNpcLocalId(healLocationId);
struct HealLocation pkmCenterHealLocation;
if (!healNpcLocalId)
{
*(warp) = gSaveBlock1Ptr->lastHealLocation;
return;
}
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;
gSpecialVar_LastTalked = healNpcLocalId;
}