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.

280 lines
8.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include <stdarg.h>
  9. #include "engine/IEngineSound.h"
  10. #include "filesystem.h"
  11. #include "igamemovement.h"
  12. #include "engine/IEngineTrace.h"
  13. #include "engine/ivmodelinfo.h"
  14. // memdbgon must be the last include file in a .cpp file!!!
  15. #include "tier0/memdbgon.h"
  16. extern CMoveData *g_pMoveData;
  17. class CMoveHelperClient : public IMoveHelper
  18. {
  19. public:
  20. CMoveHelperClient( void );
  21. virtual ~CMoveHelperClient( void );
  22. char const* GetName( EntityHandle_t handle ) const;
  23. // touch lists
  24. virtual void ResetTouchList( void );
  25. virtual bool AddToTouched( const trace_t& tr, const Vector& impactvelocity );
  26. virtual void ProcessImpacts( void );
  27. // Numbered line printf
  28. virtual void Con_NPrintf( int idx, char const* fmt, ... );
  29. virtual bool PlayerFallingDamage(void);
  30. virtual void PlayerSetAnimation( PLAYER_ANIM eAnim );
  31. // These have separate server vs client impementations
  32. virtual void StartSound( const Vector& origin, int channel, char const* sample, float volume, soundlevel_t soundlevel, int fFlags, int pitch );
  33. virtual void StartSound( const Vector& origin, const char *soundname );
  34. virtual void PlaybackEventFull( int flags, int clientindex, unsigned short eventindex, float delay, Vector& origin, Vector& angles, float fparam1, float fparam2, int iparam1, int iparam2, int bparam1, int bparam2 );
  35. virtual IPhysicsSurfaceProps *GetSurfaceProps( void );
  36. virtual bool IsWorldEntity( const CBaseHandle &handle );
  37. private:
  38. // results, tallied on client and server, but only used by server to run SV_Impact.
  39. // we store off our velocity in the trace_t structure so that we can determine results
  40. // of shoving boxes etc. around.
  41. struct touchlist_t
  42. {
  43. Vector deltavelocity;
  44. trace_t trace;
  45. touchlist_t() {}
  46. private:
  47. touchlist_t( const touchlist_t &src );
  48. };
  49. CUtlVector<touchlist_t> m_TouchList;
  50. };
  51. //-----------------------------------------------------------------------------
  52. // Singleton
  53. //-----------------------------------------------------------------------------
  54. IMPLEMENT_MOVEHELPER();
  55. static CMoveHelperClient s_MoveHelperClient;
  56. //-----------------------------------------------------------------------------
  57. // Constructor
  58. //-----------------------------------------------------------------------------
  59. CMoveHelperClient::CMoveHelperClient( void )
  60. {
  61. SetSingleton( this );
  62. }
  63. CMoveHelperClient::~CMoveHelperClient( void )
  64. {
  65. SetSingleton( 0 );
  66. }
  67. //-----------------------------------------------------------------------------
  68. // Purpose:
  69. // Output : const char
  70. //-----------------------------------------------------------------------------
  71. char const* CMoveHelperClient::GetName( EntityHandle_t handle ) const
  72. {
  73. return "";
  74. }
  75. //-----------------------------------------------------------------------------
  76. // Touch list
  77. //-----------------------------------------------------------------------------
  78. void CMoveHelperClient::ResetTouchList( void )
  79. {
  80. m_TouchList.RemoveAll();
  81. }
  82. //-----------------------------------------------------------------------------
  83. // Adds to the touched list
  84. //-----------------------------------------------------------------------------
  85. bool CMoveHelperClient::AddToTouched( const trace_t& tr, const Vector& impactvelocity )
  86. {
  87. int i;
  88. // Look for duplicates
  89. for (i = 0; i < m_TouchList.Size(); i++)
  90. {
  91. if (m_TouchList[i].trace.m_pEnt == tr.m_pEnt)
  92. {
  93. return false;
  94. }
  95. }
  96. i = m_TouchList.AddToTail();
  97. m_TouchList[i].trace = tr;
  98. VectorCopy( impactvelocity, m_TouchList[i].deltavelocity );
  99. return true;
  100. }
  101. void CMoveHelperClient::ProcessImpacts( void )
  102. {
  103. C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer();
  104. if ( !pPlayer )
  105. return;
  106. // Relink in order to build absorigin and absmin/max to reflect any changes
  107. // from prediction. Relink will early out on SOLID_NOT
  108. // TODO: Touch triggers on the client
  109. //pPlayer->PhysicsTouchTriggers();
  110. // Don't bother if the player ain't solid
  111. if ( pPlayer->IsSolidFlagSet( FSOLID_NOT_SOLID ) )
  112. return;
  113. // Save off the velocity, cause we need to temporarily reset it
  114. Vector vel = pPlayer->GetAbsVelocity();
  115. // Touch other objects that were intersected during the movement.
  116. for (int i = 0 ; i < m_TouchList.Size(); i++)
  117. {
  118. // Run the impact function as if we had run it during movement.
  119. C_BaseEntity *entity = ClientEntityList().GetEnt( m_TouchList[i].trace.m_pEnt->entindex() );
  120. if ( !entity )
  121. continue;
  122. Assert( entity != pPlayer );
  123. // Don't ever collide with self!!!!
  124. if ( entity == pPlayer )
  125. continue;
  126. // Reconstruct trace results.
  127. m_TouchList[i].trace.m_pEnt = entity;
  128. // Use the velocity we had when we collided, so boxes will move, etc.
  129. pPlayer->SetAbsVelocity( m_TouchList[i].deltavelocity );
  130. entity->PhysicsImpact( pPlayer, m_TouchList[i].trace );
  131. }
  132. // Restore the velocity
  133. pPlayer->SetAbsVelocity( vel );
  134. // So no stuff is ever left over, sigh...
  135. ResetTouchList();
  136. }
  137. void CMoveHelperClient::StartSound( const Vector& origin, const char *soundname )
  138. {
  139. if ( !soundname )
  140. return;
  141. CLocalPlayerFilter filter;
  142. filter.UsePredictionRules();
  143. C_BaseEntity::EmitSound( filter, SOUND_FROM_LOCAL_PLAYER, soundname, &origin );
  144. }
  145. //-----------------------------------------------------------------------------
  146. // Play a sound
  147. //-----------------------------------------------------------------------------
  148. void CMoveHelperClient::StartSound( const Vector& origin, int channel,
  149. char const* pSample, float volume, soundlevel_t soundlevel, int fFlags, int pitch )
  150. {
  151. if ( pSample )
  152. {
  153. C_BaseEntity::PrecacheScriptSound( pSample );
  154. CLocalPlayerFilter filter;
  155. filter.UsePredictionRules();
  156. EmitSound_t ep;
  157. ep.m_nChannel = channel;
  158. ep.m_pSoundName = pSample;
  159. ep.m_flVolume = volume;
  160. ep.m_SoundLevel = soundlevel;
  161. ep.m_nPitch = pitch;
  162. ep.m_pOrigin = &origin;
  163. C_BaseEntity::EmitSound( filter, SOUND_FROM_LOCAL_PLAYER, ep );
  164. }
  165. }
  166. //-----------------------------------------------------------------------------
  167. // Play a event
  168. //-----------------------------------------------------------------------------
  169. void CMoveHelperClient::PlaybackEventFull( int flags, int clientindex, unsigned short eventindex, float delay, Vector& origin, Vector& angles, float fparam1, float fparam2, int iparam1, int iparam2, int bparam1, int bparam2 )
  170. {
  171. // TODO
  172. if (g_pMoveData->m_bFirstRunOfFunctions )
  173. {
  174. }
  175. }
  176. //-----------------------------------------------------------------------------
  177. // Surface properties interface
  178. //-----------------------------------------------------------------------------
  179. IPhysicsSurfaceProps *CMoveHelperClient::GetSurfaceProps( void )
  180. {
  181. extern IPhysicsSurfaceProps *physprops;
  182. return physprops;
  183. }
  184. //-----------------------------------------------------------------------------
  185. // Purpose:
  186. // Input : bDeveloper -
  187. // *pFormat -
  188. // ... -
  189. //-----------------------------------------------------------------------------
  190. void CMoveHelperClient::Con_NPrintf( int idx, char const* pFormat, ...)
  191. {
  192. va_list marker;
  193. char msg[8192];
  194. va_start(marker, pFormat);
  195. Q_vsnprintf(msg, sizeof( msg ), pFormat, marker);
  196. va_end(marker);
  197. #if defined( CSTRIKE_DLL ) || defined( DOD_DLL ) // reltodo
  198. engine->Con_NPrintf( idx, "%s", msg );
  199. #else
  200. engine->Con_NPrintf( idx, msg );
  201. #endif
  202. }
  203. //-----------------------------------------------------------------------------
  204. // Purpose: Called when the player falls onto a surface fast enough to take
  205. // damage, according to the rules in CGameMovement::CheckFalling.
  206. // Output : Returns true if the player survived the fall, false if they died.
  207. //-----------------------------------------------------------------------------
  208. bool CMoveHelperClient::PlayerFallingDamage(void)
  209. {
  210. // Do nothing; falling damage is applied in MoveHelper_Server::PlayerFallingDamage.
  211. return(true);
  212. }
  213. //-----------------------------------------------------------------------------
  214. // Purpose: Sets an animation in the player.
  215. // Input : eAnim - Animation to set.
  216. //-----------------------------------------------------------------------------
  217. void CMoveHelperClient::PlayerSetAnimation( PLAYER_ANIM eAnim )
  218. {
  219. // Do nothing on the client. Animations are set on the server.
  220. }
  221. bool CMoveHelperClient::IsWorldEntity( const CBaseHandle &handle )
  222. {
  223. return handle == cl_entitylist->GetNetworkableHandle( 0 );
  224. }