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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include <vgui/ISurface.h>
#include <vgui/ILocalize.h>
#include "dod_shareddefs.h"
#include "dodoverview.h"
#include "c_playerresource.h"
#include "c_dod_objective_resource.h"
#include "usermessages.h"
#include "coordsize.h"
#include "clientmode.h"
#include <vgui_controls/AnimationController.h>
#include "voice_status.h"
#include "spectatorgui.h"
#include "dod_hud_freezepanel.h"
using namespace vgui;
void __MsgFunc_UpdateRadar(bf_read &msg)
{
if ( !g_pMapOverview )
return;
int iPlayerEntity = msg.ReadByte();
while ( iPlayerEntity > 0 )
{
int x = msg.ReadSBitLong( COORD_INTEGER_BITS-1 ) * 4;
int y = msg.ReadSBitLong( COORD_INTEGER_BITS-1 ) * 4;
int a = msg.ReadSBitLong( 9 );
Vector origin( x, y, 0 );
QAngle angles( 0, a, 0 );
g_pMapOverview->SetPlayerPositions( iPlayerEntity-1, origin, angles );
iPlayerEntity = msg.ReadByte(); // read index for next player
}
}
extern ConVar _overview_mode;
ConVar _cl_minimapzoom( "_cl_minimapzoom", "1", FCVAR_ARCHIVE );
ConVar _overview_mode( "_overview_mode", "1", FCVAR_ARCHIVE, "Overview mode - 0=off, 1=inset, 2=full\n", true, 0, true, 2 );
CDODMapOverview *GetDODOverview( void )
{
return dynamic_cast<CDODMapOverview *>(g_pMapOverview);
}
// overview_togglezoom rotates through 3 levels of zoom for the small map
//-----------------------------------------------------------------------
void ToggleZoom( void )
{
if ( !GetDODOverview() )
return;
GetDODOverview()->ToggleZoom();
}
static ConCommand overview_togglezoom( "overview_togglezoom", ToggleZoom );
// overview_largemap toggles showing the large map
//------------------------------------------------
void ShowLargeMap( void )
{
if ( !GetDODOverview() )
return;
GetDODOverview()->ShowLargeMap();
}
static ConCommand overview_showlargemap( "+overview_largemap", ShowLargeMap );
void HideLargeMap( void )
{
if ( !GetDODOverview() )
return;
GetDODOverview()->HideLargeMap();
}
static ConCommand overview_hidelargemap( "-overview_largemap", HideLargeMap );
//--------------------------------
// map border ?
// icon minimum zoom
// flag swipes
// grenades
// chatting icon
// voice com icon
//---------------------------------
DECLARE_HUDELEMENT( CDODMapOverview );
ConVar dod_overview_voice_icon_size( "dod_overview_voice_icon_size", "64", FCVAR_ARCHIVE );
CDODMapOverview::CDODMapOverview( const char *pElementName ) : BaseClass( pElementName )
{
InitTeamColorsAndIcons();
m_flIconSize = 96.0f;
m_iLastMode = MAP_MODE_OFF;
usermessages->HookMessage( "UpdateRadar", __MsgFunc_UpdateRadar );
}
void CDODMapOverview::Update()
{
UpdateCapturePoints();
BaseClass::Update();
}
void CDODMapOverview::VidInit( void )
{
m_pC4Icon = gHUD.GetIcon( "icon_c4" );
m_pExplodedIcon = gHUD.GetIcon( "icon_c4_exploded" );
m_pC4PlantedBG = gHUD.GetIcon( "icon_c4_planted_bg" );
m_pIconDefended = gHUD.GetIcon( "icon_defended" );
BaseClass::VidInit();
}
void CDODMapOverview::UpdateCapturePoints()
{
if ( !g_pObjectiveResource )
return;
Color colorGreen(0,255,0,255);
if ( !g_pObjectiveResource )
return;
for( int i=0;i<g_pObjectiveResource->GetNumControlPoints();i++ )
{
// check if CP is visible at all
if( !g_pObjectiveResource->IsCPVisible(i) )
{
if ( m_CapturePoints[i] != 0 )
{
// remove capture point from map
RemoveObject( m_CapturePoints[i] );
m_CapturePoints[i] = 0;
}
continue;
}
// ok, show CP
int iOwningTeam = g_pObjectiveResource->GetOwningTeam(i);
int iCappingTeam = g_pObjectiveResource->GetCappingTeam(i);
int iOwningIcon = g_pObjectiveResource->GetIconForTeam( i, iOwningTeam );
if ( iOwningIcon <= 0 )
continue; // baah
const char *textureName = GetMaterialNameFromIndex( iOwningIcon );
int objID = m_CapturePoints[i];
if ( objID == 0 )
{
// add object if not already there
objID = m_CapturePoints[i] = AddObject( textureName, 0, -1 );
// objective positions never change (so far)
SetObjectPosition( objID, g_pObjectiveResource->GetCPPosition(i), vec3_angle );
AddObjectFlags( objID, MAP_OBJECT_ALIGN_TO_MAP );
}
SetObjectIcon( objID, textureName, 128.0 );
int iBombs = g_pObjectiveResource->GetBombsRemaining( i );
if ( iBombs > 0 )
{
char text[8];
Q_snprintf( text, sizeof(text), "%d", iBombs );
SetObjectText( objID, text, colorGreen );
}
//Draw the number of cappers below the icon
else if ( iCappingTeam != TEAM_UNASSIGNED )
{
int numPlayers = g_pObjectiveResource->GetNumPlayersInArea( i, iCappingTeam );
int requiredPlayers = g_pObjectiveResource->GetRequiredCappers( i, iCappingTeam );
if( requiredPlayers > 1 )
{
char text[8];
Q_snprintf( text, sizeof(text), "%d/%d", numPlayers, requiredPlayers );
SetObjectText( objID, text, colorGreen );
}
else
{
SetObjectText( objID, NULL, colorGreen );
}
}
else
{
SetObjectText( objID, NULL, colorGreen );
}
float flBombTime = g_pObjectiveResource->GetBombTimeForPoint( i );
//Draw cap percentage
if( iCappingTeam != TEAM_UNASSIGNED )
{
SetObjectStatus( objID, g_pObjectiveResource->GetCPCapPercentage(i), colorGreen );
}
else if ( flBombTime > 0 )
{
float flPercentRemaining = ( flBombTime / DOD_BOMB_TIMER_LENGTH );
SetObjectStatus( objID, flPercentRemaining, colorGreen );
}
else
{
SetObjectStatus( objID, -1, colorGreen ); // turn it off
}
}
}
void CDODMapOverview::InitTeamColorsAndIcons()
{
BaseClass::InitTeamColorsAndIcons();
m_TeamColors[TEAM_ALLIES] = COLOR_DOD_GREEN;
m_TeamIcons[TEAM_ALLIES] = AddIconTexture( "sprites/minimap_icons/aplayer" );
m_CameraIcons[TEAM_ALLIES] = AddIconTexture( "sprites/minimap_icons/allies_camera" );
m_TeamColors[TEAM_AXIS] = COLOR_DOD_RED;
m_TeamIcons[TEAM_AXIS] = AddIconTexture( "sprites/minimap_icons/gplayer" );
m_CameraIcons[TEAM_AXIS] = AddIconTexture( "sprites/minimap_icons/axis_camera" );
Q_memset( m_flPlayerChatTime, 0, sizeof(m_flPlayerChatTime ) );
m_iVoiceIcon = AddIconTexture( "voice/icntlk_pl" );
m_iChatIcon = AddIconTexture( "sprites/minimap_icons/voiceIcon" );
Q_memset( m_CapturePoints, 0, sizeof(m_CapturePoints) );
}
void CDODMapOverview::DrawCamera()
{
C_BasePlayer *localPlayer = C_BasePlayer::GetLocalPlayer();
if ( !localPlayer )
return;
int iTexture = m_CameraIcons[localPlayer->GetTeamNumber()];
if ( localPlayer->IsObserver() || iTexture <= 0 )
{
BaseClass::DrawCamera();
}
else
{
MapObject_t obj;
memset( &obj, 0, sizeof(MapObject_t) );
obj.icon = iTexture;
obj.position = localPlayer->GetAbsOrigin();
obj.size = m_flIconSize * 1.5;
obj.angle = localPlayer->EyeAngles();
obj.status = -1;
DrawIcon( &obj );
DrawVoiceIconForPlayer( localPlayer->entindex() - 1 );
}
}
void CDODMapOverview::FireGameEvent( IGameEvent *event )
{
const char * type = event->GetName();
if ( Q_strcmp(type, "player_death") == 0 )
{
MapPlayer_t *player = GetPlayerByUserID( event->GetInt("userid") );
if ( player && CanPlayerBeSeen( player ) )
{
// create skull icon for 3 seconds
int handle = AddObject( "sprites/minimap_icons/death", 0, 3 );
SetObjectText( handle, player->name, player->color );
SetObjectPosition( handle, player->position, player->angle );
}
}
else if ( Q_strcmp(type, "game_newmap") == 0 )
{
SetMode( _overview_mode.GetInt() );
}
BaseClass::FireGameEvent( event );
}
// rules that define if you can see a player on the overview or not
bool CDODMapOverview::CanPlayerBeSeen(MapPlayer_t *player)
{
C_BasePlayer *localPlayer = C_BasePlayer::GetLocalPlayer();
if ( !localPlayer || !player )
return false;
// don't draw ourselves
if ( localPlayer->entindex() == (player->index+1) )
return false;
// if local player is on spectator team, he can see everyone
if ( localPlayer->GetTeamNumber() <= TEAM_SPECTATOR )
return true;
// we never track unassigned or real spectators
if ( player->team <= TEAM_SPECTATOR )
return false;
// ingame and as dead player we can only see our own teammates
return (localPlayer->GetTeamNumber() == player->team );
}
void CDODMapOverview::ShowLargeMap( void )
{
// remember old mode
m_iLastMode = GetMode();
// if we hit the toggle while full, set to disappear when we release
if ( m_iLastMode == MAP_MODE_FULL )
m_iLastMode = MAP_MODE_OFF;
SetMode( MAP_MODE_FULL );
}
void CDODMapOverview::HideLargeMap( void )
{
SetMode( m_iLastMode );
}
void CDODMapOverview::ToggleZoom( void )
{
if ( GetMode() != MAP_MODE_INSET )
return;
int iZoomLevel = ( _cl_minimapzoom.GetInt() + 1 ) % DOD_MAP_ZOOM_LEVELS;
_cl_minimapzoom.SetValue( iZoomLevel );
switch( _cl_minimapzoom.GetInt() )
{
case 0:
g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( "MapZoomLevel1" );
break;
case 1:
default:
g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( "MapZoomLevel2" );
break;
}
}
void CDODMapOverview::SetMode(int mode)
{
m_flChangeSpeed = 0; // change size instantly
if ( mode == MAP_MODE_OFF )
{
ShowPanel( false );
g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( "MapOff" );
}
else if ( mode == MAP_MODE_INSET )
{
switch( _cl_minimapzoom.GetInt() )
{
case 0:
g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( "MapZoomLevel1" );
break;
case 1:
g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( "MapZoomLevel2" );
break;
case 2:
default:
g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( "MapZoomLevel3" );
break;
}
C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer();
if ( pPlayer )
SetFollowEntity( pPlayer->entindex() );
ShowPanel( true );
if ( m_nMode == MAP_MODE_FULL )
g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( "MapScaleToSmall" );
else
g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( "SnapToSmall" );
}
else if ( mode == MAP_MODE_FULL )
{
SetFollowEntity( 0 );
ShowPanel( true );
if ( m_nMode == MAP_MODE_INSET )
g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( "ZoomToLarge" );
else
g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( "SnapToLarge" );
}
// finally set mode
m_nMode = mode;
// save in a cvar for archive
_overview_mode.SetValue( m_nMode );
UpdateSizeAndPosition();
}
void CDODMapOverview::UpdateSizeAndPosition()
{
// move back up if the spectator menu is not visible
if ( !g_pSpectatorGUI || ( !g_pSpectatorGUI->IsVisible() && GetMode() == MAP_MODE_INSET ) )
{
int x,y,w,h;
GetBounds( x,y,w,h );
y = YRES(5); // hax, align to top of the screen
SetBounds( x,y,w,h );
}
BaseClass::UpdateSizeAndPosition();
}
void CDODMapOverview::AddGrenade( C_DODBaseGrenade *pGrenade )
{
C_BasePlayer *localPlayer = C_BasePlayer::GetLocalPlayer();
if ( !localPlayer )
return;
int localTeam = localPlayer->GetTeamNumber();
// Spectators can see all grenades
// players can only see them if they are on the same team
if ( localTeam == TEAM_SPECTATOR || ( localTeam == pGrenade->GetTeamNumber() ) )
{
AddObject( pGrenade->GetOverviewSpriteName(), pGrenade->entindex(), -1 );
}
}
void CDODMapOverview::RemoveGrenade( C_DODBaseGrenade *pGrenade )
{
RemoveObjectByIndex( pGrenade->entindex() );
}
ConVar cl_voicetest( "cl_voicetest", "0", FCVAR_CHEAT );
ConVar cl_overview_chat_time( "cl_overview_chat_time", "2.0", FCVAR_ARCHIVE );
void CDODMapOverview::PlayerChat( int index )
{
m_flPlayerChatTime[index-1] = gpGlobals->curtime + cl_overview_chat_time.GetFloat();
}
void CDODMapOverview::DrawMapPlayers()
{
BaseClass::DrawMapPlayers();
C_BasePlayer *localPlayer = C_BasePlayer::GetLocalPlayer();
Assert( localPlayer );
int iLocalPlayer = localPlayer->entindex() - 1;
for (int i=0; i<MAX_PLAYERS; i++)
{
if ( i == iLocalPlayer )
continue;
MapPlayer_t *player = &m_Players[i];
if ( !CanPlayerBeSeen( player ) )
continue;
if ( player->health <= 0 ) // don't draw dead players / spectators
continue;
DrawVoiceIconForPlayer( i );
}
}
void CDODMapOverview::DrawVoiceIconForPlayer( int playerIndex )
{
Assert( playerIndex >= 0 && playerIndex < MAX_PLAYERS );
MapPlayer_t *player = &m_Players[playerIndex];
// if they just sent a chat msg, or are using voice, or did a hand signal or voice command
// draw a chat icon
if ( cl_voicetest.GetInt() || GetClientVoiceMgr()->IsPlayerSpeaking( player->index+1 ) )
{
MapObject_t obj;
memset( &obj, 0, sizeof(MapObject_t) );
obj.icon = m_iVoiceIcon;
obj.position = player->position;
obj.size = dod_overview_voice_icon_size.GetFloat();
obj.status = -1;
DrawIcon( &obj );
}
else if ( m_flPlayerChatTime[player->index] > gpGlobals->curtime )
{
MapObject_t obj;
memset( &obj, 0, sizeof(MapObject_t) );
obj.icon = m_iChatIcon;
obj.position = player->position;
obj.size = dod_overview_voice_icon_size.GetFloat();
obj.status = -1;
DrawIcon( &obj );
}
}
bool CDODMapOverview::DrawIcon( MapObject_t *obj )
{
for ( int i=0;i<MAX_CONTROL_POINTS;i++ )
{
if ( obj->objectID == m_CapturePoints[i] && obj->objectID != 0 )
{
return DrawCapturePoint( i, obj );
}
}
return BaseClass::DrawIcon( obj );
}
void CDODMapOverview::DrawQuad( Vector pos, int scale, float angle, int textureID, int alpha )
{
Vector offset;
offset.z = 0;
offset.x = -scale; offset.y = scale;
VectorYawRotate( offset, angle, offset );
Vector2D pos1 = WorldToMap( pos + offset );
offset.x = scale; offset.y = scale;
VectorYawRotate( offset, angle, offset );
Vector2D pos2 = WorldToMap( pos + offset );
offset.x = scale; offset.y = -scale;
VectorYawRotate( offset, angle, offset );
Vector2D pos3 = WorldToMap( pos + offset );
offset.x = -scale; offset.y = -scale;
VectorYawRotate( offset, angle, offset );
Vector2D pos4 = WorldToMap( pos + offset );
Vertex_t points[4] =
{
Vertex_t( MapToPanel ( pos1 ), Vector2D(0,0) ),
Vertex_t( MapToPanel ( pos2 ), Vector2D(1,0) ),
Vertex_t( MapToPanel ( pos3 ), Vector2D(1,1) ),
Vertex_t( MapToPanel ( pos4 ), Vector2D(0,1) )
};
surface()->DrawSetColor( 255, 255, 255, alpha );
surface()->DrawSetTexture( textureID );
surface()->DrawTexturedPolygon( 4, points );
}
bool CDODMapOverview::DrawCapturePoint( int iCP, MapObject_t *obj )
{
int textureID = obj->icon;
Vector pos = obj->position;
float scale = obj->size;
float angle = 0;
Vector2D pospanel = WorldToMap( pos );
pospanel = MapToPanel( pospanel );
if ( !IsInPanel( pospanel ) )
return false; // player is not within overview panel
int iBombsRequired = g_pObjectiveResource->GetBombsRequired( iCP );
if ( iBombsRequired )
{
if ( g_pObjectiveResource->IsBombSetAtPoint( iCP ) )
{
// draw swipe over blank icon
// 'white' icon
int iBlankIcon = g_pObjectiveResource->GetCPTimerCapIcon( iCP );
const char *textureName = GetMaterialNameFromIndex( iBlankIcon );
DrawQuad( pos, scale, 0, AddIconTexture( textureName ), 255 );
// the circular swipe
float flBombTime = g_pObjectiveResource->GetBombTimeForPoint( iCP );
float flPercentRemaining = ( flBombTime / DOD_BOMB_TIMER_LENGTH );
DrawBombTimerSwipeIcon( pos, scale, textureID, flPercentRemaining );
}
else
{
DrawQuad( pos, scale, 0, textureID, 255 );
}
}
else
{
// draw capture swipe
DrawQuad( pos, scale, 0, textureID, 255 );
int iCappingTeam = g_pObjectiveResource->GetCappingTeam( iCP );
if ( iCappingTeam != TEAM_UNASSIGNED )
{
int iCapperIcon = g_pObjectiveResource->GetCPCappingIcon( iCP );
const char *textureName = GetMaterialNameFromIndex( iCapperIcon );
float flCapPercent = g_pObjectiveResource->GetCPCapPercentage(iCP);
bool bSwipeLeft = ( iCappingTeam == TEAM_AXIS ) ? true : false;
DrawHorizontalSwipe( pos, scale, AddIconTexture( textureName ), flCapPercent, bSwipeLeft );
}
// fixup for noone is capping, but someone is in the area
int iNumAllies = g_pObjectiveResource->GetNumPlayersInArea( iCP, TEAM_ALLIES );
int iNumAxis = g_pObjectiveResource->GetNumPlayersInArea( iCP, TEAM_AXIS );
int iOwningTeam = g_pObjectiveResource->GetOwningTeam( iCP );
if ( iCappingTeam == TEAM_UNASSIGNED )
{
if ( iNumAllies > 0 && iNumAxis == 0 && iOwningTeam != TEAM_ALLIES )
{
iCappingTeam = TEAM_ALLIES;
}
else if ( iNumAxis > 0 && iNumAllies == 0 && iOwningTeam != TEAM_AXIS )
{
iCappingTeam = TEAM_AXIS;
}
}
if ( iCappingTeam != TEAM_UNASSIGNED )
{
// Draw the number of cappers below the icon
int numPlayers = g_pObjectiveResource->GetNumPlayersInArea( iCP, iCappingTeam );
int requiredPlayers = g_pObjectiveResource->GetRequiredCappers( iCP, iCappingTeam );
if ( requiredPlayers > 1 )
{
numPlayers = MIN( numPlayers, requiredPlayers );
wchar_t wText[6];
_snwprintf( wText, sizeof(wText)/sizeof(wchar_t), L"%d/%d", numPlayers, requiredPlayers );
int wide, tall;
surface()->GetTextSize( m_hIconFont, wText, wide, tall );
int x = pospanel.x-(wide/2);
int y = pospanel.y;
// match the offset that MapOverview uses
y += GetPixelOffset( scale ) + 4;
// draw black shadow text
surface()->DrawSetTextColor( 0, 0, 0, 255 );
surface()->DrawSetTextPos( x+1, y );
surface()->DrawPrintText( wText, wcslen(wText) );
// draw name in color
surface()->DrawSetTextColor( g_PR->GetTeamColor( iCappingTeam ) );
surface()->DrawSetTextPos( x, y );
surface()->DrawPrintText( wText, wcslen(wText) );
}
}
}
// draw bombs underneath if necessary
if ( iBombsRequired > 0 )
{
int iBombsRemaining = g_pObjectiveResource->GetBombsRemaining( iCP );
bool bBombPlanted = g_pObjectiveResource->IsBombSetAtPoint( iCP );
// draw bomb state underneath
float flBombIconScale = scale * 0.5;
switch( iBombsRequired )
{
case 1:
{
Vector bombPos = pos;
bombPos.y -= scale * 1.5;
switch( iBombsRemaining )
{
case 0:
DrawQuad( bombPos, flBombIconScale, angle, m_pExplodedIcon->textureId, 255 );
break;
case 1:
if ( bBombPlanted )
{
// draw the background behind 1
int alpha = (float)( abs( sin(2*gpGlobals->curtime) ) * 205.0 + 50.0 );
DrawQuad( bombPos, flBombIconScale*2, angle, m_pC4PlantedBG->textureId, alpha );
}
DrawQuad( bombPos, flBombIconScale, angle, m_pC4Icon->textureId, 255 );
break;
}
}
break;
case 2:
{
Vector bombPos1, bombPos2;
bombPos1 = bombPos2 = pos;
bombPos1.y = bombPos2.y = pos.y - scale * 1.5;
bombPos1.x = pos.x - scale * 0.5;
bombPos2.x = pos.x + scale * 0.5;
switch( iBombsRemaining )
{
case 0:
DrawQuad( bombPos1, flBombIconScale, angle, m_pExplodedIcon->textureId, 255 );
DrawQuad( bombPos2, flBombIconScale, angle, m_pExplodedIcon->textureId, 255 );
break;
case 1:
if ( bBombPlanted )
{
// draw the background behind 1
int alpha = (float)( abs( sin(2*gpGlobals->curtime) ) * 205.0 + 50.0 );
DrawQuad( bombPos1, flBombIconScale*2, angle, m_pC4PlantedBG->textureId, alpha );
}
DrawQuad( bombPos1, flBombIconScale, angle, m_pC4Icon->textureId, 255 );
DrawQuad( bombPos2, flBombIconScale, angle, m_pExplodedIcon->textureId, 255 );
break;
case 2:
if ( bBombPlanted )
{
// draw the background behind 2
int alpha = (float)( abs( sin(2*gpGlobals->curtime) ) * 205.0 + 50.0 );
DrawQuad( bombPos2, flBombIconScale*2, angle, m_pC4PlantedBG->textureId, alpha );
}
DrawQuad( bombPos1, flBombIconScale, angle, m_pC4Icon->textureId, 255 );
DrawQuad( bombPos2, flBombIconScale, angle, m_pC4Icon->textureId, 255 );
break;
}
}
break;
}
// draw shield over top
if ( g_pObjectiveResource->IsBombBeingDefused( iCP ) )
{
DrawQuad( pos, scale * 0.75, angle, m_pIconDefended->textureId, 255 );
}
}
return true;
}
void CDODMapOverview::DrawBombTimerSwipeIcon( Vector pos, int scale, int textureID, float flPercentRemaining )
{
const float flCompleteCircle = ( 2.0f * M_PI );
const float fl90degrees = flCompleteCircle * 0.25f;
const float fl45degrees = fl90degrees * 0.5f;
float flEndAngle = flCompleteCircle * flPercentRemaining; // clockwise
typedef struct
{
Vector2D vecTrailing;
Vector2D vecLeading;
} icon_quadrant_t;
/*
Quadrants are numbered 0 - 7 counter-clockwise
_________________
| 0 | 7 |
| | |
| 1 | 6 |
-----------------
| 2 | 5 |
| | |
| 3 | 4 |
-----------------
*/
// Encode the leading and trailing edge of each quadrant
// in the range 0.0 -> 1.0
icon_quadrant_t quadrants[8];
quadrants[0].vecTrailing.Init( 0.5, 0.0 );
quadrants[0].vecLeading.Init( 0.0, 0.0 );
quadrants[1].vecTrailing.Init( 0.0, 0.0 );
quadrants[1].vecLeading.Init( 0.0, 0.5 );
quadrants[2].vecTrailing.Init( 0.0, 0.5 );
quadrants[2].vecLeading.Init( 0.0, 1.0 );
quadrants[3].vecTrailing.Init( 0.0, 1.0 );
quadrants[3].vecLeading.Init( 0.5, 1.0 );
quadrants[4].vecTrailing.Init( 0.5, 1.0 );
quadrants[4].vecLeading.Init( 1.0, 1.0 );
quadrants[5].vecTrailing.Init( 1.0, 1.0 );
quadrants[5].vecLeading.Init( 1.0, 0.5 );
quadrants[6].vecTrailing.Init( 1.0, 0.5 );
quadrants[6].vecLeading.Init( 1.0, 0.0 );
quadrants[7].vecTrailing.Init( 1.0, 0.0 );
quadrants[7].vecLeading.Init( 0.5, 0.0 );
surface()->DrawSetColor( 255, 255, 255, 255 );
surface()->DrawSetTexture( textureID );
Vector2D uvMid( 0.5, 0.5 );
Vector2D newPos( pos.x - scale, pos.y + scale );
int j;
for ( j=0;j<=7;j++ )
{
float flMinAngle = j * fl45degrees;
float flAngle = clamp( flEndAngle - flMinAngle, 0, fl45degrees );
if ( flAngle <= 0 )
{
// past our quadrant, draw nothing
continue;
}
else
{
// draw our segment
vgui::Vertex_t vert[3];
// vert 0 is mid ( 0.5, 0.5 )
Vector2D pos0 = WorldToMap( pos );
vert[0].Init( MapToPanel( pos0 ), uvMid );
int xdir = 0, ydir = 0;
switch( j )
{
case 0:
case 7:
//right
xdir = 1;
ydir = 0;
break;
case 1:
case 2:
//up
xdir = 0;
ydir = -1;
break;
case 3:
case 4:
//left
xdir = -1;
ydir = 0;
break;
case 5:
case 6:
//down
xdir = 0;
ydir = 1;
break;
}
Vector vec1;
Vector2D uv1;
// vert 1 is the variable vert based on leading edge
vec1.x = newPos.x + quadrants[j].vecTrailing.x * scale*2 - xdir * tan(flAngle) * scale;
vec1.y = newPos.y - quadrants[j].vecTrailing.y * scale*2 + ydir * tan(flAngle) * scale;
uv1.x = quadrants[j].vecTrailing.x - xdir * abs( quadrants[j].vecLeading.x - quadrants[j].vecTrailing.x ) * tan(flAngle);
uv1.y = quadrants[j].vecTrailing.y - ydir * abs( quadrants[j].vecLeading.y - quadrants[j].vecTrailing.y ) * tan(flAngle);
Vector2D pos1 = WorldToMap( vec1 );
vert[1].Init( MapToPanel( pos1 ), uv1 );
// vert 2 is our trailing edge
Vector vec2;
vec2.x = newPos.x + quadrants[j].vecTrailing.x * scale*2;
vec2.y = newPos.y - quadrants[j].vecTrailing.y * scale*2;
Vector2D pos2 = WorldToMap( vec2 );
vert[2].Init( MapToPanel( pos2 ), quadrants[j].vecTrailing );
surface()->DrawTexturedPolygon( 3, vert );
}
}
}
void CDODMapOverview::DrawHorizontalSwipe( Vector pos, int scale, int textureID, float flCapPercentage, bool bSwipeLeft )
{
float flIconSize = scale * 2;
float width = ( flIconSize * flCapPercentage );
float uv1 = 0.0f;
float uv2 = 1.0f;
Vector2D uv11( uv1, uv2 );
Vector2D uv21( flCapPercentage, uv2 );
Vector2D uv22( flCapPercentage, uv1 );
Vector2D uv12( uv1, uv1 );
// reversing the direction of the swipe effect
if ( bSwipeLeft )
{
uv11.x = uv2 - flCapPercentage;
uv21.x = uv2;
uv22.x = uv2;
uv12.x = uv2 - flCapPercentage;
}
float flXPos = pos.x - scale;
float flYPos = pos.y - scale;
Vector upperLeft( flXPos, flYPos, 0 );
Vector upperRight( flXPos + width, flYPos, 0 );
Vector lowerRight( flXPos + width, flYPos + flIconSize, 0 );
Vector lowerLeft ( flXPos, flYPos + flIconSize, 0 );
/// reversing the direction of the swipe effect
if ( bSwipeLeft )
{
upperLeft.x = flXPos + flIconSize - width;
upperRight.x = flXPos + flIconSize;
lowerRight.x = flXPos + flIconSize;
lowerLeft.x = flXPos + flIconSize - width;
}
vgui::Vertex_t vert[4];
Vector2D pos0 = WorldToMap( upperLeft );
vert[0].Init( MapToPanel( pos0 ), uv11 );
Vector2D pos3 = WorldToMap( lowerLeft );
vert[1].Init( MapToPanel( pos3 ), uv12 );
Vector2D pos2 = WorldToMap( lowerRight );
vert[2].Init( MapToPanel( pos2 ), uv22 );
Vector2D pos1 = WorldToMap( upperRight );
vert[3].Init( MapToPanel( pos1 ), uv21 );
surface()->DrawSetColor( 255, 255, 255, 255 );
surface()->DrawSetTexture( textureID );
surface()->DrawTexturedPolygon( 4, vert );
}
bool CDODMapOverview::IsVisible( void )
{
if ( IsTakingAFreezecamScreenshot() )
return false;
return BaseClass::IsVisible();
}
|