-
Notifications
You must be signed in to change notification settings - Fork 2
/
npc.h
175 lines (162 loc) · 5.48 KB
/
npc.h
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
#pragma once
#include "types.h"
#include "object.h"
#define MAX_NPCS 0x10
struct proto_t;
struct ptr_and_size {
void *data;
u32 size;
};
typedef struct ptr_and_size gfxtable_t; // TODO: Review
typedef struct ptr_and_size animtable_t; // TODO: Review
typedef struct { u16 x, y; } coords; // = coords16
struct npc_pos_h {
u16 x, y;
u8 height;
};
enum npcbits {
// enum or #defines?
npc_active = 0x1,
#define NPC_BIT_ACTIVE 0x01
npc_nopause_1 = 0x2,
npc_ground_analysis_1_2 = 0x4,
npc_ground_analysis_3__on_grid = 0x8,
npc_4 = 0x10,
npc_enable_08067F2C = 0x20,
npc_nopause_2__noclear_an = 0x40,
npc_has_touched_54_58_tile = 0x80,
npc_pause_flags_are_stashed = 0x100,
npc_use_upper_direction_nibble = 0x200,
#define NPC_BIT_USE_UPPER_DIRECTION_NIBBLE 0x200
npc_block_justifies_pause = 0x400,
npc_unpause_pending = 0x800,
npc_12 = 0x1000,
npc_invisble = 0x2000,
npc_offscreen = 0x4000,
npc_15 = 0x8000,
};
struct npc_state {
u8 bitfield1;
// 0x01: active
// 0x02: exempt from general anim pausing
// 0x04: use npc_analyze_ground_{pre,post}
// 0x08: use npc_analyze_ground_post_2; on grid
// 0x10: ?
// 0x20: enables 08067F2C
// 0x40: refuse pause bit overriding
// 0x80: ?
u8 bitfield2; // a.k.a. anim and vis control
// 0x01: anim_delay_countdown backuped because of override
// 0x02: affects whether npc_set_direction affects the upper or both nibbles of npc->direction
// 0x04: pending image anim pausing (set and cleared based on "tile_to" at 08063E80 (read at 080679AC))
// 0x08: pending image anim unpausing
// 0x10: ?
// 0x20: invisible/hidden (controlled through script cmds 0x58 and 0x59)
// 0x40: offscreen/culled
// ^ these two are checked by 08067B0C
// 0x80: checked t 0805F1B4
u8 field_2;
// 0x80: backup of image anim pause flag
u8 field_3;
// 0x01: backup of rotscale anim pause flag
// 0x04: lock obj->y_height_related
u8 oam_id;
u8 type_id;
u8 running_behaviour;
u8 is_trainer;
u8 local_id;
u8 local_mapnr;
u8 local_mapgroup;
u8 height; // stored in lower 4 bits
coords stay_around;
coords to;
coords from;
u8 direction;
u8 movement_area;
u8 objid_surfing;
u8 objid_1B;
u8 state; // = an_index__movement_behaviour
u8 sight_distance;
u8 role_block_to;
u8 role_block_from;
u8 field_20;
u8 field_21_decrement_on_step;
u8 field_22;
u8 field_23;
};
struct npc_type {
u16 tile_tag;
u16 pal_tag;
u16 pal_tag_2;
u16 field_6;
coords pos_neg_center;
u8 pal_slot; // stored in lower 4 bits
u8 field_D;
u16 _unused;
// struct obj *obj;
// void *field_14;
// animtable_t *animtable1;
// gfxtable_t *gfxtable;
// animtable_t *animtable2;
gpu_sprite *sprite; // a.k.a. OAM
obj_oversize_formation *formation;
image_seq *image_anims;
gfxentry *gfx_table;
rotscale_seq *rotscale_anims;
};
// TODO: Move away
struct rom_npc {
u8 nr;
u8 type_nr;
u8 rival;
u8 field_3;
u16 x;
u16 y;
u8 height;
u8 running_behaviour;
u8 movement_area;
u8 field_B;
u8 trainer_or_mapnumber;
u8 field_D;
u16 sight_distance_or_mapgroup;
void *script;
u16 id_in_script;
u16 field_16;
};
extern struct npc_state npc_states[];
extern struct npc_type npc_types[];
u8 npc_id_by_local_id(u8 local_id, u8 mapnr, u8 mapgroup);
bool npc_id_by_local_id_and_map_ret_success(u8 local_id, u8 mapnr, u8 mapgroup, u8 *result);
u8 npc_id_by_local_id_and_map(u8 local_id, u8 mapnr, u8 mapgroup);
u8 rom_npc_to_npc_state(struct rom_npc *rnpc, u8, u8);
u8 npc_id_by_local_id_ignore_map(u8 local_id);
void npc_hide(struct npc_state *npc);
void hide_sprite(u8 local_id, u8 mapnr, u8 mapgroup);
void *npc_spawn_with_provided_template(struct rom_npc *rnpc, struct proto_t *p, u8 mapnr, u8 mapgroup, short x, short y);
void npc_to_template(u8 npc_type_id, void *objcallback, struct proto_t *p, struct obj_oversize_formation **npc_type_14);
void npc_turn(struct npc_state *npc, u8 direction);
void npc_turn_by_local_id_and_map(u16 local_id, u8 map, u8 bank, u8 direction);
struct npc_type *npc_get_type(u8 type_id);
void npc_pal_patch_range(u16 *ptx, u8 i, u8 j);
void npc_coords_shift(struct npc_state *n, u16 x, u16 y);
void npc_coords_set(struct npc_state *n, u16 x, u16 y);
void npc_coords_shift_still(struct npc_state *n);
void npcs_rebase();
bool npc_does_height_match(struct npc_state *npc, u8 height);
void npc_set_direction(struct npc_state *npc, u8 direction);
u16 trainerid_by_local_id_and_map(u8 local_id, u8 mapnr, u8 mapgroup);
u16 trainerid_by_npc_id(u8 npc_id);
struct rom_npc *rom_npc_by_nr_and_map(u8 local_id, u8 mapnr, u8 mapgroup);
u8 npc_reciprocate_look(struct npc_state *npc, u8 direction);
bool npc_obj_ministep_stop_on_arrival(struct npc_state *npc, struct obj *o);
bool npc_ministep(struct npc_state *npc, struct obj *o);
void step1(struct obj *o, u8 d);
void step2(struct obj *o, u8 d);
void step3(struct obj *o, u8 d);
void step4(struct obj *o, u8 d);
void step8(struct obj *o, u8 d);
void obj_npc_ministep_reset(struct obj *o, u16 speed, u16 phase);
bool obj_npc_ministep(struct obj *o);
void obj_npc_ministep_set_direction(struct obj *o, u16 direction);
void npc_apply_anim_looping(struct npc_state *npc, struct obj *obj, u8 anim_number);
void npc_hide_and_trainer_flag_clear_on_role_x66_at_pos(struct npc_state *npc);