Counter Strike : Global Offensive Source Code
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.

767 lines
30 KiB

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