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.

256 lines
8.5 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Weapon data file parsing, shared by game & client dlls.
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef WEAPON_PARSE_H
  8. #define WEAPON_PARSE_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "shareddefs.h"
  13. #include "GameEventListener.h"
  14. #include "tier1/utlsortvector.h"
  15. #include "gamestringpool.h"
  16. #ifdef CLIENT_DLL
  17. #define CEconItemView C_EconItemView
  18. #endif
  19. class IFileSystem;
  20. class CEconItemView;
  21. typedef unsigned short WEAPON_FILE_INFO_HANDLE;
  22. // -----------------------------------------------------------
  23. // Weapon sound types
  24. // Used to play sounds defined in the weapon's classname.txt file
  25. // This needs to match pWeaponSoundCategories in weapon_parse.cpp
  26. // ------------------------------------------------------------
  27. enum WeaponSound_t {
  28. EMPTY,
  29. SINGLE,
  30. SINGLE_ACCURATE,
  31. SINGLE_NPC,
  32. WPN_DOUBLE, // Can't be "DOUBLE" because windows.h uses it.
  33. DOUBLE_NPC,
  34. BURST,
  35. RELOAD,
  36. RELOAD_NPC,
  37. MELEE_MISS,
  38. MELEE_HIT,
  39. MELEE_HIT_WORLD,
  40. SPECIAL1,
  41. SPECIAL2,
  42. SPECIAL3,
  43. TAUNT,
  44. NEARLYEMPTY,
  45. FAST_RELOAD,
  46. // Add new shoot sound types here
  47. NUM_SHOOT_SOUND_TYPES,
  48. };
  49. int GetWeaponSoundFromString( const char *pszString );
  50. #define MAX_SHOOT_SOUNDS 16 // Maximum number of shoot sounds per shoot type
  51. #define MAX_WEAPON_STRING 80
  52. #define MAX_WEAPON_PREFIX 16
  53. #define MAX_WEAPON_AMMO_NAME 32
  54. #define WEAPON_PRINTNAME_MISSING "!!! Missing printname on weapon"
  55. class CHudTexture;
  56. class KeyValues;
  57. struct WeaponInfoLookup
  58. {
  59. size_t m_nWeaponParseDataOffset;
  60. _fieldtypes m_fieldType;
  61. CGameString m_iszAttribClassName;
  62. WeaponInfoLookup( void ) {}
  63. WeaponInfoLookup( size_t offset, _fieldtypes p_fieldType, const char* szAttribClassName );
  64. WeaponInfoLookup( const WeaponInfoLookup &WepInfoLookup );
  65. };
  66. class CWeaponInfoLookupListLess
  67. {
  68. public:
  69. bool Less( WeaponInfoLookup * const &src1, WeaponInfoLookup * const &src2, void *pCtx )
  70. {
  71. if ( src1->m_iszAttribClassName.Get() < src2->m_iszAttribClassName.Get() )
  72. return true;
  73. return false;
  74. }
  75. };
  76. //-----------------------------------------------------------------------------
  77. // Purpose: Contains the data read from the weapon's script file.
  78. // It's cached so we only read each weapon's script file once.
  79. // Each game provides a CreateWeaponInfo function so it can have game-specific
  80. // data (like CS move speeds) in the weapon script.
  81. //-----------------------------------------------------------------------------
  82. class FileWeaponInfo_t
  83. {
  84. public:
  85. FileWeaponInfo_t();
  86. virtual ~FileWeaponInfo_t() {}
  87. // Each game can override this to get whatever values it wants from the script.
  88. virtual void Parse( KeyValues *pKeyValuesData, const char *szWeaponName );
  89. virtual void RefreshDynamicParameters() {};
  90. public:
  91. bool bParsedScript;
  92. bool bLoadedHudElements;
  93. // SHARED
  94. char szClassName[MAX_WEAPON_STRING];
  95. char szPrintName[MAX_WEAPON_STRING]; // Name for showing in HUD, etc.
  96. int GetIndexofAttribute( string_t iszAttribClassName ) const;
  97. static CUtlSortVector< WeaponInfoLookup*, CWeaponInfoLookupListLess > ms_vecWeaponInfoLookup;
  98. protected:
  99. char szViewModel[MAX_WEAPON_STRING]; // View model of this weapon
  100. char szWorldModel[MAX_WEAPON_STRING]; // Model of this weapon seen carried by the player
  101. char szAmmo1[MAX_WEAPON_AMMO_NAME]; // "primary" ammo type
  102. char szWorldDroppedModel[MAX_WEAPON_STRING];
  103. static bool ms_bWeaponInfoLookupInitialized;
  104. public:
  105. char szAnimationPrefix[MAX_WEAPON_PREFIX]; // Prefix of the animations that should be used by the player carrying this weapon
  106. int iSlot; // inventory slot.
  107. int iPosition; // position in the inventory slot.
  108. int iMaxClip1; // max primary clip size (-1 if no clip)
  109. int iMaxClip2; // max secondary clip size (-1 if no clip)
  110. int iDefaultClip1; // amount of primary ammo in the gun when it's created
  111. int iDefaultClip2; // amount of secondary ammo in the gun when it's created
  112. int iWeight; // this value used to determine this weapon's importance in autoselection.
  113. int iRumbleEffect; // Which rumble effect to use when fired? (xbox)
  114. bool bAutoSwitchTo; // whether this weapon should be considered for autoswitching to
  115. bool bAutoSwitchFrom; // whether this weapon can be autoswitched away from when picking up another weapon or ammo
  116. int iFlags; // miscellaneous weapon flags
  117. char szAmmo2[MAX_WEAPON_AMMO_NAME]; // "secondary" ammo type
  118. char szAIAddOn[MAX_WEAPON_STRING]; // addon that this weapon can become
  119. // Sound blocks
  120. char aShootSounds[NUM_SHOOT_SOUND_TYPES][MAX_WEAPON_STRING];
  121. private:
  122. int iAmmoType;
  123. int iAmmo2Type;
  124. public:
  125. bool m_bMeleeWeapon; // Melee weapons can always "fire" regardless of ammo.
  126. // This tells if the weapon was built right-handed (defaults to true).
  127. // This helps cl_righthand make the decision about whether to flip the model or not.
  128. bool m_bBuiltRightHanded;
  129. bool m_bAllowFlipping; // False to disallow flipping the model, regardless of whether
  130. // it is built left or right handed.
  131. virtual int GetPrimaryClipSize( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const { return 0; }
  132. virtual int GetSecondaryClipSize( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const { return 0; }
  133. virtual int GetDefaultPrimaryClipSize( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const { return 0; }
  134. virtual int GetDefaultSecondaryClipSize( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const{ return 0; }
  135. virtual int GetPrimaryReserveAmmoMax( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const{ return 0; }
  136. virtual int GetSecondaryReserveAmmoMax( const CEconItemView* pWepView = NULL, int nAlt = 0, float flScale = 1.0f ) const{ return 0; }
  137. const char* GetWorldModel( const CEconItemView* pWepView = NULL, int iTeam = 0 ) const;
  138. const char* GetViewModel( const CEconItemView* pWepView = NULL, int iTeam = 0 ) const;
  139. const char* GetWorldDroppedModel( const CEconItemView* pWepView = NULL, int iTeam = 0 ) const;
  140. const char* GetPrimaryAmmo( const CEconItemView* pWepView = NULL ) const;
  141. int GetPrimaryAmmoType( const CEconItemView* pWepView = NULL ) const;
  142. // CLIENT DLL
  143. // Sprite data, read from the data file
  144. int iSpriteCount;
  145. CHudTexture *iconActive;
  146. CHudTexture *iconInactive;
  147. CHudTexture *iconAmmo;
  148. CHudTexture *iconAmmo2;
  149. CHudTexture *iconCrosshair;
  150. CHudTexture *iconAutoaim;
  151. CHudTexture *iconZoomedCrosshair;
  152. CHudTexture *iconZoomedAutoaim;
  153. CHudTexture *iconSmall;
  154. // TF2 specific
  155. bool bShowUsageHint; // if true, then when you receive the weapon, show a hint about it
  156. // SERVER DLL
  157. };
  158. WEAPON_FILE_INFO_HANDLE LookupWeaponInfoSlot( const char *name );
  159. FileWeaponInfo_t *GetFileWeaponInfoFromHandle( WEAPON_FILE_INFO_HANDLE handle );
  160. WEAPON_FILE_INFO_HANDLE GetInvalidWeaponInfoHandle( void );
  161. void PrecacheFileWeaponInfoDatabase();
  162. //
  163. // Read a possibly-encrypted KeyValues file in.
  164. // If pICEKey is NULL, then it appends .txt to the filename and loads it as an unencrypted file.
  165. // If pICEKey is non-NULL, then it appends .ctx to the filename and loads it as an encrypted file.
  166. //
  167. // (This should be moved into a more appropriate place).
  168. //
  169. KeyValues* ReadEncryptedKVFile( IFileSystem *filesystem, const char *szFilenameWithoutExtension, const unsigned char *pICEKey, bool bForceReadEncryptedFile = false );
  170. // Each game implements this. It can return a derived class and override Parse() if it wants.
  171. extern FileWeaponInfo_t* CreateWeaponInfo();
  172. extern void LoadEquipmentData();
  173. class CWeaponDatabase : public CAutoGameSystem, public CGameEventListener
  174. {
  175. public:
  176. CWeaponDatabase();
  177. void Reset();
  178. bool LoadManifest();
  179. void PrecacheAllWeapons();
  180. void RefreshAllWeapons();
  181. WEAPON_FILE_INFO_HANDLE FindWeaponInfo( const char *name );
  182. FileWeaponInfo_t *GetFileWeaponInfoFromHandle( WEAPON_FILE_INFO_HANDLE handle );
  183. protected:
  184. friend void LoadEquipmentData();
  185. virtual bool Init();
  186. WEAPON_FILE_INFO_HANDLE FindOrCreateWeaponInfo( const char *name );
  187. bool LoadWeaponDataFromFile( IFileSystem* filesystem, const char *szWeaponName, const unsigned char *pICEKey );
  188. void FireGameEvent( IGameEvent *event );
  189. private:
  190. CUtlDict< FileWeaponInfo_t*, unsigned short > m_WeaponInfoDatabase;
  191. bool m_bPreCached;
  192. };
  193. extern CWeaponDatabase g_WeaponDatabase;
  194. #endif // WEAPON_PARSE_H