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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "in_buttons.h"
#include "takedamageinfo.h"
#include "weapon_dodbase.h"
#include "ammodef.h"
#include "dod_gamerules.h"
#ifdef CLIENT_DLL
extern IVModelInfoClient* modelinfo;
#else
extern IVModelInfo* modelinfo;
#include "ilagcompensationmanager.h"
#endif
#if defined( CLIENT_DLL )
#include "vgui/ISurface.h"
#include "vgui_controls/Controls.h"
#include "c_dod_player.h"
#include "hud_crosshair.h"
#include "SoundEmitterSystem/isoundemittersystembase.h"
#else
#include "dod_player.h"
#endif
#include "effect_dispatch_data.h"
// ----------------------------------------------------------------------------- //
// Global functions.
// ----------------------------------------------------------------------------- //
bool IsAmmoType( int iAmmoType, const char *pAmmoName )
{
return GetAmmoDef()->Index( pAmmoName ) == iAmmoType;
}
//--------------------------------------------------------------------------------------------------------
//
// Given a weapon ID, return its alias
//
const char *WeaponIDToAlias( int id )
{
if ( (id >= WEAPON_MAX) || (id < 0) )
return NULL;
return s_WeaponAliasInfo[id];
}
// ----------------------------------------------------------------------------- //
// CWeaponDODBase tables.
// ----------------------------------------------------------------------------- //
IMPLEMENT_NETWORKCLASS_ALIASED( WeaponDODBase, DT_WeaponDODBase )
BEGIN_NETWORK_TABLE( CWeaponDODBase, DT_WeaponDODBase )
#ifdef CLIENT_DLL
RecvPropInt( RECVINFO(m_iReloadModelIndex) ),
RecvPropVector( RECVINFO( m_vInitialDropVelocity ) ),
RecvPropTime( RECVINFO( m_flSmackTime ) )
#else
SendPropVector( SENDINFO( m_vInitialDropVelocity ),
20, // nbits
0, // flags
-3000, // low value
3000 // high value
),
SendPropModelIndex( SENDINFO(m_iReloadModelIndex) ),
SendPropTime( SENDINFO( m_flSmackTime ) )
#endif
END_NETWORK_TABLE()
LINK_ENTITY_TO_CLASS( weapon_dod_base, CWeaponDODBase );
#ifdef GAME_DLL
BEGIN_DATADESC( CWeaponDODBase )
DEFINE_FUNCTION( FallThink ),
DEFINE_FUNCTION( Die ),
DEFINE_FUNCTION( Smack )
END_DATADESC()
#else
BEGIN_PREDICTION_DATA( CWeaponDODBase )
DEFINE_PRED_FIELD( m_flSmackTime, FIELD_FLOAT, FTYPEDESC_INSENDTABLE ), // for rifle melee attacks
DEFINE_FIELD( m_bInAttack, FIELD_BOOLEAN )
END_PREDICTION_DATA()
#endif
Vector head_hull_mins( -16, -16, -18 );
Vector head_hull_maxs( 16, 16, 18 );
void FindHullIntersection( const Vector &vecSrc, trace_t &tr, const Vector &mins, const Vector &maxs, CBaseEntity *pEntity )
{
int i, j, k;
float distance;
Vector minmaxs[2] = {mins, maxs};
trace_t tmpTrace;
Vector vecHullEnd = tr.endpos;
Vector vecEnd;
CTraceFilterSimple filter( pEntity, COLLISION_GROUP_NONE );
distance = 1e6f;
vecHullEnd = vecSrc + ((vecHullEnd - vecSrc)*2);
UTIL_TraceLine( vecSrc, vecHullEnd, MASK_SOLID, &filter, &tmpTrace );
if ( tmpTrace.fraction < 1.0 )
{
tr = tmpTrace;
return;
}
for ( i = 0; i < 2; i++ )
{
for ( j = 0; j < 2; j++ )
{
for ( k = 0; k < 2; k++ )
{
vecEnd.x = vecHullEnd.x + minmaxs[i][0];
vecEnd.y = vecHullEnd.y + minmaxs[j][1];
vecEnd.z = vecHullEnd.z + minmaxs[k][2];
UTIL_TraceLine( vecSrc, vecEnd, MASK_SOLID, &filter, &tmpTrace );
if ( tmpTrace.fraction < 1.0 )
{
float thisDistance = (tmpTrace.endpos - vecSrc).Length();
if ( thisDistance < distance )
{
tr = tmpTrace;
distance = thisDistance;
}
}
}
}
}
}
// ----------------------------------------------------------------------------- //
// CWeaponDODBase implementation.
// ----------------------------------------------------------------------------- //
CWeaponDODBase::CWeaponDODBase()
{
SetPredictionEligible( true );
m_bInAttack = false;
m_iAltFireHint = 0;
AddSolidFlags( FSOLID_TRIGGER ); // Nothing collides with these but it gets touches.
m_flNextPrimaryAttack = 0;
}
bool CWeaponDODBase::IsPredicted() const
{
return true;
}
bool CWeaponDODBase::PlayEmptySound()
{
CPASAttenuationFilter filter( this );
filter.UsePredictionRules();
EmitSound( filter, entindex(), "Default.ClipEmpty_Rifle" );
return false;
}
CBasePlayer* CWeaponDODBase::GetPlayerOwner() const
{
return dynamic_cast< CBasePlayer* >( GetOwner() );
}
CDODPlayer* CWeaponDODBase::GetDODPlayerOwner() const
{
return dynamic_cast< CDODPlayer* >( GetOwner() );
}
bool CWeaponDODBase::SendWeaponAnim( int iActivity )
{
return BaseClass::SendWeaponAnim( iActivity );
}
bool CWeaponDODBase::CanAttack( void )
{
CDODPlayer *pPlayer = ToDODPlayer( GetPlayerOwner() );
if ( pPlayer )
{
return pPlayer->CanAttack();
}
return false;
}
bool CWeaponDODBase::ShouldAutoReload( void )
{
CDODPlayer *pPlayer = ToDODPlayer( GetPlayerOwner() );
if ( pPlayer )
{
return pPlayer->ShouldAutoReload();
}
return false;
}
void CWeaponDODBase::ItemPostFrame()
{
if ( m_flSmackTime > 0 && gpGlobals->curtime > m_flSmackTime )
{
Smack();
m_flSmackTime = -1;
}
CBasePlayer *pPlayer = GetPlayerOwner();
if ( !pPlayer )
return;
#ifdef _DEBUG
CDODGameRules *mp = DODGameRules();
#endif
assert( mp );
if ((m_bInReload) && (pPlayer->m_flNextAttack <= gpGlobals->curtime))
{
// complete the reload.
int j = MIN( GetMaxClip1() - m_iClip1, pPlayer->GetAmmoCount( m_iPrimaryAmmoType ) );
// Add them to the clip
m_iClip1 += j;
pPlayer->RemoveAmmo( j, m_iPrimaryAmmoType );
m_bInReload = false;
FinishReload();
}
if ((pPlayer->m_nButtons & IN_ATTACK2) && (m_flNextSecondaryAttack <= gpGlobals->curtime))
{
if ( m_iClip2 != -1 && !pPlayer->GetAmmoCount( GetSecondaryAmmoType() ) )
{
m_bFireOnEmpty = TRUE;
}
SecondaryAttack();
pPlayer->m_nButtons &= ~IN_ATTACK2;
}
else if ((pPlayer->m_nButtons & IN_ATTACK) && (m_flNextPrimaryAttack <= gpGlobals->curtime ) && !m_bInAttack )
{
if ( (m_iClip1 == 0/* && pszAmmo1()*/) || (GetMaxClip1() == -1 && !pPlayer->GetAmmoCount( GetPrimaryAmmoType() ) ) )
{
m_bFireOnEmpty = TRUE;
}
if( CanAttack() )
PrimaryAttack();
}
else if ( pPlayer->m_nButtons & IN_RELOAD && GetMaxClip1() != WEAPON_NOCLIP && !m_bInReload && m_flNextPrimaryAttack < gpGlobals->curtime)
{
// reload when reload is pressed, or if no buttons are down and weapon is empty.
Reload();
}
else if ( !(pPlayer->m_nButtons & (IN_ATTACK|IN_ATTACK2) ) )
{
// no fire buttons down
m_bFireOnEmpty = false;
m_bInAttack = false; //reset semi-auto
if ( !IsUseable() && m_flNextPrimaryAttack < gpGlobals->curtime )
{
// Intentionally blank -- used to switch weapons here
}
else if( ShouldAutoReload() )
{
// weapon is useable. Reload if empty and weapon has waited as long as it has to after firing
if ( m_iClip1 == 0 && !(GetWeaponFlags() & ITEM_FLAG_NOAUTORELOAD) && m_flNextPrimaryAttack < gpGlobals->curtime )
{
Reload();
return;
}
}
WeaponIdle( );
return;
}
}
void CWeaponDODBase::WeaponIdle()
{
if (m_flTimeWeaponIdle > gpGlobals->curtime)
return;
SendWeaponAnim( GetIdleActivity() );
m_flTimeWeaponIdle = gpGlobals->curtime + SequenceDuration();
}
Activity CWeaponDODBase::GetIdleActivity( void )
{
return ACT_VM_IDLE;
}
const CDODWeaponInfo &CWeaponDODBase::GetDODWpnData() const
{
const FileWeaponInfo_t *pWeaponInfo = &GetWpnData();
const CDODWeaponInfo *pDODInfo;
#ifdef _DEBUG
pDODInfo = dynamic_cast< const CDODWeaponInfo* >( pWeaponInfo );
Assert( pDODInfo );
#else
pDODInfo = static_cast< const CDODWeaponInfo* >( pWeaponInfo );
#endif
return *pDODInfo;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
const char *CWeaponDODBase::GetViewModel( int /*viewmodelindex = 0 -- this is ignored in the base class here*/ ) const
{
if ( GetPlayerOwner() == NULL )
{
return BaseClass::GetViewModel();
}
return GetWpnData().szViewModel;
}
void CWeaponDODBase::Precache( void )
{
// precache base first, it loads weapon scripts
BaseClass::Precache();
PrecacheScriptSound( "Default.ClipEmpty_Rifle" );
PrecacheParticleSystem( "muzzle_pistols" );
PrecacheParticleSystem( "muzzle_fullyautomatic" );
PrecacheParticleSystem( "muzzle_rifles" );
PrecacheParticleSystem( "muzzle_rockets" );
PrecacheParticleSystem( "muzzle_mg42" );
PrecacheParticleSystem( "view_muzzle_pistols" );
PrecacheParticleSystem( "view_muzzle_fullyautomatic" );
PrecacheParticleSystem( "view_muzzle_rifles" );
PrecacheParticleSystem( "view_muzzle_rockets" );
PrecacheParticleSystem( "view_muzzle_mg42" );
const CDODWeaponInfo &info = GetDODWpnData();
int iWpnNameLen = Q_strlen(info.m_szReloadModel);
#ifdef DEBUG
// Make sure that if we declare an alt weapon, that we have criteria to show it
// and vice-versa
//Assert( ((info.m_iAltWpnCriteria & (ALTWPN_CRITERIA_RELOADING | ALTWPN_CRITERIA_FIRING)) > 0 ) ==
// (iWpnNameLen > 0) );
#endif
if( iWpnNameLen > 0 )
m_iReloadModelIndex = CBaseEntity::PrecacheModel( info.m_szReloadModel );
}
bool CWeaponDODBase::DefaultDeploy( char *szViewModel, char *szWeaponModel, int iActivity, char *szAnimExt )
{
CBasePlayer *pOwner = GetPlayerOwner();
if ( !pOwner )
{
return false;
}
pOwner->SetAnimationExtension( szAnimExt );
SetViewModel();
SendWeaponAnim( iActivity );
pOwner->SetNextAttack( gpGlobals->curtime + SequenceDuration() );
m_flNextPrimaryAttack = MAX( m_flNextPrimaryAttack, gpGlobals->curtime );
m_flNextSecondaryAttack = gpGlobals->curtime;
SetWeaponVisible( true );
SetWeaponModelIndex( szWeaponModel );
CBaseViewModel *vm = pOwner->GetViewModel( m_nViewModelIndex );
Assert( vm );
if( vm )
{
//set sleeves to proper team
switch( pOwner->GetTeamNumber() )
{
case TEAM_ALLIES:
vm->m_nSkin = SLEEVE_ALLIES;
break;
case TEAM_AXIS:
vm->m_nSkin = SLEEVE_AXIS;
break;
default:
Assert( !"TEAM_UNASSIGNED or spectator getting a view model assigned" );
break;
}
}
return true;
}
void CWeaponDODBase::SetWeaponModelIndex( const char *pName )
{
m_iWorldModelIndex = modelinfo->GetModelIndex( pName );
}
bool CWeaponDODBase::CanBeSelected( void )
{
if ( !VisibleInWeaponSelection() )
return false;
return true;
}
bool CWeaponDODBase::CanDeploy( void )
{
return BaseClass::CanDeploy();
}
bool CWeaponDODBase::CanHolster( void )
{
return BaseClass::CanHolster();
}
void CWeaponDODBase::Drop( const Vector &vecVelocity )
{
#ifndef CLIENT_DLL
if ( m_iAltFireHint )
{
CDODPlayer *pPlayer = GetDODPlayerOwner();
if ( pPlayer )
{
pPlayer->StopHintTimer( m_iAltFireHint );
}
}
#endif
// cancel any reload in progress
m_bInReload = false;
m_flSmackTime = -1;
m_vInitialDropVelocity = vecVelocity;
BaseClass::Drop( m_vInitialDropVelocity );
}
bool CWeaponDODBase::Holster( CBaseCombatWeapon *pSwitchingTo )
{
#ifndef CLIENT_DLL
CDODPlayer *pPlayer = GetDODPlayerOwner();
if ( pPlayer )
{
pPlayer->SetFOV( pPlayer, 0 ); // reset the default FOV.
if ( m_iAltFireHint )
{
pPlayer->StopHintTimer( m_iAltFireHint );
}
}
#endif
m_bInReload = false;
m_flSmackTime = -1;
return BaseClass::Holster( pSwitchingTo );
}
bool CWeaponDODBase::Deploy()
{
#ifndef CLIENT_DLL
CDODPlayer *pPlayer = GetDODPlayerOwner();
if ( pPlayer )
{
pPlayer->SetFOV( pPlayer, 0 );
if ( m_iAltFireHint )
{
pPlayer->StartHintTimer( m_iAltFireHint );
}
}
#endif
return BaseClass::Deploy();
}
#ifdef CLIENT_DLL
void CWeaponDODBase::PostDataUpdate( DataUpdateType_t updateType )
{
// We need to do this before the C_BaseAnimating code starts to drive
// clientside animation sequences on this model, which will be using bad sequences for the world model.
int iDesiredModelIndex = 0;
C_BasePlayer *localplayer = C_BasePlayer::GetLocalPlayer();
if ( localplayer && localplayer == GetOwner() && !C_BasePlayer::ShouldDrawLocalPlayer() ) // FIXME: use localplayer->ShouldDrawThisPlayer() instead.
{
iDesiredModelIndex = m_iViewModelIndex;
}
else
{
iDesiredModelIndex = GetWorldModelIndex();
// Our world models never animate
SetSequence( 0 );
}
if ( GetModelIndex() != iDesiredModelIndex )
{
SetModelIndex( iDesiredModelIndex );
}
BaseClass::PostDataUpdate( updateType );
}
void CWeaponDODBase::OnDataChanged( DataUpdateType_t type )
{
if ( m_iState == WEAPON_NOT_CARRIED && m_iOldState != WEAPON_NOT_CARRIED )
{
// we are being notified of the weapon being dropped
// add an interpolation history so the movement is smoother
// Now stick our initial velocity into the interpolation history
CInterpolatedVar< Vector > &interpolator = GetOriginInterpolator();
interpolator.ClearHistory();
float changeTime = GetLastChangeTime( LATCH_SIMULATION_VAR );
// Add a sample 1 second back.
Vector vCurOrigin = GetLocalOrigin() - m_vInitialDropVelocity;
interpolator.AddToHead( changeTime - 1.0, &vCurOrigin, false );
// Add the current sample.
vCurOrigin = GetLocalOrigin();
interpolator.AddToHead( changeTime, &vCurOrigin, false );
Vector estVel;
EstimateAbsVelocity( estVel );
/*Msg( "estimated velocity ( %.1f %.1f %.1f ) initial velocity ( %.1f %.1f %.1f )\n",
estVel.x,
estVel.y,
estVel.z,
m_vInitialDropVelocity.m_Value.x,
m_vInitialDropVelocity.m_Value.y,
m_vInitialDropVelocity.m_Value.z );*/
OnWeaponDropped();
}
BaseClass::OnDataChanged( type );
if ( GetPredictable() && !ShouldPredict() )
ShutdownPredictable();
}
int CWeaponDODBase::GetWorldModelIndex( void )
{
if( m_bUseAltWeaponModel && GetOwner() != NULL )
return m_iReloadModelIndex;
else
return m_iWorldModelIndex;
}
bool CWeaponDODBase::ShouldPredict()
{
if ( GetOwner() && GetOwner() == C_BasePlayer::GetLocalPlayer() )
return true;
return BaseClass::ShouldPredict();
}
void CWeaponDODBase::ProcessMuzzleFlashEvent()
{
CDODPlayer *pPlayer = GetDODPlayerOwner();
if ( pPlayer )
pPlayer->ProcessMuzzleFlashEvent();
BaseClass::ProcessMuzzleFlashEvent();
}
#else
//-----------------------------------------------------------------------------
// Purpose: Get the accuracy derived from weapon and player, and return it
//-----------------------------------------------------------------------------
const Vector& CWeaponDODBase::GetBulletSpread()
{
static Vector cone = VECTOR_CONE_8DEGREES;
return cone;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CWeaponDODBase::ItemBusyFrame()
{
if( ShouldAutoReload() && !m_bInReload )
{
// weapon is useable. Reload if empty and weapon has waited as long as it has to after firing
if ( m_iClip1 == 0 && !(GetWeaponFlags() & ITEM_FLAG_NOAUTORELOAD) && m_flNextPrimaryAttack < gpGlobals->curtime )
{
Reload();
}
}
BaseClass::ItemBusyFrame();
}
//-----------------------------------------------------------------------------
// Purpose: Match the anim speed to the weapon speed while crouching
//-----------------------------------------------------------------------------
float CWeaponDODBase::GetDefaultAnimSpeed()
{
return 1.0;
}
bool CWeaponDODBase::ShouldRemoveOnRoundRestart()
{
if ( GetPlayerOwner() )
return false;
else
return true;
}
//=========================================================
// Materialize - make a CWeaponDODBase visible and tangible
//=========================================================
void CWeaponDODBase::Materialize()
{
if ( IsEffectActive( EF_NODRAW ) )
{
RemoveEffects( EF_NODRAW );
DoMuzzleFlash();
}
AddSolidFlags( FSOLID_TRIGGER );
SetThink (&CWeaponDODBase::SUB_Remove);
SetNextThink( gpGlobals->curtime + 1 );
}
//=========================================================
// AttemptToMaterialize - the item is trying to rematerialize,
// should it do so now or wait longer?
//=========================================================
void CWeaponDODBase::AttemptToMaterialize()
{
float time = g_pGameRules->FlWeaponTryRespawn( this );
if ( time == 0 )
{
Materialize();
return;
}
SetNextThink( gpGlobals->curtime + time );
}
//=========================================================
// CheckRespawn - a player is taking this weapon, should
// it respawn?
//=========================================================
void CWeaponDODBase::CheckRespawn()
{
//GOOSEMAN : Do not respawn weapons!
return;
}
//=========================================================
// Respawn- this item is already in the world, but it is
// invisible and intangible. Make it visible and tangible.
//=========================================================
CBaseEntity* CWeaponDODBase::Respawn()
{
// make a copy of this weapon that is invisible and inaccessible to players (no touch function). The weapon spawn/respawn code
// will decide when to make the weapon visible and touchable.
CBaseEntity *pNewWeapon = CBaseEntity::Create( GetClassname(), g_pGameRules->VecWeaponRespawnSpot( this ), GetAbsAngles(), GetOwner() );
if ( pNewWeapon )
{
pNewWeapon->AddEffects( EF_NODRAW );// invisible for now
pNewWeapon->SetTouch( NULL );// no touch
pNewWeapon->SetThink( &CWeaponDODBase::AttemptToMaterialize );
UTIL_DropToFloor( this, MASK_SOLID );
// not a typo! We want to know when the weapon the player just picked up should respawn! This new entity we created is the replacement,
// but when it should respawn is based on conditions belonging to the weapon that was taken.
pNewWeapon->SetNextThink( gpGlobals->curtime + g_pGameRules->FlWeaponRespawnTime( this ) );
}
else
{
Msg( "Respawn failed to create %s!\n", GetClassname() );
}
return pNewWeapon;
}
bool CWeaponDODBase::Reload()
{
return BaseClass::Reload();
}
void CWeaponDODBase::Spawn()
{
BaseClass::Spawn();
// Set this here to allow players to shoot dropped weapons
SetCollisionGroup( COLLISION_GROUP_WEAPON );
SetExtraAmmoCount(0); //Start with no additional ammo
CollisionProp()->UseTriggerBounds( true, 10.0f );
}
void CWeaponDODBase::SetDieThink( bool bDie )
{
if( bDie )
SetContextThink( &CWeaponDODBase::Die, gpGlobals->curtime + 45.0f, "DieContext" );
else
SetContextThink( NULL, gpGlobals->curtime, "DieContext" );
}
void CWeaponDODBase::Die( void )
{
UTIL_Remove( this );
}
#endif
void CWeaponDODBase::OnPickedUp( CBaseCombatCharacter *pNewOwner )
{
BaseClass::OnPickedUp( pNewOwner );
#if !defined( CLIENT_DLL )
SetDieThink( false );
#endif
}
bool CWeaponDODBase::DefaultReload( int iClipSize1, int iClipSize2, int iActivity )
{
CBaseCombatCharacter *pOwner = GetOwner();
if (!pOwner)
return false;
// If I don't have any spare ammo, I can't reload
if ( pOwner->GetAmmoCount(m_iPrimaryAmmoType) <= 0 )
return false;
bool bReload = false;
// If you don't have clips, then don't try to reload them.
if ( UsesClipsForAmmo1() )
{
// need to reload primary clip?
int primary = min(iClipSize1 - m_iClip1, pOwner->GetAmmoCount(m_iPrimaryAmmoType));
if ( primary != 0 )
{
bReload = true;
}
}
if ( UsesClipsForAmmo2() )
{
// need to reload secondary clip?
int secondary = min(iClipSize2 - m_iClip2, pOwner->GetAmmoCount(m_iSecondaryAmmoType));
if ( secondary != 0 )
{
bReload = true;
}
}
if ( !bReload )
return false;
CDODPlayer *pPlayer = GetDODPlayerOwner();
if ( pPlayer )
{
#ifdef CLIENT_DLL
PlayWorldReloadSound( pPlayer );
#else
pPlayer->DoAnimationEvent( PLAYERANIMEVENT_RELOAD );
#endif
}
SendWeaponAnim( iActivity );
// Play the player's reload animation
if ( pOwner->IsPlayer() )
{
( ( CBasePlayer * )pOwner)->SetAnimation( PLAYER_RELOAD );
}
float flSequenceEndTime = gpGlobals->curtime + SequenceDuration();
pOwner->SetNextAttack( flSequenceEndTime );
m_flNextPrimaryAttack = m_flNextSecondaryAttack = flSequenceEndTime;
m_bInReload = true;
return true;
}
#ifdef CLIENT_DLL
void CWeaponDODBase::PlayWorldReloadSound( CDODPlayer *pPlayer )
{
Assert( pPlayer );
const char *shootsound = GetShootSound( RELOAD );
if ( !shootsound || !shootsound[0] )
return;
CSoundParameters params;
if ( !GetParametersForSound( shootsound, params, NULL ) )
return;
// Play weapon sound from the owner
CPASAttenuationFilter filter( pPlayer, params.soundlevel );
filter.RemoveRecipient( pPlayer ); // no local player, that is done in the model
EmitSound( filter, pPlayer->entindex(), shootsound, NULL, 0.0 );
}
#endif
bool CWeaponDODBase::IsUseable()
{
CBasePlayer *pPlayer = GetPlayerOwner();
if ( Clip1() <= 0 )
{
if ( pPlayer->GetAmmoCount( GetPrimaryAmmoType() ) <= 0 && GetMaxClip1() != -1 )
{
// clip is empty (or nonexistant) and the player has no more ammo of this type.
return false;
}
}
return true;
}
#ifndef CLIENT_DLL
ConVar dod_meleeattackforcescale( "dod_meleeattackforcescale", "8.0", FCVAR_CHEAT | FCVAR_GAMEDLL );
#endif
void CWeaponDODBase::RifleButt( void )
{
//MeleeAttack( 60, MELEE_DMG_BUTTSTOCK | MELEE_DMG_SECONDARYATTACK, 0.2f, 0.9f );
}
void CWeaponDODBase::Bayonet( void )
{
//MeleeAttack( 60, MELEE_DMG_BAYONET | MELEE_DMG_SECONDARYATTACK, 0.2f, 0.9f );
}
void CWeaponDODBase::Punch( void )
{
MeleeAttack( 60, MELEE_DMG_FIST | MELEE_DMG_SECONDARYATTACK, 0.2f, 0.4f );
}
//--------------------------------------------
// iDamageAmount - how much damage to give
// iDamageType - DMG_ bits
// flDmgDelay - delay between attack and the giving of damage, usually timed to animation
// flAttackDelay - time until we can next attack
//--------------------------------------------
CBaseEntity *CWeaponDODBase::MeleeAttack( int iDamageAmount, int iDamageType, float flDmgDelay, float flAttackDelay )
{
if ( !CanAttack() )
return NULL;
CDODPlayer *pPlayer = ToDODPlayer( GetPlayerOwner() );
#if !defined (CLIENT_DLL)
// Move other players back to history positions based on local player's lag
lagcompensation->StartLagCompensation( pPlayer, pPlayer->GetCurrentCommand() );
#endif
Vector vForward, vRight, vUp;
AngleVectors( pPlayer->EyeAngles(), &vForward, &vRight, &vUp );
Vector vecSrc = pPlayer->Weapon_ShootPosition();
Vector vecEnd = vecSrc + vForward * 48;
CTraceFilterSimple filter( pPlayer, COLLISION_GROUP_NONE );
int iTraceMask = MASK_SOLID | CONTENTS_HITBOX | CONTENTS_DEBRIS;
trace_t tr;
UTIL_TraceLine( vecSrc, vecEnd, iTraceMask, &filter, &tr );
const float rayExtension = 40.0f;
UTIL_ClipTraceToPlayers( vecSrc, vecEnd + vForward * rayExtension, iTraceMask, &filter, &tr );
// If the exact forward trace did not hit, try a larger swept box
if ( tr.fraction >= 1.0 )
{
Vector head_hull_mins( -16, -16, -18 );
Vector head_hull_maxs( 16, 16, 18 );
UTIL_TraceHull( vecSrc, vecEnd, head_hull_mins, head_hull_maxs, MASK_SOLID, &filter, &tr );
if ( tr.fraction < 1.0 )
{
// Calculate the point of intersection of the line (or hull) and the object we hit
// This is and approximation of the "best" intersection
CBaseEntity *pHit = tr.m_pEnt;
if ( !pHit || pHit->IsBSPModel() )
FindHullIntersection( vecSrc, tr, VEC_DUCK_HULL_MIN, VEC_DUCK_HULL_MAX, pPlayer );
vecEnd = tr.endpos; // This is the point on the actual surface (the hull could have hit space)
// Make sure it is in front of us
Vector vecToEnd = vecEnd - vecSrc;
VectorNormalize( vecToEnd );
// if zero length, always hit
if ( vecToEnd.Length() > 0 )
{
float dot = DotProduct( vForward, vecToEnd );
// sanity that our hit is within range
if ( abs(dot) < 0.95 )
{
// fake that we actually missed
tr.fraction = 1.0;
}
}
}
}
WeaponSound( MELEE_MISS );
bool bDidHit = ( tr.fraction < 1.0f );
if ( bDidHit ) //if the swing hit
{
// delay the decal a bit
m_trHit = tr;
// Store the ent in an EHANDLE, just in case it goes away by the time we get into our think function.
m_pTraceHitEnt = tr.m_pEnt;
m_iSmackDamage = iDamageAmount;
m_iSmackDamageType = iDamageType;
m_flSmackTime = gpGlobals->curtime + flDmgDelay;
}
SendWeaponAnim( GetMeleeActivity() );
// player animation
pPlayer->DoAnimationEvent( PLAYERANIMEVENT_SECONDARY_ATTACK );
m_flNextPrimaryAttack = gpGlobals->curtime + flAttackDelay;
m_flNextSecondaryAttack = gpGlobals->curtime + flAttackDelay;
m_flTimeWeaponIdle = gpGlobals->curtime + SequenceDuration();
#ifndef CLIENT_DLL
IGameEvent * event = gameeventmanager->CreateEvent( "dod_stats_weapon_attack" );
if ( event )
{
event->SetInt( "attacker", pPlayer->GetUserID() );
event->SetInt( "weapon", GetAltWeaponID() );
gameeventmanager->FireEvent( event );
}
lagcompensation->FinishLagCompensation( pPlayer );
#endif //CLIENT_DLL
return tr.m_pEnt;
}
//Think function to delay the impact decal until the animation is finished playing
void CWeaponDODBase::Smack()
{
Assert( GetPlayerOwner() );
if ( !GetPlayerOwner() )
return;
CDODPlayer *pPlayer = ToDODPlayer( GetPlayerOwner() );
if ( !pPlayer )
return;
// Check that we are still facing the victim
Vector vForward, vRight, vUp;
AngleVectors( pPlayer->EyeAngles(), &vForward, &vRight, &vUp );
Vector vecSrc = pPlayer->Weapon_ShootPosition();
Vector vecEnd = vecSrc + vForward * 48;
CTraceFilterSimple filter( pPlayer, COLLISION_GROUP_NONE );
int iTraceMask = MASK_SOLID | CONTENTS_HITBOX | CONTENTS_DEBRIS;
trace_t tr;
UTIL_TraceLine( vecSrc, vecEnd, iTraceMask, &filter, &tr );
const float rayExtension = 40.0f;
UTIL_ClipTraceToPlayers( vecSrc, vecEnd + vForward * rayExtension, iTraceMask, &filter, &tr );
if ( tr.fraction >= 1.0 )
{
Vector head_hull_mins( -16, -16, -18 );
Vector head_hull_maxs( 16, 16, 18 );
UTIL_TraceHull( vecSrc, vecEnd, head_hull_mins, head_hull_maxs, MASK_SOLID, &filter, &tr );
if ( tr.fraction < 1.0 )
{
// Calculate the point of intersection of the line (or hull) and the object we hit
// This is and approximation of the "best" intersection
CBaseEntity *pHit = tr.m_pEnt;
if ( !pHit || pHit->IsBSPModel() )
FindHullIntersection( vecSrc, tr, VEC_DUCK_HULL_MIN, VEC_DUCK_HULL_MAX, pPlayer );
vecEnd = tr.endpos; // This is the point on the actual surface (the hull could have hit space)
}
}
m_trHit = tr;
if ( !m_trHit.m_pEnt || (m_trHit.surface.flags & SURF_SKY) )
return;
if ( m_trHit.fraction == 1.0 )
return;
CPASAttenuationFilter attenuationFilter( this );
attenuationFilter.UsePredictionRules();
if( m_trHit.m_pEnt->IsPlayer() )
{
if ( m_iSmackDamageType & MELEE_DMG_STRONGATTACK )
WeaponSound( SPECIAL1 );
else
WeaponSound( MELEE_HIT );
}
else
WeaponSound( MELEE_HIT_WORLD );
int iDamageType = DMG_CLUB | DMG_NEVERGIB;
#ifndef CLIENT_DLL
//if they hit the bounding box, just assume a chest hit
if( m_trHit.hitgroup == HITGROUP_GENERIC )
m_trHit.hitgroup = HITGROUP_CHEST;
float flDamage = (float)m_iSmackDamage;
CTakeDamageInfo info( pPlayer, pPlayer, flDamage, iDamageType );
if ( m_iSmackDamageType & MELEE_DMG_SECONDARYATTACK )
info.SetDamageCustom( MELEE_DMG_SECONDARYATTACK );
float flScale = (1.0f / flDamage) * dod_meleeattackforcescale.GetFloat();
Vector vecForceDir = vForward;
CalculateMeleeDamageForce( &info, vecForceDir, m_trHit.endpos, flScale );
Assert( m_trHit.m_pEnt != GetPlayerOwner() );
m_trHit.m_pEnt->DispatchTraceAttack( info, vForward, &m_trHit );
ApplyMultiDamage();
#endif
// We've gotten minidumps where this happened.
if ( !GetPlayerOwner() )
return;
CEffectData data;
data.m_vOrigin = m_trHit.endpos;
data.m_vStart = m_trHit.startpos;
data.m_nSurfaceProp = m_trHit.surface.surfaceProps;
data.m_nHitBox = m_trHit.hitbox;
#ifdef CLIENT_DLL
data.m_hEntity = m_trHit.m_pEnt->GetRefEHandle();
#else
data.m_nEntIndex = m_trHit.m_pEnt->entindex();
#endif
CPASFilter effectfilter( data.m_vOrigin );
#ifndef CLIENT_DLL
effectfilter.RemoveRecipient( GetPlayerOwner() );
#endif
data.m_vAngles = GetPlayerOwner()->GetAbsAngles();
data.m_fFlags = 0x1; //IMPACT_NODECAL;
data.m_nDamageType = iDamageType;
bool bHitPlayer = m_trHit.m_pEnt && m_trHit.m_pEnt->IsPlayer();
// don't do any impacts if we hit a teammate and ff is off
if ( bHitPlayer &&
m_trHit.m_pEnt->GetTeamNumber() == GetPlayerOwner()->GetTeamNumber() &&
!friendlyfire.GetBool() )
return;
if ( bHitPlayer )
{
te->DispatchEffect( effectfilter, 0.0, data.m_vOrigin, "Impact", data );
}
else if ( m_iSmackDamageType & MELEE_DMG_EDGE )
{
data.m_nDamageType = DMG_SLASH;
te->DispatchEffect( effectfilter, 0.0, data.m_vOrigin, "KnifeSlash", data );
}
}
#if defined( CLIENT_DLL )
float g_lateralBob = 0;
float g_verticalBob = 0;
static ConVar cl_bobcycle( "cl_bobcycle","0.8" );
static ConVar cl_bob( "cl_bob","0.002" );
static ConVar cl_bobup( "cl_bobup","0.5" );
// Register these cvars if needed for easy tweaking
static ConVar v_iyaw_cycle( "v_iyaw_cycle", "2"/*, FCVAR_UNREGISTERED*/ );
static ConVar v_iroll_cycle( "v_iroll_cycle", "0.5"/*, FCVAR_UNREGISTERED*/ );
static ConVar v_ipitch_cycle( "v_ipitch_cycle", "1"/*, FCVAR_UNREGISTERED*/ );
static ConVar v_iyaw_level( "v_iyaw_level", "0.3"/*, FCVAR_UNREGISTERED*/ );
static ConVar v_iroll_level( "v_iroll_level", "0.1"/*, FCVAR_UNREGISTERED*/ );
static ConVar v_ipitch_level( "v_ipitch_level", "0.3"/*, FCVAR_UNREGISTERED*/ );
//-----------------------------------------------------------------------------
// Purpose:
// Output : float
//-----------------------------------------------------------------------------
float CWeaponDODBase::CalcViewmodelBob( void )
{
static float bobtime;
static float lastbobtime;
static float lastspeed;
float cycle;
CBasePlayer *player = ToBasePlayer( GetOwner() );
//Assert( player );
//NOTENOTE: For now, let this cycle continue when in the air, because it snaps badly without it
if ( ( !gpGlobals->frametime ) || ( player == NULL ) )
{
//NOTENOTE: We don't use this return value in our case (need to restructure the calculation function setup!)
return 0.0f;// just use old value
}
//Find the speed of the player
float speed = player->GetLocalVelocity().Length2D();
float flmaxSpeedDelta = MAX( 0, (gpGlobals->curtime - lastbobtime) * 320.0f );
// don't allow too big speed changes
speed = clamp( speed, lastspeed-flmaxSpeedDelta, lastspeed+flmaxSpeedDelta );
speed = clamp( speed, -320, 320 );
lastspeed = speed;
//FIXME: This maximum speed value must come from the server.
// MaxSpeed() is not sufficient for dealing with sprinting - jdw
float bob_offset = RemapVal( speed, 0, 320, 0.0f, 1.0f );
bobtime += ( gpGlobals->curtime - lastbobtime ) * bob_offset;
lastbobtime = gpGlobals->curtime;
//Calculate the vertical bob
cycle = bobtime - (int)(bobtime/cl_bobcycle.GetFloat())*cl_bobcycle.GetFloat();
cycle /= cl_bobcycle.GetFloat();
if ( cycle < cl_bobup.GetFloat() )
{
cycle = M_PI * cycle / cl_bobup.GetFloat();
}
else
{
cycle = M_PI + M_PI*(cycle-cl_bobup.GetFloat())/(1.0 - cl_bobup.GetFloat());
}
g_verticalBob = speed*0.005f;
g_verticalBob = g_verticalBob*0.3 + g_verticalBob*0.7*sin(cycle);
g_verticalBob = clamp( g_verticalBob, -7.0f, 4.0f );
//Calculate the lateral bob
cycle = bobtime - (int)(bobtime/cl_bobcycle.GetFloat()*2)*cl_bobcycle.GetFloat()*2;
cycle /= cl_bobcycle.GetFloat()*2;
if ( cycle < cl_bobup.GetFloat() )
{
cycle = M_PI * cycle / cl_bobup.GetFloat();
}
else
{
cycle = M_PI + M_PI*(cycle-cl_bobup.GetFloat())/(1.0 - cl_bobup.GetFloat());
}
g_lateralBob = speed*0.005f;
g_lateralBob = g_lateralBob*0.3 + g_lateralBob*0.7*sin(cycle);
g_lateralBob = clamp( g_lateralBob, -7.0f, 4.0f );
//NOTENOTE: We don't use this return value in our case (need to restructure the calculation function setup!)
return 0.0f;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : &origin -
// &angles -
// viewmodelindex -
//-----------------------------------------------------------------------------
void CWeaponDODBase::AddViewmodelBob( CBaseViewModel *viewmodel, Vector &origin, QAngle &angles )
{
Vector forward, right;
AngleVectors( angles, &forward, &right, NULL );
CalcViewmodelBob();
// Apply bob, but scaled down to 40%
VectorMA( origin, g_verticalBob * 0.4f, forward, origin );
// Z bob a bit more
origin[2] += g_verticalBob * 0.1f;
// bob the angles
angles[ ROLL ] += g_verticalBob * 0.5f;
angles[ PITCH ] -= g_verticalBob * 0.4f;
angles[ YAW ] -= g_lateralBob * 0.3f;
// VectorMA( origin, g_lateralBob * 0.2f, right, origin );
}
#include "c_te_effect_dispatch.h"
#define NUM_MUZZLE_FLASH_TYPES 4
bool CWeaponDODBase::OnFireEvent( C_BaseViewModel *pViewModel, const Vector& origin, const QAngle& angles, int event, const char *options )
{
if( event == 5001 )
{
if ( ShouldDrawMuzzleFlash() )
{
Assert( GetOwnerEntity() == C_BasePlayer::GetLocalPlayer() );
const char *pszMuzzleFlashEffect;
switch( GetDODWpnData().m_iMuzzleFlashType )
{
case DOD_MUZZLEFLASH_PISTOL:
pszMuzzleFlashEffect = "view_muzzle_pistols";
break;
case DOD_MUZZLEFLASH_AUTO:
pszMuzzleFlashEffect = "view_muzzle_fullyautomatic";
break;
case DOD_MUZZLEFLASH_RIFLE:
pszMuzzleFlashEffect = "view_muzzle_rifles";
break;
case DOD_MUZZLEFLASH_MG:
pszMuzzleFlashEffect = "view_muzzle_miniguns";
break;
case DOD_MUZZLEFLASH_ROCKET:
pszMuzzleFlashEffect = "view_muzzle_rockets";
break;
case DOD_MUZZLEFLASH_MG42:
pszMuzzleFlashEffect = "view_muzzle_mg42";
break;
default:
pszMuzzleFlashEffect = NULL;
break;
}
if ( pszMuzzleFlashEffect )
{
pViewModel->ParticleProp()->Create( pszMuzzleFlashEffect, PATTACH_POINT_FOLLOW, 1 );
}
}
return true;
}
else if( event == 6002 )
{
CEffectData data;
data.m_nHitBox = atoi( options );
data.m_hEntity = GetPlayerOwner() ? GetPlayerOwner()->GetRefEHandle() : INVALID_EHANDLE_INDEX;
pViewModel->GetAttachment( 2, data.m_vOrigin, data.m_vAngles );
DispatchEffect( "DOD_EjectBrass", data );
return true;
}
return BaseClass::OnFireEvent( pViewModel, origin, angles, event, options );
}
bool CWeaponDODBase::ShouldAutoEjectBrass( void )
{
// Don't eject brass if further than N units from the local player
C_BasePlayer *pLocalPlayer = C_BasePlayer::GetLocalPlayer();
if ( !pLocalPlayer )
return true;
float flMaxDistSqr = 250;
flMaxDistSqr *= flMaxDistSqr;
float flDistSqr = pLocalPlayer->EyePosition().DistToSqr( GetAbsOrigin() );
return ( flDistSqr < flMaxDistSqr );
}
bool CWeaponDODBase::GetEjectBrassShellType( void )
{
return 1;
}
void CWeaponDODBase::SetUseAltModel( bool bUseAltModel )
{
m_bUseAltWeaponModel = bUseAltModel;
}
void CWeaponDODBase::CheckForAltWeapon( int iCurrentState )
{
int iCriteria = GetDODWpnData().m_iAltWpnCriteria;
bool bUseAltModel = false;
if( ( iCriteria & iCurrentState ) != 0 )
bUseAltModel = true;
SetUseAltModel( bUseAltModel );
}
Vector CWeaponDODBase::GetDesiredViewModelOffset( C_DODPlayer *pOwner )
{
Vector viewOffset = pOwner->GetViewOffset();
float flPercent = ( viewOffset.z - VEC_PRONE_VIEW_SCALED( pOwner ).z ) / ( VEC_VIEW_SCALED( pOwner ).z - VEC_PRONE_VIEW_SCALED( pOwner ).z );
return ( flPercent * GetDODWpnData().m_vecViewNormalOffset +
( 1.0 - flPercent ) * GetDODWpnData().m_vecViewProneOffset );
}
bool CWeaponDODBase::ShouldDraw( void )
{
if ( GetModel() == NULL )
{
// XXX(johns): Removed, doesn't seem to be the proper spot for this warning given that weapons can call
// ShouldDraw before their properties are filled.
// C_DODPlayer *pPlayer = C_DODPlayer::GetLocalDODPlayer();
// Warning( "BADNESS! Tell Matt that the weapon '%s' tried to draw with a null model ( %d, %d, %s ) \n",
// GetDODWpnData().szClassName,
// m_iWorldModelIndex.Get(), m_iReloadModelIndex.Get(), m_bUseAltWeaponModel ? "alt" : "not alt" );
return false;
}
return BaseClass::ShouldDraw();
}
#else
void CWeaponDODBase::AddViewmodelBob( CBaseViewModel *viewmodel, Vector &origin, QAngle &angles )
{
}
float CWeaponDODBase::CalcViewmodelBob( void )
{
return 0.0f;
}
void CWeaponDODBase::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
{
if ( CanDrop() == false )
return;
CDODPlayer *pPlayer = ToDODPlayer( pActivator );
if ( pPlayer )
{
pPlayer->PickUpWeapon( this );
}
}
#endif
|