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.

145 lines
4.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "c_tf_ammo_pack.h"
  8. // memdbgon must be the last include file in a .cpp file!!!
  9. #include "tier0/memdbgon.h"
  10. #ifdef _DEBUG
  11. static ConVar tf_debug_weapontrail( "tf_debug_weapontrail", "0", FCVAR_CHEAT | FCVAR_DEVELOPMENTONLY );
  12. #endif // _DEBUG
  13. // Network table.
  14. IMPLEMENT_CLIENTCLASS_DT( C_TFAmmoPack, DT_AmmoPack, CTFAmmoPack )
  15. RecvPropVector( RECVINFO( m_vecInitialVelocity ) ),
  16. RecvPropFloat( RECVINFO_NAME( m_angNetworkAngles[0], m_angRotation[0] ) ),
  17. RecvPropFloat( RECVINFO_NAME( m_angNetworkAngles[1], m_angRotation[1] ) ),
  18. RecvPropFloat( RECVINFO_NAME( m_angNetworkAngles[2], m_angRotation[2] ) ),
  19. END_RECV_TABLE()
  20. C_TFAmmoPack::C_TFAmmoPack( void )
  21. {
  22. m_nWorldModelIndex = 0;
  23. }
  24. C_TFAmmoPack::~C_TFAmmoPack( void )
  25. {
  26. }
  27. //-----------------------------------------------------------------------------
  28. // Purpose:
  29. // Input : flags -
  30. // Output : int
  31. //-----------------------------------------------------------------------------
  32. int C_TFAmmoPack::DrawModel( int flags )
  33. {
  34. #ifdef _DEBUG
  35. // Debug!
  36. if ( tf_debug_weapontrail.GetBool() )
  37. {
  38. Msg( "Ammo Pack:: Position: (%f %f %f), Velocity (%f %f %f)\n", GetAbsOrigin().x, GetAbsOrigin().y, GetAbsOrigin().z, GetAbsVelocity().x, GetAbsVelocity().y, GetAbsVelocity().z );
  39. if ( debugoverlay )
  40. {
  41. debugoverlay->AddBoxOverlay( GetAbsOrigin(), Vector( -2, -2, -2 ), Vector( 2, 2, 2 ), QAngle( 0, 0, 0 ), 255, 255, 0, 32, 5.0 );
  42. }
  43. }
  44. #endif // _DEBUG
  45. return BaseClass::DrawModel( flags );
  46. }
  47. //-----------------------------------------------------------------------------
  48. // Purpose:
  49. // Input : updateType -
  50. //-----------------------------------------------------------------------------
  51. void C_TFAmmoPack::OnDataChanged( DataUpdateType_t updateType )
  52. {
  53. BaseClass::OnDataChanged( updateType );
  54. #ifdef _DEBUG
  55. // Debug!
  56. if ( tf_debug_weapontrail.GetBool() )
  57. {
  58. Msg( "AbsOrigin (%f %f %f), LocalOrigin(%f %f %f)\n", GetAbsOrigin().x, GetAbsOrigin().y, GetAbsOrigin().z, GetLocalOrigin().x, GetLocalOrigin().y, GetLocalOrigin().z );
  59. }
  60. #endif // _DEBUG
  61. if ( updateType == DATA_UPDATE_CREATED )
  62. {
  63. #ifdef _DEBUG
  64. // Debug!
  65. if ( tf_debug_weapontrail.GetBool() )
  66. {
  67. Msg( "Origin (%f %f %f)\n", GetAbsOrigin().x, GetAbsOrigin().y, GetAbsOrigin().z );
  68. }
  69. #endif // _DEBUG
  70. float flChangeTime = GetLastChangeTime( LATCH_SIMULATION_VAR );
  71. Vector vecCurOrigin = GetLocalOrigin();
  72. // Now stick our initial velocity into the interpolation history
  73. CInterpolatedVar< Vector > &interpolator = GetOriginInterpolator();
  74. interpolator.ClearHistory();
  75. interpolator.AddToHead( flChangeTime - 0.15f, &vecCurOrigin, false );
  76. m_nWorldModelIndex = m_nModelIndex;
  77. }
  78. }
  79. int C_TFAmmoPack::GetWorldModelIndex( void )
  80. {
  81. if ( m_nWorldModelIndex == 0 )
  82. return m_nModelIndex;
  83. if ( GameRules() )
  84. {
  85. const char *pBaseName = modelinfo->GetModelName( modelinfo->GetModel( m_nWorldModelIndex ) );
  86. const char *pTranslatedName = GameRules()->TranslateEffectForVisionFilter( "weapons", pBaseName );
  87. if ( pTranslatedName != pBaseName )
  88. {
  89. return modelinfo->GetModelIndex( pTranslatedName );
  90. }
  91. }
  92. return m_nWorldModelIndex;
  93. }
  94. void C_TFAmmoPack::ValidateModelIndex( void )
  95. {
  96. m_nModelIndex = GetWorldModelIndex();
  97. BaseClass::ValidateModelIndex();
  98. }
  99. //-----------------------------------------------------------------------------
  100. // Purpose:
  101. // Input : currentTime -
  102. // Output : Returns true on success, false on failure.
  103. //-----------------------------------------------------------------------------
  104. bool C_TFAmmoPack::Interpolate( float currentTime )
  105. {
  106. return BaseClass::Interpolate( currentTime );
  107. }
  108. //-----------------------------------------------------------------------------
  109. // Purpose:
  110. // Input : *pPlayer -
  111. //-----------------------------------------------------------------------------
  112. void C_TFAmmoPack::DisplayHintTo( C_BasePlayer *pPlayer )
  113. {
  114. C_TFPlayer *pTFPlayer = ToTFPlayer(pPlayer);
  115. if ( pTFPlayer->IsPlayerClass( TF_CLASS_ENGINEER ) )
  116. {
  117. pTFPlayer->HintMessage( HINT_ENGINEER_PICKUP_METAL );
  118. }
  119. else
  120. {
  121. pTFPlayer->HintMessage( HINT_PICKUP_AMMO );
  122. }
  123. }