|
@@ -62,6 +62,18 @@ u8 npc_dynamic_load_palette(u16 tag) {
|
62
|
62
|
return (u8)store_entry;
|
63
|
63
|
}
|
64
|
64
|
|
|
65
|
+void ov_emot_load(struct Object *obj, u16 a2, u8 a3) {
|
|
66
|
+ (void)npc_dynamic_load_palette(0x1100);
|
|
67
|
+ obj->final_oam.priority = 2;
|
|
68
|
+ obj->bitfield2 |= 2;
|
|
69
|
+ obj->priv[0] = oe_state.effect_pos.x;
|
|
70
|
+ obj->priv[1] = oe_state.effect_pos.y;
|
|
71
|
+ obj->priv[2] = oe_state.priority;
|
|
72
|
+ obj->priv[3] = -5;
|
|
73
|
+ obj->priv[7] = a2;
|
|
74
|
+ obj_anim_image_start(obj, a3);
|
|
75
|
+}
|
|
76
|
+
|
65
|
77
|
void npc_dynamic_reset() {
|
66
|
78
|
for (u8 i = 0; i < MAX_PAL_STORE; ++i) {
|
67
|
79
|
stored_palettes[i].reference_count = 0;
|
|
@@ -69,12 +81,14 @@ void npc_dynamic_reset() {
|
69
|
81
|
}
|
70
|
82
|
}
|
71
|
83
|
|
72
|
|
-void npc_dynamic_remove_entry(u8 id) {
|
73
|
|
- if (stored_palettes[id].reference_count > 0) {
|
74
|
|
- stored_palettes[id].reference_count--;
|
75
|
|
- dprintf("npc_dynamic: removed entry #%d\n", id);
|
76
|
|
- if (stored_palettes[id].reference_count == 0)
|
77
|
|
- stored_palettes[id].tag = 0;
|
|
84
|
+void npc_dynamic_remove_entry(u8 id, u16 tag) {
|
|
85
|
+ if (stored_palettes[id].tag == tag) {
|
|
86
|
+ if (stored_palettes[id].reference_count > 0) {
|
|
87
|
+ stored_palettes[id].reference_count--;
|
|
88
|
+ dprintf("npc_dynamic: removed entry #%d\n", id);
|
|
89
|
+ if (stored_palettes[id].reference_count == 0)
|
|
90
|
+ stored_palettes[id].tag = 0;
|
|
91
|
+ }
|
78
|
92
|
}
|
79
|
93
|
}
|
80
|
94
|
|
|
@@ -87,14 +101,20 @@ void npc_restore_state(u8 id, u16 x, u16 y) {
|
87
|
101
|
}
|
88
|
102
|
|
89
|
103
|
struct NpcState *npc_to_load = &npc_states[id];
|
90
|
|
- struct NpcType *type_to_load = npc_get_type(((u16)npc_to_load->type_id) | (((u16)npc_to_load->field1A << 8)));
|
|
104
|
+ u16 type_id = ((u16)npc_to_load->type_id) | (((u16)npc_to_load->field1A << 8));
|
|
105
|
+ struct NpcType *type_to_load = npc_get_type(type_id);
|
91
|
106
|
|
92
|
107
|
struct Template template_to_load;
|
93
|
108
|
u32 f14;
|
94
|
|
- npc_to_objtemplate__with_indexed_objfunc(npc_to_load->type_id, npc_to_load->running_behavior, &template_to_load,
|
|
109
|
+ npc_to_objtemplate__with_indexed_objfunc(type_id, npc_to_load->running_behavior, &template_to_load,
|
95
|
110
|
&f14);
|
96
|
111
|
template_to_load.pal_tag = 0xFFFF;
|
97
|
112
|
s8 pal_slot = npc_dynamic_load_palette(type_to_load->pal_num);
|
|
113
|
+
|
|
114
|
+ /*template_to_load.pal_tag = type_to_load->pal_num;
|
|
115
|
+ gpu_pal_obj_alloc_tag_and_apply(&npc_palettes[npc_pal_idx_for_given_tag(type_to_load->pal_num)]);
|
|
116
|
+ u8 pal_slot = gpu_pal_tags_index_of(type_to_load->pal_num);*/
|
|
117
|
+
|
98
|
118
|
u8 obj_id = template_instanciate_forward_search(&template_to_load, 0, 0, 0);
|
99
|
119
|
|
100
|
120
|
if (obj_id == 64)
|
|
@@ -113,7 +133,7 @@ void npc_restore_state(u8 id, u16 x, u16 y) {
|
113
|
133
|
}
|
114
|
134
|
|
115
|
135
|
if (f14 != 0) {
|
116
|
|
- (void) obj_set_f18_to_r0_f42_to_40(npc_obj, f14);
|
|
136
|
+ (void)obj_set_f18_to_r0_f42_to_40(npc_obj, f14);
|
117
|
137
|
}
|
118
|
138
|
|
119
|
139
|
npc_obj->final_oam.palette_num = pal_slot;
|
|
@@ -135,11 +155,16 @@ u8 npc_spawn_with_provided_template(struct RomNpc *npc, struct Template *templat
|
135
|
155
|
|
136
|
156
|
struct NpcState *created_state = &npc_states[state];
|
137
|
157
|
struct NpcType *type = npc_get_type(created_state->type_id | (npc->field3 << 8));
|
|
158
|
+
|
138
|
159
|
s8 pal_slot = npc_dynamic_load_palette(type->pal_num);
|
139
|
160
|
|
|
161
|
+ // gpu_pal_obj_alloc_tag_and_apply(&npc_palettes[npc_pal_idx_for_given_tag(type->pal_num)]);
|
|
162
|
+ // u8 pal_slot = gpu_pal_tags_index_of(type->pal_num);
|
|
163
|
+
|
140
|
164
|
if (created_state->running_behavior == 76)
|
141
|
165
|
created_state->field1 |= 0x20;
|
142
|
166
|
template->pal_tag = 0xFFFF;
|
|
167
|
+ // template->pal_tag = type->pal_num;
|
143
|
168
|
u8 obj_id = template_instanciate_forward_search(template, 0, 0, 0);
|
144
|
169
|
if (obj_id == 64) {
|
145
|
170
|
created_state->bitfield &= 0xFE;
|
|
@@ -168,3 +193,32 @@ u8 npc_spawn_with_provided_template(struct RomNpc *npc, struct Template *templat
|
168
|
193
|
npc_obj_offscreen_culling_and_flag_update(created_state, npc_object);
|
169
|
194
|
return state;
|
170
|
195
|
}
|
|
196
|
+
|
|
197
|
+void oec01_load_pal_impl(u32 *oe_script) {
|
|
198
|
+ struct SpritePalette *pal = (struct SpritePalette *)oe_read_word(oe_script);
|
|
199
|
+ s8 allocated = npc_dynamic_find_palette(pal->tag);
|
|
200
|
+ if (allocated == -1)
|
|
201
|
+ allocated = npc_dynamic_allocate_palette(pal->tag);
|
|
202
|
+ if (allocated > 0) {
|
|
203
|
+ gpu_pal_apply(pal->data, 256 + (16 * allocated), 32);
|
|
204
|
+ tint_palette_switch(allocated);
|
|
205
|
+ palette_obj_807AA8C(allocated);
|
|
206
|
+ } else {
|
|
207
|
+ dprintf("ERROR: RAN OUT OF PALETTES FOR DYNAMIC SYSTEM\n");
|
|
208
|
+ }
|
|
209
|
+ *oe_script += 4;
|
|
210
|
+}
|
|
211
|
+
|
|
212
|
+void oec02_load_pal_impl(u32 *oe_script) {
|
|
213
|
+ struct SpritePalette *pal = (struct SpritePalette *)oe_read_word(oe_script);
|
|
214
|
+ s8 allocated = npc_dynamic_find_palette(pal->tag);
|
|
215
|
+ if (allocated == -1)
|
|
216
|
+ allocated = npc_dynamic_allocate_palette(pal->tag);
|
|
217
|
+ if (allocated > 0) {
|
|
218
|
+ gpu_pal_apply(pal->data, 256 + (16 * allocated), 32);
|
|
219
|
+ tint_palette_switch(allocated);
|
|
220
|
+ } else {
|
|
221
|
+ dprintf("ERROR: RAN OUT OF PALETTES FOR DYNAMIC SYSTEM\n");
|
|
222
|
+ }
|
|
223
|
+ *oe_script += 4;
|
|
224
|
+}
|