1 /*
2  *                          SAR File Format IO
3  *
4  *	For mission and scenery files, loads data from those files into
5  *	an array of structures for easy manipulation.
6  */
7 
8 #ifndef SARFIO_H
9 #define SARFIO_H
10 
11 #include <sys/types.h>
12 
13 
14 /*
15  *	File format codes:
16  */
17 #define SAR_FILE_FORMAT_SCENE		1
18 #define SAR_FILE_FORMAT_MISSION		2
19 #define SAR_FILE_FORMAT_MISSION_LOG	4
20 
21 /*
22  *	File format parameter and value type codes:
23  */
24 #define SAR_PARM_VERSION		10	/* Of respective file */
25 #define SAR_PARM_NAME			11	/* Of respective file */
26 #define SAR_PARM_DESCRIPTION		12	/* Of respective file */
27 #define SAR_PARM_PLAYER_MODEL_FILE	13
28 #define SAR_PARM_WEATHER		14
29 #define SAR_PARM_TIME_OF_DAY		15
30 
31 #define SAR_PARM_REGISTER_LOCATION	20
32 #define SAR_PARM_SCENE_GPS		21
33 #define SAR_PARM_SCENE_MAP              22
34 #define SAR_PARM_SCENE_ELEVATION	23
35 #define SAR_PARM_SCENE_CANT		24
36 #define SAR_PARM_SCENE_GROUND_FLAGS	25
37 #define SAR_PARM_SCENE_GROUND_TILE	26
38 
39 #define SAR_PARM_TEXTURE_BASE_DIRECTORY 30
40 #define SAR_PARM_TEXTURE_LOAD		31
41 
42 #define SAR_PARM_MISSION_SCENE_FILE	40
43 #define SAR_PARM_MISSION_NEW_OBJECTIVE	41
44 #define SAR_PARM_MISSION_TIME_LEFT	42
45 #define SAR_PARM_MISSION_BEGIN_AT	43
46 #define SAR_PARM_MISSION_BEGIN_AT_POS	44
47 #define SAR_PARM_MISSION_ARRIVE_AT	45
48 #define SAR_PARM_MISSION_MESSAGE_SUCCESS	46
49 #define SAR_PARM_MISSION_MESSAGE_FAIL		47
50 #define SAR_PARM_MISSION_HUMANS_TALLY	48
51 #define SAR_PARM_MISSION_ADD_INTERCEPT	49
52 
53 #define SAR_PARM_MISSION_LOG_HEADER	80
54 #define SAR_PARM_MISSION_LOG_EVENT	81
55 
56 #define SAR_PARM_NEW_OBJECT		100
57 #define SAR_PARM_NEW_HELIPAD		101
58 #define SAR_PARM_NEW_RUNWAY		102
59 #define SAR_PARM_NEW_HUMAN		103
60 #define SAR_PARM_NEW_FIRE		104
61 #define SAR_PARM_NEW_SMOKE		105
62 #define SAR_PARM_NEW_PREMODELED		106
63 #define SAR_PARM_SELECT_OBJECT_BY_NAME	107
64 #define SAR_PARM_MODEL_FILE		108
65 #define SAR_PARM_RANGE			109
66 #define SAR_PARM_RANGE_FAR		110
67 #define SAR_PARM_TRANSLATE		111
68 #define SAR_PARM_TRANSLATE_RANDOM	112
69 #define SAR_PARM_ROTATE			113
70 #define SAR_PARM_NO_DEPTH_TEST		114
71 #define SAR_PARM_POLYGON_OFFSET		115
72 #define SAR_PARM_CONTACT_BOUNDS_SPHERICAL	116
73 #define SAR_PARM_CONTACT_BOUNDS_CYLENDRICAL	117
74 #define SAR_PARM_CONTACT_BOUNDS_RECTANGULAR	118
75 #define SAR_PARM_GROUND_ELEVATION	119
76 
77 #define SAR_PARM_OBJECT_NAME		130
78 #define SAR_PARM_OBJECT_MAP_DESCRIPTION	131
79 #define SAR_PARM_FUEL			132
80 #define SAR_PARM_HITPOINTS		133
81 #define SAR_PARM_ENGINE_STATE		134
82 #define SAR_PARM_PASSENGERS		135	/* And crew */
83 #define SAR_PARM_RUNWAY_APPROACH_LIGHTING_NORTH	150
84 #define SAR_PARM_RUNWAY_APPROACH_LIGHTING_SOUTH	151
85 #define SAR_PARM_HUMAN_MESSAGE_ENTER	180
86 #define SAR_PARM_HUMAN_REFERENCE	181
87 
88 
89 /*
90  *	File format parameter and value structures:
91  *
92  *	All structures have the first member to be an int named type
93  *	to indicate what kind of structure it is.
94  */
95 /* SAR_PARM_VERSION */
96 typedef struct {
97 	int type;
98 	int major, minor, release;
99 	char *copyright;
100 } sar_parm_version_struct;
101 
102 /* SAR_PARM_NAME */
103 typedef struct {
104 
105 	int type;
106 	char *name;
107 
108 } sar_parm_name_struct;
109 
110 /* SAR_PARM_DESCRIPTION */
111 typedef struct {
112 
113         int type;
114         char *description;
115 
116 } sar_parm_description_struct;
117 
118 /* SAR_PARM_PLAYER_MODEL_FILE */
119 typedef struct {
120 
121         int type;
122         char *file;
123 
124 } sar_parm_player_model_file_struct;
125 
126 /* SAR_PARM_WEATHER */
127 typedef struct {
128 
129 	int type;
130 	char *weather_preset_name;
131 
132 } sar_parm_weather_struct;
133 
134 /* SAR_PARM_TIME_OF_DAY */
135 typedef struct {
136 
137         int type;
138 	float tod;	/* Time of day (in seconds) since midnight */
139 
140 } sar_parm_time_of_day_struct;
141 
142 
143 /* SAR_PARM_REGISTER_LOCATION */
144 typedef struct {
145 
146         int type;
147 	char *name;
148 	sar_position_struct pos;
149 	sar_direction_struct dir;
150 
151 } sar_parm_register_location_struct;
152 
153 /* SAR_PARM_SCENE_GPS */
154 typedef struct {
155 
156         int type;
157 	float	dms_x_offset,	/* In degrees */
158 		dms_y_offset;
159 	float	planet_radius;	/* In meters */
160 
161 } sar_parm_scene_gps_struct;
162 
163 /* SAR_PARM_SCENE_MAP */
164 typedef struct {
165 
166         int type;
167         char	*file;		/* Scene map texture file */
168         float	width, height;	/* In meters */
169 
170 } sar_parm_scene_map_struct;
171 
172 /* SAR_PARM_SCENE_ELEVATION */
173 typedef struct {
174 
175         int type;
176 	float	elevation;	/* In meters */
177 
178 } sar_parm_scene_elevation_struct;
179 
180 /* SAR_PARM_SCENE_CANT */
181 typedef struct {
182 
183         int type;
184 	float	cant;	/* Radians to be applied (added) to readout angles */
185 
186 } sar_parm_scene_cant_struct;
187 
188 /* SAR_PARM_SCENE_GROUND_FLAGS */
189 typedef struct {
190 
191         int type;
192 	sar_obj_flags_t flags;	/* Any of SAR_SCENE_BASE_FLAG_* */
193 
194 } sar_parm_scene_ground_flags_struct;
195 
196 /* SAR_PARM_SCENE_GROUND_TILE */
197 typedef struct {
198 
199         int type;
200 	int tile_width, tile_height;		/* In meters */
201 	float close_range;			/* In meters */
202 	sar_color_struct color;			/* Far solid color */
203 	char *texture_name;
204 
205 } sar_parm_scene_ground_tile_struct;
206 
207 
208 /* SAR_PARM_TEXTURE_BASE_DIRECTORY */
209 typedef struct {
210 
211         int type;
212 	char *directory;
213 
214 } sar_parm_texture_base_directory_struct;
215 
216 /* SAR_PARM_TEXTURE_LOAD */
217 typedef struct {
218 
219         int type;
220 	char *name;
221 	char *file;
222 	float priority;
223 
224 } sar_parm_texture_load_struct;
225 
226 
227 /* SAR_PARM_MISSION_SCENE_FILE */
228 typedef struct {
229 
230         int type;
231         char *file;
232 
233 } sar_parm_mission_scene_file_struct;
234 
235 /* SAR_PARM_MISSION_NEW_OBJECTIVE */
236 typedef struct {
237 
238 	int type;
239 	int objective_type;	/* One of SAR_MISSION_OBJECTIVE_* */
240 
241 } sar_parm_mission_new_objective_struct;
242 
243 /* SAR_PARM_MISSION_TIME_LEFT */
244 typedef struct {
245 
246         int type;
247 	float	time_left;	/* In seconds */
248 
249 } sar_parm_mission_time_left_struct;
250 
251 /* SAR_PARM_MISSION_BEGIN_AT */
252 typedef struct {
253 
254         int type;
255 	char *name;
256 
257 } sar_parm_mission_begin_at_struct;
258 
259 /* SAR_PARM_MISSION_BEGIN_AT_POS */
260 typedef struct {
261 
262 	int type;
263 	sar_position_struct pos;
264 	sar_direction_struct dir;
265 
266 } sar_parm_mission_begin_at_pos_struct;
267 
268 /* SAR_PARM_MISSION_ARRIVE_AT */
269 typedef struct {
270 
271         int type;
272         char *name;		/* Name of object to arrive at */
273 
274 } sar_parm_mission_arrive_at_struct;
275 
276 /* SAR_PARM_MISSION_MESSAGE_SUCCESS */
277 typedef struct {
278 
279         int type;
280         char *message;
281 
282 } sar_parm_mission_message_success_struct;
283 
284 /* SAR_PARM_MISSION_MESSAGE_FAIL */
285 typedef struct {
286 
287         int type;
288         char *message;
289 
290 } sar_parm_mission_message_fail_struct;
291 
292 /* SAR_PARM_MISSION_HUMANS_TALLY */
293 typedef struct {
294 
295         int type;
296 	int humans_need_rescue;	/* Initial starting total, must be
297 				 * less or equal to total_humans.
298 				 */
299 	int total_humans;	/* Total humans that need rescue */
300 
301 } sar_parm_mission_humans_tally_struct;
302 
303 /* SAR_PARM_MISSION_ADD_INTERCEPT */
304 typedef struct {
305 
306         int type;
307 
308 	/* Reference code:
309 	 * 0 = Standard
310 	 * 1 = (Reserved)
311 	 * 2 = Begin at location
312 	 * 3 = Arrive at location
313 	 */
314 	int	ref_code;
315 
316 	sar_position_struct pos;
317 	float	radius;
318 	float	urgency;
319 	char	*name;
320 
321 } sar_parm_mission_add_intercept_struct;
322 
323 
324 /* SAR_PARM_MISSION_LOG_HEADER */
325 typedef struct {
326 
327 	int type;
328 	int	version_major,
329 		version_minor,
330 		version_release;
331 	char	*title;
332 	char	*scene_file;
333 	char	*player_stats_file;
334 
335 } sar_parm_mission_log_header_struct;
336 
337 /* SAR_PARM_MISSION_LOG_EVENT */
338 typedef struct {
339 
340 	int type;
341 	int	event_type;	/* One of SAR_MISSION_LOG_EVENT_* */
342 	float	tod;		/* Time of day (in seconds) since midnight */
343 	sar_position_struct pos;
344 	char	*message;
345 
346 } sar_parm_mission_log_event_struct;
347 
348 
349 /* SAR_PARM_NEW_OBJECT */
350 typedef struct {
351 
352         int type;
353 	int object_type;	/* One of SAR_OBJ_TYPE_* */
354 
355 } sar_parm_new_object_struct;
356 
357 /* SAR_PARM_NEW_HELIPAD */
358 typedef struct {
359 
360         int type;
361 
362 	sar_obj_flags_t flags;  /* Any of SAR_HELIPAD_FLAG_* */
363 
364 	char	*style;
365 	float	length, width;	/* In meters */
366 	float	recession;	/* In meters */
367 
368 	char	*label;
369 
370 	char	*ref_obj_name;
371 	sar_position_struct	ref_offset;	/* Rel to ref object */
372         sar_direction_struct	ref_dir;	/* Rel to ref object */
373 
374 } sar_parm_new_helipad_struct;
375 
376 /* SAR_PARM_NEW_RUNWAY */
377 typedef struct {
378 
379         int		type;
380 
381 	sar_obj_flags_t	flags;  /* Any of SAR_RUNWAY_FLAG_* */
382 
383 	float		range;		/* Visual range in meters */
384 	float		length,		/* Size (in meters) */
385 			width;
386 	int		surface_type;	/* One of SAR_RUNWAY_SURFACE_* */
387 
388 	char		*north_label,
389 			*south_label;
390 
391 	int		dashes;		/* Number of dashes (0 for none) */
392 
393 	float		north_displaced_threshold,	/* In meters (0.0 for none) */
394 			south_displaced_threshold;
395 
396 	float		edge_light_spacing;		/* In meters (0.0 for none) */
397 
398 } sar_parm_new_runway_struct;
399 
400 /* SAR_PARM_NEW_HUMAN */
401 typedef struct {
402 
403 	int type;
404 	char	*type_name;
405 	sar_obj_flags_t	flags;	/* Any of SAR_HUMAN_FLAG_* */
406 
407 } sar_parm_new_human_struct;
408 
409 /* SAR_PARM_NEW_FIRE */
410 typedef struct {
411 
412 	int type;
413 	float	radius,		/* Size in meters */
414 		height;		/* Height above base in meters */
415 
416 } sar_parm_new_fire_struct;
417 
418 /* SAR_PARM_NEW_SMOKE */
419 typedef struct {
420 
421 	int type;
422 	sar_position_struct offset;
423 	float	radius_start,	/* In meters */
424 		radius_max,	/* In meters */
425 		radius_rate;	/* Can be -1.0 for autocalculate */
426 	int hide_at_max;
427 	time_t respawn_int;	/* Respawn interval in ms */
428 	int total_units;
429 	int color_code;		/* 0 = light grey/white
430 				 * 1 = medium grey
431 				 * 2 = dark/black
432 				 */
433 } sar_parm_new_smoke_struct;
434 
435 /* SAR_PARM_NEW_PREMODELED */
436 typedef struct {
437 
438         int type;
439 	char *model_type;
440 
441 	/* Arguments (not including the model type) */
442 	char **argv;
443 	int argc;
444 
445 } sar_parm_new_premodeled_struct;
446 
447 /* SAR_PARM_SELECT_OBJECT_BY_NAME */
448 typedef struct {
449 
450 	int type;
451 	char *name;
452 
453 } sar_parm_select_object_by_name_struct;
454 
455 /* SAR_PARM_MODEL_FILE */
456 typedef struct {
457 
458         int type;
459 	char *file;
460 
461 } sar_parm_model_file_struct;
462 
463 /* SAR_PARM_RANGE */
464 typedef struct {
465 
466         int type;
467 	float	range;		/* In meters */
468 
469 } sar_parm_range_struct;
470 
471 /* SAR_PARM_RANGE_FAR */
472 typedef struct {
473 
474         int type;
475         float	range_far;	/* In meters */
476 
477 } sar_parm_range_far_struct;
478 
479 /* SAR_PARM_TRANSLATE */
480 typedef struct {
481 
482         int type;
483 	sar_position_struct translate;
484 
485 } sar_parm_translate_struct;
486 
487 /* SAR_PARM_TRANSLATE_RANDOM */
488 typedef struct {
489 
490 	int type;
491 	float	radius_bound;	/* In meters */
492 	float	z_bound;	/* In meters */
493 
494 } sar_parm_translate_random_struct;
495 
496 /* SAR_PARM_ROTATE */
497 typedef struct {
498 
499         int type;
500 	sar_direction_struct rotate;
501 
502 } sar_parm_rotate_struct;
503 
504 /* SAR_PARM_NO_DEPTH_TEST */
505 typedef struct {
506 
507         int type;
508 
509 } sar_parm_no_depth_test_struct;
510 
511 /* SAR_PARM_POLYGON_OFFSET */
512 typedef struct {
513 
514         int type;
515 
516 	/* Offset flags, can contain any of the following:
517 	 * SAR_OBJ_FLAG_POLYGON_OFFSET,
518 	 * SAR_OBJ_FLAG_POLYGON_OFFSET_REVERSE, and/or
519 	 * SAR_OBJ_FLAG_POLYGON_OFFSET_WRITE_DEPTH
520 	 */
521 	sar_obj_flags_t flags;
522 
523 } sar_parm_polygon_offset_struct;
524 
525 /* SAR_PARM_CONTACT_BOUNDS_SPHERICAL */
526 typedef struct {
527 
528         int type;
529 	float	radius;		/* In meters */
530 
531 } sar_parm_contact_bounds_spherical_struct;
532 
533 /* SAR_PARM_CONTACT_BOUNDS_CYLENDRICAL */
534 typedef struct {
535 
536         int type;
537 	float	radius;		/* In meters */
538 	float	height_min,	/* In meters */
539 		height_max;
540 
541 } sar_parm_contact_bounds_cylendrical_struct;
542 
543 /* SAR_PARM_CONTACT_BOUNDS_RECTANGULAR */
544 typedef struct {
545 
546         int type;
547 	float	x_min, x_max,		/* In meters */
548 		y_min, y_max,
549 		z_min, z_max;
550 
551 } sar_parm_contact_bounds_rectangular_struct;
552 
553 /* SAR_PARM_GROUND_ELEVATION */
554 typedef struct {
555 
556         int type;
557 	float	elevation;		/* In meters */
558 
559 } sar_parm_ground_elevation_struct;
560 
561 /* SAR_PARM_OBJECT_NAME */
562 typedef struct {
563 
564         int type;
565         char *name;
566 
567 } sar_parm_object_name_struct;
568 
569 /* SAR_PARM_OBJECT_MAP_DESCRIPTION */
570 typedef struct {
571 
572         int type;
573         char *description;
574 
575 } sar_parm_object_map_description_struct;
576 
577 /* SAR_PARM_FUEL */
578 typedef struct {
579 
580         int type;
581 	float	fuel,		/* In kg */
582 		fuel_max;
583 
584 } sar_parm_fuel_struct;
585 
586 /* SAR_PARM_HITPOINTS */
587 typedef struct {
588 
589         int type;
590 	float	hitpoints,
591 		hitpoints_max;
592 
593 } sar_parm_hitpoints_struct;
594 
595 /* SAR_PARM_ENGINE_STATE */
596 typedef struct {
597 
598         int type;
599 	int state;		/* One of SAR_ENGINE_STATE_* */
600 
601 } sar_parm_engine_state_struct;
602 
603 /* SAR_PARM_PASSENGERS */
604 typedef struct {
605 
606         int type;
607 	int	passengers,
608 		passengers_max;	/* Can be -1 for leave as is */
609 
610 } sar_parm_passengers_struct;
611 
612 /* SAR_PARM_RUNWAY_APPROACH_LIGHTING_NORTH */
613 typedef struct {
614 
615         int type;
616 
617         /* Any of SAR_RUNWAY_APPROACH_LIGHTING_* */
618         sar_obj_flags_t flags;
619 
620 } sar_parm_runway_approach_lighting_north_struct;
621 
622 /* SAR_PARM_RUNWAY_APPROACH_LIGHTING_SOUTH */
623 typedef struct {
624 
625         int type;
626 
627         /* Any of SAR_RUNWAY_APPROACH_LIGHTING_* */
628         sar_obj_flags_t flags;
629 
630 } sar_parm_runway_approach_lighting_south_struct;
631 
632 /* SAR_PARM_HUMAN_MESSAGE_ENTER */
633 typedef struct {
634 
635         int type;
636 	char *message;
637 
638 } sar_parm_human_message_enter_struct;
639 
640 /* SAR_PARM_HUMAN_REFERENCE */
641 typedef struct {
642 
643         int type;
644 
645 	/* Can contain one of the following flags;
646 	 * SAR_HUMAN_FLAG_RUN_TOWARDS or SAR_HUMAN_FLAG_RUN_AWAY
647 	 */
648 	sar_obj_flags_t flags;
649 
650 	/* Name of reference object to run to or run away from */
651         char *reference_name;
652 
653 } sar_parm_human_reference_struct;
654 
655 
656 /* In sarfio.c */
657 extern void *SARParmNew(int type);
658 extern void *SARParmNewAppend(int type, void ***ptr, int *total);
659 extern void SARParmDelete(void *p);
660 extern void SARParmDeleteAll(void ***ptr, int *total);
661 
662 /* In sarfioopen.c */
663 extern int SARParmLoadFromFile(
664         const char *filename, int file_format,
665         void ***parm, int *total_parms,
666 	int filter_parm_type,		/* One of SAR_PARM_* or -1 */
667         void *client_data,
668         int (*progress_func)(void *, long, long)
669 );
670 
671 /* In sarfiosave.c */
672 extern int SARParmSaveToFile(
673 	const char *filename, int file_format,
674 	void **parm, int total_parms,
675 	void *client_data,
676 	int (*progress_func)(void *, long, long)
677 );
678 
679 
680 #endif	/* SARFIO_H */
681