Counter Strike : Global Offensive Source Code
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.

290 lines
8.4 KiB

  1. //========= Copyright � 1996-2005, 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. void SetHost( CBaseEntity *host );
  38. private:
  39. // results, tallied on client and server, but only used by server to run SV_Impact.
  40. // we store off our velocity in the trace_t structure so that we can determine results
  41. // of shoving boxes etc. around.
  42. struct touchlist_t
  43. {
  44. Vector deltavelocity;
  45. trace_t trace;
  46. touchlist_t() {}
  47. private:
  48. touchlist_t( const touchlist_t &src );
  49. };
  50. CUtlVector<touchlist_t> m_TouchList;
  51. CBaseEntity* m_pHost;
  52. };
  53. //-----------------------------------------------------------------------------
  54. // Singleton
  55. //-----------------------------------------------------------------------------
  56. IMPLEMENT_MOVEHELPER();
  57. static CMoveHelperClient s_MoveHelperClient;
  58. //-----------------------------------------------------------------------------
  59. // Constructor
  60. //-----------------------------------------------------------------------------
  61. CMoveHelperClient::CMoveHelperClient( void )
  62. {
  63. m_pHost = 0;
  64. SetSingleton( this );
  65. }
  66. CMoveHelperClient::~CMoveHelperClient( void )
  67. {
  68. SetSingleton( 0 );
  69. }
  70. //-----------------------------------------------------------------------------
  71. // Indicates which entity we're going to move
  72. //-----------------------------------------------------------------------------
  73. void CMoveHelperClient::SetHost( CBaseEntity *host )
  74. {
  75. m_pHost = host;
  76. // In case any stuff is ever left over, sigh...
  77. ResetTouchList();
  78. }
  79. //-----------------------------------------------------------------------------
  80. // Purpose:
  81. // Output : const char
  82. //-----------------------------------------------------------------------------
  83. char const* CMoveHelperClient::GetName( EntityHandle_t handle ) const
  84. {
  85. return "";
  86. }
  87. //-----------------------------------------------------------------------------
  88. // Touch list
  89. //-----------------------------------------------------------------------------
  90. void CMoveHelperClient::ResetTouchList( void )
  91. {
  92. m_TouchList.RemoveAll();
  93. }
  94. //-----------------------------------------------------------------------------
  95. // Adds to the touched list
  96. //-----------------------------------------------------------------------------
  97. bool CMoveHelperClient::AddToTouched( const trace_t& tr, const Vector& impactvelocity )
  98. {
  99. int i;
  100. // Look for duplicates
  101. for (i = 0; i < m_TouchList.Count(); i++)
  102. {
  103. if (m_TouchList[i].trace.m_pEnt == tr.m_pEnt)
  104. {
  105. return false;
  106. }
  107. }
  108. i = m_TouchList.AddToTail();
  109. m_TouchList[i].trace = tr;
  110. VectorCopy( impactvelocity, m_TouchList[i].deltavelocity );
  111. return true;
  112. }
  113. void CMoveHelperClient::ProcessImpacts( void )
  114. {
  115. m_pHost->PhysicsTouchTriggers();
  116. // Don't bother if the player ain't solid
  117. if ( m_pHost->IsSolidFlagSet( FSOLID_NOT_SOLID ) )
  118. return;
  119. // Save off the velocity, cause we need to temporarily reset it
  120. Vector vel = m_pHost->GetAbsVelocity();
  121. // Touch other objects that were intersected during the movement.
  122. for (int i = 0 ; i < m_TouchList.Count(); i++)
  123. {
  124. // Run the impact function as if we had run it during movement.
  125. C_BaseEntity *entity = ClientEntityList().GetEnt( m_TouchList[i].trace.m_pEnt->entindex() );
  126. if ( !entity )
  127. continue;
  128. Assert( entity != m_pHost );
  129. // Don't ever collide with self!!!!
  130. if ( entity == m_pHost )
  131. continue;
  132. // Reconstruct trace results.
  133. m_TouchList[i].trace.m_pEnt = entity;
  134. // Use the velocity we had when we collided, so boxes will move, etc.
  135. m_pHost->SetAbsVelocity( m_TouchList[i].deltavelocity );
  136. entity->PhysicsImpact( m_pHost, m_TouchList[i].trace );
  137. }
  138. // Restore the velocity
  139. m_pHost->SetAbsVelocity( vel );
  140. // So no stuff is ever left over, sigh...
  141. ResetTouchList();
  142. }
  143. void CMoveHelperClient::StartSound( const Vector& origin, const char *soundname )
  144. {
  145. if ( !soundname )
  146. return;
  147. CLocalPlayerFilter filter;
  148. filter.UsePredictionRules();
  149. C_BaseEntity::EmitSound( filter, m_pHost->entindex(), soundname, &origin );
  150. }
  151. //-----------------------------------------------------------------------------
  152. // Play a sound
  153. //-----------------------------------------------------------------------------
  154. void CMoveHelperClient::StartSound( const Vector& origin, int channel,
  155. char const* pSample, float volume, soundlevel_t soundlevel, int fFlags, int pitch )
  156. {
  157. if ( pSample )
  158. {
  159. C_BaseEntity::PrecacheScriptSound( pSample );
  160. CLocalPlayerFilter filter;
  161. filter.UsePredictionRules();
  162. EmitSound_t ep;
  163. ep.m_nChannel = channel;
  164. ep.m_pSoundName = pSample;
  165. ep.m_flVolume = volume;
  166. ep.m_SoundLevel = soundlevel;
  167. ep.m_nPitch = pitch;
  168. ep.m_pOrigin = &origin;
  169. C_BaseEntity::EmitSound( filter, m_pHost->entindex(), ep );
  170. }
  171. }
  172. //-----------------------------------------------------------------------------
  173. // Play a event
  174. //-----------------------------------------------------------------------------
  175. 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 )
  176. {
  177. // TODO
  178. if (g_pMoveData->m_bFirstRunOfFunctions )
  179. {
  180. }
  181. }
  182. //-----------------------------------------------------------------------------
  183. // Surface properties interface
  184. //-----------------------------------------------------------------------------
  185. IPhysicsSurfaceProps *CMoveHelperClient::GetSurfaceProps( void )
  186. {
  187. extern IPhysicsSurfaceProps *physprops;
  188. return physprops;
  189. }
  190. //-----------------------------------------------------------------------------
  191. // Purpose:
  192. // Input : bDeveloper -
  193. // *pFormat -
  194. // ... -
  195. //-----------------------------------------------------------------------------
  196. void CMoveHelperClient::Con_NPrintf( int idx, char const* pFormat, ...)
  197. {
  198. va_list marker;
  199. char msg[8192];
  200. va_start(marker, pFormat);
  201. Q_vsnprintf(msg, sizeof( msg ), pFormat, marker);
  202. va_end(marker);
  203. #if defined( CSTRIKE_DLL )
  204. engine->Con_NPrintf( idx, "%s", msg );
  205. #else
  206. engine->Con_NPrintf( idx, msg );
  207. #endif
  208. }
  209. //-----------------------------------------------------------------------------
  210. // Purpose: Called when the player falls onto a surface fast enough to take
  211. // damage, according to the rules in CGameMovement::CheckFalling.
  212. // Output : Returns true if the player survived the fall, false if they died.
  213. //-----------------------------------------------------------------------------
  214. bool CMoveHelperClient::PlayerFallingDamage(void)
  215. {
  216. // Do nothing; falling damage is applied in MoveHelper_Server::PlayerFallingDamage.
  217. return(true);
  218. }
  219. //-----------------------------------------------------------------------------
  220. // Purpose: Sets an animation in the player.
  221. // Input : eAnim - Animation to set.
  222. //-----------------------------------------------------------------------------
  223. void CMoveHelperClient::PlayerSetAnimation( PLAYER_ANIM eAnim )
  224. {
  225. // Do nothing on the client. Animations are set on the server.
  226. }
  227. bool CMoveHelperClient::IsWorldEntity( const CBaseHandle &handle )
  228. {
  229. return handle == cl_entitylist->GetNetworkableHandle( 0 );
  230. }