-
Notifications
You must be signed in to change notification settings - Fork 2
/
hm.c
257 lines (222 loc) · 5.27 KB
/
hm.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#include "hm.h"
#include "overworld.h"
#include "save.h"
#include "vars.h"
// 02039A04
struct {
coords16 pos;
u8 height;
} in_front_of_player;
// missing hm2 functions
void hm2_ruin_valley();
void hm2_cut();
void hm_rocksmash_run_scr();
void hm2_flash();
void hm_strenght_run_scr();
void hm2_sweet_scent();
void hm_teleport_run_dp02scr();
void hm_surf_run_dp02scr();
void sub_8124ADC();
// 08097898
bool hm_prepare_cut() {
if (ruin_valley_trigger()) {
cut_ruin_valley = true;
hm_phase_1 = hm_add_c3_launch_phase_2;
hm_phase_2 = hm2_ruin_valley;
return true;
} else {
cut_ruin_valley = false;
}
if (npc_before_player_of_type(95)) {
hm_phase_1 = hm_add_c3_launch_phase_2;
hm_phase_2 = hm2_cut;
return 1;
}
player_get_pos_to(
&in_front_of_player.pos.x,
&in_front_of_player.pos.y);
for (int dy = -1; dy <= 1; dy++)
for (int dx = -1; dx <= 1; dx++)
{
coords16 p = {
in_front_of_player.pos.x + dx,
in_front_of_player.pos.x + dx
};
u8 v8 = cur_mapdata_get_upper4bit_at(p.x, p.y);
if ( v8 == in_front_of_player.height )
{
u8 v9 = sub_8097874(p.x, p.y);
if ( v9 == 1 ) {
hm_phase_1 = hm_add_c3_launch_phase_2;
hm_phase_2 = hm2_ruin_valley;
return true;
}
}
}
return false;
}
// 080C97A8
bool npc_before_player_of_type(u8 npc_type) {
struct npc_state *npc;
player_get_pos_to_plus_one_step_in_direction_player_is_facing(
&in_front_of_player.pos.x,
&in_front_of_player.pos.y);
in_front_of_player.height = player_get_height();
npc = &npc_states[npc_id_by_pos_and_height(
in_front_of_player.pos.x,
in_front_of_player.pos.y,
in_front_of_player.height) & 0xFF];
if (npc->type_id == npc_type) {
var_800F = npc->local_id;
return true;
}
return false;
}
// 080C99D8
bool hm_prepare_rocksmash() {
if (npc_before_player_of_type(96)) {
hm_phase_1 = hm_add_c3_launch_phase_2;
hm_phase_2 = hm_rocksmash_run_scr;
return true;
}
return false;
}
// 080C9A10
// void hm_rocksmash_run_scr() {
//
// }
// 080C9A78
bool hm_prepare_dig() {
if (cur_map_can_dig()) {
hm_phase_1 = hm_add_c3_launch_phase_2;
hm_phase_2 = hm2_dig;
return true;
}
return false;
}
// 080C9AAC
// void hm2_dig() {
//
// }
// 080C9B2C
bool hm_prepare_flash() {
if (current_mapheader.cave == 1 && !flag_check(2054)) {
hm_phase_1 = hm_add_c3_launch_phase_2;
hm_phase_2 = hm2_flash;
return true;
}
return false;
}
// 080CCD84
bool ruin_valley_trigger() {
return flag_check(739) != 1
&& saveblock1_mapdata->location.group == 0x03
&& saveblock1_mapdata->location.map == 0x3D
&& saveblock1_mapdata->camera_position.x == 24
&& saveblock1_mapdata->camera_position.y == 25
&& player_get_direction__sp1AA(1638424) == 2;
}
// 080D07EC
bool hm_prepare_strength() {
if ( walkrun_bitfield_and_r0(8) << 24 || npc_before_player_of_type(97) != 1 ) {
return false;
} else {
var_800D = brm_get_pokemon_selection();
hm_phase_1 = hm_add_c3_launch_phase_2;
hm_phase_2 = hm_strenght_run_scr;
return true;
}
}
// 080DE0C8
bool hm_prepare_sweet_scent() {
hm_phase_1 = hm_add_c3_launch_phase_2;
hm_phase_2 = hm2_sweet_scent;
return true;
}
// 080E5684
bool hm_prepare_dive_probably() {
struct pokemon_extended *pkmn = &party_player[brm_get_pokemon_selection()];
u16 total_hp = pokemon_getattr(pkmn, req_max_hp);
u16 current_hp = pokemon_getattr(pkmn, req_current_hp);
return current_hp > (total_hp / 5);
}
// 080F66F0
bool hm_prepare_teleport() {
if (is_light_level_1_2_3_or_6__opensky(current_mapheader.light)) {
hm_phase_1 = hm_add_c3_launch_phase_2;
hm_phase_2 = hm_teleport_run_dp02scr;
return true;
}
return false;
}
// 081248B0
bool hm_add_c3_launch_phase_2() {
pal_fill_black();
task_add(&task_launch_hm_phase_2, 8);
return 1;
}
// 081248C8
void task_launch_hm_phase_2(task_id c) {
// if (sub_807AA70() == 1) {
// LOWORD(oe_state.to_x___local_id) = brm_get_selected_species();
// oe_state.to_x___local_id = (unsigned __int16)oe_state.to_x___local_id;
// call_via_r0(hm_phase_2);
// task_del(v1);
// }
}
// 08124998
bool hm_prepare_surf() {
coords16 target;
player_get_pos_to_plus_one_step_in_direction_player_is_facing(
&target.x,
&target.y);
u8 role = cur_mapdata_block_role_at(
target.x,
target.y);
if (sub_8059CC8(role))
return false;
if (!party_has_pokemon_with_surf())
return false;
if (!sub_805C8B0())
return false;
hm_phase_1 = hm_add_c3_launch_phase_2;
hm_phase_2 = hm_surf_run_dp02scr;
return true;
}
// 08124A8C
bool hm_prepare_fly() {
return is_light_level_1_2_3_or_6__opensky(current_mapheader.light);
}
// 08124AF8
bool hm_prepare_waterfall() {
coords16 target;
player_get_pos_to_plus_one_step_in_direction_player_is_facing(
&target.x,
&target.y);
u8 role = cur_mapdata_block_role_at(target.x, target.y);
if (!is_tile_x13_waterfall(role))
return false;
if (!sub_805C88C())
return false;
hm_phase_1 = hm_add_c3_launch_phase_2;
hm_phase_2 = sub_8124ADC;
return true;
}
// 0845A788
struct hm_overworld {
bool (*prepare)(void);
u32 number;
} hm_overworld_table[] = {
{hm_prepare_flash, 0xD},
{hm_prepare_cut, 7},
{hm_prepare_fly, 0xD},
{hm_prepare_strength, 0xD},
{hm_prepare_surf, 8},
{hm_prepare_rocksmash, 0xD},
{hm_prepare_waterfall, 0xD},
{hm_prepare_teleport, 0xD},
{hm_prepare_dig, 0xD},
{hm_prepare_dive_probably, 0x10},
{hm_prepare_dive_probably, 0x10},
{hm_prepare_sweet_scent, 0xD}
};