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.

193 lines
4.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "in_buttons.h"
  9. #include "takedamageinfo.h"
  10. #include "weapon_tfcbase.h"
  11. #include "ammodef.h"
  12. #include "tfc_gamerules.h"
  13. extern IVModelInfo* modelinfo;
  14. #if defined( CLIENT_DLL )
  15. #include "vgui/ISurface.h"
  16. #include "vgui_controls/Controls.h"
  17. #include "c_tfc_player.h"
  18. #include "hud_crosshair.h"
  19. #else
  20. #include "tfc_player.h"
  21. #endif
  22. // ----------------------------------------------------------------------------- //
  23. // Global functions.
  24. // ----------------------------------------------------------------------------- //
  25. bool IsAmmoType( int iAmmoType, const char *pAmmoName )
  26. {
  27. return GetAmmoDef()->Index( pAmmoName ) == iAmmoType;
  28. }
  29. // ----------------------------------------------------------------------------- //
  30. // CWeaponTFCBase tables.
  31. // ----------------------------------------------------------------------------- //
  32. IMPLEMENT_NETWORKCLASS_ALIASED( WeaponTFCBase, DT_WeaponTFCBase )
  33. BEGIN_NETWORK_TABLE( CWeaponTFCBase, DT_WeaponTFCBase )
  34. END_NETWORK_TABLE()
  35. BEGIN_PREDICTION_DATA( CWeaponTFCBase )
  36. END_PREDICTION_DATA()
  37. LINK_ENTITY_TO_CLASS( weapon_tfc_base, CWeaponTFCBase );
  38. #ifdef GAME_DLL
  39. BEGIN_DATADESC( CWeaponTFCBase )
  40. DEFINE_FUNCTION( FallThink )
  41. END_DATADESC()
  42. #endif
  43. #ifdef CLIENT_DLL
  44. ConVar cl_crosshaircolor( "cl_crosshaircolor", "0", FCVAR_CLIENTDLL | FCVAR_ARCHIVE );
  45. ConVar cl_dynamiccrosshair( "cl_dynamiccrosshair", "1", FCVAR_CLIENTDLL | FCVAR_ARCHIVE );
  46. ConVar cl_scalecrosshair( "cl_scalecrosshair", "1", FCVAR_CLIENTDLL | FCVAR_ARCHIVE );
  47. ConVar cl_crosshairalpha( "cl_crosshairalpha", "200", FCVAR_CLIENTDLL | FCVAR_ARCHIVE );
  48. int g_iScopeTextureID = 0;
  49. int g_iScopeDustTextureID = 0;
  50. #endif
  51. // ----------------------------------------------------------------------------- //
  52. // CWeaponTFCBase implementation.
  53. // ----------------------------------------------------------------------------- //
  54. CWeaponTFCBase::CWeaponTFCBase()
  55. {
  56. SetPredictionEligible( true );
  57. AddSolidFlags( FSOLID_TRIGGER ); // Nothing collides with these but it gets touches.
  58. }
  59. bool CWeaponTFCBase::IsPredicted() const
  60. {
  61. return true;
  62. }
  63. CTFCPlayer* CWeaponTFCBase::GetPlayerOwner() const
  64. {
  65. return dynamic_cast< CTFCPlayer* >( GetOwner() );
  66. }
  67. const CTFCWeaponInfo &CWeaponTFCBase::GetTFCWpnData() const
  68. {
  69. const FileWeaponInfo_t *pWeaponInfo = &GetWpnData();
  70. const CTFCWeaponInfo *pTFCInfo;
  71. #ifdef _DEBUG
  72. pTFCInfo = dynamic_cast< const CTFCWeaponInfo* >( pWeaponInfo );
  73. Assert( pTFCInfo );
  74. #else
  75. pTFCInfo = static_cast< const CTFCWeaponInfo* >( pWeaponInfo );
  76. #endif
  77. return *pTFCInfo;
  78. }
  79. TFCWeaponID CWeaponTFCBase::GetWeaponID( void ) const
  80. {
  81. Assert( false ); return WEAPON_NONE;
  82. }
  83. bool CWeaponTFCBase::IsA( TFCWeaponID id ) const
  84. {
  85. return GetWeaponID() == id;
  86. }
  87. bool CWeaponTFCBase::IsSilenced( void ) const
  88. {
  89. return false;
  90. }
  91. void CWeaponTFCBase::Precache( void )
  92. {
  93. BaseClass::Precache();
  94. }
  95. #ifdef CLIENT_DLL
  96. #else // CLIENT_DLL
  97. void CWeaponTFCBase::Spawn()
  98. {
  99. BaseClass::Spawn();
  100. // Set this here to allow players to shoot dropped weapons
  101. SetCollisionGroup( COLLISION_GROUP_WEAPON );
  102. // Move it up a little bit, otherwise it'll be at the guy's feet, and its sound origin
  103. // will be in the ground so its EmitSound calls won't do anything.
  104. SetLocalOrigin( Vector( 0, 0, 5 ) );
  105. }
  106. bool CWeaponTFCBase::DefaultReload( int iClipSize1, int iClipSize2, int iActivity )
  107. {
  108. if ( BaseClass::DefaultReload( iClipSize1, iClipSize2, iActivity ) )
  109. {
  110. SendReloadSoundEvent();
  111. return true;
  112. }
  113. else
  114. {
  115. return false;
  116. }
  117. }
  118. void CWeaponTFCBase::SendReloadSoundEvent()
  119. {
  120. CBasePlayer *pPlayer = GetPlayerOwner();
  121. assert( pPlayer );
  122. if ( !pPlayer )
  123. return;
  124. // Send a message to any clients that have this entity to play the reload.
  125. CPASFilter filter( pPlayer->GetAbsOrigin() );
  126. filter.RemoveRecipient( pPlayer );
  127. UserMessageBegin( filter, "ReloadEffect" );
  128. WRITE_SHORT( pPlayer->entindex() );
  129. MessageEnd();
  130. }
  131. Vector CWeaponTFCBase::GetSoundEmissionOrigin() const
  132. {
  133. CBasePlayer *pPlayer = GetPlayerOwner();
  134. if ( pPlayer )
  135. return pPlayer->WorldSpaceCenter();
  136. else
  137. return WorldSpaceCenter();
  138. }
  139. #endif