-
Notifications
You must be signed in to change notification settings - Fork 182
Expand file tree
/
Copy pathhudtargetbox.cpp
More file actions
2488 lines (2037 loc) · 68.6 KB
/
Copy pathhudtargetbox.cpp
File metadata and controls
2488 lines (2037 loc) · 68.6 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"
#include "gamesnd/gamesnd.h"
#include "graphics/matrix.h"
#include "hud/hudbrackets.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/missionparse.h"
#include "model/model.h"
#include "network/multi.h"
#include "object/object.h"
#include "object/objectdock.h"
#include "parse/parselo.h"
#include "playerman/player.h"
#include "ship/ship.h"
#include "ship/subsysdamage.h"
#include "species_defs/species_defs.h"
#include "weapon/emp.h"
#include "weapon/weapon.h"
#ifndef NDEBUG
#include "hud/hudets.h"
#endif
extern fov_t View_zoom;
int Target_window_coords[GR_NUM_RESOLUTIONS][4] =
{
{ // GR_640
8, 362, 131, 112
},
{ // GR_1024
8, 629, 131, 112
}
};
object *Enemy_attacker = NULL;
static int Target_static_next;
static int Target_static_playing;
sound_handle Target_static_looping = sound_handle::invalid();
bool Target_display_cargo;
char Cargo_string[256] = "";
#ifndef NDEBUG
extern int Show_target_debug_info;
extern int Show_target_weapons;
#endif
// used to print out + or - after target distance and speed
const char* modifiers[] = {
//XSTR:OFF
"+",
"-",
""
//XSTR:ON
};
#define NUM_TBOX_COORDS 11 // keep up to date
#define TBOX_BACKGROUND 0
#define TBOX_NAME 1
#define TBOX_CLASS 2
#define TBOX_DIST 3
#define TBOX_SPEED 4
#define TBOX_CARGO 5
#define TBOX_HULL 6
#define TBOX_EXTRA 7
#define TBOX_EXTRA_ORDERS 8
#define TBOX_EXTRA_TIME 9
#define TBOX_EXTRA_DOCK 10
// cargo scanning extents
int Cargo_scan_coords[GR_NUM_RESOLUTIONS][4] = {
{ // GR_640
7, 364, 130, 109
},
{ // GR_1024
7, 635, 130, 109
}
};
// first element is time flashing expires
int Targetbox_flash_timers[NUM_TBOX_FLASH_TIMERS];
int CurrentWire = 0;
int Targetbox_wire = 0;
int Targetbox_shader_effect = -1;
color Targetbox_color;
bool Targetbox_color_override = false;
bool Lock_targetbox_mode = false;
// Different target states. This drives the text display right below the hull integrity on the targetbox.
#define TS_DIS 0
#define TS_OK 1
#define TS_DMG 2
#define TS_CRT 3
static int Current_ts; // holds current target status
static int Last_ts; // holds last target status.
/**
* @note Cut down long subsystem names to a more manageable length
*/
void hud_targetbox_truncate_subsys_name(char *outstr)
{
if (Lcl_gr && !Disable_built_in_translations) {
if ( strstr(outstr, "communication") ) {
strcpy(outstr, "Komm");
} else if ( !stricmp(outstr, "weapons") ) {
strcpy(outstr, "Waffen");
} else if ( strstr(outstr, "engine") || strstr(outstr, "Engine")) {
strcpy(outstr, "Antrieb");
} else if ( !stricmp(outstr, "sensors") ) {
strcpy(outstr, "Sensoren");
} else if ( strstr(outstr, "navigat") ) {
strcpy(outstr, "Nav");
} else if ( strstr(outstr, "fighterbay") || strstr(outstr, "Fighterbay") ) {
strcpy(outstr, "J\x84gerhangar");
} else if ( strstr(outstr, "missile") ) {
strcpy(outstr, "Raketenwerfer");
} else if ( strstr(outstr, "laser") || strstr(outstr, "turret") ) {
strcpy(outstr, "Gesch\x81tzturm");
} else if ( strstr(outstr, "Command Tower") || strstr(outstr, "Bridge") ) {
strcpy(outstr, "Br\x81""cke");
} else if ( strstr(outstr, "Barracks") ) {
strcpy(outstr, "Quartiere");
} else if ( strstr(outstr, "Reactor") ) {
strcpy(outstr, "Reaktor");
} else if ( strstr(outstr, "RadarDish") ) {
strcpy(outstr, "Radarantenne");
} else if (!stricmp(outstr, "Gas Collector")) {
strcpy(outstr, "Sammler");
}
} else if (Lcl_fr && !Disable_built_in_translations) {
if ( strstr(outstr, "communication") ) {
strcpy(outstr, "comm");
} else if ( !stricmp(outstr, "weapons") ) {
strcpy(outstr, "armes");
} else if ( strstr(outstr, "engine") ) {
strcpy(outstr, "moteur");
} else if ( !stricmp(outstr, "sensors") ) {
strcpy(outstr, "detecteurs");
} else if ( strstr(outstr, "navi") ) {
strcpy(outstr, "nav");
} else if ( strstr(outstr, "missile") ) {
strcpy(outstr, "lanceur de missiles");
} else if ( strstr(outstr, "fighter") ) {
strcpy(outstr, "baie de chasse");
} else if ( strstr(outstr, "laser") || strstr(outstr, "turret") || strstr(outstr, "missile") ) {
strcpy(outstr, "tourelle");
}
} else if (Lcl_pl && !Disable_built_in_translations) {
if ( strstr(outstr, "communication") ) {
strcpy(outstr, "komunikacja");
} else if ( !stricmp(outstr, "weapons") ) {
strcpy(outstr, "uzbrojenie");
} else if ( strstr(outstr, "engine") || strstr(outstr, "Engine")) {
strcpy(outstr, "silnik");
} else if ( !stricmp(outstr, "sensors") ) {
strcpy(outstr, "sensory");
} else if ( strstr(outstr, "navigat") ) {
strcpy(outstr, "nawigacja");
} else if ( strstr(outstr, "fighterbay") || strstr(outstr, "Fighterbay") ) {
strcpy(outstr, "dok my\x9Cliw.");
} else if ( strstr(outstr, "missile") ) {
strcpy(outstr, "wie\xBF. rakiet.");
} else if ( strstr(outstr, "laser") || strstr(outstr, "turret") ) {
strcpy(outstr, "wie\xBFyczka");
} else if ( strstr(outstr, "Command Tower") || strstr(outstr, "Bridge") ) {
strcpy(outstr, "mostek");
} else if ( strstr(outstr, "Barracks") ) {
strcpy(outstr, "koszary");
} else if ( strstr(outstr, "Reactor") ) {
strcpy(outstr, "reaktor");
} else if ( strstr(outstr, "RadarDish") || strstr(outstr, "Radar Dish") ) {
strcpy(outstr, "antena radaru");
} else if (!stricmp(outstr, "Gas Collector")) {
strcpy(outstr, "zbieracz gazu");
}
} else {
if (strstr(outstr, XSTR("communication", 333))) {
strcpy(outstr, XSTR("comm", 334));
} else if (strstr(outstr, XSTR("navigation", 335))) {
strcpy(outstr, XSTR("nav", 336));
} else if (strstr(outstr, "gas collector")) {
strcpy(outstr, "collector");
}
}
}
HudGaugeTargetBox::HudGaugeTargetBox():
HudGauge(HUD_OBJECT_TARGET_MONITOR, HUD_TARGET_MONITOR, false, false, (VM_EXTERNAL | VM_DEAD_VIEW | VM_WARP_CHASE | VM_PADLOCK_ANY), 255, 255, 255),
Monitor_mask(-1),
Use_subsys_name_offsets(false),
Use_subsys_integrity_offsets(false),
Use_disabled_status_offsets(false)
{
}
void HudGaugeTargetBox::initViewportOffsets(int x, int y)
{
Viewport_offsets[0] = x;
Viewport_offsets[1] = y;
}
void HudGaugeTargetBox::initViewportSize(int w, int h)
{
Viewport_w = w;
Viewport_h = h;
}
void HudGaugeTargetBox::initIntegrityOffsets(int x, int y)
{
Integrity_bar_offsets[0] = x;
Integrity_bar_offsets[1] = y;
}
void HudGaugeTargetBox::initIntegrityHeight(int h)
{
integrity_bar_h = h;
}
void HudGaugeTargetBox::initStatusOffsets(int x, int y)
{
Status_offsets[0] = x;
Status_offsets[1] = y;
}
void HudGaugeTargetBox::initNameOffsets(int x, int y)
{
Name_offsets[0] = x;
Name_offsets[1] = y;
}
void HudGaugeTargetBox::initClassOffsets(int x, int y)
{
Class_offsets[0] = x;
Class_offsets[1] = y;
}
void HudGaugeTargetBox::initDistOffsets(int x, int y)
{
Dist_offsets[0] = x;
Dist_offsets[1] = y;
}
void HudGaugeTargetBox::initSpeedOffsets(int x, int y)
{
Speed_offsets[0] = x;
Speed_offsets[1] = y;
}
void HudGaugeTargetBox::initCargoStringOffsets(int x, int y)
{
Cargo_string_offsets[0] = x;
Cargo_string_offsets[1] = y;
}
void HudGaugeTargetBox::initHullOffsets(int x, int y)
{
Hull_offsets[0] = x;
Hull_offsets[1] = y;
}
void HudGaugeTargetBox::initCargoScanType(CargoScanType scantype)
{
Cargo_scan_type = scantype;
}
void HudGaugeTargetBox::initCargoScanStartOffsets(int x, int y)
{
Cargo_scan_start_offsets[0] = x;
Cargo_scan_start_offsets[1] = y;
}
void HudGaugeTargetBox::initCargoScanSize(int w, int h)
{
Cargo_scan_w = w;
Cargo_scan_h = h;
}
void HudGaugeTargetBox::initSubsysNameOffsets(int x, int y, bool activate)
{
Subsys_name_offsets[0] = x;
Subsys_name_offsets[1] = y;
Use_subsys_name_offsets = activate;
}
void HudGaugeTargetBox::initSubsysIntegrityOffsets(int x, int y, bool activate)
{
Subsys_integrity_offsets[0] = x;
Subsys_integrity_offsets[1] = y;
Use_subsys_integrity_offsets = activate;
}
void HudGaugeTargetBox::initDisabledStatusOffsets(int x, int y, bool activate)
{
Disabled_status_offsets[0] = x;
Disabled_status_offsets[1] = y;
Use_disabled_status_offsets = activate;
}
void HudGaugeTargetBox::initDesaturate(bool desaturate)
{
Desaturated = desaturate;
}
void HudGaugeTargetBox::initGaugeWireframe(int wireframe)
{
GaugeWireframe = wireframe;
}
void HudGaugeTargetBox::initGaugeWirecolor(color wirecolor)
{
GaugeWirecolor = wirecolor;
}
void HudGaugeTargetBox::initGaugeWirecolorOverride(bool wirecoloroverride)
{
GaugeWirecolorOverride = wirecoloroverride;
}
void HudGaugeTargetBox::initBitmaps(char *fname_monitor, char *fname_monitor_mask, char *fname_integrity, char *fname_static)
{
Monitor_frame.first_frame = bm_load_animation(fname_monitor, &Monitor_frame.num_frames);
if ( Monitor_frame.first_frame < 0 ) {
Warning(LOCATION,"Cannot load hud ani: %s\n", fname_monitor);
}
Integrity_bar.first_frame = bm_load_animation(fname_integrity, &Integrity_bar.num_frames);
if ( Integrity_bar.first_frame < 0 ) {
Warning(LOCATION,"Cannot load hud ani: %s\n", fname_integrity);
}
if ( strlen(fname_monitor_mask) > 0 ) {
Monitor_mask = bm_load_animation(fname_monitor_mask);
if ( Monitor_mask < 0 ) {
Warning(LOCATION, "Cannot load bitmap hud mask: %s\n", fname_monitor_mask);
}
}
strcpy_s(static_fname, fname_static);
}
void HudGaugeTargetBox::initialize()
{
hud_anim_init(&Monitor_static, position[0] + Viewport_offsets[0], position[1] + Viewport_offsets[1], NOX(static_fname));
for(int i = 0; i < NUM_TBOX_FLASH_TIMERS; i++) {
initFlashTimer(i);
}
CurrentWire = GaugeWireframe;
HudGauge::initialize();
}
void HudGaugeTargetBox::initFlashTimer(int index)
{
Next_flash_timers[index] = 1;
flash_flags &= ~(1<<index);
}
void HudGaugeTargetBox::render(float frametime, bool config)
{
object *target_objp = nullptr;
if (!config && Player_ai->target_objnum == -1)
return;
if (!config && Target_static_playing )
return;
if (!config) {
target_objp = &Objects[Player_ai->target_objnum];
}
int x = position[0];
int y = position[1];
float scale = 1.0;
if (config) {
std::tie(x, y, scale) = hud_config_convert_coord_sys(position[0], position[1], base_w, base_h);
int bmw, bmh;
bm_get_info(Monitor_frame.first_frame, &bmw, &bmh);
hud_config_set_mouse_coords(gauge_config_id, x, x + fl2i(bmw * scale), y, y + fl2i(bmh * scale));
}
setGaugeColor(HUD_C_NONE, config);
// blit the background frame
if (Monitor_frame.first_frame >= 0)
renderBitmap(Monitor_frame.first_frame, x, y, scale, config);
if ( Monitor_mask >= 0 ) {
// render the alpha mask
gr_alpha_mask_set(1, 0.5f);
gr_stencil_clear();
gr_stencil_set(GR_STENCIL_WRITE);
gr_set_color_buffer(0);
renderBitmapColor(Monitor_mask, x, y, scale, config);
gr_set_color_buffer(1);
gr_stencil_set(GR_STENCIL_NONE);
gr_alpha_mask_set(0, 1.0f);
}
if (!config && target_objp == nullptr) {
return;
}
if (!config) {
switch (target_objp->type) {
case OBJ_SHIP:
renderTargetShip(target_objp);
break;
case OBJ_DEBRIS:
renderTargetDebris(target_objp);
break;
case OBJ_WEAPON:
renderTargetWeapon(target_objp);
break;
case OBJ_ASTEROID:
renderTargetAsteroid(target_objp);
break;
case OBJ_JUMP_NODE:
renderTargetJumpNode(target_objp);
break;
default:
hud_cease_targeting();
break;
} // end switch
} else {
renderTargetShip(target_objp, config);
}
if (!config && Target_static_playing ) {
setGaugeColor(HUD_C_NONE, config);
gr_set_screen_scale(base_w, base_h);
hud_anim_render(&Monitor_static, frametime, 1);
gr_reset_screen_scale();
} else {
showTargetData(frametime, config);
}
if(config || Target_display_cargo) {
// Print out what the cargo is
if (!config) {
if (maybeFlashSexp() == 1) {
setGaugeColor(HUD_C_BRIGHT);
} else {
maybeFlashElement(TBOX_FLASH_CARGO);
}
}
renderString(x + fl2i(Cargo_string_offsets[0] * scale), y + fl2i(Cargo_string_offsets[1] * scale), EG_TBOX_CARGO, config ? "cargo: <unknown>" : Cargo_string, scale, config);
}
}
void HudGaugeTargetBox::renderTargetForeground(bool config)
{
setGaugeColor(HUD_C_NONE, config);
int x = position[0];
int y = position[1];
float scale = 1.0;
if (config) {
std::tie(x, y, scale) = hud_config_convert_coord_sys(position[0], position[1], base_w, base_h);
}
if (Monitor_frame.first_frame + 1 >= 0)
renderBitmap(Monitor_frame.first_frame+1, x, y, scale, config);
}
/**
* Draw the integrity bar that is on the right of the target monitor
*/
void HudGaugeTargetBox::renderTargetIntegrity(int disabled,int force_obj_num, bool config)
{
if ( Integrity_bar.first_frame < 0 )
return;
int x = position[0];
int y = position[1];
float scale = 1.0;
if (config) {
std::tie(x, y, scale) = hud_config_convert_coord_sys(position[0], position[1], base_w, base_h);
}
if (!config && disabled ) {
renderBitmap(Integrity_bar.first_frame, x + fl2i(Integrity_bar_offsets[0] * scale), y + fl2i(Integrity_bar_offsets[1] * scale));
return;
}
if (!config) {
if (force_obj_num == -1) {
Assert(Player_ai->target_objnum >= 0);
}
}
int clip_h = fl2i((1 - (config ? 1.0 : Pl_target_integrity)) * integrity_bar_h);
int status = Current_ts;
if (config) {
status = TS_OK;
}
// print out status of ship
char buf[16];
switch(status) {
case TS_DIS:
strcpy_s(buf,XSTR( "dis", 344));
break;
case TS_OK:
strcpy_s(buf,XSTR( "ok", 345));
break;
case TS_DMG:
strcpy_s(buf,XSTR( "dmg", 346));
break;
case TS_CRT:
strcpy_s(buf,XSTR( "crt", 347));
break;
default:
UNREACHABLE("Unhandled target integrity status %d in HudGaugeTargetBox::renderTargetIntegrity!", status);
buf[0] = '\0';
break;
}
if (!config) {
maybeFlashElement(TBOX_FLASH_STATUS);
}
// finally print out the status of this ship
renderString(x + fl2i(Status_offsets[0] * scale), y + fl2i(Status_offsets[1] * scale), EG_TBOX_INTEG, buf, scale, config);
setGaugeColor(HUD_C_NONE, config);
int w, h;
bm_get_info(Integrity_bar.first_frame,&w,&h);
if ( clip_h > 0 ) {
// draw the dark portion
renderBitmapEx(Integrity_bar.first_frame, x + fl2i(Integrity_bar_offsets[0] * scale), y + fl2i(Integrity_bar_offsets[1] * scale), w, clip_h,0,0, scale, config);
}
if (clip_h <= integrity_bar_h) {
// draw the bright portion
renderBitmapEx(Integrity_bar.first_frame + 1,
x + fl2i(Integrity_bar_offsets[0] * scale),
y + fl2i(Integrity_bar_offsets[1] * scale) + fl2i(clip_h * scale),
w,
h - clip_h,
0,
clip_h,
scale,
config);
}
}
void HudGaugeTargetBox::renderTargetSetup(vec3d *camera_eye, matrix *camera_orient, fov_t zoom)
{
// JAS: g3_start_frame uses clip_width and clip_height to determine the
// size to render to. Normally, you would set this by using gr_set_clip,
// but because of the hacked in hud jittering, I couldn't. So come talk
// to me before modifying or reusing the following code. Thanks.
int clip_width = Viewport_w;
int clip_height = Viewport_h;
gr_screen.clip_width = clip_width;
gr_screen.clip_height = clip_height;
g3_start_frame(1); // Turn on zbuffering
hud_save_restore_camera_data(1);
g3_set_view_matrix( camera_eye, camera_orient, zoom);
model_set_detail_level(1); // use medium detail level
setClip(position[0] + Viewport_offsets[0], position[1] + Viewport_offsets[1], Viewport_w, Viewport_h);
// account for gauge RTT with cockpit here --wookieejedi
float clip_aspect;
if (gr_screen.rendering_to_texture != -1) {
clip_aspect = (i2fl(clip_width) / i2fl(clip_height));
} else {
clip_aspect = gr_screen.clip_aspect;
}
gr_set_proj_matrix(Proj_fov, clip_aspect, Min_draw_distance, Max_draw_distance);
gr_set_view_matrix(&Eye_position, &Eye_matrix);
}
void HudGaugeTargetBox::renderTargetShip(object *target_objp, bool config)
{
ship *target_shipp = nullptr;
ship_info *target_sip = nullptr;
if (!config) {
target_shipp = &Ships[target_objp->instance];
target_sip = &Ship_info[target_shipp->ship_info_index];
}
// Config doesn't render a ship.. but it'd be cool if it did. Maybe some other day.
if (!config) {
uint64_t flags = 0;
if (Detail.targetview_model) {
// take the forward orientation to be the vector from the player to the current target
vec3d orient_vec;
vm_vec_normalized_dir(&orient_vec, &target_objp->pos, &Player_obj->pos);
float factor = -target_sip->closeup_pos_targetbox.xyz.z;
matrix camera_orient = IDENTITY_MATRIX;
// use the player's up vector, and construct the viewers orientation matrix
vec3d tempv;
object_get_eye(&tempv, &camera_orient, Player_obj, false);
auto up_vector = &camera_orient.vec.uvec;
vm_vector_2_matrix_norm(&camera_orient, &orient_vec, up_vector, nullptr);
// normalize the vector from the player to the current target, and scale by a factor to calculate
// the objects position
vec3d obj_pos = ZERO_VECTOR;
vm_vec_copy_scale(&obj_pos, &orient_vec, factor);
// RT, changed scaling here
vec3d camera_eye = ZERO_VECTOR;
renderTargetSetup(&camera_eye, &camera_orient, target_sip->closeup_zoom_targetbox);
// IMPORTANT NOTE! Code handling the case 'missile_view == TRUE' in rendering section of
// renderTargetWeapon()
// is largely copied over from renderTargetShip(). To keep the codes similar please update
// both if and when needed
model_render_params render_info;
render_info.set_object_number(OBJ_INDEX(target_objp));
color thisColor = GaugeWirecolor;
bool thisOverride = GaugeWirecolorOverride;
if (target_sip->uses_team_colors) {
render_info.set_team_color(target_shipp->team_name,
target_shipp->secondary_team_name,
target_shipp->team_change_timestamp,
target_shipp->team_change_time);
}
switch (CurrentWire) {
case 0:
flags |= MR_NO_LIGHTING;
break;
case 1:
if (thisOverride) {
render_info.set_color(thisColor);
} else {
if (ship_is_tagged(target_objp))
render_info.set_color(*iff_get_color(IFF_COLOR_TAGGED, 1));
else
render_info.set_color(
*iff_get_color_by_team_and_object(target_shipp->team, Player_ship->team, 1, target_objp));
}
flags = MR_SHOW_OUTLINE_HTL | MR_NO_POLYS | MR_NO_LIGHTING | MR_NO_TEXTURING;
break;
case 2:
break;
case 3:
if (thisOverride) {
render_info.set_color(thisColor);
} else {
if (ship_is_tagged(target_objp))
render_info.set_color(*iff_get_color(IFF_COLOR_TAGGED, 1));
else
render_info.set_color(
*iff_get_color_by_team_and_object(target_shipp->team, Player_ship->team, 1, target_objp));
}
flags |= MR_NO_LIGHTING | MR_NO_TEXTURING;
break;
}
if (target_sip->hud_target_lod >= 0) {
render_info.set_detail_level_lock(target_sip->hud_target_lod);
}
if (Targetbox_shader_effect > -1) {
render_info.set_animated_effect(Targetbox_shader_effect, 0.0f);
}
if (Monitor_mask >= 0) {
gr_stencil_set(GR_STENCIL_READ);
}
if (Desaturated) {
flags |= MR_DESATURATED;
render_info.set_color(gauge_color);
}
if (!Glowpoint_override)
Glowpoint_override = true;
// set glowmap flag here since model_render (etc) require an objnum to handle glowmaps
// if we did pass the objnum, we'd also have thrusters drawn in the targetbox
if (target_shipp->flags[Ship::Ship_Flags::Glowmaps_disabled]) {
flags |= MR_NO_GLOWMAPS;
}
render_info.set_flags(flags | MR_AUTOCENTER | MR_NO_FOGGING);
// maybe render a special hud-target-only model
if (target_sip->model_num_hud >= 0) {
model_render_immediate(&render_info, target_sip->model_num_hud, &target_objp->orient, &obj_pos);
} else {
render_info.set_replacement_textures(
model_get_instance(target_shipp->model_instance_num)->texture_replace);
model_render_immediate(&render_info, target_sip->model_num, &target_objp->orient, &obj_pos);
}
Glowpoint_override = false;
if (Monitor_mask >= 0) {
gr_stencil_set(GR_STENCIL_NONE);
}
int sx = 0;
int sy = 0;
// check if subsystem target has changed
if (Player_ai->targeted_subsys == Player_ai->last_subsys_target) {
vec3d save_pos;
if (gr_screen.rendering_to_texture != -1) {
gr_set_screen_scale(canvas_w, canvas_h, -1, -1, target_w, target_h, target_w, target_h, true);
} else {
gr_set_screen_scale(base_w, base_h);
}
save_pos = target_objp->pos;
target_objp->pos = obj_pos;
int subsys_in_view = hud_targetbox_subsystem_in_view(target_objp, &sx, &sy);
target_objp->pos = save_pos;
if (subsys_in_view != -1) {
// AL 29-3-98: If subsystem is destroyed, draw gray brackets
// Goober5000 - hm, caught a tricky bug for destroyable fighterbays
if ((Player_ai->targeted_subsys->current_hits <= 0) &&
ship_subsys_takes_damage(Player_ai->targeted_subsys)) {
gr_set_color_fast(iff_get_color(IFF_COLOR_MESSAGE, 1));
} else {
hud_set_iff_color(target_objp, 1);
}
graphics::line_draw_list line_draw_list;
if (subsys_in_view) {
draw_brackets_square_quick(&line_draw_list, sx - 10, sy - 10, sx + 10, sy + 10);
} else {
draw_brackets_diamond_quick(&line_draw_list, sx - 10, sy - 10, sx + 10, sy + 10);
}
line_draw_list.flush();
}
}
renderTargetClose();
}
}
renderTargetForeground(config);
renderTargetIntegrity(0,config ? -1 : OBJ_INDEX(target_objp), config);
setGaugeColor(HUD_C_NONE, config);
renderTargetShipInfo(target_objp, config);
if (!config) {
maybeRenderCargoScan(target_sip, Player_ai->targeted_subsys);
}
}
/**
* @note formerly hud_render_target_debris(object *target_objp) (Swifty)
*/
void HudGaugeTargetBox::renderTargetDebris(object *target_objp)
{
vec3d obj_pos = ZERO_VECTOR;
vec3d camera_eye = ZERO_VECTOR;
matrix camera_orient = IDENTITY_MATRIX;
debris *debrisp;
float factor;
uint64_t flags = 0;
debrisp = &Debris[target_objp->instance];
if ( Detail.targetview_model ) {
// take the forward orientation to be the vector from the player to the current target
vec3d orient_vec;
vm_vec_normalized_dir(&orient_vec, &target_objp->pos, &Player_obj->pos);
factor = 2*target_objp->radius;
// use the player's up vector, and construct the viewer's orientation matrix
vec3d tempv;
object_get_eye(&tempv, &camera_orient, Player_obj, false);
auto up_vector = &camera_orient.vec.uvec;
vm_vector_2_matrix_norm(&camera_orient, &orient_vec, up_vector, nullptr);
// normalize the vector from the player to the current target, and scale by a factor to calculate
// the objects position
vm_vec_copy_scale(&obj_pos,&orient_vec,factor);
renderTargetSetup(&camera_eye, &camera_orient, 0.5f);
model_clear_instance(debrisp->model_num);
model_render_params render_info;
if (debrisp->model_instance_num >= 0)
render_info.set_replacement_textures(model_get_instance(debrisp->model_instance_num)->texture_replace);
color thisColor = GaugeWirecolor;
bool thisOverride = GaugeWirecolorOverride;
switch (CurrentWire) {
case 0:
flags |= MR_NO_LIGHTING;
break;
case 1:
if (thisOverride) {
render_info.set_color(thisColor);
} else {
render_info.set_color(255, 255, 255);
}
flags = MR_SHOW_OUTLINE_HTL | MR_NO_POLYS | MR_NO_LIGHTING | MR_NO_TEXTURING;
break;
case 2:
break;
case 3:
if (thisOverride) {
render_info.set_color(thisColor);
} else {
render_info.set_color(255, 255, 255);
}
flags |= MR_NO_LIGHTING | MR_NO_TEXTURING;
break;
}
if(Targetbox_shader_effect > -1) {
render_info.set_animated_effect(Targetbox_shader_effect, 0.0f);
}
if ( Monitor_mask >= 0 ) {
gr_stencil_set(GR_STENCIL_READ);
}
if ( Desaturated ) {
flags |= MR_DESATURATED;
render_info.set_color(gauge_color);
}
render_info.set_flags(flags | MR_NO_FOGGING);
auto pm = model_get(debrisp->model_num);
auto pmi = debrisp->model_instance_num < 0 ? nullptr : model_get_instance(debrisp->model_instance_num);
// This calls the colour that doesn't get reset
submodel_render_immediate( &render_info, pm, pmi, debrisp->submodel_num, &target_objp->orient, &obj_pos);
if ( Monitor_mask >= 0 ) {
gr_stencil_set(GR_STENCIL_NONE);
}
renderTargetClose();
}
renderTargetForeground();
renderTargetIntegrity(1);
// print out ship class that debris came from
const char *printable_ship_class;
if (debrisp->parent_alt_name >= 0)
printable_ship_class = mission_parse_lookup_alt_index(debrisp->parent_alt_name);
else
printable_ship_class = Ship_info[debrisp->ship_info_index].get_display_name();
renderString(position[0] + Class_offsets[0], position[1] + Class_offsets[1], EG_TBOX_CLASS, printable_ship_class);
renderString(position[0] + Name_offsets[0], position[1] + Name_offsets[1], EG_TBOX_NAME, XSTR("debris", 348));
}
/**
* @note Formerly hud_render_target_weapon(object *target_objp)
*/
void HudGaugeTargetBox::renderTargetWeapon(object *target_objp)
{
vec3d obj_pos = ZERO_VECTOR;
vec3d camera_eye = ZERO_VECTOR;
matrix camera_orient = IDENTITY_MATRIX;
weapon_info *target_wip = NULL;
weapon *wp = NULL;
object *viewer_obj, *viewed_obj;
std::shared_ptr<model_texture_replace> replacement_textures = nullptr;
int target_team, is_homing, is_player_missile, missile_view, viewed_model_num, hud_target_lod, w, h;
uint64_t flags = 0;
target_team = obj_team(target_objp);
wp = &Weapons[target_objp->instance];
target_wip = &Weapon_info[wp->weapon_info_index];
if (target_wip->model_num == -1)
return;
is_homing = FALSE;
if ( target_wip->is_homing() && weapon_has_homing_object(wp) )
is_homing = TRUE;
is_player_missile = FALSE;
if ( target_objp->parent_sig == Player_obj->signature ) {
is_player_missile = TRUE;
}
if ( Detail.targetview_model ) {
ship *homing_shipp = NULL;
ship_info *homing_sip = NULL;
viewer_obj = Player_obj;
viewed_obj = target_objp;
missile_view = FALSE;
viewed_model_num = target_wip->model_num;
hud_target_lod = target_wip->hud_target_lod;
// adding a check here to make sure the homing object is a ship, technically it could be some other object just as well
if ( is_homing && is_player_missile && (wp->homing_object->type == OBJ_SHIP)) {
homing_shipp = &Ships[wp->homing_object->instance];
homing_sip = &Ship_info[homing_shipp->ship_info_index];
viewer_obj = target_objp;
viewed_obj = wp->homing_object;
missile_view = TRUE;
viewed_model_num = homing_sip->model_num;
hud_target_lod = homing_sip->hud_target_lod;
}
int pmi_id = object_get_model_instance_num(viewed_obj);
if (pmi_id >= 0)
replacement_textures = model_get_instance(pmi_id)->texture_replace;
// take the forward orientation to be the vector from the player to the current target
vec3d orient_vec;
if (missile_view == FALSE)
vm_vec_normalized_dir(&orient_vec, &viewed_obj->pos, &viewer_obj->pos);
else
vm_vec_normalized_dir(&orient_vec, &wp->homing_pos, &viewer_obj->pos);
// use the viewer's up vector, and construct the viewer's orientation matrix
vec3d tempv;
object_get_eye(&tempv, &camera_orient, Player_obj, false);
auto up_vector = &camera_orient.vec.uvec;
vm_vector_2_matrix_norm(&camera_orient, &orient_vec, up_vector, nullptr);
// normalize the vector from the viewer to the viwed target, and scale by a factor to calculate
// the objects position
if (missile_view == FALSE) {
float factor = 2*target_objp->radius;
// small radius missiles need a bigger factor otherwise they are rendered larger than the targetbox
if (factor < 8.0f) {
factor = 8.0f;
}
vm_vec_copy_scale(&obj_pos,&orient_vec,factor);
} else {
vm_vec_sub(&obj_pos, &viewed_obj->pos, &viewer_obj->pos);
}