unlockables basics
[carveJwlIkooP6JGAAIwe30JlM.git] / entity.h
1 #ifndef ENTITY_H
2 #define ENTITY_H
3
4 #include "model.h"
5
6 typedef struct ent_spawn ent_spawn;
7 typedef struct ent_light ent_light;
8 typedef struct ent_gate ent_gate;
9 typedef struct ent_route_node ent_route_node;
10 typedef struct ent_path_index ent_path_index;
11 typedef struct ent_checkpoint ent_checkpoint;
12 typedef struct ent_route ent_route;
13 typedef struct ent_water ent_water;
14 typedef struct ent_audio_clip ent_audio_clip;
15 typedef struct volume_particles volume_particles;
16 typedef struct volume_trigger volume_trigger;
17 typedef struct ent_volume ent_volume;
18 typedef struct ent_audio ent_audio;
19 typedef struct ent_marker ent_marker;
20 typedef struct ent_traffic ent_traffic;
21 typedef struct ent_font ent_font;
22 typedef struct ent_font_variant ent_font_variant;
23 typedef struct ent_glyph ent_glyph;
24 typedef struct ent_skateshop ent_skateshop;
25 typedef struct ent_camera ent_camera;
26 typedef struct ent_swspreview ent_swspreview;
27 typedef struct ent_worldinfo ent_worldinfo;
28 typedef struct ent_ccmd ent_ccmd;
29 typedef struct ent_challenge ent_challenge;
30 typedef struct ent_unlock ent_unlock;
31 typedef struct ent_relay ent_relay;
32
33 enum entity_alias{
34 k_ent_none = 0,
35 k_ent_gate = 1,
36 k_ent_spawn = 2,
37 k_ent_route_node = 3,
38 k_ent_route = 4,
39 k_ent_water = 5,
40 k_ent_volume = 6,
41 k_ent_audio = 7,
42 k_ent_marker = 8,
43 k_ent_font = 9,
44 k_ent_font_variant= 10,
45 k_ent_traffic = 11,
46 k_ent_skateshop = 12,
47 k_ent_camera = 13,
48 k_ent_swspreview = 14,
49 k_ent_menuitem = 15,
50 k_ent_worldinfo = 16,
51 k_ent_ccmd = 17,
52 k_ent_challenge = 18,
53 k_ent_unlock = 19,
54 k_ent_relay = 20
55 };
56
57 static u32 mdl_entity_id_type( u32 entity_id ){
58 return (entity_id & 0xffff0000) >> 16;
59 }
60
61 static u32 mdl_entity_id_id( u32 entity_id ){
62 return entity_id & 0x0000ffff;
63 }
64
65 static u32 mdl_entity_id( u32 type, u32 index ){
66 return (type & 0xfffff)<<16 | (index & 0xfffff);
67 }
68
69 enum entity_function{
70 k_ent_function_trigger,
71 k_ent_function_particle_spawn
72 };
73
74 struct ent_spawn{
75 mdl_transform transform;
76 u32 pstr_name;
77 };
78
79 enum light_type{
80 k_light_type_point = 0,
81 k_light_type_spot = 1
82 };
83
84 struct ent_light{
85 mdl_transform transform;
86 u32 daytime,
87 type;
88
89 v4f colour;
90 float angle,
91 range;
92
93 m4x3f inverse_world;
94 v2f angle_sin_cos;
95 };
96
97 /* v101 */
98 #if 0
99 enum gate_type{
100 k_gate_type_unlinked = 0,
101 k_gate_type_teleport = 1,
102 k_gate_type_nonlocal_unlinked = 2,
103 k_gate_type_nonlocel = 3
104 };
105 #endif
106
107 /* v102+ */
108 enum ent_gate_flag{
109 k_ent_gate_linked = 0x1, /* this is a working portal */
110 k_ent_gate_nonlocal = 0x2, /* use the key string to link this portal.
111 NOTE: if set, it adds the flip flag. */
112 k_ent_gate_flip = 0x4, /* flip direction 180* for exiting portal */
113 k_ent_gate_custom_mesh = 0x8, /* use a custom submesh instead of default */
114 k_ent_gate_locked = 0x10,/* has to be unlocked to be useful */
115 };
116
117 struct ent_gate{
118 u32 flags,
119 target,
120 key;
121
122 v3f dimensions,
123 co[2];
124
125 v4f q[2];
126
127 /* runtime */
128 m4x3f to_world, transport;
129
130 union{
131 u32 timing_version;
132
133 struct{
134 u8 ref_count;
135 };
136 };
137
138 double timing_time;
139 u16 routes[4]; /* routes that pass through this gate */
140 u8 route_count;
141
142 /* v102+ */
143 u32 submesh_start, submesh_count;
144 };
145
146 struct ent_route_node{
147 v3f co;
148 u8 ref_count, ref_total;
149 };
150
151 struct ent_path_index{
152 u16 index;
153 };
154
155 struct ent_checkpoint{
156 u16 gate_index,
157 path_start,
158 path_count;
159 };
160
161 struct ent_route{
162
163 union{
164 mdl_transform transform;
165 u32 official_track_id;
166 };
167
168 u32 pstr_name;
169 u16 checkpoints_start,
170 checkpoints_count;
171
172 v4f colour;
173
174 /* runtime */
175 u16 active_checkpoint,
176 valid_checkpoints;
177
178 float factive;
179 m4x3f board_transform;
180 mdl_submesh sm;
181 double timing_base;
182 };
183
184 struct ent_water{
185 mdl_transform transform;
186 float max_dist;
187 u32 reserved0, reserved1;
188 };
189
190 struct ent_audio_clip{
191 union{
192 mdl_file file;
193 audio_clip clip;
194 }_;
195
196 float probability;
197 };
198
199 struct volume_particles{
200 u32 blank, blank2;
201 };
202
203 struct volume_trigger{
204 u32 event, blank;
205 };
206
207 enum ent_volume_flag {
208 k_ent_volume_flag_particles = 0x1,
209 k_ent_volume_flag_disabled = 0x2
210 };
211
212 struct ent_volume{
213 mdl_transform transform;
214 m4x3f to_world, to_local;
215 u32 flags;
216
217 u32 target;
218 union{
219 volume_trigger trigger;
220 volume_particles particles;
221 };
222 };
223
224 struct ent_audio{
225 mdl_transform transform;
226 u32 flags,
227 clip_start,
228 clip_count;
229 float volume, crossfade;
230 u32 behaviour,
231 group,
232 probability_curve,
233 max_channels;
234 };
235
236 struct ent_marker{
237 mdl_transform transform;
238 u32 pstr_alias;
239 };
240
241 enum skateshop_type{
242 k_skateshop_type_boardshop,
243 k_skateshop_type_charshop,
244 k_skateshop_type_worldshop
245 };
246
247 struct ent_skateshop{
248 mdl_transform transform;
249 u32 type, id_camera;
250
251 union{
252 struct{
253 u32 id_display,
254 id_info,
255 id_rack;
256 }
257 boards;
258
259 struct{
260 u32 id_display,
261 id_info;
262 }
263 character;
264
265 struct{
266 u32 id_display,
267 id_info;
268 }
269 worlds;
270 };
271 };
272
273 struct ent_swspreview{
274 u32 id_camera, id_display, id_display1;
275 };
276
277 struct ent_traffic{
278 mdl_transform transform;
279 u32 submesh_start,
280 submesh_count,
281 start_node,
282 node_count;
283 float speed,
284 t;
285 u32 index; /* into the path */
286 };
287
288 struct ent_camera{
289 mdl_transform transform;
290 float fov;
291 };
292
293 enum ent_menuitem_type{
294 k_ent_menuitem_type_visual = 0,
295 k_ent_menuitem_type_event_button = 1,
296 k_ent_menuitem_type_page_button = 2,
297 k_ent_menuitem_type_toggle = 3,
298 k_ent_menuitem_type_slider = 4,
299 k_ent_menuitem_type_page = 5
300 };
301
302 typedef struct ent_menuitem ent_menuitem;
303 struct ent_menuitem{
304 u32 type, groups,
305 id_links[4]; /* ent_menuitem */
306 f32 factive, fvisible;
307
308 mdl_transform transform;
309 u32 submesh_start, submesh_count;
310
311 union{ u64 _u64; /* force storage for 64bit pointers */
312 i32 *pi32;
313 f32 *pf32;
314 void *pvoid;
315 };
316
317 union{
318 struct{
319 u32 id_min, /* ent_marker */
320 id_max, /* . */
321 id_handle, /* ent_menuitem */
322 pstr_data;
323 }
324 slider;
325
326 struct{
327 u32 pstr;
328 }
329 button;
330
331 struct{
332 u32 id_check, /* ent_menuitem */
333 pstr_data;
334 v3f offset; /* relative to parent */
335 }
336 checkmark;
337
338 struct{
339 u32 pstr_name,
340 id_entrypoint, /* ent_menuitem */
341 id_viewpoint; /* ent_camera */
342 }
343 page;
344 };
345 };
346
347 struct ent_worldinfo{
348 u32 pstr_name, pstr_author, pstr_desc;
349 f32 timezone;
350 };
351
352 VG_STATIC ent_marker *ent_find_marker( mdl_context *mdl,
353 mdl_array_ptr *arr, const char *alias )
354 {
355 for( u32 i=0; i<mdl_arrcount(arr); i++ ){
356 ent_marker *marker = mdl_arritm( arr, i );
357
358 if( !strcmp( mdl_pstr( mdl, marker->pstr_alias ), alias ) ){
359 return marker;
360 }
361 }
362
363 return NULL;
364 }
365
366 enum channel_behaviour{
367 k_channel_behaviour_unlimited = 0,
368 k_channel_behaviour_discard_if_full = 1,
369 k_channel_behaviour_crossfade_if_full = 2
370 };
371
372 enum probability_curve{
373 k_probability_curve_constant = 0,
374 k_probability_curve_wildlife_day = 1,
375 k_probability_curve_wildlife_night = 2
376 };
377
378 struct ent_font{
379 u32 alias,
380 variant_start,
381 variant_count,
382 glyph_start,
383 glyph_count,
384 glyph_utf32_base;
385 };
386
387 struct ent_font_variant{
388 u32 name,
389 material_id;
390 };
391
392 struct ent_glyph{
393 v2f size;
394 u32 indice_start,
395 indice_count;
396 };
397
398 struct ent_ccmd{
399 u32 pstr_command;
400 };
401
402 struct ent_challenge{
403 mdl_transform transform;
404 u32 submesh_start,
405 submesh_count,
406 id_next,
407 filter,
408 id_win,
409 win_event;
410 f32 time_limit;
411 };
412
413 struct ent_unlock{
414 u32 pstr_alias,
415 target,
416 target_event,
417 status;
418 };
419
420 struct ent_relay {
421 u32 targets[4][2];
422 };
423
424 typedef struct ent_call ent_call;
425 struct ent_call{
426 u32 id, function;
427 void *data;
428 };
429
430 #include "world.h"
431 VG_STATIC void entity_call( world_instance *world, ent_call *call );
432
433 #endif /* ENTITY_H */