//-----------------------------------------------------------------------------
// Purpose: Update the designator position
//-----------------------------------------------------------------------------
void CObjectBaseMannedGun::UpdateDesignator( void )
{
	// Make the beam, if we don't have one yet
	if ( !m_hBeam && GetDriverPlayer() )
	{
		m_hBeam = BEAM_CREATE_PREDICTABLE_PERSIST( "sprites/laserbeam.vmt", 5, GetDriverPlayer() );
		if ( m_hBeam.Get() )
		{
			m_hBeam->PointEntInit( vec3_origin, this );
			m_hBeam->SetEndAttachment( m_nBarrelAttachment );
			m_hBeam->SetColor( 255, 32, 32 );
			m_hBeam->SetBrightness( 255 );
			m_hBeam->SetNoise( 0 );
			m_hBeam->SetWidth( 0.5 );
			m_hBeam->SetEndWidth( 0.5 );
		}
	}

	// We have to flush the bone cache because it's possible that only the bone controllers
	// have changed since the bonecache was generated, and bone controllers aren't checked.
	InvalidateBoneCache();

	QAngle vecAng;
	Vector vecSrc, vecAim;
	GetAttachment( m_nBarrelAttachment, vecSrc, vecAng );
	AngleVectors( vecAng, &vecAim, 0, 0 );

	// "Fire" the designator beam
	Vector vecEnd = vecSrc + vecAim * obj_manned_gun_designator_range.GetFloat();
	trace_t tr;
	TFGameRules()->WeaponTraceLine(vecSrc, vecEnd, MASK_SHOT, this, DMG_PROBE, &tr);

	if ( m_hLaserDesignation.Get() )
	{
		// Only update our designated target point if we hit something
		if ( tr.fraction != 1.0 )
		{
			m_hLaserDesignation->SetActive( true );
			m_hLaserDesignation->SetAbsOrigin( tr.endpos );
		}
		else
		{
			m_hLaserDesignation->SetActive( false );
		}
	}

	// Update beam visual
	if ( m_hBeam.Get() )
	{
		m_hBeam->SetStartPos( tr.endpos );
		m_hBeam->RelinkBeam();
	}
}
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CObjectBaseMannedGun::OnGoInactive( void )
{
	BaseClass::OnGoInactive();

	// If we've got a player in the gun, tell him he's got to get out
	if ( GetDriverPlayer() )
	{
		ClientPrint( GetDriverPlayer(), HUD_PRINTCENTER, "Lost power to the manned gun!" );
		GetDriverPlayer()->LeaveVehicle();
	}

#if 0
	if ( GetBuffStation() )
	{
		GetBuffStation()->DeBuffObject( this );
	}
#endif
}
//-----------------------------------------------------------------------------
// Purpose: Get and set the current driver.
//-----------------------------------------------------------------------------
void CObjectBaseMannedGun::SetPassenger( int nRole, CBasePlayer *pEnt )
{
	BaseClass::SetPassenger( nRole, pEnt );

	// If we don't have a driver anymore, return to our original facing after a while
	if ( !GetDriverPlayer() && (m_flGunPitch || m_flGunYaw) )
	{
		StopDesignating();
		SetContextThink( BaseMannedGunThink, gpGlobals->curtime + MANNEDGUN_RESTORE_TIME, OBJ_BASE_MANNEDGUN_THINK_CONTEXT );
	}
}
Ejemplo n.º 4
0
//-----------------------------------------------------------------------------
// Purpose: Update the driver's gun
//-----------------------------------------------------------------------------
void CBaseTFVehicle::VehicleDriverGunThink( void )
{
	if ( !m_hDriverGun )
		return;

	// No driver?
	CBaseTFPlayer *pDriver = GetDriverPlayer();
	if ( !pDriver )
		return;

	QAngle vecTargetAngles = m_hDriverGun->GetCurrentAngles();

	// Cast a ray out of the view to see where the player is looking.
	trace_t trace;
	Vector vecForward;
	Vector vecSrc;
	QAngle angEyeAngles;
	GetVehicleViewPosition( VEHICLE_DRIVER, &vecSrc, &angEyeAngles, NULL );
	AngleVectors( angEyeAngles, &vecForward, NULL, NULL );
	Vector vecEnd = vecSrc + (vecForward * 10000);
	UTIL_TraceLine( vecSrc, vecEnd, MASK_OPAQUE, this, COLLISION_GROUP_NONE, &trace );

	//NDebugOverlay::Box( vecSrc, -Vector(10,10,10), Vector(10,10,10), 255,0,0,8, 5 );
	//NDebugOverlay::Box( vecEnd, -Vector(10,10,10), Vector(10,10,10), 0,255,0,8, 5 );
	//NDebugOverlay::Box( trace.endpos, -Vector(10,10,10), Vector(10,10,10), 255,255,255,8, 0.1 );

	if ( trace.fraction < 1 )
	{
		// Figure out what angles our turret needs to be at in order to hit the target.
		Vector vFireOrigin = m_hDriverGun->GetFireOrigin();

		//NDebugOverlay::Box( vFireOrigin, -Vector(10,10,10), Vector(10,10,10), 0,255,0,8, 0.1 );

		// Get a direction vector that points at the target.
		Vector vTo = trace.endpos - vFireOrigin;

		// Transform it into the tank's local space.
		matrix3x4_t tankToWorld;
		AngleMatrix( GetAbsAngles(), tankToWorld );
		
		Vector vLocalTo;
		VectorITransform( vTo, tankToWorld, vLocalTo );

		// Now figure out what the angles are in local space.
		QAngle localAngles;
		VectorAngles( vLocalTo, localAngles );

		vecTargetAngles[YAW] = localAngles[YAW] - 90;
		vecTargetAngles[PITCH] = anglemod( localAngles[PITCH] );
	}

	// Set the gun's angles
	m_hDriverGun->SetTargetAngles( vecTargetAngles );
}
//-----------------------------------------------------------------------------
// Purpose: Return to our original facing after a while
//-----------------------------------------------------------------------------
void CObjectBaseMannedGun::BaseMannedGunThink( void )
{
	// If someone's got in the gun, stop moving
	if ( GetDriverPlayer() )
		return;

	// Otherwise, move back towards the initial state
	if ( m_flGunPitch )
	{
		float flPitch = anglemod( m_flGunPitch );
		if (( flPitch <= 180 ) && ( flPitch >= 0 ))
		{
			m_flGunPitch = max( 0, flPitch - (gpGlobals->frametime * MANNEDGUN_RESTORE_TURN_RATE) );
		}
		else
		{
			m_flGunPitch = flPitch + (gpGlobals->frametime * MANNEDGUN_RESTORE_TURN_RATE);
			if ( m_flGunPitch >= 360 )
			{
				m_flGunPitch = 0;
			}
		}
	}
	else if ( m_flGunYaw )
	{
		if ( m_flGunYaw > 180 )
		{
			m_flGunYaw = m_flGunYaw + (gpGlobals->frametime * MANNEDGUN_RESTORE_TURN_RATE);
			if ( m_flGunYaw >= 360 )
			{
				m_flGunYaw = 0;
			}
		}
		else
		{
			m_flGunYaw = max( 0, m_flGunYaw - (gpGlobals->frametime * MANNEDGUN_RESTORE_TURN_RATE) );
		}

	}
	else
	{
		// We're done
		return;
	}

	// Keep thinking
	SetContextThink( BaseMannedGunThink, gpGlobals->curtime + 0.1, OBJ_BASE_MANNEDGUN_THINK_CONTEXT );
	NetworkStateChanged();
}
Ejemplo n.º 6
0
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
bool CBaseTFVehicle::ShouldPredict( void )
{
	// Only predict vehicles driven by local players
	return GetDriverPlayer() ? GetDriverPlayer()->IsLocalPlayer() : false;
}
//-----------------------------------------------------------------------------
// Purpose: Plasma sentrygun's fire
//-----------------------------------------------------------------------------
void CObjectMannedPlasmagun::Fire( )
{
    if (m_flNextAttack > gpGlobals->curtime)
        return;

    // Because the plasma sentrygun always thinks it has ammo (see below)
    // we might not have ammo here, in which case we should just abort.
    if ( !m_nAmmoCount )
        return;

    // Make sure we think soon enough in case of firing...
    float flNextRecharge = gpGlobals->curtime + (HasPowerup(POWERUP_EMP) ? MANNED_PLASMAGUN_RECHARGE_TIME * 1.5 : MANNED_PLASMAGUN_RECHARGE_TIME);
    SetNextThink( gpGlobals->curtime + flNextRecharge );

    // We have to flush the bone cache because it's possible that only the bone controllers
    // have changed since the bonecache was generated, and bone controllers aren't checked.
    InvalidateBoneCache();

    QAngle vecAng;
    Vector vecSrc, vecAim;

    // Alternate barrels when firing
    if ( m_bFiringLeft )
    {
        // Aliens permanently fire left barrel because they have no right
        if ( GetTeamNumber() == TEAM_HUMANS )
        {
            m_bFiringLeft = false;
        }
        GetAttachment( m_nBarrelAttachment, vecSrc, vecAng );
        SetActivity( ACT_VM_PRIMARYATTACK );
    }
    else
    {
        m_bFiringLeft = true;
        GetAttachment( m_nRightBarrelAttachment, vecSrc, vecAng );
        SetActivity( ACT_VM_SECONDARYATTACK );
    }

    // Get the distance to the target
    AngleVectors( vecAng, &vecAim, 0, 0 );

    int damageType = GetAmmoDef()->DamageType( m_nAmmoType );
    CBasePlasmaProjectile *pPlasma = CBasePlasmaProjectile::CreatePredicted( vecSrc, vecAim, Vector( 0, 0, 0 ), damageType, GetDriverPlayer() );
    if ( pPlasma )
    {
        pPlasma->SetDamage( obj_manned_plasmagun_damage.GetFloat() );
        pPlasma->m_hOwner = GetDriverPlayer();
        //pPlasma->SetOwnerEntity( this );
        pPlasma->SetMaxRange( m_flMaxRange );
        if ( obj_manned_plasmagun_radius.GetFloat() )
        {
            pPlasma->SetExplosive( obj_manned_plasmagun_radius.GetFloat() );
        }
    }

    CSoundParameters params;
    if ( GetParametersForSound( "ObjectMannedPlasmagun.Fire", params, NULL ) )
    {
        CPASAttenuationFilter filter( this, params.soundlevel );
        if ( IsPredicted() )
        {
            filter.UsePredictionRules();
        }
        EmitSound( filter, entindex(), "ObjectMannedPlasmagun.Fire" );
    }
//	SetSentryAnim( TFTURRET_ANIM_FIRE );
    DoMuzzleFlash();

    --m_nAmmoCount;

    m_flNextIdleTime = gpGlobals->curtime + MANNED_PLASMAGUN_IDLE_TIME;

    // If I'm EMPed, slow the firing rate down
    m_flNextAttack = gpGlobals->curtime + ( HasPowerup(POWERUP_EMP) ? 0.3f : 0.1f );
}