Пример #1
0
void C_CFPlayer::PostDataUpdate( DataUpdateType_t updateType )
{
	// C_BaseEntity assumes we're networking the entity's angles, so pretend that it
	// networked the same value we already have.
	SetNetworkAngles( GetLocalAngles() );
	
	BaseClass::PostDataUpdate( updateType );
}
Пример #2
0
//-----------------------------------------------------------------------------
bool C_LowViolenceHostageDeathModel::SetupLowViolenceModel( C_CHostage *pHostage )
{
	const model_t *model = pHostage->GetModel();
	const char *pModelName = modelinfo->GetModelName( model );
	if ( InitializeAsClientEntity( pModelName, RENDER_GROUP_OPAQUE_ENTITY ) == false )
	{
		Release();
		return false;
	}

	// Play the low-violence death anim
	if ( LookupSequence( "death1" ) == -1 )
	{
		Release();
		return false;
	}

	m_flFadeOutStart = gpGlobals->curtime + 5.0f;
	SetNextClientThink( CLIENT_THINK_ALWAYS );

	SetSequence( LookupSequence( "death1" ) );
	ForceClientSideAnimationOn();

	if ( pHostage && !pHostage->IsDormant() )
	{
		SetNetworkOrigin( pHostage->GetAbsOrigin() );
		SetAbsOrigin( pHostage->GetAbsOrigin() );
		SetAbsVelocity( pHostage->GetAbsVelocity() );

		// move my current model instance to the ragdoll's so decals are preserved.
		pHostage->SnatchModelInstance( this );

		SetAbsAngles( pHostage->GetRenderAngles() );
		SetNetworkAngles( pHostage->GetRenderAngles() );

		CStudioHdr *pStudioHdr = GetModelPtr();

		// update pose parameters
		float poseParameter[MAXSTUDIOPOSEPARAM];
		GetPoseParameters( pStudioHdr, poseParameter );
		for ( int i=0; i<NumInterestingPoseParameters; ++i )
		{
			int poseParameterIndex = LookupPoseParameter( pStudioHdr, InterestingPoseParameters[i] );
			SetPoseParameter( pStudioHdr, poseParameterIndex, poseParameter[poseParameterIndex] );
		}
	}

	Interp_Reset( GetVarMapping() );
	return true;
}
Пример #3
0
/*void C_SDKPlayer::OnPlayerClassChange( void )
{
	// Init the anim movement vars
	m_PlayerAnimState->SetRunSpeed( GetPlayerClass()->GetMaxSpeed() );
	m_PlayerAnimState->SetWalkSpeed( GetPlayerClass()->GetMaxSpeed() * 0.5 );
}
*/
void C_SDKPlayer::PostDataUpdate( DataUpdateType_t updateType )
{
	// C_BaseEntity assumes we're networking the entity's angles, so pretend that it
	// networked the same value we already have.
	SetNetworkAngles( GetLocalAngles() );
	
	BaseClass::PostDataUpdate( updateType );

	bool bIsLocalPlayer = IsLocalPlayer();

	if( m_bSpawnInterpCounter != m_bSpawnInterpCounterCache )
	{
		MoveToLastReceivedPosition( true );
		ResetLatched();

		if ( bIsLocalPlayer )
		{
			LocalPlayerRespawn();
		}
		m_bSpawnInterpCounterCache = m_bSpawnInterpCounter.m_Value;
	}

}
Пример #4
0
void C_NEOPlayer::PostDataUpdate( DataUpdateType_t updateType )
{
	SetNetworkAngles( GetLocalAngles() );

	BaseClass::PostDataUpdate( updateType );
}
Пример #5
0
//-----------------------------------------------------------------------------
void C_Fish::ClientThink()
{
	if (FishDebug.GetBool())
	{
		debugoverlay->AddLineOverlay( m_pos, m_actualPos, 255, 0, 0, true, 0.1f );
		switch( m_localLifeState )
		{
			case LIFE_DYING:
				debugoverlay->AddTextOverlay( m_pos, 0.1f, "DYING" );
				break;

			case LIFE_DEAD:
				debugoverlay->AddTextOverlay( m_pos, 0.1f, "DEAD" );
				break;
		}
	}

	float deltaT = gpGlobals->frametime;


	// check if we just died
	if (m_localLifeState == LIFE_ALIVE && m_lifeState != LIFE_ALIVE)
	{
		// we have died
		m_localLifeState = LIFE_DYING;

		m_deathDepth = m_pos.z;

		// determine surface float angle
		m_deathAngle = RandomFloat( 87.0f, 93.0f ) * ((RandomInt( 0, 100 ) < 50) ? 1.0f : -1.0f);
	}


	switch( m_localLifeState )
	{
		case LIFE_DYING:
		{
			// depth parameter
			float t = (m_pos.z - m_deathDepth) / (m_waterLevel - m_deathDepth);
			t *= t;

			// roll onto side
			m_angles.z = m_deathAngle * t;

			// float to surface
			const float fudge = 2.0f;
			if (m_pos.z < m_waterLevel - fudge)
			{
				m_vel.z += (1.0f - t) * m_buoyancy * deltaT;
			}
			else
			{
				m_localLifeState = LIFE_DEAD;
			}

			break;
		}

		case LIFE_DEAD:
		{
			// depth parameter
			float t = (m_pos.z - m_deathDepth) / (m_waterLevel - m_deathDepth);
			t *= t;

			// roll onto side
			m_angles.z = m_deathAngle * t;

			// keep near water surface
			const float sub = 0.5f;
			m_vel.z += 10.0f * (m_waterLevel - m_pos.z - sub) * deltaT;

			// bob on surface
			const float rollAmp = 5.0f;
			const float rollFreq = 2.33f;
			m_angles.z += rollAmp * sin( rollFreq * (gpGlobals->curtime + 10.0f * entindex()) ) * deltaT;

			const float rollAmp2 = 7.0f;
			const float rollFreq2 = 4.0f;
			m_angles.x += rollAmp2 * sin( rollFreq2 * (gpGlobals->curtime + 10.0f * entindex()) ) * deltaT;

			const float bobAmp = 0.75f;
			const float bobFreq = 4.0f;
			m_vel.z += bobAmp * sin( bobFreq * (gpGlobals->curtime + 10.0f * entindex()) ) * deltaT;

			const float bobAmp2 = 0.75f;
			const float bobFreq2 = 3.333f;
			m_vel.z += bobAmp2 * sin( bobFreq2 * (gpGlobals->curtime + 10.0f * entindex()) ) * deltaT;

			// decay movement speed to zero
			const float drag = 1.0f;
			m_vel.z -= drag * m_vel.z * deltaT;

			break;
		}

		case LIFE_ALIVE:
		{
			// use server-side Z coordinate directly
			m_pos.z = m_actualPos.z;

			// use server-side angles
			m_angles = m_actualAngles;

			// fishy wiggle based on movement
			if (!m_wiggleTimer.IsElapsed())
			{
				float swimPower = 1.0f - (m_wiggleTimer.GetElapsedTime() / m_wiggleTimer.GetCountdownDuration());
				const float amp = 6.0f * swimPower;
				float wiggle = amp * sin( m_wigglePhase );

				m_wigglePhase += m_wiggleRate * deltaT;

				// wiggle decay
				const float wiggleDecay = 5.0f;
				m_wiggleRate -= wiggleDecay * deltaT;

				m_angles.y += wiggle;
			}

			break;
		}
	}

	// compute error between our local position and actual server position
	Vector error = m_actualPos - m_pos;
	error.z = 0.0f;
	float errorLen = error.Length();

	if (m_localLifeState == LIFE_ALIVE)
	{
		// if error is far above average, start swimming
		const float wiggleThreshold = 2.0f;
		if (errorLen - m_averageError > wiggleThreshold)
		{
			// if error is large, we must have started swimming
			const float swimTime = 5.0f;
			m_wiggleTimer.Start( swimTime );

			m_wiggleRate = 2.0f * errorLen;

			const float maxWiggleRate = 30.0f;
			if (m_wiggleRate > maxWiggleRate)
			{
				m_wiggleRate = maxWiggleRate;
			}
		}

		// update average error
		m_errorHistory[ m_errorHistoryIndex++ ] = errorLen;
		if (m_errorHistoryIndex >= MAX_ERROR_HISTORY)
		{
			m_errorHistoryIndex = 0;
			m_errorHistoryCount = MAX_ERROR_HISTORY;
		}
		else if (m_errorHistoryCount < MAX_ERROR_HISTORY)
		{
			++m_errorHistoryCount;
		}

		m_averageError = 0.0f;
		if (m_errorHistoryCount)
		{
			for( int r=0; r<m_errorHistoryCount; ++r )
			{
				m_averageError += m_errorHistory[r];
			}
			m_averageError /= (float)m_errorHistoryCount;
		}
	}

	// keep fish motion smooth by correcting towards actual server position
	// NOTE: This only tracks XY motion
	const float maxError = 20.0f;
	float errorT = errorLen / maxError;
	if (errorT > 1.0f)
	{
		errorT = 1.0f;
	}

	// we want a nonlinear spring force for tracking
	errorT *= errorT;

	// as fish move faster, their error increases - use a stiffer spring when fast, and a weak one when slow
	const float trackRate = 0.0f + errorT * 115.0f;
	m_vel.x += trackRate * error.x * deltaT;
	m_vel.y += trackRate * error.y * deltaT;

	const float trackDrag = 2.0f + errorT * 6.0f;
	m_vel.x -= trackDrag * m_vel.x * deltaT;
	m_vel.y -= trackDrag * m_vel.y * deltaT;


	// euler integration
	m_pos += m_vel * deltaT;

	SetNetworkOrigin( m_pos );
	SetAbsOrigin( m_pos );

	SetNetworkAngles( m_angles );
	SetAbsAngles( m_angles );
}
Пример #6
0
void CDHLProjectile::PhysicsSimulate( void )
{
	//-------------------------------------------------------------------------------
	//Our own movement/physics simulation!
	//-------------------------------------------------------------------------------
	#ifdef CLIENT_DLL
		if ( m_bCollided )
			return;

		if ( !m_pShooter && m_hShooter )
			m_pShooter = m_hShooter.Get();
	#else
		if ( m_flRemoveAt > 0.0f )
		{
			if ( m_flRemoveAt < gpGlobals->curtime )
			{
				m_flRemoveAt = 0.0f;
				SUB_Remove();
			}
			return;
		}
		if ( IsMarkedForDeletion() )
			return;
	#endif

	float flFrametime = gpGlobals->frametime;
	//Scale for slow motion
	if ( DHLRules() )
	{
		if ( (m_iType == DHL_PROJECTILE_TYPE_BULLET || m_iType == DHL_PROJECTILE_TYPE_PELLET) )
			flFrametime *= (dhl_bulletspeed.GetFloat() * DHLRules()->GetTimescale());
		else if ( m_iType == DHL_PROJECTILE_TYPE_COMBATKNIFE )
			flFrametime *= (dhl_knifespeed.GetFloat() * DHLRules()->GetTimescale());
		else
			flFrametime *= DHLRules()->GetTimescale();
	}

	Vector vecDir = vec3_origin;
#ifndef CLIENT_DLL
	Vector vecStartPos = m_vecCurPosition; //This is where we are
	Vector vecEndPos = m_vecCurPosition; //This is where we're going
	Vector vecVelocity = m_vecCurVelocity; //Velocity
#else
	Vector vecStartPos = GetLocalOrigin(); //This is where we are
	Vector vecEndPos = GetLocalOrigin(); //This is where we're going
	Vector vecVelocity = GetLocalVelocity(); //Velocity
#endif
	//Find out where we should move to
	if ( vecVelocity != vec3_origin )
	{
		static ConVarRef gravVar( "sv_gravity" );
		//Gravity
		float newZVelocity = vecVelocity.z - ( flFrametime * gravVar.GetFloat() * GetGravity() );
		vecVelocity.z = ( (vecVelocity.z + newZVelocity) / 2 );

		vecDir = vecVelocity;
		VectorNormalize( vecDir );

		//Gravity needs to be cumulative
		#ifndef CLIENT_DLL
			m_vecCurVelocity = vecVelocity;
		#else
			SetLocalVelocity( vecVelocity );
		#endif
		vecVelocity *= flFrametime;
		vecEndPos = vecStartPos + vecVelocity;
		if ( vecEndPos.IsValid() )
		{
			CTraceFilterSkipTwoEntities movetrfilter( this, m_pShooter, COLLISION_GROUP_NONE );
			trace_t movetr;
			UTIL_TraceLine( vecStartPos, vecEndPos, MASK_SHOT, &movetrfilter, &movetr );

			#ifndef CLIENT_DLL
				//Trace to triggers so we can hit surf glass and such
				CTakeDamageInfo	triggerInfo( this, GetOwnerEntity(), m_iDamage, DMG_BULLET );
				if ( m_iType == DHL_PROJECTILE_TYPE_COMBATKNIFE )
				{
					//CalculateMeleeDamageForce( &triggerInfo, vecDir, movetr.endpos, 0.7f );
					Vector vecForce = vecDir;
					VectorNormalize( vecForce );
					//vecForce *= 10.0f;
					triggerInfo.SetDamageForce( vecForce );
				}
				else
					CalculateBulletDamageForce( &triggerInfo, m_iAmmoType, vecDir, movetr.endpos, 1.0f );
				triggerInfo.SetDamagePosition( movetr.endpos );
				TraceAttackToTriggers( triggerInfo, movetr.startpos, movetr.endpos, vecDir );
			#else
				//Hit ragdolls on the client
				CBaseEntity* pEnt = DHL_FX_AffectRagdolls( movetr.endpos, movetr.startpos, DMG_BULLET, &m_RagdollHitList );

				//Keep track of ones we've hit
				if ( pEnt )
					m_RagdollHitList.AddToTail( pEnt );
			#endif

			if ( movetr.DidHit() )
				if ( OnTouch( movetr, false, &movetrfilter ) )
					return;
			
			MoveProjectileToPosition( vecEndPos );
			m_flDistanceTravelled += vecEndPos.DistTo( vecStartPos );

			#ifndef CLIENT_DLL
				//On rare occasions the projectile likes to fly right through the world and keep going forever, causing a memory leak
				if ( m_flDistanceTravelled > MAX_TRACE_LENGTH )
				{
					SUB_Remove();
					//SetThink( &CDHLProjectile::SUB_Remove );
					//SetNextThink( gpGlobals->curtime + 0.1 );
				}
			#endif

		}

		//Simulate Angles
		//QAngle angles;
		#ifdef CLIENT_DLL
			QAngle angles = GetLocalAngles();
			//VectorAngles( vecDir, angles );
			//angles.z = GetLocalAngles().z; //Vector conversion loses z
			QAngle angVel = GetLocalAngularVelocity();
			angles += angVel * flFrametime;
			SetLocalAngles( angles );
			SetNetworkAngles( angles );
		#endif
	}
}