]> icculus.org git repositories - taylor/freespace2.git/blob - src/hud/hudreticle.cpp
Initial revision
[taylor/freespace2.git] / src / hud / hudreticle.cpp
1 /*
2  * $Logfile: /Freespace2/code/Hud/HUDreticle.cpp $
3  * $Revision$
4  * $Date$
5  * $Author$
6  *
7  * C module to draw and manage the recticle
8  *
9  * $Log$
10  * Revision 1.1  2002/05/03 03:28:09  root
11  * Initial revision
12  *
13  * 
14  * 14    10/27/99 10:04p Jefff
15  * changed german match speed indicator
16  * 
17  * 13    10/14/99 2:50p Jefff
18  * localization fixes
19  * 
20  * 12    8/28/99 4:54p Dave
21  * Fixed directives display for multiplayer clients for wings with
22  * multiple waves. Fixed hud threat indicator rendering color.
23  * 
24  * 11    8/09/99 3:14p Dave
25  * Make "launch" warning gauge draw in code.
26  * 
27  * 10    6/10/99 3:43p Dave
28  * Do a better job of syncing text colors to HUD gauges.
29  * 
30  * 9     6/08/99 10:48a Jasenw
31  * new coords for new HUD stuff
32  * 
33  * 8     6/03/99 2:31p Jasenw
34  * changed coords and removed weapon indicators.
35  * 
36  * 7     1/07/99 2:21p Jasen
37  * fixed toparc
38  * 
39  * 6     1/07/99 9:07a Jasen
40  * HUD coords
41  * 
42  * 5     12/28/98 3:17p Dave
43  * Support for multiple hud bitmap filenames for hi-res mode.
44  * 
45  * 4     12/21/98 5:02p Dave
46  * Modified all hud elements to be multi-resolution friendly.
47  * 
48  * 3     11/05/98 4:18p Dave
49  * First run nebula support. Beefed up localization a bit. Removed all
50  * conditional compiles for foreign versions. Modified mission file
51  * format.
52  * 
53  * 2     10/07/98 10:53a Dave
54  * Initial checkin.
55  * 
56  * 1     10/07/98 10:49a Dave
57  * 
58  * 69    8/28/98 3:28p Dave
59  * EMP effect done. AI effects may need some tweaking as required.
60  * 
61  * 68    8/25/98 1:48p Dave
62  * First rev of EMP effect. Player side stuff basically done. Next comes
63  * AI code.
64  * 
65  * 67    6/12/98 4:52p Hoffoss
66  * Added support for special characters in in forgeign languages.
67  * 
68  * 66    6/09/98 5:17p Lawrance
69  * French/German localization
70  * 
71  * 65    6/09/98 10:31a Hoffoss
72  * Created index numbers for all xstr() references.  Any new xstr() stuff
73  * added from here on out should be added to the end if the list.  The
74  * current list count can be found in FreeSpace.cpp (search for
75  * XSTR_SIZE).
76  * 
77  * 64    5/21/98 7:18p Lawrance
78  * Don't flash 'launch' for attempted lock
79  * 
80  * 63    5/13/98 1:53p Lawrance
81  * If no secondary banks on a ship, show correct reticle gauge
82  * 
83  * 62    5/06/98 8:05p Dave
84  * Made standalone reset properly under weird conditions. Tweak
85  * optionsmulti screen. Upped MAX_WEAPONS to 350. Put in new launch
86  * countdown anim. Minro ui fixes/tweaks.
87  * 
88  * 61    5/05/98 5:51p Lawrance
89  * Draw HUD center crosshair with bright alpha index
90  * 
91  * 60    5/04/98 6:12p Lawrance
92  * fix progblems with weapon gauges in situation when weapons are on ship
93  * 
94  * 59    5/01/98 4:22p Lawrance
95  * Use ship->weapons instead of sip when displaying weapon linking gauge
96  * 
97  * 58    4/13/98 11:19a Lawrance
98  * fix launch threat indicator
99  * 
100  * 57    4/08/98 10:34p Allender
101  * make threat indicators work in multiplayer.  Fix socket problem (once
102  * and for all???)
103  * 
104  * 56    3/26/98 5:26p John
105  * added new paging code. nonfunctional.
106  * 
107  * 55    2/23/98 6:49p Lawrance
108  * Use gr_aabitmap_ex() instead of clipping regions
109  * 
110  * 54    2/22/98 4:17p John
111  * More string externalization classification... 190 left to go!
112  * 
113  * 53    2/22/98 12:19p John
114  * Externalized some strings
115  * 
116  * 52    2/12/98 4:58p Lawrance
117  * Change to new flashing method.
118  * 
119  * 51    2/09/98 9:07p Lawrance
120  * Ensure 'evaded' popup has precedence over 'launch' popup
121  * 
122  * 50    1/25/98 10:31p Lawrance
123  * Don't draw most hud gauges when viewing from another ship.
124  * 
125  * 49    1/19/98 11:37p Lawrance
126  * Fixing Optimization build warnings
127  * 
128  * 48    1/14/98 10:21a Lawrance
129  * Draw reticle correctly when gauges are disabled.
130  * 
131  * 47    1/08/98 3:20p Johnson
132  * ALAN: Ensure entire throttle gauge flashes
133  * 
134  * 46    1/05/98 9:38p Lawrance
135  * Implement flashing HUD gauges.
136  * 
137  * 45    1/02/98 9:10p Lawrance
138  * Big changes to how colors get set on the HUD.
139  * 
140  * 44    12/16/97 9:13p Lawrance
141  * Integrate new gauges into HUD config.
142  * 
143  * 43    12/10/97 10:02p Lawrance
144  * Change weapon linking to use flags.
145  * 
146  * 42    12/08/97 1:49p Lawrance
147  * only play threat lock sound when a lock is being attempted
148  * 
149  * 41    11/17/97 6:37p Lawrance
150  * new gauges: extended target view, new lock triangles, support ship view
151  * 
152  * 40    11/11/97 10:25p Lawrance
153  * add sound hook for when missile threat flashes
154  * 
155  * 39    11/11/97 5:05p Lawrance
156  * get threat indicator working more reliably
157  * 
158  * 38    11/05/97 11:20p Lawrance
159  * add speed numbers to the reticle
160  * 
161  * 37    11/04/97 7:49p Lawrance
162  * integrating new HUD reticle and shield icons
163  * 
164  * 36    11/03/97 5:38p Dave
165  * Cleaned up more multiplayer sequencing. Added OBJ_OBSERVER module/type.
166  * Restructured HUD_config structs/flags.
167  * 
168  * $NoKeywords: $
169  *
170 */
171
172 #include "2d.h"
173
174 #include "hudreticle.h"
175 #include "hud.h"
176 #include "pixel.h"
177 #include "math.h"
178 #include "player.h"
179 #include "ship.h"
180 #include "freespace.h"
181 #include "ai.h"
182 #include "bmpman.h"
183 #include "key.h"
184 #include "timer.h"
185 #include "math.h"
186 #include "gamesnd.h"
187 #include "hudtargetbox.h"
188 #include "multi.h"
189 #include "emp.h"
190 #include "localize.h"
191
192 static int Reticle_inited = 0;
193
194 #define NUM_RETICLE_ANIS                        6               // keep up to date when modifying the number of reticle ani files
195
196 #define RETICLE_TOP_ARC                         0
197 #define RETICLE_LASER_WARN                      1
198 #define RETICLE_LOCK_WARN                       2
199 #define RETICLE_LEFT_ARC                        3
200 #define RETICLE_RIGHT_ARC                       4
201 //#define RETICLE_ONE_PRIMARY           5
202 //#define RETICLE_TWO_PRIMARY           6
203 //#define RETICLE_ONE_SECONDARY         7
204 //#define RETICLE_TWO_SECONDARY         8
205 //#define RETICLE_THREE_SECONDARY       9
206 // #define RETICLE_LAUNCH_LABEL         5
207 #define RETICLE_CENTER                          5
208
209 int Hud_throttle_frame_h[GR_NUM_RESOLUTIONS] = {
210         85,
211         136
212 };
213 int Hud_throttle_frame_w[GR_NUM_RESOLUTIONS] = {
214         49, 
215         78
216 };
217 int Hud_throttle_frame_bottom_y[GR_NUM_RESOLUTIONS] = {
218         325,
219         520
220 };
221 int Hud_throttle_h[GR_NUM_RESOLUTIONS] = {
222         50,
223         80
224 };
225 int Hud_throttle_bottom_y[GR_NUM_RESOLUTIONS] = {
226         307,
227         491
228 };
229 int Hud_throttle_aburn_h[GR_NUM_RESOLUTIONS] = {
230         17,
231         27
232 };
233 int Hud_throttle_aburn_button[GR_NUM_RESOLUTIONS] = {
234         259,
235         414
236 };
237
238 int Outer_circle_radius[GR_NUM_RESOLUTIONS] = {
239         104,
240         166
241 };
242
243 int Hud_reticle_center[GR_NUM_RESOLUTIONS][2] = {
244         { // GR_640
245                 320, 242
246         },
247         { // GR_1024
248                 512, 385
249         }
250 };
251
252 char Reticle_frame_names[GR_NUM_RESOLUTIONS][NUM_RETICLE_ANIS][MAX_FILENAME_LEN] = 
253 {
254 //XSTR:OFF
255         { // GR_640
256                 "toparc1",
257                 "toparc2",
258                 "toparc3",
259                 "leftarc",
260                 "rightarc1",
261 /*              "rightarc2",
262                 "rightarc3",
263                 "rightarc4",
264                 "rightarc5",
265                 "rightarc6",    
266                 "toparc4",      */
267                 "reticle1",     
268         }, 
269         { // GR_1024
270                 "2_toparc1",
271                 "2_toparc2",
272                 "2_toparc3",
273                 "2_leftarc",
274                 "2_rightarc1",
275 /*              "2_rightarc2",
276                 "2_rightarc3",
277                 "2_rightarc4",
278                 "2_rightarc5",
279                 "2_rightarc6",  
280                 "2_toparc4",    */
281                 "2_reticle1",   
282         }
283 //XSTR:ON
284 };
285
286 // reticle frame coords
287 int Reticle_frame_coords[GR_NUM_RESOLUTIONS][NUM_RETICLE_ANIS][2] = {
288         { // GR_640
289                 {241, 137},
290                 {400, 245},
291                 {394, 261},
292                 {216, 168},
293                 {359, 168},
294 //              {406, 253},
295 //              {406, 253},
296 //              {391, 276},
297 //              {391, 276},
298 //              {391, 276},
299 //              {297, 161},
300                 {308, 235}
301         }, 
302         { // GR_1024
303                 {386, 219},
304                 {640, 393},
305                 {631, 419},
306                 {346, 269},
307                 {574, 269},
308 //              {649, 401},
309 //              {649, 401},
310 //              {625, 438},
311 //              {625, 438},
312 //              {625, 438},
313 //              {475, 258},
314                 {493, 370}
315         }
316 };
317
318 // "launch" gauge coords
319 int Reticle_launch_coords[GR_NUM_RESOLUTIONS][2] = {
320         { // GR_640
321                 297,    161
322         },
323         { // GR_1024
324                 475,    258
325         }
326 };
327
328 hud_frames Reticle_gauges[NUM_RETICLE_ANIS];
329
330 #define THREAT_DUMBFIRE                         (1<<0)
331 #define THREAT_ATTEMPT_LOCK             (1<<1)
332 #define THREAT_LOCK                                     (1<<2)
333
334 #define THREAT_UPDATE_DUMBFIRE_TIME             1000            // time between checking for dumbfire threats
335 #define THREAT_UPDATE_LOCK_TIME                 500             // time between checking for lock threats
336
337 #define THREAT_DUMBFIRE_FLASH                           180
338 #define THREAT_LOCK_FLASH                                       180
339 static int Threat_dumbfire_timer;               // timestamp for when to show next flashing frame for dumbfire threat
340 static int Threat_lock_timer;                           // timestamp for when to show next flashing frame for lock threat
341
342 static int Threat_dumbfire_frame;                       // frame offset of current dumbfire flashing warning
343 static int Threat_lock_frame;                           // frame offset of current lock flashing warning
344
345 // coordinates
346 static int Max_speed_coords[GR_NUM_RESOLUTIONS][2] = 
347 {
348         { // GR_640
349                 236, 254
350         }, 
351         { // GR_1024
352                 377, 406
353         }
354 };
355 static int Zero_speed_coords[GR_NUM_RESOLUTIONS][2] = {
356         { // GR_640
357                 252, 303
358         },
359         { // GR_1024
360                 403, 485
361         }
362 };
363
364 // Called at the start of each level.. use Reticle_inited so we only load frames once
365 void hud_init_reticle()
366 {
367         int                     i;
368         hud_frames      *hfp;
369
370         Threat_dumbfire_timer = timestamp(0);
371         Threat_lock_timer = timestamp(0);
372         Threat_dumbfire_frame = 1;
373         Threat_lock_frame = 1;
374         Player->threat_flags = 0;
375         Player->update_dumbfire_time = timestamp(0);            
376         Player->update_lock_time = timestamp(0);
377
378         if ( Reticle_inited ) {
379                 return;
380         }
381
382         for ( i = 0; i < NUM_RETICLE_ANIS; i++ ) {
383                 hfp = &Reticle_gauges[i];
384                 hfp->first_frame = bm_load_animation(Reticle_frame_names[gr_screen.res][i], &hfp->num_frames);
385                 if ( hfp->first_frame < 0 ) {
386                         Warning(LOCATION,"Cannot load hud ani: %s\n", Reticle_frame_names[gr_screen.res][i]);
387                 }
388         }
389
390         Reticle_inited = 1;
391 }
392
393 // called once per frame to update the reticle gauges.  Makes calls to
394 // ship_dumbfire_threat() and ship_lock_threat() and updates Threat_flags.
395 void hud_update_reticle( player *pp )
396 {
397         int rval;
398         ship *shipp;
399
400         // multiplayer clients won't call this routine
401         if ( MULTIPLAYER_CLIENT || MULTI_OBSERVER(Net_players[MY_NET_PLAYER_NUM]))
402                 return;
403
404         shipp = &Ships[Objects[pp->objnum].instance];
405
406         if ( ship_dumbfire_threat(shipp) ) {
407                 pp->threat_flags |= THREAT_DUMBFIRE;
408                 pp->update_dumbfire_time = timestamp(THREAT_UPDATE_DUMBFIRE_TIME);
409         }
410
411         if ( timestamp_elapsed(pp->update_dumbfire_time) ) {
412                 pp->update_dumbfire_time = timestamp(THREAT_UPDATE_DUMBFIRE_TIME);
413                 pp->threat_flags &= ~THREAT_DUMBFIRE;
414         }
415
416         if ( timestamp_elapsed(pp->update_lock_time) ) {
417                 pp->threat_flags &= ~(THREAT_LOCK | THREAT_ATTEMPT_LOCK);
418                 pp->update_lock_time = timestamp(THREAT_UPDATE_LOCK_TIME);
419                 rval = ship_lock_threat(shipp);
420                 if ( rval == 1 ) {
421                         pp->threat_flags |= THREAT_ATTEMPT_LOCK;
422                 } else if ( rval == 2 ) {
423                         pp->threat_flags |= THREAT_LOCK;
424                 }
425         }
426 }
427
428 // draw left arc (the dark portion of the throttle gauge)
429 void hud_render_throttle_background(int y_end)
430 {
431         int x,y,w,h;
432
433         hud_set_gauge_color(HUD_THROTTLE_GAUGE);
434
435         x = Reticle_frame_coords[gr_screen.res][RETICLE_LEFT_ARC][0];
436         y = Reticle_frame_coords[gr_screen.res][RETICLE_LEFT_ARC][1];
437
438         bm_get_info( Reticle_gauges[RETICLE_LEFT_ARC].first_frame+1,&w,&h);     
439
440         if ( y_end > y ) {
441                 GR_AABITMAP_EX(Reticle_gauges[RETICLE_LEFT_ARC].first_frame+1, x, y, w, y_end-y+1, 0, 0);               
442         }
443 }
444
445 // draw left arc (the bright portion of the throttle gauge)
446 void hud_render_throttle_foreground(int y_end)
447 {
448         int x,y,w,h;
449
450         hud_set_gauge_color(HUD_THROTTLE_GAUGE);
451
452         x = Reticle_frame_coords[gr_screen.res][RETICLE_LEFT_ARC][0];
453         y = Reticle_frame_coords[gr_screen.res][RETICLE_LEFT_ARC][1];
454
455         bm_get_info( Reticle_gauges[RETICLE_LEFT_ARC].first_frame+1,&w,&h);
456
457         if ( y_end < Hud_throttle_frame_bottom_y[gr_screen.res] ) {             
458                 GR_AABITMAP_EX(Reticle_gauges[RETICLE_LEFT_ARC].first_frame+2, x, y_end, w, h-(y_end-y), 0, y_end-y);           
459         }
460 }
461
462 // Draw the throttle speed number
463 void hud_render_throttle_speed(float current_speed, int y_end)
464 {
465         char buf[32];
466         int sx, sy, x_pos, y_pos, w, h;
467
468         hud_set_gauge_color(HUD_THROTTLE_GAUGE);
469
470         // y_end is the y-coordinate of the current throttle setting, calc x-coordinate for edge of 
471         // circle (x^2 + y^2 = r^2)
472         y_pos = Hud_reticle_center[gr_screen.res][1] - y_end;
473         x_pos = (int)sqrt(double(Outer_circle_radius[gr_screen.res] * Outer_circle_radius[gr_screen.res] - y_pos * y_pos) );
474         x_pos = Hud_reticle_center[gr_screen.res][0] - x_pos;
475
476         // draw current speed at (x_pos, y_end);
477         sprintf(buf, "%d", fl2i(current_speed+0.5f));
478         hud_num_make_mono(buf);
479         gr_get_string_size(&w, &h, buf);
480         sx = x_pos - w - 2;
481         sy = fl2i(y_end - h/2.0f + 1.5);
482         gr_printf(sx, sy, buf);
483
484         if ( Players[Player_num].flags & PLAYER_FLAGS_MATCH_TARGET ) {
485                 int offset;
486                 if ( current_speed <= 9.5 ) {
487                         offset = 0;
488                 } else {
489                         offset = 3;
490                 }
491 #if defined(GERMAN_BUILD)
492                 // print an m, cuz the voice says its an m.  
493                 // its a normal m cuz the german font has no special m (its an a)
494                 gr_string(sx+offset, sy + h, "m");
495 #else
496                 gr_printf(sx+offset, sy + h, "%c", Lcl_special_chars + 3);
497 #endif
498         }
499 }
500
501 // draw the "desired speed" bar on the throttle
502 void hud_render_throttle_line(int y)
503 {
504         // hud_set_bright_color();
505         hud_set_gauge_color(HUD_THROTTLE_GAUGE, HUD_C_BRIGHT);
506
507         GR_AABITMAP_EX(Reticle_gauges[RETICLE_LEFT_ARC].first_frame+3, Reticle_frame_coords[gr_screen.res][RETICLE_LEFT_ARC][0], y, Hud_throttle_frame_w[gr_screen.res], 1, 0, y-Reticle_frame_coords[gr_screen.res][RETICLE_LEFT_ARC][1]);     
508 }
509
510 // Draw the throttle gauge along the left arc of the reticle
511 void hud_show_throttle()
512 {
513         float   desired_speed, max_speed, current_speed, percent_max, percent_aburn_max;
514         int     desired_y_pos, y_end;
515
516         ship_info       *sip;
517         sip = &Ship_info[Player_ship->ship_info_index];
518
519         current_speed = Player_obj->phys_info.fspeed;
520         if ( current_speed < 0.0f){
521                 current_speed = 0.0f;
522         }
523
524         max_speed = Ships[Player_obj->instance].current_max_speed;
525         if ( max_speed <= 0 ) {
526                 max_speed = sip->max_vel.z;
527         }
528
529         desired_speed = Player->ci.forward * max_speed;
530         if ( desired_speed < 0.0f ){            // so ships that go backwards don't force the indicators below where they can go
531                 desired_speed = 0.0f;
532         }
533
534         desired_y_pos = Hud_throttle_bottom_y[gr_screen.res] - fl2i(Hud_throttle_h[gr_screen.res]*desired_speed/max_speed+0.5f) - 1;
535
536         Assert(max_speed != 0);
537         percent_max = current_speed / max_speed;
538
539         percent_aburn_max = 0.0f;
540         if ( percent_max > 1 ) {
541                 percent_max = 1.0f;
542                 percent_aburn_max = (current_speed - max_speed) / (sip->afterburner_max_vel.z - max_speed);
543                 if ( percent_aburn_max > 1.0f ) {
544                         percent_aburn_max = 1.0f;
545                 }
546                 if ( percent_aburn_max < 0 ) {
547                         percent_aburn_max = 0.0f;
548                 }
549         }
550
551         y_end = Hud_throttle_bottom_y[gr_screen.res] - fl2i(Hud_throttle_h[gr_screen.res]*percent_max+0.5f);
552         if ( percent_aburn_max > 0 ) {
553                 y_end -= fl2i(percent_aburn_max * Hud_throttle_aburn_h[gr_screen.res] + 0.5f);
554         }
555
556         if ( Player_obj->phys_info.flags & PF_AFTERBURNER_ON ) {
557                 desired_y_pos = 240;
558         }
559
560         // draw left arc (the dark portion of the throttle gauge)
561         // hud_render_throttle_background(y_end);
562
563         // draw throttle speed number
564         hud_render_throttle_speed(current_speed, y_end);
565
566         // draw the "desired speed" bar on the throttle
567         hud_render_throttle_line(desired_y_pos);
568
569         // draw left arc (the bright portion of the throttle gauge)
570         hud_render_throttle_foreground(y_end);
571
572         gr_printf(Max_speed_coords[gr_screen.res][0], Max_speed_coords[gr_screen.res][1], "%d",fl2i(max_speed));
573         gr_printf(Zero_speed_coords[gr_screen.res][0], Zero_speed_coords[gr_screen.res][1], XSTR( "0", 292));
574 }
575
576 /*
577 // Draw the primary and secondary weapon indicators along the right arc of the reticle
578 void hud_show_reticle_weapons()
579 {
580         int                     gauge_index=0, frame_offset=0;
581         ship_weapon     *swp;
582
583         swp = &Player_ship->weapons;
584
585         switch( swp->num_primary_banks ) {
586                 case 0:
587                         gauge_index = -1;
588                         break;
589
590                 case 1:
591                         gauge_index = RETICLE_ONE_PRIMARY;
592                         if ( Player_ship->weapons.current_primary_bank == -1 ) {
593                                 frame_offset = 0;       
594                         } else {
595                                 frame_offset = 1;       
596                         }
597                         break;
598
599                 case 2:
600                         gauge_index = RETICLE_TWO_PRIMARY;
601                         if ( swp->current_primary_bank == -1 ) {
602                                 frame_offset = 0;       
603                         } else {
604                                 if ( Player_ship->flags & SF_PRIMARY_LINKED ) {
605                                         frame_offset = 3;
606                                 } else {
607                                         if ( swp->current_primary_bank == 0 ) {
608                                                 frame_offset = 1;
609                                         } else {
610                                                 frame_offset = 2;
611                                         }
612                                 }
613                         }
614                         break;
615
616                 default:
617                         Int3(); // shouldn't happen (get Alan if it does)
618                         return;
619                         break;
620         }
621         
622         if ( gauge_index != -1 ) {
623                 GR_AABITMAP(Reticle_gauges[gauge_index].first_frame+frame_offset, Reticle_frame_coords[gr_screen.res][gauge_index][0], Reticle_frame_coords[gr_screen.res][gauge_index][1]);            
624         }
625
626         int num_banks = swp->num_secondary_banks;
627         if ( num_banks <= 0 ) {
628                 num_banks = Ship_info[Player_ship->ship_info_index].num_secondary_banks;
629         }
630
631         switch( num_banks ) {
632                 case 0:
633                         Int3();
634                         gauge_index = -1;
635                         break;
636
637                 case 1:
638                         gauge_index = RETICLE_ONE_SECONDARY;
639                         break;
640
641                 case 2:
642                         gauge_index = RETICLE_TWO_SECONDARY;
643                         break;
644
645                 case 3:
646                         gauge_index = RETICLE_THREE_SECONDARY;
647                         break;
648
649                 default:
650                         Int3(); // shouldn't happen (get Alan if it does)
651                         return;
652                         break;
653         }
654         
655         if ( gauge_index != -1 ) {
656                 if ( swp->num_secondary_banks <= 0 ) {
657                         frame_offset = 0;
658                 } else {
659                         frame_offset = swp->current_secondary_bank+1;
660                 }
661
662                 GR_AABITMAP(Reticle_gauges[gauge_index].first_frame+frame_offset, Reticle_frame_coords[gr_screen.res][gauge_index][0], Reticle_frame_coords[gr_screen.res][gauge_index][1]);            
663         }
664 }
665 */
666
667 // Draw the lock threat gauge on the HUD.  Use Threat_flags to determine if a 
668 // threat exists, and draw flashing frames.
669 void hud_show_lock_threat()
670 {
671         int frame_offset;
672
673         if ( Player->threat_flags & (THREAT_LOCK | THREAT_ATTEMPT_LOCK) ) {
674                 if ( timestamp_elapsed(Threat_lock_timer) ) {
675                         if ( Player->threat_flags & THREAT_LOCK )  {
676                                 Threat_lock_timer = timestamp(fl2i(THREAT_LOCK_FLASH/2.0f));
677                         } else {
678                                 Threat_lock_timer = timestamp(THREAT_LOCK_FLASH);
679                         }
680                         Threat_lock_frame++;
681                         if ( Threat_lock_frame > 2 ) {
682                                 Threat_lock_frame = 1;
683                         }
684                         if ( (Threat_lock_frame == 2) && (Player->threat_flags & THREAT_ATTEMPT_LOCK ) ) {
685                                 snd_play( &Snds[SND_THREAT_FLASH]);
686                         }
687                 }
688                 frame_offset = Threat_lock_frame;
689         } else {
690                 frame_offset = 0;
691         }
692
693         hud_set_gauge_color(HUD_THREAT_GAUGE);
694
695         GR_AABITMAP(Reticle_gauges[RETICLE_LOCK_WARN].first_frame+frame_offset, Reticle_frame_coords[gr_screen.res][RETICLE_LOCK_WARN][0], Reticle_frame_coords[gr_screen.res][RETICLE_LOCK_WARN][1]);
696
697         // "launch" flash
698         if ( (frame_offset > 0) && (Player->threat_flags & THREAT_LOCK) ) {
699                 if ( hud_targetbox_flash_expired(TBOX_FLASH_CMEASURE) ) {
700                         // hack
701                         int bright;
702                         if(frame_offset % 2){
703                                 bright = 1;
704                         } else {
705                                 bright = 0;
706                         }
707                         // GR_AABITMAP(Reticle_gauges[RETICLE_LAUNCH_LABEL].first_frame+frame_offset%2, Reticle_frame_coords[gr_screen.res][RETICLE_LAUNCH_LABEL][0], Reticle_frame_coords[gr_screen.res][RETICLE_LAUNCH_LABEL][1]);
708
709                         // use hud text flash gauge code
710                         hud_show_text_flash_icon(XSTR("Launch", 1507), Reticle_launch_coords[gr_screen.res][1], bright);
711                 }
712         }
713 }
714
715 // Draw the dumbfire threat gauge on the HUD.  Use Threat_flags to determine if a
716 // threat exists, and draw flashing frames.
717 void hud_show_dumbfire_threat()
718 {
719         int frame_offset;
720
721         if ( Player->threat_flags & THREAT_DUMBFIRE ) {
722                 if ( timestamp_elapsed(Threat_dumbfire_timer) ) {
723                         Threat_dumbfire_timer = timestamp(THREAT_DUMBFIRE_FLASH);
724                         Threat_dumbfire_frame++;
725                         if ( Threat_dumbfire_frame > 2 ) {
726                                 Threat_dumbfire_frame = 1;
727                         }
728                 }
729                 frame_offset = Threat_dumbfire_frame;
730         } else {
731                 frame_offset = 0;
732         }
733
734         hud_set_gauge_color(HUD_THREAT_GAUGE);
735
736         GR_AABITMAP(Reticle_gauges[RETICLE_LASER_WARN].first_frame + frame_offset, Reticle_frame_coords[gr_screen.res][RETICLE_LASER_WARN][0], Reticle_frame_coords[gr_screen.res][RETICLE_LASER_WARN][1]);     
737 }
738
739 // Draw the center of the reticle
740 void hud_show_center_reticle()
741 {
742         Assert(Reticle_gauges[RETICLE_CENTER].first_frame != -1 );
743
744 //      hud_set_default_color();
745         // hud_set_bright_color();
746         hud_set_gauge_color(HUD_CENTER_RETICLE, HUD_C_BRIGHT);
747
748         GR_AABITMAP(Reticle_gauges[RETICLE_CENTER].first_frame, Reticle_frame_coords[gr_screen.res][RETICLE_CENTER][0], Reticle_frame_coords[gr_screen.res][RETICLE_CENTER][1]);
749 }
750
751 // Draw top portion of reticle
752 void hud_show_top_arc()
753 {
754         hud_set_gauge_color(HUD_CENTER_RETICLE);
755
756         // hud_set_default_color();
757         if ( hud_gauge_active(HUD_THREAT_GAUGE) ) {     
758                 // draw top arc
759                 GR_AABITMAP(Reticle_gauges[RETICLE_TOP_ARC].first_frame+1, Reticle_frame_coords[gr_screen.res][RETICLE_TOP_ARC][0], Reticle_frame_coords[gr_screen.res][RETICLE_TOP_ARC][1]);           
760
761                 // draw dumbfire threat
762                 hud_show_dumbfire_threat();
763
764                 // draw lock threat
765                 hud_show_lock_threat();
766         } else {                
767                 // draw top arc without any holes
768                 GR_AABITMAP(Reticle_gauges[RETICLE_TOP_ARC].first_frame, Reticle_frame_coords[gr_screen.res][RETICLE_TOP_ARC][0], Reticle_frame_coords[gr_screen.res][RETICLE_TOP_ARC][1]);
769         }
770 }
771
772 // Draw right portion of reticle
773 void hud_show_right_arc()
774 {       
775         hud_set_gauge_color(HUD_CENTER_RETICLE);
776
777         GR_AABITMAP(Reticle_gauges[RETICLE_RIGHT_ARC].first_frame+1, Reticle_frame_coords[gr_screen.res][RETICLE_RIGHT_ARC][0], Reticle_frame_coords[gr_screen.res][RETICLE_RIGHT_ARC][1]);             
778                 
779         // draw the weapons indicators in the holes along the right arc
780         /*
781         if ( hud_gauge_active(HUD_WEAPON_LINKING_GAUGE) ) {             
782                 // draw right arc with holes in it
783                 GR_AABITMAP(Reticle_gauges[RETICLE_RIGHT_ARC].first_frame+1, Reticle_frame_coords[gr_screen.res][RETICLE_RIGHT_ARC][0], Reticle_frame_coords[gr_screen.res][RETICLE_RIGHT_ARC][1]);             
784
785 //              the following line was removed by Jasen to get rid of "undeclared identifier"
786 //              hehe - DB
787 //              hud_show_reticle_weapons();
788         } else {                
789                 // draw right arc without any holes
790                 GR_AABITMAP(Reticle_gauges[RETICLE_RIGHT_ARC].first_frame, Reticle_frame_coords[gr_screen.res][RETICLE_RIGHT_ARC][0], Reticle_frame_coords[gr_screen.res][RETICLE_RIGHT_ARC][1]);
791         }
792         */
793 }
794
795 // Draw the left portion of the reticle
796 void hud_show_left_arc()
797 {                       
798         // draw left arc (the dark portion of the throttle gauge)
799         hud_set_gauge_color(HUD_CENTER_RETICLE);        
800         GR_AABITMAP(Reticle_gauges[RETICLE_LEFT_ARC].first_frame, Reticle_frame_coords[gr_screen.res][RETICLE_LEFT_ARC][0], Reticle_frame_coords[gr_screen.res][RETICLE_LEFT_ARC][1]);                  
801         
802         // draw the throttle
803         if ( hud_gauge_active(HUD_THROTTLE_GAUGE) ) {
804                 hud_set_gauge_color(HUD_THROTTLE_GAUGE);
805                 hud_show_throttle();            
806         } 
807 }
808
809 // called once per frame from HUD_render_2d() to draw the reticle gauges
810 void hud_show_reticle()
811 {
812         if ( !(Viewer_mode & VM_OTHER_SHIP) ) {
813                 hud_show_top_arc();
814                 hud_show_right_arc();
815                 hud_show_left_arc();
816         }
817
818         // draw the center of the reticle
819         if ( hud_gauge_active(HUD_CENTER_RETICLE) ) {
820                 hud_show_center_reticle();
821         }
822 }
823
824 void hudreticle_page_in()
825 {
826         hud_frames      *hfp;
827
828         int i;
829         for ( i = 0; i < NUM_RETICLE_ANIS; i++ ) {
830                 hfp = &Reticle_gauges[i];
831                 bm_page_in_aabitmap( hfp->first_frame, hfp->num_frames);
832         }
833
834 }