2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
4 * All source code herein is the property of Volition, Inc. You may not sell
5 * or otherwise commercially exploit the source or things you created based on
10 * $Logfile: /Freespace2/code/Hud/HUDtargetbox.cpp $
15 * C module for drawing the target monitor box on the HUD
18 * Revision 1.7 2003/06/03 04:00:40 taylor
19 * Polish language support (Janusz Dziemidowicz)
21 * Revision 1.6 2003/05/25 02:30:42 taylor
24 * Revision 1.5 2002/06/18 08:58:53 relnev
25 * last few struct changes
27 * Revision 1.4 2002/06/17 06:33:09 relnev
28 * ryan's struct patch for gcc 2.95
30 * Revision 1.3 2002/06/09 04:41:21 relnev
31 * added copyright header
33 * Revision 1.2 2002/05/07 03:16:45 theoddone33
34 * The Great Newline Fix
36 * Revision 1.1.1.1 2002/05/03 03:28:09 root
40 * 31 11/02/99 3:22p Jefff
41 * translation of targetbox text
43 * 30 10/29/99 10:41p Jefff
44 * more subsystem fixes
46 * 29 10/28/99 11:17p Jefff
47 * used escape seqs for some special German chars
49 * 28 10/28/99 2:02a Jefff
50 * revised the subsystem localization
52 * 27 9/14/99 11:03p Jefff
53 * dont draw target names from # on (weapons case)
55 * 26 9/04/99 5:17p Andsager
56 * Make event log record name of destroyed subsytem, and use this name for
57 * different types of turrets
59 * 25 8/25/99 11:35a Andsager
60 * Move hud render ship subsystem target box for ships with Autocenter
62 * 24 8/17/99 7:32p Jefff
63 * models use autocenter in target view
65 * 23 8/01/99 12:39p Dave
66 * Added HUD contrast control key (for nebula).
68 * 22 7/31/99 4:15p Dave
69 * Fixed supernova particle velocities. Handle OBJ_NONE in target
70 * monitoring view. Properly use objectives notify gauge colors.
72 * 21 7/28/99 2:49p Andsager
73 * Make hud target speed use vm_vec_mag (not vm_vec_mag_quick)
75 * 20 7/15/99 9:20a Andsager
76 * FS2_DEMO initial checkin
78 * 19 7/02/99 10:56a Andsager
79 * Put in big ship - big ship attack mode. Modify stealth sweep ai.
81 * 18 6/29/99 3:16p Andsager
84 * 17 6/10/99 3:43p Dave
85 * Do a better job of syncing text colors to HUD gauges.
87 * 16 6/09/99 2:55p Andsager
88 * Allow multiple asteroid subtypes (of large, medium, small) and follow
91 * 15 6/07/99 4:20p Andsager
92 * Add HUD color for tagged object. Apply to target and radar.
94 * 14 6/03/99 11:43a Dave
95 * Added the ability to use a different model when rendering to the HUD
98 * 13 5/24/99 9:02a Andsager
99 * Remove Int3() in turret subsys name code when turret has no weapon.
101 * 12 5/21/99 1:42p Andsager
102 * Added error checking for HUD turret name
104 * 11 5/20/99 7:00p Dave
105 * Added alternate type names for ships. Changed swarm missile table
108 * 10 5/19/99 3:50p Andsager
109 * Show type of debris is debris field (species debris or asteroid). Show
110 * type of subsystem turret targeted (laser, missile, flak, beam).
112 * 9 5/14/99 4:22p Andsager
113 * Modify hud_render_target_ship to show damaged subsystems in their
114 * actual state. Now also shows rotation of subsystems.
116 * 8 4/16/99 5:54p Dave
117 * Support for on/off style "stream" weapons. Real early support for
118 * target-painting lasers.
120 * 7 1/07/99 9:08a Jasen
123 * 6 12/28/98 3:17p Dave
124 * Support for multiple hud bitmap filenames for hi-res mode.
126 * 5 12/21/98 5:03p Dave
127 * Modified all hud elements to be multi-resolution friendly.
129 * 4 11/05/98 4:18p Dave
130 * First run nebula support. Beefed up localization a bit. Removed all
131 * conditional compiles for foreign versions. Modified mission file
134 * 3 10/13/98 9:28a Dave
135 * Started neatening up freespace.h. Many variables renamed and
136 * reorganized. Added AlphaColors.[h,cpp]
138 * 2 10/07/98 10:53a Dave
141 * 1 10/07/98 10:49a Dave
143 * 108 8/28/98 3:28p Dave
144 * EMP effect done. AI effects may need some tweaking as required.
146 * 107 8/25/98 1:48p Dave
147 * First rev of EMP effect. Player side stuff basically done. Next comes
150 * 106 6/19/98 3:49p Lawrance
151 * localization tweaks
153 * 105 6/17/98 11:04a Lawrance
154 * localize subsystem names that appear on the HUD
156 * 104 6/09/98 5:18p Lawrance
157 * French/German localization
159 * 103 6/09/98 10:31a Hoffoss
160 * Created index numbers for all xstr() references. Any new xstr() stuff
161 * added from here on out should be added to the end if the list. The
162 * current list count can be found in FreeSpace.cpp (search for
165 * 102 6/01/98 11:43a John
166 * JAS & MK: Classified all strings for localization.
168 * 101 5/20/98 3:52p Allender
169 * fixed compiler warnings
171 * 100 5/20/98 12:59p John
172 * Turned optimizations on for debug builds. Also turning on automatic
173 * function inlining. Turned off the unreachable code warning.
175 * 99 5/15/98 8:36p Lawrance
176 * Add 'target ship that last sent transmission' target key
178 * 98 5/14/98 11:26a Lawrance
179 * ensure fighter bays are drawn with correct bracket color
181 * 97 5/08/98 5:32p Lawrance
182 * Allow cargo scanning even if target gauge is disabled
184 * 96 5/04/98 10:51p Lawrance
185 * remove unused local
187 * 95 5/04/98 9:17p Lawrance
188 * Truncate ship class names at # char when displaying debris on target
191 * 94 5/04/98 6:12p Lawrance
192 * Write generic function hud_end_string_at_first_hash_symbol(), to use in
193 * various spots on the HUD
195 * 93 4/15/98 12:55a Lawrance
196 * Show time to impact for bombs
198 * 92 4/02/98 6:31p Lawrance
199 * remove asteroid references if DEMO defined
201 * 91 3/31/98 5:18p John
202 * Removed demo/save/restore. Made NDEBUG defined compile. Removed a
203 * bunch of debug stuff out of player file. Made model code be able to
204 * unload models and malloc out only however many models are needed.
207 * 90 3/30/98 1:08a Lawrance
208 * Implement "blast" icon. Blink HUD icon when player ship is hit by a
216 #include "3dinternal.h"
219 #include "hudtarget.h"
220 #include "hudbrackets.h"
223 #include "missionparse.h"
228 #include "freespace.h"
231 #include "subsysdamage.h"
232 #include "hudtargetbox.h"
234 #include "asteroid.h"
235 #include "jumpnode.h"
238 #include "localize.h"
240 int Target_window_coords[GR_NUM_RESOLUTIONS][4] =
250 object *Enemy_attacker = NULL;
252 static int Target_static_next;
253 static int Target_static_playing;
254 int Target_static_looping;
257 extern int Show_target_debug_info;
258 extern int Show_target_weapons;
261 // used to print out + or - after target distance and speed
262 char* modifiers[] = {
270 char Target_view_fname[GR_NUM_RESOLUTIONS][MAX_FILENAME_LEN] = {
274 char Target_integ_fname[GR_NUM_RESOLUTIONS][MAX_FILENAME_LEN] = {
278 char Target_extra_fname[GR_NUM_RESOLUTIONS][MAX_FILENAME_LEN] = {
283 // animation frames for the target view monitor
284 // frames: 0 => background of target monitor
285 // 1 => foreground of target monitor
286 hud_frames Target_view_gauge;
287 int Target_view_gauge_loaded = 0;
289 // animation frames for the extended target information
290 // frames: 0 => normal gague
291 hud_frames Target_view_extra;
292 int Target_view_extra_loaded = 0;
294 // animation frames for the target view monitor integrity bar
295 // frames: 0 => dark bar
297 hud_frames Target_view_integrity_gauge;
298 int Target_view_integrity_gauge_loaded = 0;
300 #define NUM_TBOX_COORDS 11 // keep up to date
301 #define TBOX_BACKGROUND 0
309 #define TBOX_EXTRA_ORDERS 8
310 #define TBOX_EXTRA_TIME 9
311 #define TBOX_EXTRA_DOCK 10
313 int Targetbox_coords[GR_NUM_RESOLUTIONS][NUM_TBOX_COORDS][2] =
343 int Integrity_bar_coords[GR_NUM_RESOLUTIONS][4] = {
351 int Integrity_string_coords[GR_NUM_RESOLUTIONS][2] = {
360 // cargo scanning extents
361 int Cargo_scan_coords[GR_NUM_RESOLUTIONS][4] = {
370 // first element is time flashing expires, second element is time of next flash
371 int Targetbox_flash_timers[NUM_TBOX_FLASH_TIMERS][2];
372 int Targetbox_flash_flags;
374 // flag to indicate whether to show the extra information about a target
375 // The HUD_config controls whether this can be shown... but the player can still toggle it on/off
377 int Targetbox_show_extra_info = 1;
379 // Different target states. This drives the text display right below the hull integrity on the targetbox.
385 static int Last_ts; // holds last target status.
387 void hud_blit_target_integrity(int disabled,int force_obj_num = -1);
389 // cut down long subsystem names to a more manageable length
390 char *hud_targetbox_truncate_subsys_name(char *outstr)
393 if ( strstr(outstr, "communication") ) {
394 strcpy(outstr, "Komm");
395 } else if ( !stricmp(outstr, "weapons") ) {
396 strcpy(outstr, "Waffen");
397 } else if ( strstr(outstr, "engine") || strstr(outstr, "Engine")) {
398 strcpy(outstr, "Antrieb");
399 } else if ( !stricmp(outstr, "sensors") ) {
400 strcpy(outstr, "Sensoren");
401 } else if ( strstr(outstr, "navigat") ) {
402 strcpy(outstr, "Nav");
403 } else if ( strstr(outstr, "fighterbay") || strstr(outstr, "Fighterbay") ) {
404 strcpy(outstr, "J\x84gerhangar");
405 } else if ( strstr(outstr, "missile") ) {
406 strcpy(outstr, "Raketenwerfer");
407 } else if ( strstr(outstr, "laser") || strstr(outstr, "turret") ) {
408 strcpy(outstr, "Gesch\x81tzturm");
409 } else if ( strstr(outstr, "Command Tower") || strstr(outstr, "Bridge") ) {
410 strcpy(outstr, "Br\x81""cke");
411 } else if ( strstr(outstr, "Barracks") ) {
412 strcpy(outstr, "Quartiere");
413 } else if ( strstr(outstr, "Reactor") ) {
414 strcpy(outstr, "Reaktor");
415 } else if ( strstr(outstr, "RadarDish") ) {
416 strcpy(outstr, "Radarantenne");
417 } else if (!stricmp(outstr, "Gas Collector")) {
418 strcpy(outstr, "Sammler");
421 if ( strstr(outstr, "communication") ) {
422 strcpy(outstr, "comm");
423 } else if ( !stricmp(outstr, "weapons") ) {
424 strcpy(outstr, "armes");
425 } else if ( strstr(outstr, "engine") ) {
426 strcpy(outstr, "moteur");
427 } else if ( !stricmp(outstr, "sensors") ) {
428 strcpy(outstr, "detecteurs");
429 } else if ( strstr(outstr, "navi") ) {
430 strcpy(outstr, "nav");
431 } else if ( strstr(outstr, "missile") ) {
432 strcpy(outstr, "lanceur de missiles");
433 } else if ( strstr(outstr, "fighter") ) {
434 strcpy(outstr, "baie de chasse");
435 } else if ( strstr(outstr, "laser") || strstr(outstr, "turret") || strstr(outstr, "missile") ) {
436 strcpy(outstr, "tourelle");
439 if ( strstr(outstr, "communication") ) {
440 strcpy(outstr, "komunikacja");
441 } else if ( !stricmp(outstr, "weapons") ) {
442 strcpy(outstr, "uzbrojenie");
443 } else if ( strstr(outstr, "engine") || strstr(outstr, "Engine")) {
444 strcpy(outstr, "silnik");
445 } else if ( !stricmp(outstr, "sensors") ) {
446 strcpy(outstr, "sensory");
447 } else if ( strstr(outstr, "navigat") ) {
448 strcpy(outstr, "nawigacja");
449 } else if ( strstr(outstr, "fighterbay") || strstr(outstr, "Fighterbay") ) {
450 strcpy(outstr, "dok my\x9Cliw.");
451 } else if ( strstr(outstr, "missile") ) {
452 strcpy(outstr, "wie\xBF. rakiet.");
453 } else if ( strstr(outstr, "laser") || strstr(outstr, "turret") ) {
454 strcpy(outstr, "wie\xBFyczka");
455 } else if ( strstr(outstr, "Command Tower") || strstr(outstr, "Bridge") ) {
456 strcpy(outstr, "mostek");
457 } else if ( strstr(outstr, "Barracks") ) {
458 strcpy(outstr, "koszary");
459 } else if ( strstr(outstr, "Reactor") ) {
460 strcpy(outstr, "reaktor");
461 } else if ( strstr(outstr, "RadarDish") ) {
462 strcpy(outstr, "antena radaru");
463 } else if (!stricmp(outstr, "Gas Collector")) {
464 strcpy(outstr, "zbieracz gazu");
467 if (!strnicmp(outstr, XSTR( "communication", 333), 3)) {
468 strcpy( outstr, XSTR( "comm", 334) );
469 } else if (!strnicmp(outstr, XSTR( "navigation", 335), 3)) {
470 strcpy( outstr, XSTR( "nav", 336) );
471 } else if (!stricmp(outstr, "Gas Collector")) {
472 strcpy(outstr, "Collector");
479 // init a specific targetbox timer
480 void hud_targetbox_init_flash_timer(int index)
482 Targetbox_flash_timers[index][0] = 1;
483 Targetbox_flash_timers[index][1] = 1;
484 Targetbox_flash_flags &= ~(1<<index);
487 // init the timers used to flash different parts of the targetbox. This needs to get called whenever
488 // the current target changes.
489 void hud_targetbox_init_flash()
491 hud_targetbox_init_flash_timer(TBOX_FLASH_NAME);
492 hud_targetbox_init_flash_timer(TBOX_FLASH_CARGO);
493 hud_targetbox_init_flash_timer(TBOX_FLASH_HULL);
494 hud_targetbox_init_flash_timer(TBOX_FLASH_STATUS);
495 hud_targetbox_init_flash_timer(TBOX_FLASH_SUBSYS);
496 hud_targetbox_init_flash_timer(TBOX_FLASH_DOCKED);
501 // set the color for flashing text
502 // input: index => item to flash
503 // flash_fast => optional param (default value 0), flash twice as fast
504 // exit: 1 => set bright color
505 // 0 => set default color
506 int hud_targetbox_maybe_flash(int index, int flash_fast)
510 // hud_set_default_color();
511 hud_set_gauge_color(HUD_TARGET_MONITOR);
512 if ( !timestamp_elapsed(Targetbox_flash_timers[index][0]) ) {
513 if ( timestamp_elapsed(Targetbox_flash_timers[index][1]) ) {
515 Targetbox_flash_timers[index][1] = timestamp(fl2i(TBOX_FLASH_INTERVAL/2.0f));
517 Targetbox_flash_timers[index][1] = timestamp(TBOX_FLASH_INTERVAL);
519 Targetbox_flash_flags ^= (1<<index); // toggle between default and bright frames
522 if ( Targetbox_flash_flags & (1<<index) ) {
523 // hud_set_bright_color();
524 hud_set_gauge_color(HUD_TARGET_MONITOR, HUD_C_BRIGHT);
527 // hud_set_dim_color();
528 hud_set_gauge_color(HUD_TARGET_MONITOR, HUD_C_DIM);
535 // init all targetbox flash timers
536 void hud_targetbox_init_all_timers()
539 for ( i = 0; i < NUM_TBOX_FLASH_TIMERS; i++ ) {
540 hud_targetbox_init_flash_timer(i);
546 // Initialize the data needed for the target view. This is called from HUD_init() once per mission
547 void hud_targetbox_init()
549 if (!Target_view_gauge_loaded) {
550 Target_view_gauge.first_frame = bm_load_animation(Target_view_fname[gr_screen.res], &Target_view_gauge.num_frames);
551 if ( Target_view_gauge.first_frame < 0 ) {
552 Warning(LOCATION,"Cannot load hud ani: %s\n", Target_view_fname[gr_screen.res]);
554 Target_view_gauge_loaded = 1;
557 if (!Target_view_integrity_gauge_loaded) {
558 Target_view_integrity_gauge.first_frame = bm_load_animation(Target_integ_fname[gr_screen.res], &Target_view_integrity_gauge.num_frames);
559 if ( Target_view_integrity_gauge.first_frame < 0 ) {
560 Warning(LOCATION,"Cannot load hud ani: %s\n", Target_integ_fname[gr_screen.res]);
562 Target_view_integrity_gauge_loaded = 1;
565 if (!Target_view_extra_loaded) {
566 Target_view_extra.first_frame = bm_load_animation(Target_extra_fname[gr_screen.res], &Target_view_extra.num_frames);
567 if ( Target_view_extra.first_frame < 0 ) {
568 Warning(LOCATION,"Cannot load hud ani: %s\n", Target_extra_fname[gr_screen.res]);
570 Target_view_extra_loaded = 1;
573 hud_targetbox_init_all_timers();
576 // -------------------------------------------------------------------------------------
577 // hud_save_restore_camera_data()
579 // Called to save and restore the 3D camera settings.
581 void hud_save_restore_camera_data(int save)
583 static vector save_view_position;
584 static float save_view_zoom;
585 static matrix save_view_matrix;
586 static matrix save_eye_matrix;
587 static vector save_eye_position;
589 // save global view variables, so we can restore them
591 save_view_position = View_position;
592 save_view_zoom = View_zoom;
593 save_view_matrix = View_matrix;
594 save_eye_matrix = Eye_matrix;
595 save_eye_position = Eye_position;
598 // restore global view variables
599 View_position = save_view_position;
600 View_zoom = save_view_zoom;
601 View_matrix = save_view_matrix;
602 Eye_matrix = save_eye_matrix;
603 Eye_position = save_eye_position;
607 // -------------------------------------------------------------------------------------
608 // hud_render_target_background()
610 // Common set up for drawing the background of the target monitor, for ships/debris/missiles
612 void hud_render_target_background()
614 // blit the background frame
615 hud_set_gauge_color(HUD_TARGET_MONITOR);
617 GR_AABITMAP(Target_view_gauge.first_frame, Targetbox_coords[gr_screen.res][TBOX_BACKGROUND][0],Targetbox_coords[gr_screen.res][TBOX_BACKGROUND][1]);
619 // blit the extra targeting info frame
620 hud_set_gauge_color(HUD_TARGET_MONITOR_EXTRA_DATA);
624 // -------------------------------------------------------------------------------------
625 // hud_render_target_setup()
627 // Common set up for the 3d code for drawing the target monitor, for ships/debris/missiles
629 void hud_render_target_setup(vector *camera_eye, matrix *camera_orient, float zoom)
631 // JAS: g3_start_frame uses clip_width and clip_height to determine the
632 // size to render to. Normally, you would set this by using gr_set_clip,
633 // but because of the hacked in hud jittering, I couldn't. So come talk
634 // to me before modifying or reusing the following code. Thanks.
636 gr_screen.clip_width = Target_window_coords[gr_screen.res][2];
637 gr_screen.clip_height = Target_window_coords[gr_screen.res][3];
638 g3_start_frame(1); // Turn on zbuffering
639 hud_save_restore_camera_data(1);
640 g3_set_view_matrix( camera_eye, camera_orient, zoom);
641 model_set_detail_level(1); // use medium detail level
643 HUD_set_clip(Target_window_coords[gr_screen.res][0],Target_window_coords[gr_screen.res][1],Target_window_coords[gr_screen.res][2],Target_window_coords[gr_screen.res][3]);
647 // -------------------------------------------------------------------------------------
648 // hud_render_target_close()
650 // Common clean-up after drawing the target monitor, for ships/debris/missiles
652 void hud_render_target_close()
655 hud_save_restore_camera_data(0);
658 // -------------------------------------------------------------------------------------
659 // hud_blit_target_foreground()
661 void hud_blit_target_foreground()
663 hud_set_gauge_color(HUD_TARGET_MONITOR);
665 GR_AABITMAP(Target_view_gauge.first_frame+1, Targetbox_coords[gr_screen.res][TBOX_BACKGROUND][0],Targetbox_coords[gr_screen.res][TBOX_BACKGROUND][1]);
668 // -------------------------------------------------------------------------------------
669 // hud_get_target_strength()
671 // Get the shield and hull percentages for a given ship object
673 // input: *objp => pointer to ship object that you want strength values for
674 // shields => OUTPUT parameter: percentage value of shields (0->1.0)
675 // integrity => OUTPUT parameter: percentage value of integrity (0->1.0)
677 void hud_get_target_strength(object *objp, float *shields, float *integrity)
681 if ( objp->type != OBJ_SHIP ) {
686 sip = &Ship_info[Ships[objp->instance].ship_info_index];
688 if (!( sip->shields == 0.0f )){
689 *shields = get_shield_strength(objp) / sip->shields;
694 if (*shields < 0.0f){
698 if ( sip->initial_hull_strength == 0 ) {
699 Int3(); // illegal initial hull strength
704 *integrity = objp->hull_strength / sip->initial_hull_strength;
709 // maybe draw the extra targeted ship information above the target monitor
710 void hud_targetbox_show_extra_ship_info(ship *target_shipp, ai_info *target_aip)
712 char outstr[256], tmpbuf[256];
715 int extra_data_shown=0;
717 hud_set_gauge_color(HUD_TARGET_MONITOR_EXTRA_DATA);
719 not_training = !(The_mission.game_type & MISSION_TYPE_TRAINING);
720 if ( not_training && (hud_gauge_active(HUD_TARGET_MONITOR_EXTRA_DATA)) && (Targetbox_show_extra_info) ) {
721 // Print out current orders if the targeted ship is friendly
722 // AL 12-26-97: only show orders and time to target for friendly ships
723 if ( (Player_ship->team == target_shipp->team) && !(ship_get_SIF(target_shipp) & SIF_NOT_FLYABLE) ) {
725 if ( ship_return_orders(outstr, target_shipp) ) {
726 gr_force_fit_string(outstr, 255, 162);
729 strcpy(outstr, XSTR( "no orders", 337));
732 emp_hud_string(Targetbox_coords[gr_screen.res][TBOX_EXTRA_ORDERS][0], Targetbox_coords[gr_screen.res][TBOX_EXTRA_ORDERS][1], EG_TBOX_EXTRA1, outstr);
736 sprintf(outstr, XSTR( "time to: ", 338));
737 if ( ship_return_time_to_goal(tmpbuf, target_shipp) ) {
738 strcat(outstr, tmpbuf);
740 emp_hud_string(Targetbox_coords[gr_screen.res][TBOX_EXTRA_TIME][0], Targetbox_coords[gr_screen.res][TBOX_EXTRA_TIME][1], EG_TBOX_EXTRA2, outstr);
745 // Print out dock status
746 if ( target_aip->ai_flags & AIF_DOCKED ) {
747 if ( target_aip->dock_objnum >= 0 ) {
748 sprintf(outstr, XSTR( "Docked: %s", 339), Ships[Objects[target_aip->dock_objnum].instance].ship_name);
749 gr_force_fit_string(outstr, 255, 173);
750 hud_targetbox_maybe_flash(TBOX_FLASH_DOCKED);
752 emp_hud_string(Targetbox_coords[gr_screen.res][TBOX_EXTRA_DOCK][0], Targetbox_coords[gr_screen.res][TBOX_EXTRA_DOCK][1], EG_TBOX_EXTRA3, outstr);
757 if ( extra_data_shown ) {
758 // hud_set_default_color();
760 GR_AABITMAP(Target_view_extra.first_frame, Targetbox_coords[gr_screen.res][TBOX_EXTRA][0],Targetbox_coords[gr_screen.res][TBOX_EXTRA][1]);
764 // Render a jump node on the target monitor
765 void hud_render_target_jump_node(object *target_objp)
768 vector obj_pos = {0.0f,0.0f,0.0f};
769 vector camera_eye = {0.0f,0.0f,0.0f};
770 matrix camera_orient = IDENTITY_MATRIX;
771 vector orient_vec, up_vector;
775 if ( Detail.targetview_model ) {
776 // take the forward orientation to be the vector from the player to the current target
777 vm_vec_sub(&orient_vec, &target_objp->pos, &Player_obj->pos);
778 vm_vec_normalize(&orient_vec);
780 factor = target_objp->radius*4.0f;
782 // use the player's up vector, and construct the viewers orientation matrix
783 up_vector = Player_obj->orient.v.uvec;
784 vm_vector_2_matrix(&camera_orient,&orient_vec,&up_vector,NULL);
786 // normalize the vector from the player to the current target, and scale by a factor to calculate
787 // the objects position
788 vm_vec_copy_scale(&obj_pos,&orient_vec,factor);
790 hud_render_target_setup(&camera_eye, &camera_orient, 0.5f);
791 jumpnode_render( target_objp, &obj_pos );
792 hud_render_target_close();
796 hud_blit_target_foreground();
797 hud_blit_target_integrity(1);
798 // hud_set_default_color();
799 hud_set_gauge_color(HUD_TARGET_MONITOR);
801 emp_hud_string(Targetbox_coords[gr_screen.res][TBOX_NAME][0], Targetbox_coords[gr_screen.res][TBOX_NAME][1], EG_TBOX_NAME, Jump_nodes[target_objp->instance].name);
803 dist = vm_vec_dist_quick(&target_objp->pos, &Player_obj->pos);
805 // account for hud shaking
806 hx = fl2i(HUD_offset_x);
807 hy = fl2i(HUD_offset_y);
809 sprintf(outstr,XSTR( "d: %.0f", 340), dist);
810 hud_num_make_mono(outstr);
811 gr_get_string_size(&w,&h,outstr);
813 emp_hud_printf(Targetbox_coords[gr_screen.res][TBOX_DIST][0]+hx, Targetbox_coords[gr_screen.res][TBOX_DIST][1]+hy, EG_TBOX_DIST, outstr);
816 // -------------------------------------------------------------------------------------
817 // hud_render_target_asteroid()
819 // Render a piece of asteroid on the target monitor
821 void hud_render_target_asteroid(object *target_objp)
823 #if !(defined(FS2_DEMO) || defined(FS1_DEMO))
824 vector obj_pos = {0.0f,0.0f,0.0f};
825 vector camera_eye = {0.0f,0.0f,0.0f};
826 matrix camera_orient = IDENTITY_MATRIX;
828 vector orient_vec, up_vector;
830 float time_to_impact, factor;
833 asteroidp = &Asteroids[target_objp->instance];
835 target_team = obj_team(target_objp);
837 subtype = asteroidp->asteroid_subtype;
839 if ( Detail.targetview_model ) {
840 // take the forward orientation to be the vector from the player to the current target
841 vm_vec_sub(&orient_vec, &target_objp->pos, &Player_obj->pos);
842 vm_vec_normalize(&orient_vec);
844 factor = 2*target_objp->radius;
846 // use the player's up vector, and construct the viewers orientation matrix
847 up_vector = Player_obj->orient.v.uvec;
848 vm_vector_2_matrix(&camera_orient,&orient_vec,&up_vector,NULL);
850 // normalize the vector from the player to the current target, and scale by a factor to calculate
851 // the objects position
852 vm_vec_copy_scale(&obj_pos,&orient_vec,factor);
854 hud_render_target_setup(&camera_eye, &camera_orient, 0.5f);
855 model_clear_instance(Asteroid_info[asteroidp->type].model_num[subtype]);
856 model_render(Asteroid_info[asteroidp->type].model_num[subtype], &target_objp->orient, &obj_pos, MR_NO_LIGHTING | MR_LOCK_DETAIL );
857 hud_render_target_close();
861 hud_blit_target_foreground();
862 hud_blit_target_integrity(1);
863 // hud_set_default_color();
864 hud_set_gauge_color(HUD_TARGET_MONITOR);
866 // hud print type of Asteroid (debris)
868 switch (asteroidp->type) {
869 case ASTEROID_TYPE_SMALL:
870 case ASTEROID_TYPE_MEDIUM:
871 case ASTEROID_TYPE_BIG:
872 strcpy(hud_name, NOX("asteroid"));
876 case DEBRIS_TERRAN_SMALL:
877 case DEBRIS_TERRAN_MEDIUM:
878 case DEBRIS_TERRAN_LARGE:
879 strcpy(hud_name, NOX("terran debris"));
882 case DEBRIS_VASUDAN_SMALL:
883 case DEBRIS_VASUDAN_MEDIUM:
884 case DEBRIS_VASUDAN_LARGE:
885 strcpy(hud_name, NOX("vasudan debris"));
888 case DEBRIS_SHIVAN_SMALL:
889 case DEBRIS_SHIVAN_MEDIUM:
890 case DEBRIS_SHIVAN_LARGE:
891 strcpy(hud_name, NOX("shivan debris"));
899 emp_hud_printf(Targetbox_coords[gr_screen.res][TBOX_NAME][0], Targetbox_coords[gr_screen.res][TBOX_NAME][1], EG_TBOX_NAME, hud_name);
901 time_to_impact = asteroid_time_to_impact(target_objp);
902 if ( time_to_impact >= 0 ) {
903 emp_hud_printf(Targetbox_coords[gr_screen.res][TBOX_CLASS][0], Targetbox_coords[gr_screen.res][TBOX_CLASS][1], EG_TBOX_CLASS, NOX("impact: %.1f sec"), time_to_impact);
908 void get_turret_subsys_name(model_subsystem *system_info, char *outstr)
910 Assert(system_info->type == SUBSYSTEM_TURRET);
912 if (system_info->turret_weapon_type >= 0) {
913 // check if beam or flak using weapon flags
914 if (Weapon_info[system_info->turret_weapon_type].wi_flags & WIF_FLAK) {
915 sprintf(outstr, "%s", XSTR("Flak turret", 1566));
916 } else if (Weapon_info[system_info->turret_weapon_type].wi_flags & WIF_BEAM) {
917 sprintf(outstr, "%s", XSTR("Beam turret", 1567));
920 if (Weapon_info[system_info->turret_weapon_type].subtype == WP_LASER) {
921 sprintf(outstr, "%s", XSTR("Laser turret", 1568));
922 } else if (Weapon_info[system_info->turret_weapon_type].subtype == WP_MISSILE) {
923 sprintf(outstr, "%s", XSTR("Missile lnchr", 1569));
927 sprintf(outstr, "%s", NOX("Turret"));
931 // This should not happen
932 sprintf(outstr, "%s", NOX("Unused"));
936 // -------------------------------------------------------------------------------------
937 // hud_render_target_ship_info()
939 // Render the data for a ship on the target monitor. Called by hud_render_target_ship().
941 void hud_render_target_ship_info(object *target_objp)
944 ship_info *target_sip;
946 int w,h,screen_integrity=1, base_index;
948 float ship_integrity, shield_strength;
950 Assert(target_objp->type == OBJ_SHIP);
951 target_shipp = &Ships[target_objp->instance];
952 target_sip = &Ship_info[target_shipp->ship_info_index];
953 target_aip = &Ai_info[target_shipp->ai_index];
955 strcpy( outstr, target_shipp->ship_name );
957 if ( hud_gauge_maybe_flash(HUD_TARGET_MONITOR) == 1 ) {
958 hud_set_iff_color(target_objp, 1);
960 // Print out ship name, with wing name if it exists
961 if ( hud_targetbox_maybe_flash(TBOX_FLASH_NAME) ) {
962 hud_set_iff_color(target_objp, 1);
964 hud_set_iff_color(target_objp);
968 // take ship "copies" into account before printing ship class name.
969 base_index = target_shipp->ship_info_index;
970 if ( target_sip->flags & SIF_SHIP_COPY )
971 base_index = ship_info_base_lookup( target_shipp->ship_info_index );
973 // maybe do some translation
975 lcl_translate_targetbox_name(outstr);
978 lcl_translate_targetbox_name_pl(outstr);
980 emp_hud_string(Targetbox_coords[gr_screen.res][TBOX_NAME][0], Targetbox_coords[gr_screen.res][TBOX_NAME][1], EG_TBOX_NAME, outstr);
982 // print out ship class
983 char temp_name[NAME_LENGTH+2] = "";
985 // if this ship has an alternate type name
986 if(target_shipp->alt_type_index >= 0){
987 mission_parse_lookup_alt_index(target_shipp->alt_type_index, temp_name);
989 strcpy(temp_name, Ship_info[base_index].name);
990 if ( strstr(Ship_info[base_index].name, NOX("#")) ) {
991 strcpy(temp_name, Ship_info[base_index].name);
992 hud_end_string_at_first_hash_symbol(temp_name);
997 lcl_translate_targetbox_name(temp_name);
1000 lcl_translate_targetbox_name_pl(temp_name);
1002 emp_hud_printf(Targetbox_coords[gr_screen.res][TBOX_CLASS][0], Targetbox_coords[gr_screen.res][TBOX_CLASS][1], EG_TBOX_CLASS, temp_name);
1004 ship_integrity = 1.0f;
1005 hud_get_target_strength(target_objp, &shield_strength, &ship_integrity);
1007 // convert to values of 0->100
1008 shield_strength *= 100.0f;
1009 ship_integrity *= 100.0f;
1011 screen_integrity = fl2i(ship_integrity+0.5f);
1012 if ( screen_integrity == 0 ) {
1013 if ( ship_integrity > 0 ) {
1014 screen_integrity = 1;
1017 // Print out right-justified integrity
1018 sprintf(outstr,XSTR( "%d%%", 341), screen_integrity);
1019 gr_get_string_size(&w,&h,outstr);
1021 if ( hud_gauge_maybe_flash(HUD_TARGET_MONITOR) == 1 ) {
1022 // hud_set_bright_color();
1023 hud_set_gauge_color(HUD_TARGET_MONITOR, HUD_C_BRIGHT);
1025 hud_targetbox_maybe_flash(TBOX_FLASH_HULL);
1028 emp_hud_printf(Targetbox_coords[gr_screen.res][TBOX_HULL][0]-w, Targetbox_coords[gr_screen.res][TBOX_HULL][1], EG_TBOX_HULL, "%s", outstr);
1029 hud_set_gauge_color(HUD_TARGET_MONITOR);
1031 // print out the targeted sub-system and % integrity
1032 if (Player_ai->targeted_subsys != NULL) {
1033 shield_strength = Player_ai->targeted_subsys->current_hits/Player_ai->targeted_subsys->system_info->max_hits *100.0f;
1034 screen_integrity = fl2i(shield_strength+0.5f);
1036 if ( screen_integrity < 0 ) {
1037 screen_integrity = 0;
1040 if ( screen_integrity == 0 ) {
1041 if ( shield_strength > 0 ) {
1042 screen_integrity = 1;
1046 if ( screen_integrity <= 0 ){
1047 hud_targetbox_start_flash(TBOX_FLASH_SUBSYS); // need to flash 0% continuously
1048 hud_targetbox_maybe_flash(TBOX_FLASH_SUBSYS);
1051 // PRINT SUBSYS NAME
1052 // hud_set_default_color();
1053 // get turret subsys name
1054 if (Player_ai->targeted_subsys->system_info->type == SUBSYSTEM_TURRET) {
1055 get_turret_subsys_name(Player_ai->targeted_subsys->system_info, outstr);
1057 sprintf(outstr, "%s", Player_ai->targeted_subsys->system_info->name);
1059 hud_targetbox_truncate_subsys_name(outstr);
1060 gr_printf(Target_window_coords[gr_screen.res][0]+2, Target_window_coords[gr_screen.res][1]+Target_window_coords[gr_screen.res][3]-h, outstr);
1062 // AL 23-3-98: Fighter bays are a special case. Player cannot destroy them, so don't
1063 // show the subsystem strength
1064 if ( strnicmp(NOX("fighter"), Player_ai->targeted_subsys->system_info->name, 7) ) {
1065 sprintf(outstr,XSTR( "%d%%", 341),screen_integrity);
1066 gr_get_string_size(&w,&h,outstr);
1067 gr_printf(Target_window_coords[gr_screen.res][0]+Target_window_coords[gr_screen.res][2]-w-1, Target_window_coords[gr_screen.res][1]+Target_window_coords[gr_screen.res][3] - h, "%s", outstr);
1070 hud_set_gauge_color(HUD_TARGET_MONITOR);
1073 // print out 'disabled' on the monitor if the target is disabled
1074 if ( (target_shipp->flags & SF_DISABLED) || (ship_subsys_disrupted(target_shipp, SUBSYSTEM_ENGINE)) ) {
1075 if ( target_shipp->flags & SF_DISABLED ) {
1076 sprintf(outstr, XSTR( "DISABLED", 342));
1078 sprintf(outstr, XSTR( "DISRUPTED", 343));
1080 gr_get_string_size(&w,&h,outstr);
1081 gr_printf(Target_window_coords[gr_screen.res][0]+Target_window_coords[gr_screen.res][2]/2 - w/2 - 1, Target_window_coords[gr_screen.res][1]+Target_window_coords[gr_screen.res][3] - 2*h, "%s", outstr);
1084 hud_targetbox_show_extra_ship_info(target_shipp, target_aip);
1087 // call to draw the integrity bar that is on the right of the target monitor
1088 void hud_blit_target_integrity(int disabled,int force_obj_num)
1095 if ( Target_view_integrity_gauge.first_frame == -1 )
1099 GR_AABITMAP(Target_view_integrity_gauge.first_frame, Integrity_bar_coords[gr_screen.res][0], Integrity_bar_coords[gr_screen.res][1]);
1103 if(force_obj_num == -1){
1104 Assert(Player_ai->target_objnum >= 0 );
1105 objp = &Objects[Player_ai->target_objnum];
1107 objp = &Objects[Player_ai->target_objnum];
1110 clip_h = fl2i( (1 - Pl_target_integrity) * Integrity_bar_coords[gr_screen.res][3] );
1112 // print out status of ship
1113 if ( (Ships[objp->instance].flags & SF_DISABLED) || (ship_subsys_disrupted(&Ships[objp->instance], SUBSYSTEM_ENGINE)) ) {
1114 sprintf(buf,XSTR( "dis", 344));
1115 current_ts = TS_DIS;
1117 if ( Pl_target_integrity > 0.9 ) {
1118 sprintf(buf,XSTR( "ok", 345));
1120 } else if ( Pl_target_integrity > 0.2 ) {
1121 sprintf(buf,XSTR( "dmg", 346));
1122 current_ts = TS_DMG;
1124 sprintf(buf,XSTR( "crt", 347));
1125 current_ts = TS_CRT;
1129 if ( Last_ts != -1 && current_ts != Last_ts ) {
1130 hud_targetbox_start_flash(TBOX_FLASH_STATUS);
1132 Last_ts = current_ts;
1134 hud_targetbox_maybe_flash(TBOX_FLASH_STATUS);
1136 emp_hud_string(Integrity_string_coords[gr_screen.res][0], Integrity_string_coords[gr_screen.res][1], EG_TBOX_INTEG, buf);
1138 hud_set_gauge_color(HUD_TARGET_MONITOR);
1140 bm_get_info(Target_view_integrity_gauge.first_frame,&w,&h);
1143 // draw the dark portion
1144 GR_AABITMAP_EX(Target_view_integrity_gauge.first_frame, Integrity_bar_coords[gr_screen.res][0], Integrity_bar_coords[gr_screen.res][1], w, clip_h,0,0);
1147 if ( clip_h <= Integrity_bar_coords[gr_screen.res][3] ) {
1148 // draw the bright portion
1149 GR_AABITMAP_EX(Target_view_integrity_gauge.first_frame+1, Integrity_bar_coords[gr_screen.res][0], Integrity_bar_coords[gr_screen.res][1]+clip_h,w,h-clip_h,0,clip_h);
1153 // determine if the subsystem is in line-of sight, without taking into accout whether the player ship is
1154 // facing the subsystem
1155 int hud_targetbox_subsystem_in_view(object *target_objp, int *sx, int *sy)
1157 ship_subsys *subsys;
1159 vertex subobj_vertex;
1163 subsys = Player_ai->targeted_subsys;
1164 if (subsys != NULL ) {
1165 vm_vec_unrotate(&subobj_pos, &subsys->system_info->pnt, &target_objp->orient);
1166 vm_vec_add2(&subobj_pos, &target_objp->pos);
1168 // is it subsystem in view
1169 if ( Player->subsys_in_view == -1 ) {
1170 rval = ship_subsystem_in_sight(target_objp, subsys, &View_position, &subobj_pos, 0);
1172 rval = Player->subsys_in_view;
1175 // get screen coords, adjusting for autocenter
1176 Assert(target_objp->type == OBJ_SHIP);
1177 if (target_objp->type == OBJ_SHIP) {
1178 pm = model_get(Ships[target_objp->instance].modelnum);
1179 if (pm->flags & PM_FLAG_AUTOCEN) {
1181 vm_vec_copy_scale(&temp, &pm->autocenter, -1.0f);
1182 vm_vec_unrotate(&delta, &temp, &target_objp->orient);
1183 vm_vec_add2(&subobj_pos, &delta);
1187 g3_rotate_vertex(&subobj_vertex, &subobj_pos);
1188 g3_project_vertex(&subobj_vertex);
1189 *sx = (int) subobj_vertex.sx;
1190 *sy = (int) subobj_vertex.sy;
1196 void hud_update_cargo_scan_sound()
1198 if ( Player->cargo_inspect_time <= 0 ) {
1199 player_stop_cargo_scan_sound();
1202 player_maybe_start_cargo_scan_sound();
1206 // If the player is scanning for cargo, draw some cool scanning lines on the target monitor
1207 void hud_maybe_render_cargo_scan(ship_info *target_sip)
1210 int scan_time; // time required to scan ship
1212 if ( Player->cargo_inspect_time <= 0 ) {
1216 scan_time = target_sip->scan_time;
1217 // hud_set_default_color();
1218 hud_set_gauge_color(HUD_TARGET_MONITOR, HUD_C_BRIGHT);
1220 // draw horizontal scan line
1221 x1 = Cargo_scan_coords[gr_screen.res][0];
1222 y1 = fl2i(0.5f + Cargo_scan_coords[gr_screen.res][1] + ( (i2fl(Player->cargo_inspect_time) / scan_time) * Cargo_scan_coords[gr_screen.res][3] ));
1223 x2 = x1 + Cargo_scan_coords[gr_screen.res][2];
1225 gr_line(x1, y1, x2, y1);
1227 // draw vertical scan line
1228 x1 = fl2i(0.5f + Cargo_scan_coords[gr_screen.res][0] + ( (i2fl(Player->cargo_inspect_time) / scan_time) * Cargo_scan_coords[gr_screen.res][2] ));
1229 y1 = Cargo_scan_coords[gr_screen.res][1];
1230 y2 = y1 + Cargo_scan_coords[gr_screen.res][3];
1232 gr_line(x1, y1-3, x1, y2-1);
1235 // Get the eye position for an object at the origin, called from hud_render_target_ship()
1236 // input: eye_pos => Global pos for eye (output parameter)
1237 // orient => Orientation of object at the origin
1238 void hud_targetbox_get_eye(vector *eye_pos, matrix *orient, int ship_num)
1243 vector origin = {0.0f, 0.0f, 0.0f};
1245 shipp = &Ships[ship_num];
1246 pm = model_get( shipp->modelnum );
1248 // If there is no eye, don't do anything
1249 if ( pm->n_view_positions == 0 ) {
1253 ep = &(pm->view_positions[0] );
1255 model_find_world_point( eye_pos, &ep->pnt, shipp->modelnum, ep->parent, orient, &origin );
1258 // -------------------------------------------------------------------------------------
1259 // hud_render_target_ship()
1261 // Render a ship to the target monitor
1263 void hud_render_target_ship(object *target_objp)
1265 vector obj_pos = {0.0f,0.0f,0.0f};
1266 vector camera_eye = {0.0f,0.0f,0.0f};
1267 matrix camera_orient = IDENTITY_MATRIX;
1269 ship_info *target_sip;
1270 vector orient_vec, up_vector;
1275 target_shipp = &Ships[target_objp->instance];
1276 target_sip = &Ship_info[target_shipp->ship_info_index];
1278 if ( Detail.targetview_model ) {
1279 // take the forward orientation to be the vector from the player to the current target
1280 vm_vec_sub(&orient_vec, &target_objp->pos, &Player_obj->pos);
1281 vm_vec_normalize(&orient_vec);
1283 factor = -target_sip->closeup_pos.xyz.z;
1285 // use the player's up vector, and construct the viewers orientation matrix
1286 up_vector = Player_obj->orient.v.uvec;
1287 vm_vector_2_matrix(&camera_orient,&orient_vec,&up_vector,NULL);
1289 // normalize the vector from the player to the current target, and scale by a factor to calculate
1290 // the objects position
1291 vm_vec_copy_scale(&obj_pos,&orient_vec,factor);
1293 // set camera eye to eye of ship relative to origin
1294 // hud_targetbox_get_eye(&camera_eye, &camera_orient, Player_obj->instance);
1296 hud_render_target_setup(&camera_eye, &camera_orient, target_sip->closeup_zoom);
1297 // model_clear_instance(target_sip->modelnum);
1298 ship_model_start( target_objp );
1300 // maybe render a special hud-target-only model
1301 if(target_sip->modelnum_hud >= 0){
1302 model_render( target_sip->modelnum_hud, &target_objp->orient, &obj_pos, MR_NO_LIGHTING | MR_LOCK_DETAIL | MR_AUTOCENTER);
1304 model_render( target_sip->modelnum, &target_objp->orient, &obj_pos, MR_NO_LIGHTING | MR_LOCK_DETAIL | MR_AUTOCENTER);
1306 ship_model_stop( target_objp );
1310 // check if subsystem target has changed
1311 if ( Player_ai->targeted_subsys == Player_ai->last_subsys_target ) {
1313 save_pos = target_objp->pos;
1314 target_objp->pos = obj_pos;
1315 subsys_in_view = hud_targetbox_subsystem_in_view(target_objp, &sx, &sy);
1316 target_objp->pos = save_pos;
1318 if ( subsys_in_view != -1 ) {
1320 // AL 29-3-98: If subsystem is destroyed, draw gray brackets
1321 if ( (Player_ai->targeted_subsys->current_hits <= 0) && (strnicmp(NOX("fighter"), Player_ai->targeted_subsys->system_info->name, 7)) ) {
1322 gr_set_color_fast(&IFF_colors[IFF_COLOR_MESSAGE][1]);
1324 hud_set_iff_color( target_objp, 1 );
1327 if ( subsys_in_view ) {
1328 draw_brackets_square_quick(sx - 10, sy - 10, sx + 10, sy + 10);
1330 draw_brackets_diamond_quick(sx - 10, sy - 10, sx + 10, sy + 10);
1334 hud_render_target_close();
1337 hud_blit_target_foreground();
1338 hud_blit_target_integrity(0,OBJ_INDEX(target_objp));
1340 hud_render_target_ship_info(target_objp);
1341 hud_maybe_render_cargo_scan(target_sip);
1344 // -------------------------------------------------------------------------------------
1345 // hud_render_target_debris()
1347 // Render a piece of debris on the target monitor
1349 void hud_render_target_debris(object *target_objp)
1351 vector obj_pos = {0.0f,0.0f,0.0f};
1352 vector camera_eye = {0.0f,0.0f,0.0f};
1353 matrix camera_orient = IDENTITY_MATRIX;
1355 vector orient_vec, up_vector;
1356 int target_team, base_index;
1359 debrisp = &Debris[target_objp->instance];
1361 //target_sip = &Ship_info[debrisp->ship_info_index];
1362 target_team = obj_team(target_objp);
1365 if ( Detail.targetview_model ) {
1366 // take the forward orientation to be the vector from the player to the current target
1367 vm_vec_sub(&orient_vec, &target_objp->pos, &Player_obj->pos);
1368 vm_vec_normalize(&orient_vec);
1370 factor = 2*target_objp->radius;
1372 // use the player's up vector, and construct the viewers orientation matrix
1373 up_vector = Player_obj->orient.v.uvec;
1374 vm_vector_2_matrix(&camera_orient,&orient_vec,&up_vector,NULL);
1376 // normalize the vector from the player to the current target, and scale by a factor to calculate
1377 // the objects position
1378 vm_vec_copy_scale(&obj_pos,&orient_vec,factor);
1380 hud_render_target_setup(&camera_eye, &camera_orient, 0.5f);
1381 model_clear_instance(debrisp->model_num);
1382 submodel_render( debrisp->model_num, debrisp->submodel_num, &target_objp->orient, &obj_pos, MR_NO_LIGHTING | MR_LOCK_DETAIL );
1383 hud_render_target_close();
1387 hud_blit_target_foreground();
1388 hud_blit_target_integrity(1);
1389 // hud_set_default_color();
1390 hud_set_gauge_color(HUD_TARGET_MONITOR);
1392 // take ship "copies" into account before printing out ship class information
1393 base_index = debrisp->ship_info_index;
1394 if ( Ship_info[base_index].flags & SIF_SHIP_COPY )
1395 base_index = ship_info_base_lookup( debrisp->ship_info_index );
1397 // print out ship class that debris came from
1398 char *printable_ship_class = Ship_info[base_index].name;
1399 if ( strstr(Ship_info[base_index].name, NOX("#")) ) {
1400 char temp_name[NAME_LENGTH];
1401 strcpy(temp_name, Ship_info[base_index].name);
1402 hud_end_string_at_first_hash_symbol(temp_name);
1403 printable_ship_class = temp_name;
1406 emp_hud_string(Targetbox_coords[gr_screen.res][TBOX_CLASS][0], Targetbox_coords[gr_screen.res][TBOX_CLASS][1], EG_TBOX_CLASS, printable_ship_class);
1407 emp_hud_string(Targetbox_coords[gr_screen.res][TBOX_NAME][0], Targetbox_coords[gr_screen.res][TBOX_NAME][1], EG_TBOX_NAME, XSTR( "debris", 348));
1410 // -------------------------------------------------------------------------------------
1411 // hud_render_target_weapon()
1413 // Render a missile or a missile view to the target monitor
1415 void hud_render_target_weapon(object *target_objp)
1417 vector obj_pos = {0.0f,0.0f,0.0f};
1418 vector camera_eye = {0.0f,0.0f,0.0f};
1419 matrix camera_orient = IDENTITY_MATRIX;
1420 vector orient_vec, up_vector;
1421 weapon_info *target_wip = NULL;
1423 object *viewer_obj, *viewed_obj;
1424 int target_team, is_homing, is_player_missile, missile_view, viewed_model_num, w, h;
1426 char outstr[100]; // temp buffer
1428 target_team = obj_team(target_objp);
1430 wp = &Weapons[target_objp->instance];
1431 target_wip = &Weapon_info[wp->weapon_info_index];
1434 if ( target_wip->wi_flags & WIF_HOMING && wp->homing_object != &obj_used_list )
1437 is_player_missile = FALSE;
1438 if ( target_objp->parent_sig == Player_obj->signature ) {
1439 is_player_missile = TRUE;
1442 if ( Detail.targetview_model ) {
1444 viewer_obj = Player_obj;
1445 viewed_obj = target_objp;
1446 missile_view = FALSE;
1447 viewed_model_num = target_wip->model_num;
1448 if ( is_homing && is_player_missile ) {
1449 viewer_obj = target_objp;
1450 viewed_obj = wp->homing_object;
1451 missile_view = TRUE;
1452 viewed_model_num = Ships[wp->homing_object->instance].modelnum;
1455 // take the forward orientation to be the vector from the player to the current target
1456 vm_vec_sub(&orient_vec, &viewed_obj->pos, &viewer_obj->pos);
1457 vm_vec_normalize(&orient_vec);
1459 if ( missile_view == FALSE )
1460 factor = 2*target_objp->radius;
1462 factor = vm_vec_dist_quick(&viewer_obj->pos, &viewed_obj->pos);
1464 // use the viewer's up vector, and construct the viewers orientation matrix
1465 up_vector = viewer_obj->orient.v.uvec;
1466 vm_vector_2_matrix(&camera_orient,&orient_vec,&up_vector,NULL);
1468 // normalize the vector from the viewer to the viwed target, and scale by a factor to calculate
1469 // the objects position
1470 vm_vec_copy_scale(&obj_pos,&orient_vec,factor);
1472 hud_render_target_setup(&camera_eye, &camera_orient, View_zoom/3);
1473 model_clear_instance(viewed_model_num);
1474 model_render( viewed_model_num, &viewed_obj->orient, &obj_pos, MR_NO_LIGHTING | MR_LOCK_DETAIL );
1475 hud_render_target_close();
1479 if ( is_homing == TRUE ) {
1480 hud_blit_target_foreground();
1482 hud_blit_target_foreground();
1485 hud_blit_target_integrity(1);
1486 // hud_set_default_color();
1487 hud_set_gauge_color(HUD_TARGET_MONITOR);
1489 // print out the weapon class name
1490 sprintf( outstr,"%s", target_wip->name );
1491 gr_get_string_size(&w,&h,outstr);
1493 // drop name past the # sign
1494 if ( strstr(outstr, NOX("#")) ) {
1495 hud_end_string_at_first_hash_symbol(outstr);
1497 emp_hud_string(Targetbox_coords[gr_screen.res][TBOX_NAME][0], Targetbox_coords[gr_screen.res][TBOX_NAME][1], EG_TBOX_NAME, outstr);
1499 // If a homing weapon, show time to impact
1503 dist = vm_vec_dist(&target_objp->pos, &wp->homing_object->pos);
1504 speed = vm_vec_mag(&target_objp->phys_info.vel);
1506 sprintf(outstr, NOX("impact: %.1f sec"), dist/speed);
1508 sprintf(outstr, XSTR( "unknown", 349));
1511 emp_hud_string(Targetbox_coords[gr_screen.res][TBOX_CLASS][0], Targetbox_coords[gr_screen.res][TBOX_CLASS][1], EG_TBOX_CLASS, outstr);
1515 // -------------------------------------------------------------------------------------
1516 // hud_render_target_model() will render the target in the small targetting box. The box
1517 // is then shaded to give a monochrome effect
1519 void hud_render_target_model()
1521 object *target_objp;
1523 if ( !hud_gauge_active(HUD_TARGET_MONITOR) )
1526 if ( Player_ai->target_objnum == -1)
1529 if ( Target_static_playing )
1532 target_objp = &Objects[Player_ai->target_objnum];
1534 // Draw the background frame
1535 hud_render_target_background();
1537 switch ( target_objp->type ) {
1539 hud_render_target_ship(target_objp);
1543 hud_render_target_debris(target_objp);
1547 hud_render_target_weapon(target_objp);
1551 hud_render_target_asteroid(target_objp);
1555 hud_render_target_jump_node(target_objp);
1559 // Error(LOCATION, "Trying to show object type %d on target monitor\n", target_objp->type);
1560 hud_cease_targeting();
1565 void hud_cargo_scan_update(object *targetp, float frametime)
1567 char outstr[256]; // temp buffer for sprintf'ing hud output
1570 // Account for HUD shaking
1571 hx = fl2i(HUD_offset_x);
1572 hy = fl2i(HUD_offset_y);
1574 // display cargo inspection status
1575 if ( targetp->type == OBJ_SHIP ) {
1576 if ( player_inspect_cargo(frametime, outstr) ) {
1577 if ( hud_gauge_active(HUD_TARGET_MONITOR) ) {
1578 if ( Player->cargo_inspect_time > 0 ) {
1579 hud_targetbox_start_flash(TBOX_FLASH_CARGO);
1582 // Print out what the cargo is
1583 if ( hud_gauge_maybe_flash(HUD_TARGET_MONITOR) == 1 ) {
1584 // hud_set_bright_color();
1585 hud_set_gauge_color(HUD_TARGET_MONITOR, HUD_C_BRIGHT);
1587 hud_targetbox_maybe_flash(TBOX_FLASH_CARGO);
1590 emp_hud_string(Targetbox_coords[gr_screen.res][TBOX_CARGO][0]+hx, Targetbox_coords[gr_screen.res][TBOX_CARGO][1]+hy, EG_TBOX_CARGO, outstr);
1591 hud_set_gauge_color(HUD_TARGET_MONITOR);
1594 } // end if (is_ship)
1598 // -----------------------------------------------------------------------------------
1599 // hud_show_target_data() will display the data about the target in and
1600 // around the targetting window
1602 void hud_show_target_data(float frametime)
1604 char outstr[256]; // temp buffer for sprintf'ing hud output
1605 int w,h; // width and height of string about to print
1606 object *target_objp;
1608 debris *debrisp = NULL;
1609 ship_info *sip = NULL;
1612 hud_set_gauge_color(HUD_TARGET_MONITOR);
1614 target_objp = &Objects[Player_ai->target_objnum];
1616 switch( Objects[Player_ai->target_objnum].type ) {
1618 shipp = &Ships[target_objp->instance];
1619 sip = &Ship_info[shipp->ship_info_index];
1624 debrisp = &Debris[target_objp->instance];
1625 sip = &Ship_info[debrisp->ship_info_index];
1640 Int3(); // can't happen
1646 // Account for HUD shaking
1647 hx = fl2i(HUD_offset_x);
1648 hy = fl2i(HUD_offset_y);
1650 // print out the target distance and speed
1651 sprintf(outstr,XSTR( "d: %.0f%s", 350), Player_ai->current_target_distance, modifiers[Player_ai->current_target_dist_trend]);
1653 hud_num_make_mono(outstr);
1654 gr_get_string_size(&w,&h,outstr);
1656 emp_hud_string(Targetbox_coords[gr_screen.res][TBOX_DIST][0]+hx, Targetbox_coords[gr_screen.res][TBOX_DIST][1]+hy, EG_TBOX_DIST, outstr);
1660 spd = vm_vec_dist(&target_objp->pos, &target_objp->last_pos) / frametime;
1662 // 7/28/99 DKA: Do not use vec_mag_quick -- the error is too big
1663 spd = vm_vec_mag(&target_objp->phys_info.vel);
1664 // spd = target_objp->phys_info.fspeed;
1668 // if the speed is 0, determine if we are docked with something -- if so, get the velocity from
1669 // our docked object instead
1670 if ( (spd == 0.0f) && is_ship ) {
1674 aip = &Ai_info[shipp->ai_index];
1675 if ( aip->ai_flags & AIF_DOCKED ) {
1676 Assert( aip->dock_objnum != -1 );
1677 other_objp = &Objects[aip->dock_objnum];
1678 spd = other_objp->phys_info.fspeed;
1684 sprintf(outstr, XSTR( "s: %.0f%s", 351), spd, (spd>1)?modifiers[Player_ai->current_target_speed_trend]:"");
1685 hud_num_make_mono(outstr);
1687 emp_hud_string(Targetbox_coords[gr_screen.res][TBOX_SPEED][0]+hx, Targetbox_coords[gr_screen.res][TBOX_SPEED][1]+hy, EG_TBOX_SPEED, outstr);
1690 // output target info for debug purposes only, this will be removed later
1696 if ( Show_target_debug_info && (is_ship == 1) ) {
1699 dy = gr_get_font_height() + 1;
1702 gr_set_color_fast(&HUD_color_debug);
1704 if ( shipp->ai_index >= 0 ) {
1705 ai_info *aip = &Ai_info[shipp->ai_index];
1707 sprintf(outstr,"AI: %s",Ai_behavior_names[aip->mode]);
1709 switch (aip->mode) {
1711 Assert(aip->submode <= SM_BIG_PARALLEL); // Must be <= largest chase submode value.
1712 // sprintf(outstr,"AI: %s",Submode_text[aip->submode]);
1713 sprintf(outstr2," / %s",Submode_text[aip->submode]);
1714 strcat(outstr,outstr2);
1717 Assert(aip->submode <= AIS_STRAFE_POSITION); // Must be <= largest chase submode value.
1718 // sprintf(outstr,"AI: %s",Strafe_submode_text[aip->submode-AIS_STRAFE_ATTACK]);
1719 sprintf(outstr2," / %s",Strafe_submode_text[aip->submode-AIS_STRAFE_ATTACK]);
1720 strcat(outstr,outstr2);
1723 // gr_printf(sx, sy, "Wpnum: %i",aip->wp_index);
1724 sprintf(outstr2," / Wpnum: %i",aip->wp_index);
1725 strcat(outstr,outstr2);
1731 gr_printf(sx, sy, outstr);
1734 gr_printf(sx, sy, "Max speed = %d, (%d%%)", (int) shipp->current_max_speed, (int) (100.0f * vm_vec_mag(&target_objp->phys_info.vel)/shipp->current_max_speed));
1737 // data can be found in target montior
1738 // gr_printf(TARGET_WINDOW_X1+TARGET_WINDOW_WIDTH+3, TARGET_WINDOW_Y1+5*h, "Shields: %d", (int) Players[Player_num].current_target->shields);
1739 if (aip->target_objnum != -1) {
1740 char target_str[32];
1744 if (aip->target_objnum == Player_obj-Objects)
1745 strcpy(target_str, "Player!");
1747 sprintf(target_str, "%s", Ships[Objects[aip->target_objnum].instance].ship_name);
1749 // gr_printf(TARGET_WINDOW_X1+TARGET_WINDOW_WIDTH+2, TARGET_WINDOW_Y1+4*h, "Target: %s", target_str);
1750 gr_printf(sx, sy, "Targ: %s", target_str);
1753 dist = vm_vec_dist_quick(&Objects[Player_ai->target_objnum].pos, &Objects[aip->target_objnum].pos);
1754 vm_vec_normalized_dir(&v2t,&Objects[aip->target_objnum].pos, &Objects[Player_ai->target_objnum].pos);
1756 dot = vm_vec_dot(&v2t, &Objects[Player_ai->target_objnum].orient.v.fvec);
1758 // data can be found in target montior
1759 // gr_printf(TARGET_WINDOW_X1+TARGET_WINDOW_WIDTH+3, TARGET_WINDOW_Y1+6*h, "Targ dist: %5.1f", dist);
1760 // gr_printf(TARGET_WINDOW_X1+TARGET_WINDOW_WIDTH+2, TARGET_WINDOW_Y1+5*h, "Targ dot: %3.2f", dot);
1761 gr_printf(sx, sy, "Targ dot: %3.2f", dot);
1763 // gr_printf(TARGET_WINDOW_X1+TARGET_WINDOW_WIDTH+2, TARGET_WINDOW_Y1+6*h, "Targ dst: %3.2f", dist);
1764 gr_printf(sx, sy, "Targ dst: %3.2f", dist);
1767 if ( aip->targeted_subsys != NULL ) {
1768 sprintf(outstr, "Subsys: %s", aip->targeted_subsys->system_info->name);
1769 gr_printf(sx, sy, outstr);
1774 // print out energy transfer information on the ship
1777 sprintf(outstr,"MAX G/E: %.0f/%.0f",shipp->weapon_energy,shipp->current_max_speed);
1778 gr_printf(sx, sy, outstr);
1781 sprintf(outstr,"G/S/E: %.2f/%.2f/%.2f",Energy_levels[shipp->weapon_recharge_index],Energy_levels[shipp->shield_recharge_index],Energy_levels[shipp->engine_recharge_index]);
1782 gr_printf(sx, sy, outstr);
1785 // Show information about attacker.
1789 if (Enemy_attacker != NULL)
1790 if (Enemy_attacker->type == OBJ_SHIP) {
1796 eshipp = &Ships[Enemy_attacker->instance];
1797 eaip = &Ai_info[eshipp->ai_index];
1799 if (eaip->target_objnum == Player_obj-Objects) {
1801 dist = vm_vec_dist_quick(&Enemy_attacker->pos, &Player_obj->pos);
1802 vm_vec_normalized_dir(&v2t,&Objects[eaip->target_objnum].pos, &Enemy_attacker->pos);
1804 dot = vm_vec_dot(&v2t, &Enemy_attacker->orient.v.fvec);
1806 gr_printf(sx, sy, "#%i: %s", Enemy_attacker-Objects, Ships[Enemy_attacker->instance].ship_name);
1808 gr_printf(sx, sy, "Targ dist: %5.1f", dist);
1810 gr_printf(sx, sy, "Targ dot: %3.2f", dot);
1815 if (Player_ai->target_objnum == Enemy_attacker - Objects)
1821 Enemy_attacker = NULL;
1822 for (i=0; i<MAX_OBJECTS; i++)
1823 if (Objects[i].type == OBJ_SHIP) {
1826 if (i != Player_ai->target_objnum) {
1827 enemy = Ai_info[Ships[Objects[i].instance].ai_index].target_objnum;
1829 if (enemy == Player_obj-Objects) {
1830 Enemy_attacker = &Objects[i];
1840 gr_printf(sx, sy, "Targ size: %dx%d", Hud_target_w, Hud_target_h );
1843 polymodel *pm = model_get( shipp->modelnum );
1844 gr_printf(sx, sy, "POF:%s", pm->filename );
1847 gr_printf(sx, sy, "Mass: %.2f\n", pm->mass);
1852 // display the weapons for the target on the HUD. Include ammo counts.
1853 if ( Show_target_weapons && (is_ship == 1) ) {
1857 swp = &shipp->weapons;
1860 dy = gr_get_font_height();
1862 sprintf(outstr,"Num primaries: %d", swp->num_primary_banks);
1863 gr_printf(sx,sy,outstr);
1865 for ( i = 0; i < swp->num_primary_banks; i++ ) {
1866 sprintf(outstr,"%d. %s", i+1, Weapon_info[swp->primary_bank_weapons[i]].name);
1867 gr_printf(sx,sy,outstr);
1872 sprintf(outstr,"Num secondaries: %d", swp->num_secondary_banks);
1873 gr_printf(sx,sy,outstr);
1875 for ( i = 0; i < swp->num_secondary_banks; i++ ) {
1876 sprintf(outstr,"%d. %s", i+1, Weapon_info[swp->secondary_bank_weapons[i]].name);
1877 gr_printf(sx,sy,outstr);
1886 // called at the start of each level
1887 void hud_targetbox_static_init()
1889 Target_static_next = 0;;
1890 Target_static_playing = 0;
1893 // determine if we should draw static on top of the target box
1894 int hud_targetbox_static_maybe_blit(float frametime)
1898 // on lowest skill level, don't show static on target monitor
1899 if ( Game_skill_level == 0 )
1902 // if multiplayer observer, don't show static
1903 if((Game_mode & GM_MULTIPLAYER) && (Net_player->flags & NETINFO_FLAG_OBSERVER)){
1907 sensors_str = ship_get_subsystem_strength( Player_ship, SUBSYSTEM_SENSORS );
1909 if ( ship_subsys_disrupted(Player_ship, SUBSYSTEM_SENSORS) ) {
1910 sensors_str = SENSOR_STR_TARGET_NO_EFFECTS-1;
1913 if ( sensors_str > SENSOR_STR_TARGET_NO_EFFECTS ) {
1914 Target_static_playing = 0;
1915 Target_static_next = 0;
1917 if ( Target_static_next == 0 )
1918 Target_static_next = 1;
1921 if ( timestamp_elapsed(Target_static_next) ) {
1922 Target_static_playing ^= 1;
1923 Target_static_next = timestamp_rand(50, 750);
1926 if ( Target_static_playing ) {
1927 // hud_set_default_color();
1928 hud_set_gauge_color(HUD_TARGET_MONITOR);
1929 hud_anim_render(&Target_static, frametime, 1);
1930 if ( Target_static_looping == -1 ) {
1931 Target_static_looping = snd_play_looping(&Snds[SND_STATIC]);
1934 if ( Target_static_looping != -1 ) {
1935 snd_stop(Target_static_looping);
1936 Target_static_looping = -1;
1940 return Target_static_playing;
1943 // start the targetbox item flashing for duration ms
1944 // input: index => TBOX_FLASH_ #define
1945 // duration => optional param (default value TBOX_FLASH_DURATION), how long to flash in ms
1946 void hud_targetbox_start_flash(int index, int duration)
1948 Targetbox_flash_timers[index][0] = timestamp(duration);
1951 // stop flashing a specific targetbox item
1952 void hud_targetbox_end_flash(int index)
1954 Targetbox_flash_timers[index][0] = 1;
1957 // determine if a given flashing index is bright or not
1958 int hud_targetbox_is_bright(int index)
1960 return (Targetbox_flash_flags & (1<<index));
1963 // determine if the flashing has expired
1964 int hud_targetbox_flash_expired(int index)
1966 if ( timestamp_elapsed(Targetbox_flash_timers[index][0]) ) {
1974 void hudtargetbox_page_in()
1976 bm_page_in_aabitmap( Target_view_gauge.first_frame, Target_view_gauge.num_frames);
1978 bm_page_in_aabitmap( Target_view_integrity_gauge.first_frame, Target_view_integrity_gauge.num_frames );
1980 bm_page_in_aabitmap( Target_view_extra.first_frame, Target_view_extra.num_frames );