forked from ReactiveDrop/reactivedrop_public_src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathc_asw_weapon.cpp
More file actions
1335 lines (1135 loc) · 41.3 KB
/
c_asw_weapon.cpp
File metadata and controls
1335 lines (1135 loc) · 41.3 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 "c_asw_weapon.h"
#include "c_asw_marine.h"
#include "c_asw_marine_resource.h"
#include "c_asw_player.h"
#include "c_asw_colonist.h"
#include "in_buttons.h"
#include "fx.h"
#include "precache_register.h"
#include "c_breakableprop.h"
#include "asw_marine_skills.h"
#include "datacache/imdlcache.h"
#include "SoundEmitterSystem/isoundemittersystembase.h"
#include "c_asw_fx.h"
#include "prediction.h"
#include <vgui/ISurface.h>
#include <vgui_controls/Panel.h>
#include "asw_gamerules.h"
#include "asw_util_shared.h"
#include "dlight.h"
#include "r_efx.h"
#include "asw_input.h"
#include "asw_weapon_parse.h"
#include "asw_gamerules.h"
#include "game_timescale_shared.h"
#include "vgui/ILocalize.h"
#include "asw_equipment_list.h"
#include "gamestringpool.h"
#include "bone_setup.h"
#include "asw_trace_filter_shot.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
BEGIN_NETWORK_TABLE_NOBASE( C_ASW_Weapon, DT_ASWLocalWeaponData )
RecvPropIntWithMinusOneFlag( RECVINFO(m_iClip2 )),
RecvPropInt( RECVINFO(m_iSecondaryAmmoType )),
RecvPropFloat(RECVINFO(m_fReloadStart)),
RecvPropFloat(RECVINFO(m_fFastReloadStart)),
RecvPropFloat(RECVINFO(m_fFastReloadEnd)),
END_NETWORK_TABLE()
BEGIN_NETWORK_TABLE_NOBASE( C_ASW_Weapon, DT_ASWActiveLocalWeaponData )
RecvPropTime( RECVINFO( m_flNextPrimaryAttack ) ),
RecvPropTime( RECVINFO( m_flNextSecondaryAttack ) ),
RecvPropInt( RECVINFO( m_nNextThinkTick ) ),
RecvPropTime( RECVINFO( m_flTimeWeaponIdle ) ),
END_NETWORK_TABLE()
IMPLEMENT_NETWORKCLASS_ALIASED( ASW_Weapon, DT_ASW_Weapon )
BEGIN_NETWORK_TABLE( CASW_Weapon, DT_ASW_Weapon )
RecvPropBool ( RECVINFO( m_bIsFiring ) ),
RecvPropBool ( RECVINFO( m_bInReload ) ),
RecvPropBool ( RECVINFO( m_bSwitchingWeapons ) ),
RecvPropDataTable("ASWLocalWeaponData", 0, 0, &REFERENCE_RECV_TABLE(DT_ASWLocalWeaponData)),
RecvPropDataTable("ASWActiveLocalWeaponData", 0, 0, &REFERENCE_RECV_TABLE(DT_ASWActiveLocalWeaponData)),
RecvPropBool ( RECVINFO( m_bFastReloadSuccess ) ),
RecvPropBool ( RECVINFO( m_bFastReloadFailure ) ),
RecvPropBool ( RECVINFO( m_bPoweredUp ) ),
RecvPropIntWithMinusOneFlag( RECVINFO(m_iClip1 )),
RecvPropInt( RECVINFO(m_iPrimaryAmmoType )),
RecvPropBool ( RECVINFO( m_bIsTemporaryPickup ) ),
RecvPropEHandle( RECVINFO( m_hOriginalOwnerMR ) ),
RecvPropInt( RECVINFO( m_iInventoryEquipSlot ) ),
RecvPropInt( RECVINFO( m_iClassRequirementOverride ) ),
END_NETWORK_TABLE()
BEGIN_PREDICTION_DATA( C_ASW_Weapon )
DEFINE_PRED_FIELD( m_nNextThinkTick, FIELD_INTEGER, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD_TOL( m_flNextPrimaryAttack, FIELD_FLOAT, FTYPEDESC_INSENDTABLE, TD_MSECTOLERANCE ),
DEFINE_PRED_FIELD_TOL( m_flNextSecondaryAttack, FIELD_FLOAT, FTYPEDESC_INSENDTABLE, TD_MSECTOLERANCE ),
DEFINE_PRED_FIELD( m_iPrimaryAmmoType, FIELD_INTEGER, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD( m_iSecondaryAmmoType, FIELD_INTEGER, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD( m_iClip1, FIELD_INTEGER, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD( m_iClip2, FIELD_INTEGER, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD( m_bIsFiring, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD( m_bInReload, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE ),
DEFINE_PRED_FIELD_TOL( m_fReloadStart, FIELD_FLOAT, FTYPEDESC_INSENDTABLE, 0.1f ),
DEFINE_FIELD( m_fReloadProgress, FIELD_FLOAT ),
DEFINE_PRED_FIELD_TOL( m_fFastReloadStart, FIELD_FLOAT, FTYPEDESC_INSENDTABLE, 0.1f ),
DEFINE_PRED_FIELD_TOL( m_fFastReloadEnd, FIELD_FLOAT, FTYPEDESC_INSENDTABLE, 0.1f ),
DEFINE_FIELD( m_bFastReloadSuccess, FIELD_BOOLEAN ),
DEFINE_FIELD( m_bFastReloadFailure, FIELD_BOOLEAN ),
DEFINE_FIELD( m_fReloadClearFiringTime, FIELD_FLOAT ),
DEFINE_FIELD( m_flDelayedFire, FIELD_FLOAT ),
DEFINE_FIELD( m_bShotDelayed, FIELD_BOOLEAN ),
DEFINE_FIELD( m_hLaserSight, FIELD_EHANDLE ),
DEFINE_FIELD( m_bFastReloadSuccess, FIELD_BOOLEAN ),
DEFINE_FIELD( m_bFastReloadFailure, FIELD_BOOLEAN ),
DEFINE_PRED_FIELD( m_flTimeWeaponIdle, FIELD_FLOAT, FTYPEDESC_OVERRIDE | FTYPEDESC_PRIVATE | FTYPEDESC_NOERRORCHECK ),
DEFINE_PRED_FIELD( m_flCycle, FIELD_FLOAT, FTYPEDESC_OVERRIDE | FTYPEDESC_PRIVATE | FTYPEDESC_NOERRORCHECK ),
DEFINE_PRED_FIELD( m_nSequence, FIELD_INTEGER, FTYPEDESC_OVERRIDE | FTYPEDESC_PRIVATE | FTYPEDESC_NOERRORCHECK ),
DEFINE_PRED_FIELD( m_nNewSequenceParity, FIELD_INTEGER, FTYPEDESC_OVERRIDE | FTYPEDESC_PRIVATE | FTYPEDESC_NOERRORCHECK ),
DEFINE_PRED_FIELD( m_nResetEventsParity, FIELD_INTEGER, FTYPEDESC_OVERRIDE | FTYPEDESC_PRIVATE | FTYPEDESC_NOERRORCHECK ),
END_PREDICTION_DATA()
//DEFINE_PRED_FIELD_TOL( m_flNextCoolTime, FIELD_FLOAT, FTYPEDESC_INSENDTABLE, TD_MSECTOLERANCE ),
BEGIN_ENT_SCRIPTDESC( C_ASW_Weapon, C_BaseCombatWeapon, "Alien Swarm weapon" )
END_SCRIPTDESC()
ConVar asw_red_muzzle_r("asw_red_muzzle_r", "255");
ConVar asw_red_muzzle_g("asw_red_muzzle_g", "128");
ConVar asw_red_muzzle_b("asw_red_muzzle_b", "128");
ConVar asw_muzzle_light_radius_min( "asw_muzzle_light_radius_min", "50", FCVAR_CHEAT );
ConVar asw_muzzle_light_radius_max( "asw_muzzle_light_radius_max", "100", FCVAR_CHEAT );
ConVar asw_muzzle_light( "asw_muzzle_light", "255 192 64 6", FCVAR_CHEAT );
ConVar asw_muzzle_flash_new_type( "asw_muzzle_flash_new_type", "0", FCVAR_CHEAT );
ConVar asw_laser_sight( "asw_laser_sight", "1", FCVAR_ARCHIVE );
ConVar asw_laser_sight_min_distance( "asw_laser_sight_min_distance", "9999", 0, "The min distance at which to accurately draw the laser sight from the muzzle rather than using the shoot direction" );
ConVar glow_outline_color_weapon( "glow_outline_color_weapon", "0 102 192", FCVAR_NONE );
ConVar rd_tracer_tint_self( "rd_tracer_tint_self", "255 255 255", FCVAR_ARCHIVE, "Tint tracers and muzzle flashes from own marine" );
ConVar rd_tracer_tint_other( "rd_tracer_tint_other", "255 255 255", FCVAR_ARCHIVE, "Tint tracers and muzzle flashes from other marines" );
ConVar rd_marine_gear( "rd_marine_gear", "1", FCVAR_NONE, "Draw model overlays for marine gear items" );
ConVar rd_marine_gear_hide_backpack( "rd_marine_gear_hide_backpack", "1", FCVAR_NONE, "Disable body group 1 on the marine model when rendering certain model overlays" );
ConVar rd_drop_magazine( "rd_drop_magazine", "1", FCVAR_NONE, "Drop a magazine model when reloading weapons" );
ConVar rd_drop_magazine_force( "rd_drop_magazine_force", "50", FCVAR_NONE, "Amount of random force to apply to dropped magazine" );
ConVar rd_drop_magazine_force_up( "rd_drop_magazine_force_up", "50", FCVAR_NONE, "Amount of upward force to apply to the dropped magazine" );
ConVar rd_drop_magazine_spin( "rd_drop_magazine_spin", "1000", FCVAR_NONE, "Amount of random angular velocity to apply to dropped magazine" );
ConVar rd_drop_magazine_lifetime( "rd_drop_magazine_lifetime", "4", FCVAR_NONE, "Time before a dropped magazine fades" );
ConVar rd_strange_device_model( "rd_strange_device_model", "0", FCVAR_NONE, "Should items with strange devices attached display them in the world?" );
ConVar rd_weapon_autoaim( "rd_weapon_autoaim", "1", FCVAR_NONE, "Enable or disable weapon auto-aim if available." );
extern ConVar asw_use_particle_tracers;
extern ConVar muzzleflash_light;
extern ConVar rd_show_others_laser_pointer;
#define RD_STRANGE_DEVICE_MODEL "models/weapons/accessories/strange_device.mdl"
C_ASW_Weapon::C_ASW_Weapon() :
m_GlowObject( this, glow_outline_color_weapon.GetColorAsVector(), 1.0f, false, true)
{
SetPredictionEligible( true );
m_iEquipmentListIndex = -1;
m_pEquipItem = NULL;
m_fLastMuzzleFlashTime = 0;
m_fMuzzleFlashScale = -1;
m_fTurnRateModifier = 1.0f;
m_fReloadClearFiringTime = 0;
m_fFiringTurnRateModifier = 0.7f;
m_bSwitchingWeapons = false;
m_bShotDelayed = 0;
m_flDelayedFire = 0;
m_bOldHidden = false;
m_flReloadFailTime = 1.0;
m_fReloadStart = 0;
m_fReloadProgress = 0;
m_fFastReloadStart = 0;
m_fFastReloadEnd = 0;
m_bFastReloadSuccess = false;
m_bFastReloadFailure = false;
m_bWeaponCreated = false;
m_nMuzzleAttachment = 0;
m_nLastMuzzleAttachment = 0;
m_nLaserPointerAttachment = 0;
m_nLaserBodyGroup = -2;
m_nMagazineBodyGroup = -2;
m_nScreenBodyGroup = -2;
m_bUsingViewMarineLaserPointer = false;
m_fMuzzleFlashTime = 0.0f;
m_bPoweredUp = false;
m_bIsTemporaryPickup = false;
m_iClassRequirementOverride = -1;
}
C_ASW_Weapon::~C_ASW_Weapon()
{
// delete the bayonet, if there's any
if (m_hBayonet.Get())
{
UTIL_Remove( m_hBayonet.Get() );
m_hBayonet = NULL;
}
RemoveLaserPointerEffect();
if (m_hLaserSight.Get())
{
UTIL_Remove( m_hLaserSight.Get() );
m_hLaserSight = NULL;
}
for ( int i = 0; i < NELEMS( m_hWeaponAccessory ); i++ )
{
if ( m_hWeaponAccessory[i].Get() )
{
UTIL_Remove( m_hWeaponAccessory[i].Get() );
m_hWeaponAccessory[i] = NULL;
}
}
}
void C_ASW_Weapon::OnDataChanged( DataUpdateType_t type )
{
bool bPredict = ShouldPredict();
if (bPredict)
{
SetPredictionEligible( true );
}
else
{
SetPredictionEligible( false );
}
BaseClass::OnDataChanged( type );
if ( GetPredictable() && !bPredict )
ShutdownPredictable();
if ( type == DATA_UPDATE_CREATED )
{
m_bWeaponCreated = true;
if ( IsInventoryEquipSlotValid() )
{
const CRD_ItemInstance &instance = m_hOriginalOwnerMR->m_EquippedItemData[m_iInventoryEquipSlot];
MaybeAddStrangeDevice( -1, instance.m_iItemDefID );
for ( int i = 0; i < RD_ITEM_MAX_ACCESSORIES; i++ )
{
MaybeAddStrangeDevice( i, instance.m_iAccessory[i] );
}
}
SetNextClientThink( CLIENT_THINK_ALWAYS );
}
if (IsEffectActive(EF_NODRAW) != m_bOldHidden)
{
if (m_hBayonet.Get())
{
if (IsEffectActive(EF_NODRAW))
m_hBayonet->AddEffects( EF_NODRAW );
else
m_hBayonet->RemoveEffects( EF_NODRAW );
}
if (m_hLaserSight.Get())
{
if (IsEffectActive(EF_NODRAW))
m_hLaserSight->AddEffects( EF_NODRAW );
else
m_hLaserSight->RemoveEffects( EF_NODRAW );
}
}
m_bOldHidden = IsEffectActive(EF_NODRAW);
}
#define ASW_BAYONET_MODEL "models/swarm/Bayonet/bayonet.mdl"
void C_ASW_Weapon::CreateBayonet()
{
if (m_hBayonet.Get()) // already have a bayonet
return;
int iAttach = LookupAttachment("muzzle");
if (iAttach == -1)
{
Msg("no attachment for bayonet\n");
return;
}
C_BreakableProp *pEnt = new C_BreakableProp;
if (!pEnt)
{
Msg("No C_BreakableProp crated\n");
return;
}
if (pEnt->InitializeAsClientEntity( ASW_BAYONET_MODEL, false ))
{
//pEnt->SetFadeMinMax( 1200, 1500 );
pEnt->SetParent( this, iAttach );
pEnt->SetLocalOrigin( Vector( 0, 0, 0 ) );
pEnt->SetLocalAngles( QAngle( 0, 0, 0 ) );
pEnt->SetSolid( SOLID_NONE );
pEnt->RemoveEFlags( EFL_USE_PARTITION_WHEN_NOT_SOLID );
m_hBayonet = pEnt;
Msg("Bayonet Entity all setup: %d\n", pEnt->entindex());
}
else
{
Msg("Bayonet Failed to init as client ent\n");
}
}
bool C_ASW_Weapon::ShouldPredict( void )
{
C_BasePlayer* pOwner = NULL;
C_BaseCombatCharacter* pCombatCharOwner = GetOwner();
if ( pCombatCharOwner && pCombatCharOwner->Classify() == CLASS_ASW_MARINE )
{
C_ASW_Marine* pMarine = assert_cast<C_ASW_Marine*>(pCombatCharOwner);
if (pMarine->m_Commander && pMarine->IsInhabited())
pOwner = pMarine->GetCommander();
}
else
{
pOwner = ToBasePlayer( pCombatCharOwner );
}
if ( C_BasePlayer::IsLocalPlayer( pOwner ) )
return true;
return BaseClass::ShouldPredict();
}
C_BasePlayer *C_ASW_Weapon::GetPredictionOwner( void )
{
C_BaseCombatCharacter* pCombatCharOwner = GetOwner();
if ( pCombatCharOwner && pCombatCharOwner->Classify() == CLASS_ASW_MARINE )
{
C_ASW_Marine* pMarine = assert_cast<C_ASW_Marine*>(pCombatCharOwner);
if (pMarine->IsInhabited())
{
return pMarine->GetCommander();
}
}
return NULL;
}
int C_ASW_Weapon::GetMuzzleAttachment( void )
{
if ( m_nMuzzleAttachment == 0 )
{
// lazy initialization
m_nMuzzleAttachment = LookupAttachment( "muzzle" );
}
return m_nMuzzleAttachment;
}
void C_ASW_Weapon::SetMuzzleAttachment( int nNewAttachment )
{
m_nMuzzleAttachment = nNewAttachment;
}
int C_ASW_Weapon::GetLaserPointerAttachment( void )
{
if ( m_nLaserPointerAttachment == 0 )
{
// lazy initialization
m_nLaserPointerAttachment = LookupAttachment( "laserpointer" );
}
return m_nLaserPointerAttachment ? m_nLaserPointerAttachment : GetMuzzleAttachment();
}
void C_ASW_Weapon::SetLaserPointerAttachment( int nNewAttachment )
{
m_nLaserPointerAttachment = nNewAttachment;
}
float C_ASW_Weapon::GetMuzzleFlashScale( void )
{
// if we haven't calculated the muzzle scale based on the carrying marine's skill yet, then do so
//if (m_fMuzzleFlashScale == -1)
{
C_ASW_Marine *pMarine = GetMarine();
if (pMarine)
m_fMuzzleFlashScale = MarineSkills()->GetSkillBasedValueByMarine(pMarine, ASW_MARINE_SKILL_ACCURACY, ASW_MARINE_SUBSKILL_ACCURACY_MUZZLE);
else
return 1.5f;
}
return m_fMuzzleFlashScale;
}
Vector C_ASW_Weapon::GetMuzzleFlashTint()
{
HACK_GETLOCALPLAYER_GUARD( "need local player to see what color the muzzle flash should be" );
C_ASW_Player *pLocalPlayer = C_ASW_Player::GetLocalASWPlayer();
C_ASW_Inhabitable_NPC *pViewNPC = pLocalPlayer ? pLocalPlayer->GetViewNPC() : NULL;
Vector vecColor = pViewNPC && GetOwner() == pViewNPC ? rd_tracer_tint_self.GetColorAsVector() : rd_tracer_tint_other.GetColorAsVector();
if ( GetMuzzleFlashScale() >= 1.9f ) // red if our muzzle flash is the biggest size based on our skill
{
vecColor.y *= 0.65f;
vecColor.z *= 0.65f;
}
return vecColor;
}
void C_ASW_Weapon::ProcessMuzzleFlashEvent()
{
// we don't want weapons like the shotgun (which calls this for each pellet) to crates muzzles multiple times a frame
// but we want PDWs to be able to do this. We get around this by checking the last muzzle attachment that was used
// in the case of the PDW, it alternates back and forth, but should still never get called twice for the same attachment in the same frame
int iAttachment = GetMuzzleAttachment();
if ( m_fLastMuzzleFlashTime == gpGlobals->curtime && m_nLastMuzzleAttachment == iAttachment )
return;
m_nLastMuzzleAttachment = iAttachment;
m_fLastMuzzleFlashTime = gpGlobals->curtime; // store when we last fired, used for some clientside animation stuff
// if this weapon is a flamethrower type weapon, then tell our marine's flame emitter
// to work for a while instead of muzzle flashing
C_BaseCombatCharacter* pCombatCharOwner = GetOwner();
if (ShouldMarineFlame())
{
if ( pCombatCharOwner && pCombatCharOwner->Classify() == CLASS_ASW_MARINE )
{
C_ASW_Marine* pMarine = assert_cast<C_ASW_Marine*>(pCombatCharOwner);
pMarine->m_fFlameTime = gpGlobals->curtime + GetFireRate() + 0.02f;
}
return;
}
else if (ShouldMarineFireExtinguish())
{
if ( pCombatCharOwner && pCombatCharOwner->Classify() == CLASS_ASW_MARINE )
{
C_ASW_Marine* pMarine = assert_cast<C_ASW_Marine*>(pCombatCharOwner);
pMarine->m_fFireExtinguisherTime = gpGlobals->curtime + GetFireRate() + 0.02f;
}
return;
}
// attach muzzle flash particle system effect
if ( iAttachment > 0 )
{
float flScale = GetMuzzleFlashScale();
if ( asw_use_particle_tracers.GetBool() )
{
FX_ASW_ParticleMuzzleFlashAttached( flScale, GetRefEHandle(), iAttachment, GetMuzzleFlashTint() );
}
else
{
FX_ASW_MuzzleEffectAttached( flScale, GetRefEHandle(), iAttachment, NULL, false );
}
}
// If we have an attachment, then stick a light on it.
if ( muzzleflash_light.GetBool() )
{
Vector vAttachment;
QAngle dummyAngles;
if ( GetAttachment( GetMuzzleAttachment(), vAttachment, dummyAngles ) )
{
// Make an elight
dlight_t *el = effects->CL_AllocDlight( LIGHT_INDEX_MUZZLEFLASH + index );
el->origin = vAttachment;
el->radius = random->RandomFloat( asw_muzzle_light_radius_min.GetFloat(), asw_muzzle_light_radius_max.GetFloat() );
el->decay = el->radius / 0.05f;
el->die = gpGlobals->curtime + 0.05f;
Color c = asw_muzzle_light.GetColor();
el->color.r = c.r();
el->color.g = c.g();
el->color.b = c.b();
el->color.exponent = c.a();
}
}
OnMuzzleFlashed();
}
void C_ASW_Weapon::DropMagazineGib()
{
const char *szModelName = GetMagazineGibModelName();
if ( !szModelName )
return;
if ( !rd_drop_magazine.GetBool() )
return;
C_BaseAnimating::PushAllowBoneAccess( true, false, "C_ASW_Weapon::DropMagazineGib" );
Vector vecHand;
QAngle angHand;
Vector vecHandForward;
GetBonePosition( LookupBone( "ValveBiped.Bip01_R_Hand" ), vecHand, angHand );
AngleVectors( angHand, &vecHandForward );
C_Gib *pGib = C_Gib::CreateClientsideGib( szModelName, vecHand + vecHandForward * BoundingRadius(),
RandomVector( -rd_drop_magazine_force.GetFloat(), rd_drop_magazine_force.GetFloat() ) + Vector( 0, 0, rd_drop_magazine_force_up.GetFloat() ),
RandomAngularImpulse( -rd_drop_magazine_spin.GetFloat(), rd_drop_magazine_spin.GetFloat() ),
rd_drop_magazine_lifetime.GetFloat() );
if ( pGib )
{
pGib->SetSkin( GetMagazineGibModelSkin() );
}
if ( DisplayClipsDoubled() )
{
GetBonePosition( LookupBone( "ValveBiped.Bip01_L_Hand" ), vecHand, angHand );
AngleVectors( angHand, &vecHandForward );
pGib = C_Gib::CreateClientsideGib( szModelName, vecHand + vecHandForward * BoundingRadius(),
RandomVector( -rd_drop_magazine_force.GetFloat(), rd_drop_magazine_force.GetFloat() ) + Vector( 0, 0, rd_drop_magazine_force_up.GetFloat() ),
RandomAngularImpulse( -rd_drop_magazine_spin.GetFloat(), rd_drop_magazine_spin.GetFloat() ),
rd_drop_magazine_lifetime.GetFloat() );
if ( pGib )
{
pGib->SetSkin( GetMagazineGibModelSkin() );
}
}
C_BaseAnimating::PopBoneAccess( "C_ASW_Weapon::DropMagazineGib" );
}
bool C_ASW_Weapon::Simulate()
{
SimulateLaserPointer();
BaseClass::Simulate();
return asw_laser_sight.GetBool();
}
void C_ASW_Weapon::ClientThink()
{
bool bShouldGlow = false;
float flDistanceToMarineSqr = 0.0f;
float flWithinDistSqr = (ASW_MARINE_USE_RADIUS*4)*(ASW_MARINE_USE_RADIUS*4);
if ( !GetOwner() )
{
C_ASW_Player *pLocalPlayer = C_ASW_Player::GetLocalASWPlayer();
if ( pLocalPlayer && pLocalPlayer->GetViewNPC() && ASWInput()->GetUseGlowEntity() != this && AllowedToPickup( pLocalPlayer->GetViewNPC() ) )
{
flDistanceToMarineSqr = (pLocalPlayer->GetViewNPC()->GetAbsOrigin() - WorldSpaceCenter()).LengthSqr();
if ( flDistanceToMarineSqr < flWithinDistSqr )
bShouldGlow = true;
}
if ( ASWGameRules() && ASWGameRules()->GetMarineDeathCamInterp() > 0.0f )
{
bShouldGlow = false;
}
}
m_GlowObject.SetRenderFlags( false, bShouldGlow );
if ( m_GlowObject.IsRendering() )
{
m_GlowObject.SetAlpha( MIN( 0.7f, (1.0f - (flDistanceToMarineSqr / flWithinDistSqr)) * 1.0f) );
}
if ( m_nMagazineBodyGroup == -2 )
{
m_nMagazineBodyGroup = FindBodygroupByName( "magazine" );
Assert( m_nMagazineBodyGroup == -1 || GetBodygroupCount( m_nMagazineBodyGroup ) == 2 );
}
if ( m_nMagazineBodyGroup != -1 )
{
SetBodygroup( m_nMagazineBodyGroup, IsReloading() ? 1 : 0 );
}
if ( m_nScreenBodyGroup == -2 )
{
m_nScreenBodyGroup = FindBodygroupByName( "screen" );
Assert( m_nScreenBodyGroup == -1 || GetBodygroupCount( m_nScreenBodyGroup ) == 2 );
}
if ( m_nScreenBodyGroup != -1 )
{
SetBodygroup( m_nScreenBodyGroup, GetOwner() ? 1 : 0 );
}
if ( ASWDeathmatchMode() && ViewModelIsMarineAttachment() )
{
C_ASW_Marine *pMarine = GetMarine();
if ( pMarine )
{
SetRenderColor( pMarine->GetRenderColorR(), pMarine->GetRenderColorG(), pMarine->GetRenderColorB() );
}
else
{
SetRenderColor( 255, 255, 255 );
}
}
}
bool C_ASW_Weapon::ShouldDraw()
{
if ( IsMarkedForDeletion() )
return false;
// If it's a player, then only show active weapons
C_BaseCombatCharacter* pCombatCharOwner = GetOwner();
if ( pCombatCharOwner && pCombatCharOwner->Classify() == CLASS_ASW_MARINE )
{
C_ASW_Marine *pMarine = assert_cast< C_ASW_Marine * >( pCombatCharOwner );
if ( pMarine->IsEffectActive( EF_NODRAW ) )
{
return false;
}
return BaseClass::ShouldDraw() && ( ( pMarine->GetActiveWeapon() == this ) || ( rd_marine_gear.GetBool() && ViewModelIsMarineAttachment() && pMarine->GetRenderAlpha() > 0 ) );
}
return BaseClass::ShouldDraw();
}
//-----------------------------------------------------------------------------
// Purpose: Returns true if this client's carrying this weapon
//-----------------------------------------------------------------------------
bool C_ASW_Weapon::IsCarriedByLocalPlayer( void )
{
C_BaseCombatCharacter* pCombatCharOwner = GetOwner();
if ( !pCombatCharOwner )
return false;
if ( pCombatCharOwner->Classify() == CLASS_ASW_MARINE )
{
C_ASW_Marine* pMarine = assert_cast<C_ASW_Marine*>(pCombatCharOwner);
if (!pMarine->GetCommander() || !pMarine->IsInhabited())
return false;
return ( C_BasePlayer::IsLocalPlayer(pMarine->GetCommander()) );
}
else
return false;
}
//-----------------------------------------------------------------------------
// Purpose: Returns true if this weapon is the local client's currently wielded weapon
//-----------------------------------------------------------------------------
bool C_ASW_Weapon::IsActiveByLocalPlayer( void )
{
if ( IsCarriedByLocalPlayer() )
{
return (m_iState == WEAPON_IS_ACTIVE);
}
return false;
}
ShadowType_t C_ASW_Weapon::ShadowCastType()
{
//#ifdef DEBUG
//return SHADOWS_NONE;
//#endif
return SHADOWS_RENDER_TO_TEXTURE;
}
const char* C_ASW_Weapon::GetPartialReloadSound(int iPart)
{
switch (iPart)
{
case 1: return "ASW_Rifle.ReloadB"; break;
case 2: return "ASW_Rifle.ReloadC"; break;
default: break;
};
return "ASW_Rifle.ReloadA";
}
void C_ASW_Weapon::ASWReloadSound(int iType)
{
int iPitch = 100;
const char *shootsound = GetPartialReloadSound(iType);
if ( !shootsound || !shootsound[0] )
return;
CSoundParameters params;
if ( !GetParametersForSound( shootsound, params, NULL ) )
return;
float soundtime = 0;
EmitSound_t playparams(params);
if (soundtime != 0)
playparams.m_flSoundTime = soundtime;
playparams.m_nPitch = iPitch;
C_ASW_Player *pPlayer = GetCommander();
if ( params.play_to_owner_only )
{
// Am I only to play to my owner?
if ( pPlayer && GetOwner() && pPlayer->GetNPC() == GetOwner() )
{
CSingleUserRecipientFilter filter( pPlayer );
if ( prediction->InPrediction() && IsPredicted() )
{
filter.UsePredictionRules();
}
EmitSound(filter, GetOwner()->entindex(), playparams);
//EmitSound( filter, GetOwner()->entindex(), shootsound, NULL, soundtime );
}
}
else
{
// Play weapon sound from the owner
if ( GetOwner() )
{
CPASAttenuationFilter filter( GetOwner(), params.soundlevel );
if ( prediction->InPrediction() && IsPredicted() )
{
filter.UsePredictionRules();
}
EmitSound(filter, GetOwner()->entindex(), playparams);
}
// If no owner play from the weapon (this is used for thrown items)
else
{
CPASAttenuationFilter filter( this, params.soundlevel );
if ( prediction->InPrediction() && IsPredicted() )
{
filter.UsePredictionRules();
}
EmitSound( filter, entindex(), shootsound, NULL, soundtime );
}
}
}
// attach laser sight to all guns with that attachment
void C_ASW_Weapon::CreateLaserSight()
{
int iAttachment = LookupAttachment( "laser" );
if ( iAttachment <= 0 )
{
return;
}
C_BaseAnimating *pEnt = new C_BaseAnimating;
if (!pEnt)
{
Msg("Error, couldn't create new C_BaseAnimating\n");
return;
}
if (!pEnt->InitializeAsClientEntity( "models/swarm/shouldercone/lasersight.mdl", false ))
{
Msg("Error, couldn't InitializeAsClientEntity\n");
pEnt->Release();
return;
}
pEnt->SetParent( this, iAttachment );
pEnt->SetLocalOrigin( Vector( 0, 0, 0 ) );
pEnt->SetLocalAngles( QAngle( 0, 0, 0 ) );
pEnt->SetSolid( SOLID_NONE );
pEnt->RemoveEFlags( EFL_USE_PARTITION_WHEN_NOT_SOLID );
m_hLaserSight = pEnt;
}
//-----------------------------------------------------------------------------
// Dropped weapon functions
//-----------------------------------------------------------------------------
int C_ASW_Weapon::GetUseIconTextureID()
{
const CASW_EquipItem *pEquipItem = GetEquipItem();
Assert( pEquipItem );
return g_ASWEquipmentList.GetEquipIconTexture( !pEquipItem || !pEquipItem->m_bIsExtra, GetEquipmentListIndex() );
}
bool C_ASW_Weapon::GetUseAction( ASWUseAction &action, C_ASW_Inhabitable_NPC *pUser )
{
if ( !pUser )
return false;
C_ASW_Marine *pMarine = C_ASW_Marine::AsMarine( pUser );
action.iUseIconTexture = GetUseIconTextureID();
action.UseTarget = this;
action.fProgress = -1;
action.iInventorySlot = pMarine ? pMarine->GetWeaponPositionForPickup( GetClassname(), m_bIsTemporaryPickup ) : -1;
action.bWideIcon = ( action.iInventorySlot != ASW_INVENTORY_SLOT_EXTRA );
// build the appropriate take string
const CASW_EquipItem *pItem = GetEquipItem();
if ( pItem )
{
wchar_t wszWeaponShortName[128];
TryLocalize( pItem->m_szShortName, wszWeaponShortName, sizeof( wszWeaponShortName ) );
wchar_t wszWeaponName[128];
if ( IsInventoryEquipSlotValid() && SteamFriends() )
{
wchar_t wszPlayerName[128];
V_UTF8ToUnicode( SteamFriends()->GetFriendPersonaName( m_hOriginalOwnerMR->m_OriginalCommander->GetSteamID() ), wszPlayerName, sizeof( wszPlayerName ) );
g_pVGuiLocalize->ConstructString( wszWeaponName, sizeof( wszWeaponName ), g_pVGuiLocalize->Find( "#asw_owned_weapon_format" ), 2, wszPlayerName, wszWeaponShortName );
}
else
{
V_wcsncpy( wszWeaponName, wszWeaponShortName, sizeof( wszWeaponName ) );
}
if ( m_bSwappingWeapon )
{
g_pVGuiLocalize->ConstructString( action.wszText, sizeof( action.wszText ), g_pVGuiLocalize->Find( "#asw_swap_weapon_format" ), 1, wszWeaponName );
}
else
{
g_pVGuiLocalize->ConstructString( action.wszText, sizeof( action.wszText ), g_pVGuiLocalize->Find( "#asw_take_weapon_format" ), 1, wszWeaponName );
}
}
if ( AllowedToPickup( pUser ) )
{
action.UseIconRed = 66;
action.UseIconGreen = 142;
action.UseIconBlue = 192;
action.bShowUseKey = true;
}
else
{
action.UseIconRed = 255;
action.UseIconGreen = 0;
action.UseIconBlue = 0;
action.TextRed = 164;
action.TextGreen = 164;
action.TextBlue = 164;
action.bTextGlow = false;
if ( ASWGameRules() )
TryLocalize( ASWGameRules()->GetPickupDenial(), action.wszText, sizeof( action.wszText ) );
action.bShowUseKey = false;
}
return true;
}
int C_ASW_Weapon::DrawModel( int flags, const RenderableInstance_t &instance )
{
// HACK - avoid the hack in C_BaseCombatWeapon that changes the model inappropriately for Infested
return BASECOMBATWEAPON_DERIVED_FROM::DrawModel( flags, instance );
}
IClientModelRenderable* C_ASW_Weapon::GetClientModelRenderable()
{
// HACK - avoid the hack in C_BaseCombatWeapon that changes the model inappropriately for Infested
return BASECOMBATWEAPON_DERIVED_FROM::GetClientModelRenderable();
}
void C_ASW_Weapon::MaybeAddStrangeDevice( int i, SteamItemDef_t defID )
{
if ( !rd_strange_device_model.GetBool() )
return;
Assert( m_hWeaponAccessory[i + 1] == NULL );
if ( defID == 0 )
return;
const ReactiveDropInventory::ItemDef_t *pDef = ReactiveDropInventory::GetItemDef( defID );
Assert( pDef );
if ( !pDef )
return;
if ( pDef->CompressedDynamicProps.Count() )
{
C_RD_Weapon_Accessory *pEnt = C_RD_Weapon_Accessory::CreateWeaponAccessory( this, i );
Assert( pEnt );
if ( !pEnt )
return;
pEnt->SetBodygroup( 1, pDef->CompressedDynamicProps.Count() );
m_hWeaponAccessory[i + 1] = pEnt;
const CASW_WeaponInfo *pWeaponInfo = GetWeaponInfo();
Assert( pWeaponInfo );
if ( pWeaponInfo )
{
Assert( !pWeaponInfo->m_vecStrangeDeviceOffset[i + 1].IsZeroFast() );
Assert( !pWeaponInfo->m_bUseStrangeDeviceWorldOffsets || !pWeaponInfo->m_vecStrangeDeviceOffsetWorld[i + 1].IsZeroFast() );
// we're not using the model cache here - we probably should, but it's not causing any problems yet
CStudioHdr ViewModel{ modelinfo->GetStudiomodel( modelinfo->GetModel( modelinfo->GetModelIndex( GetViewModel() ) ) ) };
Assert( ViewModel.IsValid() );
CStudioHdr WorldModel{ modelinfo->GetStudiomodel( modelinfo->GetModel( modelinfo->GetModelIndex( GetWorldModel() ) ) ) };
Assert( WorldModel.IsValid() );
AngleMatrix( pWeaponInfo->m_angStrangeDeviceAngle[i + 1], pWeaponInfo->m_vecStrangeDeviceOffset[i + 1], pEnt->m_matAccessoryTransform );
pEnt->m_iAccessoryBone = Studio_BoneIndexByName( &ViewModel, pWeaponInfo->m_szStrangeDeviceBone[i + 1] );
Assert( pEnt->m_iAccessoryBone != -1 );
if ( pWeaponInfo->m_bUseStrangeDeviceWorldOffsets )
{
AngleMatrix( pWeaponInfo->m_angStrangeDeviceAngleWorld[i + 1], pWeaponInfo->m_vecStrangeDeviceOffsetWorld[i + 1], pEnt->m_matAccessoryTransformWorld );
pEnt->m_iAccessoryBoneWorld = Studio_BoneIndexByName( &WorldModel, pWeaponInfo->m_szStrangeDeviceBoneWorld[i + 1] );
}
else
{
AngleMatrix( pWeaponInfo->m_angStrangeDeviceAngle[i + 1], pWeaponInfo->m_vecStrangeDeviceOffset[i + 1], pEnt->m_matAccessoryTransformWorld );
pEnt->m_iAccessoryBoneWorld = Studio_BoneIndexByName( &WorldModel, pWeaponInfo->m_szStrangeDeviceBone[i + 1] );
}
Assert( pEnt->m_iAccessoryBoneWorld != -1 );
}
}
}
//--------------------------------------------------------------------------------------------------------
bool C_ASW_Weapon::ShouldShowLaserPointer()
{
if ( !asw_laser_sight.GetBool() || IsDormant() || !GetOwner() || !IsOffensiveWeapon() )
{
return false;
}
//C_ASW_Player *pPlayer = GetCommander();
C_ASW_Marine *pMarine = GetMarine();
//if ( !pPlayer || !pMarine || !pPlayer->GetMarine() )
// return false;
return ( pMarine && pMarine->GetActiveWeapon() == this );
//return ( pPlayer == C_ASW_Player::GetLocalASWPlayer() && pPlayer->GetMarine() == pMarine
// && pMarine->GetActiveWeapon() == this );
}
bool C_ASW_Weapon::ShouldAlignWeaponToLaserPointer()
{
if ( !asw_laser_sight.GetBool() || IsDormant() || !GetOwner() || !IsOffensiveWeapon() )
{
return false;
}
const CASW_WeaponInfo* pWpnInfo = GetWeaponInfo();
if ( !m_pLaserPointerEffect || !pWpnInfo || !pWpnInfo->m_bOrientToLaser )
return false;
C_ASW_Marine *pMarine = GetMarine();
if ( !pMarine || pMarine->GetActiveWeapon() != this )
return false;
if ( IsReloading() || pMarine->GetCurrentMeleeAttack() || m_bSwitchingWeapons
|| (gpGlobals->curtime < pMarine->GetStopTime()) || pMarine->IsDoingEmoteGesture()
|| pMarine->ShouldPreventLaserSight() || GameTimescale()->GetCurrentTimescale() < 1.0f
|| pMarine->GetUsingEntity() || pMarine->GetFacingPoint() != vec3_origin )
return false;
return true;
}
bool C_ASW_Weapon::ShouldDimLaserPointer()
{
return IsFiring();
}
bool C_ASW_Weapon::IsFriendlyFireTarget( C_BaseEntity *pEnt )
{
if ( !pEnt )
{
return false;
}
C_ASW_Marine *pMarine = GetMarine();
if ( pEnt->Classify() == CLASS_ASW_MARINE && ( !ASWDeathmatchMode() || ( ASWDeathmatchMode()->IsTeamDeathmatchEnabled() && pMarine && pEnt->GetTeamNumber() == pMarine->GetTeamNumber() ) ) )
{
return true;
}
if ( pEnt->Classify() == CLASS_ASW_COLONIST && !assert_cast< C_ASW_Colonist * >( pEnt )->IsAimTarget() )
{
return true;
}
return false;
}
//--------------------------------------------------------------------------------------------------------
void C_ASW_Weapon::SimulateLaserPointer()
{
if ( m_nLaserBodyGroup == -2 )
{
m_nLaserBodyGroup = FindBodygroupByName( "laser" );
Assert( m_nLaserBodyGroup == -1 || GetBodygroupCount( m_nLaserBodyGroup ) == 2 );
}
if ( m_nLaserBodyGroup != -1 )
{
SetBodygroup( m_nLaserBodyGroup, asw_laser_sight.GetBool() ? 0 : 1 );
}
if ( !ShouldShowLaserPointer() )
{
RemoveLaserPointerEffect();
return;
}
C_ASW_Marine *pMarine = GetMarine();
if ( !pMarine )
{
RemoveLaserPointerEffect();
RemoveMuzzleFlashEffect();
return;
}
bool bIsViewMarine = false;
C_ASW_Player *pPlayer = GetCommander();
C_ASW_Player *pLocalPlayer = C_ASW_Player::GetLocalASWPlayer();
if ( pLocalPlayer && pLocalPlayer->GetViewNPC() == pMarine )
bIsViewMarine = true;
// don't show laser pointers of non local players
if ( rd_show_others_laser_pointer.GetBool() == 0 && !bIsViewMarine )
{
RemoveLaserPointerEffect();
return;
}