-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathasw_hud_minimap.cpp
More file actions
2259 lines (1943 loc) · 73.4 KB
/
Copy pathasw_hud_minimap.cpp
File metadata and controls
2259 lines (1943 loc) · 73.4 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
#include "cbase.h"
#include "hud.h"
#include "hud_macros.h"
#include "view.h"
//#include "kbutton.h"
#include "input.h"
#include "iclientmode.h"
#define PAIN_NAME "sprites/%d_pain.vmt"
#include <KeyValues.h>
#include <vgui/ISurface.h>
#include <vgui/ISystem.h>
#include <vgui_controls/AnimationController.h>
#include <vgui_controls/ImagePanel.h>
#include <vgui/ILocalize.h>
using namespace vgui;
#include "filesystem.h"
#include <keyvalues.h>
#include "asw_hud_minimap.h"
#include "c_asw_player.h"
#include "c_playerresource.h"
#include "c_asw_marine.h"
#include "asw_marine_profile.h"
#include "c_asw_marine_resource.h"
#include "c_asw_game_resource.h"
#include "c_asw_scanner_info.h"
#include "vgui/ISurface.h"
#include <vgui/IInput.h>
#include "fx.h"
#include "tier0/vprof.h"
#include "asw_gamerules.h"
#include "ScanLinePanel.h"
#include "c_asw_scanner_noise.h"
#include "SoftLine.h"
#include "c_asw_objective.h"
#include "c_asw_marker.h"
#include "asw_input.h"
#include "ConVar.h"
#include "c_asw_parasite.h"
#include "asw_weapon_revive_tool_shared.h"
#include "asw_util_shared.h"
#include "rd_map_texture_shared.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
extern ConVar asw_draw_hud;
extern ConVar asw_hud_alpha;
extern ConVar asw_hud_scale;
extern ConVar rd_paint_marine_blips;
extern ConVar rd_paint_scanner_blips;
extern ConVar rd_revive_tombstone_shows_on_map;
ConVar rd_draw_minimap( "rd_draw_minimap", "1", FCVAR_NONE );
ConVar asw_map_range( "asw_map_range", "1200", FCVAR_CHEAT, "Range in world units of the minimap" );
ConVar asw_scanner_ring_scale( "asw_scanner_ring_scale", "1.0f", FCVAR_CHEAT, "Overdraw in the scanner ring size from the blip boundary" );
ConVar asw_scanner_pitch_change( "asw_scanner_pitch_change", "0.2f", FCVAR_NONE, "Change in pitch (from 0 to 1.0) of scanner blips depending on distance from the tech marine" );
ConVar asw_scanner_pitch_base( "asw_scanner_pitch_base", "1.2f", FCVAR_NONE, "Starting pitch" );
ConVar asw_scanner_warning_volume( "asw_scanner_warning_volume", "0.3f", FCVAR_NONE, "Volume of scanner warning beeps" );
ConVar asw_scanner_idle_volume( "asw_scanner_idle_volume", "0.4f", FCVAR_NONE, "Volume of scanner idle loop" );
ConVar asw_scanner_scanline_alpha( "asw_scanner_scanline_alpha", "80", 0, "Alpha of scanlines on the scanner" );
ConVar asw_scanner_scanline_double( "asw_scanner_scanline_double", "0", 0, "Whether scanlines should be single or double pixel" );
ConVar asw_scanner_interlace_alpha( "asw_scanner_interlace_alpha", "0", 0, "Alpha of interlace effect on the scanner" );
ConVar asw_scanner_noise_alpha( "asw_scanner_noise_alpha", "0", 0, "Alpha of noise effect on the scanner" );
ConVar asw_scanner_idle_sound( "asw_scanner_idle_sound", "3", 0, "Which scanner idle sound is used (from 1 to 4)" );
ConVar asw_scanner_warning_sound( "asw_scanner_warning_sound", "1", 0, "Which scanner warning sound is used (from 1 to 3)" );
ConVar asw_debug_scanner_sound( "asw_debug_scanner_sound", "0", FCVAR_CHEAT, "Prints debug output on scanner pulses" );
ConVar asw_minimap_clicks( "asw_minimap_clicks", "1", FCVAR_ARCHIVE, "Is enabled, clicking on the minimap will draw on it. If disabled, clicking there will fire your weapon as normal" );
ConVar asw_scanner_background( "asw_scanner_background", "1", FCVAR_NONE, "Draw black background behind minimap" );
ConVar asw_scanner_classic( "asw_scanner_classic", "0", FCVAR_NONE, "Scanner has white blips, is always pinging." );
ConVar rd_hud_minimap_drawing( "rd_hud_minimap_drawing", "1", FCVAR_NONE, "Allow drawing on the minimap." );
ConVar asw_use_blip_colors( "asw_use_blip_colors", "1", FCVAR_NONE, "Set to 1 to use custom blip colors" );
ConVar asw_blip_color_alien( "asw_blip_color_alien", "130 230 0", FCVAR_NONE, "The blip color for mortars, harvesters, zombies, antlions" );
ConVar asw_blip_color_boomer( "asw_blip_color_boomer", "255 255 255", FCVAR_NONE, "The boomer blip color." );
ConVar asw_blip_color_buzzer( "asw_blip_color_buzzer", "0 255 255", FCVAR_NONE, "The buzzer blip color." );
ConVar asw_blip_color_drone( "asw_blip_color_drone", "250 110 110", FCVAR_NONE, "The drone blip color." );
ConVar asw_blip_color_parasite( "asw_blip_color_parasite", "0 255 0", FCVAR_NONE, "The parasite blip color." );
ConVar asw_blip_color_parasite_egg( "asw_blip_color_parasite_egg", "170 255 0", FCVAR_NONE, "The parasite blip color while inside an egg." );
ConVar asw_blip_color_parasite_defanged( "asw_blip_color_parasite_defanged", "128 0 0", FCVAR_NONE, "The parasite defanged blip color. Detection method requires correct parasite model" );
ConVar asw_blip_color_queen( "asw_blip_color_queen", "255 0 0", FCVAR_NONE, "The queen blip color." );
ConVar asw_blip_color_ranger( "asw_blip_color_ranger", "255 0 255", FCVAR_NONE, "The ranger blip color." );
ConVar asw_blip_color_shaman( "asw_blip_color_shaman", "255 0 128", FCVAR_NONE, "The shaman blip color." );
ConVar asw_blip_color_shieldbug( "asw_blip_color_shieldbug", "255 255 110", FCVAR_NONE, "The shieldbug blip color." );
ConVar asw_blip_color_antlionguard( "asw_blip_color_antlionguard", "255 0 0", FCVAR_NONE, "The antlionguard blip color. Detection method may fail under very specific condions" );
ConVar asw_blip_color_used_marine( "asw_blip_color_used_marine", "255 255 0", FCVAR_NONE, "Blip color of used marine" );
ConVar asw_blip_color_other_marine( "asw_blip_color_other_marine", "0 192 0", FCVAR_NONE, "Blip color of other marines" );
ConVar asw_blip_color_other_marine_use_classtype( "asw_blip_color_other_marine_use_classtype", "0", FCVAR_NONE, "Set to 1 to use other marines coloring by their class" );
ConVar asw_blip_color_marine_officer( "asw_blip_color_marine_officer", "0 192 0", FCVAR_NONE, "Blip color of officer marines" );
ConVar asw_blip_color_marine_special( "asw_blip_color_marine_special", "0 0 192", FCVAR_NONE, "Blip color of special weapon marines" );
ConVar asw_blip_color_marine_medic( "asw_blip_color_marine_medic", "192 0 0", FCVAR_NONE, "Blip color of medic marines" );
ConVar asw_blip_color_marine_tech( "asw_blip_color_marine_tech", "192 142 0", FCVAR_NONE, "Blip color of tech marines" );
ConVar asw_draw_blips_real_time( "asw_draw_blips_real_time", "1", FCVAR_ARCHIVE, "Draw alien blips in realtime.", true, 0, true, 1 );
ConVar asw_draw_scanner_rings( "asw_draw_scanner_rings", "1", FCVAR_NONE );
// was 0.75f..
#define ASW_SCREENSHOT_SCALE 1.0f
MapLine::MapLine()
{
worldpos.Init( 0, 0 );
player_index = 0;
linkpos.Init( 0, 0 );
created_time = 0;
bSetLinkBlipCentre = false;
bSetBlipCentre = false;
blipcentre.Init( 0, 0 );
linkblipcentre.Init( 0, 0 );
bLink = false;
}
class CASWHudMinimap;
class CASWHudMinimapLinePanel : public vgui::Panel
{
DECLARE_CLASS_SIMPLE( CASWHudMinimapLinePanel, vgui::Panel );
public:
CASWHudMinimapLinePanel( Panel *parent, const char *panelName, CASWHudMinimap *pMap );
void TextureToLinePanel( CASWHudMinimap *pMap, const Vector2D &blip_centre, float &x, float &y );
virtual void Paint();
void PaintFollowLine( C_BaseEntity *pMarine, C_BaseEntity *pTarget );
void PaintFollowLines();
virtual void PaintScannerRing();
CPanelAnimationVarAliasType( int, m_nScannerRingTexture, "ScannerRingTexture", "vgui/swarm/HUD/ScannerRing", "textureid" );
CASWHudMinimap *m_pMap;
};
class CASWHudMinimapFramePanel : public vgui::Panel
{
DECLARE_CLASS_SIMPLE( CASWHudMinimapFramePanel, vgui::Panel );
public:
CASWHudMinimapFramePanel( Panel *parent, const char *panelName );
virtual void Paint();
};
DECLARE_HUDELEMENT_DEPTH( CASWHudMinimap, 40 );
CASWHudMinimapLinePanel::CASWHudMinimapLinePanel( Panel *parent, const char *panelName, CASWHudMinimap *pMap ) :
vgui::Panel( parent, panelName ),
m_pMap( pMap )
{
}
CASWHudMinimapFramePanel::CASWHudMinimapFramePanel( Panel *parent, const char *panelName ) :
vgui::Panel( parent, panelName )
{
}
void MsgFunc_ASWMapLine( bf_read &msg )
{
if ( !rd_hud_minimap_drawing.GetBool() )
return;
int linetype = msg.ReadByte();
int player_index = msg.ReadByte();
int world_x = msg.ReadLong();
int world_y = msg.ReadLong();
if ( g_PR->IsMuted( player_index ) )
return;
C_ASW_Player *local = C_ASW_Player::GetLocalASWPlayer();
if ( local )
{
// figure out the position of this map line dot
Vector vecMapLinePos = vec3_origin;
vecMapLinePos.x = world_x;
vecMapLinePos.y = world_y;
CASWHudMinimap *pMiniMap = GET_HUDELEMENT( CASWHudMinimap );
if ( !pMiniMap )
return;
// make the HUD store it
MapLine line;
line.player_index = player_index;
line.worldpos.x = world_x;
line.worldpos.y = world_y;
line.created_time = gpGlobals->curtime;
if ( linetype == 1 ) // links to a previous
{
line.bLink = true;
}
else
{
if ( gpGlobals->curtime > pMiniMap->m_fLastMinimapDrawSound + 5.0f )
{
CLocalPlayerFilter filter;
C_BaseEntity::EmitSound( filter, -1, "ASWScanner.Drawing" );
pMiniMap->m_fLastMinimapDrawSound = gpGlobals->curtime;
}
}
pMiniMap->m_MapLines.AddToTail( line );
}
}
// v.x * X + v.y * Y + v.z = 0
// based on https://stackoverflow.com/a/45268241
static void LineVector( const Vector2D &a, const Vector2D &b, Vector &v )
{
v.x = b.y - a.y;
v.y = a.x - b.x;
v.z = b.x * a.y - b.y * a.x;
}
// compare a point with a line (distance "above" or "below")
// based on https://stackoverflow.com/a/45268241
static float LinePointCmp( const Vector &l, const Vector2D &p )
{
return l.x * p.x + l.y * p.y + l.z;
}
// based on https://stackoverflow.com/a/45268241
template<int N>
static void ClipPolygonToLine( int &count, Vertex_t( &intersection )[N], Vertex_t( &newIntersection )[N], const Vector2D &p, const Vector2D &q )
{
Assert( count >= 0 && count < N );
if ( !count )
{
return;
}
Vector line;
LineVector( p, q, line );
int newCount = 0;
float lineValues[N];
for ( int i = 0; i < count; i++ )
{
lineValues[i] = LinePointCmp( line, intersection[i].m_Position );
}
for ( int i = 0; i < count; i++ )
{
const Vertex_t &s = intersection[i];
const Vertex_t &t = intersection[( i + 1 ) % count];
float sValue = lineValues[i];
float tValue = lineValues[( i + 1 ) % count];
if ( sValue <= 0 )
{
Assert( newCount < N );
newIntersection[newCount++] = s;
}
if ( sValue * tValue < 0 )
{
Assert( newCount < N );
Vector stLine;
LineVector( s.m_Position, t.m_Position, stLine );
float w = line.x * stLine.y - line.y * stLine.x;
Vector2D newPos{
( line.y * stLine.z - line.z * stLine.y ) / w,
( line.z * stLine.x - line.x * stLine.z ) / w,
}, newTex;
Vector2DLerp( s.m_TexCoord, t.m_TexCoord, s.m_Position.DistTo( newPos ) / s.m_Position.DistTo( t.m_Position ), newTex );
newIntersection[newCount++] = Vertex_t{ newPos, newTex };
}
}
if ( newCount <= 2 )
{
count = 0;
return;
}
count = newCount;
}
// based on https://stackoverflow.com/a/45268241
template<int N>
static void ClipToSquare( int &nPoints, Vertex_t( &vertices )[N], const Vector2D &topLeft, float flSize )
{
Assert( nPoints + 4 <= N );
Vector2D bottomRight{ topLeft.x + flSize, topLeft.y + flSize };
Vector2D topRight{ bottomRight.x, topLeft.y };
Vector2D bottomLeft{ topLeft.x, bottomRight.y };
Vertex_t tempVertices[N];
ClipPolygonToLine( nPoints, vertices, tempVertices, topLeft, topRight );
ClipPolygonToLine( nPoints, tempVertices, vertices, topRight, bottomRight );
ClipPolygonToLine( nPoints, vertices, tempVertices, bottomRight, bottomLeft );
ClipPolygonToLine( nPoints, tempVertices, vertices, bottomLeft, topLeft );
}
//////////
// CASWMap
//////////
// converts a world coord into map texture coords (0->1023)
Vector2D CASWMap::WorldToMapTexture( const Vector &worldpos )
{
if ( !m_pMinimap )
{
m_pMinimap = GET_HUDELEMENT( CASWHudMinimap );
if ( !m_pMinimap )
{
return vec2_origin;
}
}
Vector2D offset( worldpos.x - m_pMinimap->m_MapOrigin.x, worldpos.y - m_pMinimap->m_MapOrigin.y );
offset.x /= m_pMinimap->m_fMapScale;
offset.y /= -m_pMinimap->m_fMapScale;
// This was in the original release of Alien Swarm in 2010.
// Because of this, all map centers in all map overviews are wrong.
// We just have to deal with it, because map overviews are not versioned.
//
// cl_leveloverview has been modified in Alien Swarm: Reactive Drop to
// return fudged coordinates to match this.
offset.x -= 128;
return offset;
}
void CASWMap::AddBlip( const MapBlip_t &blip )
{
m_MapBlips.AddToTail( blip );
}
void CASWMap::ClearBlips( void )
{
m_MapBlips.RemoveAll();
}
void CASWMap::PaintMarineBlips( bool bRotate )
{
C_ASW_Game_Resource *pGameResource = ASWGameResource();
if ( pGameResource )
{
C_ASW_Marine *pLocalMarine = C_ASW_Marine::GetViewMarine();
// paint the blips
for ( int i = 0; i < ASW_MAX_MARINE_RESOURCES; i++ )
{
C_ASW_Marine_Resource *pMR = pGameResource->GetMarineResource( i );
if ( pMR )
{
C_ASW_Marine *pMarine = pMR->GetMarineEntity();
if ( pMarine && pMarine->GetHealth() > 0 )
{
if ( rd_paint_marine_blips.GetInt() == 2 && ASWDeathmatchMode() ) // if 2 we paint our blip for all modes and team mates' blips for TDM
{
switch ( ASWDeathmatchMode()->GetGameMode() )
{
case GAMEMODE_DEATHMATCH:
case GAMEMODE_INSTAGIB:
case GAMEMODE_GUNGAME:
default:
if ( pLocalMarine != pMarine )
continue; // don't render any marine except ours
break;
case GAMEMODE_TEAMDEATHMATCH:
if ( pLocalMarine && pLocalMarine->GetTeamNumber() != pMarine->GetTeamNumber() )
continue; // don't render blip for enemy team marines
break;
}
}
Color blipColor;
bool bClassColorings = asw_blip_color_other_marine_use_classtype.GetBool();
if ( !bClassColorings )
{
blipColor = ( pLocalMarine != pMarine ) ? asw_blip_color_other_marine.GetColor() : asw_blip_color_used_marine.GetColor();
}
else
{
if ( pLocalMarine == pMarine )
{
blipColor = asw_blip_color_used_marine.GetColor();
}
else
{
CASW_Marine_Profile *pProfile = pMR->GetProfile();
if ( pProfile )
{
switch ( pProfile->GetMarineClass() )
{
default:
case MARINE_CLASS_UNDEFINED:
case MARINE_CLASS_NCO:
blipColor = asw_blip_color_marine_officer.GetColor();
break;
case MARINE_CLASS_SPECIAL_WEAPONS:
blipColor = asw_blip_color_marine_special.GetColor();
break;
case MARINE_CLASS_MEDIC:
blipColor = asw_blip_color_marine_medic.GetColor();
break;
case MARINE_CLASS_TECH:
blipColor = asw_blip_color_marine_tech.GetColor();
break;
}
}
else
{
//should never happen but in case need to initialise blipColor
blipColor = asw_blip_color_used_marine.GetColor();
}
}
}
if ( rd_paint_marine_blips.GetInt() == 3 && ASWDeathmatchMode() && ASWDeathmatchMode()->GetGameMode() == GAMEMODE_TEAMDEATHMATCH )
{
blipColor.SetColor( pMarine->GetRenderColorR(), pMarine->GetRenderColorG(), pMarine->GetRenderColorB(), 255 );
}
Color blipColorTr = Color( blipColor.r(), blipColor.g(), blipColor.b(), 255 - 127.0f * pMarine->GetBlipStrength() );
PaintWorldBlip( pMarine->GetAbsOrigin(), pMarine->GetBlipStrength(), blipColor );
PaintWorldFacingArc( pMarine->GetAbsOrigin(), !bRotate ? pMarine->ASWEyeAngles().y : pMarine->ASWEyeAngles().y + 90 - ( ASWInput() ? ASWInput()->ASW_GetCameraYaw() : 90 ), blipColorTr );
}
}
}
}
}
void CASWMap::PaintTombstoneBlips()
{
#ifdef RD_7A_WEAPONS
FOR_EACH_VEC( IASW_Revive_Tombstone_Auto_List::AutoList(), i )
{
PaintWorldBlip( IASW_Revive_Tombstone_Auto_List::AutoList()[i]->GetEntity()->GetAbsOrigin(), 1.0f, Color{ 255, 255, 255, 255 }, MAP_BLIP_TEXTURE_DEATH );
}
#endif
}
void CASWMap::PaintExtraBlips()
{
for ( int i = 0; i < m_MapBlips.Count(); i++ )
{
PaintWorldBlip( m_MapBlips[i].vWorldPos, sinf( gpGlobals->curtime * 8.0f ) * 0.25 + 0.25f, m_MapBlips[i].rgbaColor, m_MapBlips[i].nTextureType );
}
}
void CASWMap::PaintWorldBlip( const Vector &worldpos, float fBlipStrength, Color BlipColor, MapBlipTexture_t nBlipTexture /*= MAP_BLIP_TEXTURE_NORMAL*/ )
{
PaintWorldBlip( worldpos, fBlipStrength, BlipColor, 0, nBlipTexture );
}
void CASWMap::PaintWorldBlip( const Vector &worldpos, float fBlipStrength, Color BlipColor, int radius, MapBlipTexture_t nBlipTexture /*= MAP_BLIP_TEXTURE_NORMAL*/ )
{
int nStrengthIndex = clamp<int>( fBlipStrength * 7, 0, 7 );
if ( nStrengthIndex >= 7 || !m_nBlipTexture[nStrengthIndex] )
return;
Vector2D blip_centre = WorldToMapTexture( worldpos ); // convert from world coords to the pixel on the 0->1023 map texture
//blip_centre = blip_centre - m_MapCentre + m_MapCentreInPanel;
blip_centre = MapTextureToPanel( blip_centre ); // convert from the map texture to its position on the panel
Vector2D vMapCornerInPanel = GetMapCornerInPanel();
// don't draw out of bounds
if ( blip_centre.x < vMapCornerInPanel.x || blip_centre.x > vMapCornerInPanel.x + GetMapSize() ||
blip_centre.y < vMapCornerInPanel.y || blip_centre.y > vMapCornerInPanel.y + GetMapSize() )
return;
surface()->DrawSetColor( BlipColor );
int nTextureID;
int iBlipSize = GetBlipSize();
switch ( nBlipTexture )
{
case MAP_BLIP_TEXTURE_USABLE:
nTextureID = m_nTriBlipTexture[nStrengthIndex];
break;
case MAP_BLIP_TEXTURE_DEATH:
nTextureID = m_nBlipTextureDeath;
iBlipSize *= 1.5;
break;
case MAP_BLIP_TEXTURE_NORMAL:
default:
nTextureID = m_nBlipTexture[nStrengthIndex];
break;
}
surface()->DrawSetTexture( nTextureID );
float Dest1X = blip_centre.x - ( iBlipSize * 0.5f );
float Dest1Y = blip_centre.y - ( iBlipSize * 0.5f );
float Dest2X = Dest1X + iBlipSize;
float Dest2Y = Dest1Y + iBlipSize;
Vertex_t points[4] =
{
Vertex_t( Vector2D( Dest1X, Dest1Y ), Vector2D( 0, 0 ) ),
Vertex_t( Vector2D( Dest2X, Dest1Y ), Vector2D( 1, 0 ) ),
Vertex_t( Vector2D( Dest2X, Dest2Y ), Vector2D( 1, 1 ) ),
Vertex_t( Vector2D( Dest1X, Dest2Y ), Vector2D( 0, 1 ) )
};
surface()->DrawTexturedPolygon( 4, points );
if ( radius > 0 && fBlipStrength < 0.5f && nBlipTexture == MAP_BLIP_TEXTURE_NORMAL )
{
surface()->DrawOutlinedCircle( blip_centre.x + 0.5f, blip_centre.y + 0.25f, radius * 2.0f * ( 0.5f - fBlipStrength * fBlipStrength ), radius * 10 );
}
}
void CASWMap::PaintWorldFacingArc( const Vector &worldpos, float fFacingYaw, Color FacingColor )
{
if ( GetFacingArcTexture() == -1 )
return;
Vector2D blip_centre = WorldToMapTexture( worldpos ); // convert from world coords to the pixel on the 0->1023 map texture
blip_centre = MapTextureToPanel( blip_centre ); // convert from the map texture to its position on the panel
Vector2D vMapCornerInPanel = GetMapCornerInPanel();
// don't draw out of bounds
if ( blip_centre.x < vMapCornerInPanel.x || blip_centre.y < vMapCornerInPanel.y ||
blip_centre.x > vMapCornerInPanel.x + GetMapSize() || blip_centre.y > vMapCornerInPanel.y + GetMapSize() )
return;
int iFacingSize = GetArcSize();
// set up a square to the right
int xoffset = -2; // temp? to make the arc look nice next to blips..
int yoffset = 1;
Vector vecCornerTL( xoffset, iFacingSize * -0.5f + yoffset, 0 );
Vector vecCornerTR( iFacingSize + xoffset, iFacingSize * -0.5f + yoffset, 0 );
Vector vecCornerBR( iFacingSize + xoffset, iFacingSize * 0.5f + yoffset, 0 );
Vector vecCornerBL( xoffset, iFacingSize * 0.5f + yoffset, 0 );
Vector vecCornerTL_rotated, vecCornerTR_rotated, vecCornerBL_rotated, vecCornerBR_rotated;
// rotate it by our facing yaw
QAngle angFacing( 0, -fFacingYaw, 0 );
VectorRotate( vecCornerTL, angFacing, vecCornerTL_rotated );
VectorRotate( vecCornerTR, angFacing, vecCornerTR_rotated );
VectorRotate( vecCornerBR, angFacing, vecCornerBR_rotated );
VectorRotate( vecCornerBL, angFacing, vecCornerBL_rotated );
surface()->DrawSetColor( FacingColor );
surface()->DrawSetTexture( GetFacingArcTexture() );
//surface()->DrawTexturedRect(Dest1X,Dest1Y,Dest2X,Dest2Y);
Vertex_t points[4] =
{
Vertex_t( Vector2D( blip_centre.x + vecCornerTL_rotated.x, blip_centre.y + vecCornerTL_rotated.y ), Vector2D( 0,0 ) ),
Vertex_t( Vector2D( blip_centre.x + vecCornerTR_rotated.x, blip_centre.y + vecCornerTR_rotated.y ), Vector2D( 1,0 ) ),
Vertex_t( Vector2D( blip_centre.x + vecCornerBR_rotated.x, blip_centre.y + vecCornerBR_rotated.y ), Vector2D( 1,1 ) ),
Vertex_t( Vector2D( blip_centre.x + vecCornerBL_rotated.x, blip_centre.y + vecCornerBL_rotated.y ), Vector2D( 0,1 ) )
};
surface()->DrawTexturedPolygon( 4, points );
}
void CASWMap::LoadBlipTextures()
{
char buffer[64];
for ( int i = 0; i < 7; i++ )
{
m_nBlipTexture[i] = vgui::surface()->CreateNewTextureID();
Q_snprintf( buffer, sizeof( buffer ), "%s%d", "vgui/swarm/HUD/blip", i + 1 );
vgui::surface()->DrawSetTextureFile( m_nBlipTexture[i], buffer, true, false );
m_nTriBlipTexture[i] = vgui::surface()->CreateNewTextureID();
Q_snprintf( buffer, sizeof( buffer ), "%s%d", "vgui/swarm/HUD/triblip", i + 1 );
vgui::surface()->DrawSetTextureFile( m_nTriBlipTexture[i], buffer, true, false );
}
m_nBlipTextureDeath = vgui::surface()->CreateNewTextureID();
vgui::surface()->DrawSetTextureFile( m_nBlipTextureDeath, "vgui/swarm/Briefing/deadmarine", true, false );
m_nBlipTextureFriendlyDamage = m_nBlipTextureKill = m_nBlipTextureHeal = m_nBlipTextureFoundAmmo = m_nBlipTextureNoAmmo = m_nBlipTexture[0];
}
MapMarkCandidate::MapMarkCandidate( C_ASW_Objective *pLegacy )
{
HACK_GETLOCALPLAYER_GUARD( "need minimap for overview scale/center" );
CASWHudMinimap *pMap = GET_HUDELEMENT( CASWHudMinimap );
if ( !pMap )
{
return;
}
CSplitString split( STRING( pLegacy->m_LegacyMapMarkings ), " " );
if ( split.Count() < 5 || V_strcmp( split[0], "BRACKETS" ) )
{
center.Init();
size.Init();
yaw = 0;
dist = FLT_MAX;
return;
}
center.Init( atof( split[1] ), atof( split[2] ) );
size.Init( atof( split[3] ), atof( split[4] ) );
center = center + size / 2;
yaw = 0;
dist = pMap->m_MapCentre.DistToSqr( center );
}
MapMarkCandidate::MapMarkCandidate( C_ASW_Marker *pMarker )
{
HACK_GETLOCALPLAYER_GUARD( "need minimap for overview scale/center" );
CASWHudMinimap *pMap = GET_HUDELEMENT( CASWHudMinimap );
if ( !pMap )
{
return;
}
center = pMap->WorldToMapTexture( pMarker->GetAbsOrigin() );
size.Init(
pMarker->GetMapWidth() / pMap->m_fMapScale,
pMarker->GetMapHeight() / pMap->m_fMapScale
);
yaw = pMarker->GetAbsAngles()[YAW];
dist = pMap->m_MapCentre.DistToSqr( center );
}
CASWHudMinimap::CASWHudMinimap( const char *pElementName ) : CASW_HudElement( pElementName ), CHudNumericDisplay( NULL, "ASWHudMinimap" ), CASW_VGUI_Ingame_Panel()
{
SetHiddenBits( HIDEHUD_PLAYERDEAD | HIDEHUD_REMOTE_TURRET );
vgui::HScheme scheme = vgui::scheme()->LoadSchemeFromFile( "resource/SwarmSchemeNew.res", "SwarmSchemeNew" );
SetScheme( scheme );
m_pLinePanel = new CASWHudMinimapLinePanel( this, "CASWHudMinimapLinePanel", this );
//m_pFramePanel = new CASWHudMinimapFramePanel(this, "CASWHudMinimapFramePanel");
m_nWhiteTexture = vgui::surface()->CreateNewTextureID();
vgui::surface()->DrawSetTextureFile( m_nWhiteTexture, "vgui/white", true, false );
m_pScanLinePanel = new ScanLinePanel( this, "ScanlinePanel", false );
m_pInterlacePanel = new vgui::ImagePanel( this, "InterlacePanel" );
m_pNoisePanel = new vgui::ImagePanel( this, "NoisePanel" );
if ( asw_scanner_background.GetBool() )
{
m_pBackdrop = new CASWHudMinimap_Border( GetParent(), "MapBackdrop", this );
}
else
{
m_pBackdrop = NULL;
}
if ( m_pBackdrop )
{
m_pBackdrop->SetPaintBackgroundEnabled( true );
m_pBackdrop->SetPaintBackgroundType( 0 );
m_pBackdrop->SetBgColor( Color( 0, 0, 0, asw_hud_alpha.GetInt() ) );
MoveToFront();
}
m_bHasOverview = false;
m_szServerName[0] = '\0';
Q_snprintf( m_szMissionTitle, sizeof( m_szMissionTitle ), "" );
}
CASWHudMinimap::~CASWHudMinimap()
{
if ( m_pLinePanel )
m_pLinePanel->MarkForDeletion();
}
void CASWHudMinimap::PerformLayout()
{
BaseClass::PerformLayout();
int wide, tall, x, y;
GetBounds( x, y, wide, tall );
int ox, oy;
GetScaledOffset( ox, oy );
wide *= asw_hud_scale.GetFloat();
tall *= asw_hud_scale.GetFloat();
m_iMapSize = wide * 0.7f;
m_MapCornerInPanel.x = int( wide - m_iMapSize ) + ox;
m_MapCornerInPanel.y = int( tall - m_iMapSize ) + oy;
int black_border = m_iMapSize * 0.0455f;
if ( m_pBackdrop )
{
m_pBackdrop->SetBounds( x + m_MapCornerInPanel.x - black_border, y + m_MapCornerInPanel.y - black_border,
m_iMapSize + black_border * 2 + 1, m_iMapSize + black_border * 2 + 1 );
m_pBackdrop->SetBgColor( Color( 0, 0, 0, asw_hud_alpha.GetInt() ) );
}
m_pScanLinePanel->SetBounds( m_MapCornerInPanel.x, m_MapCornerInPanel.y, m_iMapSize, m_iMapSize );
m_pInterlacePanel->SetBounds( m_MapCornerInPanel.x, m_MapCornerInPanel.y, m_iMapSize, m_iMapSize );
m_pNoisePanel->SetBounds( m_MapCornerInPanel.x, m_MapCornerInPanel.y, m_iMapSize, m_iMapSize );
}
void CASWHudMinimap::Init()
{
gameeventmanager->AddListener( this, "game_newmap", false );
gameeventmanager->AddListener( this, "server_spawn", false );
m_pMinimap = this;
for ( int i = 0; i < ASW_MAX_MAP_VERTICAL_SECTIONS; i++ )
{
m_nMapTextureID[i] = -1;
m_flMapMinZ[i] = HUGE_VAL;
}
m_bHasOverview = false;
m_szLastLevelName.Clear();
m_bDrawingMapLines = false;
m_MapOrigin = Vector( 0, 0, 0 );
m_fMapScale = 1.0f;
m_fLastMapLine = 0;
m_fLastBlipSpeechTime = -100.0f;
m_fLastBlipHitTime = 0.0f;
m_MapCentre = Vector2D( 0, 0 );
m_MapCentreInPanel = Vector2D( 0, 0 );
Reset();
usermessages->HookMessage( "ASWMapLine", MsgFunc_ASWMapLine );
}
void CASWHudMinimap::Reset()
{
SetLabelText( L" " );
m_bDrawingMapLines = false;
m_fLastMapLine = 0;
m_fLastMinimapDrawSound = 0;
SetShouldDisplayValue( false );
}
void CASWHudMinimap::VidInit()
{
Reset();
}
void CASWHudMinimap::OnThink()
{
VPROF_BUDGET( "CASWHudMinimap::OnThink", VPROF_BUDGETGROUP_ASW_CLIENT );
if ( m_pScanLinePanel )
{
m_pScanLinePanel->SetAlpha( asw_scanner_scanline_alpha.GetInt() );
m_pScanLinePanel->m_bDouble = asw_scanner_scanline_double.GetBool();
}
if ( m_pInterlacePanel )
{
m_pInterlacePanel->SetAlpha( asw_scanner_interlace_alpha.GetInt() );
}
// remove any map lines that have faded out
for ( int i = 0; i < m_MapLines.Count(); i++ )
{
if ( gpGlobals->curtime - m_MapLines[i].created_time > MAP_LINE_SOLID_TIME + MAP_LINE_FADE_TIME )
m_MapLines.Remove( i );
}
C_ASW_Player *local = C_ASW_Player::GetLocalASWPlayer();
if ( local )
{
if ( m_bDrawingMapLines && gpGlobals->realtime >= m_fLastMapLine + MAP_LINE_INTERVAL )
{
if ( IsWithinMapBounds( m_iMouseX, m_iMouseY ) )
{
int ox, oy;
GetScaledOffset( ox, oy );
SendMapLine( m_iMouseX + ox, m_iMouseY + oy, false );
}
else
{
m_bDrawingMapLines = false;
}
}
C_ASW_Inhabitable_NPC *marine = local->GetViewNPC();
if ( marine )
{
if ( m_pNoisePanel )
{
float fScannerNoise = g_pScannerNoise ? g_pScannerNoise->GetScannerNoiseAt( marine->GetAbsOrigin() ) : 0;
m_pNoisePanel->SetAlpha( float( asw_scanner_noise_alpha.GetInt() ) * fScannerNoise );
}
}
else
{
m_pNoisePanel->SetAlpha( 0 );
}
}
}
void CASWHudMinimap::ApplySchemeSettings( IScheme *pScheme )
{
BaseClass::ApplySchemeSettings( pScheme );
SetBgColor( Color( 255, 255, 255, 0 ) );
m_pInterlacePanel->SetImage( "swarm/Computer/ComputerCameraBlack" );
m_pInterlacePanel->SetShouldScaleImage( true );
m_pNoisePanel->SetImage( "swarm/Computer/TVNoise" );
m_pNoisePanel->SetShouldScaleImage( true );
}
void CASWHudMinimapFramePanel::Paint()
{
VPROF_BUDGET( "CASWHudMinimapFramePanel::Paint", VPROF_BUDGETGROUP_ASW_CLIENT );
CASWHudMinimap *m_pMap = dynamic_cast< CASWHudMinimap * >( GetParent() );
if ( !m_pMap || !asw_draw_hud.GetBool() || rd_draw_minimap.GetFloat() <= 0 )
return;
int x, y, wide, tall;
m_pMap->GetBounds( x, y, wide, tall );
wide *= asw_hud_scale.GetFloat();
tall *= asw_hud_scale.GetFloat();
int ox, oy;
m_pMap->GetScaledOffset( ox, oy );
SetPos( ox, oy );
SetSize( wide, tall );
//if ( m_pMap->m_nFrameTexture == -1 )
//return;
//surface()->DrawSetColor(m_pMap->GetBgColor());
//surface()->DrawSetTexture(m_pMap->m_nFrameTexture);
//surface()->DrawTexturedRect(0, 0, wide, tall);
}
void CASWHudMinimap::GetScaledOffset( int &ox, int &oy )
{
int wide, tall;
GetSize( wide, tall );
int scaled_wide = wide * asw_hud_scale.GetFloat();
int scaled_tall = tall * asw_hud_scale.GetFloat();
ox = wide - scaled_wide;
oy = tall - scaled_tall;
}
void CASWHudMinimap::PaintMapSection()
{
ISurface *pSurface = surface();
int wide, tall;
GetSize( wide, tall );
wide *= asw_hud_scale.GetFloat();
tall *= asw_hud_scale.GetFloat();
int ox, oy;
GetScaledOffset( ox, oy );
m_iMapSize = wide * 0.7f;
m_MapCornerInPanel.x = int( wide - m_iMapSize ) + ox;
m_MapCornerInPanel.y = int( tall - m_iMapSize ) + oy;
m_MapCentreInPanel.x = m_MapCornerInPanel.x + m_iMapSize * 0.5f;
m_MapCentreInPanel.y = m_MapCornerInPanel.y + m_iMapSize * 0.5f;
m_pLinePanel->SetBounds( m_MapCornerInPanel.x, m_MapCornerInPanel.y,
m_MapCornerInPanel.x + m_iMapSize, m_MapCornerInPanel.y + m_iMapSize );
int alpha = clamp<int>( rd_draw_minimap.GetFloat() * 255.0f, 0, 255 );
C_ASW_Player *local = C_ASW_Player::GetLocalASWPlayer();
if ( local )
{
C_ASW_Inhabitable_NPC *marine = local->GetViewNPC();
if ( marine )
{
float z = marine->GetAbsOrigin().z;
m_MapCentre = WorldToMapTexture( marine->GetAbsOrigin() );
int iMapTextureIndex = 0;
while ( iMapTextureIndex + 1 < ASW_MAX_MAP_VERTICAL_SECTIONS && m_flMapMinZ[iMapTextureIndex + 1] <= z )
{
iMapTextureIndex++;
}
if ( iMapTextureIndex >= ASW_MAX_MAP_VERTICAL_SECTIONS || m_nMapTextureID[iMapTextureIndex] == -1 )
{
return;
}
if ( m_bHasOverview )
{
// draw a section of the minimap
int nPoints = 4;
Vertex_t points[8]
{
{ MapTextureToPanel( Vector2D( 0, 0 ) ), Vector2D( 0, 0 ) },
{ MapTextureToPanel( Vector2D( 1024, 0 ) ), Vector2D( 1, 0 ) },
{ MapTextureToPanel( Vector2D( 1024, 1024 ) ), Vector2D( 1, 1 ) },
{ MapTextureToPanel( Vector2D( 0, 1024 ) ), Vector2D( 0, 1 ) },
};
ClipToSquare( nPoints, points, m_MapCornerInPanel, m_iMapSize );
pSurface->DrawSetColor( 255, 255, 255, alpha );
pSurface->DrawSetTexture( m_nMapTextureID[iMapTextureIndex] );
pSurface->DrawTexturedPolygon( nPoints, points );
FOR_EACH_VEC( IRDMapTextures::AutoList(), i )
{
C_RD_Map_Texture *pTexture = assert_cast< C_RD_Map_Texture * >( IRDMapTextures::AutoList()[i]->GetEntity() );
Assert( pTexture );
if ( !pTexture || pTexture->m_bDisabled )
continue;
if ( !pTexture->m_hVGuiTexture )
{
pTexture->m_hVGuiTexture = pSurface->CreateNewTextureID();
pSurface->DrawSetTextureFile( pTexture->m_hVGuiTexture, pTexture->m_szMaterialName, 1, false );
}
nPoints = 4;
points[0].Init( MapTextureToPanel( WorldToMapTexture( pTexture->GetTopLeftCorner() ) ), Vector2D( 0, 0 ) );
points[1].Init( MapTextureToPanel( WorldToMapTexture( pTexture->GetTopRightCorner() ) ), Vector2D( 1, 0 ) );
points[2].Init( MapTextureToPanel( WorldToMapTexture( pTexture->GetBottomRightCorner() ) ), Vector2D( 1, 1 ) );
points[3].Init( MapTextureToPanel( WorldToMapTexture( pTexture->GetBottomLeftCorner() ) ), Vector2D( 0, 1 ) );
ClipToSquare( nPoints, points, m_MapCornerInPanel, m_iMapSize );
pSurface->DrawSetTexture( pTexture->m_hVGuiTexture );
pSurface->DrawTexturedPolygon( nPoints, points );
}
}
else
{
Assert( iMapTextureIndex == 0 );
int map_left = m_MapCornerInPanel.x;
int map_right = wide + ox;
int map_top = m_MapCornerInPanel.y;
int map_bottom = tall + oy;
// no overview, we're just drawing our scanner texture
Vertex_t points[4]
{
{ Vector2D( map_left, map_top ), Vector2D( 0, 0 ) },
{ Vector2D( map_right, map_top ), Vector2D( 1, 0 ) },
{ Vector2D( map_right, map_bottom ), Vector2D( 1, 1 ) },
{ Vector2D( map_left, map_bottom ), Vector2D( 0, 1 ) },
};
pSurface->DrawSetColor( 255, 255, 255, alpha );
pSurface->DrawSetTexture( m_nMapTextureID[iMapTextureIndex] );
pSurface->DrawTexturedPolygon( 4, points );
}
}
}
}
void CASWHudMinimap::Paint()
{
VPROF_BUDGET( "CASWHudMinimap::Paint", VPROF_BUDGETGROUP_ASW_CLIENT );
BaseClass::Paint();
PaintMapSection();
PaintObjectiveMarkers();
if ( ASWGameRules() && ASWGameRules()->GetGameState() == ASW_GS_INGAME )
{
// hack to make our child panel draw the follow lines underneath the marine blips painted by this panel
if ( m_pLinePanel )
{
vgui::VPANEL vpanel = m_pLinePanel->GetVPanel();
vgui::surface()->PushMakeCurrent( vpanel, true );
m_pLinePanel->PaintFollowLines();
vgui::surface()->PopMakeCurrent( vpanel );
}
PaintBlips();
}
else
{
C_ASW_Game_Resource *pGameResource = ASWGameResource();
if ( !pGameResource )
return;
C_ASW_Scanner_Info *pScanner = pGameResource->GetScannerInfo();
if ( !pScanner )
return;
// fade blips out
pScanner->CopyServerBlips();
pScanner->FadeBlips();
}
//PaintFrame();
}
void CASWHudMinimap::PaintObjectiveMarkers()
{
C_ASW_Game_Resource *pGameResource = ASWGameResource();
Assert( pGameResource );
if ( !pGameResource )