-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathasw_weapon_pdw_shared.cpp
More file actions
387 lines (323 loc) · 11 KB
/
asw_weapon_pdw_shared.cpp
File metadata and controls
387 lines (323 loc) · 11 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
#include "cbase.h"
#include "asw_weapon_pdw_shared.h"
#include "in_buttons.h"
#ifdef CLIENT_DLL
#include "c_asw_player.h"
#include "c_asw_weapon.h"
#include "c_asw_marine.h"
#include "c_te_legacytempents.h"
#include "c_breakableprop.h"
#include "fx.h"
#include "c_asw_fx.h"
#define CASW_Marine C_ASW_Marine
#define CASW_Inhabitable_NPC C_ASW_Inhabitable_NPC
#else
#include "asw_lag_compensation.h"
#include "asw_marine.h"
#include "asw_player.h"
#include "asw_weapon.h"
#include "asw_marine_resource.h"
#include "npcevent.h"
#include "shot_manipulator.h"
#include "asw_marine_speech.h"
#include "asw_weapon_ammo_bag_shared.h"
#include "asw_gamerules.h"
#endif
#include "asw_marine_skills.h"
#include "asw_weapon_parse.h"
#include "asw_deathmatch_mode_light.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
IMPLEMENT_NETWORKCLASS_ALIASED( ASW_Weapon_PDW, DT_ASW_Weapon_PDW )
BEGIN_NETWORK_TABLE( CASW_Weapon_PDW, DT_ASW_Weapon_PDW )
#ifdef CLIENT_DLL
// recvprops
RecvPropBool( RECVINFO( m_bIsSingle ) ),
#else
// sendprops
SendPropBool( SENDINFO( m_bIsSingle ) ),
#endif
END_NETWORK_TABLE()
BEGIN_PREDICTION_DATA( CASW_Weapon_PDW )
END_PREDICTION_DATA()
LINK_ENTITY_TO_CLASS( asw_weapon_pdw, CASW_Weapon_PDW );
#ifndef CLIENT_DLL
LINK_ENTITY_TO_CLASS( asw_weapon_pdw_single, CASW_Weapon_PDW );
#endif
PRECACHE_WEAPON_REGISTER( asw_weapon_pdw );
ConVar asw_pdw_max_shooting_distance( "asw_pdw_max_shooting_distance", "400", FCVAR_CHEAT | FCVAR_REPLICATED, "Maximum distance of the hitscan weapons." );
extern ConVar asw_weapon_max_shooting_distance;
extern ConVar asw_weapon_force_scale;
#ifndef CLIENT_DLL
ConVar sk_npc_dmg_smg1( "sk_npc_dmg_smg1", "3", FCVAR_CHEAT );
#endif
CASW_Weapon_PDW::CASW_Weapon_PDW()
{
}
CASW_Weapon_PDW::~CASW_Weapon_PDW()
{
}
#ifndef CLIENT_DLL
extern ConVar asw_debug_marine_damage;
//---------------------------------------------------------
// Save/Restore
//---------------------------------------------------------
BEGIN_DATADESC( CASW_Weapon_PDW )
END_DATADESC()
acttable_t CASW_Weapon_PDW::m_acttable[] =
{
{ ACT_RANGE_ATTACK1, ACT_RANGE_ATTACK_SMG1, true },
{ ACT_RELOAD, ACT_RELOAD_SMG1, true },
{ ACT_IDLE, ACT_IDLE_SMG1, true },
{ ACT_IDLE_ANGRY, ACT_IDLE_ANGRY_SMG1, true },
{ ACT_WALK, ACT_WALK_RIFLE, true },
{ ACT_WALK_AIM, ACT_WALK_AIM_RIFLE, true },
// Readiness activities (not aiming)
{ ACT_IDLE_RELAXED, ACT_IDLE_SMG1_RELAXED, false },//never aims
{ ACT_IDLE_STIMULATED, ACT_IDLE_SMG1_STIMULATED, false },
{ ACT_IDLE_AGITATED, ACT_IDLE_ANGRY_SMG1, false },//always aims
{ ACT_WALK_RELAXED, ACT_WALK_RIFLE_RELAXED, false },//never aims
{ ACT_WALK_STIMULATED, ACT_WALK_RIFLE_STIMULATED, false },
{ ACT_WALK_AGITATED, ACT_WALK_AIM_RIFLE, false },//always aims
{ ACT_RUN_RELAXED, ACT_RUN_RIFLE_RELAXED, false },//never aims
{ ACT_RUN_STIMULATED, ACT_RUN_RIFLE_STIMULATED, false },
{ ACT_RUN_AGITATED, ACT_RUN_AIM_RIFLE, false },//always aims
// Readiness activities (aiming)
{ ACT_IDLE_AIM_RELAXED, ACT_IDLE_SMG1_RELAXED, false },//never aims
{ ACT_IDLE_AIM_STIMULATED, ACT_IDLE_AIM_RIFLE_STIMULATED, false },
{ ACT_IDLE_AIM_AGITATED, ACT_IDLE_ANGRY_SMG1, false },//always aims
{ ACT_WALK_AIM_RELAXED, ACT_WALK_RIFLE_RELAXED, false },//never aims
{ ACT_WALK_AIM_STIMULATED, ACT_WALK_AIM_RIFLE_STIMULATED, false },
{ ACT_WALK_AIM_AGITATED, ACT_WALK_AIM_RIFLE, false },//always aims
{ ACT_RUN_AIM_RELAXED, ACT_RUN_RIFLE_RELAXED, false },//never aims
{ ACT_RUN_AIM_STIMULATED, ACT_RUN_AIM_RIFLE_STIMULATED, false },
{ ACT_RUN_AIM_AGITATED, ACT_RUN_AIM_RIFLE, false },//always aims
//End readiness activities
{ ACT_WALK_AIM, ACT_WALK_AIM_RIFLE, true },
{ ACT_WALK_CROUCH, ACT_WALK_CROUCH_RIFLE, true },
{ ACT_WALK_CROUCH_AIM, ACT_WALK_CROUCH_AIM_RIFLE, true },
{ ACT_RUN, ACT_RUN_RIFLE, true },
{ ACT_RUN_AIM, ACT_RUN_AIM_RIFLE, true },
{ ACT_RUN_CROUCH, ACT_RUN_CROUCH_RIFLE, true },
{ ACT_RUN_CROUCH_AIM, ACT_RUN_CROUCH_AIM_RIFLE, true },
{ ACT_GESTURE_RANGE_ATTACK1, ACT_GESTURE_RANGE_ATTACK_SMG1, true },
{ ACT_RANGE_ATTACK1_LOW, ACT_RANGE_ATTACK_SMG1_LOW, true },
{ ACT_COVER_LOW, ACT_COVER_SMG1_LOW, false },
{ ACT_RANGE_AIM_LOW, ACT_RANGE_AIM_SMG1_LOW, false },
{ ACT_RELOAD_LOW, ACT_RELOAD_SMG1_LOW, false },
{ ACT_GESTURE_RELOAD, ACT_GESTURE_RELOAD_SMG1, true },
};
IMPLEMENT_ACTTABLE( CASW_Weapon_PDW );
// just dry fire by default
void CASW_Weapon_PDW::SecondaryAttack( void )
{
// Only the player fires this way so we can cast
CASW_Player *pPlayer = GetCommander();
if (!pPlayer)
return;
CASW_Marine *pMarine = GetMarine();
if (!pMarine)
return;
SendWeaponAnim( ACT_VM_DRYFIRE );
BaseClass::WeaponSound( EMPTY );
m_flNextSecondaryAttack = gpGlobals->curtime + 0.5f;
}
#endif /* not client */
void CASW_Weapon_PDW::Precache()
{
PrecacheScriptSound( "ASW_Weapon_PDW.ReloadA" );
PrecacheScriptSound( "ASW_Weapon_PDW.ReloadB" );
PrecacheScriptSound( "ASW_Weapon_PDW.ReloadC" );
#ifndef CLIENT_DLL
m_bIsSingle = false;
if ( ClassMatches( "asw_weapon_pdw_single" ) )
{
m_bIsSingle = true;
PrecacheModel( "models/weapons/pdw/pdw_single.mdl" );
// swap the entity class so we get the weapon script that exists
SetClassname( "asw_weapon_pdw" );
}
#endif
BaseClass::Precache();
}
const Vector& CASW_Weapon_PDW::GetBulletSpread( void )
{
static const Vector cone = VECTOR_CONE_3DEGREES;
static const Vector cone_duck = VECTOR_CONE_1DEGREES;
CASW_Marine* marine = GetMarine();
if ( marine )
{
if ( marine->GetLocalVelocity().IsZero() && marine->m_bWalking )
return cone_duck;
}
return cone;
}
void CASW_Weapon_PDW::PrimaryAttack()
{
// If my clip is empty (and I use clips) start reload
if ( UsesClipsForAmmo1() && !m_iClip1 )
{
Reload();
return;
}
CASW_Player *pPlayer = GetCommander();
CBaseCombatCharacter *pOwner = GetOwner();
CASW_Inhabitable_NPC *pNPC = pOwner && pOwner->IsInhabitableNPC() ? assert_cast< CASW_Inhabitable_NPC * >( pOwner ) : NULL;
if ( pNPC )
{
m_bIsFiring = true;
// MUST call sound before removing a round from the clip of a CMachineGun
WeaponSound( SINGLE );
if ( m_iClip1 <= AmmoClickPoint() )
{
LowAmmoSound();
}
// tell the marine to tell its weapon to draw the muzzle flash
pNPC->DoMuzzleFlash();
// sets the animation on the weapon model iteself
SendWeaponAnim( GetPrimaryAttackActivity() );
// sets the animation on the marine holding this weapon
//pMarine->SetAnimation( PLAYER_ATTACK1 );
#ifdef GAME_DLL // check for turning on lag compensation
if ( pPlayer && pNPC->IsInhabited() )
{
CASW_Lag_Compensation::RequestLagCompensation( pPlayer, pPlayer->GetCurrentUserCommand() );
}
#endif
FireBulletsInfo_t info;
info.m_vecSrc = pNPC->Weapon_ShootPosition();
CASW_Marine *pMarine = CASW_Marine::AsMarine( pNPC );
if ( pPlayer && pMarine && pMarine->IsInhabited() )
{
info.m_vecDirShooting = pPlayer->GetAutoaimVectorForMarine( pMarine, GetAutoAimAmount(), GetVerticalAdjustOnlyAutoAimAmount() ); // 45 degrees = 0.707106781187
}
else
{
#ifdef CLIENT_DLL
Msg( "Error, clientside firing of a weapon that's being controlled by an AI marine\n" );
#else
info.m_vecDirShooting = pNPC->GetActualShootTrajectory( info.m_vecSrc );
#endif
}
// To make the firing framerate independent, we may have to fire more than one bullet here on low-framerate systems,
// especially if the weapon we're firing has a really fast rate of fire.
info.m_iShots = 0;
float fireRate = GetFireRate();
while ( m_flNextPrimaryAttack <= gpGlobals->curtime )
{
m_flNextPrimaryAttack = m_flNextPrimaryAttack + fireRate;
info.m_iShots++;
if ( !fireRate )
break;
}
// Make sure we don't fire more than the amount in the clip
if ( UsesClipsForAmmo1() )
{
info.m_iShots = MIN( info.m_iShots, m_iClip1 );
for ( int k = 0; k < info.m_iShots; k++ )
{
m_iClip1 -= 1;
NotifyIfNoneClip1Ammo( pMarine );
}
}
else
{
info.m_iShots = MIN( info.m_iShots, pNPC->GetAmmoCount( m_iPrimaryAmmoType ) );
for ( int k = 0; k < info.m_iShots; k++ )
{
pNPC->RemoveAmmo( info.m_iShots, m_iPrimaryAmmoType );;
}
}
info.m_flDistance = asw_weapon_max_shooting_distance.GetFloat();
info.m_iAmmoType = m_iPrimaryAmmoType;
info.m_iTracerFreq = 1; // asw tracer test everytime
info.m_vecSpread = GetBulletSpread();
info.m_flDamage = GetWeaponDamage();
info.m_flDamageForceScale = asw_weapon_force_scale.GetFloat();
#ifndef CLIENT_DLL
if ( asw_debug_marine_damage.GetBool() )
Msg( "Weapon dmg = %f\n", info.m_flDamage );
if ( pMarine && pMarine->GetMarineResource() )
pMarine->GetMarineResource()->OnFired_ScaleDamage( info );
#endif
pNPC->FireBullets( info );
// increment shooting stats
#ifndef CLIENT_DLL
if ( pMarine && pMarine->GetMarineResource() )
{
pMarine->GetMarineResource()->UsedWeapon( this, info.m_iShots );
pMarine->OnWeaponFired( this, info.m_iShots );
}
#endif
}
}
int CASW_Weapon_PDW::ASW_SelectWeaponActivity(int idealActivity)
{
switch( idealActivity )
{
case ACT_WALK: idealActivity = ACT_MP_WALK_ITEM1; break;
case ACT_RUN: idealActivity = ACT_MP_RUN_ITEM1; break;
case ACT_IDLE: idealActivity = ACT_MP_STAND_ITEM1; break;
case ACT_RELOAD: idealActivity = ACT_RELOAD_PISTOL; break; // short (pistol) reload
case ACT_RANGE_ATTACK1: idealActivity = ACT_MP_ATTACK_STAND_ITEM1; break;
case ACT_CROUCHIDLE: idealActivity = ACT_MP_CROUCHWALK_ITEM1; break;
case ACT_JUMP: idealActivity = ACT_MP_JUMP_ITEM1; break;
default:
return BaseClass::ASW_SelectWeaponActivity(idealActivity);
}
return idealActivity;
}
float CASW_Weapon_PDW::GetWeaponDamage()
{
float flDamage = BaseClass::GetWeaponDamage();
#ifdef GAME_DLL
if ( !GetMarine() && ASWGameRules() )
{
flDamage = ASWGameRules()->ModifyAlienDamageBySkillLevel( sk_npc_dmg_smg1.GetFloat() );
}
#endif
return flDamage;
}
float CASW_Weapon_PDW::GetWeaponBaseDamageOverride()
{
extern ConVar rd_pdw_dmg_base;
return rd_pdw_dmg_base.GetFloat();
}
int CASW_Weapon_PDW::GetWeaponSkillId()
{
return ASW_MARINE_SKILL_ACCURACY;
}
int CASW_Weapon_PDW::GetWeaponSubSkillId()
{
return ASW_MARINE_SUBSKILL_ACCURACY_PDW_DMG;
}
// user message based tracer type
const char* CASW_Weapon_PDW::GetUTracerType()
{
// BenLubar: for some reason, ASWUTracerDualLeft makes the right-hand gun fire. ugh.
return m_bIsSingle ? "ASWUTracerDualLeft" : "ASWUTracerDual";
}
#ifdef GAME_DLL
// Combine soldiers don't have animations for akimbo-style weapons, so only give them one PDW.
const char *CASW_Weapon_PDW::GetViewModel( int viewmodelindex ) const
{
if ( m_bIsSingle )
return "models/weapons/pdw/pdw_single.mdl";
return BaseClass::GetViewModel( viewmodelindex );
}
const char *CASW_Weapon_PDW::GetWorldModel( void ) const
{
if ( m_bIsSingle )
return "models/weapons/pdw/pdw_single.mdl";
return BaseClass::GetWorldModel();
}
#else
const char *CASW_Weapon_PDW::GetPartialReloadSound( int iPart )
{
if ( iPart == 1 )
return "ASW_Weapon_PDW.ReloadB";
if ( iPart == 2 )
return "ASW_Weapon_PDW.ReloadC";
return "ASW_Weapon_PDW.ReloadA";
}
#endif