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.

432 lines
17 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef CS_WEAPON_PARSE_H
  7. #define CS_WEAPON_PARSE_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #ifdef CLIENT_DLL
  12. #define CWeaponCSBase C_WeaponCSBase
  13. #endif
  14. #include "weapon_parse.h"
  15. #include "econ_item_constants.h"
  16. class CWeaponCSBase;
  17. //--------------------------------------------------------------------------------------------------------
  18. enum CSWeaponType
  19. {
  20. WEAPONTYPE_KNIFE=0,
  21. WEAPONTYPE_PISTOL,
  22. WEAPONTYPE_SUBMACHINEGUN,
  23. WEAPONTYPE_RIFLE,
  24. WEAPONTYPE_SHOTGUN,
  25. WEAPONTYPE_SNIPER_RIFLE,
  26. WEAPONTYPE_MACHINEGUN,
  27. WEAPONTYPE_C4,
  28. WEAPONTYPE_GRENADE,
  29. WEAPONTYPE_EQUIPMENT,
  30. WEAPONTYPE_STACKABLEITEM,
  31. WEAPONTYPE_UNKNOWN
  32. };
  33. /*
  34. NOTE!!!! Please try not to change the order. If you need to add something, please add it to the end.
  35. Anytime the order of the weaponID's change, we need to updated a bunch of tables in a couple DB's. Also,
  36. changing the order can invalidate saved queries and in general makes using the OGS stats difficult.
  37. */
  38. //--------------------------------------------------------------------------------------------------------
  39. enum CSWeaponID
  40. {
  41. WEAPON_NONE = 0,
  42. WEAPON_FIRST,
  43. WEAPON_DEAGLE = WEAPON_FIRST,
  44. WEAPON_ELITE,
  45. WEAPON_FIVESEVEN,
  46. WEAPON_GLOCK,
  47. WEAPON_P228,
  48. WEAPON_USP,
  49. WEAPON_AK47,
  50. WEAPON_AUG,
  51. WEAPON_AWP,
  52. WEAPON_FAMAS,
  53. WEAPON_G3SG1,
  54. WEAPON_GALIL,
  55. WEAPON_GALILAR,
  56. WEAPON_M249,
  57. WEAPON_M3,
  58. WEAPON_M4A1,
  59. WEAPON_MAC10,
  60. WEAPON_MP5NAVY,
  61. WEAPON_P90,
  62. WEAPON_SCOUT,
  63. WEAPON_SG550,
  64. WEAPON_SG552,
  65. WEAPON_TMP,
  66. WEAPON_UMP45,
  67. WEAPON_XM1014,
  68. WEAPON_BIZON,
  69. WEAPON_MAG7,
  70. WEAPON_NEGEV,
  71. WEAPON_SAWEDOFF,
  72. WEAPON_TEC9,
  73. WEAPON_TASER,
  74. WEAPON_HKP2000,
  75. WEAPON_MP7,
  76. WEAPON_MP9,
  77. WEAPON_NOVA,
  78. WEAPON_P250,
  79. WEAPON_SCAR17,
  80. WEAPON_SCAR20,
  81. WEAPON_SG556,
  82. WEAPON_SSG08,
  83. WEAPON_LAST = WEAPON_SSG08,
  84. ITEM_FIRST,
  85. WEAPON_KNIFE_GG = ITEM_FIRST,
  86. WEAPON_KNIFE,
  87. WEAPON_FLASHBANG,
  88. WEAPON_HEGRENADE,
  89. WEAPON_SMOKEGRENADE,
  90. WEAPON_MOLOTOV,
  91. WEAPON_DECOY,
  92. WEAPON_INCGRENADE,
  93. WEAPON_TAGRENADE,
  94. WEAPON_C4,
  95. ITEM_MAX = WEAPON_C4,
  96. EQUIPMENT_FIRST,
  97. ITEM_KEVLAR = EQUIPMENT_FIRST,
  98. ITEM_ASSAULTSUIT,
  99. ITEM_HEAVYASSAULTSUIT,
  100. ITEM_NVG,
  101. ITEM_DEFUSER,
  102. ITEM_CUTTERS,
  103. EQUIPMENT_MAX,
  104. WEAPON_HEALTHSHOT,
  105. WEAPON_MAX = EQUIPMENT_MAX, // number of weapons weapon index
  106. };
  107. #define MAX_EQUIPMENT (EQUIPMENT_MAX - EQUIPMENT_FIRST)
  108. enum
  109. {
  110. ITEM_PRICE_KEVLAR = 650,
  111. ITEM_PRICE_HELMET = 350,
  112. ITEM_PRICE_ASSAULTSUIT = ITEM_PRICE_KEVLAR + ITEM_PRICE_HELMET,
  113. ITEM_PRICE_HEAVYASSAULTSUIT = 1250,
  114. ITEM_PRICE_DEFUSEKIT = 400,
  115. ITEM_PRICE_NVG = 1250,
  116. };
  117. struct WeaponPaintableMaterial_t;
  118. void PrepareEquipmentInfo( void );
  119. class WeaponRecoilData
  120. {
  121. public:
  122. WeaponRecoilData();
  123. ~WeaponRecoilData();
  124. void GetRecoilOffsets( CWeaponCSBase *pWeapon, int iMode, int iIndex, float& fAngle, float &fMagnitude );
  125. void GenerateRecoilPatternForItemDefinition( item_definition_index_t idx );
  126. private:
  127. struct RecoilOffset
  128. {
  129. float fAngle;
  130. float fMagnitude;
  131. };
  132. struct RecoilData
  133. {
  134. item_definition_index_t iItemDefIndex;
  135. RecoilOffset recoilTable[2][64];
  136. };
  137. CUtlMap< item_definition_index_t, RecoilData* > m_mapRecoilTables;
  138. void GenerateRecoilTable( RecoilData *data );
  139. };
  140. //--------------------------------------------------------------------------------------------------------
  141. class CCSWeaponInfo : public FileWeaponInfo_t
  142. {
  143. public:
  144. DECLARE_CLASS_GAMEROOT( CCSWeaponInfo, FileWeaponInfo_t );
  145. CCSWeaponInfo();
  146. virtual void Parse( ::KeyValues *pKeyValuesData, const char *szWeaponName );
  147. // recoiltable in csweaponinfo is obsolete. remove this once confirmed that the new implementation generates the same result.
  148. virtual void RefreshDynamicParameters() { GenerateRecoilTable(); }
  149. const char *GetZoomInSound( void ) const { return m_szZoomINSound; }
  150. const char *GetZoomOutSound( void ) const { return m_szZoomOUTSound; }
  151. const Vector& GetSmokeColor() const { return m_vSmokeColor; }
  152. // recoiltable in csweaponinfo is obsolete. remove this once confirmed that the new implementation generates the same result.
  153. void GetRecoilOffsets( int iMode, int iIndex, float& fAngle, float &fMagnitude ) const;
  154. protected:
  155. CSWeaponType m_WeaponType;
  156. int m_iTeam; // Which team can have this weapon. TEAM_UNASSIGNED if both can have it.
  157. public:
  158. CSWeaponID m_weaponId;
  159. int GetWeaponPrice ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const;
  160. bool IsFullAuto ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const;
  161. bool HasSilencer ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const;
  162. int GetBullets ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const;
  163. float GetCycleTime ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const;
  164. float GetHeatPerShot ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const;
  165. float GetRecoveryTimeCrouch ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const;
  166. float GetRecoveryTimeStand ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const;
  167. float GetRecoveryTimeCrouchFinal ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const;
  168. float GetRecoveryTimeStandFinal ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const;
  169. int GetRecoveryTransitionStartBullet( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const;
  170. int GetRecoveryTransitionEndBullet ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const;
  171. int GetRecoilSeed ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const;
  172. float GetFlinchVelocityModifierLarge ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const;
  173. float GetFlinchVelocityModifierSmall ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const;
  174. float GetTimeToIdleAfterFire ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const;
  175. float GetIdleInterval ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const;
  176. float GetRange ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const;
  177. float GetRangeModifier ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const;
  178. int GetDamage ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const;
  179. float GetPenetration ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const;
  180. int GetCrosshairDeltaDistance ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const;
  181. int GetCrosshairMinDistance ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const;
  182. float GetInaccuracyAltSwitch ( void ) const { return m_fInaccuracyAltSwitch; };
  183. float GetInaccuracyPitchShift ( void ) const { return m_fInaccuracyPitchShift; }
  184. float GetInaccuracyAltSoundThreshhold ( void ) const { return m_fInaccuracyAltSoundThreshold; }
  185. float GetMaxSpeed ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const;
  186. float GetSpread ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 0.001f ) const;
  187. float GetInaccuracyCrouch ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 0.001f ) const;
  188. float GetInaccuracyStand ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 0.001f ) const;
  189. float GetInaccuracyJumpInitial ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 0.001f ) const;
  190. float GetInaccuracyJump ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 0.001f ) const;
  191. float GetInaccuracyLand ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 0.001f ) const;
  192. float GetInaccuracyLadder ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 0.001f ) const;
  193. float GetInaccuracyFire ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 0.001f ) const;
  194. float GetInaccuracyMove ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 0.001f ) const;
  195. float GetInaccuracyReload ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 0.001f ) const;
  196. float GetRecoilAngle ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const;
  197. float GetRecoilAngleVariance ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const;
  198. float GetRecoilMagnitude ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const;
  199. float GetRecoilMagnitudeVariance ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const;
  200. int GetTracerFrequency ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const;
  201. int GetPrimaryClipSize ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const;
  202. int GetSecondaryClipSize ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const;
  203. int GetDefaultPrimaryClipSize ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const;
  204. int GetDefaultSecondaryClipSize ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const;
  205. int GetKillAward ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const;
  206. bool HasBurstMode ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const;
  207. bool IsRevolver ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const;
  208. bool HasAlternateFastSlowReload ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const;
  209. float GetArmorRatio ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const;
  210. bool HasTraditionalScope ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const;
  211. bool CannotShootUnderwater ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const;
  212. bool DoesUnzoomAfterShot ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const;
  213. bool DoesHideViewModelWhenZoomed ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const;
  214. int GetBucketSlot ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const;
  215. int GetZoomLevels ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const;
  216. int GetZoomFOV1 ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const;
  217. int GetZoomFOV2 ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const;
  218. float GetZoomTime0 ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const;
  219. float GetZoomTime1 ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const;
  220. float GetZoomTime2 ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const;
  221. int GetPrimaryReserveAmmoMax ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const;
  222. int GetSecondaryReserveAmmoMax ( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const;
  223. CSWeaponType GetWeaponType ( const CEconItemView* pWepView = NULL ) const;
  224. const char* GetAddonLocation ( const CEconItemView* pWepView = NULL ) const;
  225. const char* GetEjectBrassEffectName ( const CEconItemView* pWepView = NULL ) const;
  226. const char* GetTracerEffectName ( const CEconItemView* pWepView = NULL ) const;
  227. const char* GetMuzzleFlashEffectName_1stPerson ( const CEconItemView* pWepView = NULL ) const;
  228. const char* GetMuzzleFlashEffectName_1stPersonAlt ( const CEconItemView* pWepView = NULL ) const;
  229. const char* GetMuzzleFlashEffectName_3rdPerson ( const CEconItemView* pWepView = NULL ) const;
  230. const char* GetMuzzleFlashEffectName_3rdPersonAlt ( const CEconItemView* pWepView = NULL ) const;
  231. const char* GetHeatEffectName ( const CEconItemView* pWepView = NULL ) const;
  232. const char* GetPlayerAnimationExtension ( const CEconItemView* pWepView = NULL ) const;
  233. void SetUsedByTeam ( int nTeam ) { m_iTeam = nTeam; }
  234. int GetUsedByTeam ( const CEconItemView* pWepView = NULL ) const;
  235. bool CanBeUsedWithShield() const { return m_bCanUseWithShield; }
  236. float GetBotAudibleRange() const { return m_flBotAudibleRange; }
  237. const char* GetWrongTeamMsg() const { return m_WrongTeamMsg; }
  238. const char* GetAnimExtension() const { return m_szAnimExtension; }
  239. const char* GetShieldViewModel() const { return m_szShieldViewModel; }
  240. const char* GetSilencerModel() const { return m_szSilencerModel; }
  241. float GetAddonScale() const { return m_flAddonScale; }
  242. float GetThrowVelocity() const { return m_fThrowVelocity; }
  243. const char* GetAddonModel ( const CEconItemView* pWepView = NULL ) const;
  244. const CUtlVector< WeaponPaintableMaterial_t >* GetPaintData( const CEconItemView* pWepView = NULL ) const;
  245. // recoiltable in csweaponinfo is obsolete. remove this once confirmed that the new implementation generates the same result.
  246. void GenerateRecoilTable();
  247. void SetWeaponPrice( int price ) { m_iWeaponPrice = price; };
  248. void SetWeaponType( CSWeaponType type ) { m_WeaponType = type; };
  249. private:
  250. static bool m_bCSWeaponInfoLookupInitialized;
  251. bool m_bFullAuto; // is this a fully automatic weapon?
  252. float m_flHeatPerShot;
  253. int m_iWeaponPrice;
  254. float m_flArmorRatio;
  255. float m_flMaxSpeed[2]; // How fast the player can run while this is his primary weapon.
  256. int m_iCrosshairMinDistance;
  257. int m_iCrosshairDeltaDistance;
  258. // Parameters for FX_FireBullets:
  259. float m_flPenetration;
  260. int m_iDamage;
  261. float m_flRange;
  262. float m_flRangeModifier;
  263. int m_iBullets;
  264. float m_flCycleTime;
  265. float m_flCycleTimeAlt;
  266. char m_szHeatEffectName[MAX_WEAPON_STRING];
  267. Vector m_vSmokeColor;
  268. char m_szMuzzleFlashEffectName_1stPerson[MAX_WEAPON_STRING];
  269. char m_szMuzzleFlashEffectName_3rdPerson[MAX_WEAPON_STRING];
  270. char m_szEjectBrassEffectName[MAX_WEAPON_STRING];
  271. char m_szTracerEffectName[MAX_WEAPON_STRING];
  272. int m_iTracerFequency;
  273. // variables for new accuracy model
  274. float m_fSpread[2];
  275. float m_fInaccuracyCrouch[2];
  276. float m_fInaccuracyStand[2];
  277. float m_fInaccuracyJump[2];
  278. float m_fInaccuracyLand[2];
  279. float m_fInaccuracyLadder[2];
  280. float m_fInaccuracyImpulseFire[2];
  281. float m_fInaccuracyMove[2];
  282. float m_fRecoveryTimeStand;
  283. float m_fRecoveryTimeCrouch;
  284. float m_fRecoveryTimeStandFinal;
  285. float m_fRecoveryTimeCrouchFinal;
  286. float m_fInaccuracyReload;
  287. float m_fInaccuracyAltSwitch;
  288. float m_fInaccuracyPitchShift;
  289. float m_fInaccuracyAltSoundThreshold;
  290. float m_fRecoilAngle[2];
  291. float m_fRecoilAngleVariance[2];
  292. float m_fRecoilMagnitude[2];
  293. float m_fRecoilMagnitudeVariance[2];
  294. int m_iRecoilSeed;
  295. float m_fFlinchVelocityModifierLarge; // velocity modifier for anyone hit by this weapon
  296. float m_fFlinchVelocityModifierSmall; // velocity modifier for anyone hit by this weapon
  297. // Delay until the next idle animation after shooting.
  298. float m_flTimeToIdleAfterFire;
  299. float m_flIdleInterval;
  300. // recoiltable in csweaponinfo is obsolete. remove this once confirmed that the new implementation generates the same result.
  301. struct RecoilOffset
  302. {
  303. float fAngle;
  304. float fMagnitude;
  305. };
  306. RecoilOffset m_recoilTable[2][64];
  307. int m_iZoomLevels;
  308. int m_iZoomFov[ 3 ];
  309. float m_fZoomTime[ 3 ];
  310. bool m_bHideViewModelZoomed;
  311. char m_szZoomINSound[ MAX_WEAPON_STRING ];
  312. char m_szZoomOUTSound[ MAX_WEAPON_STRING ];
  313. float m_flBotAudibleRange; // How far away a bot can hear this weapon.
  314. bool m_bCanUseWithShield;
  315. char m_WrongTeamMsg[ 32 ]; // Reference to a string describing the error if someone tries to buy
  316. // this weapon but they're on the wrong team to have it.
  317. // Zero-length if no specific message for this weapon.
  318. char m_szAnimExtension[ 16 ];
  319. char m_szShieldViewModel[ 64 ];
  320. char m_szAddonModel[ MAX_WEAPON_STRING ]; // If this is set, it is used as the addon model. Otherwise, szWorldModel is used.
  321. char m_szAddonLocation[ MAX_WEAPON_STRING ]; //If this is set, the weapon will look for an attachment location with this name. Otherwize the default is used based on weapon type.
  322. char m_szSilencerModel[ MAX_WEAPON_STRING ]; // Alternate model with silencer attached
  323. float m_flAddonScale;
  324. // grenade throw parameters
  325. float m_fThrowVelocity;
  326. int m_iKillAward;
  327. };
  328. //--------------------------------------------------------------------------------------------------------
  329. // Utility conversion functions
  330. //--------------------------------------------------------------------------------------------------------
  331. const char* WeaponClassAsString( CSWeaponType weaponType );
  332. CSWeaponType WeaponClassFromString( const char * weaponType );
  333. CSWeaponType WeaponClassFromWeaponID( CSWeaponID weaponID );
  334. const char* WeaponIdAsString( CSWeaponID weaponID );
  335. CSWeaponID WeaponIdFromString( const char *szWeaponName );
  336. const char *WeaponIDToAlias( int id );
  337. CSWeaponID AliasToWeaponID( const char *szAlias );
  338. const CCSWeaponInfo* GetWeaponInfo( CSWeaponID weaponID );
  339. bool IsGunWeapon( CSWeaponType weaponType );
  340. #endif // CS_WEAPON_PARSE_H