2 * $Logfile: /Freespace2/code/Hud/HUDtarget.cpp $
7 * C module to provide HUD targeting functions
10 * Revision 1.1 2002/05/03 03:28:09 root
14 * 43 11/01/99 11:22a Jefff
15 * some weapon name translations
17 * 42 9/15/99 1:59p Mikek
18 * Fix bug in targeting due to Alt-Y (target last ship sending
19 * transmission). Was just bogus code in the call to
20 * hud_restore_subsystem_target().pm.
22 * 41 9/08/99 11:42p Andsager
23 * Remove maximum target distance check when finding enemy target
25 * 40 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 * 39 9/01/99 12:58a Andsager
30 * Make all targeting keys able to choose turret on BIG|HUGE ships
32 * 38 8/24/99 2:55p Andsager
33 * Add new prioritized turret selection code.
35 * 37 8/18/99 10:59p Andsager
36 * Enable "b" key to target bombers.
38 * 36 8/17/99 8:32p Jefff
39 * fixes to auto-speed/target so it looks much better in the nebula
41 * 35 8/17/99 7:15p Jefff
42 * auto-target & auto-speed text drawn in code
44 * 34 8/04/99 9:54a Andsager
45 * Auto target turrets on big ships.
47 * 33 8/02/99 4:03p Andsager
48 * target closest favors beams and flak
50 * 32 8/01/99 12:39p Dave
51 * Added HUD contrast control key (for nebula).
53 * 31 7/30/99 11:10a Andsager
54 * Modify hud_target_closest() to consider turrets against all ships, not
57 * 30 7/15/99 5:41p Andsager
60 * 29 7/15/99 9:20a Andsager
61 * FS2_DEMO initial checkin
63 * 28 7/09/99 12:00a Andsager
64 * Added target box with distance for remote detonate weapons
66 * 27 7/07/99 4:31p Andsager
67 * Make closest_attacking_hostile guage respect stealth. Kill a bunch of
70 * 26 7/01/99 11:44a Dave
71 * Updated object sound system to allow multiple obj sounds per ship.
72 * Added hit-by-beam sound. Added killed by beam sound.
74 * 25 6/17/99 9:04a Andsager
77 * 24 6/16/99 5:32p Andsager
80 * 23 6/15/99 9:24a Andsager
81 * Make hotkeys work with stealth
83 * 22 6/10/99 3:43p Dave
84 * Do a better job of syncing text colors to HUD gauges.
86 * 21 6/09/99 2:55p Andsager
87 * Allow multiple asteroid subtypes (of large, medium, small) and follow
90 * 20 6/08/99 8:35a Jasenw
91 * new coords for new lead indicator
93 * 19 6/07/99 4:20p Andsager
94 * Add HUD color for tagged object. Apply to target and radar.
96 * 18 6/02/99 3:23p Andsager
97 * Make AI aware of team visibility. Allow player targeting with team
98 * visibility info. Make stealth ships not targetable by AI in nebula
101 * 17 5/24/99 9:00a Andsager
102 * modify target next/prev live turret only when turret has a weapon
104 * 16 4/20/99 6:39p Dave
105 * Almost done with artillery targeting. Added support for downloading
106 * images on the PXO screen.
108 * 15 2/25/99 4:19p Dave
109 * Added multiplayer_beta defines. Added cd_check define. Fixed a few
110 * release build warnings. Added more data to the squad war request and
113 * 14 1/27/99 3:02p Anoop
114 * Fixed 640 HUD afterburner and weapon energy gauge.
116 * 13 1/25/99 5:03a Dave
117 * First run of stealth, AWACS and TAG missile support. New mission type
120 * 12 1/07/99 10:07a Jasen
123 * 11 1/07/99 9:06a Jasen
126 * 10 1/06/99 2:24p Dave
127 * Stubs and release build fixes.
129 * 9 12/29/98 7:21p Dave
130 * Put in a bunch of missing hi-res coord globalizations.
132 * 8 12/29/98 2:29p Jasen
133 * added new coords for some 1024 HUD stuff.
135 * 7 12/28/98 3:17p Dave
136 * Support for multiple hud bitmap filenames for hi-res mode.
138 * 5 12/21/98 5:03p Dave
139 * Modified all hud elements to be multi-resolution friendly.
141 * 4 11/05/98 4:18p Dave
142 * First run nebula support. Beefed up localization a bit. Removed all
143 * conditional compiles for foreign versions. Modified mission file
146 * 3 10/13/98 9:28a Dave
147 * Started neatening up freespace.h. Many variables renamed and
148 * reorganized. Added AlphaColors.[h,cpp]
150 * 2 10/07/98 10:53a Dave
153 * 1 10/07/98 10:49a Dave
155 * 407 9/21/98 9:27a Dave
156 * Special case code to draw Cluster Bomb as Cluster on the HUD.
158 * 406 8/28/98 3:28p Dave
159 * EMP effect done. AI effects may need some tweaking as required.
161 * 405 8/25/98 1:48p Dave
162 * First rev of EMP effect. Player side stuff basically done. Next comes
165 * 404 6/12/98 4:52p Hoffoss
166 * Added support for special characters in in forgeign languages.
168 * 403 6/09/98 5:17p Lawrance
169 * French/German localization
171 * 402 6/09/98 10:31a Hoffoss
172 * Created index numbers for all xstr() references. Any new xstr() stuff
173 * added from here on out should be added to the end if the list. The
174 * current list count can be found in FreeSpace.cpp (search for
177 * 401 5/27/98 1:24p Allender
178 * make targeting dots work (as well as other targeting features) properly
179 * in multiplayer. Don't query for CD when entering debrief in
182 * 400 5/27/98 1:20p Mike
183 * Fix bug in target nearest ship attacking target.
189 #include "hudtarget.h"
190 #include "hudreticle.h"
195 #include "3dinternal.h"
197 #include "linklist.h"
202 #include "freespace.h" // for flFrametime
206 #include "missionparse.h"
207 #include "player.h" // for MAX_PLAYERS
209 #include "hudbrackets.h"
211 #include "eventmusic.h"
213 #include "missionmessage.h"
216 #include "hudtargetbox.h"
218 #include "subsysdamage.h"
219 #include "hudshield.h"
220 #include "missionhotkey.h"
221 #include "asteroid.h"
222 #include "jumpnode.h"
225 #include "alphacolors.h"
226 #include "localize.h"
228 #include "hudartillery.h"
230 // If any of these bits in the ship->flags are set, ignore this ship when targetting
231 int TARGET_SHIP_IGNORE_FLAGS = (SF_EXPLODED|SF_DEPART_WARP|SF_DYING|SF_ARRIVING_STAGE_1|SF_HIDDEN_FROM_SENSORS);
233 // Global values for the target bracket width and height, used for debugging
234 int Hud_target_w, Hud_target_h;
236 // offscreen triangle that point the the off-screen target
237 float Offscreen_tri_base[GR_NUM_RESOLUTIONS] = {
241 float Offscreen_tri_height[GR_NUM_RESOLUTIONS] = {
245 float Max_offscreen_tri_seperation[GR_NUM_RESOLUTIONS] = {
249 float Max_front_seperation[GR_NUM_RESOLUTIONS] = {
254 // The following variables are global to this file, and do not need to be persistent from frame-to-frame
255 // This means the variables are not player-specific
256 static int Target_in_reticle = 0;
258 extern object obj_used_list; // dummy node in linked list of active objects
259 extern char *Cargo_names[];
261 // shader is used to shade the target box
262 shader Training_msg_glass;
264 // the target triangle (that orbits the reticle) dimensions
265 float Target_triangle_base[GR_NUM_RESOLUTIONS] = {
269 float Target_triangle_height[GR_NUM_RESOLUTIONS] = {
274 // stuff for hotkey targeting lists
275 htarget_list htarget_items[MAX_HOTKEY_TARGET_ITEMS];
276 htarget_list htarget_free_list;
278 // coordinates and widths used to render the HUD afterburner energy gauge
279 int Aburn_coords[GR_NUM_RESOLUTIONS][4] = {
288 // coordinates and widths used to render the HUD weapons energy gauge
289 int Wenergy_coords[GR_NUM_RESOLUTIONS][4] = {
298 #define MIN_DISTANCE_TO_CONSIDER_THREAT 1500 // min distance to show hostile warning triangle
300 //////////////////////////////////////////////////////////////////////////
301 // lists for target in reticle cycling
302 //////////////////////////////////////////////////////////////////////////
303 #define RL_USED (1<<0)
304 #define RL_USE_DOT (1<<1) // use dot product result, not distance
306 typedef struct _reticle_list {
307 _reticle_list *next, *prev;
313 #define RESET_TARGET_IN_RETICLE 750
314 int Reticle_save_timestamp;
315 reticle_list Reticle_cur_list;
316 reticle_list Reticle_save_list;
317 #define MAX_RETICLE_TARGETS 50
318 reticle_list Reticle_list[MAX_RETICLE_TARGETS];
320 //////////////////////////////////////////////////////////////////////////
321 // used for closest target cycling
322 //////////////////////////////////////////////////////////////////////////
323 #define TL_RESET 1500
324 #define TURRET_RESET 1000
325 static int Tl_hostile_reset_timestamp;
326 static int Tl_friendly_reset_timestamp;
327 static int Target_next_uninspected_object_timestamp;
328 static int Target_newest_ship_timestamp;
329 static int Target_next_turret_timestamp;
331 // animation frames for the hud targeting gauges
332 // frames: 0 => out of range lead
333 // 1 => in range lead
334 float Lead_indicator_half[GR_NUM_RESOLUTIONS][2] = {
344 hud_frames Lead_indicator_gauge;
345 int Lead_indicator_gauge_loaded = 0;
346 char Lead_fname[GR_NUM_RESOLUTIONS][MAX_FILENAME_LEN] = {
351 // animation frames for the afterburner gauge and the weapon energy gauge
352 // frames: 0 => afterburner dark
353 // 1 => afterburner light
354 // 2 => gun energy dark
355 // 3 => gun energy light
356 hud_frames Energy_bar_gauges;
357 int Energy_bar_gauges_loaded = 0;
358 char Energy_fname[GR_NUM_RESOLUTIONS][MAX_FILENAME_LEN] = {
362 int Weapon_energy_text_coords[GR_NUM_RESOLUTIONS][2] = {
371 // animation frames for the countermeasures gauge
372 // frames: 0 => background
373 hud_frames Cmeasure_gauge;
374 int Cmeasure_gauge_loaded = 0;
375 int Cm_coords[GR_NUM_RESOLUTIONS][2] = {
383 int Cm_text_coords[GR_NUM_RESOLUTIONS][2] = {
391 int Cm_text_val_coords[GR_NUM_RESOLUTIONS][2] = {
399 char Cm_fname[GR_NUM_RESOLUTIONS][MAX_FILENAME_LEN] = {
404 // animation frames for the auto-target and auto-match_speed icons
405 // frames: 0 => auto-target off
406 // 1 => auto-target on
407 // 2 => auto-match-speed on
408 // 3 => auto-match-speed off
409 hud_frames Toggle_gauge;
410 int Toggle_gauge_loaded = 0;
411 int Toggle_target_gauge_coords[GR_NUM_RESOLUTIONS][2] = {
419 int Toggle_speed_gauge_coords[GR_NUM_RESOLUTIONS][2] = {
427 char Toggle_fname[GR_NUM_RESOLUTIONS][MAX_FILENAME_LEN] = {
432 #define TOGGLE_TEXT_AUTOT 0
433 #define TOGGLE_TEXT_TARGET 1
434 #define TOGGLE_TEXT_AUTOS 2
435 #define TOGGLE_TEXT_SPEED 3
436 static int Hud_toggle_coords[GR_NUM_RESOLUTIONS][4][2] = {
451 static int Toggle_text_alpha = 255;
454 // animation files for the weapons gauge
455 #define NUM_WEAPON_GAUGES 5
456 hud_frames Weapon_gauges[NUM_WEAPON_GAUGES];
457 int Weapon_gauges_loaded = 0;
459 int Weapon_gauge_primary_coords[GR_NUM_RESOLUTIONS][3][2] = {
461 // based on the # of primaries
462 {509, 273}, // top of weapon gauge, first frame, always
463 {497, 293}, // for the first primary
464 {497, 305} // for the second primary
467 // based on the # of primaries
468 {892, 525}, // top of weapon gauge, first frame, always
469 {880, 545}, // for the first primary
470 {880, 557} // for the second primary
473 int Weapon_gauge_secondary_coords[GR_NUM_RESOLUTIONS][5][2] = {
475 // based on the # of secondaries
476 {497, 318}, // bottom of gauge, 0 secondaries
477 {497, 318}, // bottom of gauge, 1 secondaries
478 {497, 317}, // middle of gauge, 2 secondaries AND middle of gauge, 3 secondaries
479 {497, 326}, // bottom of gauge, 2 secondaries AND middle of gauge, 3 secondaries
480 {497, 335} // bottom of gauge, 3 secondaries
483 // based on the # of secondaries
484 {880, 570}, // bottom of gauge, 0 secondaries
485 {880, 570}, // bottom of gauge, 1 secondaries
486 {880, 569}, // middle of gauge, 2 secondaries AND middle of gauge, 3 secondaries
487 {880, 578}, // bottom of gauge, 2 secondaries AND middle of gauge, 3 secondaries
488 {880, 587} // bottom of gauge, 3 secondaries
491 int Weapon_title_coords[GR_NUM_RESOLUTIONS][2] = {
499 int Weapon_plink_coords[GR_NUM_RESOLUTIONS][2][2] = {
501 {530, 285}, // fire-linked thingie, for the first primary
502 {530, 295} // fire-linked thingie, for the second primary
505 {913, 537}, // fire-linked thingie, for the first primary
506 {913, 547} // fire-linked thingie, for the second primary
509 int Weapon_pname_coords[GR_NUM_RESOLUTIONS][2][2] = {
511 {536, 285}, // weapon name, first primary
512 {536, 295} // weapon name, second primary
515 {919, 537}, // weapon name, first primary
516 {919, 547} // weapon name, second primary
519 int Weapon_slinked_x[GR_NUM_RESOLUTIONS] = {
520 525, // where to draw the second thingie if this weapon is fire-linked
523 int Weapon_sunlinked_x[GR_NUM_RESOLUTIONS] = {
524 530, // where to draw the first thingie if this weapon is selected at all (fire-linked or not)
527 int Weapon_secondary_y[GR_NUM_RESOLUTIONS][3] = {
529 309, // y location of where to draw text for the first secondary
530 318, // y location of where to draw text for the second secondary
531 327 // y location of where to draw text for the third secondary
534 561, // y location of where to draw text for the third secondary
535 570, // y location of where to draw text for the third secondary
536 579 // y location of where to draw text for the third secondary
539 int Weapon_secondary_name_x[GR_NUM_RESOLUTIONS] = {
540 536, // x location of where to draw weapon name
543 int Weapon_secondary_ammo_x[GR_NUM_RESOLUTIONS] = {
544 525, // x location of where to draw weapon ammo count
547 int Weapon_secondary_reload_x[GR_NUM_RESOLUTIONS] = {
548 615, // x location of where to draw the weapon reload time
551 char *Weapon_gauge_fnames[GR_NUM_RESOLUTIONS][NUM_WEAPON_GAUGES] =
571 // Flash the line for a weapon. This normally occurs when the player tries to fire that
572 // weapon, but the firing fails (due to lack of energy or damaged weapons subsystem).
573 #define MAX_WEAPON_FLASH_LINES 7 // 3 primary and 4 secondary
574 typedef struct weapon_flash
576 int flash_duration[MAX_WEAPON_FLASH_LINES];
577 int flash_next[MAX_WEAPON_FLASH_LINES];
580 weapon_flash Weapon_flash_info;
582 // Data used for the proximity warning
583 typedef struct homing_beep_info
585 int snd_handle; // sound handle for last played beep
586 fix last_time_played; // time beep was last played
587 int min_cycle_time; // time (in ms) for fastest cycling of the sound
588 int max_cycle_time; // time (in ms) for slowest cycling of the sound
589 float min_cycle_dist; // distance at which fastest cycling occurs
590 float max_cycle_dist; // distance at which slowest cycling occurs
591 float precalced_interp; // a precalculated value used in a linear interpretation
594 homing_beep_info Homing_beep = { -1, 0, 150, 1000, 30.0f, 1500.0f };
596 // Set at the start of a mission, used to decide how to draw the separation for the warning missile indicators
597 float Min_warning_missile_dist;
598 float Max_warning_missile_dist;
600 void hud_maybe_flash_weapon(int index);
602 // if a given object should be ignored because of AWACS effects
603 int hud_target_invalid_awacs(object *objp)
605 // if objp is ship object, first check if can be targeted with team info
606 if (objp->type == OBJ_SHIP) {
607 if (Player_ship != NULL) {
608 if (ship_is_visible_by_team(objp->instance, Player_ship->team)) {
614 // check for invalid status
615 if((Player_ship != NULL) && (awacs_get_level(objp, Player_ship) < 1.0f)){
623 ship_subsys *advance_subsys(ship_subsys *cur, int next_flag)
626 return GET_NEXT(cur);
628 return GET_LAST(cur);
632 // select a sorted turret subsystem on a ship if no other subsys has been selected
633 void hud_maybe_set_sorted_turret_subsys(ship *shipp)
635 Assert((Player_ai->target_objnum >= 0) && (Player_ai->target_objnum < MAX_OBJECTS));
636 if (!((Player_ai->target_objnum >= 0) && (Player_ai->target_objnum < MAX_OBJECTS))) {
639 Assert(Objects[Player_ai->target_objnum].type == OBJ_SHIP);
640 if (Objects[Player_ai->target_objnum].type != OBJ_SHIP) {
644 if (Ship_info[shipp->ship_info_index].flags & (SIF_BIG_SHIP|SIF_HUGE_SHIP)) {
645 if (shipp->last_targeted_subobject[Player_num] == NULL) {
646 hud_target_live_turret(1, 1);
652 // -----------------------------------------------------------------------
653 // clear out the linked list of targets in the reticle
654 void hud_reticle_clear_list(reticle_list *rlist)
657 for ( cur = GET_FIRST(rlist); cur != END_OF_LIST(rlist); cur = GET_NEXT(cur) ) {
663 // --------------------------------------------------------------------------------------
664 // hud_reticle_list_init()
665 void hud_reticle_list_init()
669 for ( i = 0; i < MAX_RETICLE_TARGETS; i++ ) {
670 Reticle_list[i].flags = 0;
673 Reticle_save_timestamp = 1;
674 list_init(&Reticle_save_list);
675 list_init(&Reticle_cur_list);
678 // --------------------------------------------------------------------------------------
679 // hud_check_reticle_list()
682 void hud_check_reticle_list()
684 reticle_list *rl, *temp;
686 // cull dying objects from reticle list
687 rl = GET_FIRST(&Reticle_cur_list);
688 while( rl !=END_OF_LIST(&Reticle_cur_list) ) {
690 if ( rl->objp->flags & OF_SHOULD_BE_DEAD ) {
691 list_remove( &Reticle_cur_list, rl );
697 if ( timestamp_elapsed(Reticle_save_timestamp) ) {
698 hud_reticle_clear_list(&Reticle_save_list);
699 Reticle_save_timestamp = timestamp(RESET_TARGET_IN_RETICLE);
703 // --------------------------------------------------------------------------------------
704 // hud_reticle_list_find_free()
707 int hud_reticle_list_find_free()
711 // find a free reticle_list element
712 for ( i = 0; i < MAX_RETICLE_TARGETS; i++ ) {
713 if ( !(Reticle_list[i].flags & RL_USED) ) {
718 if ( i == MAX_RETICLE_TARGETS ) {
719 // nprintf(("Warning","Warning ==> Ran out of reticle target elements...\n"));
726 // --------------------------------------------------------------------------------------
727 // hud_stuff_reticle_list()
730 #define RETICLE_DEFAULT_DIST 100000.0f
731 #define RETICLE_DEFAULT_DOT 1.0f
732 void hud_stuff_reticle_list(reticle_list *rl, object *objp, float measure, int dot_flag)
736 rl->dist = RETICLE_DEFAULT_DIST;
737 rl->flags |= RL_USE_DOT;
741 rl->dot = RETICLE_DEFAULT_DOT;
746 // --------------------------------------------------------------------------------------
747 // hud_reticle_list_update()
749 // Update Reticle_cur_list with an object that lies in the reticle
751 // parmeters: objp => object pointer to target
752 // measure => distance or dot product, depending on dot_flag
753 // dot_flag => if 0, measure is distance, if 1 measure is dot
755 void hud_reticle_list_update(object *objp, float measure, int dot_flag)
757 reticle_list *rl, *new_rl;
760 for ( rl = GET_FIRST(&Reticle_cur_list); rl != END_OF_LIST(&Reticle_cur_list); rl = GET_NEXT(rl) ) {
761 if ( rl->objp == objp )
765 i = hud_reticle_list_find_free();
769 new_rl = &Reticle_list[i];
770 new_rl->flags |= RL_USED;
771 hud_stuff_reticle_list(new_rl, objp, measure, dot_flag);
773 int was_inserted = 0;
775 if ( EMPTY(&Reticle_cur_list) ) {
776 list_insert(&Reticle_cur_list, new_rl);
780 for ( rl = GET_FIRST(&Reticle_cur_list); rl != END_OF_LIST(&Reticle_cur_list); rl = GET_NEXT(rl) ) {
782 // compare based on distance
783 if ( measure < rl->dist ) {
784 list_insert_before(rl, new_rl);
790 // compare based on dot
791 if ( measure > rl->dot ) {
792 list_insert_before(rl, new_rl);
800 if ( !was_inserted ) {
801 list_append(&Reticle_cur_list, new_rl);
805 // --------------------------------------------------------------------------------------
806 // hud_reticle_pick_target()
808 // Pick a target from Reticle_cur_list, based on what is in Reticle_save_list
811 object *hud_reticle_pick_target()
813 reticle_list *cur_rl, *save_rl, *new_rl;
819 // As a first step, see if both ships and debris are in the list. If so, cull the debris.
820 int debris_in_list = 0;
821 int ship_in_list = 0;
822 for ( cur_rl = GET_FIRST(&Reticle_cur_list); cur_rl != END_OF_LIST(&Reticle_cur_list); cur_rl = GET_NEXT(cur_rl) ) {
823 if ( (cur_rl->objp->type == OBJ_SHIP) || (cur_rl->objp->type == OBJ_JUMP_NODE) ) {
828 if ( cur_rl->objp->type == OBJ_WEAPON ) {
829 if ( Weapon_info[Weapons[cur_rl->objp->instance].weapon_info_index].subtype == WP_MISSILE ) {
835 if ( (cur_rl->objp->type == OBJ_DEBRIS) || (cur_rl->objp->type == OBJ_ASTEROID) ) {
841 if ( ship_in_list && debris_in_list ) {
843 reticle_list *rl, *next;
845 rl = GET_FIRST(&Reticle_cur_list);
846 while ( rl != &Reticle_cur_list ) {
848 if ( (rl->objp->type == OBJ_DEBRIS) || (rl->objp->type == OBJ_ASTEROID) ){
849 list_remove(&Reticle_cur_list,rl);
856 for ( cur_rl = GET_FIRST(&Reticle_cur_list); cur_rl != END_OF_LIST(&Reticle_cur_list); cur_rl = GET_NEXT(cur_rl) ) {
858 for ( save_rl = GET_FIRST(&Reticle_save_list); save_rl != END_OF_LIST(&Reticle_save_list); save_rl = GET_NEXT(save_rl) ) {
859 if ( cur_rl->objp == save_rl->objp ) {
865 if ( !in_save_list ) {
866 return_objp = cur_rl->objp;
867 i = hud_reticle_list_find_free();
871 new_rl = &Reticle_list[i];
872 new_rl->flags |= RL_USED;
873 if ( cur_rl->flags & RL_USE_DOT ) {
874 hud_stuff_reticle_list(new_rl, cur_rl->objp, cur_rl->dot, 1);
877 hud_stuff_reticle_list(new_rl, cur_rl->objp, cur_rl->dist, 0);
880 list_append(&Reticle_save_list, new_rl);
885 if ( return_objp == NULL && !EMPTY(&Reticle_cur_list) ) {
886 i = hud_reticle_list_find_free();
889 new_rl = &Reticle_list[i];
890 cur_rl = GET_FIRST(&Reticle_cur_list);
892 return_objp = cur_rl->objp;
893 hud_reticle_clear_list(&Reticle_save_list);
894 list_append(&Reticle_save_list, new_rl);
900 // hud_target_hotkey_add_remove takes as it's parameter which hotkey (1-0) to add/remove the current
901 // target from. This functio behaves like the Shift-<selection> does in Windows -- using shift # will toggle
902 // the current target in and out of the selection set.
903 void hud_target_hotkey_add_remove( int k, object *ctarget, int how_to_add )
905 htarget_list *hitem, *plist;
907 // don't do anything if a standalone multiplayer server
908 if ( MULTIPLAYER_STANDALONE )
911 if ( k < 0 || k > 7 ) {
912 nprintf(("Warning", "Bogus hotkey %d sent to hud_target_hotkey_add_remove\n"));
916 plist = &(Players[Player_num].keyed_targets[k]);
918 // we must operate only on ships
919 if ( ctarget->type != OBJ_SHIP )
922 // don't allow player into hotkey set
923 if ( ctarget == Player_obj )
926 // don't put dying or departing
927 if ( Ships[ctarget->instance].flags & (SF_DYING|SF_DEPARTING) )
930 // don't add mission file added hotkey assignments if there are player added assignments
931 // already in the list
932 if ( (how_to_add == HOTKEY_MISSION_FILE_ADDED) && NOT_EMPTY(plist) ) {
933 for ( hitem = GET_FIRST(plist); hitem != END_OF_LIST(plist); hitem = GET_NEXT(hitem) ) {
934 if ( hitem->how_added == HOTKEY_USER_ADDED )
939 // determine if the current target is currently in the set or not
940 for ( hitem = GET_FIRST(plist); hitem != END_OF_LIST(plist); hitem = GET_NEXT(hitem) ) {
941 if ( hitem->objp == ctarget )
945 // if hitem == end of the list, then the target should be added, else it should be removed
946 if ( hitem == END_OF_LIST(plist) ) {
947 if ( EMPTY(&htarget_free_list) ) {
948 Int3(); // get Allender -- no more free hotkey target items
952 nprintf(("network", "Hotkey: Adding %s\n", Ships[ctarget->instance].ship_name));
953 hitem = GET_FIRST( &htarget_free_list );
954 list_remove( &htarget_free_list, hitem );
955 list_append( plist, hitem );
956 hitem->objp = ctarget;
957 hitem->how_added = how_to_add;
959 nprintf(("network", "Hotkey: Removing %s\n", Ships[ctarget->instance].ship_name));
960 list_remove( plist, hitem );
961 list_append( &htarget_free_list, hitem );
962 hitem->objp = NULL; // for safety
966 // the following function clears the hotkey set given by parameter passed in
967 void hud_target_hotkey_clear( int k )
969 htarget_list *hitem, *plist, *temp;
971 plist = &(Players[Player_num].keyed_targets[k]);
972 hitem = GET_FIRST(plist);
973 while ( hitem != END_OF_LIST(plist) ) {
974 temp = GET_NEXT(hitem);
975 list_remove( plist, hitem );
976 list_append( &htarget_free_list, hitem );
980 if ( Players[Player_num].current_hotkey_set == k ) // clear this variable if we removed the bindings
981 Players[Player_num].current_hotkey_set = -1;
984 // the next function sets the current selected set to be N. If there is just one ship in the selection
985 // set, this ship will become the new target. If there is more than one ship in the selection set,
986 // then the current_target will remain what it was.
987 void hud_target_hotkey_select( int k )
989 int visible_count = 0;
990 htarget_list *hitem, *plist, *target, *next_target, *first_target;
993 plist = &(Players[Player_num].keyed_targets[k]);
995 if ( EMPTY( plist ) ) // no items in list, then do nothing
998 // a simple walk of the list to get the count
999 for ( hitem = GET_FIRST(plist); hitem != END_OF_LIST(plist); hitem = GET_NEXT(hitem) ){
1000 if (awacs_get_level(hitem->objp, Player_ship, 1) > 1) {
1005 // no visible ships in list
1006 if (visible_count == 0) {
1010 // set the current target to be the "next" ship in the list. Scan the list to see if our
1011 // current target is in the set. If so, target the next ship in the list, otherwise target
1013 // set first_target - first visible item in list
1014 // target - item in list that is the player's currently selected target
1015 // next_target - next visible item in list following target
1016 target_objnum = Player_ai->target_objnum;
1019 first_target = NULL;
1020 for ( hitem = GET_FIRST(plist); hitem != END_OF_LIST(plist); hitem = GET_NEXT(hitem) ) {
1022 if (awacs_get_level(hitem->objp, Player_ship, 1) > 1) {
1023 // get the first valid target
1024 if (first_target == NULL) {
1025 first_target = hitem;
1028 // get the next target in the list following the player currently selected target
1029 if (target != NULL) {
1030 next_target = hitem;
1035 // mark the player currently selected target
1036 if ( OBJ_INDEX(hitem->objp) == target_objnum ) {
1041 // if current target is not in list, then target and next_target will be NULL
1042 // so we use the first found target
1043 if (target == NULL) {
1044 Assert(first_target != NULL);
1045 if (first_target != NULL) {
1046 target = first_target;
1047 next_target = first_target;
1049 // this should not happen
1054 // update target if more than 1 is visible
1055 if (visible_count > 1) {
1056 // next already found (after current target in list)
1057 if (next_target != NULL) {
1058 target = next_target;
1061 // next is before current target, so search from start of list
1062 for ( hitem = GET_FIRST(plist); hitem != END_OF_LIST(plist); hitem = GET_NEXT(hitem) ) {
1063 if (awacs_get_level(hitem->objp, Player_ship, 1) > 1) {
1071 Assert( target != END_OF_LIST(plist) );
1073 if ( Player_obj != target->objp ){
1074 set_target_objnum( Player_ai, OBJ_INDEX(target->objp) );
1077 Players[Player_num].current_hotkey_set = k;
1080 // hud_init_targeting_colors() will initalize the shader and gradient objects used
1084 color HUD_color_homing_indicator;
1086 void hud_make_shader(shader *sh, int r, int g, int b, float dimmer = 1000.0f)
1090 // The m matrix converts all colors to shades of green
1091 float tmp = 0.0015625f * i2fl(HUD_color_alpha+1.0f) / 16.0f;
1096 cf = (i2fl(r) / dimmer)*(i2fl(HUD_color_alpha) / 15.0f);
1098 gr_create_shader( sh, rf, gf, bf, cf );
1101 void hud_init_targeting_colors()
1103 gr_init_color( &HUD_color_homing_indicator, 0x7f, 0x7f, 0 ); // yellow
1105 hud_make_shader(&Training_msg_glass, 61, 61, 85, 500.0f);
1107 hud_init_brackets();
1110 void hud_keyed_targets_clear()
1114 // clear out the keyed target list
1115 for (i = 0; i < MAX_KEYED_TARGETS; i++ )
1116 list_init( &(Players[Player_num].keyed_targets[i]) );
1117 Players[Player_num].current_hotkey_set = -1;
1119 // place all of the hoykey target items back onto the free list
1120 list_init( &htarget_free_list );
1121 for ( i = 0; i < MAX_HOTKEY_TARGET_ITEMS; i++ )
1122 list_append( &htarget_free_list, &htarget_items[i] );
1125 // Init data used for the weapons display on the HUD
1126 void hud_weapons_init()
1130 Weapon_flash_info.is_bright = 0;
1131 for ( i = 0; i < MAX_WEAPON_FLASH_LINES; i++ ) {
1132 Weapon_flash_info.flash_duration[i] = 1;
1133 Weapon_flash_info.flash_next[i] = 1;
1136 if ( !Weapon_gauges_loaded ) {
1137 for ( i = 0; i < NUM_WEAPON_GAUGES; i++ ) {
1138 Weapon_gauges[i].first_frame = bm_load_animation(Weapon_gauge_fnames[gr_screen.res][i], &Weapon_gauges[i].num_frames);
1139 if ( Weapon_gauges[i].first_frame < 0 ) {
1140 Warning(LOCATION,"Cannot load hud ani: %s\n",Weapon_gauge_fnames[gr_screen.res][i]);
1143 Weapon_gauges_loaded = 1;
1147 // init data used to play the homing "proximity warning" sound
1148 void hud_init_homing_beep()
1150 Homing_beep.snd_handle = -1;
1151 Homing_beep.last_time_played = 0;
1152 Homing_beep.precalced_interp = (Homing_beep.max_cycle_dist-Homing_beep.min_cycle_dist) / (Homing_beep.max_cycle_time - Homing_beep.min_cycle_time );
1155 // hud_init_targeting() will set the current target to point to the dummy node
1156 // in the object used list
1158 void hud_init_targeting()
1160 Assert(Player_ai != NULL);
1162 // make sure there is no current target
1163 set_target_objnum( Player_ai, -1 );
1164 Player_ai->last_target = -1;
1165 Player_ai->last_subsys_target = NULL;
1166 Player_ai->last_dist = 0.0f;
1167 Player_ai->last_speed = 0.0f;
1169 hud_keyed_targets_clear();
1170 hud_init_missile_lock();
1171 hud_init_artillery();
1173 // Init the lists that hold targets in reticle (to allow cycling of targets in reticle)
1174 hud_reticle_list_init();
1175 hud_init_homing_beep();
1177 // Load in the frames need for the lead indicator
1178 if (!Lead_indicator_gauge_loaded) {
1179 Lead_indicator_gauge.first_frame = bm_load_animation(Lead_fname[gr_screen.res], &Lead_indicator_gauge.num_frames);
1180 if ( Lead_indicator_gauge.first_frame < 0 ) {
1181 Warning(LOCATION,"Cannot load hud ani: %s\n", Lead_fname[gr_screen.res]);
1183 Lead_indicator_gauge_loaded = 1;
1186 if (!Energy_bar_gauges_loaded) {
1187 Energy_bar_gauges.first_frame = bm_load_animation(Energy_fname[gr_screen.res], &Energy_bar_gauges.num_frames);
1188 if ( Energy_bar_gauges.first_frame < 0 ) {
1189 Warning(LOCATION,"Cannot load hud ani: %s\n", Energy_fname[gr_screen.res]);
1191 Energy_bar_gauges_loaded = 1;
1194 if (!Toggle_gauge_loaded) {
1195 Toggle_gauge.first_frame = bm_load_animation(Toggle_fname[gr_screen.res], &Toggle_gauge.num_frames);
1196 if ( Toggle_gauge.first_frame < 0 ) {
1197 Warning(LOCATION,"Cannot load hud ani: %s\n", Toggle_fname[gr_screen.res]);
1199 Toggle_gauge_loaded = 1;
1202 if (!Cmeasure_gauge_loaded) {
1203 Cmeasure_gauge.first_frame = bm_load_animation(Cm_fname[gr_screen.res], &Cmeasure_gauge.num_frames);
1204 if ( Cmeasure_gauge.first_frame < 0 ) {
1205 Warning(LOCATION,"Cannot load hud ani: %s\n", Cm_fname[gr_screen.res]);
1207 Cmeasure_gauge_loaded = 1;
1213 Min_warning_missile_dist = 2.5f*Player_obj->radius;
1214 Max_warning_missile_dist = 1500.0f;
1216 Tl_hostile_reset_timestamp = timestamp(0);
1217 Tl_friendly_reset_timestamp = timestamp(0);
1218 Target_next_uninspected_object_timestamp = timestamp(0);
1219 Target_newest_ship_timestamp = timestamp(0);
1220 Target_next_turret_timestamp = timestamp(0);
1222 if(The_mission.flags & MISSION_FLAG_FULLNEB) {
1223 Toggle_text_alpha = 127;
1225 Toggle_text_alpha = 160;
1231 // Target the next or previous subobject on the currently selected ship, based on next_flag.
1232 void hud_target_subobject_common(int next_flag)
1234 if (Player_ai->target_objnum == -1) {
1235 HUD_sourced_printf(HUD_SOURCE_HIDDEN, XSTR( "No target selected.", 322));
1236 snd_play( &Snds[SND_TARGET_FAIL] );
1240 if (Objects[Player_ai->target_objnum].type != OBJ_SHIP) {
1241 snd_play( &Snds[SND_TARGET_FAIL]);
1245 ship_subsys *start, *start2, *A;
1246 ship_subsys *subsys_to_target=NULL;
1249 target_shipp = &Ships[Objects[Player_ai->target_objnum].instance];
1251 if (!Player_ai->targeted_subsys) {
1252 start = GET_FIRST(&target_shipp->subsys_list);
1254 start = Player_ai->targeted_subsys;
1257 start2 = advance_subsys(start, next_flag);
1259 for ( A = start2; A != start; A = advance_subsys(A, next_flag) ) {
1261 if ( A == &target_shipp->subsys_list ) {
1266 if ( A->system_info->type == SUBSYSTEM_TURRET ) {
1270 subsys_to_target = A;
1275 if ( subsys_to_target == NULL ) {
1276 snd_play( &Snds[SND_TARGET_FAIL]);
1278 set_targeted_subsys(Player_ai, subsys_to_target, Player_ai->target_objnum);
1279 target_shipp->last_targeted_subobject[Player_num] = Player_ai->targeted_subsys;
1283 object *advance_fb(object *objp, int next_flag)
1286 return GET_NEXT(objp);
1288 return GET_LAST(objp);
1291 // Target the previous subobject on the currently selected ship.
1294 void hud_target_prev_subobject()
1296 hud_target_subobject_common(0);
1299 void hud_target_next_subobject()
1301 hud_target_subobject_common(1);
1304 // hud_target_next() will set the Players[Player_num].current_target to the next target in the object
1305 // used list whose team matches the team parameter. The player is NOT included in the target list.
1307 // parameters: team => team of ship to target next. Default value is -1, if team doesn't matter.
1310 void hud_target_common(int team, int next_flag)
1312 object *A, *start, *start2;
1314 int is_ship, target_found = FALSE;
1316 if (Player_ai->target_objnum == -1)
1317 start = &obj_used_list;
1319 start = &Objects[Player_ai->target_objnum];
1321 start2 = advance_fb(start, next_flag);
1323 for ( A = start2; A != start; A = advance_fb(A, next_flag) ) {
1326 if ( A == &obj_used_list ) {
1330 if (A == Player_obj || ( A->type != OBJ_SHIP && A->type != OBJ_WEAPON && A->type != OBJ_JUMP_NODE) ){
1334 if(hud_target_invalid_awacs(A)){
1338 if ( A->type == OBJ_WEAPON ) {
1339 if ( !(Weapon_info[Weapons[A->instance].weapon_info_index].wi_flags & WIF_BOMB) ){
1344 if ( A->type == OBJ_SHIP ) {
1345 if ( Ships[A->instance].flags & TARGET_SHIP_IGNORE_FLAGS ){
1351 if ( vm_vec_same( &A->pos, &Eye_position ) ) {
1356 shipp = &Ships[A->instance]; // get a pointer to the ship information
1358 if ( !hud_team_matches_filter(team, shipp->team) ) {
1359 // if we're in multiplayer dogfight, ignore this
1360 if(!((Game_mode & GM_MULTIPLAYER) && (Netgame.type_flags & NG_TYPE_DOGFIGHT))){
1365 if ( A == Player_obj || (shipp->flags & TARGET_SHIP_IGNORE_FLAGS) ){
1369 // if we've reached here, it is a valid next target
1370 if ( Player_ai->target_objnum != A-Objects ) {
1371 target_found = TRUE;
1372 set_target_objnum( Player_ai, OBJ_INDEX(A) );
1373 // if ship is BIG|HUGE and last subsys is NULL, get turret
1374 hud_maybe_set_sorted_turret_subsys(shipp);
1375 hud_restore_subsystem_target(shipp);
1378 target_found = TRUE;
1379 set_target_objnum( Player_ai, OBJ_INDEX(A) );
1385 if ( target_found == FALSE ) {
1386 snd_play( &Snds[SND_TARGET_FAIL] );
1390 void hud_target_next(int team)
1392 hud_target_common(team, 1);
1395 void hud_target_prev(int team)
1397 hud_target_common(team, 0);
1400 // -------------------------------------------------------------------
1401 // advance_missile_obj()
1403 missile_obj *advance_missile_obj(missile_obj *mo, int next_flag)
1406 return GET_NEXT(mo);
1409 return GET_LAST(mo);
1412 ship_obj *advance_ship(ship_obj *so, int next_flag)
1415 return GET_NEXT(so);
1418 return GET_LAST(so);
1421 ship_obj *get_ship_obj_ptr_from_index(int index);
1422 // -------------------------------------------------------------------
1423 // hud_target_missile()
1425 // Target the closest locked missile that is locked on locked_obj
1427 // input: source_obj => pointer to object that fired weapon
1428 // next_flag => 0 -> previous 1 -> next
1430 // NOTE: this function is only allows targeting bombs
1431 void hud_target_missile(object *source_obj, int next_flag)
1433 missile_obj *end, *start, *mo;
1434 object *A, *target_objp;
1438 int target_found = 0;
1440 if ( source_obj->type != OBJ_SHIP )
1443 Assert( Ships[source_obj->instance].ai_index != -1 );
1444 aip = &Ai_info[Ships[source_obj->instance].ai_index];
1446 end = &Missile_obj_list;
1447 if (aip->target_objnum != -1) {
1448 target_objp = &Objects[aip->target_objnum];
1449 if ( target_objp->type == OBJ_WEAPON && Weapon_info[Weapons[target_objp->instance].weapon_info_index].subtype == WP_MISSILE ) { // must be a missile
1450 end = missile_obj_return_address(Weapons[target_objp->instance].missile_list_index);
1454 start = advance_missile_obj(end, next_flag);
1456 for ( mo = start; mo != end; mo = advance_missile_obj(mo, next_flag) ) {
1457 if ( mo == &Missile_obj_list ){
1461 Assert(mo->objnum >= 0 && mo->objnum < MAX_OBJECTS);
1462 A = &Objects[mo->objnum];
1464 Assert(A->type == OBJ_WEAPON);
1465 Assert((A->instance >= 0) && (A->instance < MAX_WEAPONS));
1466 wp = &Weapons[A->instance];
1467 wip = &Weapon_info[wp->weapon_info_index];
1469 // only allow targeting of bombs
1470 if ( !(wip->wi_flags & WIF_BOMB) ) {
1474 // only allow targeting of hostile bombs
1475 if ( (obj_team(A) == Player_ship->team) && (Player_ship->team != TEAM_TRAITOR) ) {
1479 if(hud_target_invalid_awacs(A)){
1483 // if we've reached here, got a new target
1484 target_found = TRUE;
1485 set_target_objnum( aip, OBJ_INDEX(A) );
1489 if ( !target_found ) {
1490 // if no bomb is found, search for bombers
1491 ship_obj *start, *so;
1493 extern ship_obj *Ship_objs;
1494 if ( (aip->target_objnum != -1) && (Objects[aip->target_objnum].type == OBJ_SHIP) && (Ship_info[Ships[Objects[aip->target_objnum].instance].ship_info_index].flags & SIF_BOMBER) ) {
1495 int index = Ships[Objects[aip->target_objnum].instance].ship_list_index;
1496 start = get_ship_obj_ptr_from_index(index);
1498 start = GET_FIRST(&Ship_obj_list);
1501 for (so=advance_ship(start, next_flag); so!=start; so=advance_ship(so, next_flag)) {
1502 object *ship_obj = &Objects[so->objnum];
1504 // don't look at header
1505 if (so == &Ship_obj_list) {
1509 // only allow targeting of hostile bombs
1510 if ( (obj_team(ship_obj) == Player_ship->team) && (Player_ship->team != TEAM_TRAITOR) ) {
1514 if(hud_target_invalid_awacs(ship_obj)){
1518 // check if ship type is bomber
1519 if ( !(Ship_info[Ships[ship_obj->instance].ship_info_index].flags & SIF_BOMBER) ) {
1524 if ( Ships[ship_obj->instance].flags & TARGET_SHIP_IGNORE_FLAGS ){
1529 target_found = TRUE;
1530 set_target_objnum( aip, OBJ_INDEX(ship_obj) );
1535 if ( !target_found ) {
1536 snd_play( &Snds[SND_TARGET_FAIL], 0.0f );
1540 // Return !0 if shipp can be scanned, otherwise return 0
1541 int hud_target_ship_can_be_scanned(ship *shipp)
1545 sip = &Ship_info[shipp->ship_info_index];
1547 // ignore cargo that has already been scanned
1548 if ( shipp->flags & SF_CARGO_REVEALED ) {
1552 // allow ships with scannable flag set
1553 if ( shipp->flags & SF_SCANNABLE ) {
1557 // ignore ships that don't carry cargo
1558 if ( !(sip->flags & (SIF_CARGO|SIF_FREIGHTER)) ) {
1565 // target the next/prev uninspected cargo container
1566 void hud_target_uninspected_cargo(int next_flag)
1568 object *A, *start, *start2;
1570 int target_found = 0;
1572 if (Player_ai->target_objnum == -1) {
1573 start = &obj_used_list;
1575 start = &Objects[Player_ai->target_objnum];
1578 start2 = advance_fb(start, next_flag);
1580 for ( A = start2; A != start; A = advance_fb(A, next_flag) ) {
1581 if ( A == &obj_used_list ) {
1585 if (A == Player_obj || (A->type != OBJ_SHIP) ) {
1589 shipp = &Ships[A->instance]; // get a pointer to the ship information
1591 if ( shipp->flags & TARGET_SHIP_IGNORE_FLAGS ) {
1595 // ignore all non-cargo carrying craft
1596 if ( !hud_target_ship_can_be_scanned(shipp) ) {
1600 if(hud_target_invalid_awacs(A)){
1604 // if we've reached here, it is a valid next target
1605 if ( Player_ai->target_objnum != OBJ_INDEX(A) ) {
1606 target_found = TRUE;
1607 set_target_objnum( Player_ai, OBJ_INDEX(A) );
1611 if ( target_found == FALSE ) {
1612 snd_play( &Snds[SND_TARGET_FAIL]);
1616 // target the newest ship in the area
1617 void hud_target_newest_ship()
1619 object *A, *player_target_objp;
1620 object *newest_obj=NULL;
1623 uint current_target_arrived_time = 0xffffffff, newest_time = 0;
1625 if ( Player_ai->target_objnum >= 0 ) {
1626 player_target_objp = &Objects[Player_ai->target_objnum];
1627 if ( player_target_objp->type == OBJ_SHIP ) {
1628 current_target_arrived_time = Ships[player_target_objp->instance].create_time;
1631 player_target_objp = NULL;
1634 // If no target is selected, then simply target the closest uninspected cargo
1635 if ( Player_ai->target_objnum == -1 || timestamp_elapsed(Target_newest_ship_timestamp) ) {
1636 current_target_arrived_time = 0xffffffff;
1639 Target_newest_ship_timestamp = timestamp(TL_RESET);
1641 for ( so = GET_FIRST(&Ship_obj_list); so != END_OF_LIST(&Ship_obj_list); so = GET_NEXT(so) ) {
1642 A = &Objects[so->objnum];
1643 shipp = &Ships[A->instance]; // get a pointer to the ship information
1645 if ( (A == Player_obj) || (shipp->flags & TARGET_SHIP_IGNORE_FLAGS) )
1649 if ( Ship_info[shipp->ship_info_index].flags & SIF_NAVBUOY ) {
1653 if ( A == player_target_objp ) {
1657 if(hud_target_invalid_awacs(A)){
1661 if ( (shipp->create_time >= newest_time) && (shipp->create_time <= current_target_arrived_time) ) {
1662 newest_time = shipp->create_time;
1668 set_target_objnum( Player_ai, OBJ_INDEX(newest_obj) );
1669 // if BIG|HUGE and no selected subsystem, get sorted turret
1670 hud_maybe_set_sorted_turret_subsys(&Ships[newest_obj->instance]);
1671 hud_restore_subsystem_target(&Ships[newest_obj->instance]);
1674 snd_play( &Snds[SND_TARGET_FAIL]);
1679 #define TYPE_FACING_BEAM 1
1680 #define TYPE_FACING_FLAK 2
1681 #define TYPE_FACING_MISSILE 3
1682 #define TYPE_FACING_LASER 4
1683 #define TYPE_NONFACING_BEAM 5
1684 #define TYPE_NONFACING_FLAK 6
1685 #define TYPE_NONFACING_MISSILE 7
1686 #define TYPE_NONFACING_LASER 8
1687 #define TYPE_NONFACING_INC 4
1689 typedef struct eval_next_turret {
1695 int sort_turret_func(const void *e1, const void *e2)
1697 eval_next_turret *p1 = (eval_next_turret*)e1;
1698 eval_next_turret *p2 = (eval_next_turret*)e2;
1700 Assert(p1->type != TYPE_NONE);
1701 Assert(p2->type != TYPE_NONE);
1703 if (p1->type != p2->type) {
1704 return (p1->type - p2->type);
1706 float delta_dist = p1->dist - p2->dist;
1707 if (delta_dist < 0) {
1709 } else if (delta_dist > 0) {
1717 // target the next/prev live turret on the current target
1718 // auto_advance from hud_update_closest_turret
1719 void hud_target_live_turret(int next_flag, int auto_advance, int only_player_target)
1722 ship_subsys *live_turret=NULL;
1725 eval_next_turret ent[MAX_MODEL_SUBSYSTEMS];
1726 int num_live_turrets = 0;
1728 // make sure we're targeting a ship
1729 if (Player_ai->target_objnum == -1 && !auto_advance) {
1730 snd_play(&Snds[SND_TARGET_FAIL]);
1734 // only targeting subsystems on ship
1735 if ((Objects[Player_ai->target_objnum].type != OBJ_SHIP) && (!auto_advance)) {
1736 snd_play( &Snds[SND_TARGET_FAIL]);
1740 // set some pointers
1741 objp = &Objects[Player_ai->target_objnum];
1742 target_shipp = &Ships[objp->instance];
1745 int timestamp_val = 0;
1746 if (!auto_advance) {
1747 timestamp_val = Target_next_turret_timestamp;
1748 Target_next_turret_timestamp = timestamp(TURRET_RESET);
1751 // If no target is selected, then simply target the closest (or facing) turret
1752 int last_subsys_turret = FALSE;
1753 if (Player_ai->targeted_subsys != NULL) {
1754 if (Player_ai->targeted_subsys->system_info->type == SUBSYSTEM_TURRET) {
1755 if (Player_ai->targeted_subsys->system_info->turret_weapon_type >= 0) {
1756 last_subsys_turret = TRUE;
1761 // do we want the closest turret (or the one our ship is pointing at)
1762 int get_closest_turret = (auto_advance || !last_subsys_turret || timestamp_elapsed(timestamp_val));
1764 // initialize eval struct
1765 memset(ent,0, sizeof(ent));
1766 int use_straigh_ahead_turret = FALSE;
1768 // go through list of turrets
1769 for (A=GET_FIRST(&target_shipp->subsys_list); A!=END_OF_LIST(&target_shipp->subsys_list); A=GET_NEXT(A)) {
1771 if (A->system_info->type == SUBSYSTEM_TURRET) {
1772 // check turret has hit points and has a weapon
1773 if ( (A->current_hits > 0) && (A->system_info->turret_weapon_type >= 0) ) {
1774 if ( !only_player_target || (A->turret_enemy_objnum == OBJ_INDEX(Player_obj)) ) {
1775 vector gsubpos, vec_to_subsys;
1776 float distance, dot;
1777 // get world pos of subsystem and its distance
1778 get_subsystem_world_pos(objp, A, &gsubpos);
1779 distance = vm_vec_normalized_dir(&vec_to_subsys, &gsubpos, &View_position);
1781 // check if facing and in view
1782 int facing = ship_subsystem_in_sight(objp, A, &View_position, &gsubpos, 0);
1784 if (!auto_advance && get_closest_turret && !only_player_target) {
1785 // if within 3 degrees and not previous subsys, use subsys in front
1786 dot = vm_vec_dotprod(&vec_to_subsys, &Player_obj->orient.fvec);
1787 if ((dot > 0.9986) && facing) {
1788 use_straigh_ahead_turret = TRUE;
1793 // set weapon_type to allow sort of ent on type
1794 if (Weapon_info[A->system_info->turret_weapon_type].wi_flags & WIF_BEAM) {
1795 ent[num_live_turrets].type = TYPE_FACING_BEAM;
1796 } else if (Weapon_info[A->system_info->turret_weapon_type].wi_flags & WIF_FLAK) {
1797 ent[num_live_turrets].type = TYPE_FACING_FLAK;
1799 if (Weapon_info[A->system_info->turret_weapon_type].subtype == WP_MISSILE) {
1800 ent[num_live_turrets].type = TYPE_FACING_MISSILE;
1801 } else if (Weapon_info[A->system_info->turret_weapon_type].subtype == WP_LASER) {
1802 ent[num_live_turrets].type = TYPE_FACING_LASER;
1805 ent[num_live_turrets].type = TYPE_FACING_LASER;
1809 // fill out ent struct
1810 ent[num_live_turrets].ss = A;
1811 ent[num_live_turrets].dist = distance;
1813 ent[num_live_turrets].type += TYPE_NONFACING_INC;
1821 // sort the list if we're not using turret straigh ahead of us
1822 if (!use_straigh_ahead_turret) {
1823 qsort(ent, num_live_turrets, sizeof(eval_next_turret), sort_turret_func);
1826 if (use_straigh_ahead_turret) {
1827 // use the straight ahead turret
1830 // check if we have a currently targeted turret and find its position after the sort
1831 int i, start_index, next_index;
1832 if (get_closest_turret) {
1836 for (i=0; i<num_live_turrets; i++) {
1837 if (ent[i].ss == Player_ai->targeted_subsys) {
1842 // check that we started with a turret
1843 if (start_index == -1) {
1848 // set next live turret
1849 if (num_live_turrets == 0) {
1852 } else if (num_live_turrets == 1 || get_closest_turret) {
1853 // only 1 live turret, so set it
1854 live_turret = ent[0].ss;
1857 // advance to next closest turret
1858 next_index = start_index + 1;
1859 if (next_index == num_live_turrets) {
1863 // go to next farther turret
1864 next_index = start_index - 1;
1865 if (next_index == -1) {
1866 next_index = num_live_turrets - 1;
1870 // set the next turret to be targeted based on next_index
1871 live_turret = ent[next_index].ss;
1874 //if (live_turret) {
1876 // mprintf(("name %s, index: %d, type: %d\n", live_turret->system_info->subobj_name, next_index, ent[next_index].type));
1880 if ( live_turret != NULL ) {
1881 set_targeted_subsys(Player_ai, live_turret, Player_ai->target_objnum);
1882 target_shipp->last_targeted_subobject[Player_num] = Player_ai->targeted_subsys;
1884 if (!auto_advance) {
1885 snd_play( &Snds[SND_TARGET_FAIL]);
1891 // -------------------------------------------------------------------
1892 // hud_target_closest_locked_missile()
1894 // Target the closest locked missile that is locked on locked_obj
1896 // input: locked_obj => pointer to object that you want to find
1897 // closest missile to
1899 void hud_target_closest_locked_missile(object *locked_obj)
1901 object *A, *nearest_obj=NULL;
1904 float nearest_dist, dist;
1905 int target_found = FALSE;
1908 nearest_dist = 10000.0f;
1910 for ( mo = GET_NEXT(&Missile_obj_list); mo != END_OF_LIST(&Missile_obj_list); mo = GET_NEXT(mo) ) {
1911 Assert(mo->objnum >= 0 && mo->objnum < MAX_OBJECTS);
1912 A = &Objects[mo->objnum];
1914 if (A->type != OBJ_WEAPON){
1918 Assert((A->instance >= 0) && (A->instance < MAX_WEAPONS));
1919 wp = &Weapons[A->instance];
1920 wip = &Weapon_info[wp->weapon_info_index];
1922 if ( wip->subtype != WP_MISSILE ){
1926 if ( !(wip->wi_flags & (WIF_HOMING_ASPECT|WIF_HOMING_HEAT) ) ){
1930 if(hud_target_invalid_awacs(A)){
1934 if (wp->homing_object == locked_obj) {
1935 dist = vm_vec_dist_quick(&A->pos, &locked_obj->pos); // Find distance!
1937 if (dist < nearest_dist) {
1939 nearest_dist = dist;
1944 if (nearest_dist < 10000.0f) {
1945 Assert(nearest_obj);
1946 set_target_objnum( Player_ai, OBJ_INDEX(nearest_obj) );
1947 target_found = TRUE;
1950 if ( !target_found ){
1951 snd_play( &Snds[SND_TARGET_FAIL], 0.0f );
1955 // Return bitmask of all opponents.
1956 int opposing_team_mask(int team_mask)
1958 return ((TEAM_FRIENDLY | TEAM_NEUTRAL | TEAM_HOSTILE) & ~team_mask) | TEAM_TRAITOR;
1961 // select a new target, by auto-targeting
1962 void hud_target_auto_target_next()
1964 if ( Framecount < 2 ) {
1968 // No auto-targeting after dead.
1969 if (Game_mode & (GM_DEAD | GM_DEAD_BLEW_UP))
1974 valid_team = opposing_team_mask(Player_ship->team);
1976 // try target closest ship attacking player
1977 hud_target_closest(valid_team, OBJ_INDEX(Player_obj), FALSE, TRUE );
1979 // if none, try targeting closest hostile fighter/bomber
1980 if ( Player_ai->target_objnum == -1 ){
1981 hud_target_closest(valid_team, -1, FALSE, TRUE);
1984 // No fighter/bombers exists, so go ahead an target the closest hostile
1985 if ( Player_ai->target_objnum == -1 ){
1986 hud_target_closest(valid_team, -1, FALSE);
1989 // um, ok. Try targeting asteroids that are on a collision course for an escort ship
1990 if ( Player_ai->target_objnum == -1 ) {
1991 asteroid_target_closest_danger();
1996 // Given that object 'targeter' is targetting object 'targetee',
1997 // how far are they? This uses the point closest to the targeter
1998 // object on the targetee's bounding box. So if targeter is inside
1999 // targtee's bounding box, the distance is 0.
2000 float hud_find_target_distance( object *targetee, object *targeter )
2006 // Which model is it?
2007 switch( targetee->type ) {
2009 model_num = Ships[targetee->instance].modelnum;
2012 // model_num = Debris[targetee->instance].model_num;
2015 // Don't find model_num since circles would work better
2016 //model_num = Weapon_info[Weapons[targetee->instance].weapon_info_index].model_num;
2019 // Don't find model_num since circles would work better
2020 //model_num = Asteroid_info[Asteroids[targetee->instance].type].model_num;
2023 // Don't find model_num since circles would work better
2024 //model_num = Jump_nodes[targetee->instance].modelnum;
2030 // New way, that uses bounding box.
2031 if ( model_num > -1 ) {
2032 dist = model_find_closest_point( &tmp_pnt, model_num, -1, &targetee->orient, &targetee->pos, &targeter->pos );
2034 // Old way, that uses radius.
2035 dist = vm_vec_dist_quick(&targetee->pos, &targeter->pos) - targetee->radius;
2036 if ( dist < 0.0f ) {
2043 // hud_target_closest() will set the Players[Player_num].current_target to the closest
2044 // ship to the player that matches the team passed as a paramater
2046 // The current algorithm is to simply iterate through the objects and calculate the
2047 // magnitude of the vector that connects the player to the target. The smallest magnitude
2048 // is tracked, and then used to locate the closest hostile ship. Note only the square of the
2049 // magnitude is required, since we are only comparing magnitudes
2051 // parameters: team => team of closest ship that should be targeted.
2052 // Default value is -1, if team doesn't matter.
2054 // attacked_objnum => object number of ship that is being attacked
2055 // play_fail_snd => boolean, whether to play SND_TARGET_FAIL
2056 // (needed, since function called repeatedly when auto-targeting is
2057 // enabled, and we don't want a string of fail sounds playing).
2058 // This is a default parameter with a value of TRUE
2059 // filter => OPTIONAL parameter (default value 0): when set to TRUE, only
2060 // fighters and bombers are considered for new targets
2062 // returns: TRUE ==> a target was acquired
2063 // FALSE ==> no target was acquired
2065 // eval target as closest struct
2072 int check_nearest_turret;
2073 int attacked_objnum;
2074 int check_all_turrets;
2075 int turret_attacking_target; // check that turret is actually attacking the attacked_objnum
2078 // evaluate a ship (and maybe turrets) as a potential target
2079 // check if shipp (or its turrets) is attacking attacked_objnum
2080 // special case for player trying to select target (don't check if turrets are aimed at player)
2081 void evaluate_ship_as_closest_target(esct *esct)
2083 int targeting_player, turret_is_attacking;
2088 esct->min_distance = FLT_MAX;
2089 esct->check_nearest_turret = FALSE;
2090 turret_is_attacking = FALSE;
2093 object *objp = &Objects[esct->shipp->objnum];
2094 Assert(objp->type == OBJ_SHIP);
2095 if (objp->type != OBJ_SHIP) {
2099 // player being targeted, so we will want closest distance from player
2100 targeting_player = (esct->attacked_objnum == OBJ_INDEX(Player_obj));
2102 // filter on team, except in multiplayer
2103 if ( !hud_team_matches_filter(esct->team, esct->shipp->team) ) {
2104 // if we're in multiplayer dogfight, ignore this
2105 if(!((Game_mode & GM_MULTIPLAYER) && (Netgame.type_flags & NG_TYPE_DOGFIGHT))){
2110 // check if player or ignore ship
2111 if ( (esct->shipp->objnum == OBJ_INDEX(Player_obj)) || (esct->shipp->flags & TARGET_SHIP_IGNORE_FLAGS) ) {
2116 if ( Ship_info[esct->shipp->ship_info_index].flags & SIF_HARMLESS ) {
2120 // only look at targets that are AWACS valid
2121 if (hud_target_invalid_awacs(&Objects[esct->shipp->objnum])) {
2125 // If filter is set, only target fighters and bombers
2126 if ( esct->filter ) {
2127 if ( !(Ship_info[esct->shipp->ship_info_index].flags & (SIF_FIGHTER | SIF_BOMBER)) ) {
2132 // find closest turret to player if BIG or HUGE ship
2133 if (Ship_info[esct->shipp->ship_info_index].flags & (SIF_BIG_SHIP|SIF_HUGE_SHIP)) {
2134 for (ss=GET_FIRST(&esct->shipp->subsys_list); ss!=END_OF_LIST(&esct->shipp->subsys_list); ss=GET_NEXT(ss)) {
2135 if ( (ss->system_info->type == SUBSYSTEM_TURRET) && (ss->current_hits > 0) ) {
2137 if (esct->check_all_turrets || (ss->turret_enemy_objnum == esct->attacked_objnum)) {
2138 turret_is_attacking = 1;
2139 esct->check_nearest_turret = TRUE;
2141 if ( !esct->turret_attacking_target || (esct->turret_attacking_target && (ss->turret_enemy_objnum == esct->attacked_objnum)) ) {
2143 // get world pos of subsystem
2144 vm_vec_unrotate(&gsubpos, &ss->system_info->pnt, &objp->orient);
2145 vm_vec_add2(&gsubpos, &objp->pos);
2146 new_distance = vm_vec_dist_quick(&gsubpos, &Player_obj->pos);
2149 // GET TURRET TYPE, FAVOR BEAM, FLAK, OTHER
2150 int turret_type = ss->system_info->turret_weapon_type;
2151 if (Weapon_info[turret_type].wi_flags & WIF_BEAM) {
2152 new_distance *= 0.3f;
2153 } else if (Weapon_info[turret_type].wi_flags & WIF_FLAK) {
2154 new_distance *= 0.6f;
2157 // get the closest distance
2158 if (new_distance <= esct->min_distance) {
2159 esct->min_distance = new_distance;
2167 // If no turret is attacking, check if objp is actually targetting attacked_objnum
2168 // dont bail if targeting is for player
2169 if ( !targeting_player && !turret_is_attacking ) {
2170 ai_info *aip = &Ai_info[esct->shipp->ai_index];
2172 if (aip->target_objnum != esct->attacked_objnum) {
2176 if ( (Game_mode & GM_NORMAL) && ( aip->mode != AIM_CHASE ) && (aip->mode != AIM_STRAFE) && (aip->mode != AIM_EVADE) && (aip->mode != AIM_EVADE_WEAPON) && (aip->mode != AIM_AVOID)) {
2181 // consider the ship alone if there are no attacking turrets
2182 if ( !turret_is_attacking ) {
2183 //new_distance = hud_find_target_distance(objp, Player_obj);
2184 new_distance = vm_vec_dist_quick(&objp->pos, &Player_obj->pos);
2186 if (new_distance <= esct->min_distance) {
2187 esct->min_distance = new_distance;
2188 esct->check_nearest_turret = FALSE;
2193 int hud_target_closest(int team, int attacked_objnum, int play_fail_snd, int filter, int get_closest_turret_attacking_player)
2196 object *nearest_obj = &obj_used_list;
2199 int check_nearest_turret = FALSE;
2201 // evaluate ship closest target struct
2204 float min_distance = FLT_MAX;
2205 int target_found = FALSE;
2207 int player_obj_index = OBJ_INDEX(Player_obj);
2208 ship_subsys *ss; //*nearest_turret_subsys = NULL, *ss;
2210 if ( (attacked_objnum >= 0) && (attacked_objnum != player_obj_index) ) {
2211 // bail if player does not have target
2212 if ( Player_ai->target_objnum == -1) {
2213 if ( Objects[attacked_objnum].type != OBJ_SHIP ) {
2214 goto Target_closest_done;
2217 // bail if ship is to be ignored
2218 if (!(Ships[Objects[attacked_objnum].instance].flags & TARGET_SHIP_IGNORE_FLAGS)) {
2219 goto Target_closest_done;
2224 if (attacked_objnum == -1) {
2225 attacked_objnum = player_obj_index;
2228 // check all turrets if for player.
2229 esct.check_all_turrets = (attacked_objnum == player_obj_index);
2230 esct.filter = filter;
2232 esct.attacked_objnum = attacked_objnum;
2233 esct.turret_attacking_target = get_closest_turret_attacking_player;
2235 for ( so=GET_FIRST(&Ship_obj_list); so!=END_OF_LIST(&Ship_obj_list); so=GET_NEXT(so) ) {
2237 A = &Objects[so->objnum];
2238 shipp = &Ships[A->instance]; // get a pointer to the ship information
2240 // fill in rest of esct
2243 // check each shipp on list and update nearest obj and subsys
2244 evaluate_ship_as_closest_target(&esct);
2245 if (esct.min_distance < min_distance) {
2246 target_found = TRUE;
2247 min_distance = esct.min_distance;
2249 check_nearest_turret = esct.check_nearest_turret;
2253 Target_closest_done:
2255 // maybe ignore target if too far away
2256 // DKA 9/8/99 Remove distance check
2259 // get distance to nearest attacker
2260 float dist = vm_vec_dist_quick(&Objects[attacked_objnum].pos, &nearest_obj->pos);
2262 // no distance limit for player obj
2263 if ((attacked_objnum != player_obj_index) && (dist > MIN_DISTANCE_TO_CONSIDER_THREAT)) {
2264 target_found = FALSE;
2269 set_target_objnum(Player_ai, OBJ_INDEX(nearest_obj));
2270 if ( check_nearest_turret ) {
2272 // if former subobject was not a turret do, not change subsystem
2273 ss = Ships[nearest_obj->instance].last_targeted_subobject[Player_num];
2274 if (ss == NULL || get_closest_turret_attacking_player) {
2275 // set_targeted_subsys(Player_ai, nearest_turret_subsys, OBJ_INDEX(nearest_obj));
2276 // update nearest turret with later func
2277 hud_target_live_turret(1, 1, get_closest_turret_attacking_player);
2278 Ships[nearest_obj->instance].last_targeted_subobject[Player_num] = Player_ai->targeted_subsys;
2281 hud_restore_subsystem_target(&Ships[nearest_obj->instance]);
2284 // no target found, maybe play fail sound
2285 if (play_fail_snd == TRUE) {
2286 snd_play(&Snds[SND_TARGET_FAIL]);
2290 return target_found;
2293 // auto update closest turret to attack on big or huge ships
2294 void hud_update_closest_turret()
2296 hud_target_live_turret(1, 1);
2299 float nearest_distance, new_distance;
2300 ship_subsys *ss, *closest_subsys;
2304 nearest_distance = FLT_MAX;
2305 objp = &Objects[Player_ai->target_objnum];
2306 shipp = &Ships[objp->instance];
2307 closest_subsys = NULL;
2310 Assert(Ship_info[shipp->ship_info_index].flags & (SIF_BIG_SHIP|SIF_HUGE_SHIP));
2312 for (ss=GET_FIRST(&shipp->subsys_list); ss!=END_OF_LIST(&shipp->subsys_list); ss=GET_NEXT(ss)) {
2313 if ( (ss->system_info->type == SUBSYSTEM_TURRET) && (ss->current_hits > 0) ) {
2314 // make sure turret is not "unused"
2315 if (ss->system_info->turret_weapon_type >= 0) {
2317 // get world pos of subsystem
2318 vm_vec_unrotate(&gsubpos, &ss->system_info->pnt, &objp->orient);
2319 vm_vec_add2(&gsubpos, &objp->pos);
2320 new_distance = vm_vec_dist_quick(&gsubpos, &Player_obj->pos);
2322 // GET TURRET TYPE, FAVOR BEAM, FLAK, OTHER
2323 int turret_type = ss->system_info->turret_weapon_type;
2324 if (Weapon_info[turret_type].wi_flags & WIF_BEAM) {
2325 new_distance *= 0.3f;
2326 } else if (Weapon_info[turret_type].wi_flags & WIF_FLAK) {
2327 new_distance *= 0.6f;
2330 // check if facing and in view
2331 int facing = ship_subsystem_in_sight(objp, ss, &View_position, &gsubpos, 0);
2334 new_distance *= 0.5f;
2337 // get the closest distance
2338 if (new_distance <= nearest_distance) {
2339 nearest_distance = new_distance;
2340 closest_subsys = ss;
2346 // check if new subsys to target
2347 if (Player_ai->targeted_subsys != NULL) {
2348 set_targeted_subsys(Player_ai, closest_subsys, Player_ai->target_objnum);
2349 shipp->last_targeted_subobject[Player_num] = Player_ai->targeted_subsys;
2355 // --------------------------------------------------------------------
2356 // hud_target_targets_target()
2358 // Target your target's target. Your target is specified by objnum passed
2361 void hud_target_targets_target()
2366 if ( Player_ai->target_objnum < 0 || Player_ai->target_objnum >= MAX_OBJECTS ) {
2370 objp = &Objects[Player_ai->target_objnum];
2371 if ( objp->type != OBJ_SHIP ) {
2375 if (hud_target_invalid_awacs(objp)) {
2379 if ( Ships[objp->instance].flags & TARGET_SHIP_IGNORE_FLAGS ) {
2383 tt_objnum = Ai_info[Ships[objp->instance].ai_index].target_objnum;
2384 if ( tt_objnum < 0 || tt_objnum >= MAX_OBJECTS ) {
2388 if ( tt_objnum == OBJ_INDEX(Player_obj) ) {
2392 // if we've reached here, found player target's target
2393 set_target_objnum( Player_ai, tt_objnum );
2394 if (Objects[tt_objnum].type == OBJ_SHIP) {
2395 hud_maybe_set_sorted_turret_subsys(&Ships[Objects[tt_objnum].instance]);
2397 hud_restore_subsystem_target(&Ships[Objects[tt_objnum].instance]);
2401 snd_play( &Snds[SND_TARGET_FAIL], 0.0f );
2404 // Return !0 if target_objp is a valid object type for targeting in reticle, otherwise return 0
2405 int object_targetable_in_reticle(object *target_objp)
2408 if (target_objp == Player_obj ) {
2412 obj_type = target_objp->type;
2414 if ( (obj_type == OBJ_SHIP) || (obj_type == OBJ_DEBRIS) || (obj_type == OBJ_WEAPON) || (obj_type == OBJ_ASTEROID) || (obj_type == OBJ_JUMP_NODE) ) {
2422 // hud_target_in_reticle_new() will target the object that is closest to the player, and who is
2423 // intersected by a ray passed from the center of the reticle out along the forward vector of the
2426 // targeting of objects of type OBJ_SHIP and OBJ_DEBRIS are supported
2428 // Method: A ray is cast from the center of the reticle, and we keep track of any eligible object
2429 // the ray intersects. We take the ship closest to us that intersects an object.
2431 // Since this method may work poorly with objects that are far away, hud_target_in_reticle_old()
2432 // is called if no intersections are found.
2435 #define TARGET_IN_RETICLE_DISTANCE 10000.0f
2437 void hud_target_in_reticle_new()
2444 hud_reticle_clear_list(&Reticle_cur_list);
2445 Reticle_save_timestamp = timestamp(RESET_TARGET_IN_RETICLE);
2447 // Get 3d vector through center of reticle
2448 vm_vec_scale_add(&terminus, &Eye_position, &Player_obj->orient.fvec, TARGET_IN_RETICLE_DISTANCE);
2451 for ( A = GET_FIRST(&obj_used_list); A !=END_OF_LIST(&obj_used_list); A = GET_NEXT(A) ) {
2453 if ( !object_targetable_in_reticle(A) ) {
2457 if ( A->type == OBJ_WEAPON ) {
2458 if ( !(Weapon_info[Weapons[A->instance].weapon_info_index].wi_flags & WIF_BOMB) ){
2463 if ( A->type == OBJ_SHIP ) {
2464 if ( Ships[A->instance].flags & TARGET_SHIP_IGNORE_FLAGS ){
2469 if(hud_target_invalid_awacs(A)){
2475 mc.model_num = Ships[A->instance].modelnum;
2478 mc.model_num = Debris[A->instance].model_num;
2481 mc.model_num = Weapon_info[Weapons[A->instance].weapon_info_index].model_num;
2487 subtype = Asteroids[A->instance].asteroid_subtype;
2488 mc.model_num = Asteroid_info[Asteroids[A->instance].type].model_num[subtype];
2493 mc.model_num = Jump_nodes[A->instance].modelnum;
2496 Int3(); // Illegal object type.
2499 model_clear_instance( mc.model_num );
2500 mc.orient = &A->orient; // The object's orient
2501 mc.pos = &A->pos; // The object's position
2502 mc.p0 = &Eye_position; // Point 1 of ray to check
2503 mc.p1 = &terminus; // Point 2 of ray to check
2504 mc.flags = MC_CHECK_MODEL; // | MC_ONLY_BOUND_BOX; // check the model, but only its bounding box
2507 if ( mc.num_hits ) {
2508 dist = vm_vec_dist_squared(&mc.hit_point_world, &Eye_position);
2509 hud_reticle_list_update(A, dist, 0);
2511 } // end for (go to next object)
2513 hud_target_in_reticle_old(); // try the old method (works well with ships far away)
2516 // hud_target_in_reticle_old() will target the object that is closest to the reticle center and inside
2519 // targeting of objects of type OBJ_SHIP and OBJ_DEBRIS are supported
2522 // Method: take the dot product of the foward vector and the vector to target. Take
2523 // the one that is closest to 1 and at least MIN_DOT_FOR_TARGET
2525 // IMPORTANT: The MIN_DOT_FOR_TARGET value was arrived at by trial and error and
2526 // is only valid for the HUD reticle in use at that time.
2528 #define MIN_DOT_FOR_TARGET 0.9726// fov for targeting in reticle
2530 void hud_target_in_reticle_old()
2532 object *A, *target_obj;
2534 vector vec_to_target;
2536 for ( A = GET_FIRST(&obj_used_list); A !=END_OF_LIST(&obj_used_list); A = GET_NEXT(A) ) {
2538 if ( !object_targetable_in_reticle(A) ) {
2542 if ( A->type == OBJ_WEAPON ) {
2543 if ( !(Weapon_info[Weapons[A->instance].weapon_info_index].wi_flags & WIF_BOMB) ){
2548 if ( A->type == OBJ_SHIP ) {
2549 if ( Ships[A->instance].flags & TARGET_SHIP_IGNORE_FLAGS ){
2554 if(hud_target_invalid_awacs(A)){
2558 if ( vm_vec_same( &A->pos, &Eye_position ) ) {
2562 dist = vm_vec_normalized_dir(&vec_to_target, &A->pos, &Eye_position);
2563 dot = vm_vec_dot(&Player_obj->orient.fvec, &vec_to_target);
2565 if ( dot > MIN_DOT_FOR_TARGET ) {
2566 hud_reticle_list_update(A, dot, 1);
2570 target_obj = hud_reticle_pick_target();
2571 if ( target_obj != NULL ) {
2572 set_target_objnum( Player_ai, OBJ_INDEX(target_obj) );
2573 if ( target_obj->type == OBJ_SHIP ) {
2574 // if BIG|HUGE, maybe set subsys to turret
2575 hud_maybe_set_sorted_turret_subsys(&Ships[target_obj->instance]);
2576 hud_restore_subsystem_target(&Ships[target_obj->instance]);
2580 snd_play( &Snds[SND_TARGET_FAIL], 0.0f );
2584 // hud_target_subsystem_in_reticle() will target the subsystem that is within the reticle and
2585 // is closest to the reticle center. The current target is the only object that is searched for
2588 // Method: take the dot product of the foward vector and the vector to target. Take
2589 // the one that is closest to 1 and at least MIN_DOT_FOR_TARGET
2591 // IMPORTANT: The MIN_DOT_FOR_TARGET value was arrived at by trial and error and
2592 // is only valid for the HUD reticle in use at that time.
2595 void hud_target_subsystem_in_reticle()
2598 ship_subsys *subsys;
2599 ship_subsys *nearest_subsys = NULL;
2602 float dist, dot, best_dot;
2603 vector vec_to_target;
2606 if ( Player_ai->target_objnum == -1){
2607 hud_target_in_reticle_old();
2610 if ( Player_ai->target_objnum == -1) {
2611 snd_play( &Snds[SND_TARGET_FAIL]);
2615 targetp = &Objects[Player_ai->target_objnum];
2617 if ( targetp->type != OBJ_SHIP ){ // only targeting subsystems on ship
2621 int shipnum = targetp->instance;
2623 for (subsys = GET_FIRST(&Ships[shipnum].subsys_list); subsys != END_OF_LIST(&Ships[shipnum].subsys_list) ; subsys = GET_NEXT( subsys ) ) {
2624 get_subsystem_world_pos(targetp, subsys, &subobj_pos);
2626 dist = vm_vec_normalized_dir(&vec_to_target, &subobj_pos, &Eye_position);
2627 dot = vm_vec_dot(&Player_obj->orient.fvec, &vec_to_target);
2629 if ( dot > best_dot ) {
2631 if ( best_dot > MIN_DOT_FOR_TARGET )
2632 nearest_subsys = subsys;
2635 Assert(best_dot <= 1.0f);
2638 if ( nearest_subsys != NULL ) {
2639 set_targeted_subsys(Player_ai, nearest_subsys, Player_ai->target_objnum);
2640 HUD_sourced_printf(HUD_SOURCE_HIDDEN, XSTR( "Targeting subsystem %s.", 323), Player_ai->targeted_subsys->system_info->name);
2641 Ships[shipnum].last_targeted_subobject[Player_num] = Player_ai->targeted_subsys;
2644 snd_play( &Snds[SND_TARGET_FAIL]);
2649 #define T_OFFSET_FROM_CIRCLE -13
2650 #define T_BASE_LENGTH 4
2654 void hud_render_orientation_tee(object *from_objp, object *to_objp, matrix *from_orientp)
2657 vector target_to_obj;
2658 float x1,y1,x2,y2,x3,y3,x4,y4;
2660 vm_vec_sub(&target_to_obj, &from_objp->pos, &to_objp->pos);
2662 vm_vec_normalize(&target_to_obj);
2664 // calculate the dot product between the target_to_player vector and the targets forward vector
2666 // 0 - vectors are perpendicular
2667 // 1 - vectors are collinear and in the same direction (target is facing player)
2668 // -1 - vectors are collinear and in the opposite direction (target is facing away from player)
2669 dot_product = vm_vec_dotprod(&from_orientp->fvec, &target_to_obj);
2671 if (vm_vec_dotprod(&from_orientp->rvec, &target_to_obj) >= 0) {
2672 if (dot_product >= 0){
2673 dot_product = -PI/2*dot_product + PI;
2675 dot_product = -PI/2*dot_product - PI;
2679 dot_product *= PI/2; //(range is now -PI/2 => PI/2)
2682 y1 = (float)sin(dot_product) * (Outer_circle_radius[gr_screen.res] - T_OFFSET_FROM_CIRCLE);
2683 x1 = (float)cos(dot_product) * (Outer_circle_radius[gr_screen.res] - T_OFFSET_FROM_CIRCLE);
2685 y1 += Hud_reticle_center[gr_screen.res][1];
2686 x1 += Hud_reticle_center[gr_screen.res][0];
2691 y2 = (float)sin(dot_product) * (Outer_circle_radius[gr_screen.res] - T_OFFSET_FROM_CIRCLE - T_LENGTH);
2692 x2 = (float)cos(dot_product) * (Outer_circle_radius[gr_screen.res] - T_OFFSET_FROM_CIRCLE - T_LENGTH);
2694 y2 += Hud_reticle_center[gr_screen.res][1];
2695 x2 += Hud_reticle_center[gr_screen.res][0];
2700 x3 = x1 - T_BASE_LENGTH * (float)sin(dot_product);
2701 y3 = y1 + T_BASE_LENGTH * (float)cos(dot_product);
2702 x4 = x1 + T_BASE_LENGTH * (float)sin(dot_product);
2703 y4 = y1 - T_BASE_LENGTH * (float)cos(dot_product);
2705 // HACK! Should be antialiased!
2706 gr_line(fl2i(x3),fl2i(y3),fl2i(x4),fl2i(y4)); // bottom of T
2707 gr_line(fl2i(x1),fl2i(y1),fl2i(x2),fl2i(y2)); // part of T pointing towards center
2711 void hud_tri(float x1,float y1,float x2,float y2,float x3,float y3)
2715 // Make the triangle always be the correct handiness so
2716 // the tmapper won't think its back-facing and throw it out.
2717 float det = (y2-y1)*(x3-x1) - (x2-x1)*(y3-y1);
2718 if ( det >= 0.0f ) {
2732 vertex * vertlist[3];
2735 for (i=0; i<3; i++ )
2736 vertlist[i] = &verts[i];
2738 verts[0].sx = x1; verts[0].sy = y1;
2739 verts[1].sx = x2; verts[1].sy = y2;
2740 verts[2].sx = x3; verts[2].sy = y3;
2742 uint saved_mode = gr_zbuffer_get();
2744 gr_zbuffer_set( GR_ZBUFF_NONE );
2746 gr_tmapper( 3, vertlist, 0 );
2748 gr_zbuffer_set( saved_mode );
2752 void hud_tri_empty(float x1,float y1,float x2,float y2,float x3,float y3)
2754 gr_line(fl2i(x1),fl2i(y1),fl2i(x2),fl2i(y2));
2755 gr_line(fl2i(x2),fl2i(y2),fl2i(x3),fl2i(y3));
2756 gr_line(fl2i(x3),fl2i(y3),fl2i(x1),fl2i(y1));
2760 // Render a missile warning triangle that has a tail on it to indicate distance
2761 void hud_render_tail_missile_triangle(float ang, float xpos, float ypos, float cur_dist, int draw_solid, int draw_inside)
2770 float sin_ang, cos_ang, tail_len;
2772 float max_tail_len=20.0f;
2774 sin_ang=(float)sin(ang);
2775 cos_ang=(float)cos(ang);
2777 if ( cur_dist < Min_warning_missile_dist ) {
2779 } else if ( cur_dist > Max_warning_missile_dist ) {
2780 tail_len = max_tail_len;
2782 tail_len = cur_dist/Max_warning_missile_dist * max_tail_len;
2785 if ( draw_inside ) {
2786 x1 = xpos - Target_triangle_base[gr_screen.res] * -sin_ang;
2787 y1 = ypos + Target_triangle_base[gr_screen.res] * cos_ang;
2788 x2 = xpos + Target_triangle_base[gr_screen.res] * -sin_ang;
2789 y2 = ypos - Target_triangle_base[gr_screen.res] * cos_ang;
2791 xpos -= Target_triangle_height[gr_screen.res] * cos_ang;
2792 ypos += Target_triangle_height[gr_screen.res] * sin_ang;
2794 if ( tail_len > 0 ) {
2795 xtail = xpos - tail_len * cos_ang;
2796 ytail = ypos + tail_len * sin_ang;
2800 x1 = xpos - Target_triangle_base[gr_screen.res] * -sin_ang;
2801 y1 = ypos + Target_triangle_base[gr_screen.res] * cos_ang;
2802 x2 = xpos + Target_triangle_base[gr_screen.res] * -sin_ang;
2803 y2 = ypos - Target_triangle_base[gr_screen.res] * cos_ang;
2805 xpos += Target_triangle_height[gr_screen.res] * cos_ang;
2806 ypos -= Target_triangle_height[gr_screen.res] * sin_ang;
2808 if ( tail_len > 0 ) {
2809 xtail = xpos + tail_len * cos_ang;
2810 ytail = ypos - tail_len * sin_ang;
2815 hud_tri(xpos,ypos,x1,y1,x2,y2);
2817 hud_tri_empty(xpos,ypos,x1,y1,x2,y2);
2820 // draw the tail indicating length
2821 if ( tail_len > 0 ) {
2822 gr_line(fl2i(xpos), fl2i(ypos), fl2i(xtail), fl2i(ytail));
2826 // Render a missile warning triangle, that splits apart to indicate distance
2827 void hud_render_split_missile_triangle(float ang, float xpos, float ypos, float cur_dist, int draw_solid, int draw_inside)
2829 // points to draw triangles
2843 float triangle_sep, half_triangle_sep,sin_ang,cos_ang;
2845 sin_ang=(float)sin(ang);
2846 cos_ang=(float)cos(ang);
2848 if ( cur_dist < Min_warning_missile_dist ) {
2849 triangle_sep = 0.0f;
2850 } else if ( cur_dist > Max_warning_missile_dist ) {
2851 triangle_sep = Max_offscreen_tri_seperation[gr_screen.res]+Max_front_seperation[gr_screen.res];
2853 triangle_sep = (cur_dist/Max_warning_missile_dist) * (Max_offscreen_tri_seperation[gr_screen.res]+Max_front_seperation[gr_screen.res]);
2856 // calculate these values only once, since it will be used in several places
2857 half_triangle_sep = 0.5f * triangle_sep;
2859 xpos = (float)floor(xpos);
2860 ypos = (float)floor(ypos);
2862 if ( triangle_sep == 0 ) {
2863 x1 = xpos - Target_triangle_base[gr_screen.res] * -sin_ang;
2864 y1 = ypos + Target_triangle_base[gr_screen.res] * cos_ang;
2865 x2 = xpos + Target_triangle_base[gr_screen.res] * -sin_ang;
2866 y2 = ypos - Target_triangle_base[gr_screen.res] * cos_ang;
2867 if ( draw_inside ) {
2869 xpos += Target_triangle_height[gr_screen.res] * cos_ang;
2870 ypos -= Target_triangle_height[gr_screen.res] * sin_ang;
2873 hud_tri(xpos,ypos,x1,y1,x2,y2);
2875 hud_tri_empty(xpos,ypos,x1,y1,x2,y2);
2878 // calc left side points
2879 x5 = xpos - half_triangle_sep * -sin_ang;
2880 y5 = ypos + half_triangle_sep * cos_ang;
2882 x6 = x5 - Target_triangle_base[gr_screen.res] * -sin_ang;
2883 y6 = y5 + Target_triangle_base[gr_screen.res] * cos_ang;
2887 if ( draw_inside ) {
2888 x4 -= Target_triangle_height[gr_screen.res] * cos_ang;
2889 y4 += Target_triangle_height[gr_screen.res] * sin_ang;
2891 x4 += Target_triangle_height[gr_screen.res] * cos_ang;
2892 y4 -= Target_triangle_height[gr_screen.res] * sin_ang;
2895 // calc right side points
2896 x2 = xpos + half_triangle_sep * -sin_ang;
2897 y2 = ypos - half_triangle_sep * cos_ang;
2899 x3 = x2 + Target_triangle_base[gr_screen.res] * -sin_ang;
2900 y3 = y2 - Target_triangle_base[gr_screen.res] * cos_ang;
2904 if ( draw_inside ) {
2905 x1 -= Target_triangle_height[gr_screen.res] * cos_ang;
2906 y1 += Target_triangle_height[gr_screen.res] * sin_ang;
2908 x1 += Target_triangle_height[gr_screen.res] * cos_ang;
2909 y1 -= Target_triangle_height[gr_screen.res] * sin_ang;
2912 // draw both tris with a line connecting them
2914 hud_tri(x3,y3,x2,y2,x1,y1);
2915 hud_tri(x4,y4,x5,y5,x6,y6);
2917 hud_tri_empty(x3,y3,x2,y2,x1,y1);
2918 hud_tri_empty(x4,y4,x5,y5,x6,y6);
2920 gr_line(fl2i(x2+0.5f),fl2i(y2+0.5f),fl2i(x5+0.5f),fl2i(y5+0.5f));
2924 // Render a triangle on the outside of the targeting circle.
2925 // Must be inside a g3_start_frame().
2926 // If aspect_flag !0, then render filled, indicating aspect lock.
2927 // If show_interior !0, then point inwards to positions inside reticle
2928 void hud_render_triangle(vector *hostile_pos, int aspect_flag, int show_interior, int split_tri)
2930 vertex hostile_vertex;
2932 float xpos,ypos,cur_dist,sin_ang,cos_ang;
2935 // determine if the closest firing object is within the targeting reticle (which means the triangle
2938 cur_dist = vm_vec_dist_quick(&Player_obj->pos, hostile_pos);
2940 g3_rotate_vertex(&hostile_vertex, hostile_pos);
2942 if (hostile_vertex.codes == 0) {// on screen
2943 float projected_x, projected_y;
2945 g3_project_vertex(&hostile_vertex);
2947 if (!(hostile_vertex.flags & PF_OVERFLOW)) { // make sure point projected
2950 projected_x = hostile_vertex.sx;
2951 projected_y = hostile_vertex.sy;
2953 mag_squared = (projected_x-Hud_reticle_center[gr_screen.res][0])*(projected_x-Hud_reticle_center[gr_screen.res][0]) +
2954 (projected_y-Hud_reticle_center[gr_screen.res][1])*(projected_y-Hud_reticle_center[gr_screen.res][1]);
2956 if ( mag_squared < Outer_circle_radius[gr_screen.res]*Outer_circle_radius[gr_screen.res] ) {
2957 if ( !show_interior ) {
2966 ang = atan2_safe(hostile_vertex.y,hostile_vertex.x);
2967 sin_ang=(float)sin(ang);
2968 cos_ang=(float)cos(ang);
2970 if ( draw_inside ) {
2971 xpos = Hud_reticle_center[gr_screen.res][0] + cos_ang*(Outer_circle_radius[gr_screen.res]-7);
2972 ypos = Hud_reticle_center[gr_screen.res][1] - sin_ang*(Outer_circle_radius[gr_screen.res]-7);
2974 xpos = Hud_reticle_center[gr_screen.res][0] + cos_ang*(Outer_circle_radius[gr_screen.res]+4);
2975 ypos = Hud_reticle_center[gr_screen.res][1] - sin_ang*(Outer_circle_radius[gr_screen.res]+4);
2978 xpos += HUD_offset_x;
2979 ypos += HUD_offset_y;
2982 // hud_render_split_missile_triangle(ang, xpos, ypos, cur_dist, aspect_flag, draw_inside);
2983 hud_render_tail_missile_triangle(ang, xpos, ypos, cur_dist, aspect_flag, draw_inside);
2990 if ( draw_inside ) {
2991 x1 = xpos - Target_triangle_base[gr_screen.res] * -sin_ang;
2992 y1 = ypos + Target_triangle_base[gr_screen.res] * cos_ang;
2993 x2 = xpos + Target_triangle_base[gr_screen.res] * -sin_ang;
2994 y2 = ypos - Target_triangle_base[gr_screen.res] * cos_ang;
2996 xpos -= Target_triangle_height[gr_screen.res] * cos_ang;
2997 ypos += Target_triangle_height[gr_screen.res] * sin_ang;
3000 x1 = xpos - Target_triangle_base[gr_screen.res] * -sin_ang;
3001 y1 = ypos + Target_triangle_base[gr_screen.res] * cos_ang;
3002 x2 = xpos + Target_triangle_base[gr_screen.res] * -sin_ang;
3003 y2 = ypos - Target_triangle_base[gr_screen.res] * cos_ang;
3005 xpos += Target_triangle_height[gr_screen.res] * cos_ang;
3006 ypos -= Target_triangle_height[gr_screen.res] * sin_ang;
3010 hud_tri(xpos,ypos,x1,y1,x2,y2);
3012 hud_tri_empty(xpos,ypos,x1,y1,x2,y2);
3017 // Show all homing missiles locked onto the player.
3018 // Also, play the beep!
3019 void hud_show_homing_missiles()
3024 float dist, nearest_dist;
3025 int closest_is_aspect=0;
3027 gr_set_color_fast(&HUD_color_homing_indicator);
3028 nearest_dist = Homing_beep.max_cycle_dist;
3030 for ( mo = GET_NEXT(&Missile_obj_list); mo != END_OF_LIST(&Missile_obj_list); mo = GET_NEXT(mo) ) {
3031 A = &Objects[mo->objnum];
3032 Assert((A->instance >= 0) && (A->instance < MAX_WEAPONS));
3034 wp = &Weapons[A->instance];
3036 if (wp->homing_object == Player_obj) {
3037 hud_render_triangle(&A->pos, Weapon_info[wp->weapon_info_index].wi_flags & WIF_HOMING_ASPECT, 1, 1);
3038 dist = vm_vec_dist_quick(&A->pos, &Player_obj->pos);
3040 if (dist < nearest_dist) {
3041 nearest_dist = dist;
3042 if ( Weapon_info[wp->weapon_info_index].wi_flags & WIF_HOMING_ASPECT ) {
3043 closest_is_aspect=1;
3045 closest_is_aspect=0;
3051 // See if need to play warning beep.
3052 if (nearest_dist < Homing_beep.max_cycle_dist ) {
3056 delta_time = f2fl(Missiontime - Homing_beep.last_time_played);
3058 // figure out the cycle time by doing a linear interpretation
3059 cycle_time = Homing_beep.min_cycle_time + (nearest_dist-Homing_beep.min_cycle_dist) * Homing_beep.precalced_interp;
3061 // play a new 'beep' if cycle time has elapsed
3062 if ( (delta_time*1000) > cycle_time ) {
3063 Homing_beep.last_time_played = Missiontime;
3064 if ( snd_is_playing(Homing_beep.snd_handle) ) {
3065 snd_stop(Homing_beep.snd_handle);
3068 if ( closest_is_aspect ) {
3069 Homing_beep.snd_handle = snd_play(&Snds[SND_PROXIMITY_ASPECT_WARNING]);
3071 Homing_beep.snd_handle = snd_play(&Snds[SND_PROXIMITY_WARNING]);
3077 // hud_show_orientation_tee() will draw the orientation gauge that orbits the inside of the
3078 // outer reticle ring. If the T is at 12 o'clock, the target is facing the player, if the T
3079 // is at 6 o'clock the target is facing away from the player. If the T is at 3 or 9 o'clock
3080 // the target is facing 90 away from the player.
3081 void hud_show_orientation_tee()
3085 if (Player_ai->target_objnum == -1)
3088 targetp = &Objects[Player_ai->target_objnum];
3090 if ( hud_gauge_maybe_flash(HUD_ORIENTATION_TEE) == 1 ) {
3091 hud_set_iff_color( targetp );
3093 hud_set_iff_color( targetp, 1);
3095 hud_render_orientation_tee(targetp, Player_obj, &targetp->orient);
3098 // routine to draw a bounding box around a remote detonate missile and distance to
3099 void hud_show_remote_detonate_missile()
3104 vertex target_point;
3107 // check for currently locked missiles (highest precedence)
3108 for ( mo = GET_FIRST(&Missile_obj_list); mo != END_OF_LIST(&Missile_obj_list); mo = GET_NEXT(mo) ) {
3109 Assert(mo->objnum >= 0 && mo->objnum < MAX_OBJECTS);
3110 mobjp = &Objects[mo->objnum];
3112 if ((Player_obj != NULL) && (mobjp->parent_sig == Player_obj->parent_sig)) {
3113 if (Weapon_info[Weapons[mobjp->instance].weapon_info_index].wi_flags & WIF_REMOTE) {
3115 distance = hud_find_target_distance(mobjp, Player_obj);
3117 // get box center point
3118 g3_rotate_vertex(&target_point,&mobjp->pos);
3121 g3_project_vertex(&target_point);
3123 if (!(target_point.flags & PF_OVERFLOW)) { // make sure point projected
3124 int modelnum, bound_rval;
3126 switch ( mobjp->type ) {
3128 modelnum = Weapon_info[Weapons[mobjp->instance].weapon_info_index].model_num;
3129 bound_rval = model_find_2d_bound_min( modelnum, &mobjp->orient, &mobjp->pos,&x1,&y1,&x2,&y2 );
3133 Int3(); // should never happen
3137 if ( bound_rval == 0 ) {
3138 // draw brackets and distance
3140 color = hud_brackets_get_iff_color(MESSAGE_SENDER);
3141 gr_set_color_fast(&IFF_colors[color][1]);
3142 draw_bounding_brackets(x1-5,y1-5,x2+5,y2+5,0,0, distance, OBJ_INDEX(mobjp));
3145 // do only for the first remote detonate missile
3153 // routine to possibly draw a bouding box around a ship sending a message to the player
3154 void hud_show_message_sender()
3157 vertex target_point; // temp vertex used to find screen position for 3-D object;
3162 // don't draw brackets if no ship sending a message
3163 if ( Message_shipnum == -1 )
3166 targetp = &Objects[Ships[Message_shipnum].objnum];
3167 Assert ( targetp != NULL );
3169 Assert ( targetp->type == OBJ_SHIP );
3171 // Don't do this for the ship you're flying!
3172 if ( targetp == Player_obj ) {
3176 Assert ( targetp->instance >=0 && targetp->instance < MAX_SHIPS );
3177 target_shipp = &Ships[Message_shipnum];
3179 // check the object flags to see if this ship is gone. If so, then don't do this stuff anymore
3180 if ( targetp->flags & OF_SHOULD_BE_DEAD ) {
3181 Message_shipnum = -1;
3185 // find the current target vertex
3187 g3_rotate_vertex(&target_point,&targetp->pos);
3189 hud_set_iff_color( targetp, 1);
3191 g3_project_vertex(&target_point);
3193 if (!(target_point.flags & PF_OVERFLOW)) { // make sure point projected
3194 int modelnum, bound_rval;
3196 switch ( targetp->type ) {
3198 modelnum = target_shipp->modelnum;
3199 bound_rval = model_find_2d_bound_min( modelnum, &targetp->orient, &targetp->pos,&x1,&y1,&x2,&y2 );
3203 Int3(); // should never happen
3207 if ( bound_rval == 0 ) {
3209 color = hud_brackets_get_iff_color(MESSAGE_SENDER);
3210 gr_set_color_fast(&IFF_colors[color][1]);
3211 draw_bounding_brackets(x1-5,y1-5,x2+5,y2+5,10,10);
3215 if ( hud_gauge_active(HUD_OFFSCREEN_INDICATOR) ) {
3216 if (target_point.codes != 0) { // target center is not on screen
3217 // draw the offscreen indicator at the edge of the screen where the target is closest to
3218 // AL 11-19-97: only show offscreen indicator if player sensors are functioning
3219 if ( (OBJ_INDEX(targetp) != Player_ai->target_objnum) || (Message_shipnum == Objects[Player_ai->target_objnum].instance) ) {
3220 if ( hud_sensors_ok(Player_ship, 0) ) {
3222 gr_set_color_fast(&IFF_colors[IFF_COLOR_MESSAGE][1]);
3223 //dist = vm_vec_dist_quick(&Player_obj->pos, &targetp->pos);
3224 dist = hud_find_target_distance( targetp, Player_obj );
3225 hud_draw_offscreen_indicator(&target_point, &targetp->pos, dist);
3232 // hud_prune_hotkeys()
3234 // Check for ships that are dying, departed or dead. These should be removed from the player's
3236 void hud_prune_hotkeys()
3239 htarget_list *hitem, *plist;
3243 for ( i = 0; i < MAX_KEYED_TARGETS; i++ ) {
3244 plist = &(Players[Player_num].keyed_targets[i]);
3245 if ( EMPTY( plist ) ) // no items in list, then do nothing
3248 hitem = GET_FIRST(plist);
3249 while ( hitem != END_OF_LIST(plist) ) {
3255 Assert ( objp != NULL );
3256 if ( objp->type == OBJ_SHIP ) {
3257 Assert ( objp->instance >=0 && objp->instance < MAX_SHIPS );
3258 sp = &Ships[objp->instance];
3260 // if the object isn't a ship, it shouldn't be on the list, so remove it without question
3265 // check to see if the object is dying -- if so, remove it from the list
3266 // check to see if the ship is departing -- if so, remove it from the list
3267 if ( remove_item || (objp->flags & OF_SHOULD_BE_DEAD) || (sp->flags & (SF_DEPARTING|SF_DYING)) ) {
3269 nprintf(("Network", "Hotkey: Pruning %s\n", sp->ship_name));
3273 temp = GET_NEXT(hitem);
3274 list_remove( plist, hitem );
3275 list_append( &htarget_free_list, hitem );
3280 hitem = GET_NEXT( hitem );
3284 // save the hotkey sets with mission time reaches a certain point. Code was put here because this
3285 // function always called for both single/multiplayer. Maybe not the best location, but whatever.
3286 mission_hotkey_maybe_save_sets();
3289 int HUD_drew_selection_bracket_on_target;
3291 // hud_show_selection_set draws some indicator around all the ships in the current selection set. No
3292 // indicators will be drawn if there is only 1 ship in the set.
3293 void hud_show_selection_set()
3295 htarget_list *hitem, *plist;
3298 vertex target_point; // temp vertex used to find screen position for 3-D object;
3301 HUD_drew_selection_bracket_on_target = 0;
3303 set = Players[Player_num].current_hotkey_set;
3307 Assert ( (set >= 0) && (set < MAX_KEYED_TARGETS) );
3308 plist = &(Players[Player_num].keyed_targets[set]);
3311 for ( hitem = GET_FIRST(plist); hitem != END_OF_LIST(plist); hitem = GET_NEXT(hitem) )
3314 if ( count == 0 ) { // only one ship, do nothing
3315 Players[Player_num].current_hotkey_set = -1;
3319 for ( hitem = GET_FIRST(plist); hitem != END_OF_LIST(plist); hitem = GET_NEXT(hitem) ) {
3320 targetp = hitem->objp;
3321 Assert ( targetp != NULL );
3323 ship *target_shipp = NULL;
3325 Assert ( targetp->type == OBJ_SHIP );
3326 Assert ( targetp->instance >=0 && targetp->instance < MAX_SHIPS );
3327 target_shipp = &Ships[targetp->instance];
3329 if ( (Game_mode & GM_MULTIPLAYER) && (target_shipp == Player_ship) ) {
3333 // find the current target vertex
3335 g3_rotate_vertex(&target_point,&targetp->pos);
3337 vm_vec_sub(&target_vec,&targetp->pos,&Player_obj->pos);
3341 hud_set_iff_color( targetp, 1 );
3343 g3_project_vertex(&target_point);
3345 if (!(target_point.flags & PF_OVERFLOW)) { // make sure point projected
3346 int modelnum, bound_rval;
3348 switch ( targetp->type ) {
3350 modelnum = target_shipp->modelnum;
3351 bound_rval = model_find_2d_bound_min( modelnum, &targetp->orient, &targetp->pos,&x1,&y1,&x2,&y2 );
3355 Int3(); // should never happen
3359 if ( bound_rval == 0 ) {
3360 gr_set_color_fast(&IFF_colors[IFF_COLOR_SELECTION][1]);
3361 draw_bounding_brackets(x1-5,y1-5,x2+5,y2+5,5,5);
3362 if ( OBJ_INDEX(targetp) == Player_ai->target_objnum ) {
3363 HUD_drew_selection_bracket_on_target = 1;
3368 if ( hud_gauge_active(HUD_OFFSCREEN_INDICATOR) ) {
3369 if (target_point.codes != 0) { // target center is not on screen
3370 // draw the offscreen indicator at the edge of the screen where the target is closest to
3371 // AL 11-19-97: only show offscreen indicator if player sensors are functioning
3373 if ( OBJ_INDEX(targetp) != Player_ai->target_objnum ) {
3374 if ( hud_sensors_ok(Player_ship, 0) ) {
3376 gr_set_color_fast(&IFF_colors[IFF_COLOR_SELECTION][1]);
3377 //dist = vm_vec_dist_quick(&Player_obj->pos, &targetp->pos);
3378 dist = hud_find_target_distance( targetp, Player_obj );
3379 hud_draw_offscreen_indicator(&target_point, &targetp->pos, dist);
3387 void hud_show_brackets(object *targetp, vertex *projected_v)
3390 int draw_box = TRUE;
3393 if ( Player->target_is_dying <= 0 ) {
3396 switch ( targetp->type ) {
3398 modelnum = Ships[targetp->instance].modelnum;
3399 bound_rc = model_find_2d_bound_min( modelnum, &targetp->orient, &targetp->pos,&x1,&y1,&x2,&y2 );
3400 if ( bound_rc != 0 ) {
3406 modelnum = Debris[targetp->instance].model_num;
3407 bound_rc = submodel_find_2d_bound_min( modelnum, Debris[targetp->instance].submodel_num, &targetp->orient, &targetp->pos,&x1,&y1,&x2,&y2 );
3408 if ( bound_rc != 0 ) {
3414 Assert(Weapon_info[Weapons[targetp->instance].weapon_info_index].subtype == WP_MISSILE);
3415 modelnum = Weapon_info[Weapons[targetp->instance].weapon_info_index].model_num;
3416 bound_rc = model_find_2d_bound_min( modelnum, &targetp->orient, &targetp->pos,&x1,&y1,&x2,&y2 );
3423 subtype = Asteroids[targetp->instance].asteroid_subtype;
3424 modelnum = Asteroid_info[Asteroids[targetp->instance].type].model_num[subtype];
3425 bound_rc = model_find_2d_bound_min( modelnum, &targetp->orient, &targetp->pos,&x1,&y1,&x2,&y2 );
3431 modelnum = Jump_nodes[targetp->instance].modelnum;
3432 bound_rc = model_find_2d_bound_min( modelnum, &targetp->orient, &targetp->pos,&x1,&y1,&x2,&y2 );
3436 Int3(); // should never happen
3440 Hud_target_w = x2-x1+1;
3441 if ( Hud_target_w > gr_screen.clip_width ) {
3442 Hud_target_w = gr_screen.clip_width;
3445 Hud_target_h = y2-y1+1;
3446 if ( Hud_target_h > gr_screen.clip_height ) {
3447 Hud_target_h = gr_screen.clip_height;
3450 if ( targetp->type == OBJ_ASTEROID ) {
3451 if ( OBJ_INDEX(targetp) == Player_ai->target_objnum ) {
3452 team = TEAM_TRAITOR;
3454 team = SELECTION_SET;
3457 team = obj_team(targetp);
3460 if ( draw_box == TRUE ) {
3463 color = hud_brackets_get_iff_color(team);
3464 // maybe color as tagged
3465 if ( ship_is_tagged(targetp) ) {
3466 color = IFF_COLOR_TAGGED;
3468 distance = hud_find_target_distance( targetp, Player_obj );
3469 gr_set_color_fast(&IFF_colors[color][1]);
3470 draw_bounding_brackets(x1-5,y1-5,x2+5,y2+5,0,0,distance, OBJ_INDEX(targetp));
3473 if ( targetp->type == OBJ_SHIP ) {
3474 draw_bounding_brackets_subobject();
3479 void hud_update_target_in_reticle(vertex *projected_v)
3482 mag_squared = (projected_v->sx-Hud_reticle_center[gr_screen.res][0])*(projected_v->sx-Hud_reticle_center[gr_screen.res][0]) +
3483 (projected_v->sy-Hud_reticle_center[gr_screen.res][1])*(projected_v->sy-Hud_reticle_center[gr_screen.res][1]);
3485 if (mag_squared < Outer_circle_radius[gr_screen.res]*Outer_circle_radius[gr_screen.res]) {
3486 // this information can be used elsewhere
3487 Target_in_reticle = 1;
3490 // this information can be used elsewhere
3491 Target_in_reticle = 0;
3498 // hud_show_targeting_gauges() will display the targeting information on the HUD. Called once per frame.
3500 // Must be inside a g3_start_frame()
3501 // input: frametime => time in seconds since last update
3502 // in_cockpit => flag (default value 1) indicating whether viewpoint is from cockpit or external
3503 void hud_show_targeting_gauges(float frametime, int in_cockpit)
3505 vertex target_point; // temp vertex used to find screen position for 3-D object;
3508 // draw the triangle that points to the closest hostile ship that is firing on the player
3509 // This is always drawn, even if there is no current target. There is also a hook that will
3510 // maybe warn the player via a voice message of an attacking ship.
3512 hud_show_hostile_triangle();
3515 if (Player_ai->target_objnum == -1)
3518 object * targetp = &Objects[Player_ai->target_objnum];
3519 Players[Player_num].lead_indicator_active = 0;
3521 // check to see if there is even a current target
3522 if ( targetp == &obj_used_list ) {
3526 Target_in_reticle = 0;
3528 // AL 1/20/97: Point to targted subsystem if one exists
3529 if ( Player_ai->targeted_subsys != NULL ) {
3530 get_subsystem_world_pos(targetp, Player_ai->targeted_subsys, &target_pos);
3532 Player_ai->current_target_distance = vm_vec_dist_quick(&target_pos,&Player_obj->pos);
3534 target_pos = targetp->pos;
3536 Player_ai->current_target_distance = hud_find_target_distance(targetp,Player_obj);
3539 // find the current target vertex
3541 // The 2D screen pos depends on the current viewer position and orientation.
3542 g3_rotate_vertex(&target_point,&target_pos);
3545 hud_set_iff_color( targetp, 1 );
3546 g3_project_vertex(&target_point);
3548 if (!(target_point.flags & PF_OVERFLOW)) { // make sure point projected
3549 if (target_point.codes == 0) { // target center is not on screen
3550 hud_show_brackets(targetp, &target_point);
3552 hud_update_target_in_reticle(&target_point);
3559 // show the leading target indicator
3560 if ((hud_gauge_active(HUD_LEAD_INDICATOR)) && (!Player->target_is_dying)) {
3561 hud_show_lead_indicator(&target_pos);
3565 // show the indicator that orbits the outer reticle and points in the direction of the target
3566 hud_show_target_triangle_indicator(&target_point);
3568 // draw the orientation tee that orbits the inside of the outer circle of the reticle
3569 if ((hud_gauge_active(HUD_ORIENTATION_TEE)) && (!Player->target_is_dying)) {
3570 hud_show_orientation_tee();
3573 // display the information about the target
3574 if ( hud_gauge_active(HUD_TARGET_MONITOR) ){
3575 if ( !hud_targetbox_static_maybe_blit(frametime) )
3576 hud_show_target_data(frametime);
3579 // update cargo scanning
3580 hud_cargo_scan_update(targetp, frametime);
3582 // draw the shield icon for the current target
3583 if ( hud_gauge_active(HUD_TARGET_SHIELD_ICON) ) {
3584 hud_shield_show(targetp);
3587 // draw the mini target+shield gauge that sits near the bottom of the retcle
3588 if ( hud_gauge_active(HUD_TARGET_MINI_ICON) ) {
3589 int show_gauge_flag=1;
3590 // is gauge configured as a popup?
3591 if ( hud_gauge_is_popup(HUD_TARGET_MINI_ICON) ) {
3592 if ( !hud_gauge_popup_active(HUD_TARGET_MINI_ICON) ) {
3597 if ( show_gauge_flag ) {
3598 hud_shield_show_mini(targetp);
3602 Player->cargo_inspect_time = 0;
3603 player_stop_cargo_scan_sound();
3606 // display the lock indicator
3607 if (!Player->target_is_dying) {
3608 hud_update_lock_indicator(frametime);
3609 hud_show_lock_indicator(frametime);
3611 // update and render artillery
3612 hud_artillery_update();
3613 hud_artillery_render();
3616 // Point to offscreen target
3617 if ( hud_gauge_active(HUD_OFFSCREEN_INDICATOR) ) {
3618 if (target_point.codes != 0) { // target center is not on screen
3619 // draw the offscreen indicator at the edge of the screen where the target is closest to
3620 Assert(Player_ai->target_objnum != -1);
3622 // AL 11-11-97: don't draw the indicator if the ship is messaging, the indicator is drawn
3623 // in the message sending color in hud_show_message_sender()
3624 if ( Message_shipnum != Objects[Player_ai->target_objnum].instance ) {
3625 if ( hud_gauge_maybe_flash(HUD_OFFSCREEN_INDICATOR) != 1) {
3627 hud_set_iff_color( targetp, 1 );
3628 //dist = vm_vec_dist_quick(&Player_obj->pos, &target_pos);
3629 dist = hud_find_target_distance( targetp, Player_obj );
3630 hud_draw_offscreen_indicator(&target_point, &target_pos, dist);
3637 // hud_show_hostile_triangle() will draw an empty triangle that oribits around the outer
3638 // circle of the reticle. It will point to the closest enemy that is firing on the player.
3639 // Currently, it points to the closest enemy that has the player as its target_objnum and has
3640 // SM_ATTACK or SM_SUPER_ATTACK as its ai submode.
3642 void hud_show_hostile_triangle()
3645 float min_distance=1e20f;
3646 float new_distance=0.0f;
3647 object* hostile_obj = &obj_used_list;
3648 object* nearest_obj = &obj_used_list;
3652 ship_subsys *ss, *nearest_turret_subsys = NULL;
3654 int player_obj_index = OBJ_INDEX(Player_obj);
3655 int turret_is_attacking = 0;
3657 so = GET_FIRST(&Ship_obj_list);
3658 for ( so = GET_FIRST(&Ship_obj_list); so != END_OF_LIST(&Ship_obj_list); so = GET_NEXT(so) ) {
3660 A = &Objects[so->objnum];
3661 sp = &Ships[A->instance];
3663 // only look at ships on other team
3664 if ( (A == Player_obj) || (Ships[A->instance].team & Player_ship->team) ) {
3668 aip = &Ai_info[Ships[A->instance].ai_index];
3670 // dont look at ignore ships
3671 if ( sp->flags & TARGET_SHIP_IGNORE_FLAGS ) {
3675 // always ignore cargo containers and navbuoys
3676 if ( Ship_info[sp->ship_info_index].flags & SIF_HARMLESS ) {
3680 // check if ship is stealthy
3681 if (awacs_get_level(&Objects[sp->objnum], Player_ship, 1) < 1) {
3685 turret_is_attacking = 0;
3687 // check if any turrets on ship are firing at the player (only on non fighter-bombers)
3688 if ( !(Ship_info[sp->ship_info_index].flags & (SIF_FIGHTER|SIF_BOMBER)) ) {
3689 for (ss = GET_FIRST(&sp->subsys_list); ss != END_OF_LIST(&sp->subsys_list); ss = GET_NEXT(ss) ) {
3690 if ( (ss->system_info->type == SUBSYSTEM_TURRET) && (ss->current_hits > 0) ) {
3692 if ( ss->turret_enemy_objnum == player_obj_index ) {
3693 turret_is_attacking = 1;
3696 // get world pos of subsystem
3697 vm_vec_unrotate(&gsubpos, &ss->system_info->pnt, &A->orient);
3698 vm_vec_add2(&gsubpos, &A->pos);
3699 new_distance = vm_vec_dist_quick(&gsubpos, &Player_obj->pos);
3701 if (new_distance <= min_distance) {
3702 min_distance=new_distance;
3704 nearest_turret_subsys = ss;
3711 if ( !turret_is_attacking ) {
3712 // check for ships attacking the player
3713 if ( aip->target_objnum != Player_ship->objnum ) {
3717 // ignore enemy if not in chase mode
3718 if ( (Game_mode & GM_NORMAL) && (aip->mode != AIM_CHASE) ) {
3722 new_distance = vm_vec_dist_quick(&A->pos, &Player_obj->pos);
3724 if (new_distance <= min_distance) {
3725 min_distance=new_distance;
3727 nearest_turret_subsys = NULL;
3732 if ( nearest_obj == &obj_used_list ) {
3736 if ( min_distance > MIN_DISTANCE_TO_CONSIDER_THREAT ) {
3740 hostile_obj = nearest_obj;
3742 // hook to maybe warn player about this attacking ship
3743 ship_maybe_warn_player(&Ships[nearest_obj->instance], min_distance);
3745 // check if the closest firing hostile is the current target, if so return
3746 if (OBJ_INDEX(hostile_obj) == Player_ai->target_objnum)
3749 if ( hud_gauge_active(HUD_HOSTILE_TRIANGLE) ) {
3750 if ( hud_gauge_maybe_flash(HUD_HOSTILE_TRIANGLE) != 1 ) {
3751 // hud_set_iff_color( TEAM_HOSTILE, 1 ); // Note: This should really be TEAM_HOSTILE, not opposite of Player_ship->team.
3752 hud_set_iff_color( hostile_obj, 1 );
3753 hud_render_triangle(&hostile_obj->pos, 0, 1, 0);
3758 // Return the bank number for the primary weapon that can fire the farthest, from
3759 // the number of active primary weapons
3760 // input: range => output parameter... it is the range of the selected bank
3761 int hud_get_best_primary_bank(float *range)
3763 int i, best_bank, bank_to_fire, num_to_test;
3764 float weapon_range, farthest_weapon_range;
3768 swp = &Player_ship->weapons;
3770 farthest_weapon_range = 0.0f;
3773 if ( Player_ship->flags & SF_PRIMARY_LINKED ) {
3774 num_to_test = swp->num_primary_banks;
3776 num_to_test = min(1, swp->num_primary_banks);
3779 for ( i = 0; i < num_to_test; i++ ) {
3781 bank_to_fire = (swp->current_primary_bank+i)%2; // Max supported banks is 2
3783 // calculate the range of the weapon, and only display the lead target indicator when
3784 // if the weapon can actually hit the target
3785 Assert(bank_to_fire >= 0);
3786 Assert(swp->primary_bank_weapons[bank_to_fire] >= 0);
3787 wip = &Weapon_info[swp->primary_bank_weapons[bank_to_fire]];
3788 weapon_range = wip->max_speed * wip->lifetime;
3790 if ( weapon_range > farthest_weapon_range ) {
3791 best_bank = bank_to_fire;
3792 farthest_weapon_range = weapon_range;
3796 *range = farthest_weapon_range;
3800 // -----------------------------------------------------------------------------
3801 // polish_predicted_target_pos()
3803 // Called by the draw lead indicator code to predict where the enemy is going to be
3805 void polish_predicted_target_pos(vector *enemy_pos, vector *predicted_enemy_pos, float dist_to_enemy, vector *last_delta_vec, int num_polish_steps)
3808 vector player_pos = Player_obj->pos;
3809 float time_to_enemy;
3810 vector last_predicted_enemy_pos = *predicted_enemy_pos;
3813 shipp = &Ships[Player_obj->instance];
3814 Assert(shipp->weapons.current_primary_bank < shipp->weapons.num_primary_banks);
3815 weapon_info *wip = &Weapon_info[shipp->weapons.primary_bank_weapons[shipp->weapons.current_primary_bank]];
3817 float weapon_speed = wip->max_speed;
3819 vm_vec_zero(last_delta_vec);
3821 for (iteration=0; iteration < num_polish_steps; iteration++) {
3822 dist_to_enemy = vm_vec_dist_quick(predicted_enemy_pos, &player_pos);
3823 time_to_enemy = dist_to_enemy/weapon_speed;
3824 // vm_vec_scale_add(predicted_enemy_pos, enemy_pos, &Objects[Player_ai->target_objnum].orient.fvec, en_physp->speed * time_to_enemy);
3825 vm_vec_scale_add(predicted_enemy_pos, enemy_pos, &Objects[Player_ai->target_objnum].phys_info.vel, time_to_enemy);
3826 vm_vec_sub(last_delta_vec, predicted_enemy_pos, &last_predicted_enemy_pos);
3827 last_predicted_enemy_pos= *predicted_enemy_pos;
3831 // determine the correct frame to draw for the lead indicator
3832 // 0 -> center only (in secondary range only)
3833 // 1 -> full (in secondary and primary range)
3834 // 2 -> oustide only (in primary range only)
3836 // input: prange => range of current primary weapon
3837 // srange => range of current secondary weapon
3838 // dist_to_target => current dist to target
3840 // exit: 0-2 => frame offset
3841 // -1 => don't draw anything
3842 int hudtarget_lead_indicator_pick_frame(float prange, float srange, float dist_to_target)
3844 int frame_offset=-1;
3845 int in_prange=0, in_srange=0;
3847 if ( dist_to_target < prange ) {
3851 if ( dist_to_target < srange ) {
3855 if ( in_prange && in_srange ) {
3857 } else if ( in_prange && !in_srange ) {
3859 } else if ( !in_prange && in_srange ) {
3865 return frame_offset;
3868 // decide what frame of lead indicator to draw
3870 // hud_show_lead_indicator() determine where to draw the lead target box and display it
3871 void hud_show_lead_indicator(vector *target_world_pos)
3873 vector target_moving_direction, last_delta_vector, source_pos;
3875 vertex lead_target_vertex;
3880 float dist_to_target, time_to_target, target_moved_dist, prange, srange;
3881 int bank_to_fire, indicator_frame, frame_offset;
3883 if (Player_ai->target_objnum == -1)
3886 targetp = &Objects[Player_ai->target_objnum];
3887 if ( (targetp->type != OBJ_SHIP) && (targetp->type != OBJ_WEAPON) && (targetp->type != OBJ_ASTEROID) ) {
3891 // only allow bombs to have lead indicator displayed
3892 if ( targetp->type == OBJ_WEAPON ) {
3893 if ( !(Weapon_info[Weapons[targetp->instance].weapon_info_index].wi_flags & WIF_BOMB) ) {
3898 // If the target is out of range, then draw the correct frame for the lead indicator
3899 if ( Lead_indicator_gauge.first_frame == -1 ) {
3904 po = model_get( Player_ship->modelnum );
3905 swp = &Player_ship->weapons;
3907 // Added to take care of situation where there are no primary banks on the player ship
3908 // (this may not be possible, depending on what we decide for the weapons loadout rules)
3909 if ( swp->num_primary_banks == 0 )
3912 bank_to_fire = hud_get_best_primary_bank(&prange);
3913 if ( bank_to_fire < 0 )
3915 wip = &Weapon_info[swp->primary_bank_weapons[bank_to_fire]];
3917 if (po->n_guns && bank_to_fire != -1 ) {
3918 rel_pos = &po->gun_banks[bank_to_fire].pnt[0];
3923 // source_pos will contain the world coordinate of where to base the lead indicator prediction
3924 // from. Normally, this will be the world pos of the gun turret of the currently selected primary
3926 source_pos = Player_obj->pos;
3927 if (rel_pos != NULL) {
3929 vm_vec_unrotate(&gun_point, rel_pos, &Player_obj->orient);
3930 vm_vec_add2(&source_pos, &gun_point);
3933 // Determine "accurate" distance to target. This is the distance from the player ship
3934 // to the closest point on the bounding box of the target
3935 dist_to_target = hud_find_target_distance(targetp, Player_obj);
3937 srange = ship_get_secondary_weapon_range(Player_ship);
3939 if ( swp->current_secondary_bank >= 0 ) {
3941 int bank = swp->current_secondary_bank;
3942 wip = &Weapon_info[swp->secondary_bank_weapons[bank]];
3943 if ( wip->wi_flags & WIF_HOMING_ASPECT ) {
3944 if ( !Player->target_in_lock_cone ) {
3950 frame_offset=hudtarget_lead_indicator_pick_frame(prange, srange, dist_to_target);
3951 if ( frame_offset < 0 ) {
3955 indicator_frame = Lead_indicator_gauge.first_frame + frame_offset;
3957 Assert(wip->max_speed != 0);
3958 time_to_target = dist_to_target / wip->max_speed;
3960 target_moved_dist = targetp->phys_info.speed * time_to_target;
3962 target_moving_direction = targetp->phys_info.vel;
3964 // if we've reached here, the lead target indicator will be displayed
3965 Players[Player_num].lead_indicator_active = 1;
3967 // test if the target is moving at all
3968 if ( vm_vec_mag_quick(&targetp->phys_info.vel) < 0.1f) // Find distance!
3969 Players[Player_num].lead_target_pos = *target_world_pos;
3971 vm_vec_normalize(&target_moving_direction);
3972 vm_vec_scale(&target_moving_direction,target_moved_dist);
3973 vm_vec_add(&Players[Player_num].lead_target_pos, target_world_pos, &target_moving_direction );
3974 polish_predicted_target_pos(target_world_pos, &Players[Player_num].lead_target_pos, dist_to_target, &last_delta_vector, 1); // Not used:, float time_to_enemy)
3977 g3_rotate_vertex(&lead_target_vertex,&Players[Player_num].lead_target_pos);
3979 if (lead_target_vertex.codes == 0) { // on screen
3981 g3_project_vertex(&lead_target_vertex);
3982 if (!(lead_target_vertex.flags & PF_OVERFLOW)) {
3984 if ( hud_gauge_maybe_flash(HUD_LEAD_INDICATOR) == 1 ) {
3985 hud_set_iff_color(targetp, 0);
3987 hud_set_iff_color(targetp, 1);
3990 if ( indicator_frame >= 0 ) {
3991 GR_AABITMAP(indicator_frame, fl2i(lead_target_vertex.sx - Lead_indicator_half[gr_screen.res][0]), fl2i(lead_target_vertex.sy - Lead_indicator_half[gr_screen.res][1]));
3997 // hud_cease_subsystem_targeting() will cease targeting the current targets subsystems
3999 void hud_cease_subsystem_targeting(int print_message)
4003 ship_index = Objects[Player_ai->target_objnum].instance;
4004 if ( ship_index < 0 )
4007 Ships[ship_index].last_targeted_subobject[Player_num] = NULL;
4008 Player_ai->targeted_subsys = NULL;
4009 Player_ai->targeted_subsys_parent = -1;
4010 if ( print_message ) {
4011 HUD_sourced_printf(HUD_SOURCE_HIDDEN, XSTR( "Deactivating sub-system targeting", 324));
4014 hud_stop_looped_locking_sounds();
4018 // hud_cease_targeting() will cease all targeting (main target and subsystem)
4020 void hud_cease_targeting()
4022 set_target_objnum( Player_ai, -1 );
4023 Players[Player_num].flags &= ~PLAYER_FLAGS_AUTO_TARGETING;
4024 hud_cease_subsystem_targeting(0);
4025 HUD_sourced_printf(HUD_SOURCE_HIDDEN, XSTR( "Deactivating targeting system", 325));
4029 // hud_restore_subsystem_target() will remember the last targeted subsystem
4032 void hud_restore_subsystem_target(ship* shipp)
4034 // check if there was a previously targeted sub-system for this target
4035 if ( shipp->last_targeted_subobject[Player_num] != NULL ) {
4036 Player_ai->targeted_subsys = shipp->last_targeted_subobject[Player_num];
4037 Player_ai->targeted_subsys_parent = Player_ai->target_objnum;
4040 Player_ai->targeted_subsys = NULL;
4041 Player_ai->targeted_subsys_parent = -1;
4045 // --------------------------------------------------------------------------------
4046 // get_subsystem_world_pos() returns the world position for a given subobject on a ship
4048 vector* get_subsystem_world_pos(object* parent_obj, ship_subsys* subsys, vector* world_pos)
4050 if (subsys == NULL) {
4051 *world_pos = parent_obj->pos;
4055 vm_vec_unrotate(world_pos, &subsys->system_info->pnt, &parent_obj->orient);
4056 vm_vec_add2(world_pos, &parent_obj->pos);
4061 // If Pl_objp is docking, see if it (or the dockee) are in the target view. If so, flash dock
4063 void hud_maybe_flash_docking_text(object *objp)
4066 int docker_objnum, dockee_objnum;
4068 if ( Player_ai->target_objnum < 0 ) {
4072 if ( objp->type != OBJ_SHIP ) {
4076 aip = &Ai_info[Ships[objp->instance].ai_index];
4080 if ( aip->ai_flags & AIF_DOCKED ) {
4081 docker_objnum = OBJ_INDEX(objp);
4082 dockee_objnum = aip->dock_objnum;
4085 if ( (Player_ai->target_objnum == docker_objnum) || (Player_ai->target_objnum == dockee_objnum) ) {
4086 hud_targetbox_start_flash(TBOX_FLASH_DOCKED, 2000);
4091 // ----------------------------------------------------------------------------
4092 // hud_target_change_check()
4094 // called once per frame to account for when the target changes
4096 void hud_target_change_check()
4098 float current_speed=0.0f;
4100 // Check if player subsystem target has changed, and reset necessary player flag
4101 if ( Player_ai->targeted_subsys != Player_ai->last_subsys_target ) {
4102 Player->subsys_in_view=-1;
4105 // check if the main target has changed
4106 if (Player_ai->last_target != Player_ai->target_objnum) {
4108 if ( Player_ai->target_objnum != -1){
4109 snd_play( &Snds[SND_TARGET_ACQUIRE], 0.0f );
4112 // if we have a hotkey set active, see if new target is in set. If not in
4113 // set, deselect the current hotkey set.
4114 if ( Player->current_hotkey_set != -1 ) {
4115 htarget_list *hitem, *plist;
4117 plist = &(Player->keyed_targets[Player->current_hotkey_set]);
4118 for ( hitem = GET_FIRST(plist); hitem != END_OF_LIST(plist); hitem = GET_NEXT(hitem) ) {
4119 if ( OBJ_INDEX(hitem->objp) == Player_ai->target_objnum ){
4123 if ( hitem == END_OF_LIST(plist) ){
4124 Player->current_hotkey_set = -1;
4128 player_stop_cargo_scan_sound();
4129 hud_shield_hit_reset();
4130 hud_targetbox_init_flash();
4131 hud_targetbox_start_flash(TBOX_FLASH_NAME);
4132 hud_gauge_popup_start(HUD_TARGET_MINI_ICON);
4133 Player->cargo_inspect_time=0;
4134 Player->locking_subsys=NULL;
4135 Player->locking_on_center=0;
4136 Player->locking_subsys_parent=-1;
4138 Player_ai->current_target_dist_trend = NO_CHANGE;
4139 Player_ai->current_target_speed_trend = NO_CHANGE;
4141 if ( Players[Player_num].flags & PLAYER_FLAGS_AUTO_MATCH_SPEED ) {
4142 Players[Player_num].flags &= ~PLAYER_FLAGS_MATCH_TARGET;
4143 // player_match_target_speed("", "", XSTR("Matching speed of newly acquired target",-1));
4144 player_match_target_speed();
4147 if ( Players[Player_num].flags & PLAYER_FLAGS_MATCH_TARGET )
4148 Players[Player_num].flags &= ~PLAYER_FLAGS_MATCH_TARGET; // no more target matching.
4153 if ( Player_ai->target_objnum != -1) {
4154 if ( Objects[Player_ai->target_objnum].type == OBJ_SHIP ) {
4155 hud_restore_subsystem_target(&Ships[Objects[Player_ai->target_objnum].instance]);
4159 // if this target is docked, then flash DOCKING on the hud for a couple of seconds
4160 hud_targetbox_end_flash(TBOX_FLASH_DOCKED);
4161 if ( Player_ai->target_objnum >= 0 ) {
4162 hud_maybe_flash_docking_text(&Objects[Player_ai->target_objnum]);
4166 if (Player_ai->current_target_distance < Player_ai->last_dist-0.01){
4167 Player_ai->current_target_dist_trend = DECREASING;
4168 } else if (Player_ai->current_target_distance > Player_ai->last_dist+0.01){
4169 Player_ai->current_target_dist_trend = INCREASING;
4171 Player_ai->current_target_dist_trend = NO_CHANGE;
4174 current_speed = Objects[Player_ai->target_objnum].phys_info.speed;
4176 if (current_speed < Player_ai->last_speed-0.01){
4177 Player_ai->current_target_speed_trend = DECREASING;
4178 } else if (current_speed > Player_ai->last_speed+0.01) {
4179 Player_ai->current_target_speed_trend = INCREASING;
4181 Player_ai->current_target_speed_trend = NO_CHANGE;
4184 if ( Players[Player_num].flags & PLAYER_FLAGS_AUTO_MATCH_SPEED ) {
4185 if ( !(Players[Player_num].flags & PLAYER_FLAGS_MATCH_TARGET) ) {
4186 // player_match_target_speed("", "", XSTR("Matching target speed",-1));
4187 player_match_target_speed();
4192 Player_ai->last_dist = Player_ai->current_target_distance;
4193 Player_ai->last_speed = current_speed;
4195 Player_ai->last_target = Player_ai->target_objnum;
4196 Player_ai->last_subsys_target = Player_ai->targeted_subsys;
4199 // ---------------------------------------------------------------------
4200 // hud_draw_offscreen_indicator()
4202 // draws the offscreen target indicator
4204 void hud_draw_offscreen_indicator(vertex* target_point, vector *tpos, float distance)
4208 int on_top, on_right, on_left, on_bottom;
4209 float target_x, target_y;
4212 // points to draw triangles
4226 vector targ_to_player;
4229 float half_gauge_length, half_triangle_sep;
4232 // calculate the dot product between the players forward vector and the vector connecting
4233 // the player to the target. Normalize targ_to_player since we want the dot product
4234 // to range between 0 -> 1.
4235 vm_vec_sub(&targ_to_player, &Player_obj->pos, tpos);
4236 vm_vec_normalize(&targ_to_player);
4237 dist_behind = vm_vec_dot(&Player_obj->orient.fvec, &targ_to_player);
4241 if (dist_behind < 0) { // still in front of player, but not in view
4243 dist_behind = dist_behind + 1.0f;
4244 if (dist_behind > 0.2 ){
4245 triangle_sep = ( dist_behind ) * Max_front_seperation[gr_screen.res];
4247 triangle_sep = 0.0f;
4251 triangle_sep = dist_behind * Max_offscreen_tri_seperation[gr_screen.res] + Max_offscreen_tri_seperation[gr_screen.res];
4254 if ( triangle_sep > Max_offscreen_tri_seperation[gr_screen.res] + Max_front_seperation[gr_screen.res]){
4255 triangle_sep = Max_offscreen_tri_seperation[gr_screen.res] + Max_front_seperation[gr_screen.res];
4258 // calculate these values only once, since it will be used in several places
4259 half_triangle_sep = 0.5f * triangle_sep;
4260 half_gauge_length = half_triangle_sep + Offscreen_tri_base[gr_screen.res];
4262 target_x = target_point->x;
4263 target_y = target_point->y;
4265 // We need to find the screen (x,y) for where to draw the offscreen indicator
4267 // The best way I've found is to draw a line from the eye_pos to the target, and
4268 // then use clip_line() to find the screen (x,y) for where the line hits the edge
4271 // The weird thing about clip_line() is that is flips around the two verticies,
4272 // so I use eye_vertex->sx and eye_vertex->sy for the off-screen indicator (x,y)
4274 vertex *eye_vertex = NULL;
4275 vertex real_eye_vertex;
4276 eye_vertex = &real_eye_vertex; // this is needed since clip line takes a **vertex
4278 vm_vec_add( &eye_pos, &Eye_position, &View_matrix.fvec);
4279 g3_rotate_vertex(eye_vertex, &eye_pos);
4282 codes_or = (ubyte)(target_point->codes | eye_vertex->codes);
4283 clip_line(&target_point,&eye_vertex,codes_or,0);
4285 if (!(target_point->flags&PF_PROJECTED))
4286 g3_project_vertex(target_point);
4288 if (!(eye_vertex->flags&PF_PROJECTED))
4289 g3_project_vertex(eye_vertex);
4291 if (eye_vertex->flags&PF_OVERFLOW) {
4292 Int3(); // This is unlikely to happen, but can if a clip goes through the player's eye.
4293 Player_ai->target_objnum = -1;
4297 if (target_point->flags & PF_TEMP_POINT)
4298 free_temp_point(target_point);
4300 if (eye_vertex->flags & PF_TEMP_POINT)
4301 free_temp_point(eye_vertex);
4303 xpos = eye_vertex->sx;
4304 ypos = eye_vertex->sy;
4306 on_left = on_right = on_top = on_bottom = 0;
4307 xpos = (xpos<1) ? 0 : xpos;
4308 ypos = (ypos<1) ? 0 : ypos;
4310 if ( xpos <= gr_screen.clip_left ) {
4311 xpos = i2fl(gr_screen.clip_left);
4314 if ( ypos < (half_gauge_length - gr_screen.clip_top) )
4315 ypos = half_gauge_length;
4318 if ( ypos > (gr_screen.clip_bottom - half_gauge_length) )
4319 ypos = gr_screen.clip_bottom - half_gauge_length;
4322 else if ( xpos >= gr_screen.clip_right) {
4323 xpos = i2fl(gr_screen.clip_right);
4326 if ( ypos < (half_gauge_length - gr_screen.clip_top) )
4327 ypos = half_gauge_length;
4329 if ( ypos > (gr_screen.clip_bottom - half_gauge_length) )
4330 ypos = gr_screen.clip_bottom - half_gauge_length;
4333 else if ( ypos <= gr_screen.clip_top ) {
4334 ypos = i2fl(gr_screen.clip_top);
4337 if ( xpos < ( half_gauge_length - gr_screen.clip_left) )
4338 xpos = half_gauge_length;
4340 if ( xpos > (gr_screen.clip_right - half_gauge_length) )
4341 xpos = gr_screen.clip_right - half_gauge_length;
4344 else if ( ypos >= gr_screen.clip_bottom ) {
4345 ypos = i2fl(gr_screen.clip_bottom);
4348 if ( xpos < ( half_gauge_length - gr_screen.clip_left) )
4349 xpos = half_gauge_length;
4351 if ( xpos > (gr_screen.clip_right - half_gauge_length) )
4352 xpos = gr_screen.clip_right - half_gauge_length;
4359 // The offscreen target triangles are drawn according the the diagram below
4368 // ......|...........|...............(xpos,ypos)
4377 xpos = (float)floor(xpos);
4378 ypos = (float)floor(ypos);
4380 if ( hud_gauge_active(HUD_OFFSCREEN_RANGE) && (distance > 0) ) {
4381 sprintf(buf,"%d",fl2i(distance+0.5f));
4382 hud_num_make_mono(buf);
4383 gr_get_string_size(&w, &h, buf);
4391 x2 = x3 = x5 = x6 = x1 - Offscreen_tri_height[gr_screen.res];
4392 y1 = y2 = ypos - half_triangle_sep;
4393 y3 = y2 - Offscreen_tri_base[gr_screen.res];
4395 y4 = y5 = ypos + half_triangle_sep;
4396 y6 = y5 + Offscreen_tri_base[gr_screen.res];
4399 gr_string( fl2i(xpos - w - 10), fl2i(ypos - h/2.0f+0.5f), buf);
4405 x2 = x3 = x5 = x6 = x1 + Offscreen_tri_height[gr_screen.res];
4406 y1 = y2 = ypos - half_triangle_sep;
4407 y3 = y2 - Offscreen_tri_base[gr_screen.res];
4409 y4 = y5 = ypos + half_triangle_sep;
4410 y6 = y5 + Offscreen_tri_base[gr_screen.res];
4413 gr_string(fl2i(xpos + 10), fl2i(ypos - h/2.0f+0.5f), buf);
4419 y2 = y3 = y5 = y6 = y1 + Offscreen_tri_height[gr_screen.res];
4420 x1 = x2 = xpos - half_triangle_sep;
4421 x3 = x2 - Offscreen_tri_base[gr_screen.res];
4423 x4 = x5 = xpos + half_triangle_sep;
4424 x6 = x5 + Offscreen_tri_base[gr_screen.res];
4427 gr_string(fl2i(xpos - w/2.0f+0.5f), fl2i(ypos+10), buf);
4430 else if (on_bottom) {
4433 y2 = y3 = y5 = y6 = y1 - Offscreen_tri_height[gr_screen.res];
4434 x1 = x2 = xpos - half_triangle_sep;
4435 x3 = x2 - Offscreen_tri_base[gr_screen.res];
4437 x4 = x5 = xpos + half_triangle_sep;
4438 x6 = x5 + Offscreen_tri_base[gr_screen.res];
4441 gr_string(fl2i(xpos - w/2.0f+0.5f), fl2i(ypos-h-10), buf);
4445 hud_tri(x3,y3,x2,y2,x1,y1);
4446 hud_tri(x4,y4,x5,y5,x6,y6);
4447 if (on_right || on_bottom){
4448 gr_line(fl2i(x2),fl2i(y2),fl2i(x5),fl2i(y5));
4449 } else if (on_left) {
4450 gr_line(fl2i(x2-1),fl2i(y2),fl2i(x5-1),fl2i(y5));
4452 gr_line(fl2i(x2),fl2i(y2-1),fl2i(x5),fl2i(y5-1));
4457 // Render the HUD afterburner energy gauge
4458 void hud_show_afterburner_gauge()
4463 if ( Energy_bar_gauges.first_frame == -1 ){
4467 Assert(Player_ship);
4468 if ( !(Ship_info[Player_ship->ship_info_index].flags & SIF_AFTERBURNER) ) {
4469 percent_left = 0.0f;
4471 percent_left = Player_ship->afterburner_fuel/Ship_info[Player_ship->ship_info_index].afterburner_fuel_capacity;
4474 if ( percent_left > 1 ) {
4475 percent_left = 1.0f;
4478 clip_h = fl2i( (1.0f - percent_left) * Aburn_coords[gr_screen.res][3] + 0.5f );
4480 bm_get_info(Energy_bar_gauges.first_frame,&w,&h);
4483 GR_AABITMAP_EX(Energy_bar_gauges.first_frame, Aburn_coords[gr_screen.res][0], Aburn_coords[gr_screen.res][1],w,clip_h,0,0);
4486 if ( clip_h <= Aburn_coords[gr_screen.res][3] ) {
4487 GR_AABITMAP_EX(Energy_bar_gauges.first_frame+1, Aburn_coords[gr_screen.res][0], Aburn_coords[gr_screen.res][1]+clip_h,w,h-clip_h,0,clip_h);
4491 // Render the player weapon energy on the HUD
4492 void hud_show_weapon_energy_gauge()
4495 int clip_h, i, w, h;
4497 if ( Energy_bar_gauges.first_frame == -1 ){
4501 if ( Player_ship->weapons.num_primary_banks <= 0 ){
4505 percent_left = Player_ship->weapon_energy/Ship_info[Player_ship->ship_info_index].max_weapon_reserve;
4506 if ( percent_left > 1 ) {
4507 percent_left = 1.0f;
4510 if ( percent_left <= 0.3 ) {
4512 if ( percent_left < 0.1 ) {
4513 gr_set_color_fast(&Color_bright_red);
4515 sprintf(buf,XSTR( "%d%%", 326), fl2i(percent_left*100+0.5f));
4516 hud_num_make_mono(buf);
4517 gr_string(Weapon_energy_text_coords[gr_screen.res][0], Weapon_energy_text_coords[gr_screen.res][1], buf);
4520 hud_set_gauge_color(HUD_WEAPONS_ENERGY);
4521 for ( i = 0; i < Player_ship->weapons.num_primary_banks; i++ ) {
4522 if ( !timestamp_elapsed(Weapon_flash_info.flash_duration[i]) ) {
4523 if ( Weapon_flash_info.is_bright & (1<<i) ) {
4524 // hud_set_bright_color();
4525 hud_set_gauge_color(HUD_WEAPONS_ENERGY, HUD_C_BRIGHT);
4531 clip_h = fl2i( (1.0f - percent_left) * Wenergy_coords[gr_screen.res][3] + 0.5f );
4533 bm_get_info(Energy_bar_gauges.first_frame+2,&w,&h);
4536 GR_AABITMAP_EX(Energy_bar_gauges.first_frame+2, Wenergy_coords[gr_screen.res][0], Wenergy_coords[gr_screen.res][1], w,clip_h,0,0);
4539 if ( clip_h <= Wenergy_coords[gr_screen.res][3] ) {
4540 GR_AABITMAP_EX(Energy_bar_gauges.first_frame+3, Wenergy_coords[gr_screen.res][0], Wenergy_coords[gr_screen.res][1] + clip_h, w,h-clip_h,0,clip_h);
4543 // hud_set_default_color();
4546 // --------------------------------------------------------------------------------------
4547 // hud_show_target_triangle_indicator()
4549 // Draw the solid triangle that orbits the reticle and points to the nearest target
4551 void hud_show_target_triangle_indicator(vertex *projected_v)
4554 float xpos,ypos,ang;
4556 if ( Player_ai->target_objnum == -1)
4559 object *targetp = &Objects[Player_ai->target_objnum];
4561 // draw the targeting triangle that orbits the outside of the outer circle of the reticle
4562 if ((hud_gauge_active(HUD_TARGET_TRIANGLE)) && !Player->target_is_dying && !Target_in_reticle) {
4563 if ( hud_gauge_maybe_flash(HUD_TARGET_TRIANGLE) == 1 ) {
4567 hud_set_iff_color(targetp, 1);
4569 ang = atan2_safe(projected_v->y,projected_v->x);
4570 xpos = Hud_reticle_center[gr_screen.res][0] + (float)cos(ang)*(Outer_circle_radius[gr_screen.res]+4);
4571 ypos = Hud_reticle_center[gr_screen.res][1] - (float)sin(ang)*(Outer_circle_radius[gr_screen.res]+4);
4573 xpos += HUD_offset_x;
4574 ypos += HUD_offset_y;
4576 x3 = xpos - Target_triangle_base[gr_screen.res] * (float)sin(-ang);
4577 y3 = ypos + Target_triangle_base[gr_screen.res] * (float)cos(-ang);
4578 x4 = xpos + Target_triangle_base[gr_screen.res] * (float)sin(-ang);
4579 y4 = ypos - Target_triangle_base[gr_screen.res] * (float)cos(-ang);
4581 xpos += Target_triangle_height[gr_screen.res] * (float)cos(ang);
4582 ypos -= Target_triangle_height[gr_screen.res] * (float)sin(ang);
4584 hud_tri(xpos,ypos,x3,y3,x4,y4);
4588 // called from hud_show_weapons() to plot out the secondary weapon name and amo
4589 void hud_show_secondary_weapon(int count, ship_weapon *sw, int dual_fire)
4592 char weapon_name[NAME_LENGTH + 10];
4597 if ( sw->num_primary_banks == 2 ) {
4601 for ( i = 0; i < count; i++ ) {
4602 hud_maybe_flash_weapon(sw->num_primary_banks+i);
4603 wip = &Weapon_info[sw->secondary_bank_weapons[i]];
4605 // HACK - make Cluster Bomb fit on the HUD.
4606 if(!stricmp(wip->name,"cluster bomb")){
4607 strcpy(weapon_name, NOX("Cluster"));
4609 strcpy(weapon_name, wip->name);
4612 hud_end_string_at_first_hash_symbol(weapon_name);
4614 if ( sw->current_secondary_bank == i ) {
4615 emp_hud_printf(Weapon_sunlinked_x[gr_screen.res], Weapon_secondary_y[gr_screen.res][i] - np*12, EG_NULL, "%c", Lcl_special_chars + 2);
4618 emp_hud_printf(Weapon_slinked_x[gr_screen.res], Weapon_secondary_y[gr_screen.res][i] - np*12, EG_NULL, "%c", Lcl_special_chars + 2);
4621 emp_hud_string(Weapon_secondary_name_x[gr_screen.res], Weapon_secondary_y[gr_screen.res][i] - np*12, i ? EG_WEAPON_S1 : EG_WEAPON_S2, weapon_name);
4623 if ( (sw->secondary_bank_ammo[i] > 0) && (sw->current_secondary_bank >= 0) ) {
4624 int ms_till_fire = timestamp_until(sw->next_secondary_fire_stamp[sw->current_secondary_bank]);
4625 if ( (ms_till_fire >= 500) && ((wip->fire_wait >= 1 ) || (ms_till_fire > wip->fire_wait*1000)) ) {
4626 emp_hud_printf(Weapon_secondary_reload_x[gr_screen.res], Weapon_secondary_y[gr_screen.res][i] - np*12, EG_NULL, "%d", fl2i(ms_till_fire/1000.0f +0.5f));
4630 emp_hud_string(Weapon_secondary_name_x[gr_screen.res], Weapon_secondary_y[gr_screen.res][i] - np*12, i ? EG_WEAPON_S1 : EG_WEAPON_S2, weapon_name);
4633 // print out the ammo right justified
4634 sprintf(ammo_str, "%d", sw->secondary_bank_ammo[i]);
4635 hud_num_make_mono(ammo_str);
4636 gr_get_string_size(&w, &h, ammo_str);
4638 emp_hud_string(Weapon_secondary_ammo_x[gr_screen.res] - w, Weapon_secondary_y[gr_screen.res][i] - np*12, EG_NULL, ammo_str);
4640 hud_set_gauge_color(HUD_WEAPONS_GAUGE);
4644 // start the weapon line (on the HUD) flashing
4645 void hud_start_flash_weapon(int index)
4647 if ( index >= MAX_WEAPON_FLASH_LINES ) {
4652 if ( timestamp_elapsed(Weapon_flash_info.flash_duration[index]) ) {
4653 Weapon_flash_info.flash_next[index] = timestamp(TBOX_FLASH_INTERVAL);
4654 Weapon_flash_info.is_bright &= ~(1<<index);
4657 Weapon_flash_info.flash_duration[index] = timestamp(TBOX_FLASH_DURATION);
4660 // maybe change the text color for the weapon line indicated by index
4661 void hud_maybe_flash_weapon(int index)
4663 if ( index >= MAX_WEAPON_FLASH_LINES ) {
4668 // hud_set_default_color();
4669 hud_set_gauge_color(HUD_WEAPONS_GAUGE);
4670 if ( !timestamp_elapsed(Weapon_flash_info.flash_duration[index]) ) {
4671 if ( timestamp_elapsed(Weapon_flash_info.flash_next[index]) ) {
4672 Weapon_flash_info.flash_next[index] = timestamp(TBOX_FLASH_INTERVAL);
4673 Weapon_flash_info.is_bright ^= (1<<index);
4676 if ( Weapon_flash_info.is_bright & (1<<index) ) {
4677 hud_set_gauge_color(HUD_WEAPONS_GAUGE, HUD_C_BRIGHT);
4678 // hud_set_bright_color();
4680 hud_set_gauge_color(HUD_WEAPONS_GAUGE, HUD_C_DIM);
4681 // hud_set_dim_color();
4686 // render the coutermeasure HUD gauge
4687 void hud_show_cmeasure_gague()
4689 if ( Cmeasure_gauge.first_frame == -1 ) {
4690 Int3(); // failed to load coutermeasure gauge background
4694 // hud_set_default_color();
4695 hud_set_gauge_color(HUD_CMEASURE_GAUGE);
4697 // blit the background
4698 GR_AABITMAP(Cmeasure_gauge.first_frame, Cm_coords[gr_screen.res][0], Cm_coords[gr_screen.res][1]);
4701 gr_string(Cm_text_coords[gr_screen.res][0], Cm_text_coords[gr_screen.res][1], XSTR( "cm.", 327));
4702 if ( !Player_ship ) {
4703 Int3(); // player ship doesn't exist?
4706 gr_printf(Cm_text_val_coords[gr_screen.res][0], Cm_text_val_coords[gr_screen.res][1], NOX("%02d"),Player_ship->cmeasure_count);
4710 // ------------------------------------------------------------------
4711 // hud_show_weapons()
4713 // Show the player's primary and secondary weapons, along with ammo and % energy
4715 void hud_show_weapons()
4718 int np, ns; // np == num primary, ns == num secondary
4719 char name[NAME_LENGTH];
4721 if(Player_obj->type == OBJ_OBSERVER)
4724 Assert(Player_obj->type == OBJ_SHIP);
4725 Assert(Player_obj->instance >= 0 && Player_obj->instance < MAX_SHIPS);
4727 sw = &Ships[Player_obj->instance].weapons;
4729 np = sw->num_primary_banks;
4730 ns = sw->num_secondary_banks;
4732 // NOTE: I hate to hard-code numbers, but there is no clean way to organize these coords... they
4733 // are all over the place. UGLY.
4735 // BAH. You're a moron, above guy. :)
4737 hud_set_gauge_color(HUD_WEAPONS_GAUGE);
4739 // draw top of primary display
4740 GR_AABITMAP(Weapon_gauges[0].first_frame, Weapon_gauge_primary_coords[gr_screen.res][0][0], Weapon_gauge_primary_coords[gr_screen.res][0][1]);
4742 emp_hud_string(Weapon_title_coords[gr_screen.res][0], Weapon_title_coords[gr_screen.res][1], EG_WEAPON_TITLE, XSTR( "weapons", 328));
4746 // draw bottom of border
4747 GR_AABITMAP(Weapon_gauges[2].first_frame, Weapon_gauge_primary_coords[gr_screen.res][1][0], Weapon_gauge_primary_coords[gr_screen.res][1][1]);
4749 emp_hud_string(Weapon_pname_coords[gr_screen.res][0][0], Weapon_pname_coords[gr_screen.res][0][1], EG_WEAPON_P1, XSTR( "<none>", 329));
4755 // draw bottom of border
4756 GR_AABITMAP(Weapon_gauges[2].first_frame, Weapon_gauge_primary_coords[gr_screen.res][1][0], Weapon_gauge_primary_coords[gr_screen.res][1][1]);
4758 strcpy(name, Weapon_info[sw->primary_bank_weapons[0]].name);
4760 lcl_translate_wep_name(name);
4763 // maybe modify name here to fit
4764 if ( hud_gauge_maybe_flash(HUD_WEAPONS_GAUGE) == 1 ) {
4765 // hud_set_bright_color();
4766 hud_set_gauge_color(HUD_WEAPONS_GAUGE, HUD_C_BRIGHT);
4768 hud_maybe_flash_weapon(0);
4771 emp_hud_printf(Weapon_plink_coords[gr_screen.res][0][0], Weapon_plink_coords[gr_screen.res][0][1], EG_NULL, "%c", Lcl_special_chars + 2);
4772 emp_hud_printf(Weapon_pname_coords[gr_screen.res][0][0], Weapon_pname_coords[gr_screen.res][0][1], EG_WEAPON_P2, "%s", name);
4776 // draw border to accomodate second primary weapon
4777 GR_AABITMAP(Weapon_gauges[1].first_frame, Weapon_gauge_primary_coords[gr_screen.res][1][0], Weapon_gauge_primary_coords[gr_screen.res][1][1]);
4779 // draw bottom of border
4780 GR_AABITMAP(Weapon_gauges[2].first_frame, Weapon_gauge_primary_coords[gr_screen.res][2][0], Weapon_gauge_primary_coords[gr_screen.res][2][1]);
4782 strcpy(name, Weapon_info[sw->primary_bank_weapons[0]].name);
4784 lcl_translate_wep_name(name);
4786 // maybe modify name here to fit
4788 if ( hud_gauge_maybe_flash(HUD_WEAPONS_GAUGE) == 1 ) {
4789 // hud_set_bright_color();
4790 hud_set_gauge_color(HUD_WEAPONS_GAUGE, HUD_C_BRIGHT);
4792 hud_maybe_flash_weapon(0);
4794 if ( (sw->current_primary_bank == 0) || (Player_ship->flags & SF_PRIMARY_LINKED) ) {
4795 emp_hud_printf(Weapon_plink_coords[gr_screen.res][0][0], Weapon_plink_coords[gr_screen.res][0][1], EG_NULL, "%c", Lcl_special_chars + 2);
4797 emp_hud_printf(Weapon_pname_coords[gr_screen.res][0][0], Weapon_pname_coords[gr_screen.res][0][1], EG_WEAPON_P1, "%s", name);
4799 strcpy(name, Weapon_info[sw->primary_bank_weapons[1]].name);
4801 lcl_translate_wep_name(name);
4803 // maybe modify name here to fit
4804 if ( hud_gauge_maybe_flash(HUD_WEAPONS_GAUGE) == 1 ) {
4805 // hud_set_bright_color();
4806 hud_set_gauge_color(HUD_WEAPONS_GAUGE, HUD_C_BRIGHT);
4808 hud_maybe_flash_weapon(1);
4810 if ( sw->current_primary_bank == 1 || (Player_ship->flags & SF_PRIMARY_LINKED) ) {
4811 emp_hud_printf(Weapon_plink_coords[gr_screen.res][1][0], Weapon_plink_coords[gr_screen.res][1][1], EG_NULL, "%c", Lcl_special_chars + 2);
4813 emp_hud_printf(Weapon_pname_coords[gr_screen.res][1][0], Weapon_pname_coords[gr_screen.res][1][1], EG_WEAPON_P2, "%s", name);
4818 Int3(); // can't happen - get Alan
4823 hud_set_gauge_color(HUD_WEAPONS_GAUGE);
4827 // draw the bottom of the secondary weapons
4828 GR_AABITMAP(Weapon_gauges[4].first_frame, Weapon_gauge_secondary_coords[gr_screen.res][0][0], Weapon_gauge_secondary_coords[gr_screen.res][0][1] - 12*np - 1);
4830 emp_hud_string(Weapon_pname_coords[gr_screen.res][0][0], Weapon_secondary_y[gr_screen.res][0] - np*12, EG_WEAPON_S1, XSTR( "<none>", 329));
4834 // draw the bottom of the secondary weapons
4835 GR_AABITMAP(Weapon_gauges[4].first_frame, Weapon_gauge_secondary_coords[gr_screen.res][1][0], Weapon_gauge_secondary_coords[gr_screen.res][1][1] - 12*np - 1);
4837 hud_show_secondary_weapon(1, sw, Player_ship->flags & SF_SECONDARY_DUAL_FIRE);
4841 // draw the middle border, only present when there are 2 or more secondaries
4842 GR_AABITMAP(Weapon_gauges[3].first_frame, Weapon_gauge_secondary_coords[gr_screen.res][2][0], Weapon_gauge_secondary_coords[gr_screen.res][2][1] - np*12);
4844 // draw the bottom of the secondary weapons
4845 GR_AABITMAP(Weapon_gauges[4].first_frame, Weapon_gauge_secondary_coords[gr_screen.res][3][0], Weapon_gauge_secondary_coords[gr_screen.res][3][1] - 12*np);
4847 hud_show_secondary_weapon(2, sw, Player_ship->flags & SF_SECONDARY_DUAL_FIRE);
4851 // draw the middle border, only present when there are 2 or more secondaries
4852 GR_AABITMAP(Weapon_gauges[3].first_frame, Weapon_gauge_secondary_coords[gr_screen.res][2][0], Weapon_gauge_secondary_coords[gr_screen.res][2][1] - np*12);
4854 // draw the bottm border, only present when there are 3 secondaries
4855 GR_AABITMAP(Weapon_gauges[3].first_frame, Weapon_gauge_secondary_coords[gr_screen.res][3][0], Weapon_gauge_secondary_coords[gr_screen.res][3][1] - np*12);
4857 // draw the bottom of the secondary weapons
4858 GR_AABITMAP(Weapon_gauges[4].first_frame, Weapon_gauge_secondary_coords[gr_screen.res][4][0], Weapon_gauge_secondary_coords[gr_screen.res][4][1] - 12*np);
4860 hud_show_secondary_weapon(3, sw, Player_ship->flags & SF_SECONDARY_DUAL_FIRE);
4864 Int3(); // can't happen - get Alan
4870 // check if targeting is possible based on sensors strength
4871 int hud_sensors_ok(ship *sp, int show_msg)
4875 // If playing on lowest skill level, sensors don't affect targeting
4876 // If dead, still allow player to target, despite any subsystem damage
4877 // If i'm a multiplayer observer, allow me to target
4878 if ( (Game_skill_level == 0) || (Game_mode & GM_DEAD) || ((Game_mode & GM_MULTIPLAYER) && (Net_player->flags & NETINFO_FLAG_OBSERVER)) ) {
4882 // if the ship is currently being affected by EMP
4883 if(emp_active_local()){
4887 // ensure targeting functions are not disabled through damage
4888 sensors_str = ship_get_subsystem_strength( sp, SUBSYSTEM_SENSORS );
4889 if ( (sensors_str < MIN_SENSOR_STR_TO_TARGET) || (ship_subsys_disrupted(sp, SUBSYSTEM_SENSORS)) ) {
4891 HUD_sourced_printf(HUD_SOURCE_HIDDEN, XSTR( "Targeting is disabled due to sensors damage", 330));
4892 snd_play(&Snds[SND_TARGET_FAIL]);
4900 int hud_communications_state(ship *sp, int show_msg)
4903 int comm_state = COMM_OK;
4905 // If playing on the lowest skill level, communications always ok
4906 // If dead, still allow player to communicate, despite any subsystem damage
4907 if ( Game_skill_level == 0 || (Game_mode & GM_DEAD) ) {
4911 str = ship_get_subsystem_strength( sp, SUBSYSTEM_COMMUNICATION );
4912 // str = 1.0f; // DEBUG CODE! MK, change, 11/12/97, comm system could be taken out by one laser, too frustrating.
4913 // Change this back when comm systems have been better placed.
4915 if ( (str <= 0.01) || ship_subsys_disrupted(sp, SUBSYSTEM_COMMUNICATION) ) {
4917 HUD_sourced_printf(HUD_SOURCE_HIDDEN, XSTR( "Messaging is restricted due to communications damage", 331));
4919 comm_state = COMM_DESTROYED;
4920 } else if ( str < MIN_COMM_STR_TO_MESSAGE ) {
4921 comm_state = COMM_DAMAGED;
4927 // target the next or previous hostile/friendly ship
4928 void hud_target_next_list(int hostile, int next_flag)
4930 object *A, *min_obj, *max_obj, *nearest_obj;
4933 // vector target_vec;
4934 float cur_dist, min_dist, max_dist, new_dist, nearest_dist, diff;
4935 int timestamp_val, valid_team;
4938 timestamp_val = Tl_hostile_reset_timestamp;
4939 Tl_hostile_reset_timestamp = timestamp(TL_RESET);
4940 valid_team = opposing_team_mask(Player_ship->team);
4942 timestamp_val = Tl_friendly_reset_timestamp;
4943 Tl_friendly_reset_timestamp = timestamp(TL_RESET);
4944 valid_team = Player_ship->team;
4947 // If no target is selected, then simply target the closest ship
4948 if ( Player_ai->target_objnum == -1 || timestamp_elapsed(timestamp_val) ) {
4949 hud_target_closest(valid_team);
4953 cur_dist = hud_find_target_distance(&Objects[Player_ai->target_objnum],Player_obj);
4955 min_obj = max_obj = nearest_obj = NULL;
4959 nearest_dist = 1e20f;
4961 nearest_dist = 0.0f;
4964 for ( so = GET_FIRST(&Ship_obj_list); so != END_OF_LIST(&Ship_obj_list); so = GET_NEXT(so) ) {
4965 A = &Objects[so->objnum];
4966 shipp = &Ships[A->instance]; // get a pointer to the ship information
4968 if ( (A == Player_obj) || (shipp->flags & TARGET_SHIP_IGNORE_FLAGS) )
4971 // choose from the correct team
4972 if ( !hud_team_matches_filter(valid_team, shipp->team) ) {
4973 // if we're in multiplayer dogfight, ignore this
4974 if(!((Game_mode & GM_MULTIPLAYER) && (Netgame.type_flags & NG_TYPE_DOGFIGHT))){
4979 // always ignore navbuoys and cargo
4980 if ( Ship_info[shipp->ship_info_index].flags & (SIF_CARGO | SIF_NAVBUOY) ) {
4984 // don't use object if it is already a target
4985 if ( OBJ_INDEX(A) == Player_ai->target_objnum ) {
4989 if(hud_target_invalid_awacs(A)){
4993 new_dist = hud_find_target_distance(A,Player_obj);
4995 if (new_dist <= min_dist) {
4996 min_dist = new_dist;
5000 if (new_dist >= max_dist) {
5001 max_dist = new_dist;
5006 diff = new_dist - cur_dist;
5008 if ( diff < ( nearest_dist - cur_dist ) ) {
5009 nearest_dist = new_dist;
5014 diff = cur_dist - new_dist;
5016 if ( diff < ( cur_dist - nearest_dist ) ) {
5017 nearest_dist = new_dist;
5024 if ( nearest_obj == NULL ) {
5027 if ( min_obj != NULL ) {
5028 nearest_obj = min_obj;
5031 if ( max_obj != NULL ) {
5032 nearest_obj = max_obj;
5037 if (nearest_obj != NULL) {
5039 set_target_objnum( Player_ai, OBJ_INDEX(nearest_obj) );
5041 // maybe set new turret subsystem
5042 hud_maybe_set_sorted_turret_subsys(&Ships[nearest_obj->instance]);
5043 hud_restore_subsystem_target(&Ships[nearest_obj->instance]);
5046 snd_play( &Snds[SND_TARGET_FAIL], 0.0f );
5050 // draw auto-target icon
5051 void hud_auto_target_icon()
5055 if ( Players[Player_num].flags & PLAYER_FLAGS_AUTO_TARGETING ) {
5061 // draw the box background
5062 hud_set_gauge_color(HUD_AUTO_TARGET);
5063 GR_AABITMAP(Toggle_gauge.first_frame+frame_offset, Toggle_target_gauge_coords[gr_screen.res][0], Toggle_target_gauge_coords[gr_screen.res][1]);
5065 // draw the text on top
5066 if (frame_offset == 1) {
5068 gr_init_alphacolor(&text_color, 0, 0, 0, Toggle_text_alpha);
5069 gr_set_color_fast(&text_color);
5072 gr_string(Hud_toggle_coords[gr_screen.res][TOGGLE_TEXT_AUTOT][0], Hud_toggle_coords[gr_screen.res][TOGGLE_TEXT_AUTOT][1], XSTR("auto", 1463));
5073 gr_string(Hud_toggle_coords[gr_screen.res][TOGGLE_TEXT_TARGET][0], Hud_toggle_coords[gr_screen.res][TOGGLE_TEXT_TARGET][1], XSTR("target", 1465));
5076 // draw auto-speed match icon
5077 void hud_auto_speed_match_icon()
5081 if ( Players[Player_num].flags & PLAYER_FLAGS_AUTO_MATCH_SPEED ) {
5087 hud_set_gauge_color(HUD_AUTO_SPEED);
5089 GR_AABITMAP(Toggle_gauge.first_frame+frame_offset, Toggle_speed_gauge_coords[gr_screen.res][0], Toggle_speed_gauge_coords[gr_screen.res][1]);
5091 // draw the text on top
5092 if (frame_offset == 3) {
5094 gr_init_alphacolor(&text_color, 0, 0, 0, Toggle_text_alpha);
5095 gr_set_color_fast(&text_color);
5097 gr_string(Hud_toggle_coords[gr_screen.res][TOGGLE_TEXT_AUTOS][0], Hud_toggle_coords[gr_screen.res][TOGGLE_TEXT_AUTOS][1], XSTR("auto", 1463));
5098 gr_string(Hud_toggle_coords[gr_screen.res][TOGGLE_TEXT_SPEED][0], Hud_toggle_coords[gr_screen.res][TOGGLE_TEXT_SPEED][1], XSTR("speed", 1464));
5101 // display the auto-targeting and auto-speed-matching icons on the HUD
5102 void hud_show_auto_icons()
5105 if ( Toggle_gauge.first_frame == -1 )
5108 // display auto target icon
5109 if ( hud_gauge_active(HUD_AUTO_TARGET) ) {
5111 // is gauge configured as a popup?
5112 if ( hud_gauge_is_popup(HUD_AUTO_TARGET) ) {
5113 if ( !hud_gauge_popup_active(HUD_AUTO_TARGET) ) {
5119 hud_auto_target_icon();
5123 // display auto speed match icon
5124 if ( hud_gauge_active(HUD_AUTO_SPEED) ) {
5126 // is gauge configured as a popup?
5127 if ( hud_gauge_is_popup(HUD_AUTO_SPEED) ) {
5128 if ( !hud_gauge_popup_active(HUD_AUTO_SPEED) ) {
5134 hud_auto_speed_match_icon();
5139 // Set the player target to the closest friendly repair ship
5140 // input: goal_objnum => Try to find repair ship where aip->goal_objnum matches this
5141 // output: 1 => A repair ship was targeted
5142 // 0 => No targeting change
5143 int hud_target_closest_repair_ship(int goal_objnum)
5146 object *nearest_obj=&obj_used_list;
5149 float min_distance=1e20f;
5150 float new_distance=0.0f;
5153 for ( so = GET_FIRST(&Ship_obj_list); so != END_OF_LIST(&Ship_obj_list); so = GET_NEXT(so) ) {
5154 A = &Objects[so->objnum];
5155 shipp = &Ships[A->instance]; // get a pointer to the ship information
5157 // ignore all ships that aren't repair ships
5158 if ( !(Ship_info[shipp->ship_info_index].flags & SIF_SUPPORT) ) {
5162 if ( (A == Player_obj) || (shipp->flags & TARGET_SHIP_IGNORE_FLAGS) )
5165 // only consider friendly ships
5166 if ( !hud_team_matches_filter(Player_ship->team, shipp->team)) {
5167 // if we're in multiplayer dogfight, ignore this
5168 if(!((Game_mode & GM_MULTIPLAYER) && (Netgame.type_flags & NG_TYPE_DOGFIGHT))){
5173 if(hud_target_invalid_awacs(A)){
5177 if ( goal_objnum >= 0 ) {
5178 if ( Ai_info[shipp->ai_index].goal_objnum != goal_objnum ) {
5183 new_distance = hud_find_target_distance(A,Player_obj);
5185 if (new_distance <= min_distance) {
5186 min_distance=new_distance;
5191 if (nearest_obj != &obj_used_list) {
5192 set_target_objnum( Player_ai, OBJ_INDEX(nearest_obj) );
5193 hud_restore_subsystem_target(&Ships[nearest_obj->instance]);
5197 // inform player how to get a support ship
5198 if ( goal_objnum == -1 ) {
5199 HUD_sourced_printf(HUD_SOURCE_HIDDEN, XSTR( "No support ships in area. Use messaging to call one in.", 332));
5207 void hud_target_toggle_hidden_from_sensors()
5209 if ( TARGET_SHIP_IGNORE_FLAGS & SF_HIDDEN_FROM_SENSORS ) {
5210 TARGET_SHIP_IGNORE_FLAGS &= ~SF_HIDDEN_FROM_SENSORS;
5211 HUD_sourced_printf(HUD_SOURCE_HIDDEN, NOX("Target hiding from sensors disabled"));
5213 TARGET_SHIP_IGNORE_FLAGS |= SF_HIDDEN_FROM_SENSORS;
5214 HUD_sourced_printf(HUD_SOURCE_HIDDEN, NOX("Target hiding from sensors enabled"));
5218 // target the closest uninspected object
5219 void hud_target_closest_uninspected_object()
5221 object *A, *nearest_obj = NULL;
5224 float min_distance = 1e20f;
5225 float new_distance = 0.0f;
5227 for ( so = GET_FIRST(&Ship_obj_list); so != END_OF_LIST(&Ship_obj_list); so = GET_NEXT(so) ) {
5229 A = &Objects[so->objnum];
5230 shipp = &Ships[A->instance]; // get a pointer to the ship information
5232 if ( (A == Player_obj) || (shipp->flags & TARGET_SHIP_IGNORE_FLAGS) ){
5236 if(hud_target_invalid_awacs(A)){
5240 // ignore all non-cargo carrying craft
5241 if ( !hud_target_ship_can_be_scanned(shipp) ) {
5245 new_distance = hud_find_target_distance(A,Player_obj);
5247 if (new_distance <= min_distance) {
5248 min_distance=new_distance;
5253 if (nearest_obj != NULL) {
5254 set_target_objnum( Player_ai, OBJ_INDEX(nearest_obj) );
5255 hud_restore_subsystem_target(&Ships[nearest_obj->instance]);
5258 snd_play( &Snds[SND_TARGET_FAIL] );
5262 // target the next or previous uninspected/unscanned object
5263 void hud_target_uninspected_object(int next_flag)
5265 object *A, *min_obj, *max_obj, *nearest_obj;
5268 float cur_dist, min_dist, max_dist, new_dist, nearest_dist, diff;
5270 // If no target is selected, then simply target the closest uninspected cargo
5271 if ( Player_ai->target_objnum == -1 || timestamp_elapsed(Target_next_uninspected_object_timestamp) ) {
5272 Target_next_uninspected_object_timestamp = timestamp(TL_RESET);
5273 hud_target_closest_uninspected_object();
5277 Target_next_uninspected_object_timestamp = timestamp(TL_RESET);
5279 cur_dist = hud_find_target_distance(&Objects[Player_ai->target_objnum], Player_obj);
5281 min_obj = max_obj = nearest_obj = NULL;
5285 nearest_dist = 1e20f;
5287 nearest_dist = 0.0f;
5290 for ( so = GET_FIRST(&Ship_obj_list); so != END_OF_LIST(&Ship_obj_list); so = GET_NEXT(so) ) {
5291 A = &Objects[so->objnum];
5292 shipp = &Ships[A->instance]; // get a pointer to the ship information
5294 if ( (A == Player_obj) || (shipp->flags & TARGET_SHIP_IGNORE_FLAGS) )
5297 // ignore all non-cargo carrying craft
5298 if ( !hud_target_ship_can_be_scanned(shipp) ) {
5302 // don't use object if it is already a target
5303 if ( OBJ_INDEX(A) == Player_ai->target_objnum ) {
5307 if(hud_target_invalid_awacs(A)){
5311 new_dist = hud_find_target_distance(A, Player_obj);
5313 if (new_dist <= min_dist) {
5314 min_dist = new_dist;
5318 if (new_dist >= max_dist) {
5319 max_dist = new_dist;
5324 diff = new_dist - cur_dist;
5326 if ( diff < ( nearest_dist - cur_dist ) ) {
5327 nearest_dist = new_dist;
5332 diff = cur_dist - new_dist;
5334 if ( diff < ( cur_dist - nearest_dist ) ) {
5335 nearest_dist = new_dist;
5342 if ( nearest_obj == NULL ) {
5345 if ( min_obj != NULL ) {
5346 nearest_obj = min_obj;
5349 if ( max_obj != NULL ) {
5350 nearest_obj = max_obj;
5355 if (nearest_obj != NULL) {
5356 set_target_objnum( Player_ai, OBJ_INDEX(nearest_obj) );
5357 hud_restore_subsystem_target(&Ships[nearest_obj->instance]);
5360 snd_play( &Snds[SND_TARGET_FAIL] );
5364 // ----------------------------------------------------------------
5366 // Target Last Transmission Sender code START
5368 // ----------------------------------------------------------------
5370 typedef struct transmit_target
5376 static int Transmit_target_next_slot = 0;
5377 static int Transmit_target_current_slot = -1;
5378 static int Transmit_target_reset_timer = timestamp(0);
5380 #define MAX_TRANSMIT_TARGETS 10
5381 static transmit_target Transmit_target_list[MAX_TRANSMIT_TARGETS];
5383 // called once per level to initialize the target last transmission sender list
5384 void hud_target_last_transmit_level_init()
5388 for ( i = 0; i < MAX_TRANSMIT_TARGETS; i++ ) {
5389 Transmit_target_list[i].objnum = -1;
5390 Transmit_target_list[i].objsig = -1;
5393 Transmit_target_next_slot = 0;
5394 Transmit_target_current_slot = 0;
5395 Transmit_target_reset_timer = timestamp(0);
5398 // internal function only.. used to find index for last recorded ship transmission
5399 int hud_target_last_transmit_newest()
5403 latest_slot = Transmit_target_next_slot - 1;
5404 if ( latest_slot < 0 ) {
5405 latest_slot = MAX_TRANSMIT_TARGETS - 1;
5411 // called externally to set the player target to the last ship which sent a tranmission to the player
5412 void hud_target_last_transmit()
5416 if ( Transmit_target_current_slot < 0 ) {
5417 Transmit_target_current_slot = hud_target_last_transmit_newest();
5420 // If timed out, then simply target the last ship to transmit
5421 if ( timestamp_elapsed(Transmit_target_reset_timer) ) {
5422 Transmit_target_current_slot = hud_target_last_transmit_newest();
5425 Transmit_target_reset_timer = timestamp(TL_RESET);
5427 int play_fail_sound = 1;
5428 int transmit_index = Transmit_target_current_slot;
5429 Assert(transmit_index >= 0);
5430 for ( i = 0; i < MAX_TRANSMIT_TARGETS; i++ ) {
5431 if ( Transmit_target_list[transmit_index].objnum >= 0 ) {
5432 int transmit_objnum = Transmit_target_list[transmit_index].objnum;
5434 if ( Player_ai->target_objnum == transmit_objnum ) {
5435 play_fail_sound = 0;
5437 if ( Transmit_target_list[transmit_index].objsig == Objects[Transmit_target_list[transmit_index].objnum].signature ) {
5438 if ( !(Ships[Objects[transmit_objnum].instance].flags & TARGET_SHIP_IGNORE_FLAGS) ) {
5439 Transmit_target_current_slot = transmit_index-1;
5440 if ( Transmit_target_current_slot < 0 ) {
5441 Transmit_target_current_slot = MAX_TRANSMIT_TARGETS - 1;
5450 if ( transmit_index < 0 ) {
5451 transmit_index = MAX_TRANSMIT_TARGETS - 1;
5455 if ( i == MAX_TRANSMIT_TARGETS ) {
5456 if ( play_fail_sound ) {
5457 snd_play( &Snds[SND_TARGET_FAIL] );
5459 Transmit_target_current_slot = -1;
5463 if(hud_target_invalid_awacs(&Objects[Transmit_target_list[transmit_index].objnum])){
5468 // Fix bug in targeting due to Alt-Y (target last ship sending transmission).
5469 // Was just bogus code in the call to hud_restore_subsystem_target(). -- MK, 9/15/99, 1:59 pm.
5470 int targeted_objnum;
5471 targeted_objnum = Transmit_target_list[transmit_index].objnum;
5472 Assert((targeted_objnum >= 0) && (targeted_objnum < MAX_OBJECTS));
5474 if ((targeted_objnum >= 0) && (targeted_objnum < MAX_OBJECTS)) {
5475 set_target_objnum( Player_ai, Transmit_target_list[transmit_index].objnum );
5476 hud_restore_subsystem_target(&Ships[Objects[Transmit_target_list[transmit_index].objnum].instance]);
5480 // called externally to add a message sender to the list
5481 void hud_target_last_transmit_add(int ship_num)
5486 ship_objnum = Ships[ship_num].objnum;
5487 Assert(ship_objnum >= 0 && ship_objnum < MAX_OBJECTS);
5488 ship_objp = &Objects[ship_objnum];
5489 Assert(ship_objp->type == OBJ_SHIP);
5491 Transmit_target_list[Transmit_target_next_slot].objnum = ship_objnum;
5492 Transmit_target_list[Transmit_target_next_slot].objsig = ship_objp->signature;
5493 Transmit_target_next_slot++;
5494 if ( Transmit_target_next_slot >= MAX_TRANSMIT_TARGETS ) {
5495 Transmit_target_next_slot = 0;
5499 // target a random ship (useful for EMP stuff)
5500 void hud_target_random_ship()
5505 shipnum = ship_get_random_ship();
5506 if((shipnum < 0) || (Ships[shipnum].objnum < 0)){
5509 objnum = Ships[shipnum].objnum;
5511 if((objnum >= 0) && (Player_ai != NULL) && !hud_target_invalid_awacs(&Objects[objnum])){
5512 // never target yourself
5513 if(objnum == OBJ_INDEX(Player_obj)){
5514 set_target_objnum(Player_ai, -1);
5516 set_target_objnum(Player_ai, objnum);
5521 // ----------------------------------------------------------------
5523 // Target Last Transmission Sender code END
5525 // ----------------------------------------------------------------
5527 void hudtarget_page_in()
5531 for ( i = 0; i < NUM_WEAPON_GAUGES; i++ ) {
5532 bm_page_in_aabitmap( Weapon_gauges[i].first_frame, Weapon_gauges[i].num_frames);
5534 bm_page_in_aabitmap( Lead_indicator_gauge.first_frame, Lead_indicator_gauge.num_frames);
5535 bm_page_in_aabitmap( Energy_bar_gauges.first_frame, Energy_bar_gauges.num_frames);
5536 bm_page_in_aabitmap( Toggle_gauge.first_frame, Toggle_gauge.num_frames);
5537 bm_page_in_aabitmap( Cmeasure_gauge.first_frame, Cmeasure_gauge.num_frames);