Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

673 lines
27 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //===========================================================================//
  6. #ifndef COMBATWEAPON_SHARED_H
  7. #define COMBATWEAPON_SHARED_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "sharedInterface.h"
  12. #include "vphysics_interface.h"
  13. #include "predictable_entity.h"
  14. #include "soundflags.h"
  15. #include "weapon_parse.h"
  16. #include "baseviewmodel_shared.h"
  17. #include "weapon_proficiency.h"
  18. #include "utlmap.h"
  19. #if defined( CLIENT_DLL )
  20. #define CBaseCombatWeapon C_BaseCombatWeapon
  21. #endif
  22. // Hacky
  23. #if defined ( TF_CLIENT_DLL ) || defined ( TF_DLL )
  24. #include "econ_entity.h"
  25. #endif // TF_CLIENT_DLL || TF_DLL
  26. #if !defined( CLIENT_DLL )
  27. extern void OnBaseCombatWeaponCreated( CBaseCombatWeapon * );
  28. extern void OnBaseCombatWeaponDestroyed( CBaseCombatWeapon * );
  29. void *SendProxy_SendLocalWeaponDataTable( const SendProp *pProp, const void *pStruct, const void *pVarData, CSendProxyRecipients *pRecipients, int objectID );
  30. #endif
  31. class CBasePlayer;
  32. class CBaseCombatCharacter;
  33. class IPhysicsConstraint;
  34. class CUserCmd;
  35. // How many times to display altfire hud hints (per weapon)
  36. #define WEAPON_ALTFIRE_HUD_HINT_COUNT 1
  37. #define WEAPON_RELOAD_HUD_HINT_COUNT 1
  38. //Start with a constraint in place (don't drop to floor)
  39. #define SF_WEAPON_START_CONSTRAINED (1<<0)
  40. #define SF_WEAPON_NO_PLAYER_PICKUP (1<<1)
  41. #define SF_WEAPON_NO_PHYSCANNON_PUNT (1<<2)
  42. //Percent
  43. #define CLIP_PERC_THRESHOLD 0.75f
  44. // Put this in your derived class definition to declare it's activity table
  45. // UNDONE: Cascade these?
  46. #define DECLARE_ACTTABLE() static acttable_t m_acttable[];\
  47. virtual acttable_t *ActivityList( int &iActivityCount ) OVERRIDE;
  48. // You also need to include the activity table itself in your class' implementation:
  49. // e.g.
  50. // acttable_t CWeaponStunstick::m_acttable[] =
  51. // {
  52. // { ACT_MELEE_ATTACK1, ACT_MELEE_ATTACK_SWING, TRUE },
  53. // };
  54. //
  55. // The stunstick overrides the ACT_MELEE_ATTACK1 activity, replacing it with ACT_MELEE_ATTACK_SWING.
  56. // This animation is required for this weapon's operation.
  57. //
  58. // Put this after your derived class' definition to implement the accessors for the
  59. // activity table.
  60. // UNDONE: Cascade these?
  61. #define IMPLEMENT_ACTTABLE(className) \
  62. acttable_t *className::ActivityList( int &iActivityCount ) { iActivityCount = ARRAYSIZE(m_acttable); return m_acttable; }
  63. typedef struct
  64. {
  65. int baseAct;
  66. int weaponAct;
  67. bool required;
  68. } acttable_t;
  69. struct poseparamtable_t
  70. {
  71. const char *pszName;
  72. float flValue;
  73. };
  74. // Put this in your derived class definition to declare it's poseparam table
  75. #define DECLARE_POSEPARAMTABLE() static poseparamtable_t m_poseparamtable[];\
  76. virtual poseparamtable_t* PoseParamList( int &iPoseParamCount ) { return NULL; }
  77. // You also need to include the activity table itself in your class' implementation:
  78. // e.g.
  79. // acttable_t CTFGrapplingHook::m_poseparamtable[] =
  80. // {
  81. // { "r_arm", 2 },
  82. // };
  83. //
  84. // The grapplinghook overrides the r_arm pose param, value to 2.
  85. #define IMPLEMENT_POSEPARAMTABLE(className)\
  86. poseparamtable_t* className::PoseParamList( int &iPoseParamCount ) { iPoseParamCount = ARRAYSIZE(m_poseparamtable); return m_poseparamtable; }
  87. class CHudTexture;
  88. class Color;
  89. namespace vgui2
  90. {
  91. typedef unsigned long HFont;
  92. }
  93. // -----------------------------------------
  94. // Vector cones
  95. // -----------------------------------------
  96. // VECTOR_CONE_PRECALCULATED - this resolves to vec3_origin, but adds some
  97. // context indicating that the person writing the code is not allowing
  98. // FireBullets() to modify the direction of the shot because the shot direction
  99. // being passed into the function has already been modified by another piece of
  100. // code and should be fired as specified. See GetActualShotTrajectory().
  101. // NOTE: The way these are calculated is that each component == sin (degrees/2)
  102. #define VECTOR_CONE_PRECALCULATED vec3_origin
  103. #define VECTOR_CONE_1DEGREES Vector( 0.00873, 0.00873, 0.00873 )
  104. #define VECTOR_CONE_2DEGREES Vector( 0.01745, 0.01745, 0.01745 )
  105. #define VECTOR_CONE_3DEGREES Vector( 0.02618, 0.02618, 0.02618 )
  106. #define VECTOR_CONE_4DEGREES Vector( 0.03490, 0.03490, 0.03490 )
  107. #define VECTOR_CONE_5DEGREES Vector( 0.04362, 0.04362, 0.04362 )
  108. #define VECTOR_CONE_6DEGREES Vector( 0.05234, 0.05234, 0.05234 )
  109. #define VECTOR_CONE_7DEGREES Vector( 0.06105, 0.06105, 0.06105 )
  110. #define VECTOR_CONE_8DEGREES Vector( 0.06976, 0.06976, 0.06976 )
  111. #define VECTOR_CONE_9DEGREES Vector( 0.07846, 0.07846, 0.07846 )
  112. #define VECTOR_CONE_10DEGREES Vector( 0.08716, 0.08716, 0.08716 )
  113. #define VECTOR_CONE_15DEGREES Vector( 0.13053, 0.13053, 0.13053 )
  114. #define VECTOR_CONE_20DEGREES Vector( 0.17365, 0.17365, 0.17365 )
  115. //-----------------------------------------------------------------------------
  116. // Purpose: Base weapon class, shared on client and server
  117. //-----------------------------------------------------------------------------
  118. #if defined USES_ECON_ITEMS
  119. #define BASECOMBATWEAPON_DERIVED_FROM CEconEntity
  120. #else
  121. #define BASECOMBATWEAPON_DERIVED_FROM CBaseAnimating
  122. #endif
  123. //-----------------------------------------------------------------------------
  124. // Collect trace attacks for weapons that fire multiple projectiles per attack that also penetrate
  125. //-----------------------------------------------------------------------------
  126. class CDmgAccumulator
  127. {
  128. public:
  129. CDmgAccumulator( void );
  130. ~CDmgAccumulator();
  131. #ifdef GAME_DLL
  132. virtual void Start( void ) { m_bActive = true; }
  133. virtual void AccumulateMultiDamage( const CTakeDamageInfo &info, CBaseEntity *pEntity );
  134. virtual void Process( void );
  135. private:
  136. CTakeDamageInfo m_updatedInfo;
  137. CUtlMap< int, CTakeDamageInfo > m_TargetsDmgInfo;
  138. #endif // GAME_DLL
  139. private:
  140. bool m_bActive;
  141. };
  142. //-----------------------------------------------------------------------------
  143. // Purpose: Client side rep of CBaseTFCombatWeapon
  144. //-----------------------------------------------------------------------------
  145. // Hacky
  146. class CBaseCombatWeapon : public BASECOMBATWEAPON_DERIVED_FROM
  147. {
  148. public:
  149. DECLARE_CLASS( CBaseCombatWeapon, BASECOMBATWEAPON_DERIVED_FROM );
  150. DECLARE_NETWORKCLASS();
  151. DECLARE_PREDICTABLE();
  152. CBaseCombatWeapon();
  153. virtual ~CBaseCombatWeapon();
  154. virtual bool IsBaseCombatWeapon( void ) const { return true; }
  155. virtual CBaseCombatWeapon *MyCombatWeaponPointer( void ) { return this; }
  156. // A derived weapon class should return true here so that weapon sounds, etc, can
  157. // apply the proper filter
  158. virtual bool IsPredicted( void ) const { return false; }
  159. virtual void Spawn( void );
  160. virtual void Precache( void );
  161. void MakeTracer( const Vector &vecTracerSrc, const trace_t &tr, int iTracerType );
  162. // Subtypes are used to manage multiple weapons of the same type on the player.
  163. virtual int GetSubType( void ) { return m_iSubType; }
  164. virtual void SetSubType( int iType ) { m_iSubType = iType; }
  165. virtual void Equip( CBaseCombatCharacter *pOwner );
  166. virtual void Drop( const Vector &vecVelocity );
  167. virtual int UpdateClientData( CBasePlayer *pPlayer );
  168. virtual bool IsAllowedToSwitch( void );
  169. virtual bool CanBeSelected( void );
  170. virtual bool VisibleInWeaponSelection( void );
  171. virtual bool HasAmmo( void );
  172. // Weapon Pickup For Player
  173. virtual void SetPickupTouch( void );
  174. virtual void DefaultTouch( CBaseEntity *pOther ); // default weapon touch
  175. virtual void GiveTo( CBaseEntity *pOther );
  176. // HUD Hints
  177. virtual bool ShouldDisplayAltFireHUDHint();
  178. virtual void DisplayAltFireHudHint();
  179. virtual void RescindAltFireHudHint(); ///< undisplay the hud hint and pretend it never showed.
  180. virtual bool ShouldDisplayReloadHUDHint();
  181. virtual void DisplayReloadHudHint();
  182. virtual void RescindReloadHudHint();
  183. // Weapon client handling
  184. virtual void SetViewModelIndex( int index = 0 );
  185. virtual bool SendWeaponAnim( int iActivity );
  186. virtual void SendViewModelAnim( int nSequence );
  187. float GetViewModelSequenceDuration(); // Return how long the current view model sequence is.
  188. bool IsViewModelSequenceFinished( void ) const; // Returns if the viewmodel's current animation is finished
  189. virtual void SetViewModel();
  190. virtual bool HasWeaponIdleTimeElapsed( void );
  191. virtual void SetWeaponIdleTime( float time );
  192. virtual float GetWeaponIdleTime( void );
  193. // Weapon selection
  194. virtual bool HasAnyAmmo( void ); // Returns true is weapon has ammo
  195. virtual bool HasPrimaryAmmo( void ); // Returns true is weapon has ammo
  196. virtual bool HasSecondaryAmmo( void ); // Returns true is weapon has ammo
  197. bool UsesPrimaryAmmo( void ); // returns true if the weapon actually uses primary ammo
  198. bool UsesSecondaryAmmo( void ); // returns true if the weapon actually uses secondary ammo
  199. void GiveDefaultAmmo( void );
  200. virtual bool CanHolster( void ) const { return TRUE; }; // returns true if the weapon can be holstered
  201. virtual bool DefaultDeploy( char *szViewModel, char *szWeaponModel, int iActivity, char *szAnimExt );
  202. virtual bool CanDeploy( void ) { return true; } // return true if the weapon's allowed to deploy
  203. virtual bool Deploy( void ); // returns true is deploy was successful
  204. virtual bool Holster( CBaseCombatWeapon *pSwitchingTo = NULL );
  205. virtual CBaseCombatWeapon *GetLastWeapon( void ) { return this; }
  206. virtual void SetWeaponVisible( bool visible );
  207. virtual bool IsWeaponVisible( void );
  208. virtual bool ReloadOrSwitchWeapons( void );
  209. virtual void OnActiveStateChanged( int iOldState ) { return; }
  210. virtual bool HolsterOnDetach() { return false; }
  211. virtual bool IsHolstered(){ return false; }
  212. virtual void Detach() {}
  213. // Weapon behaviour
  214. virtual void ItemPreFrame( void ); // called each frame by the player PreThink
  215. virtual void ItemPostFrame( void ); // called each frame by the player PostThink
  216. virtual void ItemBusyFrame( void ); // called each frame by the player PostThink, if the player's not ready to attack yet
  217. virtual void ItemHolsterFrame( void ) {}; // called each frame by the player PreThink, if the weapon is holstered
  218. virtual void WeaponIdle( void ); // called when no buttons pressed
  219. virtual void HandleFireOnEmpty(); // Called when they have the attack button down
  220. // but they are out of ammo. The default implementation
  221. // either reloads, switches weapons, or plays an empty sound.
  222. virtual bool CanPerformSecondaryAttack() const;
  223. virtual bool ShouldBlockPrimaryFire() { return false; }
  224. #ifdef CLIENT_DLL
  225. virtual void CreateMove( float flInputSampleTime, CUserCmd *pCmd, const QAngle &vecOldViewAngles ) {}
  226. virtual int CalcOverrideModelIndex() OVERRIDE;
  227. #endif
  228. virtual bool IsWeaponZoomed() { return false; } // Is this weapon in its 'zoomed in' mode?
  229. // Reloading
  230. virtual void CheckReload( void );
  231. virtual void FinishReload( void );
  232. virtual void AbortReload( void );
  233. virtual bool Reload( void );
  234. bool DefaultReload( int iClipSize1, int iClipSize2, int iActivity );
  235. bool ReloadsSingly( void ) const;
  236. virtual bool AutoFiresFullClip( void ) const { return false; }
  237. virtual void UpdateAutoFire( void );
  238. // Weapon firing
  239. virtual void PrimaryAttack( void ); // do "+ATTACK"
  240. virtual void SecondaryAttack( void ) { return; } // do "+ATTACK2"
  241. // Firing animations
  242. virtual Activity GetPrimaryAttackActivity( void );
  243. virtual Activity GetSecondaryAttackActivity( void );
  244. virtual Activity GetDrawActivity( void );
  245. virtual float GetDefaultAnimSpeed( void ) { return 1.0; }
  246. // Bullet launch information
  247. virtual int GetBulletType( void );
  248. virtual const Vector& GetBulletSpread( void );
  249. virtual Vector GetBulletSpread( WeaponProficiency_t proficiency ) { return GetBulletSpread(); }
  250. virtual float GetSpreadBias( WeaponProficiency_t proficiency ) { return 1.0; }
  251. virtual float GetFireRate( void );
  252. virtual int GetMinBurst() { return 1; }
  253. virtual int GetMaxBurst() { return 1; }
  254. virtual float GetMinRestTime() { return 0.3; }
  255. virtual float GetMaxRestTime() { return 0.6; }
  256. virtual int GetRandomBurst() { return random->RandomInt( GetMinBurst(), GetMaxBurst() ); }
  257. virtual void WeaponSound( WeaponSound_t sound_type, float soundtime = 0.0f );
  258. virtual void StopWeaponSound( WeaponSound_t sound_type );
  259. virtual const WeaponProficiencyInfo_t *GetProficiencyValues();
  260. // Autoaim
  261. virtual float GetMaxAutoAimDeflection() { return 0.99f; }
  262. virtual float WeaponAutoAimScale() { return 1.0f; } // allows a weapon to influence the perceived size of the target's autoaim radius.
  263. // TF Sprinting functions
  264. virtual bool StartSprinting( void ) { return false; };
  265. virtual bool StopSprinting( void ) { return false; };
  266. // TF Injury functions
  267. virtual float GetDamage( float flDistance, int iLocation ) { return 0.0; };
  268. virtual void SetActivity( Activity act, float duration );
  269. inline void SetActivity( Activity eActivity ) { m_Activity = eActivity; }
  270. inline Activity GetActivity( void ) const { return m_Activity; }
  271. virtual void AddViewKick( void ); // Add in the view kick for the weapon
  272. virtual char *GetDeathNoticeName( void ); // Get the string to print death notices with
  273. CBaseCombatCharacter *GetOwner() const;
  274. void SetOwner( CBaseCombatCharacter *owner );
  275. virtual void OnPickedUp( CBaseCombatCharacter *pNewOwner );
  276. virtual void AddViewmodelBob( CBaseViewModel *viewmodel, Vector &origin, QAngle &angles ) {};
  277. virtual float CalcViewmodelBob( void ) { return 0.0f; };
  278. // Returns information about the various control panels
  279. virtual void GetControlPanelInfo( int nPanelIndex, const char *&pPanelName );
  280. virtual void GetControlPanelClassName( int nPanelIndex, const char *&pPanelName );
  281. virtual bool ShouldShowControlPanels( void ) { return true; }
  282. void Lock( float lockTime, CBaseEntity *pLocker );
  283. bool IsLocked( CBaseEntity *pAsker );
  284. //All weapons can be picked up by NPCs by default
  285. virtual bool CanBePickedUpByNPCs( void ) { return true; }
  286. virtual int GetSkinOverride() const { return -1; }
  287. public:
  288. // Weapon info accessors for data in the weapon's data file
  289. const FileWeaponInfo_t &GetWpnData( void ) const;
  290. virtual const char *GetViewModel( int viewmodelindex = 0 ) const;
  291. virtual const char *GetWorldModel( void ) const;
  292. virtual const char *GetAnimPrefix( void ) const;
  293. virtual int GetMaxClip1( void ) const;
  294. virtual int GetMaxClip2( void ) const;
  295. virtual int GetDefaultClip1( void ) const;
  296. virtual int GetDefaultClip2( void ) const;
  297. virtual int GetWeight( void ) const;
  298. virtual bool AllowsAutoSwitchTo( void ) const;
  299. virtual bool AllowsAutoSwitchFrom( void ) const;
  300. virtual bool ForceWeaponSwitch( void ) const { return false; }
  301. virtual int GetWeaponFlags( void ) const;
  302. virtual int GetSlot( void ) const;
  303. virtual int GetPosition( void ) const;
  304. virtual char const *GetName( void ) const;
  305. virtual char const *GetPrintName( void ) const;
  306. virtual char const *GetShootSound( int iIndex ) const;
  307. virtual int GetRumbleEffect() const;
  308. virtual bool UsesClipsForAmmo1( void ) const;
  309. virtual bool UsesClipsForAmmo2( void ) const;
  310. bool IsMeleeWeapon() const;
  311. // derive this function if you mod uses encrypted weapon info files
  312. virtual const unsigned char *GetEncryptionKey( void );
  313. virtual int GetPrimaryAmmoType( void ) const { return m_iPrimaryAmmoType; }
  314. virtual int GetSecondaryAmmoType( void ) const { return m_iSecondaryAmmoType; }
  315. virtual int Clip1() { return m_iClip1; }
  316. virtual int Clip2() { return m_iClip2; }
  317. // Ammo quantity queries for weapons that do not use clips. These are only
  318. // used to determine how much ammo is in a weapon that does not have an owner.
  319. // That is, a weapon that's on the ground for the player to get ammo out of.
  320. int GetPrimaryAmmoCount() { return m_iPrimaryAmmoCount; }
  321. void SetPrimaryAmmoCount( int count ) { m_iPrimaryAmmoCount = count; }
  322. int GetSecondaryAmmoCount() { return m_iSecondaryAmmoCount; }
  323. void SetSecondaryAmmoCount( int count ) { m_iSecondaryAmmoCount = count; }
  324. virtual CHudTexture const *GetSpriteActive( void ) const;
  325. virtual CHudTexture const *GetSpriteInactive( void ) const;
  326. virtual CHudTexture const *GetSpriteAmmo( void ) const;
  327. virtual CHudTexture const *GetSpriteAmmo2( void ) const;
  328. virtual CHudTexture const *GetSpriteCrosshair( void ) const;
  329. virtual CHudTexture const *GetSpriteAutoaim( void ) const;
  330. virtual CHudTexture const *GetSpriteZoomedCrosshair( void ) const;
  331. virtual CHudTexture const *GetSpriteZoomedAutoaim( void ) const;
  332. virtual Activity ActivityOverride( Activity baseAct, bool *pRequired );
  333. virtual acttable_t* ActivityList( int &iActivityCount ) { return NULL; }
  334. virtual void PoseParameterOverride( bool bReset );
  335. virtual poseparamtable_t* PoseParamList( int &iPoseParamCount ) { return NULL; }
  336. virtual void Activate( void );
  337. virtual bool ShouldUseLargeViewModelVROverride() { return false; }
  338. public:
  339. // Server Only Methods
  340. #if !defined( CLIENT_DLL )
  341. DECLARE_DATADESC();
  342. virtual void FallInit( void ); // prepare to fall to the ground
  343. virtual void FallThink( void ); // make the weapon fall to the ground after spawning
  344. // Weapon spawning
  345. bool IsConstrained() { return m_pConstraint != NULL; }
  346. bool IsInBadPosition ( void ); // Is weapon in bad position to pickup?
  347. bool RepositionWeapon ( void ); // Attempts to reposition the weapon in a location where it can be
  348. virtual void Materialize( void ); // make a weapon visible and tangible
  349. void AttemptToMaterialize( void ); // see if the game rules will let the weapon become visible and tangible
  350. virtual void CheckRespawn( void ); // see if this weapon should respawn after being picked up
  351. CBaseEntity *Respawn ( void ); // copy a weapon
  352. static int GetAvailableWeaponsInBox( CBaseCombatWeapon **pList, int listMax, const Vector &mins, const Vector &maxs );
  353. // Weapon dropping / destruction
  354. virtual void Delete( void );
  355. void DestroyItem( void );
  356. virtual void Kill( void );
  357. virtual int CapabilitiesGet( void ) { return 0; }
  358. virtual int ObjectCaps( void );
  359. bool IsRemoveable() { return m_bRemoveable; }
  360. void SetRemoveable( bool bRemoveable ) { m_bRemoveable = bRemoveable; }
  361. // Returns bits for weapon conditions
  362. virtual bool WeaponLOSCondition( const Vector &ownerPos, const Vector &targetPos, bool bSetConditions );
  363. virtual int WeaponRangeAttack1Condition( float flDot, float flDist );
  364. virtual int WeaponRangeAttack2Condition( float flDot, float flDist );
  365. virtual int WeaponMeleeAttack1Condition( float flDot, float flDist );
  366. virtual int WeaponMeleeAttack2Condition( float flDot, float flDist );
  367. virtual void Operator_FrameUpdate( CBaseCombatCharacter *pOperator );
  368. virtual void Operator_HandleAnimEvent( animevent_t *pEvent, CBaseCombatCharacter *pOperator );
  369. virtual void Operator_ForceNPCFire( CBaseCombatCharacter *pOperator, bool bSecondary ) { return; }
  370. // NOTE: This should never be called when a character is operating the weapon. Animation events should be
  371. // routed through the character, and then back into CharacterAnimEvent()
  372. void HandleAnimEvent( animevent_t *pEvent );
  373. virtual int UpdateTransmitState( void );
  374. void InputHideWeapon( inputdata_t &inputdata );
  375. void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
  376. virtual CDmgAccumulator *GetDmgAccumulator( void ) { return NULL; }
  377. void SetSoundsEnabled( bool bSoundsEnabled ) { m_bSoundsEnabled = bSoundsEnabled; }
  378. // Client only methods
  379. #else
  380. virtual void BoneMergeFastCullBloat( Vector &localMins, Vector &localMaxs, const Vector &thisEntityMins, const Vector &thisEntityMaxs ) const;
  381. virtual bool OnFireEvent( C_BaseViewModel *pViewModel, const Vector& origin, const QAngle& angles, int event, const char *options )
  382. {
  383. #if defined USES_ECON_ITEMS
  384. return BaseClass::OnFireEvent( pViewModel, origin, angles, event, options );
  385. #else
  386. return false;
  387. #endif
  388. }
  389. // Should this object cast shadows?
  390. virtual ShadowType_t ShadowCastType();
  391. virtual void SetDormant( bool bDormant );
  392. virtual void OnDataChanged( DataUpdateType_t updateType );
  393. virtual void OnRestore();
  394. virtual void RestartParticleEffect( void ) {}
  395. virtual void Redraw(void);
  396. virtual void ViewModelDrawn( CBaseViewModel *pViewModel );
  397. // Get the position that bullets are seen coming out. Note: the returned values are different
  398. // for first person and third person.
  399. bool GetShootPosition( Vector &vOrigin, QAngle &vAngles );
  400. virtual void DrawCrosshair( void );
  401. virtual bool ShouldDrawCrosshair( void ) { return true; }
  402. // Weapon state checking
  403. virtual bool IsCarriedByLocalPlayer( void );
  404. virtual bool ShouldDrawUsingViewModel( void );
  405. virtual bool IsActiveByLocalPlayer( void );
  406. bool IsBeingCarried() const;
  407. // Is the carrier alive?
  408. bool IsCarrierAlive() const;
  409. // Returns the aiment render origin + angles
  410. virtual int DrawModel( int flags );
  411. virtual bool ShouldDraw( void );
  412. virtual bool ShouldDrawPickup( void );
  413. virtual void HandleInput( void ) { return; };
  414. virtual void OverrideMouseInput( float *x, float *y ) { return; };
  415. virtual int KeyInput( int down, ButtonCode_t keynum, const char *pszCurrentBinding ) { return 1; }
  416. virtual bool AddLookShift( void ) { return true; };
  417. virtual void GetViewmodelBoneControllers(C_BaseViewModel *pViewModel, float controllers[MAXSTUDIOBONECTRLS]) { return; }
  418. virtual void NotifyShouldTransmit( ShouldTransmitState_t state );
  419. WEAPON_FILE_INFO_HANDLE GetWeaponFileInfoHandle() { return m_hWeaponFileInfo; }
  420. virtual int GetWorldModelIndex( void );
  421. virtual void GetToolRecordingState( KeyValues *msg );
  422. virtual void GetWeaponCrosshairScale( float &flScale ) { flScale = 1.f; }
  423. #if !defined USES_ECON_ITEMS
  424. // Viewmodel overriding
  425. virtual bool ViewModel_IsTransparent( void ) { return IsTransparent(); }
  426. virtual bool ViewModel_IsUsingFBTexture( void ) { return UsesPowerOfTwoFrameBufferTexture(); }
  427. virtual bool IsOverridingViewmodel( void ) { return false; };
  428. virtual int DrawOverriddenViewmodel( C_BaseViewModel *pViewmodel, int flags ) { return 0; };
  429. bool WantsToOverrideViewmodelAttachments( void ) { return false; }
  430. #endif
  431. #endif // End client-only methods
  432. virtual bool CanLower( void ) { return false; }
  433. virtual bool Ready( void ) { return false; }
  434. virtual bool Lower( void ) { return false; }
  435. virtual void HideThink( void );
  436. virtual bool CanReload( void );
  437. private:
  438. typedef CHandle< CBaseCombatCharacter > CBaseCombatCharacterHandle;
  439. CNetworkVar( CBaseCombatCharacterHandle, m_hOwner ); // Player carrying this weapon
  440. protected:
  441. #if defined ( TF_CLIENT_DLL ) || defined ( TF_DLL )
  442. // Regulate crit frequency to reduce client-side seed hacking
  443. void AddToCritBucket( float flAmount );
  444. void RemoveFromCritBucket( float flAmount ) { m_flCritTokenBucket -= flAmount; }
  445. bool IsAllowedToWithdrawFromCritBucket( float flDamage );
  446. float m_flCritTokenBucket;
  447. int m_nCritChecks;
  448. int m_nCritSeedRequests;
  449. #endif // TF
  450. public:
  451. // Networked fields
  452. CNetworkVar( int, m_nViewModelIndex );
  453. // Weapon firing
  454. CNetworkVar( float, m_flNextPrimaryAttack ); // soonest time ItemPostFrame will call PrimaryAttack
  455. CNetworkVar( float, m_flNextSecondaryAttack ); // soonest time ItemPostFrame will call SecondaryAttack
  456. CNetworkVar( float, m_flTimeWeaponIdle ); // soonest time ItemPostFrame will call WeaponIdle
  457. // Weapon state
  458. bool m_bInReload; // Are we in the middle of a reload;
  459. bool m_bFireOnEmpty; // True when the gun is empty and the player is still holding down the attack key(s)
  460. bool m_bFiringWholeClip; // Are we in the middle of firing the whole clip;
  461. // Weapon art
  462. CNetworkVar( int, m_iViewModelIndex );
  463. CNetworkVar( int, m_iWorldModelIndex );
  464. // Sounds
  465. float m_flNextEmptySoundTime; // delay on empty sound playing
  466. Activity GetIdealActivity( void ) { return m_IdealActivity; }
  467. int GetIdealSequence( void ) { return m_nIdealSequence; }
  468. bool SetIdealActivity( Activity ideal );
  469. void MaintainIdealActivity( void );
  470. #ifdef CLIENT_DLL
  471. virtual const Vector& GetViewmodelOffset() { return vec3_origin; }
  472. #endif // CLIENT_DLL
  473. private:
  474. Activity m_Activity;
  475. int m_nIdealSequence;
  476. Activity m_IdealActivity;
  477. bool m_bRemoveable;
  478. int m_iPrimaryAmmoCount;
  479. int m_iSecondaryAmmoCount;
  480. public:
  481. IMPLEMENT_NETWORK_VAR_FOR_DERIVED( m_nNextThinkTick );
  482. #ifdef CLIENT_DLL
  483. static void RecvProxy_WeaponState( const CRecvProxyData *pData, void *pStruct, void *pOut );
  484. #endif
  485. int WeaponState() const { return m_iState; }
  486. // Weapon data
  487. CNetworkVar( int, m_iState ); // See WEAPON_* definition
  488. string_t m_iszName; // Classname of this weapon.
  489. CNetworkVar( int, m_iPrimaryAmmoType ); // "primary" ammo index into the ammo info array
  490. CNetworkVar( int, m_iSecondaryAmmoType ); // "secondary" ammo index into the ammo info array
  491. CNetworkVar( int, m_iClip1 ); // number of shots left in the primary weapon clip, -1 it not used
  492. CNetworkVar( int, m_iClip2 ); // number of shots left in the secondary weapon clip, -1 it not used
  493. bool m_bFiresUnderwater; // true if this weapon can fire underwater
  494. bool m_bAltFiresUnderwater; // true if this weapon can fire underwater
  495. float m_fMinRange1; // What's the closest this weapon can be used?
  496. float m_fMinRange2; // What's the closest this weapon can be used?
  497. float m_fMaxRange1; // What's the furthest this weapon can be used?
  498. float m_fMaxRange2; // What's the furthest this weapon can be used?
  499. bool m_bReloadsSingly; // True if this weapon reloads 1 round at a time
  500. float m_fFireDuration; // The amount of time that the weapon has sustained firing
  501. int m_iSubType;
  502. float m_flUnlockTime;
  503. EHANDLE m_hLocker; // Who locked this weapon.
  504. CNetworkVar( bool, m_bFlipViewModel );
  505. IPhysicsConstraint *GetConstraint() { return m_pConstraint; }
  506. private:
  507. WEAPON_FILE_INFO_HANDLE m_hWeaponFileInfo;
  508. IPhysicsConstraint *m_pConstraint;
  509. int m_iAltFireHudHintCount; // How many times has this weapon displayed its alt-fire HUD hint?
  510. int m_iReloadHudHintCount; // How many times has this weapon displayed its reload HUD hint?
  511. bool m_bAltFireHudHintDisplayed; // Have we displayed an alt-fire HUD hint since this weapon was deployed?
  512. bool m_bReloadHudHintDisplayed; // Have we displayed a reload HUD hint since this weapon was deployed?
  513. float m_flHudHintPollTime; // When to poll the weapon again for whether it should display a hud hint.
  514. float m_flHudHintMinDisplayTime; // if the hint is squelched before this, reset my counter so we'll display it again.
  515. // Server only
  516. #if !defined( CLIENT_DLL )
  517. bool m_bSoundsEnabled;
  518. // Outputs
  519. protected:
  520. COutputEvent m_OnPlayerUse; // Fired when the player uses the weapon.
  521. COutputEvent m_OnPlayerPickup; // Fired when the player picks up the weapon.
  522. COutputEvent m_OnNPCPickup; // Fired when an NPC picks up the weapon.
  523. COutputEvent m_OnCacheInteraction; // For awarding lambda cache achievements in HL2 on 360. See .FGD file for details
  524. #else // Client .dll only
  525. bool m_bJustRestored;
  526. // Allow weapons resource to access m_hWeaponFileInfo directly
  527. friend class WeaponsResource;
  528. protected:
  529. int m_iOldState;
  530. #endif // End Client .dll only
  531. };
  532. #endif // COMBATWEAPON_SHARED_H