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.

195 lines
6.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include <KeyValues.h>
  8. #include "dod_weapon_parse.h"
  9. #include "dod_shareddefs.h"
  10. // criteria that we parse out of the file.
  11. // tells us which player animation states
  12. // should use the alternate wpn p model
  13. static struct
  14. {
  15. const char *m_pCriteriaName;
  16. int m_iFlagValue;
  17. } g_AltWpnCritera[] =
  18. {
  19. { "ALTWPN_CRITERIA_FIRING", ALTWPN_CRITERIA_FIRING },
  20. { "ALTWPN_CRITERIA_RELOADING", ALTWPN_CRITERIA_RELOADING },
  21. { "ALTWPN_CRITERIA_DEPLOYED", ALTWPN_CRITERIA_DEPLOYED },
  22. { "ALTWPN_CRITERIA_DEPLOYED_RELOAD", ALTWPN_CRITERIA_DEPLOYED_RELOAD },
  23. { "ALTWPN_CRITERIA_PRONE_DEPLOYED_RELOAD", ALTWPN_CRITERIA_PRONE_DEPLOYED_RELOAD }
  24. };
  25. FileWeaponInfo_t* CreateWeaponInfo()
  26. {
  27. return new CDODWeaponInfo;
  28. }
  29. CDODWeaponInfo::CDODWeaponInfo()
  30. {
  31. m_szReloadModel[0] = '\0';
  32. m_szDeployedModel[0] = '\0';
  33. m_szDeployedReloadModel[0] = '\0';
  34. m_szProneDeployedReloadModel[0] = '\0';
  35. }
  36. void CDODWeaponInfo::Parse( KeyValues *pKeyValuesData, const char *szWeaponName )
  37. {
  38. BaseClass::Parse( pKeyValuesData, szWeaponName );
  39. m_iCrosshairMinDistance = pKeyValuesData->GetInt( "CrosshairMinDistance", 4 );
  40. m_iCrosshairDeltaDistance = pKeyValuesData->GetInt( "CrosshairDeltaDistance", 3 );
  41. m_iMuzzleFlashType = pKeyValuesData->GetFloat( "MuzzleFlashType", 0 );
  42. m_flMuzzleFlashScale = pKeyValuesData->GetFloat( "MuzzleFlashScale", 0.5 );
  43. m_iDamage = pKeyValuesData->GetInt( "Damage", 1 );
  44. m_flAccuracy = pKeyValuesData->GetFloat( "Accuracy", 1.0 );
  45. m_flSecondaryAccuracy = pKeyValuesData->GetFloat( "SecondaryAccuracy", 1.0 );
  46. m_flAccuracyMovePenalty = pKeyValuesData->GetFloat( "AccuracyMovePenalty", 0.1 );
  47. m_flRecoil = pKeyValuesData->GetFloat( "Recoil", 99.0 );
  48. m_flPenetration = pKeyValuesData->GetFloat( "Penetration", 1.0 );
  49. m_flFireDelay = pKeyValuesData->GetFloat( "FireDelay", 0.1 );
  50. m_flSecondaryFireDelay = pKeyValuesData->GetFloat( "SecondaryFireDelay", 0.1 );
  51. m_flTimeToIdleAfterFire = pKeyValuesData->GetFloat( "IdleTimeAfterFire", 1.0 );
  52. m_flIdleInterval = pKeyValuesData->GetFloat( "IdleInterval", 1.0 );
  53. m_bCanDrop = ( pKeyValuesData->GetInt( "CanDrop", 1 ) > 0 );
  54. m_iBulletsPerShot = pKeyValuesData->GetInt( "BulletsPerShot", 1 );
  55. m_iHudClipHeight = pKeyValuesData->GetInt( "HudClipHeight", 0 );
  56. m_iHudClipBaseHeight = pKeyValuesData->GetInt( "HudClipBaseHeight", 0 );
  57. m_iHudClipBulletHeight = pKeyValuesData->GetInt( "HudClipBulletHeight", 0 );
  58. m_iAmmoPickupClips = pKeyValuesData->GetInt( "AmmoPickupClips", 2 );
  59. m_iDefaultAmmoClips = pKeyValuesData->GetInt( "DefaultAmmoClips", 0 );
  60. m_flViewModelFOV = pKeyValuesData->GetFloat( "ViewModelFOV", 90.0f );
  61. // const char *pAnimEx = pKeyValuesData->GetString( "PlayerAnimationExtension", "error" );
  62. // Q_strncpy( m_szAnimExtension, pAnimEx, sizeof( m_szAnimExtension ) );
  63. // if this key exists, use this for reload animations instead of anim_prefix
  64. // Q_strncpy( m_szReloadAnimPrefix, pKeyValuesData->GetString( "reload_anim_prefix", "" ), MAX_WEAPON_PREFIX );
  65. m_flBotAudibleRange = pKeyValuesData->GetFloat( "BotAudibleRange", 2000.0f );
  66. m_iTracerType = pKeyValuesData->GetInt( "Tracer", 0 );
  67. //Weapon Type
  68. const char *pTypeString = pKeyValuesData->GetString( "WeaponType", NULL );
  69. m_WeaponType = WPN_TYPE_UNKNOWN;
  70. if ( !pTypeString )
  71. {
  72. Assert( false );
  73. }
  74. else if ( Q_stricmp( pTypeString, "Melee" ) == 0 )
  75. {
  76. m_WeaponType = WPN_TYPE_MELEE;
  77. }
  78. else if ( Q_stricmp( pTypeString, "Camera" ) == 0 )
  79. {
  80. m_WeaponType = WPN_TYPE_CAMERA;
  81. }
  82. else if ( Q_stricmp( pTypeString, "Grenade" ) == 0 )
  83. {
  84. m_WeaponType = WPN_TYPE_GRENADE;
  85. }
  86. else if ( Q_stricmp( pTypeString, "Pistol" ) == 0 )
  87. {
  88. m_WeaponType = WPN_TYPE_PISTOL;
  89. }
  90. else if ( Q_stricmp( pTypeString, "Rifle" ) == 0 )
  91. {
  92. m_WeaponType = WPN_TYPE_RIFLE;
  93. }
  94. else if ( Q_stricmp( pTypeString, "Sniper" ) == 0 )
  95. {
  96. m_WeaponType = WPN_TYPE_SNIPER;
  97. }
  98. else if ( Q_stricmp( pTypeString, "SubMG" ) == 0 )
  99. {
  100. m_WeaponType = WPN_TYPE_SUBMG;
  101. }
  102. else if ( Q_stricmp( pTypeString, "MG" ) == 0 )
  103. {
  104. m_WeaponType = WPN_TYPE_MG;
  105. }
  106. else if ( Q_stricmp( pTypeString, "Bazooka" ) == 0 )
  107. {
  108. m_WeaponType = WPN_TYPE_BAZOOKA;
  109. }
  110. else if ( Q_stricmp( pTypeString, "Bandage" ) == 0 )
  111. {
  112. m_WeaponType = WPN_TYPE_BANDAGE;
  113. }
  114. else if ( Q_stricmp( pTypeString, "Sidearm" ) == 0 )
  115. {
  116. m_WeaponType = WPN_TYPE_SIDEARM;
  117. }
  118. else if ( Q_stricmp( pTypeString, "RifleGrenade" ) == 0 )
  119. {
  120. m_WeaponType = WPN_TYPE_RIFLEGRENADE;
  121. }
  122. else if ( Q_stricmp( pTypeString, "Bomb" ) == 0 )
  123. {
  124. m_WeaponType = WPN_TYPE_BOMB;
  125. }
  126. else
  127. {
  128. Assert( false );
  129. }
  130. Q_strncpy( m_szReloadModel, pKeyValuesData->GetString( "reloadmodel" ), sizeof( m_szReloadModel ) );
  131. Q_strncpy( m_szDeployedModel, pKeyValuesData->GetString( "deployedmodel" ), sizeof( m_szDeployedModel ) );
  132. Q_strncpy( m_szDeployedReloadModel, pKeyValuesData->GetString( "deployedreloadmodel" ), sizeof( m_szDeployedReloadModel ) );
  133. Q_strncpy( m_szProneDeployedReloadModel, pKeyValuesData->GetString( "pronedeployedreloadmodel" ), sizeof( m_szProneDeployedReloadModel ) );
  134. m_iAltWpnCriteria = ALTWPN_CRITERIA_NONE;
  135. for ( int i=0; i < ARRAYSIZE( g_AltWpnCritera ); i++ )
  136. {
  137. int iVal = pKeyValuesData->GetInt( g_AltWpnCritera[i].m_pCriteriaName, 0 );
  138. if ( iVal == 1 )
  139. {
  140. m_iAltWpnCriteria |= g_AltWpnCritera[i].m_iFlagValue;
  141. }
  142. }
  143. const char *szNormalOffset = pKeyValuesData->GetString( "vm_normal_offset", "0 0 0" );
  144. const char *szProneOffset = pKeyValuesData->GetString( "vm_prone_offset", "0 0 0" );
  145. const char *szIronSightOffset = pKeyValuesData->GetString( "vm_ironsight_offset", "0 0 0" );
  146. sscanf( szNormalOffset, "%f %f %f", &m_vecViewNormalOffset[0], &m_vecViewNormalOffset[1], &m_vecViewNormalOffset[2]);
  147. sscanf( szProneOffset, "%f %f %f", &m_vecViewProneOffset[0], &m_vecViewProneOffset[1], &m_vecViewProneOffset[2]);
  148. sscanf( szIronSightOffset, "%f %f %f", &m_vecIronSightOffset[0], &m_vecIronSightOffset[1], &m_vecIronSightOffset[2]);
  149. m_iDefaultTeam = TEAM_ALLIES;
  150. const char *pDefaultTeam = pKeyValuesData->GetString( "default_team", NULL );
  151. if ( pDefaultTeam )
  152. {
  153. if ( FStrEq( pDefaultTeam, "Axis" ) )
  154. {
  155. m_iDefaultTeam = TEAM_AXIS;
  156. }
  157. else if ( FStrEq( pDefaultTeam, "Allies" ) )
  158. {
  159. m_iDefaultTeam = TEAM_ALLIES;
  160. }
  161. else
  162. {
  163. Assert( !"invalid param to \"default_team\" in weapon scripts\n" );
  164. }
  165. }
  166. }