File: hudreticle.cpp

package info (click to toggle)
freespace2 3.7.0%2Brepack-2
  • links: PTS, VCS
  • area: non-free
  • in suites: jessie, jessie-kfreebsd
  • size: 22,848 kB
  • ctags: 41,897
  • sloc: cpp: 369,931; makefile: 1,060; xml: 129; sh: 112
file content (984 lines) | stat: -rw-r--r-- 25,746 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
/*
 * Copyright (C) Volition, Inc. 1999.  All rights reserved.
 *
 * All source code herein is the property of Volition, Inc. You may not sell 
 * or otherwise commercially exploit the source or things you created based on the 
 * source.
 *
*/ 




#include "hud/hudreticle.h"
#include "hud/hud.h"
#include "playerman/player.h"
#include "ship/ship.h"
#include "io/timer.h"
#include "gamesnd/gamesnd.h"
#include "hud/hudtargetbox.h"
#include "weapon/emp.h"
#include "localization/localize.h"
#include "network/multi.h"

#define NUM_RETICLE_ANIS			11		// keep up to date when modifying the number of reticle ani files

#define RETICLE_TOP_ARC				0
#define RETICLE_LASER_WARN			1
#define RETICLE_LOCK_WARN			2
#define RETICLE_LEFT_ARC			3
#define RETICLE_RIGHT_ARC			4
#define RETICLE_ONE_PRIMARY			5
#define RETICLE_TWO_PRIMARY			6
#define RETICLE_ONE_SECONDARY		7
#define RETICLE_TWO_SECONDARY		8
#define RETICLE_THREE_SECONDARY		9
//#define RETICLE_LAUNCH_LABEL		5
#define RETICLE_CENTER				10

int Hud_throttle_frame_w[GR_NUM_RESOLUTIONS] = {
	49, 
	78
};
int Hud_throttle_h[GR_NUM_RESOLUTIONS] = {
	50, 80
};
int Hud_throttle_bottom_y[NUM_HUD_RETICLE_STYLES][GR_NUM_RESOLUTIONS] = {
	{ 309, 494 },
	{ 307, 491 }
};
int Hud_throttle_aburn_h[GR_NUM_RESOLUTIONS] = {
	17,
	27
};
int Hud_throttle_aburn_button[GR_NUM_RESOLUTIONS] = {
	259,
	414
};

int Outer_circle_radius[GR_NUM_RESOLUTIONS] = {
	104,
	166
};

int Hud_reticle_center[GR_NUM_RESOLUTIONS][2] =
{
	{ // GR_640
		320, 242
	},
	{ // GR_1024
		512, 387
	}
};

char Reticle_frame_names[NUM_HUD_RETICLE_STYLES][GR_NUM_RESOLUTIONS][NUM_RETICLE_ANIS][MAX_FILENAME_LEN] = 
{
//XSTR:OFF
	{
		{ // GR_640
			"toparc1_fs1",
			"toparc2_fs1",
			"toparc3_fs1",
			"leftarc_fs1",
			"rightarc1_fs1",
			"rightarc2_fs1",
			"rightarc3_fs1",
			"rightarc4_fs1",
			"rightarc5_fs1",
			"rightarc6_fs1",
//			"toparc4_fs1",
			"reticle1_fs1",	
		}, 
		{ // GR_1024
			"2_toparc1_fs1",
			"2_toparc2_fs1",
			"2_toparc3_fs1",
			"2_leftarc_fs1",
			"2_rightarc1_fs1",
			"2_rightarc2_fs1",
			"2_rightarc3_fs1",
			"2_rightarc4_fs1",
			"2_rightarc5_fs1",
			"2_rightarc6_fs1",
//			"2_toparc4_fs1",
			"2_reticle1_fs1",	
		}
	},
	{
		{ // GR_640
			"toparc1",
			"toparc2",
			"toparc3",
			"leftarc",
			"rightarc1",
			"<none>",
			"<none>",
			"<none>",
			"<none>",
			"<none>",
//			"<none>",
			"reticle1",	
		}, 
		{ // GR_1024
			"2_toparc1",
			"2_toparc2",
			"2_toparc3",
			"2_leftarc",
			"2_rightarc1",
			"<none>",
			"<none>",
			"<none>",
			"<none>",
			"<none>",
//			"<none>",
			"2_reticle1",	
		}
	}
//XSTR:ON
};

// reticle frame coords
int Reticle_frame_coords[NUM_HUD_RETICLE_STYLES][GR_NUM_RESOLUTIONS][NUM_RETICLE_ANIS][2] =
{
	{
		{ // GR_640
			{241, 137},
			{300, 137},
			{320, 137},
			{217, 244},
			{374, 242},
			{406, 253},
			{406, 253},
			{391, 276},
			{391, 276},
			{391, 276},
//			{297, 162},
			{308, 235}
		}, 
		{ // GR_1024
			{386, 219},
			{480, 219},
			{512, 219},
			{347, 390},
			{598, 387},
			{650, 405},
			{650, 405},
			{626, 442},
			{626, 442},
			{626, 442},
//			{475, 259},
			{493, 376}
		},
	},
	{
		{ // GR_640
			{241, 137},
			{400, 245},
			{394, 261},
			{216, 168},
			{359, 168},
			{406, 253},
			{406, 253},
			{391, 276},
			{391, 276},
			{391, 276},
//			{297, 161},
			{308, 235}
		}, 
		{ // GR_1024
			{386, 219},
			{640, 393},
			{631, 419},
			{346, 269},
			{574, 269},
			{649, 401},
			{649, 401},
			{625, 438},
			{625, 438},
			{625, 438},
//			{475, 258},
			{493, 370}
		}
	}
};

// "launch" gauge coords
int Reticle_launch_coords[GR_NUM_RESOLUTIONS][2] = {
	{ // GR_640
		297,	161
	},
	{ // GR_1024
		475,	258
	}
};

#define THREAT_DUMBFIRE				(1<<0)
#define THREAT_ATTEMPT_LOCK			(1<<1)
#define THREAT_LOCK					(1<<2)

#define THREAT_UPDATE_DUMBFIRE_TIME		1000		// time between checking for dumbfire threats
#define THREAT_UPDATE_LOCK_TIME			500		// time between checking for lock threats

#define THREAT_DUMBFIRE_FLASH				180
#define THREAT_LOCK_FLASH					180
static int Threat_lock_timer;				// timestamp for when to show next flashing frame for lock threat
static int Threat_lock_frame;				// frame offset of current lock flashing warning


HudGaugeReticle::HudGaugeReticle():
HudGauge(HUD_OBJECT_CENTER_RETICLE, HUD_CENTER_RETICLE, true, false, (VM_EXTERNAL | VM_DEAD_VIEW | VM_WARP_CHASE | VM_PADLOCK_ANY | VM_TOPDOWN | VM_OTHER_SHIP), 255, 255, 255)
{
}

void HudGaugeReticle::initBitmaps(char *fname)
{
	crosshair.first_frame = bm_load_animation(fname, &crosshair.num_frames);
	if (crosshair.first_frame < 0) {
		mprintf(("Cannot load hud ani: %s\n", fname));
	}
}

void HudGaugeReticle::initFirepointDisplay(bool firepoint, int scaleX, int scaleY, int size) {
	firepoint_display = firepoint;
	firepoint_scale_x = scaleX;
	firepoint_scale_y = scaleY;
	firepoint_size = size;
}

void HudGaugeReticle::render(float frametime)
{
	setGaugeColor(HUD_C_BRIGHT);

	renderBitmap(crosshair.first_frame, position[0], position[1]);

	if (firepoint_display) {
		fp.clear();
		getFirepointStatus();
		
		if (fp.size() > 0) {
			int ax, ay;
			bm_get_info(crosshair.first_frame, &ax, &ay);
			int centerX = position[0] + (ax / 2);
			int centerY = position[1] + (ay / 2);

			for (SCP_vector<firepoint>::iterator fpi = fp.begin(); fpi != fp.end(); ++fpi) {
				if (fpi->active == 2)
					setGaugeColor(HUD_C_BRIGHT);
				else if (fpi->active == 1)
					setGaugeColor(HUD_C_NORMAL);
				else
					setGaugeColor(HUD_C_DIM);
			
				renderCircle((int) (centerX + (fpi->xy.x * firepoint_scale_x)), (int) (centerY + (fpi->xy.y * firepoint_scale_y)), firepoint_size);
			}
		}
	}
}

void HudGaugeReticle::getFirepointStatus() {
	//First, get the player ship
	ship_info* pship;
	ship* shipp;
	polymodel* pm;

	Assert(Objects[Player->objnum].type == OBJ_SHIP);

	if (Objects[Player->objnum].type == OBJ_SHIP) {
		shipp = &Ships[Objects[Player->objnum].instance];
		pship = &Ship_info[shipp->ship_info_index];
	
		//Get the player eyepoint
		pm = model_get(pship->model_num);

		if (pm->n_guns > 0) { 
			eye eyepoint = pm->view_positions[shipp->current_viewpoint];
			vec2d ep = {eyepoint.pnt.xyz.x, eyepoint.pnt.xyz.y};

			for (int i = 0; i < pm->n_guns; i++) {
				int isactive = 0;

				if ( !timestamp_elapsed(shipp->weapons.next_primary_fire_stamp[i]) )
					isactive = 1;
				else if (timestamp_elapsed(shipp->weapons.primary_animation_done_time[i]))
					isactive = 1;
				else if (i == shipp->weapons.current_primary_bank || shipp->flags & SF_PRIMARY_LINKED)
					isactive = 2;

				for (int j = 0; j < pm->gun_banks[i].num_slots; j++) {
					firepoint tmp = { {ep.x - pm->gun_banks[i].pnt[j].xyz.x, ep.y - pm->gun_banks[i].pnt[j].xyz.y}, isactive};
					fp.push_back(tmp);
				}
			}
		}
	}
}

void HudGaugeReticle::pageIn()
{
	bm_page_in_aabitmap( crosshair.first_frame, crosshair.num_frames);
}

HudGaugeThrottle::HudGaugeThrottle():
HudGauge(HUD_OBJECT_THROTTLE, HUD_THROTTLE_GAUGE, true, false, (VM_EXTERNAL | VM_DEAD_VIEW | VM_WARP_CHASE | VM_PADLOCK_ANY | VM_OTHER_SHIP), 255, 255, 255)
{

}
void HudGaugeThrottle::initThrottleStartY(int y)
{
	Bottom_offset_y = y;
}

void HudGaugeThrottle::initThrottleSizes(int w, int h)
{
	throttle_w = w;
	throttle_h = h;
}

void HudGaugeThrottle::initAburnHeight(int h)
{
	throttle_aburn_h = h;
}

void HudGaugeThrottle::initMaxSpeedOffsets(int x, int y, bool show)
{
	Max_speed_offsets[0] = x;
	Max_speed_offsets[1] = y;
	Show_max_speed = show;
}

void HudGaugeThrottle::initZeroSpeedOffsets(int x, int y, bool show)
{
	Zero_speed_offsets[0] = x;
	Zero_speed_offsets[1] = y;
	Show_min_speed = show;
}

void HudGaugeThrottle::initOrbitCenterOffsets(int x, int y, bool orbiting)
{
	Orbit_center_offsets[0] = x;
	Orbit_center_offsets[1] = y;
	orbit = orbiting;
}

void HudGaugeThrottle::initOrbitRadius(int radius)
{
	orbit_radius = radius;
}

void HudGaugeThrottle::initTargetSpeedOffsets(int x, int y, bool show, bool percent)
{
	Target_speed_offsets[0] = x;
	Target_speed_offsets[1] = y;
	Show_target_speed = show;
	Show_percent = percent;
}

void HudGaugeThrottle::showBackground(bool show)
{
	Show_background = show;
}

void HudGaugeThrottle::initGlideOffsets(int x, int y, bool custom)
{
	Glide_offsets[0] = x;
	Glide_offsets[1] = y;
	Use_custom_glide = custom;
}

void HudGaugeThrottle::initMatchSpeedOffsets(int x, int y, bool custom)
{
	Match_speed_offsets[0] = x;
	Match_speed_offsets[1] = y;
	Use_custom_match_speed = custom;
}

void HudGaugeThrottle::initBitmaps(char *fname)
{
	throttle_frames.first_frame = bm_load_animation(fname, &throttle_frames.num_frames);

	if (throttle_frames.first_frame < 0) {
		mprintf(("Cannot load hud ani: %s\n", fname));
	}
}

void HudGaugeThrottle::pageIn()
{
	bm_page_in_aabitmap( throttle_frames.first_frame, throttle_frames.num_frames);
}

void HudGaugeThrottle::render(float frametime)
{
	float	desired_speed, max_speed, current_speed, absolute_speed, absolute_displayed_speed, max_displayed_speed, percent_max, percent_aburn_max;
	int	desired_y_pos, y_end;

	ship_info	*sip;
	sip = &Ship_info[Player_ship->ship_info_index];

	current_speed = Player_obj->phys_info.fspeed;
	if ( current_speed < 0.0f){
		current_speed = 0.0f;
	}

	max_speed = Ships[Player_obj->instance].current_max_speed;
	if ( max_speed <= 0 ) {
		max_speed = sip->max_vel.xyz.z;
	}

	absolute_speed = Player_obj->phys_info.speed;

	// scale by distance modifier from hud_guages.tbl for display purposes
	absolute_displayed_speed = absolute_speed * Hud_speed_multiplier;
	max_displayed_speed = max_speed * Hud_speed_multiplier;

	desired_speed = Player->ci.forward * max_speed;
	if ( desired_speed < 0.0f ){		// so ships that go backwards don't force the indicators below where they can go
		desired_speed = 0.0f;
	}

	desired_y_pos = position[1] + Bottom_offset_y - fl2i(throttle_h*desired_speed/max_speed+0.5f) - 1;

	if (max_speed <= 0) {
		percent_max = 0.0f;
	} else {
		percent_max = current_speed / max_speed;
	}

	percent_aburn_max = 0.0f;
	if ( percent_max > 1 ) {
		percent_max = 1.0f;
		percent_aburn_max = (current_speed - max_speed) / (sip->afterburner_max_vel.xyz.z - max_speed);
		if ( percent_aburn_max > 1.0f ) {
			percent_aburn_max = 1.0f;
		}
		if ( percent_aburn_max < 0 ) {
			percent_aburn_max = 0.0f;
		}
	}

	y_end = position[1] + Bottom_offset_y - fl2i(throttle_h*percent_max+0.5f);
	if ( percent_aburn_max > 0 ) {
		y_end -= fl2i(percent_aburn_max * throttle_aburn_h + 0.5f);
	}

	if ( Player_obj->phys_info.flags & PF_AFTERBURNER_ON ) {
		// default value is 240 when afterburner is on. 
		//I'm assuming that this value is basically Bottom_offset_y - throttle_aburn_h - throttle_h
		desired_y_pos = position[1] + Bottom_offset_y - throttle_aburn_h - throttle_h; 
	}

	setGaugeColor();
	
	if(Show_background) {
		renderThrottleBackground(y_end);
	} else {
		renderBitmap(throttle_frames.first_frame, position[0], position[1]);			
	}

	// draw throttle speed number
	//hud_render_throttle_speed(current_speed, y_end);
	// Absolute speed, not forward speed, for hud speed reticle - fixes the guage for sliding -- kazan
	renderThrottleSpeed(absolute_displayed_speed, y_end);

	// draw target speed if necessary
	if ( Show_target_speed ) {
		char buf[32];
		int w, h;

		if ( Show_percent ) {
			if ( Player_obj->phys_info.flags & PF_AFTERBURNER_ON ) {
				strcpy_s(buf, "A/B");
			} else {
				sprintf(buf, XSTR( "%d%%", 326), fl2i( (desired_speed/max_speed)*100 + 0.5f ));
			}
		} else {
			sprintf(buf, "%d", fl2i(desired_speed * Hud_speed_multiplier + 0.5f));
		}

		hud_num_make_mono(buf);
		gr_get_string_size(&w, &h, buf);

		renderString(position[0] + Target_speed_offsets[0] - w, position[1] + Target_speed_offsets[1], buf);
	}

	// draw the "desired speed" bar on the throttle
	renderThrottleLine(desired_y_pos);

	// draw left arc (the bright portion of the throttle gauge)
	renderThrottleForeground(y_end);

	if ( Show_max_speed ) {
		renderPrintf(position[0] + Max_speed_offsets[0], position[1] + Max_speed_offsets[1], "%d",fl2i(max_displayed_speed+0.5f));
	}
	
	if ( Show_min_speed ) {
		renderPrintf(position[0] + Zero_speed_offsets[0], position[1] + Zero_speed_offsets[1], XSTR( "0", 292));
	}
}

void HudGaugeThrottle::renderThrottleSpeed(float current_speed, int y_end)
{
	char buf[32];
	int sx, sy, x_pos, y_pos, w, h;

	//setGaugeColor();
	sprintf(buf, "%d", fl2i(current_speed+0.5f));
	hud_num_make_mono(buf);
	gr_get_string_size(&w, &h, buf);

	if ( orbit ) {
		// y_end is the y-coordinate of the current throttle setting, calc x-coordinate for edge of 
		// circle (x^2 + y^2 = r^2)
		y_pos = position[1] + Orbit_center_offsets[1] - y_end;
		x_pos = (int)sqrt(double(orbit_radius * orbit_radius - y_pos * y_pos) );
		x_pos = position[0] + Orbit_center_offsets[0] - x_pos;

		// draw current speed at (x_pos, y_end);
		sx = x_pos - w - 2;
		sy = fl2i(y_end - h/2.0f + 1.5);
	} else {
		sx = position[0] + Orbit_center_offsets[0] - w;
		sy = position[1] + Orbit_center_offsets[1];
	}
	
	renderPrintf(sx, sy, buf);

	if ( object_get_gliding(Player_obj) ) { 
		if ( Use_custom_glide ) {
			renderString(position[0] + Glide_offsets[0], position[1] + Glide_offsets[1], "GLIDE");
		} else {
			int offset;
			if ( current_speed <= 9.5 ) {
				offset = -31;
			} else if ( current_speed <= 99.5 ) {
				offset = -22;
			} else {
				offset = -13;
			}

			renderString(sx+offset, sy + h, "GLIDE");
		}
	} else if ( Players[Player_num].flags & PLAYER_FLAGS_MATCH_TARGET ) {
		if ( Use_custom_match_speed ) {
			if (Lcl_gr) {
				// print an m, cuz the voice says its an m.  
				// its a normal m cuz the german font has no special m (its an a)
				renderString(position[0] + Match_speed_offsets[0], position[1] + Match_speed_offsets[1], "m");
			} else {
				renderPrintf(position[0] + Match_speed_offsets[0], position[1] + Match_speed_offsets[1], "%c", Lcl_special_chars + 3);
			}
		} else {
			int offset;
			if ( current_speed <= 9.5 ) {
				offset = 0;
			} else {
				offset = 3;
			}

			if (Lcl_gr) {
				// print an m, cuz the voice says its an m.  
				// its a normal m cuz the german font has no special m (its an a)
				renderString(sx+offset, sy + h, "m");
			} else {
				renderPrintf(sx+offset, sy + h, "%c", Lcl_special_chars + 3);
			}
		}
	}
}

void HudGaugeThrottle::renderThrottleLine(int y_line)
{
	// hud_set_bright_color();
	//setGaugeColor(HUD_C_BRIGHT);

	renderBitmapEx(throttle_frames.first_frame+3, 
		position[0], y_line, 
		throttle_w, 1, 
		0, 
		y_line-position[1]);
}

void HudGaugeThrottle::renderThrottleForeground(int y_end)
{
	int w,h;

	//setGaugeColor();

	bm_get_info(throttle_frames.first_frame+1,&w,&h);

	if ( y_end < (position[1] + h - 1) ) {		
		renderBitmapEx(throttle_frames.first_frame + 2, position[0], y_end, w, h - (y_end - position[1]), 0, y_end - position[1]);
	}
}

void HudGaugeThrottle::renderThrottleBackground(int y_end)
{
	int w,h;

	//setGaugeColor();

	bm_get_info( throttle_frames.first_frame+1,&w,&h);

	if ( y_end > position[1] ) {
		renderBitmapEx(throttle_frames.first_frame+1, position[0], position[1], w, y_end-position[1]+1, 0, 0);		
	}
}

HudGaugeThreatIndicator::HudGaugeThreatIndicator():
HudGauge(HUD_OBJECT_THREAT, HUD_THREAT_GAUGE, true, false, (VM_EXTERNAL | VM_DEAD_VIEW | VM_WARP_CHASE | VM_PADLOCK_ANY | VM_OTHER_SHIP), 255, 255, 255)
{
}

void HudGaugeThreatIndicator::initLaserWarnOffsets(int x, int y)
{
	Laser_warn_offsets[0] = x;
	Laser_warn_offsets[1] = y;
}

void HudGaugeThreatIndicator::initLockWarnOffsets(int x, int y)
{
	Lock_warn_offsets[0] = x;
	Lock_warn_offsets[1] = y;
}

void HudGaugeThreatIndicator::initBitmaps(char *fname_arc, char *fname_laser, char *fname_lock)
{
	threat_arc.first_frame = bm_load_animation(fname_arc, &threat_arc.num_frames);
	if (threat_arc.first_frame < 0) {
		mprintf(("Cannot load hud ani: %s\n", fname_arc));
	}
	
	laser_warn.first_frame = bm_load_animation(fname_laser, &laser_warn.num_frames);
	if (laser_warn.first_frame < 0) {
		mprintf(("Cannot load hud ani: %s\n", fname_laser));
	}

	lock_warn.first_frame = bm_load_animation(fname_lock, &lock_warn.num_frames);
	if (lock_warn.first_frame < 0) {
		mprintf(("Cannot load hud ani: %s\n", fname_lock));
	}
}

void HudGaugeThreatIndicator::initialize()
{
	laser_warn_timer = timestamp(1);
	laser_warn_frame = 0;

	lock_warn_timer = timestamp(1);
	lock_warn_frame = 0;

	HudGauge::initialize();
}

void HudGaugeThreatIndicator::pageIn()
{
	bm_page_in_aabitmap(threat_arc.first_frame, threat_arc.num_frames);
	bm_page_in_aabitmap(laser_warn.first_frame, laser_warn.num_frames);
	bm_page_in_aabitmap(lock_warn.first_frame, lock_warn.num_frames);
}

void HudGaugeThreatIndicator::render(float frametime)
{
	setGaugeColor();
	renderBitmap(threat_arc.first_frame+1, position[0], position[1]);

	renderLaserThreat();
	renderLockThreat();
}

void HudGaugeThreatIndicator::renderLaserThreat()
{
	int frame_offset, num_frames;

	//Check how many frames the ani actually has
	num_frames = laser_warn.num_frames;
	//We need at least two frames here
	Assert( num_frames >= 2 );

	if ( Player->threat_flags & THREAT_DUMBFIRE ) {
		if ( timestamp_elapsed(laser_warn_timer) ) {
			laser_warn_timer = timestamp(THREAT_DUMBFIRE_FLASH);
			laser_warn_frame++;
			if ( laser_warn_frame > (num_frames - 1) ) { //The first frame being the default "off" setting, we need to cycle through all the other frames
				laser_warn_frame = 1;
			}
		}
		frame_offset = laser_warn_frame;
	} else {
		frame_offset = 0;
	}

	renderBitmap(laser_warn.first_frame + frame_offset, position[0] + Laser_warn_offsets[0], position[1] + Laser_warn_offsets[1]);	
}

void HudGaugeThreatIndicator::renderLockThreat()
{
	int frame_offset, num_frames;

	//Let's find out how many frames our ani has, and adjust accordingly
	num_frames = lock_warn.num_frames;
	//We need at least two frames here
	Assert( num_frames >= 2 );

	if ( Player->threat_flags & (THREAT_LOCK | THREAT_ATTEMPT_LOCK) ) {
		if ( timestamp_elapsed(lock_warn_timer) ) {
			if ( Player->threat_flags & THREAT_LOCK )  {
				lock_warn_timer = timestamp(fl2i(THREAT_LOCK_FLASH/2.0f));
			} else {
				lock_warn_timer = timestamp(THREAT_LOCK_FLASH);
			}
			lock_warn_frame++;
			if ( lock_warn_frame > (num_frames - 1) ) { //The first frame being the default "off" setting, we need to cycle through all the other frames
				lock_warn_frame = 1;
			}
		}
		frame_offset = lock_warn_frame;
	} else {
		frame_offset = 0;
	}

	renderBitmap(lock_warn.first_frame+frame_offset, position[0] + Lock_warn_offsets[0], position[1] + Lock_warn_offsets[1]);
}

HudGaugeWeaponLinking::HudGaugeWeaponLinking():
HudGauge(HUD_OBJECT_WEAPON_LINKING, HUD_THREAT_GAUGE, true, false, (VM_EXTERNAL | VM_DEAD_VIEW | VM_WARP_CHASE | VM_PADLOCK_ANY | VM_OTHER_SHIP), 255, 255, 255)
{
}

void HudGaugeWeaponLinking::init1PrimaryOffsets(int x, int y)
{
	Weapon_link_offsets[LINK_ONE_PRIMARY][0] = x;
	Weapon_link_offsets[LINK_ONE_PRIMARY][1] = y;
}

void HudGaugeWeaponLinking::init2PrimaryOffsets(int x, int y)
{
	Weapon_link_offsets[LINK_TWO_PRIMARY][0] = x;
	Weapon_link_offsets[LINK_TWO_PRIMARY][1] = y;
}

void HudGaugeWeaponLinking::init1SecondaryOffsets(int x, int y)
{
	Weapon_link_offsets[LINK_ONE_SECONDARY][0] = x;
	Weapon_link_offsets[LINK_ONE_SECONDARY][1] = y;
}

void HudGaugeWeaponLinking::init2SecondaryOffsets(int x, int y)
{
	Weapon_link_offsets[LINK_TWO_SECONDARY][0] = x;
	Weapon_link_offsets[LINK_TWO_SECONDARY][1] = y;
}

void HudGaugeWeaponLinking::init3SecondaryOffsets(int x, int y)
{
	Weapon_link_offsets[LINK_THREE_SECONDARY][0] = x;
	Weapon_link_offsets[LINK_THREE_SECONDARY][1] = y;
}

void HudGaugeWeaponLinking::initBitmaps(char *fname_arc, 
										char *fname_primary_link_1, 
										char *fname_primary_link_2, 
										char *fname_secondary_link_1, 
										char *fname_secondary_link_2, 
										char *fname_secondary_link_3)
{
	arc.first_frame = bm_load_animation(fname_arc, &arc.num_frames);
	if (arc.first_frame < 0) {
		Warning(LOCATION, "Cannot load hud ani: %s\n", fname_arc);
	}
	
	weapon_linking_modes[LINK_ONE_PRIMARY].first_frame = bm_load_animation(fname_primary_link_1, &weapon_linking_modes[LINK_ONE_PRIMARY].num_frames);
	if (weapon_linking_modes[LINK_ONE_PRIMARY].first_frame < 0) {
		Warning(LOCATION, "Cannot load hud ani: %s\n", fname_primary_link_1);
	}

	weapon_linking_modes[LINK_TWO_PRIMARY].first_frame = bm_load_animation(fname_primary_link_2, &weapon_linking_modes[LINK_TWO_PRIMARY].num_frames);
	if (weapon_linking_modes[LINK_TWO_PRIMARY].first_frame < 0) {
		Warning(LOCATION, "Cannot load hud ani: %s\n", fname_primary_link_2);
	}

	weapon_linking_modes[LINK_ONE_SECONDARY].first_frame = bm_load_animation(fname_secondary_link_1, &weapon_linking_modes[LINK_ONE_SECONDARY].num_frames);
	if (weapon_linking_modes[LINK_ONE_SECONDARY].first_frame < 0) {
		Warning(LOCATION, "Cannot load hud ani: %s\n", fname_secondary_link_1);
	}

	weapon_linking_modes[LINK_TWO_SECONDARY].first_frame = bm_load_animation(fname_secondary_link_2, &weapon_linking_modes[LINK_TWO_SECONDARY].num_frames);
	if (weapon_linking_modes[LINK_TWO_SECONDARY].first_frame < 0) {
		Warning(LOCATION, "Cannot load hud ani: %s\n", fname_secondary_link_2);
	}

	weapon_linking_modes[LINK_THREE_SECONDARY].first_frame = bm_load_animation(fname_secondary_link_3, &weapon_linking_modes[LINK_THREE_SECONDARY].num_frames);
	if (weapon_linking_modes[LINK_THREE_SECONDARY].first_frame < 0) {
		Warning(LOCATION, "Cannot load hud ani: %s\n", fname_secondary_link_3);
	}
}


void HudGaugeWeaponLinking::pageIn()
{
	bm_page_in_aabitmap(arc.first_frame, arc.num_frames);

	for(int i = 0; i < NUM_WEAPON_LINK_MODES; i++) {
		bm_page_in_aabitmap(weapon_linking_modes[i].first_frame, weapon_linking_modes[i].num_frames);
	}
}

void HudGaugeWeaponLinking::render(float frametime)
{
	int			gauge_index=0, frame_offset=0;
	ship_weapon	*swp;

	setGaugeColor();

	if (arc.first_frame >= 0) {
		renderBitmap(arc.first_frame+1, position[0], position[1]);
	}

	swp = &Player_ship->weapons;

	switch( swp->num_primary_banks ) {
		case 0:
			gauge_index = -1;
			break;

		case 1:
			gauge_index = LINK_ONE_PRIMARY;
			if ( Player_ship->weapons.current_primary_bank == -1 ) {
				frame_offset = 0;	
			} else {
				frame_offset = 1;	
			}
			break;

		case 2:
			gauge_index = LINK_TWO_PRIMARY;
			if ( swp->current_primary_bank == -1 ) {
				frame_offset = 0;	
			} else {
				if ( Player_ship->flags & SF_PRIMARY_LINKED ) {
					frame_offset = 3;
				} else {
					if ( swp->current_primary_bank == 0 ) {
						frame_offset = 1;
					} else {
						frame_offset = 2;
					}
				}
			}
			break;

		default:
			Int3();	// shouldn't happen (get Alan if it does)
			return;
			break;
	}
	
	if ( gauge_index != -1 ) {
		if (weapon_linking_modes[gauge_index].first_frame >= 0) {
			renderBitmap(weapon_linking_modes[gauge_index].first_frame+frame_offset, position[0] + Weapon_link_offsets[gauge_index][0], position[1] + Weapon_link_offsets[gauge_index][1]);
		}
	}

	int num_banks = swp->num_secondary_banks;
	if ( num_banks <= 0 ) {
		num_banks = Ship_info[Player_ship->ship_info_index].num_secondary_banks;
	}

	switch( num_banks ) {
		case 0:
			Int3();
			gauge_index = -1;
			break;

		case 1:
			gauge_index = LINK_ONE_SECONDARY;
			break;

		case 2:
			gauge_index = LINK_TWO_SECONDARY;
			break;

		case 3:
			gauge_index = LINK_THREE_SECONDARY;
			break;

		default:
			Int3();	// shouldn't happen (get Alan if it does)
			return;
			break;
	}
	
	if ( gauge_index != -1 ) {
		if ( swp->num_secondary_banks <= 0 ) {
			frame_offset = 0;
		} else {
			frame_offset = swp->current_secondary_bank+1;
		}
		if (weapon_linking_modes[gauge_index].first_frame >= 0) {
			renderBitmap(weapon_linking_modes[gauge_index].first_frame+frame_offset, position[0] + Weapon_link_offsets[gauge_index][0],  position[1] + Weapon_link_offsets[gauge_index][1]);
		}
	}
}

// Called at the start of each level.. use Reticle_inited so we only load frames once
void hud_init_reticle()
{
	Threat_lock_timer = timestamp(0);
	Threat_lock_frame = 1;
	Player->threat_flags = 0;
	Player->update_dumbfire_time = timestamp(0);		
	Player->update_lock_time = timestamp(0);
}

// called once per frame to update the reticle gauges.  Makes calls to
// ship_dumbfire_threat() and ship_lock_threat() and updates Threat_flags.
void hud_update_reticle( player *pp )
{
	int rval;
	ship *shipp;

	// multiplayer clients won't call this routine
	if ( MULTIPLAYER_CLIENT || MULTI_OBSERVER(Net_players[MY_NET_PLAYER_NUM]))
		return;

	shipp = &Ships[Objects[pp->objnum].instance];

	if ( ship_dumbfire_threat(shipp) ) {
		pp->threat_flags |= THREAT_DUMBFIRE;
		pp->update_dumbfire_time = timestamp(THREAT_UPDATE_DUMBFIRE_TIME);
	}

	if ( timestamp_elapsed(pp->update_dumbfire_time) ) {
		pp->update_dumbfire_time = timestamp(THREAT_UPDATE_DUMBFIRE_TIME);
		pp->threat_flags &= ~THREAT_DUMBFIRE;
	}

	if ( timestamp_elapsed(pp->update_lock_time) ) {
		pp->threat_flags &= ~(THREAT_LOCK | THREAT_ATTEMPT_LOCK);
		pp->update_lock_time = timestamp(THREAT_UPDATE_LOCK_TIME);
		rval = ship_lock_threat(shipp);
		if ( rval == 1 ) {
			pp->threat_flags |= THREAT_ATTEMPT_LOCK;
		} else if ( rval == 2 ) {
			pp->threat_flags |= THREAT_LOCK;
		}
	}

	if(Player->threat_flags & THREAT_LOCK ) {
		// a less hacked up version of the missile launch warning
		hud_start_text_flash(XSTR("Launch", 1507), THREAT_LOCK_FLASH, fl2i(THREAT_LOCK_FLASH/2.0f));
	}

	if ( Player->threat_flags & (THREAT_ATTEMPT_LOCK) ) {
		if ( timestamp_elapsed(Threat_lock_timer) ) {
			Threat_lock_timer = timestamp(THREAT_LOCK_FLASH);
			
			Threat_lock_frame++;
			if ( Threat_lock_frame > 2 ) {
				Threat_lock_frame = 1;
			}
			if ( (Threat_lock_frame == 2) && (Player->threat_flags & THREAT_ATTEMPT_LOCK ) ) {
				snd_play( &Snds[ship_get_sound(Player_obj, SND_THREAT_FLASH)]);
			}
		}
	} 
}