#include "cbase.h"
#include "c_prop_sfr_vehicle.h"
#include "vehicle_viewblend_shared.h"
extern ConVar joy_response_move_vehicle;
void RecvProxy_SFRVehicle_LocalVelocityX( const CRecvProxyData *pData, void *pStruct, void *pOut )
{
C_PropSFRVehicle *pVehicle = (C_PropSFRVehicle *) pStruct;
Assert( pVehicle );
float flNewVel_x = pData->m_Value.m_Float;
Vector vecVelocity = pVehicle->GetLocalVelocity();
if( vecVelocity.x != flNewVel_x ) // Should this use an epsilon check?
{
//if (vecVelocity.x > 30.0f)
//{
//}
vecVelocity.x = flNewVel_x;
pVehicle->SetLocalVelocity( vecVelocity );
}
}
void RecvProxy_SFRVehicle_LocalVelocityY( const CRecvProxyData *pData, void *pStruct, void *pOut )
{
C_PropSFRVehicle *pVehicle = (C_PropSFRVehicle *) pStruct;
Assert( pVehicle );
float flNewVel_y = pData->m_Value.m_Float;
Vector vecVelocity = pVehicle->GetLocalVelocity();
if( vecVelocity.y != flNewVel_y )
{
vecVelocity.y = flNewVel_y;
pVehicle->SetLocalVelocity( vecVelocity );
}
}
void RecvProxy_SFRVehicle_LocalVelocityZ( const CRecvProxyData *pData, void *pStruct, void *pOut )
{
C_PropSFRVehicle *pVehicle = (C_PropSFRVehicle *) pStruct;
Assert( pVehicle );
float flNewVel_z = pData->m_Value.m_Float;
Vector vecVelocity = pVehicle->GetLocalVelocity();
if( vecVelocity.z != flNewVel_z )
{
vecVelocity.z = flNewVel_z;
pVehicle->SetLocalVelocity( vecVelocity );
}
}
IMPLEMENT_CLIENTCLASS_DT(C_PropSFRVehicle, DT_PropSFRVehicle, CPropSFRVehicle)
RecvPropEHandle( RECVINFO(m_hPlayer) ),
RecvPropBool( RECVINFO( m_bIsOn ) ),
RecvPropVectorXY( RECVINFO_NAME( m_vecNetworkOrigin, m_vecOrigin ), 0, C_BasePlayer::RecvProxy_LocalOriginXY ),
RecvPropFloat( RECVINFO_NAME( m_vecNetworkOrigin[2], m_vecOrigin[2] ), 0, C_BasePlayer::RecvProxy_LocalOriginZ ),
RecvPropFloat ( RECVINFO( m_vecVelocity[0] ), 0, RecvProxy_SFRVehicle_LocalVelocityX ),
RecvPropFloat ( RECVINFO( m_vecVelocity[1] ), 0, RecvProxy_SFRVehicle_LocalVelocityY ),
RecvPropFloat ( RECVINFO( m_vecVelocity[2] ), 0, RecvProxy_SFRVehicle_LocalVelocityZ ),
//RecvPropFloat( RECVINFO_NAME( m_angNetworkAngles[0], m_angRotation[0] ) ),
//RecvPropFloat( RECVINFO_NAME( m_angNetworkAngles[1], m_angRotation[1] ) ),
//RecvPropFloat( RECVINFO_NAME( m_angNetworkAngles[2], m_angRotation[2] ) ),
END_RECV_TABLE();
C_PropSFRVehicle::C_PropSFRVehicle()
{
}
//-----------------------------------------------------------------------------
// By default all driveable vehicles use the curve defined by the convar.
//-----------------------------------------------------------------------------
int C_PropSFRVehicle::GetJoystickResponseCurve() const
{
return joy_response_move_vehicle.GetInt();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
C_BaseCombatCharacter *C_PropSFRVehicle::GetPassenger( int nRole )
{
if ( nRole == VEHICLE_ROLE_DRIVER )
return m_hPlayer.Get();
return NULL;
}
//-----------------------------------------------------------------------------
// Returns the role of the passenger
//-----------------------------------------------------------------------------
int C_PropSFRVehicle::GetPassengerRole( C_BaseCombatCharacter *pPassenger )
{
if ( m_hPlayer.Get() == pPassenger )
return VEHICLE_ROLE_DRIVER;
return VEHICLE_ROLE_NONE;
}
//-----------------------------------------------------------------------------
// Should this object cast render-to-texture shadows?
//-----------------------------------------------------------------------------
ShadowType_t C_PropSFRVehicle::ShadowCastType()
{
CStudioHdr *pStudioHdr = GetModelPtr();
if ( !pStudioHdr )
return SHADOWS_NONE;
if ( IsEffectActive(EF_NODRAW | EF_NOSHADOW) )
return SHADOWS_NONE;
// Always use render-to-texture. We'll always the dirty bits in our think function
return SHADOWS_RENDER_TO_TEXTURE;
}
//-----------------------------------------------------------------------------
// Mark the shadow as dirty while the vehicle is being driven
//-----------------------------------------------------------------------------
void C_PropSFRVehicle::ClientThink()
{
// The vehicle is always dirty owing to pose parameters while it's being driven.
g_pClientShadowMgr->MarkRenderToTextureShadowDirty( GetShadowHandle() );
}
//-----------------------------------------------------------------------------
// Futzes with the clip planes
//-----------------------------------------------------------------------------
void C_PropSFRVehicle::GetVehicleClipPlanes( float &flZNear, float &flZFar ) const
{
// FIXME: Need something a better long-term, this fixes the buggy.
flZNear = 1;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void C_PropSFRVehicle::UpdateViewAngles( C_BasePlayer *pLocalPlayer, CUserCmd *pCmd )
{
}
void C_PropSFRVehicle::GetVehicleViewPosition( int nRole, Vector *pOrigin, QAngle *pAngles, float *pFOV )
{
Vector forward(0,0,0), right(0,0,0), up(0,0,0);
GetVectors( &forward, &right, &up );
if( pOrigin != 0 )
{
*pOrigin = GetAbsOrigin();
}
if( pAngles != 0 )
{
*pAngles = GetAbsAngles();
}
if( pFOV != 0 )
{
GetVehicleFOV( (*pFOV) );
}
}
//-----------------------------------------------------------------------------
// Renders hud elements
//-----------------------------------------------------------------------------
void C_PropSFRVehicle::DrawHudElements( )
{
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void C_PropSFRVehicle::OnEnteredVehicle( C_BaseCombatCharacter *pPassenger )
{
}
#define ROLL_CURVE_ZERO 20 // roll less than this is clamped to zero
#define ROLL_CURVE_LINEAR 90 // roll greater than this is copied out
#define PITCH_CURVE_ZERO 10 // pitch less than this is clamped to zero
#define PITCH_CURVE_LINEAR 45 // pitch greater than this is copied out
// spline in between
//=============================================================================
//C_PropSFRVehicleWithViewSmoothing
//=============================================================================
BEGIN_DATADESC(C_PropSFRVehicleWithViewSmoothing)
DEFINE_EMBEDDED( m_ViewSmoothingData ),
END_DATADESC();
C_PropSFRVehicleWithViewSmoothing::C_PropSFRVehicleWithViewSmoothing()
{
memset( &m_ViewSmoothingData, 0, sizeof( m_ViewSmoothingData ) );
m_ViewSmoothingData.pVehicle = this;
m_ViewSmoothingData.bClampEyeAngles = true;
m_ViewSmoothingData.bDampenEyePosition = true;
m_ViewSmoothingData.flPitchCurveZero = PITCH_CURVE_ZERO;
m_ViewSmoothingData.flPitchCurveLinear = PITCH_CURVE_LINEAR;
m_ViewSmoothingData.flRollCurveZero = ROLL_CURVE_ZERO;
m_ViewSmoothingData.flRollCurveLinear = ROLL_CURVE_LINEAR;
m_ViewSmoothingData.flFOV = 75.0;
}
void C_PropSFRVehicleWithViewSmoothing::GetVehicleViewPosition( int nRole, Vector *pOrigin, QAngle *pAngles, float *pFOV )
{
SFRSharedVehicleViewSmoothing( m_hPlayer,
pOrigin, pAngles,
false, false,
GetAbsOrigin(),
&m_ViewSmoothingData,
pFOV );
}
void C_PropSFRVehicleWithViewSmoothing::DampenEyePosition( Vector &vecVehicleEyePos, QAngle &vecVehicleEyeAngles )
{
}