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.

403 lines
10 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef WEAPON_DODBASE_H
  7. #define WEAPON_DODBASE_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "dod_playeranimstate.h"
  12. #include "dod_weapon_parse.h"
  13. #if defined( CLIENT_DLL )
  14. #define CWeaponDODBase C_WeaponDODBase
  15. #endif
  16. extern int AliasToWeaponID( const char *alias );
  17. extern const char *WeaponIDToAlias( int id );
  18. extern bool IsPrimaryWeapon( int id );
  19. extern bool IsSecondaryWeapon( int id );
  20. class CDODPlayer;
  21. // These are the names of the ammo types that go in the CAmmoDefs and that the
  22. // weapon script files reference.
  23. #define DOD_AMMO_SUBMG "DOD_AMMO_SUBMG"
  24. #define DOD_AMMO_ROCKET "DOD_AMMO_ROCKET"
  25. #define DOD_AMMO_COLT "DOD_AMMO_COLT"
  26. #define DOD_AMMO_P38 "DOD_AMMO_P38"
  27. #define DOD_AMMO_C96 "DOD_AMMO_C96"
  28. #define DOD_AMMO_WEBLEY "DOD_AMMO_WEBLEY"
  29. #define DOD_AMMO_GARAND "DOD_AMMO_GARAND"
  30. #define DOD_AMMO_K98 "DOD_AMMO_K98"
  31. #define DOD_AMMO_M1CARBINE "DOD_AMMO_M1CARBINE"
  32. #define DOD_AMMO_ENFIELD "DOD_AMMO_ENFIELD"
  33. #define DOD_AMMO_SPRING "DOD_AMMO_SPRING"
  34. #define DOD_AMMO_FG42 "DOD_AMMO_FG42"
  35. #define DOD_AMMO_BREN "DOD_AMMO_BREN"
  36. #define DOD_AMMO_BAR "DOD_AMMO_BAR"
  37. #define DOD_AMMO_30CAL "DOD_AMMO_30CAL"
  38. #define DOD_AMMO_MG34 "DOD_AMMO_MG34"
  39. #define DOD_AMMO_MG42 "DOD_AMMO_MG42"
  40. #define DOD_AMMO_HANDGRENADE "DOD_AMMO_HANDGRENADE"
  41. #define DOD_AMMO_HANDGRENADE_EX "DOD_AMMO_HANDGRENADE_EX" // the EX is for EXploding! :)
  42. #define DOD_AMMO_STICKGRENADE "DOD_AMMO_STICKGRENADE"
  43. #define DOD_AMMO_STICKGRENADE_EX "DOD_AMMO_STICKGRENADE_EX"
  44. #define DOD_AMMO_SMOKEGRENADE_US "DOD_AMMO_SMOKEGRENADE_US"
  45. #define DOD_AMMO_SMOKEGRENADE_GER "DOD_AMMO_SMOKEGRENADE_GER"
  46. #define DOD_AMMO_SMOKEGRENADE_US_LIVE "DOD_AMMO_SMOKEGRENADE_US_LIVE"
  47. #define DOD_AMMO_SMOKEGRENADE_GER_LIVE "DOD_AMMO_SMOKEGRENADE_GER_LIVE"
  48. #define DOD_AMMO_RIFLEGRENADE_US "DOD_AMMO_RIFLEGRENADE_US"
  49. #define DOD_AMMO_RIFLEGRENADE_GER "DOD_AMMO_RIFLEGRENADE_GER"
  50. #define DOD_AMMO_RIFLEGRENADE_US_LIVE "DOD_AMMO_RIFLEGRENADE_US_LIVE"
  51. #define DOD_AMMO_RIFLEGRENADE_GER_LIVE "DOD_AMMO_RIFLEGRENADE_GER_LIVE"
  52. #define CROSSHAIR_CONTRACT_PIXELS_PER_SECOND 7.0f
  53. // Given an ammo type (like from a weapon's GetPrimaryAmmoType()), this compares it
  54. // against the ammo name you specify.
  55. // MIKETODO: this should use indexing instead of searching and strcmp()'ing all the time.
  56. bool IsAmmoType( int iAmmoType, const char *pAmmoName );
  57. typedef enum
  58. {
  59. WEAPON_NONE = 0,
  60. //Melee
  61. WEAPON_AMERKNIFE,
  62. WEAPON_SPADE,
  63. //Pistols
  64. WEAPON_COLT,
  65. WEAPON_P38,
  66. WEAPON_C96,
  67. //Rifles
  68. WEAPON_GARAND,
  69. WEAPON_M1CARBINE,
  70. WEAPON_K98,
  71. //Sniper Rifles
  72. WEAPON_SPRING,
  73. WEAPON_K98_SCOPED,
  74. //SMG
  75. WEAPON_THOMPSON,
  76. WEAPON_MP40,
  77. WEAPON_MP44,
  78. WEAPON_BAR,
  79. //Machine guns
  80. WEAPON_30CAL,
  81. WEAPON_MG42,
  82. //Rocket weapons
  83. WEAPON_BAZOOKA,
  84. WEAPON_PSCHRECK,
  85. //Grenades
  86. WEAPON_FRAG_US,
  87. WEAPON_FRAG_GER,
  88. WEAPON_FRAG_US_LIVE,
  89. WEAPON_FRAG_GER_LIVE,
  90. WEAPON_SMOKE_US,
  91. WEAPON_SMOKE_GER,
  92. WEAPON_RIFLEGREN_US,
  93. WEAPON_RIFLEGREN_GER,
  94. WEAPON_RIFLEGREN_US_LIVE,
  95. WEAPON_RIFLEGREN_GER_LIVE,
  96. // not actually separate weapons, but defines used in stats recording
  97. // find a better way to do this without polluting the list of actual weapons.
  98. WEAPON_THOMPSON_PUNCH,
  99. WEAPON_MP40_PUNCH,
  100. WEAPON_GARAND_ZOOMED,
  101. WEAPON_K98_ZOOMED,
  102. WEAPON_SPRING_ZOOMED,
  103. WEAPON_K98_SCOPED_ZOOMED,
  104. WEAPON_30CAL_UNDEPLOYED,
  105. WEAPON_MG42_UNDEPLOYED,
  106. WEAPON_BAR_SEMIAUTO,
  107. WEAPON_MP44_SEMIAUTO,
  108. WEAPON_MAX, // number of weapons weapon index
  109. } DODWeaponID;
  110. //Class Heirarchy for dod weapons
  111. /*
  112. CWeaponDODBase
  113. |
  114. |
  115. |--> CWeaponDODBaseMelee
  116. | |
  117. | |--> CWeaponSpade
  118. | |--> CWeaponUSKnife
  119. |
  120. |--> CWeaponDODBaseGrenade
  121. | |
  122. | |--> CWeaponHandgrenade
  123. | |--> CWeaponStickGrenade
  124. | |--> CWeaponSmokeGrenadeUS
  125. | |--> CWeaponSmokeGrenadeGER
  126. |
  127. |--> CWeaponBaseRifleGrenade
  128. | |
  129. | |--> CWeaponRifleGrenadeUS
  130. | |--> CWeaponRifleGrenadeGER
  131. |
  132. |--> CDODBaseRocketWeapon
  133. | |
  134. | |--> CWeaponBazooka
  135. | |--> CWeaponPschreck
  136. |
  137. |--> CWeaponDODBaseGun
  138. |
  139. |--> CDODFullAutoWeapon
  140. | |
  141. | |--> CWeaponC96
  142. | |
  143. | |--> CDODFullAutoPunchWeapon
  144. | | |
  145. | | |--> CWeaponThompson
  146. | | |--> CWeaponMP40
  147. | |
  148. | |--> CDODBipodWeapon
  149. | |
  150. | |-> CWeapon30Cal
  151. | |-> CWeaponMG42
  152. |
  153. |--> CDODFireSelectWeapon
  154. | |
  155. | |--> CWeaponMP44
  156. | |--> CWeaponBAR
  157. |
  158. |
  159. |--> CDODSemiAutoWeapon
  160. |
  161. |--> CWeaponColt
  162. |--> CWeaponP38
  163. |--> CWeaponM1Carbine
  164. |--> CDODSniperWeapon
  165. |
  166. |--> CWeaponSpring
  167. |--> CWeaponScopedK98
  168. |--> CWeaponGarand
  169. |--> CWeaponK98
  170. */
  171. void FindHullIntersection( const Vector &vecSrc, trace_t &tr, const Vector &mins, const Vector &maxs, CBaseEntity *pEntity );
  172. typedef enum
  173. {
  174. Primary_Mode = 0,
  175. Secondary_Mode,
  176. } DODWeaponMode;
  177. class CWeaponDODBase : public CBaseCombatWeapon
  178. {
  179. public:
  180. DECLARE_CLASS( CWeaponDODBase, CBaseCombatWeapon );
  181. DECLARE_NETWORKCLASS();
  182. DECLARE_PREDICTABLE();
  183. CWeaponDODBase();
  184. #ifdef GAME_DLL
  185. DECLARE_DATADESC();
  186. virtual void CheckRespawn();
  187. virtual CBaseEntity* Respawn();
  188. virtual const Vector& GetBulletSpread();
  189. virtual float GetDefaultAnimSpeed();
  190. virtual void ItemBusyFrame();
  191. virtual bool ShouldRemoveOnRoundRestart();
  192. void Materialize();
  193. void AttemptToMaterialize();
  194. #else
  195. void PlayWorldReloadSound( CDODPlayer *pPlayer );
  196. #endif
  197. virtual bool DefaultReload( int iClipSize1, int iClipSize2, int iActivity );
  198. virtual bool Holster( CBaseCombatWeapon *pSwitchingTo );
  199. virtual void Drop( const Vector &vecVelocity );
  200. virtual void AddViewmodelBob( CBaseViewModel *viewmodel, Vector &origin, QAngle &angles );
  201. virtual float CalcViewmodelBob( void );
  202. // All predicted weapons need to implement and return true
  203. virtual bool IsPredicted() const;
  204. virtual int ObjectCaps( void ) { return BaseClass::ObjectCaps() | FCAP_USE_IN_RADIUS; }
  205. CBasePlayer* GetPlayerOwner() const;
  206. CDODPlayer* GetDODPlayerOwner() const;
  207. virtual void WeaponIdle( void );
  208. virtual Activity GetIdleActivity( void );
  209. // Get DOD-specific weapon data.
  210. CDODWeaponInfo const &GetDODWpnData() const;
  211. // Get specific DOD weapon ID (ie: WEAPON_GARAND, etc)
  212. virtual DODWeaponID GetWeaponID( void ) const { return WEAPON_NONE; }
  213. virtual DODWeaponID GetStatsWeaponID( void ) { return GetWeaponID(); }
  214. virtual DODWeaponID GetAltWeaponID( void ) const { return WEAPON_NONE; }
  215. // return true if this weapon is an instance of the given weapon type (ie: "IsA" WEAPON_GLOCK)
  216. bool IsA( DODWeaponID id ) const { return GetWeaponID() == id; }
  217. // return true if this weapon has a silencer equipped
  218. virtual bool IsSilenced( void ) const { return false; }
  219. void KickBack( float up_base, float lateral_base, float up_modifier, float lateral_modifier, float up_max, float lateral_max, int direction_change );
  220. virtual void SetWeaponModelIndex( const char *pName );
  221. virtual bool CanDrop( void ) { return false; }
  222. virtual bool ShouldDrawCrosshair( void ) { return true; }
  223. virtual bool ShouldDrawViewModel( void ) { return true; }
  224. virtual bool ShouldDrawMuzzleFlash( void ) { return true; }
  225. virtual float GetWeaponAccuracy( float flPlayerSpeed ) { return 0; }
  226. virtual bool HideViewModelWhenZoomed( void ) { return false; }
  227. virtual bool CanAttack( void );
  228. virtual bool ShouldAutoReload( void );
  229. CNetworkVar( int, m_iReloadModelIndex );
  230. CNetworkVector( m_vInitialDropVelocity );
  231. virtual void FinishReload( void ) {}
  232. public:
  233. #if defined( CLIENT_DLL )
  234. virtual void ProcessMuzzleFlashEvent();
  235. virtual bool ShouldPredict();
  236. virtual void PostDataUpdate( DataUpdateType_t type );
  237. virtual void OnDataChanged( DataUpdateType_t type );
  238. virtual bool OnFireEvent( C_BaseViewModel *pViewModel, const Vector& origin, const QAngle& angles, int event, const char *options );
  239. virtual bool ShouldAutoEjectBrass( void );
  240. virtual bool GetEjectBrassShellType( void );
  241. void SetUseAltModel( bool bUseAlt );
  242. virtual int GetWorldModelIndex( void );
  243. virtual void CheckForAltWeapon( int iCurrentState );
  244. virtual Vector GetDesiredViewModelOffset( C_DODPlayer *pOwner );
  245. virtual float GetViewModelSwayScale( void ) { return 1.0; }
  246. virtual void OnWeaponDropped( void ) {}
  247. virtual bool ShouldDraw( void );
  248. float m_flCrosshairDistance;
  249. int m_iAmmoLastCheck;
  250. int m_iAlpha;
  251. int m_iScopeTextureID;
  252. bool m_bUseAltWeaponModel; //use alternate left handed world model? reset on new sequence
  253. #else
  254. virtual bool Reload();
  255. virtual void Spawn();
  256. void SetDieThink( bool bDie );
  257. void Die( void );
  258. void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
  259. #endif
  260. virtual void OnPickedUp( CBaseCombatCharacter *pNewOwner );
  261. bool IsUseable();
  262. virtual bool CanDeploy( void );
  263. virtual bool CanHolster( void );
  264. virtual bool SendWeaponAnim( int iActivity );
  265. virtual void Precache( void );
  266. virtual bool CanBeSelected( void );
  267. virtual bool DefaultDeploy( char *szViewModel, char *szWeaponModel, int iActivity, char *szAnimExt );
  268. virtual bool Deploy();
  269. bool PlayEmptySound();
  270. virtual void ItemPostFrame();
  271. virtual const char *GetViewModel( int viewmodelindex = 0 ) const;
  272. bool m_bInAttack; //True after a semi-auto weapon fires - will not fire a second time on the same button press
  273. void SetExtraAmmoCount( int count ) { m_iExtraPrimaryAmmo = count; }
  274. int GetExtraAmmoCount( void ) { return m_iExtraPrimaryAmmo; }
  275. virtual const char *GetSecondaryDeathNoticeName( void ) { return "world"; }
  276. virtual CBaseEntity *MeleeAttack( int iDamageAmount, int iDamageType, float flDmgDelay, float flAttackDelay );
  277. void EXPORT Smack( void );
  278. //Secondary Attacks
  279. void RifleButt( void );
  280. void Bayonet( void );
  281. void Punch( void );
  282. virtual Activity GetMeleeActivity( void ) { return ACT_VM_SECONDARYATTACK; }
  283. virtual Activity GetStrongMeleeActivity( void ) { return ACT_VM_SECONDARYATTACK; }
  284. virtual float GetRecoil( void ) { return 0.0f; }
  285. protected:
  286. CNetworkVar( float, m_flSmackTime );
  287. int m_iSmackDamage;
  288. int m_iSmackDamageType;
  289. EHANDLE m_pTraceHitEnt;
  290. trace_t m_trHit;
  291. int m_iAltFireHint;
  292. private:
  293. void EjectBrassLate();
  294. float m_flDecreaseShotsFired;
  295. CWeaponDODBase( const CWeaponDODBase & );
  296. int m_iExtraPrimaryAmmo;
  297. #ifdef CLIENT_DLL
  298. int m_iCrosshairTexture;
  299. #endif
  300. };
  301. #endif // WEAPON_DODBASE_H