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.

161 lines
5.6 KiB

  1. //========= Copyright 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. class IFileSystem;
  14. typedef unsigned short WEAPON_FILE_INFO_HANDLE;
  15. // -----------------------------------------------------------
  16. // Weapon sound types
  17. // Used to play sounds defined in the weapon's classname.txt file
  18. // This needs to match pWeaponSoundCategories in weapon_parse.cpp
  19. // ------------------------------------------------------------
  20. typedef enum {
  21. EMPTY,
  22. SINGLE,
  23. SINGLE_NPC,
  24. WPN_DOUBLE, // Can't be "DOUBLE" because windows.h uses it.
  25. DOUBLE_NPC,
  26. BURST,
  27. RELOAD,
  28. RELOAD_NPC,
  29. MELEE_MISS,
  30. MELEE_HIT,
  31. MELEE_HIT_WORLD,
  32. SPECIAL1,
  33. SPECIAL2,
  34. SPECIAL3,
  35. TAUNT,
  36. DEPLOY,
  37. // Add new shoot sound types here
  38. NUM_SHOOT_SOUND_TYPES,
  39. } WeaponSound_t;
  40. int GetWeaponSoundFromString( const char *pszString );
  41. #define MAX_SHOOT_SOUNDS 16 // Maximum number of shoot sounds per shoot type
  42. #define MAX_WEAPON_STRING 80
  43. #define MAX_WEAPON_PREFIX 16
  44. #define MAX_WEAPON_AMMO_NAME 32
  45. #define WEAPON_PRINTNAME_MISSING "!!! Missing printname on weapon"
  46. class CHudTexture;
  47. class KeyValues;
  48. //-----------------------------------------------------------------------------
  49. // Purpose: Contains the data read from the weapon's script file.
  50. // It's cached so we only read each weapon's script file once.
  51. // Each game provides a CreateWeaponInfo function so it can have game-specific
  52. // data (like CS move speeds) in the weapon script.
  53. //-----------------------------------------------------------------------------
  54. class FileWeaponInfo_t
  55. {
  56. public:
  57. FileWeaponInfo_t();
  58. // Each game can override this to get whatever values it wants from the script.
  59. virtual void Parse( KeyValues *pKeyValuesData, const char *szWeaponName );
  60. public:
  61. bool bParsedScript;
  62. bool bLoadedHudElements;
  63. // SHARED
  64. char szClassName[MAX_WEAPON_STRING];
  65. char szPrintName[MAX_WEAPON_STRING]; // Name for showing in HUD, etc.
  66. char szViewModel[MAX_WEAPON_STRING]; // View model of this weapon
  67. char szWorldModel[MAX_WEAPON_STRING]; // Model of this weapon seen carried by the player
  68. char szAnimationPrefix[MAX_WEAPON_PREFIX]; // Prefix of the animations that should be used by the player carrying this weapon
  69. int iSlot; // inventory slot.
  70. int iPosition; // position in the inventory slot.
  71. int iMaxClip1; // max primary clip size (-1 if no clip)
  72. int iMaxClip2; // max secondary clip size (-1 if no clip)
  73. int iDefaultClip1; // amount of primary ammo in the gun when it's created
  74. int iDefaultClip2; // amount of secondary ammo in the gun when it's created
  75. int iWeight; // this value used to determine this weapon's importance in autoselection.
  76. int iRumbleEffect; // Which rumble effect to use when fired? (xbox)
  77. bool bAutoSwitchTo; // whether this weapon should be considered for autoswitching to
  78. bool bAutoSwitchFrom; // whether this weapon can be autoswitched away from when picking up another weapon or ammo
  79. int iFlags; // miscellaneous weapon flags
  80. char szAmmo1[MAX_WEAPON_AMMO_NAME]; // "primary" ammo type
  81. char szAmmo2[MAX_WEAPON_AMMO_NAME]; // "secondary" ammo type
  82. // Sound blocks
  83. char aShootSounds[NUM_SHOOT_SOUND_TYPES][MAX_WEAPON_STRING];
  84. int iAmmoType;
  85. int iAmmo2Type;
  86. bool m_bMeleeWeapon; // Melee weapons can always "fire" regardless of ammo.
  87. // This tells if the weapon was built right-handed (defaults to true).
  88. // This helps cl_righthand make the decision about whether to flip the model or not.
  89. bool m_bBuiltRightHanded;
  90. bool m_bAllowFlipping; // False to disallow flipping the model, regardless of whether
  91. // it is built left or right handed.
  92. // CLIENT DLL
  93. // Sprite data, read from the data file
  94. int iSpriteCount;
  95. CHudTexture *iconActive;
  96. CHudTexture *iconInactive;
  97. CHudTexture *iconAmmo;
  98. CHudTexture *iconAmmo2;
  99. CHudTexture *iconCrosshair;
  100. CHudTexture *iconAutoaim;
  101. CHudTexture *iconZoomedCrosshair;
  102. CHudTexture *iconZoomedAutoaim;
  103. CHudTexture *iconSmall;
  104. // TF2 specific
  105. bool bShowUsageHint; // if true, then when you receive the weapon, show a hint about it
  106. // SERVER DLL
  107. };
  108. // The weapon parse function
  109. bool ReadWeaponDataFromFileForSlot( IFileSystem* filesystem, const char *szWeaponName,
  110. WEAPON_FILE_INFO_HANDLE *phandle, const unsigned char *pICEKey = NULL );
  111. // If weapon info has been loaded for the specified class name, this returns it.
  112. WEAPON_FILE_INFO_HANDLE LookupWeaponInfoSlot( const char *name );
  113. FileWeaponInfo_t *GetFileWeaponInfoFromHandle( WEAPON_FILE_INFO_HANDLE handle );
  114. WEAPON_FILE_INFO_HANDLE GetInvalidWeaponInfoHandle( void );
  115. void PrecacheFileWeaponInfoDatabase( IFileSystem *filesystem, const unsigned char *pICEKey );
  116. //
  117. // Read a possibly-encrypted KeyValues file in.
  118. // If pICEKey is NULL, then it appends .txt to the filename and loads it as an unencrypted file.
  119. // If pICEKey is non-NULL, then it appends .ctx to the filename and loads it as an encrypted file.
  120. //
  121. // (This should be moved into a more appropriate place).
  122. //
  123. KeyValues* ReadEncryptedKVFile( IFileSystem *filesystem, const char *szFilenameWithoutExtension, const unsigned char *pICEKey, bool bForceReadEncryptedFile = false );
  124. // Each game implements this. It can return a derived class and override Parse() if it wants.
  125. extern FileWeaponInfo_t* CreateWeaponInfo();
  126. #endif // WEAPON_PARSE_H