Portable Half-Life SDK. GoldSource and Xash3D. Crossplatform.
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.

269 lines
7.0 KiB

9 years ago
/***
*
* Copyright (c) 1996-2002, Valve LLC. All rights reserved.
*
* This product contains software technology licensed from Id
* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc.
* All Rights Reserved.
*
* This source code contains proprietary and confidential information of
* Valve LLC and its suppliers. Access to this code is restricted to
* persons who have executed a written SDK license with Valve. Any access,
* use or distribution of this code by or to any unlicensed person is illegal.
*
****/
9 years ago
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "monsters.h"
#include "schedule.h"
#include "flyingmonster.h"
#define FLYING_AE_FLAP (8)
#define FLYING_AE_FLAPSOUND (9)
8 years ago
extern DLL_GLOBAL edict_t *g_pBodyQueueHead;
9 years ago
8 years ago
int CFlyingMonster::CheckLocalMove( const Vector &vecStart, const Vector &vecEnd, CBaseEntity *pTarget, float *pflDist )
9 years ago
{
// UNDONE: need to check more than the endpoint
8 years ago
if( FBitSet( pev->flags, FL_SWIM ) && ( UTIL_PointContents( vecEnd ) != CONTENTS_WATER ) )
9 years ago
{
8 years ago
// ALERT( at_aiconsole, "can't swim out of water\n" );
9 years ago
return FALSE;
}
TraceResult tr;
UTIL_TraceHull( vecStart + Vector( 0.0f, 0.0f, 32.0f ), vecEnd + Vector( 0.0f, 0.0f, 32.0f ), dont_ignore_monsters, large_hull, edict(), &tr );
9 years ago
// ALERT( at_console, "%.0f %.0f %.0f : ", vecStart.x, vecStart.y, vecStart.z );
// ALERT( at_console, "%.0f %.0f %.0f\n", vecEnd.x, vecEnd.y, vecEnd.z );
8 years ago
if( pflDist )
9 years ago
{
*pflDist = ( ( tr.vecEndPos - Vector( 0.0f, 0.0f, 32.0f ) ) - vecStart ).Length();// get the distance.
9 years ago
}
// ALERT( at_console, "check %d %d %f\n", tr.fStartSolid, tr.fAllSolid, tr.flFraction );
if( tr.fStartSolid || tr.flFraction < 1.0f )
9 years ago
{
8 years ago
if( pTarget && pTarget->edict() == gpGlobals->trace_ent )
9 years ago
return LOCALMOVE_VALID;
return LOCALMOVE_INVALID;
}
return LOCALMOVE_VALID;
}
8 years ago
BOOL CFlyingMonster::FTriangulate( const Vector &vecStart, const Vector &vecEnd, float flDist, CBaseEntity *pTargetEnt, Vector *pApex )
9 years ago
{
return CBaseMonster::FTriangulate( vecStart, vecEnd, flDist, pTargetEnt, pApex );
}
8 years ago
Activity CFlyingMonster::GetStoppedActivity( void )
9 years ago
{
8 years ago
if( pev->movetype != MOVETYPE_FLY ) // UNDONE: Ground idle here, IDLE may be something else
9 years ago
return ACT_IDLE;
return ACT_HOVER;
}
8 years ago
void CFlyingMonster::Stop( void )
{
9 years ago
Activity stopped = GetStoppedActivity();
8 years ago
if( m_IdealActivity != stopped )
9 years ago
{
m_flightSpeed = 0;
m_IdealActivity = stopped;
}
pev->angles.z = 0.0f;
pev->angles.x = 0.0f;
9 years ago
m_vecTravel = g_vecZero;
}
8 years ago
float CFlyingMonster::ChangeYaw( int speed )
9 years ago
{
8 years ago
if( pev->movetype == MOVETYPE_FLY )
9 years ago
{
float diff = FlYawDiff();
float target = 0.0f;
9 years ago
8 years ago
if( m_IdealActivity != GetStoppedActivity() )
9 years ago
{
if( diff < -20.0f )
target = 90.0f;
else if( diff > 20.0f )
target = -90.0f;
9 years ago
}
pev->angles.z = UTIL_Approach( target, pev->angles.z, 220.0f * gpGlobals->frametime );
9 years ago
}
return CBaseMonster::ChangeYaw( speed );
}
8 years ago
void CFlyingMonster::Killed( entvars_t *pevAttacker, int iGib )
9 years ago
{
pev->movetype = MOVETYPE_STEP;
ClearBits( pev->flags, FL_ONGROUND );
pev->angles.z = 0;
pev->angles.x = 0;
CBaseMonster::Killed( pevAttacker, iGib );
}
8 years ago
void CFlyingMonster::HandleAnimEvent( MonsterEvent_t *pEvent )
9 years ago
{
switch( pEvent->event )
{
case FLYING_AE_FLAP:
m_flightSpeed = 400;
break;
case FLYING_AE_FLAPSOUND:
8 years ago
if( m_pFlapSound )
9 years ago
EMIT_SOUND( edict(), CHAN_BODY, m_pFlapSound, 1, ATTN_NORM );
break;
default:
CBaseMonster::HandleAnimEvent( pEvent );
break;
}
}
8 years ago
void CFlyingMonster::Move( float flInterval )
9 years ago
{
8 years ago
if( pev->movetype == MOVETYPE_FLY )
9 years ago
m_flGroundSpeed = m_flightSpeed;
CBaseMonster::Move( flInterval );
}
8 years ago
BOOL CFlyingMonster::ShouldAdvanceRoute( float flWaypointDist )
9 years ago
{
// Get true 3D distance to the goal so we actually reach the correct height
8 years ago
if( m_Route[m_iRouteIndex].iType & bits_MF_IS_GOAL )
flWaypointDist = ( m_Route[m_iRouteIndex].vecLocation - pev->origin ).Length();
9 years ago
if( flWaypointDist <= 64.0f + ( m_flGroundSpeed * gpGlobals->frametime ) )
9 years ago
return TRUE;
return FALSE;
}
void CFlyingMonster::MoveExecute( CBaseEntity *pTargetEnt, const Vector &vecDir, float flInterval )
{
8 years ago
if( pev->movetype == MOVETYPE_FLY )
9 years ago
{
if( gpGlobals->time - m_stopTime > 1.0f )
9 years ago
{
8 years ago
if( m_IdealActivity != m_movementActivity )
9 years ago
{
m_IdealActivity = m_movementActivity;
m_flGroundSpeed = m_flightSpeed = 200;
}
}
8 years ago
Vector vecMove = pev->origin + ( ( vecDir + ( m_vecTravel * m_momentum ) ).Normalize() * (m_flGroundSpeed * flInterval ) );
9 years ago
8 years ago
if( m_IdealActivity != m_movementActivity )
9 years ago
{
m_flightSpeed = UTIL_Approach( 100, m_flightSpeed, 75.0f * gpGlobals->frametime );
8 years ago
if( m_flightSpeed < 100 )
9 years ago
m_stopTime = gpGlobals->time;
}
else
m_flightSpeed = UTIL_Approach( 20, m_flightSpeed, 300.0f * gpGlobals->frametime );
8 years ago
if( CheckLocalMove( pev->origin, vecMove, pTargetEnt, NULL ) )
9 years ago
{
8 years ago
m_vecTravel = vecMove - pev->origin;
9 years ago
m_vecTravel = m_vecTravel.Normalize();
8 years ago
UTIL_MoveToOrigin( ENT( pev ), vecMove, ( m_flGroundSpeed * flInterval ), MOVE_STRAFE );
9 years ago
}
else
{
m_IdealActivity = GetStoppedActivity();
m_stopTime = gpGlobals->time;
m_vecTravel = g_vecZero;
}
}
else
CBaseMonster::MoveExecute( pTargetEnt, vecDir, flInterval );
}
float CFlyingMonster::CeilingZ( const Vector &position )
{
TraceResult tr;
Vector minUp = position;
Vector maxUp = position;
maxUp.z += 4096.0f;
9 years ago
8 years ago
UTIL_TraceLine( position, maxUp, ignore_monsters, NULL, &tr );
if( tr.flFraction != 1.0f )
9 years ago
maxUp.z = tr.vecEndPos.z;
8 years ago
if( ( pev->flags ) & FL_SWIM )
9 years ago
{
return UTIL_WaterLevel( position, minUp.z, maxUp.z );
}
return maxUp.z;
}
8 years ago
BOOL CFlyingMonster::ProbeZ( const Vector &position, const Vector &probe, float *pFraction )
9 years ago
{
8 years ago
int conPosition = UTIL_PointContents( position );
if( ( ( ( pev->flags ) & FL_SWIM ) == FL_SWIM ) ^ ( conPosition == CONTENTS_WATER ) )
9 years ago
{
// SWIMING & !WATER
// or FLYING & WATER
//
*pFraction = 0.0f;
9 years ago
return TRUE; // We hit a water boundary because we are where we don't belong.
}
8 years ago
int conProbe = UTIL_PointContents( probe );
if( conProbe == conPosition )
9 years ago
{
// The probe is either entirely inside the water (for fish) or entirely
// outside the water (for birds).
//
*pFraction = 1.0f;
9 years ago
return FALSE;
}
8 years ago
Vector ProbeUnit = ( probe - position ).Normalize();
float ProbeLength = ( probe - position ).Length();
9 years ago
float maxProbeLength = ProbeLength;
float minProbeLength = 0;
float diff = maxProbeLength - minProbeLength;
while( diff > 1.0f )
9 years ago
{
float midProbeLength = minProbeLength + diff / 2.0f;
9 years ago
Vector midProbeVec = midProbeLength * ProbeUnit;
8 years ago
if( UTIL_PointContents( position + midProbeVec ) == conPosition )
9 years ago
{
minProbeLength = midProbeLength;
}
else
{
maxProbeLength = midProbeLength;
}
diff = maxProbeLength - minProbeLength;
}
*pFraction = minProbeLength/ProbeLength;
return TRUE;
}
float CFlyingMonster::FloorZ( const Vector &position )
{
TraceResult tr;
Vector down = position;
down.z -= 2048.0f;
9 years ago
UTIL_TraceLine( position, down, ignore_monsters, NULL, &tr );
if( tr.flFraction != 1.0f )
9 years ago
return tr.vecEndPos.z;
return down.z;
}