-
Notifications
You must be signed in to change notification settings - Fork 721
/
Copy pathweapon_csbase.cpp
3916 lines (3176 loc) · 116 KB
/
weapon_csbase.cpp
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 � 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose: Laser Rifle & Shield combo
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "in_buttons.h"
#include "takedamageinfo.h"
#include "weapon_csbase.h"
#include "ammodef.h"
#include "cs_gamerules.h"
#include "basegrenade_shared.h"
#include "weapon_basecsgrenade.h"
#include "platforminputdevice.h"
#include "inputsystem/iinputsystem.h"
// CS-PRO TEST CHANGE: instant movement inaccuracy, curve exponent x^0.25
#define MOVEMENT_ACCURACY_DECAYED 0
#define MOVEMENT_WALK_CURVE01_EXPONENT 0.85
#define MOVEMENT_CURVE01_EXPONENT 0.25
#define SILENCER_VISIBLE 0
#define SILENCER_HIDDEN 1
#ifdef SIXENSE
#include "sixense\in_sixense.h"
#include "view.h"
#endif
#if defined( CLIENT_DLL )
#include "vgui/ISurface.h"
#include "vgui_controls/Controls.h"
#include "c_cs_player.h"
#include "predicted_viewmodel.h"
#include "hud_crosshair.h"
#include "c_te_effect_dispatch.h"
#include "c_te_legacytempents.h"
#include "cs_hud_weaponselection.h"
#include "prediction.h"
#include "materialsystem/icompositetexturegenerator.h"
#include "materialsystem/icustommaterialmanager.h"
#include "cs_custom_material_swap.h"
#include "cs_custom_weapon_visualsdata_processor.h"
//#include "glow_outline_effect.h"
#include "HUD/sfhudreticle.h"
extern IVModelInfoClient* modelinfo;
extern ConVar spec_show_xray;
#else
#include "cs_player.h"
#include "te_effect_dispatch.h"
#include "keyvalues.h"
#include "cs_ammodef.h"
#include "cvisibilitymonitor.h"
extern IVModelInfo* modelinfo;
#endif
// NOTE: This has to be the last file included!
#include "tier0/memdbgon.h"
#if defined( CSTRIKE15 )
extern ConVar crosshair;
extern WeaponRecoilData g_WeaponRecoilData;
#endif
extern ConVar cl_righthand;
extern ConVar mp_weapons_allow_map_placed;
extern ConVar mp_weapons_glow_on_ground;
extern ConVar sv_jump_impulse;
ConVar weapon_land_dip_amt( "weapon_land_dip_amt", "20.0", FCVAR_DEVELOPMENTONLY | FCVAR_CHEAT | FCVAR_REPLICATED, "The amount the gun should dip when the player lands after a jump." );
ConVar weapon_recoil_decay1( "weapon_recoil_decay1_exp", "3.5", FCVAR_RELEASE | FCVAR_CHEAT | FCVAR_REPLICATED, "Decay factor exponent for weapon recoil" );
ConVar weapon_recoil_decay2_exp( "weapon_recoil_decay2_exp", "8", FCVAR_RELEASE | FCVAR_CHEAT | FCVAR_REPLICATED, "Decay factor exponent for weapon recoil" );
ConVar weapon_recoil_decay2_lin( "weapon_recoil_decay2_lin", "18", FCVAR_RELEASE | FCVAR_CHEAT | FCVAR_REPLICATED, "Decay factor (linear term) for weapon recoil" );
ConVar weapon_recoil_vel_decay( "weapon_recoil_vel_decay", "4.5", FCVAR_RELEASE | FCVAR_CHEAT | FCVAR_REPLICATED, "Decay factor for weapon recoil velocity" );
ConVar weapon_recoil_decay_coefficient( "weapon_recoil_decay_coefficient", "2.0", FCVAR_RELEASE | FCVAR_CHEAT | FCVAR_REPLICATED, "" );
ConVar weapon_accuracy_nospread( "weapon_accuracy_nospread", "0", FCVAR_RELEASE | FCVAR_CHEAT | FCVAR_REPLICATED, "Disable weapon inaccuracy spread" );
ConVar weapon_recoil_cooldown( "weapon_recoil_cooldown", "0.55", FCVAR_RELEASE | FCVAR_CHEAT | FCVAR_REPLICATED, "DEPRECATED. Recoil now decays using weapon_recoil_decay_coefficient");
ConVar weapon_recoil_scale( "weapon_recoil_scale", "2.0", FCVAR_RELEASE | FCVAR_CHEAT | FCVAR_REPLICATED, "Overall scale factor for recoil. Used to reduce recoil on specific platforms");
ConVar weapon_recoil_scale_motion_controller( "weapon_recoil_scale_motion_controller", "1.0", FCVAR_RELEASE | FCVAR_CHEAT |FCVAR_REPLICATED, "Overall scale factor for recoil. Used to reduce recoil. Only for motion controllers");
ConVar weapon_air_spread_scale( "weapon_air_spread_scale", "1.0", FCVAR_RELEASE | FCVAR_CHEAT | FCVAR_REPLICATED, "Scale factor for jumping inaccuracy, set to 0 to make jumping accuracy equal to standing", true, 0.0f, false, 1.0f );
ConVar weapon_legacy_recoiltable( "weapon_legacy_recoiltable", "0", FCVAR_REPLICATED | FCVAR_DEVELOPMENTONLY );
ConVar weapon_reticle_knife_show( "weapon_reticle_knife_show", "0", FCVAR_RELEASE | FCVAR_REPLICATED, "When enabled will show knife reticle on clients. Used for game modes requiring target id display when holding a knife." );
ConVar weapon_auto_cleanup_time( "weapon_auto_cleanup_time", "0", FCVAR_RELEASE, "If set to non-zero, weapons will delete themselves after the specified time (in seconds) if no players are near." );
ConVar weapon_max_before_cleanup( "weapon_max_before_cleanup", "0", FCVAR_RELEASE, "If set to non-zero, will remove the oldest dropped weapon to maintain the specified number of dropped weapons in the world." );
#if defined( CLIENT_DLL )
ConVar cl_weapon_debug_print_accuracy("cl_weapon_debug_print_accuracy", "0", FCVAR_RELEASE | FCVAR_CHEAT );
ConVar cl_weapon_debug_show_accuracy("cl_weapon_debug_show_accuracy", "0", FCVAR_RELEASE | FCVAR_CHEAT, "Draws a circle representing the effective range with every shot." );
ConVar cl_weapon_debug_show_accuracy_duration( "cl_weapon_debug_show_accuracy_duration", "10", FCVAR_RELEASE | FCVAR_CHEAT );
#endif
#define MP_WEAPON_ACCURACY_SEPARATE_WALK_FUNCTION true
/*
// TODO[pmf] make these work with recoil tables
ConVar weapon_recoil_seed( "weapon_recoil_seed", "0", FCVAR_DEVELOPMENTONLY | FCVAR_CHEAT | FCVAR_REPLICATED );
#if defined( GAME_DLL )
CON_COMMAND_F( weapon_recoil_reseed, "Randomly generate a new recoil seed for the current weapon", FCVAR_DEVELOPMENTONLY )
{
int iNewSeed = RandomInt(0, 0xFFFF);
weapon_recoil_seed.SetValue(iNewSeed);
Msg("Recoil seed set to %i\n", iNewSeed);
}
#endif
*/
void TE_DynamicLight( IRecipientFilter& filter, float delay,
const Vector* org, int r, int g, int b, int exponent, float radius, float time, float decay, int nLightIndex = LIGHT_INDEX_TE_DYNAMIC );
// ----------------------------------------------------------------------------- //
// Global functions.
// ----------------------------------------------------------------------------- //
struct WeaponAliasTranslationInfoStruct
{
char* alias;
char* translatedAlias;
};
static const WeaponAliasTranslationInfoStruct s_WeaponAliasTranslationInfo[] =
{
{ "cv47", "ak47" },
{ "defender", "galil" },
{ "krieg552", "sg552" },
{ "magnum", "awp" },
{ "d3au1", "g3sg1" },
{ "clarion", "famas" },
{ "bullpup", "aug" },
{ "krieg550", "sg550" },
{ "9x19mm", "glock" },
{ "km45", "usp" },
{ "228compact", "p228" },
{ "nighthawk", "deagle" },
{ "elites", "elite" },
{ "fn57", "fiveseven" },
{ "12gauge", "m3" },
{ "autoshotgun", "xm1014" },
{ "mp", "tmp" },
{ "smg", "mp5navy" },
{ "mp5", "mp5navy" },
{ "c90", "p90" },
{ "vest", "kevlar" },
{ "vesthelm", "assaultsuit" },
{ "nvgs", "nightvision" },
{ "", "" } // this needs to be last
};
struct WeaponAliasInfo
{
CSWeaponID id;
const char* alias;
};
bool IsAmmoType( int iAmmoType, const char *pAmmoName )
{
return GetAmmoDef()->Index( pAmmoName ) == iAmmoType;
}
//--------------------------------------------------------------------------------------------------------
//
// Given an alias, return the translated alias.
//
const char * GetTranslatedWeaponAlias( const char *szAlias )
{
for ( int i = 0; i < ARRAYSIZE( s_WeaponAliasTranslationInfo ); ++i )
{
if ( Q_stricmp( s_WeaponAliasTranslationInfo[i].alias, szAlias ) == 0 )
{
return s_WeaponAliasTranslationInfo[i].translatedAlias;
}
}
return szAlias;
}
//--------------------------------------------------------------------------------------------------------
//
// Given a translated alias, return the alias.
//
const char * GetWeaponAliasFromTranslated( const char *translatedAlias )
{
int i = 0;
const WeaponAliasTranslationInfoStruct *info = &( s_WeaponAliasTranslationInfo[i] );
while ( info->alias[0] != 0 )
{
if ( Q_stricmp( translatedAlias, info->translatedAlias ) == 0 )
{
return info->alias;
}
info = &( s_WeaponAliasTranslationInfo[++i] );
}
return translatedAlias;
}
//--------------------------------------------------------------------------------------------------------
//
// Return true if given weapon ID is a primary weapon
//
bool IsPrimaryWeapon( CSWeaponID id )
{
const CCSWeaponInfo* pWeaponInfo = GetWeaponInfo( id );
if ( pWeaponInfo )
{
return pWeaponInfo->iSlot == WEAPON_SLOT_RIFLE;
}
return false;
}
//--------------------------------------------------------------------------------------------------------
//
// Return true if given weapon ID is a secondary weapon
//
bool IsSecondaryWeapon( CSWeaponID id )
{
const CCSWeaponInfo* pWeaponInfo = GetWeaponInfo( id );
if ( pWeaponInfo )
return pWeaponInfo->iSlot == WEAPON_SLOT_PISTOL;
return false;
}
//--------------------------------------------------------------------------------------------------------
//
// Return true if given weapon ID is a grenade weapon
//
bool IsGrenadeWeapon( CSWeaponID id )
{
const CCSWeaponInfo* pWeaponInfo = GetWeaponInfo( id );
if ( pWeaponInfo )
{
return pWeaponInfo->iSlot == WEAPON_SLOT_GRENADES;
}
return false;
}
//--------------------------------------------------------------------------------------------------------
//
// Return true if given weapon ID is armor
//
bool IsArmor( CSWeaponID id )
{
return id == ITEM_ASSAULTSUIT || id == ITEM_KEVLAR;
}
#ifdef CLIENT_DLL
int GetShellForAmmoType( const char *ammoname )
{
if ( !Q_strcmp( BULLET_PLAYER_762MM, ammoname ) )
return CS_SHELL_762NATO;
if ( !Q_strcmp( BULLET_PLAYER_556MM, ammoname ) )
return CS_SHELL_556;
if ( !Q_strcmp( BULLET_PLAYER_338MAG, ammoname ) )
return CS_SHELL_338MAG;
if ( !Q_strcmp( BULLET_PLAYER_BUCKSHOT, ammoname ) )
return CS_SHELL_12GAUGE;
if ( !Q_strcmp( BULLET_PLAYER_57MM, ammoname ) )
return CS_SHELL_57;
// default 9 mm
return CS_SHELL_9MM;
}
#endif
// ----------------------------------------------------------------------------- //
// CWeaponCSBase tables.
// ----------------------------------------------------------------------------- //
IMPLEMENT_NETWORKCLASS_ALIASED( WeaponCSBase, DT_WeaponCSBase )
BEGIN_NETWORK_TABLE( CWeaponCSBase, DT_WeaponCSBase )
#if !defined( CLIENT_DLL )
SendPropInt( SENDINFO( m_weaponMode ), 1, SPROP_UNSIGNED ),
SendPropFloat( SENDINFO( m_fAccuracyPenalty ), 0, SPROP_CHANGES_OFTEN ),
SendPropFloat( SENDINFO( m_fLastShotTime ) ),
//SendPropInt( SENDINFO( m_iRecoilIndex ) ), //DEPRECATED
SendPropFloat( SENDINFO( m_flRecoilIndex ) ),
// world weapon models have no aminations
SendPropExclude( "DT_AnimTimeMustBeFirst", "m_flAnimTime" ),
SendPropExclude( "DT_BaseAnimating", "m_nSequence" ),
SendPropEHandle( SENDINFO( m_hPrevOwner ) ),
SendPropBool( SENDINFO( m_bBurstMode ) ),
SendPropTime( SENDINFO( m_flPostponeFireReadyTime ) ),
SendPropBool( SENDINFO( m_bReloadVisuallyComplete ) ),
// SendPropExclude( "DT_LocalActiveWeaponData", "m_flTimeWeaponIdle" ),
SendPropBool( SENDINFO( m_bSilencerOn ) ),
SendPropTime( SENDINFO( m_flDoneSwitchingSilencer ) ),
SendPropInt( SENDINFO( m_iOriginalTeamNumber ) ),
#if defined( WEAPON_FIRE_BULLETS_ACCURACY_FISHTAIL_FEATURE )
SendPropFloat( SENDINFO( m_fAccuracyFishtail ) ),
#endif
#ifdef IRONSIGHT
SendPropInt( SENDINFO( m_iIronSightMode ), 2, SPROP_UNSIGNED ),
#endif //IRONSIGHT
#else
RecvPropInt( RECVINFO( m_weaponMode ) ),
RecvPropFloat( RECVINFO( m_fAccuracyPenalty ) ),
RecvPropFloat( RECVINFO( m_fLastShotTime ) ),
RecvPropInt( RECVINFO( m_iRecoilIndex ) ), // DEPRECATED. Kept for old demo compatibility.
RecvPropFloat( RECVINFO( m_flRecoilIndex ) ),
RecvPropEHandle( RECVINFO( m_hPrevOwner ) ),
RecvPropBool( RECVINFO( m_bBurstMode ) ),
RecvPropTime( RECVINFO( m_flPostponeFireReadyTime ) ),
RecvPropBool( RECVINFO( m_bReloadVisuallyComplete ) ),
RecvPropBool( RECVINFO( m_bSilencerOn ) ),
RecvPropTime( RECVINFO( m_flDoneSwitchingSilencer ) ),
RecvPropInt( RECVINFO( m_iOriginalTeamNumber ) ),
#if defined( WEAPON_FIRE_BULLETS_ACCURACY_FISHTAIL_FEATURE )
RecvPropFloat( RECVINFO( m_fAccuracyFishtail ) ),
#endif
#ifdef IRONSIGHT
RecvPropInt( RECVINFO( m_iIronSightMode ) ),
#endif //IRONSIGHT
#endif
END_NETWORK_TABLE()
#if defined( CLIENT_DLL )
BEGIN_PREDICTION_DATA( CWeaponCSBase )
DEFINE_PRED_FIELD( m_flTimeWeaponIdle, FIELD_FLOAT, FTYPEDESC_OVERRIDE | FTYPEDESC_NOERRORCHECK ),
DEFINE_PRED_FIELD( m_flNextPrimaryAttack, FIELD_FLOAT, FTYPEDESC_OVERRIDE | FTYPEDESC_NOERRORCHECK ),
DEFINE_PRED_FIELD( m_flNextSecondaryAttack, FIELD_FLOAT, FTYPEDESC_OVERRIDE | FTYPEDESC_NOERRORCHECK ),
DEFINE_PRED_FIELD( m_weaponMode, FIELD_INTEGER, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD_TOL( m_fAccuracyPenalty, FIELD_FLOAT, FTYPEDESC_INSENDTABLE, TD_MSECTOLERANCE ),
#if defined( WEAPON_FIRE_BULLETS_ACCURACY_FISHTAIL_FEATURE )
DEFINE_PRED_FIELD_TOL( m_fAccuracyFishtail, FIELD_FLOAT, FTYPEDESC_INSENDTABLE, TD_MSECTOLERANCE ),
#endif
DEFINE_PRED_FIELD( m_fLastShotTime, FIELD_FLOAT, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD( m_iRecoilIndex, FIELD_INTEGER, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD( m_flRecoilIndex, FIELD_FLOAT, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD( m_bReloadVisuallyComplete, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE ),
#ifdef IRONSIGHT
DEFINE_PRED_FIELD( m_iIronSightMode, FIELD_INTEGER, FTYPEDESC_INSENDTABLE ),
#endif
DEFINE_PRED_FIELD( m_flPostponeFireReadyTime, FIELD_FLOAT, FTYPEDESC_OVERRIDE | FTYPEDESC_NOERRORCHECK ),
END_PREDICTION_DATA()
#endif
LINK_ENTITY_TO_CLASS_ALIASED( weapon_cs_base, WeaponCSBase );
#ifdef GAME_DLL
#define REMOVEUNOWNEDWEAPON_THINK_CONTEXT "WeaponCSBase_RemoveUnownedWeaponThink"
#define REMOVEUNOWNEDWEAPON_THINK_INTERVAL 0.2
#define REMOVEUNOWNEDWEAPON_THINK_REMOVE 3
BEGIN_DATADESC( CWeaponCSBase )
//DEFINE_FUNCTION( DefaultTouch ),
DEFINE_THINKFUNC( FallThink ),
DEFINE_THINKFUNC( RemoveUnownedWeaponThink ),
DEFINE_KEYFIELD( m_bCanBePickedUp, FIELD_BOOLEAN, "CanBePickedUp" )
END_DATADESC()
#endif
#if defined( CLIENT_DLL )
ConVar cl_crosshairstyle( "cl_crosshairstyle", "2", FCVAR_CLIENTDLL | FCVAR_ARCHIVE | FCVAR_SS, "0 = DEFAULT, 1 = DEFAULT STATIC, 2 = ACCURATE SPLIT (accurate recoil/spread feedback with a fixed inner part), 3 = ACCURATE DYNAMIC (accurate recoil/spread feedback), 4 = CLASSIC STATIC, 5 = OLD CS STYLE (fake recoil - inaccurate feedback)" );
ConVar cl_crosshaircolor( "cl_crosshaircolor", "1", FCVAR_CLIENTDLL | FCVAR_ARCHIVE | FCVAR_ARCHIVE_GAMECONSOLE | FCVAR_SS, "Set crosshair color as defined in game_options.consoles.txt" );
//ConVar cl_dynamiccrosshair( "cl_dynamiccrosshair", "1", FCVAR_CLIENTDLL | FCVAR_ARCHIVE | FCVAR_SS );
ConVar cl_scalecrosshair( "cl_scalecrosshair", "1", FCVAR_CLIENTDLL | FCVAR_ARCHIVE | FCVAR_SS, "Enable crosshair scaling (deprecated)" );
ConVar cl_crosshairscale( "cl_crosshairscale", "0", FCVAR_CLIENTDLL | FCVAR_ARCHIVE | FCVAR_SS, "Crosshair scaling factor (deprecated)" );
ConVar cl_crosshairalpha( "cl_crosshairalpha", "200", FCVAR_CLIENTDLL | FCVAR_ARCHIVE | FCVAR_SS );
ConVar cl_crosshairusealpha( "cl_crosshairusealpha", "1", FCVAR_CLIENTDLL | FCVAR_ARCHIVE | FCVAR_SS );
ConVar cl_crosshairgap( "cl_crosshairgap", "1", FCVAR_CLIENTDLL | FCVAR_ARCHIVE | FCVAR_SS );
ConVar cl_crosshairgap_useweaponvalue( "cl_crosshairgap_useweaponvalue", "0", FCVAR_CLIENTDLL | FCVAR_ARCHIVE | FCVAR_SS, "If set to 1, the gap will update dynamically based on which weapon is currently equipped" );
ConVar cl_crosshairsize( "cl_crosshairsize", "5", FCVAR_CLIENTDLL | FCVAR_ARCHIVE | FCVAR_SS );
ConVar cl_crosshairthickness( "cl_crosshairthickness", "0.5", FCVAR_CLIENTDLL | FCVAR_ARCHIVE | FCVAR_SS );
ConVar cl_crosshairdot( "cl_crosshairdot", "1", FCVAR_CLIENTDLL | FCVAR_ARCHIVE | FCVAR_SS );
ConVar cl_crosshaircolor_r( "cl_crosshaircolor_r", "50", FCVAR_CLIENTDLL | FCVAR_ARCHIVE | FCVAR_SS );
ConVar cl_crosshaircolor_g( "cl_crosshaircolor_g", "250", FCVAR_CLIENTDLL | FCVAR_ARCHIVE | FCVAR_SS );
ConVar cl_crosshaircolor_b( "cl_crosshaircolor_b", "50", FCVAR_CLIENTDLL | FCVAR_ARCHIVE | FCVAR_SS );
ConVar weapon_debug_spread_show( "weapon_debug_spread_show", "0", FCVAR_CLIENTDLL | FCVAR_SS | FCVAR_CHEAT, "Enables display of weapon accuracy; 1: show accuracy box, 3: show accuracy with dynamic crosshair" );
ConVar weapon_debug_spread_gap( "weapon_debug_spread_gap", "0.67", FCVAR_CLIENTDLL | FCVAR_SS | FCVAR_CHEAT );
ConVar cl_crosshair_drawoutline( "cl_crosshair_drawoutline", "1", FCVAR_CLIENTDLL | FCVAR_ARCHIVE | FCVAR_SS, "Draws a black outline around the crosshair for better visibility" );
ConVar cl_crosshair_outlinethickness( "cl_crosshair_outlinethickness", "1", FCVAR_CLIENTDLL | FCVAR_ARCHIVE | FCVAR_SS, "Set how thick you want your crosshair outline to draw (0.1-3)", true, 0.1, true, 3 );
ConVar cl_crosshair_dynamic_splitdist("cl_crosshair_dynamic_splitdist", "7", FCVAR_CLIENTDLL | FCVAR_ARCHIVE | FCVAR_SS, "If using cl_crosshairstyle 2, this is the distance that the crosshair pips will split into 2. (default is 7)"/*, true, 10, true, 3*/);
ConVar cl_crosshair_dynamic_splitalpha_innermod("cl_crosshair_dynamic_splitalpha_innermod", "1", FCVAR_CLIENTDLL | FCVAR_ARCHIVE | FCVAR_SS, "If using cl_crosshairstyle 2, this is the alpha modification that will be used for the INNER crosshair pips once they've split. [0 - 1]", true, 0, true, 1);
ConVar cl_crosshair_dynamic_splitalpha_outermod("cl_crosshair_dynamic_splitalpha_outermod", "0.5", FCVAR_CLIENTDLL | FCVAR_ARCHIVE | FCVAR_SS, "If using cl_crosshairstyle 2, this is the alpha modification that will be used for the OUTER crosshair pips once they've split. [0.3 - 1]", true, 0.3, true, 1);
ConVar cl_crosshair_dynamic_maxdist_splitratio("cl_crosshair_dynamic_maxdist_splitratio", "0.35", FCVAR_CLIENTDLL | FCVAR_ARCHIVE | FCVAR_SS, "If using cl_crosshairstyle 2, this is the ratio used to determine how long the inner and outer xhair pips will be. [inner = cl_crosshairsize*(1-cl_crosshair_dynamic_maxdist_splitratio), outer = cl_crosshairsize*cl_crosshair_dynamic_maxdist_splitratio] [0 - 1]", true, 0, true, 1);
void DrawCrosshairRect( int r, int g, int b, int a, int x0, int y0, int x1, int y1, bool bAdditive )
{
if ( cl_crosshair_drawoutline.GetBool() )
{
float flThick = cl_crosshair_outlinethickness.GetFloat();
vgui::surface()->DrawSetColor( 0, 0, 0, a );
vgui::surface()->DrawFilledRect( x0-flThick, y0-flThick, x1+flThick, y1+flThick );
}
vgui::surface()->DrawSetColor( r, g, b, a );
if ( bAdditive )
{
vgui::surface()->DrawTexturedRect( x0, y0, x1, y1 );
}
else
{
// Alpha-blended crosshair
vgui::surface()->DrawFilledRect( x0, y0, x1, y1 );
}
}
#endif
// must be included after the above macros
#ifndef CLIENT_DLL
#include "cs_bot.h"
#endif
// ----------------------------------------------------------------------------- //
// CWeaponCSBase implementation.
// ----------------------------------------------------------------------------- //
CWeaponCSBase::CWeaponCSBase()
#ifdef CLIENT_DLL
: m_GlowObject( this, Vector( 1.0f, 1.0f, 1.0f ), 0.0f, false, false )
#endif
{
m_nWeaponID = WEAPON_NONE;
SetPredictionEligible( true );
m_nextOwnerTouchTime = 0.0f;
m_nextPrevOwnerTouchTime = 0.0f;
m_hPrevOwner = NULL;
AddSolidFlags( FSOLID_TRIGGER ); // Nothing collides with these but it gets touches.
m_bCanBePickedUp = true;
m_fAccuracyPenalty = 0.0f;
#if defined( WEAPON_FIRE_BULLETS_ACCURACY_FISHTAIL_FEATURE )
m_fAccuracyFishtail = 0.0f;
#endif
m_fLastShotTime = 0.0f;
m_weaponMode = Primary_Mode;
m_fAccuracySmoothedForZoom = 0.0f;
m_fScopeZoomEndTime = 0.0f;
m_bBurstMode = false;
ResetPostponeFireReadyTime();
m_bWasOwnedByCT = false;
m_bWasOwnedByTerrorist = false;
#ifdef CLIENT_DLL
m_bOldFirstPersonSpectatedState = false;
// This will make it so the weapons get lit with the same ambient cube that the player gets lit with.
SetUseParentLightingOrigin( true );
m_iCrosshairTextureID = 0;
m_flGunAccuracyPosition = 0;
m_bVisualsDataSet = false;
m_flLastClientFireBulletTime = 0;
#else
m_iDefaultExtraAmmo = 0;
m_bFiredOutOfAmmoEvent = false;
m_numRemoveUnownedWeaponThink = 0;
#endif
m_bReloadVisuallyComplete = false;
m_bSilencerOn = false;
m_flDoneSwitchingSilencer = 0.0f;
m_iOriginalTeamNumber = 0;
ResetGunHeat();
#ifdef IRONSIGHT
m_iIronSightMode = IronSight_should_approach_unsighted;
m_IronSightController = NULL;
UpdateIronSightController();
#endif //IRONSIGHT
}
CWeaponCSBase::~CWeaponCSBase()
{
#ifdef IRONSIGHT
delete m_IronSightController;
m_IronSightController = NULL;
#endif //IRONSIGHT
#ifndef CLIENT_DLL
if ( CSGameRules() )
CSGameRules()->RemoveDroppedWeaponFromList( this );
#endif
}
void CWeaponCSBase::ResetGunHeat()
{
#ifdef CLIENT_DLL
m_gunHeat = 0.0f;
m_smokeAttachments = 0x0;
m_lastSmokeTime = 0.0f;
#endif
}
#ifndef CLIENT_DLL
bool CWeaponCSBase::KeyValue( const char *szKeyName, const char *szValue )
{
if ( !BaseClass::KeyValue( szKeyName, szValue ) )
{
if ( FStrEq( szKeyName, "ammo" ) )
{
int bullets = atoi( szValue );
if ( bullets < 0 )
return false;
m_iDefaultExtraAmmo = bullets;
return true;
}
}
return false;
}
#endif
bool CWeaponCSBase::IsPredicted() const
{
return true;
}
bool CWeaponCSBase::IsPistol() const
{
return GetWeaponType() == WEAPONTYPE_PISTOL;
}
bool CWeaponCSBase::PlayEmptySound()
{
//MIKETODO: certain weapons should override this to make it empty:
// C4
// Flashbang
// HE Grenade
// Smoke grenade
CPASAttenuationFilter filter( this );
filter.UsePredictionRules();
if ( IsPistol() )
{
EmitSound( filter, entindex(), "Default.ClipEmpty_Pistol" );
}
else
{
EmitSound( filter, entindex(), "Default.ClipEmpty_Rifle" );
}
return 0;
}
const char *CWeaponCSBase::GetShootSound( int iIndex ) const
{
CEconItemView *pItem = ( (CWeaponCSBase *)this )->GetEconItemView();
if ( pItem && pItem->IsValid() )
{
const char *pszSound = pItem->GetStaticData()->GetWeaponReplacementSound( (WeaponSound_t)iIndex );
if ( pszSound )
{
return pszSound;
}
}
return BaseClass::GetShootSound(iIndex);
}
const char *CWeaponCSBase::GetPlayerAnimationExtension( void ) const
{
CEconItemView *pItem = ( (CWeaponCSBase *)this )->GetEconItemView();
if ( pItem && pItem->IsValid() )
{
return GetCSWpnData().GetPlayerAnimationExtension( pItem );
}
return GetCSWpnData().GetPlayerAnimationExtension();
}
const char *CWeaponCSBase::GetAddonModel( void ) const
{
CEconItemView *pItem = ( (CWeaponCSBase *)this )->GetEconItemView();
if ( pItem && pItem->IsValid() )
{
return GetCSWpnData().GetAddonModel( pItem );
}
return GetCSWpnData().GetAddonModel();
}
CCSPlayer* CWeaponCSBase::GetPlayerOwner() const
{
return dynamic_cast< CCSPlayer* >( GetOwner() );
}
#ifdef CLIENT_DLL
// -----------------------------------------------------------------------------
// Purpose:
// -----------------------------------------------------------------------------
C_BaseEntity *CWeaponCSBase::GetWeaponForEffect()
{
C_CSPlayer *pLocalPlayer = C_CSPlayer::GetLocalCSPlayer();
if ( !pLocalPlayer )
return NULL;
bool bThird = false;
FOR_EACH_VALID_SPLITSCREEN_PLAYER( nSlot )
{
if ( GetPlayerOwner()->GetPlayerRenderMode( nSlot ) == PLAYER_RENDER_THIRDPERSON )
{
bThird = true;
}
}
if ( pLocalPlayer == GetPlayerOwner() && !bThird )
return pLocalPlayer->GetViewModel();
return this;
}
void CWeaponCSBase::UpdateOutlineGlow( void )
{
Vector glowColor;
bool bRender = false;
if ( !GetPlayerOwner() )
{
bool bRenderForSpectator = CanSeeSpectatorOnlyTools() && spec_show_xray.GetInt();
if ( bRenderForSpectator && (GetWeaponType() == WEAPONTYPE_C4) )
{
glowColor.x = (240.0f/255.0f);
glowColor.y = (225.0f/255.0f);
glowColor.z = (90.0f/255.0f);
bRender = true;
}
else if ( (m_iClip1 > 0 || m_iClip2 > 0) && mp_weapons_glow_on_ground.GetBool() )
{
glowColor.x = (224.0f/255.0f);
glowColor.y = (224.0f/255.0f);
glowColor.z = (224.0f/255.0f);
bRender = true;
}
}
// Start glowing
m_GlowObject.SetRenderFlags( bRender, false );
m_GlowObject.SetColor( glowColor );
m_GlowObject.SetAlpha( bRender ? 0.8f : 0.0f );
}
#endif
void CWeaponCSBase::AddToPriorOwnerList( CCSPlayer* pPlayer )
{
if ( !IsAPriorOwner( pPlayer ) )
{
// Add player to prior owner list
m_PriorOwners.AddToTail( pPlayer );
}
}
void CWeaponCSBase::AddPriorOwner( CCSPlayer* pPlayer )
{
if ( pPlayer )
{
if ( !IsAPriorOwner( pPlayer ) )
AddToPriorOwnerList( pPlayer );
// Assign the team that once owned this weapon
if ( pPlayer->GetTeamNumber() == TEAM_CT )
{
m_bWasOwnedByCT = true;
}
else if ( pPlayer->GetTeamNumber() == TEAM_TERRORIST )
{
m_bWasOwnedByTerrorist = true;
}
}
}
bool CWeaponCSBase::WasOwnedByTeam( int teamNumber )
{
// Verify if the incoming team matches the team of a previous owner
switch ( teamNumber )
{
case TEAM_CT:
return m_bWasOwnedByCT;
case TEAM_TERRORIST:
return m_bWasOwnedByTerrorist;
}
return false;
}
bool CWeaponCSBase::IsAPriorOwner( CCSPlayer* pPlayer ) const
{
return ( m_PriorOwners.Find( pPlayer ) != -1 );
}
void CWeaponCSBase::SecondaryAttack( void )
{
#ifndef CLIENT_DLL
CCSPlayer *pPlayer = GetPlayerOwner();
if ( !pPlayer )
return;
if ( pPlayer->HasShield() == false )
BaseClass::SecondaryAttack();
else
{
pPlayer->SetShieldDrawnState( !pPlayer->IsShieldDrawn() );
if ( pPlayer->IsShieldDrawn() )
SendWeaponAnim( ACT_SHIELD_UP );
else
SendWeaponAnim( ACT_SHIELD_DOWN );
m_flNextSecondaryAttack = gpGlobals->curtime + 0.4;
m_flNextPrimaryAttack = gpGlobals->curtime + 0.4;
}
#endif
}
bool CWeaponCSBase::SendWeaponAnim( int iActivity )
{
#ifdef CS_SHIELD_ENABLED
CCSPlayer *pPlayer = GetPlayerOwner();
if ( pPlayer && pPlayer->HasShield() )
{
CBaseViewModel *vm = pPlayer->GetViewModel( 1 );
if ( vm == NULL )
return false;
vm->SetWeaponModel( SHIELD_VIEW_MODEL, this );
int idealSequence = vm->SelectWeightedSequence( ( Activity )iActivity );
if ( idealSequence >= 0 )
{
vm->SendViewModelMatchingSequence( idealSequence );
}
}
#endif
return BaseClass::SendWeaponAnim( iActivity );
}
void CWeaponCSBase::SendViewModelAnim( int nSequence )
{
CCSPlayer *pPlayer = GetPlayerOwner();
if ( !pPlayer || pPlayer->IsTaunting() || pPlayer->IsLookingAtWeapon() )
return;
CBaseViewModel *vm = pPlayer->GetViewModel( m_nViewModelIndex );
if (vm)
{
bool bIsLookingAt = ( vm->GetSequence() != ACT_INVALID && V_stristr( vm->GetSequenceName(vm->GetSequence()), "lookat" ) );
if ( vm->GetCycle() < 0.98f && bIsLookingAt && V_stristr( vm->GetSequenceName( nSequence ), "idle" ) )
{
// Don't switch from taunt to idle
return;
}
#ifdef CLIENT_DLL
if ( !bIsLookingAt )
{
//Fade down stat trak glow if we're doing anything other than inspecting
vm->SetStatTrakGlowMultiplier( 0.0f );
}
#endif
}
BaseClass::SendViewModelAnim( nSequence );
}
// Common code put here to support separate zoom from silencer/burst
void CWeaponCSBase::CallSecondaryAttack()
{
CCSPlayer *pPlayer = GetPlayerOwner();
if ( !pPlayer )
return;
if ( m_iClip2 != -1 && !GetReserveAmmoCount( AMMO_POSITION_SECONDARY ) )
{
m_bFireOnEmpty = TRUE;
}
if ( pPlayer->HasShield() )
CWeaponCSBase::SecondaryAttack();
else
SecondaryAttack();
}
void CWeaponCSBase::UpdateGunHeat( float heat, int iAttachmentIndex )
{
#ifdef CLIENT_DLL
static const float SECONDS_FOR_COOL_DOWN = 2.0f;
static const float MIN_TIME_BETWEEN_SMOKES = 4.0f;
float currentShotTime = gpGlobals->curtime;
float timeSinceLastShot = currentShotTime - m_fLastShotTime;
// Drain off any heat from prior shots.
m_gunHeat -= timeSinceLastShot * ( 1.0f/SECONDS_FOR_COOL_DOWN );
if ( m_gunHeat <= 0.0f )
{
m_gunHeat = 0.0f;
}
// Add the new heat to the gun.
m_gunHeat += heat;
if ( m_gunHeat > 1.0f )
{
// Reset the heat so we have to build up to it again.
m_gunHeat = 0.0f;
m_smokeAttachments |= ( 0x1 << iAttachmentIndex );
}
// Logic for the gun smoke.
if ( m_smokeAttachments != 0x0 )
{
// We don't want to hammer the smoke effect too much, so prevent smoke from spawning too soon after the last smoke.
if ( currentShotTime - m_lastSmokeTime > MIN_TIME_BETWEEN_SMOKES )
{
const char *pszHeatEffect = GetCSWpnData().GetHeatEffectName();
if ( pszHeatEffect && Q_strlen( pszHeatEffect ) > 0 )
{
static const int MAX_SMOKE_ATTACHMENT_INDEX = 16;
for ( int i=0; i<MAX_SMOKE_ATTACHMENT_INDEX && m_smokeAttachments > 0x0; ++i )
{
int attachmentFlag = ( 0x1<<i );
if ( ( attachmentFlag & m_smokeAttachments ) > 0x0 )
{
//Remove the attachment flag from the smoke attachments since we are firing it off.
m_smokeAttachments = ( m_smokeAttachments & ( ~attachmentFlag ) );
CCSPlayer *pPlayer = GetPlayerOwner();
if ( pPlayer )
{
C_BaseViewModel *pViewModel = pPlayer->GetViewModel();
if ( pViewModel )
{
// Dispatch this effect to the split screens that are rendering this first person view model.
int nSlot = GetViewModelSplitScreenSlot( pViewModel );
DispatchParticleEffect( pszHeatEffect, PATTACH_POINT_FOLLOW, pViewModel, i, false, nSlot );
m_lastSmokeTime = currentShotTime;
}
}
}
}
}
//Reset the smoke attachments so that we can start doing a smoke effect for later shots.
m_smokeAttachments = 0x0;
}
}
#endif
}
void CWeaponCSBase::ItemPostFrame()
{
CCSPlayer *pPlayer = GetPlayerOwner();
if ( !pPlayer )
return;
UpdateAccuracyPenalty();
UpdateShieldState();
if ( ( m_bInReload ) && ( pPlayer->m_flNextAttack <= gpGlobals->curtime ))
{
// the AE_WPN_COMPLETE_RELOAD event should handle the stocking the clip, but in case it's missing, we can do it here as well
int j = MIN( GetMaxClip1() - m_iClip1, GetReserveAmmoCount( AMMO_POSITION_PRIMARY ) );
// Add them to the clip
m_iClip1 += j;
GiveReserveAmmo( AMMO_POSITION_PRIMARY, -j, true );
m_bInReload = false;
}
if ( (pPlayer->m_nButtons & IN_ATTACK ) && ( m_flNextPrimaryAttack <= gpGlobals->curtime ) )
{
ItemPostFrame_ProcessPrimaryAttack( pPlayer );
}
else if ( ( pPlayer->m_nButtons & IN_ZOOM ) && ( m_flNextSecondaryAttack <= gpGlobals->curtime ) )
{
if ( ItemPostFrame_ProcessZoomAction( pPlayer ) )
pPlayer->m_nButtons &= ~IN_ZOOM;
}
else if ( (pPlayer->m_nButtons & IN_ATTACK2 ) && ( m_flNextSecondaryAttack <= gpGlobals->curtime ))
{
if ( ItemPostFrame_ProcessSecondaryAttack( pPlayer ) )
pPlayer->m_nButtons &= ~IN_ATTACK2;
}
else if ( pPlayer->m_nButtons & IN_RELOAD && GetMaxClip1() != WEAPON_NOCLIP && !m_bInReload && m_flNextPrimaryAttack < gpGlobals->curtime )
{
ItemPostFrame_ProcessReloadAction( pPlayer );
}
else if ( !( pPlayer->m_nButtons & ( IN_ATTACK|IN_ATTACK2|IN_ZOOM ) ) )
{
ItemPostFrame_ProcessIdleNoAction( pPlayer );
}
}
void CWeaponCSBase::ItemPostFrame_ProcessPrimaryAttack( CCSPlayer *pPlayer )
{
if ( ( m_iClip1 == 0 ) || ( GetMaxClip1() == -1 && !GetReserveAmmoCount( AMMO_POSITION_PRIMARY ) ) )
{
m_bFireOnEmpty = TRUE;
}
if ( CSGameRules()->IsFreezePeriod() ) // Can't shoot during the freeze period
return;
if ( pPlayer->m_bIsDefusing )
return;
if ( pPlayer->State_Get() != STATE_ACTIVE )
return;
if ( pPlayer->IsShieldDrawn() )
return;
// don't repeat fire if this is not a full auto weapon or it's clip is empty
if ( pPlayer->m_iShotsFired > 0 && ( !IsFullAuto() || m_iClip1 == 0 ) )
return;
// ignore attack if we're waiting for the attack button to be released
if ( pPlayer->m_bWaitForNoAttack )
return;
if ( !CanPrimaryAttack() )
return;
if ( IsRevolver() ) // holding primary, will fire when time is elapsed
{