forked from hitmen047/Source-PlusPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweapon_sdkbase.cpp
163 lines (122 loc) · 3.89 KB
/
weapon_sdkbase.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "in_buttons.h"
#include "takedamageinfo.h"
#include "weapon_sdkbase.h"
#include "ammodef.h"
#if defined( CLIENT_DLL )
#include "c_sdk_player.h"
#else
#include "sdk_player.h"
#endif
// ----------------------------------------------------------------------------- //
// Global functions.
// ----------------------------------------------------------------------------- //
//--------------------------------------------------------------------------------------------------------
static const char * s_WeaponAliasInfo[] =
{
"none", // WEAPON_NONE
"mp5", // WEAPON_MP5
"shotgun", // WEAPON_SHOTGUN
"grenade", // WEAPON_GRENADE
NULL, // WEAPON_NONE
};
//--------------------------------------------------------------------------------------------------------
//
// Given an alias, return the associated weapon ID
//
int AliasToWeaponID( const char *alias )
{
if (alias)
{
for( int i=0; s_WeaponAliasInfo[i] != NULL; ++i )
if (!Q_stricmp( s_WeaponAliasInfo[i], alias ))
return i;
}
return WEAPON_NONE;
}
//--------------------------------------------------------------------------------------------------------
//
// Given a weapon ID, return its alias
//
const char *WeaponIDToAlias( int id )
{
if ( (id >= WEAPON_MAX) || (id < 0) )
return NULL;
return s_WeaponAliasInfo[id];
}
// ----------------------------------------------------------------------------- //
// CWeaponSDKBase tables.
// ----------------------------------------------------------------------------- //
IMPLEMENT_NETWORKCLASS_ALIASED( WeaponSDKBase, DT_WeaponSDKBase )
BEGIN_NETWORK_TABLE( CWeaponSDKBase, DT_WeaponSDKBase )
#ifdef CLIENT_DLL
#else
// world weapon models have no animations
SendPropExclude( "DT_AnimTimeMustBeFirst", "m_flAnimTime" ),
SendPropExclude( "DT_BaseAnimating", "m_nSequence" ),
#endif
END_NETWORK_TABLE()
#ifdef CLIENT_DLL
BEGIN_PREDICTION_DATA( CWeaponSDKBase )
DEFINE_PRED_FIELD( m_flTimeWeaponIdle, FIELD_FLOAT, FTYPEDESC_OVERRIDE | FTYPEDESC_NOERRORCHECK ),
END_PREDICTION_DATA()
#endif
LINK_ENTITY_TO_CLASS( weapon_sdk_base, CWeaponSDKBase );
#ifdef GAME_DLL
BEGIN_DATADESC( CWeaponSDKBase )
// New weapon Think and Touch Functions go here..
END_DATADESC()
#endif
// ----------------------------------------------------------------------------- //
// CWeaponCSBase implementation.
// ----------------------------------------------------------------------------- //
CWeaponSDKBase::CWeaponSDKBase()
{
SetPredictionEligible( true );
AddSolidFlags( FSOLID_TRIGGER ); // Nothing collides with these but it gets touches.
}
const CSDKWeaponInfo &CWeaponSDKBase::GetSDKWpnData() const
{
const FileWeaponInfo_t *pWeaponInfo = &GetWpnData();
const CSDKWeaponInfo *pSDKInfo;
#ifdef _DEBUG
pSDKInfo = dynamic_cast< const CSDKWeaponInfo* >( pWeaponInfo );
Assert( pSDKInfo );
#else
pSDKInfo = static_cast< const CSDKWeaponInfo* >( pWeaponInfo );
#endif
return *pSDKInfo;
}
bool CWeaponSDKBase::PlayEmptySound()
{
CPASAttenuationFilter filter( this );
filter.UsePredictionRules();
EmitSound( filter, entindex(), "Default.ClipEmpty_Rifle" );
return 0;
}
CSDKPlayer* CWeaponSDKBase::GetPlayerOwner() const
{
return dynamic_cast< CSDKPlayer* >( GetOwner() );
}
#ifdef GAME_DLL
void CWeaponSDKBase::SendReloadEvents()
{
CSDKPlayer *pPlayer = dynamic_cast< CSDKPlayer* >( GetOwner() );
if ( !pPlayer )
return;
// Send a message to any clients that have this entity to play the reload.
CPASFilter filter( pPlayer->GetAbsOrigin() );
filter.RemoveRecipient( pPlayer );
UserMessageBegin( filter, "ReloadEffect" );
WRITE_SHORT( pPlayer->entindex() );
MessageEnd();
// Make the player play his reload animation.
pPlayer->DoAnimationEvent( PLAYERANIMEVENT_RELOAD );
}
#endif