-
Notifications
You must be signed in to change notification settings - Fork 2
/
npc.c
669 lines (590 loc) · 19.8 KB
/
npc.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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
#include "npc.h"
#include "object.h"
#include "object_anim.h"
#include "continuegame.h" // for objc_npc_alternative
// 0805DF60
u8 npc_id_by_local_id(u8 local_id, u8 mapnr, u8 mapgroup) {
if (local_id == 0xFF)
return npc_id_by_local_id_ignore_map(local_id);
else
return npc_id_by_local_id_and_map(local_id, mapnr, mapgroup);
}
// 0805DF84
bool npc_id_by_local_id_and_map_ret_success(u8 local_id, u8 mapnr, u8 mapgroup, u8 *result) {
return (*result=npc_id_by_local_id(local_id, mapnr, mapgroup)) == MAX_NPCS;
}
// 0805DFF4
u8 npc_id_by_local_id_and_map(u8 local_id, u8 mapnr, u8 mapgroup) {
u8 i=0;
while (i<MAX_NPCS) {
if (npc_states[i].bitfield1 & NPC_BIT_ACTIVE && \
npc_states[i].local_id == local_id && \
npc_states[i].local_mapnr == mapnr && \
npc_states[i].local_mapgroup == mapgroup) break;
i++;
}
return i;
}
// 0805E080
u8 rom_npc_to_npc_state(struct rom_npc *rnpc, u8 mapnr, u8 mapgroup) {
// TODO
}
// 0805E044
u8 npc_id_by_local_id_ignore_map(u8 local_id) {
u8 i=0;
while (i<MAX_NPCS) {
if (npc_states[i].bitfield1 & NPC_BIT_ACTIVE && \
npc_states[i].local_id == local_id) break;
i++;
}
return i;
}
// 0805E4B4
void npc_hide(struct npc_state *npc) {
npc->bitfield1 &= ~npc_nopause_1; // clear bit 2
sub_805E510(npc); // TODO
}
// 0805E4C8
void hide_sprite(u8 local_id, u8 mapnr, u8 mapgroup) {
// TODO: Find better name. Check correctness of this transcription.
u8 npc_id;
if (!npc_id_by_local_id_and_map_ret_success(local_id, mapnr, mapgroup, &npc_id)) {
flag_set(trainerid_by_npc_id(npc_id));
npc_hide(&npc_states[npc_id]);
}
}
// 0805E590
void *npc_spawn_with_provided_template(struct rom_npc *rnpc, struct proto_t *p, u8 mapnr, u8 mapgroup, short x, short y) {
// TODO
return 0;
}
// 0805E8E8
void npc_to_template(u8 npc_type_id, void *objcallback, struct proto_t *p, struct obj_oversize_formation **npc_type_obj_formation) {
struct npc_type *nt;
nt = npc_get_type(npc_type_id);
p->tile_tag = nt->tile_tag;
p->pal_tag = nt->pal_tag; // tag or num?
p->sprite = nt->sprite;
p->image_anims = nt->image_anims;
p->gfx_table = nt->gfx_table;
p->rotscale_anims = nt->rotscale_anims;
if (script_env_2_context_is_eq_x0() || sub_8112CAC() != 1) {
p->callback = objcallback;
} else {
p->callback = &objc_npc_alternative;
}
*npc_type_obj_formation = nt->formation;
}
// 0805F218
void npc_turn(struct npc_state *npc, u8 direction) {
npc_set_direction(npc, direction);
if (npc->bitfield2 & (npc_invisble >> 8))
return;
struct obj *o = &objects[npc->oam_id];
obj_anim_image_start(o, npc_direction_to_obj_anim_image_number(npc->direction & 4));
obj_anim_image_seek(o, 0);
}
// 0805F268
void npc_turn_by_local_id_and_map(u16 local_id, u8 map, u8 bank, u8 direction) {
u8 npc_id;
npc_id_by_local_id_and_map_ret_success(local_id, map, bank, &npc_id);
npc_turn(&npc_states[npc_id], direction);
}
// 0805F2C8
struct npc_type *npc_get_type(u8 type_id) {
if (type_id >= 0xF0)
type_id = var_load_x4010_plus(type_id-0xF0);
if (type_id >= 152)
type_id = 10;
return &npc_types[type_id];
}
// 0805F574
void npc_pal_patch_range(u16 *ptx, u8 i, u8 j) {
while (i<j)
pal_patch_for_npc(*ptx++, i++);
}
// 0805F700
void npc_coords_shift(struct npc_state *n, u16 x, u16 y) {
n->from = n->to;
n->to.x = x;
n->to.y = y;
}
// 0805F710
void npc_coords_set(struct npc_state *n, u16 x, u16 y) {
n->from.x = x;
n->from.y = y;
n->to.x = x;
n->to.y = y;
}
// 0805F818
void npc_coords_shift_still(struct npc_state *n) {
n->from = n->to;
}
// 0805F82C
void npcs_rebase() {
if (!translate_info.active)
return;
i16 dx = translate_info.delta.x;
i16 dy = translate_info.delta.y;
for (u8 i=0; i<MAX_NPCS; i++) {
struct npc_state *npc = npc_states + i;
if (!(npc->bitfield1 & NPC_BIT_ACTIVE))
continue;
npc->stay_around.x -= dx;
npc->stay_around.y -= dy;
npc->to.x -= dx;
npc->to.y -= dy;
npc->from.x -= dx;
npc->from.y -= dy;
}
}
// 0805F8FC
bool npc_does_height_match(struct npc_state *npc, u8 height) {
u8 nh = npc->height & 0xF;
if (nh == 0) return true;
if (height == 0) return true;
if (nh == height) return true;
return false;
}
// 0805F218
void npc_set_direction(struct npc_state *npc, u8 direction) {
direction &= 0xf;
npc->field_20 = npc->direction & 0xf;
if (npc->bitfield2 & (npc_use_upper_direction_nibble >> 8) == 0)
npc->direction = direction | (npc->direction & 0xf0);
else
npc->direction = direction * 0x11;
}
// 0805FC5C
u16 trainerid_by_local_id_and_map(u8 local_id, u8 mapnr, u8 mapgroup) {
struct rom_npc *rnpc = (rom_npc_by_nr_and_map(local_id, mapnr, mapgroup));
return rnpc->id_in_script; // TODO: Function has wrong name? Field has wrong name?
}
// 0805FC74
u16 trainerid_by_npc_id(u8 npc_id) {
struct npc_state *npc = &npc_states[npc_id];
return trainerid_by_local_id_and_map(npc->local_id, npc->local_mapnr, npc->local_mapgroup);
}
// 0805FD5C
struct rom_npc *rom_npc_by_nr_and_map(u8 local_id, u8 mapnr, u8 mapgroup) {
// To be written.
}
// 080642C8
u8 npc_reciprocate_look(struct npc_state *npc, u8 direction) {
u8 state = d2s_look1(direction_reversed(direction));
return npc_set_state_2(npc, state);
}
#define AN(name) bool an_##name(struct npc_state *npc, struct obj *obj)
typedef bool (*anptr)(struct npc_state *npc, struct obj *obj);
AN(loop) { return true; } // 08067930
AN(stop) { obj->anim_delay_countdown |= OBJ_ANIM_IMAGE_PAUSED; return true; } // 08067934
AN(look1_dn_1) { an_look_any(1); return true; } // 08064638
AN(look1_up_1) { an_look_any(2); return true; } // 08064648
AN(look1_lf_1) { an_look_any(3); return true; } // 08064658
AN(look1_rt_1) { an_look_any(4); return true; } // 08064668
anptr an_look1_dn[] = { an_look1_dn_1, an_stop }; // 083A6864
anptr an_look1_up[] = { an_look1_up_1, an_stop }; // 083A686C
anptr an_look1_lf[] = { an_look1_lf_1, an_stop }; // 083A6874
anptr an_look1_rt[] = { an_look1_rt_1, an_stop }; // 083A6874
AN(look2_dn_1) { /* ... */ } // 080655D4
AN(look2_up_1) { /* ... */ }
AN(look2_lf_1) { /* ... */ }
AN(look2_rt_1) { /* ... */ }
anptr an_look2_dn[] = { an_look2_dn_1, an_loop }; // 083A6A30
anptr an_look2_up[] = { an_look2_up_1, an_loop }; // 083A6A38
anptr an_look2_lf[] = { an_look2_lf_1, an_loop }; // 083A6A40
anptr an_look2_rt[] = { an_look2_rt_1, an_loop }; // 083A6A48
AN(walk_dn_2) { return an_walk_any_2(npc, obj) && (obj->priv2 = 1, true); }
AN(walk_up_2) { return an_walk_any_2(npc, obj) && (obj->priv2 = 2, true); }
AN(walk_lf_2) { return an_walk_any_2(npc, obj) && (obj->priv2 = 3, true); }
AN(walk_rt_2) { return an_walk_any_2(npc, obj) && (obj->priv2 = 4, true); }
// 2 before 1 or we need forward decls
AN(walk_dn_1) { an_walk_any_1(npc, obj, 1); return an_walk_dn_2(npc, obj); }
AN(walk_up_1) { an_walk_any_1(npc, obj, 2); return an_walk_up_2(npc, obj); }
AN(walk_lf_1) { an_walk_any_1(npc, obj, 3); return an_walk_lf_2(npc, obj); }
AN(walk_rt_1) { an_walk_any_1(npc, obj, 4); return an_walk_rt_2(npc, obj); }
anptr an_walk_dn[] = { an_walk_dn_1, an_walk_dn_2, an_stop }; // 083A68C8
anptr an_walk_up[] = { an_walk_up_1, an_walk_up_2, an_stop }; // 083A68D4
anptr an_walk_lf[] = { an_walk_lf_1, an_walk_lf_2, an_stop }; // 083A68E0
anptr an_walk_rt[] = { an_walk_rt_1, an_walk_rt_2, an_stop }; // 083A68EC
// TODO
extern anptr an_go_dn[];
extern anptr an_go_up[];
extern anptr an_go_lf[];
extern anptr an_go_rt[];
extern anptr an_pulse_dn[];
extern anptr an_pulse_up[];
extern anptr an_pulse_lf[];
extern anptr an_pulse_rt[];
AN(run_dn_2) { return npc_obj_ministep_stop_on_arrival(npc, obj) && (obj->priv2 = 2, true); } // 080652EC
AN(run_up_2) { return npc_obj_ministep_stop_on_arrival(npc, obj) && (obj->priv2 = 2, true); } // 0806530C
AN(run_lf_2) { return npc_obj_ministep_stop_on_arrival(npc, obj) && (obj->priv2 = 2, true); } // 0806532C
AN(run_rt_2) { return npc_obj_ministep_stop_on_arrival(npc, obj) && (obj->priv2 = 2, true); } // 0806534C
AN(run_dn_1) { an_run_any(npc, obj, 1, 1); return an_run_dn_2(npc, obj); } // 080652CC
AN(run_up_1) { an_run_any(npc, obj, 2, 1); return an_run_up_2(npc, obj); } // 080652EC
AN(run_lf_1) { an_run_any(npc, obj, 3, 1); return an_run_lf_2(npc, obj); } // 080652FC
AN(run_rt_1) { an_run_any(npc, obj, 4, 1); return an_run_rt_2(npc, obj); } // 0806530C
anptr an_run_dn[] = { an_run_dn_1, an_run_dn_2, an_stop }; // 083A69D0
anptr an_run_up[] = { an_run_up_1, an_run_up_2, an_stop }; // 083A69DC
anptr an_run_lf[] = { an_run_lf_1, an_run_lf_2, an_stop }; // 083A69E8
anptr an_run_rt[] = { an_run_rt_1, an_run_rt_2, an_stop }; // 083A69F4
#define Q(n) n##_dn, n##_up, n##_lf, n##_rt
// temporary forward decls
extern anptr off_83A6964[];
extern anptr off_83A6970[];
extern anptr off_83A697C[];
extern anptr off_83A6988[];
extern anptr off_83A6994[];
extern anptr off_83A69A0[];
extern anptr off_83A69AC[];
extern anptr off_83A69B8[];
extern anptr off_83A69C4[];
extern anptr off_83A6A50[];
extern anptr off_83A6A5C[];
extern anptr off_83A6A68[];
extern anptr off_83A6A74[];
extern anptr off_83A6A80[];
extern anptr off_83A6A8C[];
extern anptr off_83A6A98[];
extern anptr off_83A6AA4[];
extern anptr off_83A6AB0[];
extern anptr off_83A6ABC[];
extern anptr off_83A6AC8[];
extern anptr off_83A6AD4[];
extern anptr off_83A6AE0[];
extern anptr off_83A6AEC[];
extern anptr off_83A6AF8[];
extern anptr off_83A6B04[];
extern anptr off_83A6B10[];
extern anptr off_83A6B1C[];
extern anptr off_83A6B28[];
extern anptr off_83A6B34[];
extern anptr off_83A6B40[];
extern anptr off_83A6B4C[];
extern anptr off_83A6B58[];
extern anptr off_83A6B64[];
extern anptr off_83A6B70[];
extern anptr off_83A6B7C[];
extern anptr off_83A6B88[];
extern anptr off_83A6B94[];
extern anptr off_83A6BA0[];
extern anptr off_83A6BAC[];
extern anptr off_83A6BB8[];
extern anptr off_83A6BC4[];
extern anptr off_83A6BD0[];
extern anptr off_83A6BDC[];
extern anptr off_83A6BE8[];
extern anptr off_83A6BF4[];
extern anptr off_83A6C00[];
extern anptr off_83A6C0C[];
extern anptr off_83A6C18[];
extern anptr off_83A6C24[];
extern anptr off_83A6C30[];
extern anptr off_83A6C6C[];
extern anptr off_83A6C74[];
extern anptr off_83A6C7C[];
extern anptr off_83A6C84[];
extern anptr off_83A6C8C[];
extern anptr off_83A6C98[];
extern anptr off_83A6CA4[];
extern anptr off_83A6CB0[];
extern anptr off_83A6CBC[];
extern anptr off_83A6CC8[];
extern anptr off_83A6CD4[];
extern anptr off_83A6CE0[];
extern anptr off_83A6CEC[];
extern anptr off_83A6CF8[];
extern anptr off_83A6D04[];
extern anptr off_83A6D10[];
extern anptr off_83A6D1C[];
extern anptr off_83A6D24[];
extern anptr off_83A6D30[];
extern anptr off_83A6D38[];
extern anptr off_83A6D40[];
extern anptr off_83A6D48[];
extern anptr off_83A6D50[];
extern anptr off_83A6D58[];
extern anptr off_83A6D60[];
extern anptr off_83A6D68[];
extern anptr off_83A6D70[];
extern anptr off_83A6D78[];
extern anptr off_83A6D80[];
extern anptr off_83A6D88[];
extern anptr off_83A6D94[];
extern anptr off_83A6DA4[];
extern anptr off_83A6DB4[];
extern anptr off_83A6DBC[];
extern anptr off_83A6DC4[];
extern anptr off_83A6DCC[];
extern anptr off_83A6DD4[];
extern anptr off_83A6DE0[];
extern anptr off_83A6DEC[];
extern anptr off_83A6DF4[];
extern anptr off_83A6DFC[];
extern anptr off_83A6E04[];
extern anptr off_83A6E0C[];
extern anptr off_83A6E18[];
extern anptr off_83A6E24[];
extern anptr off_83A6E30[];
extern anptr off_83A6E3C[];
extern anptr off_83A6E48[];
extern anptr off_83A6E54[];
extern anptr off_83A6E60[];
extern anptr off_83A6E9C[];
extern anptr off_83A6EA8[];
extern anptr off_83A6EB4[];
extern anptr off_83A6EC0[];
extern anptr off_83A6ECC[];
extern anptr off_83A6ED8[];
extern anptr off_83A6EE4[];
extern anptr off_83A6EF0[];
extern anptr off_83A6EFC[];
extern anptr off_83A6F08[];
extern anptr off_83A6F14[];
extern anptr off_83A6F20[];
extern anptr off_83A6F2C[];
extern anptr off_83A6F38[];
extern anptr off_83A6F44[];
extern anptr off_83A6F50[];
extern anptr off_83A6F5C[];
extern anptr off_83A6F68[];
extern anptr off_83A6F74[];
extern anptr off_83A6F80[];
extern anptr off_83A6F8C[];
extern anptr off_83A6F98[];
extern anptr off_83A6FA4[];
extern anptr off_83A6FB0[];
extern anptr off_83A6FBC[];
extern anptr off_83A6FC8[];
extern anptr off_83A6FD4[];
extern anptr off_83A6FE0[];
extern anptr off_83A6FEC[];
extern anptr off_83A6FF4[];
extern anptr off_83A6FFC[];
extern anptr off_83A6898[];
extern anptr off_83A68A4[];
extern anptr off_83A68B0[];
extern anptr off_83A68BC[];
extern anptr off_83A7004[];
extern anptr off_83A6A00[];
extern anptr off_83A6A0C[];
extern anptr off_83A6A18[];
extern anptr off_83A6A24[];
extern anptr off_83A700C[];
extern anptr off_83A7018[];
extern anptr off_83A6C3C[];
extern anptr off_83A6C48[];
extern anptr off_83A6C54[];
extern anptr off_83A6C60[];
// end temporary forward decls
// 083A65BC
anptr (*an_table[]) = {
Q(an_look1), // 0x00
Q(an_look2), // 0x04
Q(an_walk), // 0x08
Q(an_go), // 0x0C; can't remember the difference between "walk" and "go"
Q(an_pulse), // 0x10
off_83A6964, off_83A6970, off_83A697C, off_83A6988, // 0x14
off_83A6994, off_83A69A0, off_83A69AC, off_83A69B8, // 0x18
off_83A69C4,
Q(an_run),
off_83A6A50, off_83A6A5C, off_83A6A68, // 0x20
off_83A6A74, off_83A6A80, off_83A6A8C, off_83A6A98, // 0x24
off_83A6AA4, off_83A6AB0, off_83A6ABC, off_83A6AC8, // 0x28
off_83A6AD4, off_83A6AE0, off_83A6AEC, off_83A6AF8, // 0x2C
off_83A6B04, off_83A6B10, off_83A6B1C, off_83A6B28, // 0x30
off_83A6B34, off_83A6B40, off_83A6B4C, off_83A6B58, // 0x34
off_83A6B64, off_83A6B70, off_83A6B7C, off_83A6B88, // 0x38
off_83A6B94, off_83A6BA0, off_83A6BAC, off_83A6BB8, // 0x3C
off_83A6BC4, off_83A6BD0, off_83A6BDC, off_83A6BE8, // 0x40
off_83A6BF4, off_83A6C00, off_83A6C0C, off_83A6C18, // 0x44
off_83A6C24, off_83A6C30, off_83A6C6C, off_83A6C74, // 0x48
off_83A6C7C, off_83A6C84, off_83A6C8C, off_83A6C98, // 0x4C
off_83A6CA4, off_83A6CB0, off_83A6CBC, off_83A6CC8, // 0x50
off_83A6CD4, off_83A6CE0, off_83A6CEC, off_83A6CF8, // 0x54
off_83A6D04, off_83A6D10, off_83A6D1C, off_83A6D24, // 0x58
off_83A6D30, off_83A6D38, off_83A6D40, off_83A6D48, // 0x5C
off_83A6D50, off_83A6D58, off_83A6D60, off_83A6D68, // 0x60
off_83A6D70, off_83A6D78, off_83A6D80, off_83A6D88, // 0x64
off_83A6D94, off_83A6DA4, off_83A6DB4, off_83A6DBC, // 0x68
off_83A6DC4, off_83A6DCC, off_83A6DD4, off_83A6DE0, // 0x6C
off_83A6DEC, off_83A6DF4, off_83A6DFC, off_83A6E04, // 0x70
off_83A6E0C, off_83A6E18, off_83A6E24, off_83A6E30, // 0x74
off_83A6E3C, off_83A6E48, off_83A6E54, off_83A6E60, // 0x78
off_83A6E9C, off_83A6EA8, off_83A6EB4, off_83A6EC0, // 0x7C
off_83A6ECC, off_83A6ED8, off_83A6EE4, off_83A6EF0, // 0x80
off_83A6EFC, off_83A6F08, off_83A6F14, off_83A6F20, // 0x84
off_83A6F2C, off_83A6F38, off_83A6F44, off_83A6F50, // 0x88
off_83A6F5C, off_83A6F68, off_83A6F74, off_83A6F80, // 0x8C
off_83A6F8C, off_83A6F98, off_83A6FA4, off_83A6FB0, // 0x90
off_83A6FBC, off_83A6FC8, off_83A6FD4, off_83A6FE0, // 0x94
off_83A6FEC, off_83A6FF4, off_83A6FFC, off_83A6898, // 0x98
off_83A68A4, off_83A68B0, off_83A68BC, off_83A7004, // 0x9C
off_83A6A00, off_83A6A0C, off_83A6A18, off_83A6A24, // 0xA0
off_83A700C, off_83A7018, off_83A6C3C, off_83A6C48, // 0xA4
off_83A6C54, off_83A6C60 // 0xA8
};
// 08064788
bool npc_obj_ministep_stop_on_arrival(struct npc_state *npc, struct obj *o) {
if (!obj_npc_ministep(o))
// stepping continues
return false;
// step done, npc is on it's target position
npc->from.x = npc->to.x;
npc->from.y = npc->to.y;
npc->bitfield1 |= npc_ground_analysis_3__on_grid; //NPC_BIT_ONGRID;
o->anim_delay_countdown |= OBJ_ANIM_IMAGE_PAUSED;
return true;
}
// 080653CC
bool npc_ministep(struct npc_state *npc, struct obj *o) {
if (!obj_npc_ministep(o))
// stepping continues
return false;
// step done, npc is on it's target position
npc->from.x = npc->to.x;
npc->from.y = npc->to.y;
npc->bitfield1 |= npc_ground_analysis_3__on_grid; //NPC_BIT_ONGRID;
return true;
}
// 083A64C8
coords directions_i16[] = {
{ 0, 0},
{ 0, 1},
{ 0, -1},
{-1, 0},
{ 1, 0},
{-1, 1},
{ 1, 1},
{-1, -1},
{ 1, -1}
};
// 08068A8C
void step1(struct obj *o, u8 d) {
o->pos_1.x += directions_i16[d].x;
o->pos_1.y += directions_i16[d].y;
}
// 08068AAC
void step2(struct obj *o, u8 d) {
o->pos_1.x += directions_i16[d].x * 2;
o->pos_1.y += directions_i16[d].y * 2;
}
// 08068AD0
void step3(struct obj *o, u8 d) {
o->pos_1.x += directions_i16[d].x * 3;
o->pos_1.y += directions_i16[d].y * 3;
}
// 08068AF8
void step4(struct obj *o, u8 d) {
o->pos_1.x += directions_i16[d].x * 4;
o->pos_1.y += directions_i16[d].y * 4;
}
// 08068B1C
void step8(struct obj *o, u8 d) {
o->pos_1.x += directions_i16[d].x * 8;
o->pos_1.y += directions_i16[d].y * 8;
}
// 08068B40
void obj_npc_ministep_reset(struct obj *o, u16 speed, u16 phase) {
o->priv3 = 0;
o->priv4 = speed;
o->priv5 = phase;
}
// 083A710C
void (*stepspeed1[])(struct obj*, u8) = {
step1, step1, step1, step1,
step1, step1, step1, step1,
step1, step1, step1, step1,
step1, step1, step1, step1
};
// 083A714C
void (*stepspeed2[])(struct obj*, u8) = {
step2, step2, step2, step2,
step2, step2, step2, step2
};
// 083A716C
void (*stepspeed3[])(struct obj*, u8) = {
step2, step3, step3,
step2, step3, step3
};
// 083A7184
void (*stepspeed4[])(struct obj*, u8) = {
step4, step4, step4, step4
};
// 083A7194
void (*stepspeed5[])(struct obj*, u8) = {
step8, step8
};
// 083A719C
void (**stepspeeds[])(struct obj *, u8) = {
stepspeed1,
stepspeed2,
stepspeed3,
stepspeed4,
stepspeed5
};
// 083A71B0
u16 stepspeed_seq_length[] = {
16, 8, 6, 4, 2
};
// 08068B54
bool obj_npc_ministep(struct obj *o) {
u8 z = o->priv3; // direction
u16 s = o->priv4; // speed
u16 *i = &o->priv5; // phase
u16 l = stepspeed_seq_length[s];
if (*i >= l) return false;
stepspeeds[s][*i](o, z);
if ((*i)++ >= l) return true;
return false;
}
// 08068BBC
void obj_npc_ministep_set_direction(struct obj *o, u16 direction) {
o->priv3 = direction;
o->priv4 = 0;
o->priv5 = 0;
}
struct npc_image_anim_looping_info {
struct image_seq *animtable;
struct loopingpoint { u8 trigger; u8 target; } l1, l2;
};
// 08063530
struct npc_image_anim_looping_info *animtable_get_tp(void *key);
// 08063554
void npc_apply_anim_looping(struct npc_state *npc, struct obj *obj, u8 anim_number) {
if (npc->bitfield2 & (npc_unpause_pending >> 8)) return;
obj->anim_number = anim_number;
struct npc_image_anim_looping_info *tp = animtable_get_tp(obj->image_anims);
if (tp) {
if (obj->anim_frame == tp->l1.trigger) obj->anim_frame = tp->l1.trigger;
else if (obj->anim_frame == tp->l2.trigger) obj->anim_frame = tp->l2.trigger;
}
obj_anim_image_seek(obj, obj->anim_frame);
}
// 0806DE28
void npc_hide_and_trainer_flag_clear_on_role_x66_at_pos(struct npc_state *npc) {
u8 role = cur_mapdata_block_role_at(npc->to.x, npc->to.y);
if (role != 0x66) return;
sound_play(0x25);
npc_hide_by_local_id_and_map(
npc->local_id,
sav1i->location.map,
sav1i->location.group);
u16 flag = rom_npc_by_local_id_and_map_get_trainer_flag(
npc->local_id,
sav1i->location.map,
sav1i->location.group);
flag_clear(flag);
}
// 0826D2D8
i32 directions_i32[9*2] = {
0, 0,
0, 1,
0, -1,
-1, 0,
1, 0,
-1, 1,
1, 1,
-1, -1,
1, -1
};