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