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.

289 lines
9.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef WEAPON_CSBASE_H
  7. #define WEAPON_CSBASE_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "cs_playeranimstate.h"
  12. #include "cs_weapon_parse.h"
  13. #if defined( CLIENT_DLL )
  14. #define CWeaponCSBase C_WeaponCSBase
  15. #endif
  16. extern CSWeaponID AliasToWeaponID( const char *alias );
  17. extern const char *WeaponIDToAlias( int id );
  18. extern const char *GetTranslatedWeaponAlias( const char *alias);
  19. extern const char * GetWeaponAliasFromTranslated(const char *translatedAlias);
  20. extern bool IsPrimaryWeapon( CSWeaponID id );
  21. extern bool IsSecondaryWeapon( CSWeaponID id );
  22. extern int GetShellForAmmoType( const char *ammoname );
  23. #define SHIELD_VIEW_MODEL "models/weapons/v_shield.mdl"
  24. #define SHIELD_WORLD_MODEL "models/weapons/w_shield.mdl"
  25. class CCSPlayer;
  26. // These are the names of the ammo types that go in the CAmmoDefs and that the
  27. // weapon script files reference.
  28. #define BULLET_PLAYER_50AE "BULLET_PLAYER_50AE"
  29. #define BULLET_PLAYER_762MM "BULLET_PLAYER_762MM"
  30. #define BULLET_PLAYER_556MM "BULLET_PLAYER_556MM"
  31. #define BULLET_PLAYER_556MM_BOX "BULLET_PLAYER_556MM_BOX"
  32. #define BULLET_PLAYER_338MAG "BULLET_PLAYER_338MAG"
  33. #define BULLET_PLAYER_9MM "BULLET_PLAYER_9MM"
  34. #define BULLET_PLAYER_BUCKSHOT "BULLET_PLAYER_BUCKSHOT"
  35. #define BULLET_PLAYER_45ACP "BULLET_PLAYER_45ACP"
  36. #define BULLET_PLAYER_357SIG "BULLET_PLAYER_357SIG"
  37. #define BULLET_PLAYER_57MM "BULLET_PLAYER_57MM"
  38. #define AMMO_TYPE_HEGRENADE "AMMO_TYPE_HEGRENADE"
  39. #define AMMO_TYPE_FLASHBANG "AMMO_TYPE_FLASHBANG"
  40. #define AMMO_TYPE_SMOKEGRENADE "AMMO_TYPE_SMOKEGRENADE"
  41. #define CROSSHAIR_CONTRACT_PIXELS_PER_SECOND 7.0f
  42. // Given an ammo type (like from a weapon's GetPrimaryAmmoType()), this compares it
  43. // against the ammo name you specify.
  44. // MIKETODO: this should use indexing instead of searching and strcmp()'ing all the time.
  45. bool IsAmmoType( int iAmmoType, const char *pAmmoName );
  46. enum CSWeaponMode
  47. {
  48. Primary_Mode = 0,
  49. Secondary_Mode,
  50. WeaponMode_MAX
  51. };
  52. #if defined( CLIENT_DLL )
  53. //--------------------------------------------------------------------------------------------------------------
  54. /**
  55. * Returns the client's ID_* value for the currently owned weapon, or ID_NONE if no weapon is owned
  56. */
  57. CSWeaponID GetClientWeaponID( bool primary );
  58. #endif
  59. //--------------------------------------------------------------------------------------------------------------
  60. CCSWeaponInfo * GetWeaponInfo( CSWeaponID weaponID );
  61. class CWeaponCSBase : public CBaseCombatWeapon
  62. {
  63. public:
  64. DECLARE_CLASS( CWeaponCSBase, CBaseCombatWeapon );
  65. DECLARE_NETWORKCLASS();
  66. DECLARE_PREDICTABLE();
  67. CWeaponCSBase();
  68. #ifdef GAME_DLL
  69. DECLARE_DATADESC();
  70. virtual void CheckRespawn();
  71. virtual CBaseEntity* Respawn();
  72. virtual const Vector& GetBulletSpread();
  73. virtual float GetDefaultAnimSpeed();
  74. virtual void BulletWasFired( const Vector &vecStart, const Vector &vecEnd );
  75. virtual bool ShouldRemoveOnRoundRestart();
  76. //=============================================================================
  77. // HPE_BEGIN:
  78. // [dwenger] Handle round restart processing for the weapon.
  79. //=============================================================================
  80. virtual void OnRoundRestart();
  81. //=============================================================================
  82. // HPE_END
  83. //=============================================================================
  84. virtual bool DefaultReload( int iClipSize1, int iClipSize2, int iActivity );
  85. void SendReloadEvents();
  86. void Materialize();
  87. void AttemptToMaterialize();
  88. virtual void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
  89. virtual bool IsRemoveable();
  90. #endif
  91. virtual bool Holster( CBaseCombatWeapon *pSwitchingTo );
  92. virtual void AddViewmodelBob( CBaseViewModel *viewmodel, Vector &origin, QAngle &angles );
  93. virtual float CalcViewmodelBob( void );
  94. // All predicted weapons need to implement and return true
  95. virtual bool IsPredicted() const;
  96. // Pistols reset m_iShotsFired to 0 when the attack button is released.
  97. bool IsPistol() const;
  98. virtual bool IsFullAuto() const;
  99. CCSPlayer* GetPlayerOwner() const;
  100. virtual float GetMaxSpeed() const; // What's the player's max speed while holding this weapon.
  101. // Get CS-specific weapon data.
  102. CCSWeaponInfo const &GetCSWpnData() const;
  103. // Get specific CS weapon ID (ie: WEAPON_AK47, etc)
  104. virtual CSWeaponID GetWeaponID( void ) const { return WEAPON_NONE; }
  105. // return true if this weapon is an instance of the given weapon type (ie: "IsA" WEAPON_GLOCK)
  106. bool IsA( CSWeaponID id ) const { return GetWeaponID() == id; }
  107. // return true if this weapon is a kinf of the given weapon type (ie: "IsKindOf" WEAPONTYPE_RIFLE )
  108. bool IsKindOf( CSWeaponType type ) const { return GetCSWpnData().m_WeaponType == type; }
  109. // return true if this weapon has a silencer equipped
  110. virtual bool IsSilenced( void ) const { return false; }
  111. virtual void SetWeaponModelIndex( const char *pName );
  112. virtual void OnPickedUp( CBaseCombatCharacter *pNewOwner );
  113. virtual void OnJump( float fImpulse );
  114. virtual void OnLand( float fVelocity );
  115. public:
  116. #if defined( CLIENT_DLL )
  117. virtual void ProcessMuzzleFlashEvent();
  118. virtual bool OnFireEvent( C_BaseViewModel *pViewModel, const Vector& origin, const QAngle& angles, int event, const char *options );
  119. virtual bool ShouldPredict();
  120. virtual void DrawCrosshair();
  121. virtual void OnDataChanged( DataUpdateType_t type );
  122. virtual int GetMuzzleAttachment( void );
  123. virtual bool HideViewModelWhenZoomed( void ) { return true; }
  124. float m_flCrosshairDistance;
  125. int m_iAmmoLastCheck;
  126. int m_iAlpha;
  127. int m_iScopeTextureID;
  128. int m_iCrosshairTextureID; // for white additive texture
  129. virtual int GetMuzzleFlashStyle( void );
  130. #else
  131. virtual bool Reload();
  132. virtual void Spawn();
  133. virtual bool KeyValue( const char *szKeyName, const char *szValue );
  134. virtual bool PhysicsSplash( const Vector &centerPoint, const Vector &normal, float rawSpeed, float scaledSpeed );
  135. #endif
  136. bool IsUseable();
  137. virtual bool CanDeploy( void );
  138. virtual void UpdateShieldState( void );
  139. virtual bool SendWeaponAnim( int iActivity );
  140. virtual void SecondaryAttack( void );
  141. virtual void Precache( void );
  142. virtual bool CanBeSelected( void );
  143. virtual Activity GetDeployActivity( void );
  144. virtual bool DefaultDeploy( char *szViewModel, char *szWeaponModel, int iActivity, char *szAnimExt );
  145. virtual void DefaultTouch( CBaseEntity *pOther ); // default weapon touch
  146. virtual bool DefaultPistolReload();
  147. virtual bool Deploy();
  148. virtual void Drop( const Vector &vecVelocity );
  149. bool PlayEmptySound();
  150. virtual void ItemPostFrame();
  151. virtual void ItemBusyFrame();
  152. virtual const char *GetViewModel( int viewmodelindex = 0 ) const;
  153. bool m_bDelayFire; // This variable is used to delay the time between subsequent button pressing.
  154. float m_flAccuracy;
  155. //=============================================================================
  156. // HPE_BEGIN:
  157. // [pfreese] new accuracy model
  158. //=============================================================================
  159. CNetworkVar( CSWeaponMode, m_weaponMode);
  160. virtual float GetInaccuracy() const;
  161. virtual float GetSpread() const;
  162. virtual void UpdateAccuracyPenalty();
  163. CNetworkVar( float, m_fAccuracyPenalty );
  164. //=============================================================================
  165. // HPE_END
  166. //=============================================================================
  167. void SetExtraAmmoCount( int count ) { m_iExtraPrimaryAmmo = count; }
  168. int GetExtraAmmoCount( void ) { return m_iExtraPrimaryAmmo; }
  169. //=============================================================================
  170. // HPE_BEGIN:
  171. //=============================================================================
  172. // [tj] Accessors for the previous owner of the gun
  173. void SetPreviousOwner(CCSPlayer* player) { m_prevOwner = player; }
  174. CCSPlayer* GetPreviousOwner() { return m_prevOwner; }
  175. // [tj] Accessors for the donor system
  176. void SetDonor(CCSPlayer* player) { m_donor = player; }
  177. CCSPlayer* GetDonor() { return m_donor; }
  178. void SetDonated(bool donated) { m_donated = true;}
  179. bool GetDonated() { return m_donated; }
  180. //[dwenger] Accessors for the prior owner list
  181. void AddToPriorOwnerList(CCSPlayer* pPlayer);
  182. bool IsAPriorOwner(CCSPlayer* pPlayer);
  183. //=============================================================================
  184. // HPE_END
  185. //=============================================================================
  186. protected:
  187. float CalculateNextAttackTime( float flCycleTime );
  188. private:
  189. float m_flDecreaseShotsFired;
  190. CWeaponCSBase( const CWeaponCSBase & );
  191. int m_iExtraPrimaryAmmo;
  192. float m_nextPrevOwnerTouchTime;
  193. CCSPlayer *m_prevOwner;
  194. int m_iDefaultExtraAmmo;
  195. //=============================================================================
  196. // HPE_BEGIN:
  197. //=============================================================================
  198. // [dwenger] track all prior owners of this weapon
  199. CUtlVector< CCSPlayer* > m_PriorOwners;
  200. // [tj] To keep track of people who drop weapons for teammates during the buy round
  201. CHandle<CCSPlayer> m_donor;
  202. bool m_donated;
  203. //=============================================================================
  204. // HPE_END
  205. //=============================================================================
  206. };
  207. extern ConVar weapon_accuracy_model;
  208. #endif // WEAPON_CSBASE_H