forked from scp-fs2open/fs2open.github.com
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhudtarget.cpp
More file actions
8032 lines (6653 loc) · 237 KB
/
Copy pathhudtarget.cpp
File metadata and controls
8032 lines (6653 loc) · 237 KB
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
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* 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 "asteroid/asteroid.h"
#include "cmdline/cmdline.h"
#include "debris/debris.h"
#include "freespace.h" // for flFrametime
#include "gamesnd/gamesnd.h"
#include "globalincs/alphacolors.h"
#include "globalincs/linklist.h"
#include "globalincs/utility.h"
#include "graphics/matrix.h"
#include "hud/hudartillery.h"
#include "hud/hudbrackets.h"
#include "hud/hudlock.h"
#include "hud/hudmessage.h"
#include "hud/hudparse.h"
#include "hud/hudreticle.h"
#include "hud/hudshield.h"
#include "hud/hudtarget.h"
#include "hud/hudtargetbox.h"
#include "iff_defs/iff_defs.h"
#include "io/timer.h"
#include "jumpnode/jumpnode.h"
#include "localization/localize.h"
#include "mission/missionhotkey.h"
#include "mission/missionmessage.h"
#include "model/model.h"
#include "network/multi.h"
#include "network/multiutil.h"
#include "object/object.h"
#include "libs/renderdoc/renderdoc.h"
#include "parse/parselo.h"
#include "playerman/player.h"
#include "render/3dinternal.h"
#include "ship/awacs.h"
#include "ship/ship.h"
#include "ship/subsysdamage.h"
#include "weapon/emp.h"
#include "weapon/weapon.h"
// Global values for the target bracket width and height, used for debugging
int Hud_target_w, Hud_target_h;
// offscreen triangle that point the the off-screen target
float Offscreen_tri_base[GR_NUM_RESOLUTIONS] = {
6.0f,
9.5f
};
float Offscreen_tri_height[GR_NUM_RESOLUTIONS] = {
7.0f,
11.0f
};
float Max_offscreen_tri_seperation[GR_NUM_RESOLUTIONS] = {
10.0f,
16.0f
};
float Max_front_seperation[GR_NUM_RESOLUTIONS] = {
10.0f,
16.0f
};
SCP_vector<target_display_info> target_display_list;
// The following variables are global to this file, and do not need to be persistent from frame-to-frame
// This means the variables are not player-specific
object* hostile_obj = NULL;
static int ballistic_hud_index = 0; // Goober5000
extern object obj_used_list; // dummy node in linked list of active objects
extern char *Cargo_names[];
// shader is used to shade the target box
shader Training_msg_glass;
// the target triangle (that orbits the reticle) dimensions
float Target_triangle_base[GR_NUM_RESOLUTIONS] = {
6.0f,
9.5f
};
float Target_triangle_height[GR_NUM_RESOLUTIONS] = {
7.0f,
11.0f
};
// stuff for hotkey targeting lists
htarget_list htarget_items[MAX_HOTKEY_TARGET_ITEMS];
htarget_list htarget_free_list;
/*
// coordinates and widths used to render the HUD afterburner energy gauge
int current_hud->Aburn_coords[GR_NUM_RESOLUTIONS][4] = {
{ // GR_640
171, 265, 60, 60
},
{ // GR_1024
274, 424, 86, 96
}
};
// coordinates and widths used to render the HUD weapons energy gauge
int current_hud->Wenergy_coords[GR_NUM_RESOLUTIONS][4] = {
{ // GR_640
416, 265, 60, 60
},
{ // GR_1024
666, 424, 86, 96
}
};*/
#define MIN_DISTANCE_TO_CONSIDER_THREAT 1500 // min distance to show hostile warning triangle
//////////////////////////////////////////////////////////////////////////
// lists for target in reticle cycling
//////////////////////////////////////////////////////////////////////////
#define RL_USED (1<<0)
#define RL_USE_DOT (1<<1) // use dot product result, not distance
typedef struct _reticle_list {
_reticle_list *next, *prev;
object *objp;
float dist, dot;
int flags;
} reticle_list;
#define RESET_TARGET_IN_RETICLE 750
int Reticle_save_timestamp;
reticle_list Reticle_cur_list;
reticle_list Reticle_save_list;
#define MAX_RETICLE_TARGETS 50
reticle_list Reticle_list[MAX_RETICLE_TARGETS];
//////////////////////////////////////////////////////////////////////////
// used for closest target cycling
//////////////////////////////////////////////////////////////////////////
#define TL_RESET 1500
#define TURRET_RESET 1000
static int Tl_hostile_reset_timestamp;
static int Tl_friendly_reset_timestamp;
static int Target_next_uninspected_object_timestamp;
static int Target_newest_ship_timestamp;
static int Target_next_turret_timestamp;
// animation frames for the hud targeting gauges
// frames: 0 => out of range lead
// 1 => in range lead
float Lead_indicator_half[NUM_HUD_RETICLE_STYLES][GR_NUM_RESOLUTIONS][2] =
{
{
{ // GR_640
12.5f, // half-width
12.5f // half-height
},
{ // GR_1024
20.0f, // half-width
20.0f // half-height
}
},
{
{ // GR_640
8.0f, // half-width
8.0f // half-height
},
{ // GR_1024
13.0f, // half-width
13.0f // half-height
}
}
};
hud_frames Lead_indicator_gauge;
int Lead_indicator_gauge_loaded = 0;
char Lead_fname[NUM_HUD_RETICLE_STYLES][GR_NUM_RESOLUTIONS][MAX_FILENAME_LEN] =
{
{ "lead1_fs1", "2_lead1_fs1" },
{ "lead1", "2_lead1" }
};
// animation frames for the countermeasures gauge
// frames: 0 => background
hud_frames Cmeasure_gauge;
int Cmeasure_gauge_loaded = 0;
int Cm_coords[GR_NUM_RESOLUTIONS][2] = {
{ // GR_640
497, 343
},
{ // GR_1024
880, 602
}
};
int Cm_text_coords[GR_NUM_RESOLUTIONS][2] = {
{ // GR_640
533, 347
},
{ // GR_1024
916, 606
}
};
int Cm_text_val_coords[GR_NUM_RESOLUTIONS][2] = {
{ // GR_640
506, 347
},
{ // GR_1024
889, 606
}
};
char Cm_fname[GR_NUM_RESOLUTIONS][MAX_FILENAME_LEN] = {
"countermeasure1",
"countermeasure1"
};
#define TOGGLE_TEXT_AUTOT 0
#define TOGGLE_TEXT_TARGET 1
#define TOGGLE_TEXT_AUTOS 2
#define TOGGLE_TEXT_SPEED 3
int Toggle_text_alpha = 255;
// animation files for the weapons gauge
#define NUM_WEAPON_GAUGES 5
hud_frames Weapon_gauges[NUM_HUD_SETTINGS][NUM_WEAPON_GAUGES];
hud_frames New_weapon;
int Weapon_gauges_loaded = 0;
// for primaries
int Weapon_gauge_primary_coords[NUM_HUD_SETTINGS][GR_NUM_RESOLUTIONS][3][2] =
{
{ // normal HUD
{ // GR_640
// based on the # of primaries
{509, 273}, // top of weapon gauge, first frame, always
{497, 293}, // for the first primary
{497, 305} // for the second primary
},
{ // GR_1024
// based on the # of primaries
{892, 525}, // top of weapon gauge, first frame, always
{880, 545}, // for the first primary
{880, 557} // for the second primary
}
},
{ // ballistic HUD - slightly different alignment
{ // GR_640
// based on the # of primaries
{485, 273}, // top of weapon gauge, first frame, always
{485, 293}, // for the first primary
{485, 305} // for the second primary
},
{ // GR_1024
// based on the # of primaries
{868, 525}, // top of weapon gauge, first frame, always
{868, 545}, // for the first primary
{868, 557} // for the second primary
}
}
};
int Weapon_gauge_secondary_coords[NUM_HUD_SETTINGS][GR_NUM_RESOLUTIONS][5][2] =
{
{ // normal HUD
{ // GR_640
// based on the # of secondaries
{497, 318}, // bottom of gauge, 0 secondaries
{497, 318}, // bottom of gauge, 1 secondaries
{497, 317}, // middle of gauge, 2 secondaries AND middle of gauge, 3 secondaries
{497, 326}, // bottom of gauge, 2 secondaries AND middle of gauge, 3 secondaries
{497, 335} // bottom of gauge, 3 secondaries
},
{ // GR_1024
// based on the # of secondaries
{880, 570}, // bottom of gauge, 0 secondaries
{880, 570}, // bottom of gauge, 1 secondaries
{880, 569}, // middle of gauge, 2 secondaries AND middle of gauge, 3 secondaries
{880, 578}, // bottom of gauge, 2 secondaries AND middle of gauge, 3 secondaries
{880, 587} // bottom of gauge, 3 secondaries
}
},
{ // ballistic HUD - slightly different alignment
{ // GR_640
// based on the # of secondaries
{485, 318}, // bottom of gauge, 0 secondaries
{485, 318}, // bottom of gauge, 1 secondaries
{485, 317}, // middle of gauge, 2 secondaries AND middle of gauge, 3 secondaries
{485, 326}, // bottom of gauge, 2 secondaries AND middle of gauge, 3 secondaries
{485, 335} // bottom of gauge, 3 secondaries
},
{ // GR_1024
// based on the # of secondaries
{868, 570}, // bottom of gauge, 0 secondaries
{868, 570}, // bottom of gauge, 1 secondaries
{868, 569}, // middle of gauge, 2 secondaries AND middle of gauge, 3 secondaries
{868, 578}, // bottom of gauge, 2 secondaries AND middle of gauge, 3 secondaries
{868, 587} // bottom of gauge, 3 secondaries
}
}
};
int Weapon_title_coords[NUM_HUD_SETTINGS][GR_NUM_RESOLUTIONS][2] =
{
{ // normal HUD
{ // GR_640
518, 274
},
{ // GR_1024
901, 527
}
},
{ // ballistic HUD - slightly different alignment
{ // GR_640
487, 274
},
{ // GR_1024
870, 527
}
}
};
int Weapon_plink_coords[GR_NUM_RESOLUTIONS][2][2] = {
{ // GR_640
{530, 285}, // fire-linked thingie, for the first primary
{530, 295} // fire-linked thingie, for the second primary
},
{ // GR_1024
{913, 537}, // fire-linked thingie, for the first primary
{913, 547} // fire-linked thingie, for the second primary
}
};
int Weapon_pname_coords[GR_NUM_RESOLUTIONS][2][2] = {
{ // GR_640
{536, 285}, // weapon name, first primary
{536, 295} // weapon name, second primary
},
{ // GR_1024
{919, 537}, // weapon name, first primary
{919, 547} // weapon name, second primary
}
};
int Weapon_slinked_x[GR_NUM_RESOLUTIONS] = {
525, // where to draw the second thingie if this weapon is fire-linked
908
};
int Weapon_sunlinked_x[GR_NUM_RESOLUTIONS] = {
530, // where to draw the first thingie if this weapon is selected at all (fire-linked or not)
913
};
int Weapon_secondary_y[GR_NUM_RESOLUTIONS][3] = {
{ // GR_640
309, // y location of where to draw text for the first secondary
318, // y location of where to draw text for the second secondary
327 // y location of where to draw text for the third secondary
},
{ // GR_1024
561, // y location of where to draw text for the third secondary
570, // y location of where to draw text for the third secondary
579 // y location of where to draw text for the third secondary
}
};
int Weapon_primary_y[GR_NUM_RESOLUTIONS][2] = {
{ // GR_640
285, // y location of where to draw text for the first primary
295 // y location of where to draw text for the second primary
},
{ // GR_1024
537, // y location of where to draw text for the first primary
547 // y location of where to draw text for the second primary
}
};
int Weapon_secondary_name_x[GR_NUM_RESOLUTIONS] = {
536, // x location of where to draw weapon name
919
};
int Weapon_secondary_ammo_x[GR_NUM_RESOLUTIONS] = {
525, // x location of where to draw weapon ammo count
908
};
int Weapon_primary_ammo_x[GR_NUM_RESOLUTIONS] = {
525, // x location of where to draw primary weapon ammo count
908
};
int Weapon_secondary_reload_x[GR_NUM_RESOLUTIONS] = {
615, // x location of where to draw the weapon reload time
998
};
const char *Weapon_gauge_fnames[NUM_HUD_SETTINGS][GR_NUM_RESOLUTIONS][NUM_WEAPON_GAUGES] =
{
//XSTR:OFF
{ // normal HUD
{ // GR_640
"weapons1",
"weapons2",
"weapons3",
"weapons4",
"weapons5"
},
{ // GR_1024
"weapons1",
"weapons2",
"weapons3",
"weapons4",
"weapons5"
}
},
{ // ballistic HUD - slightly different alignment
{ // GR_640
"weapons1_b",
"weapons2_b",
"weapons3_b",
"weapons4_b",
"weapons5_b"
},
{ // GR_1024
"weapons1_b",
"weapons2_b",
"weapons3_b",
"weapons4_b",
"weapons5_b"
}
}
//XSTR:ON
};
// Flash the line for a weapon. This normally occurs when the player tries to fire that
// weapon, but the firing fails (due to lack of energy or damaged weapons subsystem).
#define MAX_WEAPON_FLASH_LINES 7 // 3 primary and 4 secondary
typedef struct weapon_flash
{
int flash_duration[MAX_WEAPON_FLASH_LINES];
int flash_next[MAX_WEAPON_FLASH_LINES];
bool flash_energy[MAX_WEAPON_FLASH_LINES];
int is_bright;
} weapon_flash;
weapon_flash Weapon_flash_info;
// Data used for the proximity warning
typedef struct homing_beep_info
{
sound_handle snd_handle; // sound handle for last played beep
fix last_time_played; // time beep was last played
int min_cycle_time; // time (in ms) for fastest cycling of the sound
int max_cycle_time; // time (in ms) for slowest cycling of the sound
float min_cycle_dist; // distance at which fastest cycling occurs
float max_cycle_dist; // distance at which slowest cycling occurs
float precalced_interp; // a precalculated value used in a linear interpretation
} homing_beep_info;
homing_beep_info Homing_beep = {sound_handle::invalid(), 0, 150, 1000, 30.0f, 1500.0f, 1.729412f};
// Set at the start of a mission, used to decide how to draw the separation for the warning missile indicators
float Min_warning_missile_dist;
float Max_warning_missile_dist;
void hud_maybe_flash_weapon(int index);
// if a given object should be ignored because of AWACS effects
int hud_target_invalid_awacs(object *objp)
{
// if objp is ship object, first check if can be targeted with team info
if (objp->type == OBJ_SHIP) {
if (Player_ship != NULL) {
if (ship_is_visible_by_team(objp, Player_ship)) {
return 0;
}
}
}
// check for invalid status
if((Player_ship != nullptr) && (awacs_get_level(objp, Player_ship) < 1.0f)){
return 1;
}
// valid
return 0;
}
// Returns true if the weapon object can currently be targeted from source_objp.
// For mines, uses range-based detection (mine_targetable_range). For other weapons, uses flags.
static bool weapon_is_targetable_from(object *source_objp, object *objp)
{
weapon_info *wip = &Weapon_info[Weapons[objp->instance].weapon_info_index];
if (wip->is_mine()) {
Assertion(source_objp != nullptr, "weapon_is_targetable_from called with null source_objp");
return vm_vec_dist(&source_objp->pos, &objp->pos) <= wip->mine_targetable_range;
}
return wip->wi_flags[Weapon::Info_Flags::Can_be_targeted] || wip->wi_flags[Weapon::Info_Flags::Bomb];
}
ship_subsys *advance_subsys(ship_subsys *cur, int next_flag)
{
if (next_flag) {
return GET_NEXT(cur);
} else {
return GET_LAST(cur);
}
}
// select a sorted turret subsystem on a ship if no other subsys has been selected
void hud_maybe_set_sorted_turret_subsys(ship *shipp)
{
// this targeting behavior was introduced in FS2, so mods may not want to use it
// (the FS2 behavior makes FSPort's Playing Judas harder than it was designed to be)
if (Dont_automatically_select_turret_when_targeting_ship) {
return;
}
Assert((Player_ai->target_objnum >= 0) && (Player_ai->target_objnum < MAX_OBJECTS));
if (!((Player_ai->target_objnum >= 0) && (Player_ai->target_objnum < MAX_OBJECTS))) {
return;
}
Assert(Objects[Player_ai->target_objnum].type == OBJ_SHIP);
if (Objects[Player_ai->target_objnum].type != OBJ_SHIP) {
return;
}
if (Ship_info[shipp->ship_info_index].is_big_or_huge()) {
if (shipp->last_targeted_subobject[Player_num] == NULL) {
hud_target_live_turret(1, 1);
}
}
}
// -----------------------------------------------------------------------
// clear out the linked list of targets in the reticle
void hud_reticle_clear_list(reticle_list *rlist)
{
reticle_list *cur;
for ( cur = GET_FIRST(rlist); cur != END_OF_LIST(rlist); cur = GET_NEXT(cur) ) {
cur->flags = 0;
}
list_init(rlist);
}
// --------------------------------------------------------------------------------------
// hud_reticle_list_init()
void hud_reticle_list_init()
{
int i;
for ( i = 0; i < MAX_RETICLE_TARGETS; i++ ) {
Reticle_list[i].flags = 0;
}
Reticle_save_timestamp = 1;
list_init(&Reticle_save_list);
list_init(&Reticle_cur_list);
}
// --------------------------------------------------------------------------------------
// hud_check_reticle_list()
//
//
void hud_check_reticle_list()
{
reticle_list *rl, *temp;
// cull dying objects from reticle list
rl = GET_FIRST(&Reticle_cur_list);
while( rl !=END_OF_LIST(&Reticle_cur_list) ) {
temp = GET_NEXT(rl);
if ( rl->objp->flags[Object::Object_Flags::Should_be_dead] ) {
list_remove( &Reticle_cur_list, rl );
rl->flags = 0;
}
rl = temp;
}
if ( timestamp_elapsed(Reticle_save_timestamp) ) {
hud_reticle_clear_list(&Reticle_save_list);
Reticle_save_timestamp = timestamp(RESET_TARGET_IN_RETICLE);
}
}
// --------------------------------------------------------------------------------------
// hud_reticle_list_find_free()
//
//
int hud_reticle_list_find_free()
{
int i;
// find a free reticle_list element
for ( i = 0; i < MAX_RETICLE_TARGETS; i++ ) {
if ( !(Reticle_list[i].flags & RL_USED) ) {
break;
}
}
if ( i == MAX_RETICLE_TARGETS ) {
// nprintf(("Warning","Warning ==> Ran out of reticle target elements...\n"));
return -1;
}
return i;
}
// --------------------------------------------------------------------------------------
// hud_stuff_reticle_list()
//
//
#define RETICLE_DEFAULT_DIST 100000.0f
#define RETICLE_DEFAULT_DOT 1.0f
void hud_stuff_reticle_list(reticle_list *rl, object *objp, float measure, int dot_flag)
{
if ( dot_flag ) {
rl->dot = measure;
rl->dist = RETICLE_DEFAULT_DIST;
rl->flags |= RL_USE_DOT;
}
else {
rl->dist = measure;
rl->dot = RETICLE_DEFAULT_DOT;
}
rl->objp = objp;
}
// --------------------------------------------------------------------------------------
// hud_reticle_list_update()
//
// Update Reticle_cur_list with an object that lies in the reticle
//
// parmeters: objp => object pointer to target
// measure => distance or dot product, depending on dot_flag
// dot_flag => if 0, measure is distance, if 1 measure is dot
//
void hud_reticle_list_update(object *objp, float measure, int dot_flag)
{
reticle_list *rl, *new_rl;
int i;
if (objp->type == OBJ_JUMP_NODE) {
auto jnp = jumpnode_get_by_objp(objp);
if (!jnp || jnp->IsHidden())
return;
}
for ( rl = GET_FIRST(&Reticle_cur_list); rl != END_OF_LIST(&Reticle_cur_list); rl = GET_NEXT(rl) ) {
if ( rl->objp == objp )
return;
}
i = hud_reticle_list_find_free();
if ( i == -1 )
return;
new_rl = &Reticle_list[i];
new_rl->flags |= RL_USED;
hud_stuff_reticle_list(new_rl, objp, measure, dot_flag);
int was_inserted = 0;
if ( EMPTY(&Reticle_cur_list) ) {
list_insert(&Reticle_cur_list, new_rl);
was_inserted = 1;
}
else {
for ( rl = GET_FIRST(&Reticle_cur_list); rl != END_OF_LIST(&Reticle_cur_list); rl = GET_NEXT(rl) ) {
if ( !dot_flag ) {
// compare based on distance
if ( measure < rl->dist ) {
list_insert_before(rl, new_rl);
was_inserted = 1;
break;
}
}
else {
// compare based on dot
if ( measure > rl->dot ) {
list_insert_before(rl, new_rl);
was_inserted = 1;
break;
}
}
} // end for
}
if ( !was_inserted ) {
list_append(&Reticle_cur_list, new_rl);
}
}
// --------------------------------------------------------------------------------------
// hud_reticle_pick_target()
//
// Pick a target from Reticle_cur_list, based on what is in Reticle_save_list
//
//
object *hud_reticle_pick_target()
{
reticle_list *cur_rl, *save_rl, *new_rl;
object *return_objp;
int in_save_list, i;
return_objp = NULL;
// As a first step, see if both ships and debris are in the list. If so, cull the debris.
int debris_in_list = 0;
int ship_in_list = 0;
for ( cur_rl = GET_FIRST(&Reticle_cur_list); cur_rl != END_OF_LIST(&Reticle_cur_list); cur_rl = GET_NEXT(cur_rl) ) {
if ( (cur_rl->objp->type == OBJ_SHIP) || (cur_rl->objp->type == OBJ_JUMP_NODE) ) {
ship_in_list = 1;
continue;
}
if ( cur_rl->objp->type == OBJ_WEAPON ) {
if ( Weapon_info[Weapons[cur_rl->objp->instance].weapon_info_index].subtype == WP_MISSILE ) {
ship_in_list = 1;
continue;
}
}
if ( (cur_rl->objp->type == OBJ_DEBRIS) || (cur_rl->objp->type == OBJ_ASTEROID) ) {
debris_in_list = 1;
continue;
}
}
if ( ship_in_list && debris_in_list ) {
// cull debris
reticle_list *rl, *next;
rl = GET_FIRST(&Reticle_cur_list);
while ( rl != &Reticle_cur_list ) {
next = rl->next;
if ( (rl->objp->type == OBJ_DEBRIS) || (rl->objp->type == OBJ_ASTEROID) ){
list_remove(&Reticle_cur_list,rl);
rl->flags = 0;
}
rl = next;
}
}
for ( cur_rl = GET_FIRST(&Reticle_cur_list); cur_rl != END_OF_LIST(&Reticle_cur_list); cur_rl = GET_NEXT(cur_rl) ) {
in_save_list = 0;
for ( save_rl = GET_FIRST(&Reticle_save_list); save_rl != END_OF_LIST(&Reticle_save_list); save_rl = GET_NEXT(save_rl) ) {
if ( cur_rl->objp == save_rl->objp ) {
in_save_list = 1;
break;
}
}
if ( !in_save_list ) {
return_objp = cur_rl->objp;
i = hud_reticle_list_find_free();
if ( i == -1 )
break;
new_rl = &Reticle_list[i];
new_rl->flags |= RL_USED;
if ( cur_rl->flags & RL_USE_DOT ) {
hud_stuff_reticle_list(new_rl, cur_rl->objp, cur_rl->dot, 1);
}
else {
hud_stuff_reticle_list(new_rl, cur_rl->objp, cur_rl->dist, 0);
}
list_append(&Reticle_save_list, new_rl);
break;
}
} // end for
if ( return_objp == NULL && !EMPTY(&Reticle_cur_list) ) {
i = hud_reticle_list_find_free();
if ( i == -1 )
return NULL;
new_rl = &Reticle_list[i];
cur_rl = GET_FIRST(&Reticle_cur_list);
*new_rl = *cur_rl;
return_objp = cur_rl->objp;
hud_reticle_clear_list(&Reticle_save_list);
list_append(&Reticle_save_list, new_rl);
}
return return_objp;
}
// hud_target_hotkey_add_remove takes as its parameter which hotkey (1-0) to add/remove the current
// target from. This function behaves like the Shift-<selection> does in Windows -- using shift # will toggle
// the current target in and out of the selection set.
void hud_target_hotkey_add_remove( int k, object *ctarget, int how_to_add )
{
htarget_list *hitem, *plist;
// don't do anything if a standalone multiplayer server
if ( MULTIPLAYER_STANDALONE )
return;
if ( (k < 0) || (k >= MAX_KEYED_TARGETS) ) {
nprintf(("Warning", "Bogus hotkey %d sent to hud_target_hotkey_add_remove\n", k));
return;
}
plist = &(Players[Player_num].keyed_targets[k]);
// we must operate only on ships
if ( ctarget->type != OBJ_SHIP )
return;
// don't allow player into hotkey set
if ( ctarget == Player_obj )
return;
// don't put dying or departing
if ( Ships[ctarget->instance].is_dying_or_departing() )
return;
// don't add mission file added hotkey assignments if there are player added assignments
// already in the list
if ( (how_to_add == HOTKEY_MISSION_FILE_ADDED) && NOT_EMPTY(plist) ) {
for ( hitem = GET_FIRST(plist); hitem != END_OF_LIST(plist); hitem = GET_NEXT(hitem) ) {
if ( hitem->how_added == HOTKEY_USER_ADDED )
return;
}
}
// determine if the current target is currently in the set or not
for ( hitem = GET_FIRST(plist); hitem != END_OF_LIST(plist); hitem = GET_NEXT(hitem) ) {
if ( hitem->objp == ctarget )
break;
}
// if hitem == end of the list, then the target should be added, else it should be removed
if ( hitem == END_OF_LIST(plist) ) {
if ( EMPTY(&htarget_free_list) ) {
Int3(); // get Allender -- no more free hotkey target items
return;
}
nprintf(("network", "Hotkey: Adding %s\n", Ships[ctarget->instance].ship_name));
hitem = GET_FIRST( &htarget_free_list );
list_remove( &htarget_free_list, hitem );
list_append( plist, hitem );
hitem->objp = ctarget;
hitem->how_added = how_to_add;
} else {
nprintf(("network", "Hotkey: Removing %s\n", Ships[ctarget->instance].ship_name));
list_remove( plist, hitem );
list_append( &htarget_free_list, hitem );
hitem->objp = NULL; // for safety
}
}
// the following function clears the hotkey set given by parameter passed in
void hud_target_hotkey_clear( int k )
{
htarget_list *hitem, *plist, *temp;
plist = &(Players[Player_num].keyed_targets[k]);
hitem = GET_FIRST(plist);
while ( hitem != END_OF_LIST(plist) ) {
temp = GET_NEXT(hitem);
list_remove( plist, hitem );
list_append( &htarget_free_list, hitem );
hitem->objp = NULL;
hitem = temp;
}
if ( Players[Player_num].current_hotkey_set == k ) // clear this variable if we removed the bindings
Players[Player_num].current_hotkey_set = -1;
}
// the next function sets the current selected set to be N. If there is just one ship in the selection
// set, this ship will become the new target. If there is more than one ship in the selection set,
// then the current_target will remain what it was.
void hud_target_hotkey_select( int k )
{
int visible_count = 0;
htarget_list *hitem, *plist, *target, *next_target, *first_target;
int target_objnum;
plist = &(Players[Player_num].keyed_targets[k]);
if ( EMPTY( plist ) ) // no items in list, then do nothing
return;
// a simple walk of the list to get the count
for ( hitem = GET_FIRST(plist); hitem != END_OF_LIST(plist); hitem = GET_NEXT(hitem) ){
if (awacs_get_level(hitem->objp, Player_ship, true) > 1.0f) {
visible_count++;
}
}
// no visible ships in list
if (visible_count == 0) {
return;
}
// set the current target to be the "next" ship in the list. Scan the list to see if our
// current target is in the set. If so, target the next ship in the list, otherwise target
// the first
// set first_target - first visible item in list
// target - item in list that is the player's currently selected target
// next_target - next visible item in list following target
target_objnum = Player_ai->target_objnum;
target = NULL;
next_target = NULL;
first_target = NULL;
for ( hitem = GET_FIRST(plist); hitem != END_OF_LIST(plist); hitem = GET_NEXT(hitem) ) {
if (awacs_get_level(hitem->objp, Player_ship, true) > 1.0f) {
// get the first valid target
if (first_target == NULL) {
first_target = hitem;
}
// get the next target in the list following the player currently selected target
if (target != NULL) {
next_target = hitem;
break;
}
}
// mark the player currently selected target
if ( OBJ_INDEX(hitem->objp) == target_objnum ) {
target = hitem;
}
}
// if current target is not in list, then target and next_target will be NULL
// so we use the first found target
if (target == NULL) {
Assert(first_target != NULL);
if (first_target != NULL) {
target = first_target;
next_target = first_target;
} else {
// this should not happen
return;
}
// if current target is in the list but this is not our current selection set,
// then we don't want to change target.
} else if (Players[Player_num].current_hotkey_set != k) {
next_target = target;
}
// update target if more than 1 is visible
if (visible_count > 1) {
// next already found (after current target in list)
if (next_target != NULL) {
target = next_target;
} else {
// next is before current target, so search from start of list
for ( hitem = GET_FIRST(plist); hitem != END_OF_LIST(plist); hitem = GET_NEXT(hitem) ) {
if (awacs_get_level(hitem->objp, Player_ship, true) > 1.0f) {
target = hitem;
break;
}
}
}
}
Assert( target != END_OF_LIST(plist) );
if ( Player_obj != target->objp ){
set_target_objnum( Player_ai, OBJ_INDEX(target->objp) );
hud_shield_hit_reset(target->objp);
}
Players[Player_num].current_hotkey_set = k;
}
// hud_init_targeting_colors() will initialize the shader and gradient objects used
// on the HUD
//
color HUD_color_homing_indicator;
void hud_make_shader(shader *sh, ubyte r, ubyte /*g*/, ubyte /*b*/, float dimmer = 1000.0f)
{
// The m matrix converts all colors to shades of green
//float tmp = 16.0f*(0.0015625f * i2fl(HUD_color_alpha+1.0f));
float tmp = 0.025f * i2fl(HUD_color_alpha+1.0f);
ubyte R = ubyte(r * tmp);
ubyte G = ubyte(r * tmp);
ubyte B = ubyte(r * tmp);
ubyte A = ubyte((float(r) / dimmer)*(i2fl(HUD_color_alpha) / 15.0f) * 255.0f);
gr_create_shader( sh, R, G, B, A );
}
void hud_init_targeting_colors()
{
gr_init_color( &HUD_color_homing_indicator, 0x7f, 0x7f, 0 ); // yellow
hud_make_shader(&Training_msg_glass, 61, 61, 85, 500.0f);
hud_init_brackets();
}
void hud_keyed_targets_clear()
{
int i;
// clear out the keyed target list