1 /*
2 			  Search and Rescue Core
3  */
4 
5 #ifndef SAR_H
6 #define SAR_H
7 
8 #include <limits.h>
9 #include <sys/types.h>
10 #ifdef __MSW__
11 # include "../include/os.h"
12 #else
13 # include <sys/time.h>
14 #endif
15 
16 #include "gw.h"
17 #include "stategl.h"
18 #include "textinput.h"
19 #include "obj.h"
20 #include "human.h"
21 #include "weather.h"
22 #include "gctl.h"
23 #include "menu.h"
24 #include "sound.h"
25 #include "musiclistio.h"
26 #include "mission.h"
27 #include "texturelistio.h"
28 #include "sarfps.h"
29 #include "sarfio.h"
30 
31 
32 /*
33  *	Units:
34  */
35 typedef enum {
36 	SAR_UNITS_ENGLISH,
37 	SAR_UNITS_METRIC,
38 	SAR_UNITS_METRIC_ALT_FEET
39 } sar_units;
40 
41 /*
42  *	Rotor Blur Styles:
43  */
44 typedef enum {
45 	SAR_ROTOR_BLUR_SOLID,
46 	SAR_ROTOR_BLUR_CLOCK_RADIAL
47 } sar_rotor_blur_style;
48 
49 /*
50  *	Flight Physics Levels:
51  */
52 typedef enum {
53 	FLIGHT_PHYSICS_EASY,
54 	FLIGHT_PHYSICS_MODERATE,
55 	FLIGHT_PHYSICS_REALISTIC
56 } sar_flight_physics_level;
57 
58 /*
59  *	Options:
60  */
61 typedef struct {
62 
63 	Boolean		menu_backgrounds,	/* Draw menu backgrounds */
64 			menu_change_affects,	/* Special affects when changing menus */
65 			menu_always_full_redraw;	/* Always do complete
66 							 * menu redraws even if
67 							 * only a part of the
68 							 * menu has changed
69 							 * (needed for some
70 							 * accelerated video
71 							 * cards */
72 
73         Boolean		console_quiet,
74 			internal_debug,
75 			runtime_debug,
76 			prioritize_memory;
77 
78 	/* Units */
79 	sar_units	units;
80 
81 	/* Graphics options */
82 	Boolean		textured_ground,
83 			textured_objects,
84 			textured_clouds,
85 			atmosphere,
86 			dual_pass_depth,
87 			prop_wash,
88 			smoke_trails,
89 			celestial_objects;
90 
91 	float		gl_polygon_offset_factor;	/* For glPolygonOffset() */
92 
93 	/* GL shade model for drawing premodeled objects only
94 	 * (GL_FLAT or GL_SMOOTH
95 	 */
96 	int		gl_shade_model;
97 
98 	/* Maximum drawing visibility (0 to 6)
99 	 *
100 	 * Computed by; miles = 3 + (option.visibility_max * 3)
101 	 */
102 	int		visibility_max;
103 
104 	/* Rotor blade blur style */
105 	sar_rotor_blur_style	rotor_blur_style;
106 
107 	/* Graphics acceleration coefficient, 1.0 is for maximum and
108 	 * 0.0 is for none/minimum
109 	 */
110 	float		graphics_acceleration;
111 
112 	/* Sound options */
113 	Boolean		engine_sounds,
114 			event_sounds,
115 			voice_sounds,
116 			music;
117 
118 	/* Sound priority (one of SND_PRIORITY_*) */
119 	int		sound_priority;
120 
121 	/* Use system time when starting free flights */
122 	Boolean		system_time_free_flight;
123 
124 	/* HUD color and font */
125 	sar_color_struct	hud_color;
126 	GWFont		*hud_font;
127 
128 	/* Standard messages color and font */
129 	sar_color_struct	message_color;
130 	GWFont		*message_font;
131 	GWFont		*menu_font;	/* Menu std font (except menu values) */
132 
133 	Boolean		show_hud_text,		/* Show HUD text */
134 			show_outside_text;	/* Show outside display text */
135 
136 	/* Sticky banner text (first line) big font */
137 	GWFont		*banner_font;
138 
139 
140 	/* Intervals in milliseconds */
141 	time_t		explosion_frame_int,	/* Explosion frame inc interval */
142 			splash_frame_int;	/* Splash frame inc interval */
143 
144 	time_t		crash_explosion_life_span,	/* Explosions by crashes */
145 			fuel_tank_life_span;	/* Dropped tanks landed on ground */
146 
147 	float		rotor_wash_vis_coeff;	/* 0.0 to 1.0 */
148 
149 	/* Game controllers mask, any of GCTL_CONTROLLER_* */
150 	gctl_controllers	gctl_controllers;
151 	/* Game controller options mask */
152 	gctl_options		gctl_options;
153 
154 	/* Joystick priority, one of GCTL_JS_PRIORITY_* */
155 	gctl_js_priority	js_priority;
156 
157 	/* Joystick connection type, one of GCTL_JS_CONNECTION_* */
158 	int		js0_connection,
159 			js1_connection;
160 
161 	/* Joystick button mappings */
162 	int		js0_btn_rotate,		/* Treat bank to heading axis */
163 			js0_btn_air_brakes,
164 			js0_btn_wheel_brakes,
165 			js0_btn_zoom_in,
166 			js0_btn_zoom_out,
167 			js0_btn_hoist_up,
168 			js0_btn_hoist_down;
169 
170 	int		js1_btn_rotate,		/* Treat bank as heading axis */
171 			js1_btn_air_brakes,
172 			js1_btn_wheel_brakes,
173 			js1_btn_zoom_in,
174 			js1_btn_zoom_out,
175 			js1_btn_hoist_up,
176 			js1_btn_hoist_down;
177 
178 	/* Game controller joystick axis roles, any of
179 	 * GCTL_JS_AXIS_ROLE_*
180 	 *
181 	 * If any of these are all 0 then that implies the joystick is
182 	 * not enabled
183 	 */
184 	gctl_js_axis_roles	gctl_js0_axis_roles,
185 				gctl_js1_axis_roles;
186 
187 	/* Simulation difficulty */
188 	float		hoist_contact_expansion_coeff;	/* Hoist contact radius coeff */
189 	float		damage_resistance_coeff;
190 	sar_flight_physics_level	flight_physics_level;
191 
192 
193 	/* Last run selections */
194 	int		last_selected_player,
195 			last_selected_mission,	/* Matches menu list obj sel pos */
196 			last_selected_ffscene,
197 			last_selected_ffaircraft,
198 			last_selected_ffweather;
199 
200 	/* Last geometry of main window */
201 	int		last_x,
202 			last_y,
203 			last_width,
204 			last_height;
205 	Boolean		last_fullscreen;
206 	int             draw_style;
207 
208 } sar_option_struct;
209 #define SAR_OPTION(p)	((sar_option_struct *)(p))
210 
211 
212 /*
213  *	Directory names:
214  */
215 typedef struct {
216 
217 	char local_data[PATH_MAX];
218 	char global_data[PATH_MAX];
219 
220 } sar_dname_struct;
221 extern sar_dname_struct dname;
222 
223 /*
224  *	File names:
225  */
226 typedef struct {
227 
228 	/* Main configuration file */
229 	char options[PATH_MAX + NAME_MAX];
230 
231 	/* Predefined humans file */
232 	char human[PATH_MAX + NAME_MAX];
233 
234 	/* Music references file */
235 	char music[PATH_MAX + NAME_MAX];
236 
237 	/* Players file */
238 	char players[PATH_MAX + NAME_MAX];
239 
240 	/* Global textures file */
241 	char textures[PATH_MAX + NAME_MAX];
242 
243 	/* Predefined weather conditions file */
244 	char weather[PATH_MAX + NAME_MAX];
245 
246 	/* Mission log file */
247 	char mission_log[PATH_MAX + NAME_MAX];
248 
249 } sar_fname_struct;
250 extern sar_fname_struct fname;
251 
252 
253 /*
254  *	Timmers:
255  *
256  *	All members are in milliseconds.
257  */
258 typedef struct {
259 
260 	time_t	reclaim;
261 
262 } sar_next_struct;
263 extern sar_next_struct next;
264 
265 
266 /*
267  *	Player statistics:
268  */
269 typedef struct {
270 
271 	char	*name;
272 
273 	int	score,
274 		crashes,
275 		rescues,
276 		missions_succeeded,
277 		missions_failed;
278 
279 	time_t	time_aloft;		/* Seconds */
280 
281 	time_t	last_mission,		/* Systime seconds */
282 		last_free_flight;
283 
284 } sar_player_stat_struct;
285 #define SAR_PLAYER_STAT(p)	((sar_player_stat_struct *)(p))
286 
287 
288 /*
289  *	Map name matching structure for SARDrawMap():
290  *
291  *	Map draw OpenGL names to string names record structure, used in
292  *	sardraw.c's map drawing function. This is used for selection
293  *	matching.
294  *
295  *	Note that the structure's index is not the matched object's index.
296  *	The matched object's index will be dmon_ptr->gl_name if and only
297  *	if it is 0 <= dmon_ptr->gl_name < total_objects.
298  */
299 typedef struct {
300 
301 	/* The object's index number or some special code. A special
302 	 * code is when: gl_name >= total_objects AND when total_objects
303 	 * is subtracted from gl_name: special_code = gl_name -
304 	 * total_objects (and not negative)
305 	 */
306 	GLuint	gl_name;
307 
308 	/* Coppied pointer to the object's name */
309 	char	*obj_name;
310 
311 } sar_drawmap_objname_struct;
312 #define SAR_DRAWMAP_OBJNAME(p)	((sar_drawmap_objname_struct *)(p))
313 
314 
315 /*
316  *	Core structure:
317  */
318 typedef struct {
319 
320 	/* Program file (name only) and full path */
321 	char		*prog_file;
322 	char		*prog_file_full_path;
323 
324 	/* Stop count, used during the loading of scene/mission and
325 	 * other places where the user may want to abort
326 	 */
327 	int		stop_count;
328 
329 	/* Video, sound, and game controller */
330 	gw_display_struct	*display;	/* Graphics Wrapper */
331 	char		*recorder_address;	/* Sound Server Address */
332 	snd_recorder_struct	*recorder;	/* Sound Server Connection */
333 	char		*audio_mode_name;	/* Sound Server's current Audio Mode */
334 	gctl_struct	*gctl;			/* Game Controller */
335 
336 	/* Our code to indicate what background music is currently being
337 	 * played (one of SAR_MUSIC_ID_*).
338 	 */
339 	int		cur_music_id;
340 
341 	/* Music file references list */
342 	sar_music_ref_struct	**music_ref;
343 	int		total_music_refs;
344 
345 
346 	/* Human presets data */
347 	sar_human_data_struct	*human_data;
348 
349 	/* Weather presets data */
350 	sar_weather_data_struct	*weather_data;
351 
352 	/* SAR Scene, Objects, and Mission */
353 	sar_scene_struct	*scene;		/* SAR scene */
354 	sar_mission_struct	*mission;	/* SAR mission */
355 	sar_object_struct	**object;	/* SAR objects */
356 	int		total_objects;
357 
358 
359 	/* Menu and shared data for menus */
360 	sar_menu_struct	**menu;
361 	int		total_menus,
362 			cur_menu;
363 	/* Menu images (shared amoung menu object/widgets */
364 	sar_image_struct	**menu_list_bg_img,	/* 9 images */
365 				*menu_button_armed_img,
366 				*menu_button_unarmed_img,
367 				*menu_button_highlighted_img,
368 				*menu_button_label_img,
369 				*menu_label_bg_img,
370 				*menu_switch_bg_img,
371 				*menu_switch_off_img,
372 				*menu_switch_on_img,
373 				*menu_spin_label_img,
374 				*menu_spin_value_img,
375 				*menu_spin_dec_armed_img,
376 				*menu_spin_dec_unarmed_img,
377 				*menu_spin_inc_armed_img,
378 				*menu_spin_inc_unarmed_img,
379 				*menu_slider_label_img,
380 				*menu_slider_trough_img,
381 				*menu_slider_handle_img,
382 				*menu_progress_bg_img,
383 				*menu_progress_fg_img,
384 
385 				*menu_button_pan_up_armed_img,
386 				*menu_button_pan_up_unarmed_img,
387 				*menu_button_pan_down_armed_img,
388 				*menu_button_pan_down_unarmed_img,
389 				*menu_button_pan_left_armed_img,
390 				*menu_button_pan_left_unarmed_img,
391 				*menu_button_pan_right_armed_img,
392 				*menu_button_pan_right_unarmed_img,
393 
394 				*menu_button_zoom_in_armed_img,
395 				*menu_button_zoom_in_unarmed_img,
396 				*menu_button_zoom_out_armed_img,
397 				*menu_button_zoom_out_unarmed_img,
398 
399 				*menumap_helipad_img,	/* Helipad */
400 				*menumap_intercept_img,	/* Intercept point */
401 				*menumap_helicopter_img,/* Helicopter */
402 				*menumap_victim_img,	/* Victim */
403 				*menumap_vessel_img,	/* Vessel */
404 				*menumap_crash_img;	/* Crash/explosion */
405 
406 	/* Global list of standard texture reference names and file names
407 	 * that are to be loaded *when* a scene is loaded so that it
408 	 * has a standard set of textures to use
409 	 */
410 	sar_texture_name_struct	**texture_list;
411 	int		total_texture_list;
412 
413 	/* Player stats (also list of players) */
414 	sar_player_stat_struct	**player_stat;
415 	int		total_player_stats;
416 
417 	/* Selected files */
418 	char		*cur_mission_file;
419 	char		*cur_player_model_file;
420 	char		*cur_scene_file;
421 
422 	/* Display help during simulation, value of 0 means display
423 	 * nothing while any positive value corresponds to the `page'
424 	 * being displayed starting from page 1 being a value of 1
425 	 */
426 	int		display_help;
427 
428 	/* FLIR (night visiion) state */
429 	Boolean		flir;
430 
431 	/* Draw map object name reference structures, used by
432 	 * SARDrawMap()
433 	 */
434 	sar_drawmap_objname_struct	**drawmap_objname;
435 	int		total_drawmap_objnames;
436 	/* Draw map ground hit contact result, a value from 0.0 to
437 	 * 1.0 which corresponds to the alpha value from reading
438 	 * back the pixels
439 	 */
440 	float		drawmap_ghc_result;
441 
442 	/* Text input prompt */
443 	text_input_struct	*text_input;
444 	void		(*text_input_cb)(
445 		void *,			/* Data */
446 		const char *		/* Value */
447 	);
448 
449 	/* Options */
450 	sar_option_struct	option;
451 
452 	/* Frames Per Second counter
453 	 *
454 	 * Note that that we have one FPS per Graphics Wrapper
455 	 * (which we only have one) so we only have one FPS
456 	 */
457 	sar_fps_struct	fps;
458 
459 } sar_core_struct;
460 
461 #define SAR_CORE(p)	((sar_core_struct *)(p))
462 
463 
464 /*
465  *	Client data for menu list widget/object items.
466  */
467 typedef struct {
468 
469 	void		*core_ptr;
470 	char		*name;
471 	char		*filename;	/* For items that have files */
472 	sar_position_struct	pos;	/* For items that have locations */
473 	sar_direction_struct	dir;
474 
475 } sar_menu_list_item_data_struct;
476 
477 #define SAR_MENU_LIST_ITEM_DATA(p)	((sar_menu_list_item_data_struct *)(p))
478 
479 
480 /*
481  *	Callback data for load progress menu updates:
482  */
483 typedef struct {
484 
485 	void		*core_ptr;
486 	float		coeff_offset;	/* From 0.0 to 1.0 */
487 	float		coeff_range;	/* From 0.0 to 1.0 */
488 	Boolean		can_abort;	/* True if operation can be aborted */
489 
490 } sar_progress_cb_struct;
491 
492 #define SAR_PROGRESS_CB(p)	((sar_progress_cb_struct *)(p))
493 
494 
495 
496 extern float	debug_value;		/* Arbitary global debug value */
497 
498 extern int	runlevel;		/* Program run level from 0 to 4 */
499 
500 extern time_t	cur_millitime,		/* Current time in ms */
501 		cur_systime,		/* Current time in systime seconds */
502 		lapsed_millitime;	/* Delta ms between main loop */
503 
504 extern float	time_compensation,	/* Coeff of delta ms of loop vs 1 second */
505 		time_compression;	/* Slow motion or acceleration, 0.25 to 8.0 */
506 
507 
508 
509 /* In main.c */
510 extern void SARHandleSignal(int s);
511 
512 extern int SARInitGCTL(sar_core_struct *core_ptr);
513 
514 extern void SARFullScreen(sar_core_struct *core_ptr);
515 extern void SARResolution(gw_display_struct *display, int width, int height);
516 extern void SARResolutionIncrease(gw_display_struct *display);
517 extern void SARResolutionDecrease(gw_display_struct *display);
518 
519 extern int SARLoadProgressCB(void *ptr, long pos, long size);
520 
521 extern void SARTextInputCBSendMessage(const char *value, void *data);
522 extern void SARTextInputCBQuitSimulation(const char *value, void *data);
523 
524 extern void SARDrawCB(int ctx_num, void *ptr);
525 extern void SARReshapeCB(int ctx_num, void *ptr, int x, int y, int width, int height);
526 extern void SARKeyBoardCB(
527 	void *ptr, int c, Boolean state, unsigned long t);
528 extern void SARPointerCB(
529 	int ctx_num, void *ptr,
530 	int x, int y, gw_event_type type, int btn_num, unsigned long t
531 );
532 extern void SARVisibilityCB(int ctx_num, void *ptr, gw_visibility v);
533 extern void SARSaveYourselfCB(int ctx_num, void *ptr);
534 extern void SARCloseCB(int ctx_num, void *ptr, void *data);
535 extern void SARResetTimmersCB(sar_core_struct *core_ptr, time_t t_new);
536 
537 extern sar_core_struct *SARInit(int argc, char **argv);
538 extern void SARManage(void *ptr);
539 extern void SARShutdown(sar_core_struct *core_ptr);
540 
541 /* In mission.c */
542 extern sar_mission_struct *SARMissionNew(void);
543 extern void SARMissionDelete(sar_mission_struct *mission);
544 
545 extern void SARMissionPrintStats(
546 	sar_core_struct *core_ptr,
547 	sar_scene_struct *scene,
548 	sar_mission_struct *mission,
549 	sar_object_struct *obj_ptr
550 );
551 
552 extern void SARMissionDestroyNotify(
553 	sar_core_struct *core_ptr, sar_object_struct *obj_ptr
554 );
555 extern void SARMissionHoistInNotify(
556 	sar_core_struct *core_ptr, sar_object_struct *obj_ptr,
557 	int hoisted_in		/* Number of humans hoisted in */
558 );
559 extern void SARMissionPassengersEnterNotify(
560 	sar_core_struct *core_ptr, sar_object_struct *obj_ptr,
561 	int passengers_entered	/* Number of passengers entered */
562 );
563 extern void SARMissionPassengersLeaveNotify(
564 	sar_core_struct *core_ptr, sar_object_struct *obj_ptr,
565 	int passengers_left	/* Number of passengers that left */
566 );
567 extern void SARMissionLandNotify(
568 	sar_core_struct *core_ptr, sar_object_struct *obj_ptr,
569 	const int *ground_contact, int total_ground_contacts
570 );
571 extern int SARMissionManage(sar_core_struct *core_ptr);
572 
573 /* In sarutils.c (sar specific utility functions) */
574 extern Boolean SARGetGLVersion(int *major, int *minor, int *release);
575 extern char *SARGetGLVendorName(void);
576 extern char *SARGetGLRendererName(void);
577 extern char **SARGelGLExtensionNames(int *strc);
578 
579 extern int SARIsMenuAllocated(sar_core_struct *core_ptr, int n);
580 extern int SARMatchMenuByName(
581 	sar_core_struct *core_ptr, const char *name
582 );
583 extern sar_menu_struct *SARMatchMenuByNamePtr(
584 	sar_core_struct *core_ptr, const char *name
585 );
586 extern sar_menu_struct *SARGetCurrentMenuPtr(sar_core_struct *core_ptr);
587 
588 extern sar_player_stat_struct *SARGetPlayerStatPtr(
589 	sar_core_struct *core_ptr, int i
590 );
591 extern sar_player_stat_struct *SARPlayerStatNew(
592 	const char *name,
593 	int score
594 );
595 extern void SARPlayerStatDelete(sar_player_stat_struct *pstat);
596 extern void SARPlayerStatResort(sar_player_stat_struct **list, int total);
597 extern sar_player_stat_struct *SARPlayerStatCurrent(
598         sar_core_struct *core_ptr, int *n
599 );
600 
601 extern void SARDeleteListItemData(
602 	sar_menu_list_item_struct *item_ptr
603 );
604 
605 extern char *SARTimeOfDayString(sar_core_struct *core_ptr, float t);
606 extern char *SARDeltaTimeString(sar_core_struct *core_ptr, time_t t);
607 
608 extern void SARSetGlobalTextColorBrightness(
609 	sar_core_struct *core_ptr, float g
610 );
611 extern void SARReportGLError(
612 	sar_core_struct *core_ptr, GLenum error_code
613 );
614 
615 /* In sceneio.c (scenery file io) */
616 extern void SARSceneDestroy(
617 	sar_core_struct *core_ptr,
618 	sar_scene_struct *scene,
619 	sar_object_struct ***ptr,
620 	int *total
621 );
622 extern void SARSceneLoadLocationsToList(
623 	sar_core_struct *core_ptr,
624 	sar_menu_struct *menu_ptr,
625 	sar_menu_list_struct *list_ptr,
626 	int list_num,
627 	const char *filename
628 );
629 extern int SARSceneAddPlayerObject(
630 	sar_core_struct *core_ptr,
631 	sar_scene_struct *scene,
632 	const char *model_file,
633 	sar_position_struct *pos,
634 	sar_direction_struct *dir
635 );
636 extern int SARSceneLoadFromFile(
637 	sar_core_struct *core_struct,
638 	sar_scene_struct *scene,
639 	const char *filename,
640 	const char *weather_preset_name,
641 	void *client_data,
642 	int (*progress_func)(void *, long, long)
643 );
644 
645 
646 #endif	/* SAR_H */
647