⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vehicle_chopper.cpp

📁 hl2 source code. Do not use it illegal.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
{
	SetMoveType( MOVETYPE_FLYGRAVITY );
	m_flGravity = 0.3;

	UTIL_SetSize( this, Vector( -32, -32, -64), Vector( 32, 32, 0) );
	SetThink( DyingThink );
	SetTouch( CrashTouch );

	SetNextThink( gpGlobals->curtime + 0.1f );
	m_iHealth = 0;
	m_takedamage = DAMAGE_NO;

	if (m_spawnflags & SF_NOWRECKAGE)
	{
		m_flNextRocket = gpGlobals->curtime + 4.0;
	}
	else
	{
		m_flNextRocket = gpGlobals->curtime + 15.0;
	}

	CreateRagGib( "models/combine_soldier.mdl", GetAbsOrigin(), GetAbsAngles(), m_vecVelocity * 50 );
	
	m_OnDeath.FireOutput( pAttacker, this );
}


void CNPC_Helicopter::GibMonster( void )
{
}


//------------------------------------------------------------------------------
// Purpose :
// Input   :
// Output  :
//------------------------------------------------------------------------------
#define CHOPPER_MISSILE_HOMING_STRENGTH		0.3
#define CHOPPER_MISSILE_HOMING_DELAY		0.5
#define CHOPPER_MISSILE_HOMING_RAMP_UP		0.5
#define CHOPPER_MISSILE_HOMING_DURATION		1.0
#define CHOPPER_MISSILE_HOMING_RAMP_DOWN	0.5
void CNPC_Helicopter::FireRocket( Vector vLaunchPos, Vector vLaunchDir )
{
	CGrenadeHomer *pGrenade = CGrenadeHomer::CreateGrenadeHomer( MAKE_STRING("models/weapons/w_missile.mdl"), MAKE_STRING("weapons/stinger_fire1.wav"), vLaunchPos, vLaunchDir, edict() );
	pGrenade->Spawn( );
	pGrenade->SetHoming(CHOPPER_MISSILE_HOMING_STRENGTH,
						CHOPPER_MISSILE_HOMING_DELAY,
						CHOPPER_MISSILE_HOMING_RAMP_UP,
						CHOPPER_MISSILE_HOMING_DURATION,
						CHOPPER_MISSILE_HOMING_RAMP_DOWN);
	pGrenade->Launch(this,m_hEnemy,m_vecVelocity+vLaunchDir*500,500,0.5,true);
	UTIL_EmitSoundDyn(pev, CHAN_WEAPON, "weapons/stinger_fire1.wav", 1.0, 0.5, 1,100);

	m_flNextRocket = gpGlobals->curtime + 4.0;

	g_pEffects->Smoke(vLaunchPos,random->RandomInt(10, 15), 10);
}

//------------------------------------------------------------------------------
// Purpose :
// Input   :
// Output  :
//------------------------------------------------------------------------------
void CNPC_Helicopter::AimRocketGun( )
{
	Vector forward, right, up;
	AngleVectors( GetAngles(), &forward, &right, &up );
		
	Vector vBasePos, vBaseAng;
	Vector vTipPos, vTipAng;
	GetAttachment( CHOPPER_AP_LR_POD_BASE, vBasePos, vBaseAng );
	GetAttachment( CHOPPER_AP_LR_POD_TIP, vTipPos, vTipAng );
	
	// ----------------------------
	//  Aim Left
	// ----------------------------
	Vector vTargetDir;
	if (m_hEnemy != NULL)
	{
		vTargetDir = m_posTarget - vTipPos;
	}
	else
	{
		vTargetDir = forward;
	}
	VectorNormalize( vTargetDir );

	Vector vecOut;
	vecOut.x = DotProduct( forward, vTargetDir );
	vecOut.y = -DotProduct( right, vTargetDir );
	vecOut.z = DotProduct( up, vTargetDir );

	Vector angles;
	VectorAngles(vecOut, angles);

	if (angles.y > 180)
		angles.y = angles.y - 360;
	if (angles.y < -180)
		angles.y = angles.y + 360;
	if (angles.x > 180)
		angles.x = angles.x - 360;
	if (angles.x < -180)
		angles.x = angles.x + 360;

	if (angles.x > m_angPod.x)
		m_angPod.x = min( angles.x, m_angPod.x + 12 );
	if (angles.x < m_angPod.x)
		m_angPod.x = max( angles.x, m_angPod.x - 12 );
	if (angles.y > m_angPod.y)
		m_angPod.y = min( angles.y, m_angPod.y + 12 );
	if (angles.y < m_angPod.y)
		m_angPod.y = max( angles.y, m_angPod.y - 12 );

	m_angPod.x = SetBoneController( CHOPPER_BC_POD_PITCH,	m_angPod.x );

	// ------------------------
	// If no enemy we're done
	// ------------------------
	if (m_hEnemy == NULL)
	{
		return;
	}

	// --------------------------------
	//  Can I attack yet?
	// --------------------------------
	if (gpGlobals->curtime < m_flNextRocket)
	{
		return;
	}

	// -------------------------------
	// Don't fire when close to enemy
	// -------------------------------
	float flDist = (GetAbsOrigin() - m_hEnemy->GetAbsOrigin()).Length();
	if (flDist < CHOPPER_MIN_ROCKET_DIST)
	{
		return;
	}

	// -------------------------------
	//  Pick a pod to fire from
	//  Is left or right side closer?
	// -------------------------------
	Vector vMyFacing;
	BodyDirection2D(&vMyFacing);
	vMyFacing.z = 0;

	Vector	vEnemyDir   = m_hEnemy->EyePosition() - GetAbsOrigin();
	vEnemyDir.z = 0;

	Vector crossProduct;
	CrossProduct(vMyFacing, vEnemyDir, crossProduct);
	if (crossProduct.z < 0)
	{
		if (random->RandomInt(0,1)==0)
		{
			GetAttachment( CHOPPER_AP_RR_POD_BASE, vBasePos, vBaseAng );
			GetAttachment( CHOPPER_AP_RR_POD_TIP, vTipPos, vTipAng );
		}
		else
		{
			GetAttachment( CHOPPER_AP_RL_POD_BASE, vBasePos, vBaseAng );
			GetAttachment( CHOPPER_AP_RL_POD_TIP, vTipPos, vTipAng );
		}
	}
	else
	{
		if (random->RandomInt(0,1)==0)
		{
			GetAttachment( CHOPPER_AP_LR_POD_BASE, vBasePos, vBaseAng );
			GetAttachment( CHOPPER_AP_LR_POD_TIP, vTipPos, vTipAng );
		}
		else
		{
			GetAttachment( CHOPPER_AP_LL_POD_BASE, vBasePos, vBaseAng );
			GetAttachment( CHOPPER_AP_LL_POD_TIP, vTipPos, vTipAng );
		}
	}

	Vector vGunDir = vTipPos - vBasePos;
	VectorNormalize( vGunDir );
	
	float fDotPr = DotProduct( vGunDir, vTargetDir );

	if (fDotPr > 0.5)
	{
		FireRocket(vBasePos,vGunDir);
	}
}

//------------------------------------------------------------------------------
// Purpose :
// Input   :
// Output  :
//------------------------------------------------------------------------------
bool CNPC_Helicopter::FireGun( )
{
	Vector forward, right, up;
	AngleVectors( GetAngles(), &forward, &right, &up );
		
	// Get gun attachment points
	Vector vBasePos, vBaseAng;
	GetAttachment( CHOPPER_AP_GUN_BASE, vBasePos, vBaseAng );
	Vector vTipPos, vTipAng;
	GetAttachment( CHOPPER_AP_GUN_TIP, vTipPos, vTipAng );

	Vector vTargetDir = m_posTarget - vBasePos;
	VectorNormalize( vTargetDir );

	Vector vecOut;
	vecOut.x = DotProduct( forward, vTargetDir );
	vecOut.y = -DotProduct( right, vTargetDir );
	vecOut.z = DotProduct( up, vTargetDir );

	Vector angles;
	VectorAngles(vecOut, angles);

	if (angles.y > 180)
		angles.y = angles.y - 360;
	if (angles.y < -180)
		angles.y = angles.y + 360;
	if (angles.x > 180)
		angles.x = angles.x - 360;
	if (angles.x < -180)
		angles.x = angles.x + 360;

	if (angles.x > m_angGun.x)
		m_angGun.x = min( angles.x, m_angGun.x + 12 );
	if (angles.x < m_angGun.x)
		m_angGun.x = max( angles.x, m_angGun.x - 12 );
	if (angles.y > m_angGun.y)
		m_angGun.y = min( angles.y, m_angGun.y + 12 );
	if (angles.y < m_angGun.y)
		m_angGun.y = max( angles.y, m_angGun.y - 12 );

	m_angGun.y = SetBoneController( CHOPPER_BC_GUN_YAW,		m_angGun.y );
	m_angGun.x = SetBoneController( CHOPPER_BC_GUN_PITCH,	m_angGun.x );


	// -----------------------------------------
	//  Don't fire if far away, rockets do that
	// -----------------------------------------
	if (m_hEnemy)
	{
		float flDist = (GetAbsOrigin() - m_hEnemy->GetAbsOrigin()).Length();
		if (flDist > CHOPPER_MAX_GUN_DIST)
		{
			return false;
		}
	}
	Vector vGunDir = vBasePos - vTipPos;
	VectorNormalize( vGunDir );
	
	float fDotPr = DotProduct( vGunDir, vTargetDir );
	if (fDotPr > 0.95)
	{
		UTIL_EmitSound(pev, CHAN_WEAPON, "weapons/ar2/ar2_fire2.wav", 1.0, 0.2);//<<TEMP>>temp sound
		FireBullets( 1, vBasePos, vGunDir, VECTOR_CONE_1DEGREES, 8192, m_iAmmoType, 1 );
		return true;
	}
	return false;
}



void CNPC_Helicopter::ShowDamage( void )
{
	if (m_iDoSmokePuff > 0 || random->RandomInt(0,99) > m_iHealth)
	{
		Vector vSmoke = GetAbsOrigin();
		vSmoke.z -= 32;
		UTIL_Smoke(vSmoke,random->RandomInt(10, 15), 10);
	}
	if (m_iDoSmokePuff > 0)
	{
		m_iDoSmokePuff--;
	}
}


int CNPC_Helicopter::OnTakeDamage_Alive( const CTakeDamageInfo &info )
{
#if 0
	// This code didn't port easily. WTF does it do? (sjb)
	if (pevInflictor->m_owner == pev)
		return 0;
#endif

	if (bitsDamageType & DMG_BLAST)
	{
		flDamage *= 2;
	}

	/*
	if ( (bitsDamageType & DMG_BULLET) && flDamage > 50)
	{
		// clip bullet damage at 50
		flDamage = 50;
	}
	*/

	return BaseClass::OnTakeDamage_Alive( info );
}



void CNPC_Helicopter::TraceAttack( edict_t *pevAttacker, float flDamage, const Vector &vecDir, trace_t *ptr, int bitsDamageType)
{
	// ALERT( at_console, "%d %.0f\n", ptr->iHitgroup, flDamage );

#if 0 
	// HITGROUPS don't work currently.
	// ignore blades
	if (ptr->iHitgroup == 6 && (bitsDamageType & (DMG_ENERGYBEAM|DMG_BULLET|DMG_CLUB)))
		return;

	// hit hard, hits cockpit, hits engines
	if (flDamage > 50 || ptr->iHitgroup == 1 || ptr->iHitgroup == 2)
	{
		// ALERT( at_console, "%map .0f\n", flDamage );
		AddMultiDamage( pevAttacker, this, flDamage, bitsDamageType );
		m_iDoSmokePuff = 3 + (flDamage / 5.0);
	}
	else
	{
		// do half damage in the body
		// AddMultiDamage( pevAttacker, this, flDamage / 2.0, bitsDamageType );
		UTIL_Ricochet( ptr->vecEndPos );
	}
#endif
}

//------------------------------------------------------------------------------
// Purpose :
// Input   :
// Output  :
//------------------------------------------------------------------------------
CNPC_Helicopter::~CNPC_Helicopter(void)
{
}


#endif // 0

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -