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.

135 lines
3.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "hl1mp_basecombatweapon_shared.h"
  9. #include "effect_dispatch_data.h"
  10. #ifdef CLIENT_DLL
  11. #include "c_te_effect_dispatch.h"
  12. #else
  13. #include "te_effect_dispatch.h"
  14. #endif
  15. #include "hl1_player_shared.h"
  16. LINK_ENTITY_TO_CLASS( basehl1mpcombatweapon, CBaseHL1MPCombatWeapon );
  17. IMPLEMENT_NETWORKCLASS_ALIASED( BaseHL1MPCombatWeapon , DT_BaseHL1MPCombatWeapon )
  18. BEGIN_NETWORK_TABLE( CBaseHL1MPCombatWeapon , DT_BaseHL1MPCombatWeapon )
  19. END_NETWORK_TABLE()
  20. BEGIN_PREDICTION_DATA( CBaseHL1MPCombatWeapon )
  21. END_PREDICTION_DATA()
  22. CBaseHL1MPCombatWeapon::CBaseHL1MPCombatWeapon()
  23. {
  24. SetPredictionEligible( true );
  25. AddSolidFlags( FSOLID_TRIGGER ); // Nothing collides with these but it gets touches.
  26. }
  27. void CBaseHL1MPCombatWeapon::EjectShell( CBaseEntity *pPlayer, int iType )
  28. {
  29. QAngle angShellAngles = pPlayer->GetAbsAngles();
  30. Vector vecForward, vecRight, vecUp;
  31. AngleVectors( angShellAngles, &vecForward, &vecRight, &vecUp );
  32. Vector vecShellPosition = pPlayer->GetAbsOrigin() + pPlayer->GetViewOffset();
  33. switch ( iType )
  34. {
  35. case 0:
  36. default:
  37. vecShellPosition += vecRight * 4;
  38. vecShellPosition += vecUp * -12;
  39. vecShellPosition += vecForward * 20;
  40. break;
  41. case 1:
  42. vecShellPosition += vecRight * 6;
  43. vecShellPosition += vecUp * -12;
  44. vecShellPosition += vecForward * 32;
  45. break;
  46. }
  47. Vector vecShellVelocity = vec3_origin; // pPlayer->GetAbsVelocity();
  48. vecShellVelocity += vecRight * random->RandomFloat( 50, 70 );
  49. vecShellVelocity += vecUp * random->RandomFloat( 100, 150 );
  50. vecShellVelocity += vecForward * 25;
  51. angShellAngles.x = 0;
  52. angShellAngles.z = 0;
  53. CEffectData data;
  54. data.m_vStart = vecShellVelocity;
  55. data.m_vOrigin = vecShellPosition;
  56. data.m_vAngles = angShellAngles;
  57. data.m_fFlags = iType;
  58. DispatchEffect( "HL1ShellEject", data );
  59. }
  60. #ifdef CLIENT_DLL
  61. void CBaseHL1MPCombatWeapon::OnDataChanged( DataUpdateType_t type )
  62. {
  63. BaseClass::OnDataChanged( type );
  64. if ( GetPredictable() && !ShouldPredict() )
  65. ShutdownPredictable();
  66. }
  67. bool CBaseHL1MPCombatWeapon::ShouldPredict()
  68. {
  69. if ( GetOwner() && GetOwner() == C_BasePlayer::GetLocalPlayer() )
  70. return true;
  71. return BaseClass::ShouldPredict();
  72. }
  73. void CBaseHL1MPCombatWeapon::ApplyBoneMatrixTransform( matrix3x4_t& transform )
  74. {
  75. BaseClass::ApplyBoneMatrixTransform( transform );
  76. }
  77. #endif
  78. bool CBaseHL1MPCombatWeapon::IsPredicted() const
  79. {
  80. return true;
  81. }
  82. CBasePlayer* CBaseHL1MPCombatWeapon::GetPlayerOwner() const
  83. {
  84. return dynamic_cast< CBasePlayer* >( GetOwner() );
  85. }
  86. void CBaseHL1MPCombatWeapon::WeaponSound( WeaponSound_t sound_type, float soundtime /* = 0.0f */ )
  87. {
  88. #ifdef CLIENT_DLL
  89. // If we have some sounds from the weapon classname.txt file, play a random one of them
  90. const char *shootsound = GetWpnData().aShootSounds[ sound_type ];
  91. if ( !shootsound || !shootsound[0] )
  92. return;
  93. CBroadcastRecipientFilter filter; // this is client side only
  94. if ( !te->CanPredict() )
  95. return;
  96. CBaseEntity::EmitSound( filter, GetPlayerOwner()->entindex(), shootsound, &GetPlayerOwner()->GetAbsOrigin() );
  97. #else
  98. BaseClass::WeaponSound( sound_type, soundtime );
  99. #endif
  100. }