-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathasw_weapon_flechette_shared.cpp
More file actions
190 lines (155 loc) · 4.46 KB
/
asw_weapon_flechette_shared.cpp
File metadata and controls
190 lines (155 loc) · 4.46 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
#include "cbase.h"
#include "asw_weapon_flechette_shared.h"
#include "in_buttons.h"
#ifdef CLIENT_DLL
#define CASW_Weapon C_ASW_Weapon
#define CASW_Marine C_ASW_Marine
#define CBasePlayer C_BasePlayer
#include "c_asw_player.h"
#include "c_asw_weapon.h"
#include "c_asw_marine.h"
#include "c_asw_marine_resource.h"
#include "precache_register.h"
#include "c_te_effect_dispatch.h"
#else
#include "asw_marine.h"
#include "asw_player.h"
#include "asw_weapon.h"
#include "npcevent.h"
#include "shot_manipulator.h"
#include "te_effect_dispatch.h"
#include "asw_marine_resource.h"
#include "asw_marine_speech.h"
#include "decals.h"
#include "ammodef.h"
#include "asw_weapon_ammo_bag_shared.h"
#include "asw_gamerules.h"
#include "asw_rocket.h"
#endif
#include "asw_marine_skills.h"
#include "asw_weapon_parse.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
IMPLEMENT_NETWORKCLASS_ALIASED( ASW_Weapon_Flechette, DT_ASW_Weapon_Flechette )
BEGIN_NETWORK_TABLE( CASW_Weapon_Flechette, DT_ASW_Weapon_Flechette )
#ifdef CLIENT_DLL
// recvprops
#else
// sendprops
#endif
END_NETWORK_TABLE()
#ifdef CLIENT_DLL
BEGIN_PREDICTION_DATA( CASW_Weapon_Flechette )
END_PREDICTION_DATA()
#endif
LINK_ENTITY_TO_CLASS( asw_weapon_flechette, CASW_Weapon_Flechette );
PRECACHE_WEAPON_REGISTER( asw_weapon_flechette );
extern ConVar asw_weapon_max_shooting_distance;
#ifndef CLIENT_DLL
extern ConVar asw_debug_marine_damage;
#endif
CASW_Weapon_Flechette::CASW_Weapon_Flechette()
{
}
CASW_Weapon_Flechette::~CASW_Weapon_Flechette()
{
}
void CASW_Weapon_Flechette::Precache()
{
BaseClass::Precache();
#ifdef GAME_DLL
UTIL_PrecacheOther( "asw_rocket" );
#endif
}
void CASW_Weapon_Flechette::PrimaryAttack()
{
// If my clip is empty (and I use clips) start reload
if ( UsesClipsForAmmo1() && !m_iClip1 )
{
Reload();
return;
}
CASW_Player *pPlayer = GetCommander();
CASW_Marine *pMarine = GetMarine();
if ( pMarine ) // firing from a marine
{
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
pMarine->DoMuzzleFlash();
// sets the animation on the weapon model iteself
SendWeaponAnim( GetPrimaryAttackActivity() );
pMarine->DoAnimationEvent( PLAYERANIMEVENT_FIRE_GUN_PRIMARY );
Vector vecDir;
Vector vecSrc = pMarine->Weapon_ShootPosition();
if ( pPlayer && pMarine->IsInhabited() )
{
// Aim directly at crosshair (so we hit the floor if we miss)
vecDir = pPlayer->GetCrosshairTracePos() - vecSrc;
vecDir.NormalizeInPlace();
}
else
{
#ifdef CLIENT_DLL
Msg( "Error, clientside firing of a weapon that's being controlled by an AI marine\n" );
#else
vecDir = pMarine->GetActualShootTrajectory( vecSrc );
#endif
}
int iShots = 1;
// Make sure we don't fire more than the amount in the clip
if ( UsesClipsForAmmo1() )
{
iShots = MIN( iShots, m_iClip1 );
m_iClip1 -= iShots;
NotifyIfNoneClip1Ammo( pMarine );
}
else
{
iShots = MIN( iShots, pMarine->GetAmmoCount( m_iPrimaryAmmoType ) );
pMarine->RemoveAmmo( iShots, m_iPrimaryAmmoType );
}
// increment shooting stats
#ifndef CLIENT_DLL
float fGrenadeDamage = MarineSkills()->GetSkillBasedValueByMarine( pMarine, ASW_MARINE_SKILL_GRENADES, ASW_MARINE_SUBSKILL_GRENADE_FLECHETTE_DMG );
CShotManipulator manipulator( vecDir );
Vector vecShoot = manipulator.ApplySpread( GetBulletSpread() );
QAngle vecRocketAngle;
VectorAngles( vecShoot, vecRocketAngle );
vecRocketAngle[YAW] += random->RandomFloat( -10, 10 );
CASW_Rocket::Create( fGrenadeDamage, vecSrc, vecRocketAngle, GetMarine() );
if ( pMarine->GetMarineResource() )
{
pMarine->GetMarineResource()->UsedWeapon( this, iShots );
pMarine->OnWeaponFired( this, iShots );
}
if ( ASWGameRules() )
ASWGameRules()->m_fLastFireTime = gpGlobals->curtime;
#endif
m_flNextPrimaryAttack = m_flNextPrimaryAttack + GetFireRate();
}
}
void CASW_Weapon_Flechette::SecondaryAttack()
{
CASW_Player *pPlayer = GetCommander();
if ( !pPlayer )
return;
CASW_Marine *pMarine = GetMarine();
if ( !pMarine )
return;
// dry fire
SendWeaponAnim( ACT_VM_DRYFIRE );
BaseClass::WeaponSound( EMPTY );
m_flNextSecondaryAttack = gpGlobals->curtime + 0.5f;
}
float CASW_Weapon_Flechette::GetFireRate()
{
float flRate = GetEquipItem()->m_flFireRate;
//CALL_ATTRIB_HOOK_FLOAT( flRate, mod_fire_rate );
return flRate;
}