2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
4 * All source code herein is the property of Volition, Inc. You may not sell
5 * or otherwise commercially exploit the source or things you created based on
10 * $Logfile: /Freespace2/code/Hud/HUDtarget.h $
15 * Header file for HUD targeting functions
18 * Revision 1.2 2002/06/09 04:41:13 relnev
19 * added copyright header
21 * Revision 1.1.1.1 2002/05/03 03:28:12 root
25 * 8 9/07/99 11:26p Andsager
26 * Fix "r" targeting key, making evaluate_ship_as_closest_target() and
27 * hud_target_live_turret() consider if turret is targeting player
29 * 7 8/24/99 2:55p Andsager
30 * Add new prioritized turret selection code.
32 * 6 7/09/99 12:00a Andsager
33 * Added target box with distance for remote detonate weapons
35 * 5 5/28/99 10:00a Andsager
36 * Make player hud target affected by Nebula range
38 * 4 2/26/99 6:01p Andsager
39 * Add sexp has-been-tagged-delay and cap-subsys-cargo-known-delay
41 * 3 12/21/98 5:03p Dave
42 * Modified all hud elements to be multi-resolution friendly.
44 * 2 10/07/98 10:53a Dave
47 * 1 10/07/98 10:49a Dave
49 * 101 8/25/98 1:48p Dave
50 * First rev of EMP effect. Player side stuff basically done. Next comes
53 * 100 5/15/98 8:36p Lawrance
54 * Add 'target ship that last sent transmission' target key
56 * 99 5/04/98 6:12p Lawrance
57 * Write generic function hud_end_string_at_first_hash_symbol(), to use in
58 * various spots on the HUD
60 * 98 4/13/98 5:06p Lawrance
61 * truncate secondary weapons names at the '#' char
63 * 97 4/08/98 1:18a Lawrance
64 * Externalize function to find distance between two objects.
66 * 96 4/07/98 5:30p Lawrance
67 * Player can't send/receive messages when comm is destroyed. Garble
68 * messages when comm is damaged.
70 * 95 3/30/98 12:20a Lawrance
71 * remove CARGO_REVEAL time, it is now in ship_info
73 * 94 3/20/98 5:40p Lawrance
74 * Change targeting of uninspected cargo to select the next closest.
76 * 93 3/12/98 5:36p John
77 * Took out any unused shaders. Made shader code take rgbc instead of
78 * matrix and vector since noone used it like a matrix and it would have
79 * been impossible to do in hardware. Made Glide implement a basic
80 * shader for online help.
82 * 92 3/11/98 12:14a Lawrance
83 * Added hud_target_auto_target_next()
85 * 91 3/10/98 4:19p John
86 * Cleaned up graphics lib. Took out most unused gr functions. Made D3D
87 * & Glide have popups and print screen. Took out all >8bpp software
88 * support. Made Fred zbuffer. Made zbuffer allocate dynamically to
89 * support Fred. Made zbuffering key off of functions rather than one
92 * 90 3/07/98 3:50p Lawrance
93 * Add lead indicator for asteroids
95 * 89 3/04/98 3:44p Lawrance
96 * Only flash docking text for a couple of seconds
98 * 88 3/02/98 11:32p Lawrance
99 * Allow asteroids about to impact ships to be bracketed
101 * 87 2/26/98 12:33a Lawrance
102 * Added back slew mode, lots of changes to external and chase views.
104 * 86 2/24/98 2:49p Lawrance
105 * Enable cheat key to disable 'hidden from sensors' targeting
107 * 85 2/06/98 4:33p Lawrance
108 * extern hud_get_best_primary_bank()
110 * 84 2/02/98 7:00p Lawrance
111 * Adding new targeting keys (bomb, uninspected cargo, new ship, live
114 * 83 1/29/98 11:53p Lawrance
115 * Change repair ship targeting to favor support ships that are headed for
118 * 82 1/20/98 9:30p Lawrance
119 * Have lead indicator, offscreen indicator and distance be relative to
120 * targeted subsystem when possible.
122 * 81 1/17/98 1:30a Lawrance
123 * Add countermeasure gauge
125 * 80 1/10/98 12:42a Lawrance
126 * make cargo inspection more realistic
128 * 79 1/08/98 11:34p Lawrance
129 * change cargo reveal formula to max(150,1.5*radius)
131 * 78 1/02/98 9:10p Lawrance
132 * Big changes to how colors get set on the HUD.
134 * 77 12/16/97 9:13p Lawrance
135 * Integrate new gauges into HUD config.
137 * 76 12/09/97 8:12a Allender
138 * changes to hotkey stuff. Don't allow mission defined hotkeys to
139 * override user defined ones once the mission starts
141 * 75 12/04/97 10:23a Lawrance
142 * don't allow matching speed unless target speed is above
143 * MATCH_SPEED_THRESHOLD
145 * 74 12/01/97 5:12p Lawrance
146 * have minimial targeting gauges shown in chase and external view
148 * 73 12/01/97 12:27a Lawrance
149 * redo default alpha color for HUD, make it easy to modify in the future
151 * 72 11/27/97 4:23p Lawrance
152 * add subsys_in_view to the player struct, which indicates that the
153 * player has a line of sight to his targeted subsystem
155 * 71 11/20/97 5:40p Lawrance
156 * Make cargo revealing work so that anyone (including AI) on your team
157 * can reveal cargo for everyone else on the team.
159 * 70 11/20/97 1:09a Lawrance
160 * add support for 'target closest friendly repair ship'
162 * 69 11/11/97 12:58a Lawrance
163 * implement new target monitor view
165 * 68 10/30/97 12:33a Lawrance
166 * update to show AIM_STRAFE debug output
168 * 67 10/27/97 10:48p Lawrance
169 * get previous hostile/friendly targeting working.. simplify code a lot
171 * 66 10/22/97 5:53p Lawrance
172 * move out subsystem_in_sight function
174 * 65 10/12/97 3:44p Lawrance
175 * use target lists to cycle through closest hostile and friendly ships
177 * 64 10/11/97 6:38p Lawrance
178 * having damage affect targeting
180 * 63 10/10/97 6:15p Hoffoss
181 * Implemented a training objective list display.
183 * 62 10/08/97 5:07p Lawrance
184 * make sensors and communication subsystem damage affect player
186 * 61 9/22/97 4:55p Hoffoss
187 * Added a training message window display thingy.
189 * 60 8/31/97 6:40p Lawrance
190 * make auto-target always target fighters/bombers first
192 * 59 8/25/97 12:24a Lawrance
193 * implemented HUD shield management
195 * 58 8/19/97 11:46p Lawrance
196 * adding new hud gauges for shileds, escort view, and weapons
198 * 57 8/15/97 9:26a Lawrance
199 * split off target box code into HUDtargetbox.cpp
201 * 56 8/14/97 5:29p Lawrance
202 * restructure target monitor code... support missile view and red shading
204 * 55 8/12/97 5:51p Lawrance
205 * allow targeting of missiles
207 * 54 7/13/97 5:54p Lawrance
208 * fix bug with restore game and the keyed targets
210 * 53 7/01/97 11:53a Lawrance
211 * allow cycling through targets in the reticle
213 * 52 5/14/97 8:55a Lawrance
214 * fix autotargeting so it switches to a new target as soon as current
217 * 51 5/02/97 2:11p Lawrance
218 * added hud_prune_hotkeys()
220 * 50 4/28/97 2:18p Lawrance
221 * made hotkey_add_remove more generic
223 * 49 4/22/97 4:53p Lawrance
224 * allow auto-targeting to not play target fail sound when searching for
227 * 48 4/15/97 4:00p Mike
228 * Intermediate checkin caused by getting other files. Working on camera
231 * 47 4/13/97 3:53p Lawrance
232 * separate out the non-rendering dependant portions of the HUD ( sounds,
233 * updating lock position, changing targets, etc) and put into
236 * 46 4/12/97 4:29p Lawrance
237 * get missle locking and offscreen indicator working properly with
238 * different sized screens
240 * 45 4/10/97 5:29p Lawrance
241 * hud rendering split up into hud_render_3d(), hud_render_2d() and
242 * hud_render_target_model()
244 * 44 4/08/97 10:55a Allender
245 * draw purple brackets on ship sending a message
247 * 43 4/07/97 3:50p Allender
248 * ability to assign > 1 ship to a hotkey. Enabled use of hotkeys in
249 * squadmate messaging
251 * 42 3/27/97 3:58p Lawrance
252 * modified target_closest() to allow targeting closest ship that is
253 * attacking a given objnum
255 * 41 3/27/97 9:29a Lawrance
256 * If reach maximum bounding box size, use radius targeting box method
258 * 40 3/26/97 6:43p Lawrance
259 * implemented new method for detecting target in reticle, that doesn't
260 * require center point of target to be in reticle
262 * 39 3/26/97 12:44p Lawrance
263 * modified targeting functions to take team into accout for Target
266 * 38 3/19/97 5:53p Lawrance
267 * integrating new Misc_sounds[] array (replaces old Game_sounds
270 * 37 3/17/97 3:47p Mike
271 * Homing missile lock sound.
272 * More on AI ships firing missiles.
274 * 36 3/10/97 8:53a Lawrance
275 * using hud_stop_looped_locking_sounds() in place of
276 * hud_stop_looped_sounds()
278 * 35 1/02/97 10:32a Lawrance
279 * fixed some bugs related to stopping looped sounds when targets die and
282 * 34 12/24/96 4:31p Lawrance
283 * Target bracket drawing code moved to separate files
285 * 33 12/23/96 7:53p Lawrance
286 * took out missile lock code and moved to HUDlock.cpp and HUDlock.h
288 * 32 12/17/96 11:10a Lawrance
289 * added targeting of subsystem in reticle
306 #define MATCH_SPEED_THRESHOLD 0.1f // minimum speed target must be moving for match speed to apply
307 #define CARGO_RADIUS_DELTA 100 // distance added to radius required for cargo scanning
308 #define CAPITAL_CARGO_RADIUS_DELTA 250 // distance added to radius required for cargo scanning
309 #define CARGO_REVEAL_MIN_DIST 150 // minimum distance for reveal cargo (used if radius+CARGO_RADIUS_DELTA < CARGO_REVEAL_MIN_DIST)
310 #define CAP_CARGO_REVEAL_MIN_DIST 300 // minimum distance for reveal cargo (used if radius+CARGO_RADIUS_DELTA < CARGO_REVEAL_MIN_DIST)
311 #define CARGO_MIN_DOT_TO_REVEAL 0.95 // min dot to proceed to have cargo scanning take place
313 // structure and defines used for hotkey targeting
314 #define MAX_HOTKEY_TARGET_ITEMS 50 // maximum number of ships that can be targeted on *all* keys
315 #define SELECTION_SET 0x5000 // variable used for drawing brackets. The bracketinng code uses
316 // TEAM_* values. I picked this value to be totally out of that
317 // range. Only used for drawing selection sets
318 #define MESSAGE_SENDER 0x5001 // variable used for drawing brackets around a message sender.
319 // See above comments for SELECTION_SET
321 // defines used to tell how a particular hotkey was added
322 #define HOTKEY_USER_ADDED 1
323 #define HOTKEY_MISSION_FILE_ADDED 2
325 typedef struct htarget_list {
326 struct htarget_list *next, *prev; // for linked lists
327 int how_added; // determines how this hotkey was added (mission default or player)
328 object *objp; // the actual object
331 extern htarget_list htarget_free_list;
332 extern int Hud_target_w, Hud_target_h;
334 extern shader Training_msg_glass;
336 extern char *Ai_class_names[];
337 extern char *Submode_text[];
338 extern char *Strafe_submode_text[];
340 extern void hud_init_targeting_colors();
342 void hud_init_targeting();
343 void hud_target_next(int team = -1);
344 void hud_target_prev(int team = -1);
345 int hud_target_closest(int team = -1, int attacked_objnum = -1, int play_fail_sound = TRUE, int filter = 0, int turret_attacking_target = 0);
346 void hud_target_in_reticle_old();
347 void hud_target_in_reticle_new();
348 void hud_target_subsystem_in_reticle();
349 void hud_show_targeting_gauges(float frametime, int in_cockpit=1);
350 void hud_target_targets_target();
351 void hud_check_reticle_list();
352 void hud_target_closest_locked_missile(object *A);
353 void hud_target_missile(object *source_obj, int next_flag);
354 void hud_target_next_list(int hostile=1, int next_flag=1);
355 int hud_target_closest_repair_ship(int goal_objnum=-1);
356 void hud_target_auto_target_next();
357 void hud_show_remote_detonate_missile();
359 void hud_target_uninspected_object(int next_flag);
360 void hud_target_newest_ship();
361 void hud_target_live_turret(int next_flag, int auto_advance=0, int turret_attacking_target=0);
363 void hud_target_last_transmit_level_init();
364 void hud_target_last_transmit();
365 void hud_target_last_transmit_add(int ship_num);
367 void hud_target_random_ship();
369 void hud_target_next_subobject();
370 void hud_target_prev_subobject();
371 void hud_cease_subsystem_targeting(int print_message=1);
372 void hud_cease_targeting();
373 void hud_restore_subsystem_target(ship* shipp);
374 int subsystem_in_sight(object* objp, ship_subsys* subsys, vector *eye, vector* subsystem);
375 vector* get_subsystem_world_pos(object* parent_obj, ship_subsys* subsys, vector* world_pos);
376 void hud_target_change_check();
378 void hud_show_target_triangle_indicator(vertex *projected_v);
379 void hud_show_lead_indicator(vector *target_world_pos);
380 void hud_show_orientation_tee();
381 void hud_show_hostile_triangle();
382 void hud_show_target_data();
383 void hud_show_afterburner_gauge();
384 void hud_show_weapons();
385 void hud_start_flash_weapon(int index);
386 void hud_show_auto_icons();
387 void hud_show_weapon_energy_gauge();
388 void hud_show_cmeasure_gague();
389 void hud_show_brackets(object *targetp, vertex *projected_v);
390 void hud_draw_offscreen_indicator(vertex* target_point, vector *tpos, float distance=0.0f);
391 void hud_show_homing_missiles(void);
393 int hud_sensors_ok(ship *sp, int show_msg = 1);
394 int hud_communications_state(ship *sp, int show_msg = 0);
396 int hud_get_best_primary_bank(float *range);
397 void hud_target_toggle_hidden_from_sensors();
398 void hud_maybe_flash_docking_text(object *objp);
399 int hud_target_invalid_awacs(object *objp);
401 // functions for hotkey selection sets
403 extern void hud_target_hotkey_select( int k );
404 extern void hud_target_hotkey_clear( int k );
406 extern void hud_target_hotkey_add_remove( int k, object *objp, int how_to_add);
407 extern void hud_show_selection_set();
408 extern void hud_show_message_sender();
409 void hud_prune_hotkeys();
410 void hud_keyed_targets_clear();
412 // Code to draw filled triangles
413 void hud_tri(float x1,float y1,float x2,float y2,float x3,float y3);
414 // Code to draw empty triangles.
415 void hud_tri_empty(float x1,float y1,float x2,float y2,float x3,float y3);
417 float hud_find_target_distance( object *targetee, object *targeter );