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.

1101 lines
25 KiB

7 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.
*
****/
#if !defined( OEM_BUILD ) && !defined( HLDEMO_BUILD )
//=========================================================
// icthyosaur - evin, satan fish monster
//=========================================================
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "monsters.h"
#include "schedule.h"
#include "flyingmonster.h"
7 years ago
#include "nodes.h"
#include "soundent.h"
#include "animation.h"
#include "effects.h"
#include "weapons.h"
#define SEARCH_RETRY 16
#define ICHTHYOSAUR_SPEED 150
extern CGraph WorldGraph;
#define EYE_MAD 0
#define EYE_BASE 1
#define EYE_CLOSED 2
#define EYE_BACK 3
#define EYE_LOOK 4
//=========================================================
// Monster's Anim Events Go Here
//=========================================================
// UNDONE: Save/restore here
class CIchthyosaur : public CFlyingMonster
{
public:
9 years ago
void Spawn( void );
void Precache( void );
void SetYawSpeed( void );
int Classify( void );
void HandleAnimEvent( MonsterEvent_t *pEvent );
CUSTOM_SCHEDULES
9 years ago
9 years ago
int Save( CSave &save );
7 years ago
int Restore( CRestore &restore );
static TYPEDESCRIPTION m_SaveData[];
Schedule_t *GetSchedule( void );
Schedule_t *GetScheduleOfType ( int Type );
void Killed( entvars_t *pevAttacker, int iGib );
void BecomeDead( void );
void EXPORT CombatUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
void EXPORT BiteTouch( CBaseEntity *pOther );
9 years ago
void StartTask( Task_t *pTask );
void RunTask( Task_t *pTask );
7 years ago
9 years ago
BOOL CheckMeleeAttack1( float flDot, float flDist );
BOOL CheckRangeAttack1( float flDot, float flDist );
7 years ago
float ChangeYaw( int speed );
Activity GetStoppedActivity( void );
9 years ago
void Move( float flInterval );
void MoveExecute( CBaseEntity *pTargetEnt, const Vector &vecDir, float flInterval );
void MonsterThink( void );
void Stop( void );
void Swim( void );
Vector DoProbe(const Vector &Probe );
7 years ago
9 years ago
float VectorToPitch( const Vector &vec );
7 years ago
float FlPitchDiff( void );
float ChangePitch( int speed );
Vector m_SaveVelocity;
float m_idealDist;
float m_flBlink;
float m_flEnemyTouched;
BOOL m_bOnAttack;
float m_flMaxSpeed;
float m_flMinSpeed;
float m_flMaxDist;
CBeam *m_pBeam;
float m_flNextAlert;
static const char *pIdleSounds[];
static const char *pAlertSounds[];
static const char *pAttackSounds[];
static const char *pBiteSounds[];
static const char *pDieSounds[];
static const char *pPainSounds[];
void IdleSound( void );
void AlertSound( void );
void AttackSound( void );
void BiteSound( void );
void DeathSound( void );
void PainSound( void );
};
LINK_ENTITY_TO_CLASS( monster_ichthyosaur, CIchthyosaur )
7 years ago
TYPEDESCRIPTION CIchthyosaur::m_SaveData[] =
7 years ago
{
DEFINE_FIELD( CIchthyosaur, m_SaveVelocity, FIELD_VECTOR ),
DEFINE_FIELD( CIchthyosaur, m_idealDist, FIELD_FLOAT ),
DEFINE_FIELD( CIchthyosaur, m_flBlink, FIELD_FLOAT ),
DEFINE_FIELD( CIchthyosaur, m_flEnemyTouched, FIELD_FLOAT ),
DEFINE_FIELD( CIchthyosaur, m_bOnAttack, FIELD_BOOLEAN ),
DEFINE_FIELD( CIchthyosaur, m_flMaxSpeed, FIELD_FLOAT ),
DEFINE_FIELD( CIchthyosaur, m_flMinSpeed, FIELD_FLOAT ),
DEFINE_FIELD( CIchthyosaur, m_flMaxDist, FIELD_FLOAT ),
DEFINE_FIELD( CIchthyosaur, m_flNextAlert, FIELD_TIME ),
};
IMPLEMENT_SAVERESTORE( CIchthyosaur, CFlyingMonster )
7 years ago
const char *CIchthyosaur::pIdleSounds[] =
7 years ago
{
"ichy/ichy_idle1.wav",
"ichy/ichy_idle2.wav",
"ichy/ichy_idle3.wav",
"ichy/ichy_idle4.wav",
};
const char *CIchthyosaur::pAlertSounds[] =
7 years ago
{
"ichy/ichy_alert2.wav",
"ichy/ichy_alert3.wav",
};
const char *CIchthyosaur::pAttackSounds[] =
7 years ago
{
"ichy/ichy_attack1.wav",
"ichy/ichy_attack2.wav",
};
const char *CIchthyosaur::pBiteSounds[] =
7 years ago
{
"ichy/ichy_bite1.wav",
"ichy/ichy_bite2.wav",
};
const char *CIchthyosaur::pPainSounds[] =
7 years ago
{
"ichy/ichy_pain2.wav",
"ichy/ichy_pain3.wav",
"ichy/ichy_pain5.wav",
};
const char *CIchthyosaur::pDieSounds[] =
7 years ago
{
"ichy/ichy_die2.wav",
"ichy/ichy_die4.wav",
};
#define EMIT_ICKY_SOUND( chan, array ) \
9 years ago
EMIT_SOUND_DYN( ENT( pev ), chan , array[RANDOM_LONG( 0, ARRAYSIZE( array ) - 1 )], 1.0, 0.6, 0, RANDOM_LONG( 95, 105 ) );
7 years ago
9 years ago
void CIchthyosaur::IdleSound( void )
7 years ago
{
EMIT_ICKY_SOUND( CHAN_VOICE, pIdleSounds );
}
9 years ago
void CIchthyosaur::AlertSound( void )
{
7 years ago
EMIT_ICKY_SOUND( CHAN_VOICE, pAlertSounds );
}
9 years ago
void CIchthyosaur::AttackSound( void )
7 years ago
{
EMIT_ICKY_SOUND( CHAN_VOICE, pAttackSounds );
}
9 years ago
void CIchthyosaur::BiteSound( void )
7 years ago
{
EMIT_ICKY_SOUND( CHAN_WEAPON, pBiteSounds );
}
9 years ago
void CIchthyosaur::DeathSound( void )
7 years ago
{
EMIT_ICKY_SOUND( CHAN_VOICE, pDieSounds );
}
9 years ago
void CIchthyosaur::PainSound( void )
7 years ago
{
EMIT_ICKY_SOUND( CHAN_VOICE, pPainSounds );
}
//=========================================================
// monster-specific tasks and states
//=========================================================
9 years ago
enum
7 years ago
{
TASK_ICHTHYOSAUR_CIRCLE_ENEMY = LAST_COMMON_TASK + 1,
TASK_ICHTHYOSAUR_SWIM,
TASK_ICHTHYOSAUR_FLOAT
7 years ago
};
//=========================================================
// AI Schedules Specific to this monster
//=========================================================
static Task_t tlSwimAround[] =
{
{ TASK_SET_ACTIVITY, (float)ACT_WALK },
{ TASK_ICHTHYOSAUR_SWIM, 0.0 },
};
static Schedule_t slSwimAround[] =
{
{
tlSwimAround,
ARRAYSIZE(tlSwimAround),
bits_COND_LIGHT_DAMAGE |
bits_COND_HEAVY_DAMAGE |
bits_COND_SEE_ENEMY |
bits_COND_NEW_ENEMY |
bits_COND_HEAR_SOUND,
bits_SOUND_PLAYER |
bits_SOUND_COMBAT,
"SwimAround"
},
};
static Task_t tlSwimAgitated[] =
{
{ TASK_STOP_MOVING, (float) 0 },
{ TASK_SET_ACTIVITY, (float)ACT_RUN },
{ TASK_WAIT, (float)2.0 },
};
static Schedule_t slSwimAgitated[] =
{
{
tlSwimAgitated,
ARRAYSIZE(tlSwimAgitated),
0,
0,
"SwimAgitated"
},
};
static Task_t tlCircleEnemy[] =
{
{ TASK_SET_ACTIVITY, (float)ACT_WALK },
{ TASK_ICHTHYOSAUR_CIRCLE_ENEMY, 0.0 },
};
static Schedule_t slCircleEnemy[] =
{
{
tlCircleEnemy,
ARRAYSIZE(tlCircleEnemy),
bits_COND_NEW_ENEMY |
bits_COND_LIGHT_DAMAGE |
bits_COND_HEAVY_DAMAGE |
bits_COND_CAN_MELEE_ATTACK1 |
bits_COND_CAN_RANGE_ATTACK1,
0,
"CircleEnemy"
},
};
Task_t tlTwitchDie[] =
{
{ TASK_STOP_MOVING, 0 },
{ TASK_SOUND_DIE, (float)0 },
{ TASK_DIE, (float)0 },
{ TASK_ICHTHYOSAUR_FLOAT, (float)0 },
};
Schedule_t slTwitchDie[] =
{
{
tlTwitchDie,
ARRAYSIZE( tlTwitchDie ),
0,
0,
"Die"
},
};
DEFINE_CUSTOM_SCHEDULES( CIchthyosaur )
7 years ago
{
9 years ago
slSwimAround,
7 years ago
slSwimAgitated,
slCircleEnemy,
slTwitchDie,
};
IMPLEMENT_CUSTOM_SCHEDULES( CIchthyosaur, CFlyingMonster )
7 years ago
//=========================================================
// Classify - indicates this monster's place in the
// relationship table.
//=========================================================
9 years ago
int CIchthyosaur::Classify( void )
7 years ago
{
return m_iClass?m_iClass:CLASS_ALIEN_MONSTER;
}
//=========================================================
// CheckMeleeAttack1
//=========================================================
9 years ago
BOOL CIchthyosaur::CheckMeleeAttack1( float flDot, float flDist )
7 years ago
{
9 years ago
if( flDot >= 0.7 && m_flEnemyTouched > gpGlobals->time - 0.2 )
7 years ago
{
return TRUE;
}
return FALSE;
}
void CIchthyosaur::BiteTouch( CBaseEntity *pOther )
{
// bite if we hit who we want to eat
9 years ago
if( pOther == m_hEnemy )
7 years ago
{
m_flEnemyTouched = gpGlobals->time;
m_bOnAttack = TRUE;
}
}
void CIchthyosaur::CombatUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
{
9 years ago
if( !ShouldToggle( useType, m_bOnAttack ) )
7 years ago
return;
9 years ago
if( m_bOnAttack )
7 years ago
{
m_bOnAttack = 0;
}
else
{
m_bOnAttack = 1;
}
}
//=========================================================
// CheckRangeAttack1 - swim in for a chomp
//
//=========================================================
9 years ago
BOOL CIchthyosaur::CheckRangeAttack1( float flDot, float flDist )
7 years ago
{
9 years ago
if( flDot > -0.7 && (m_bOnAttack || ( flDist <= 192 && m_idealDist <= 192 ) ) )
7 years ago
{
return TRUE;
}
return FALSE;
}
//=========================================================
// SetYawSpeed - allows each sequence to have a different
// turn rate associated with it.
//=========================================================
9 years ago
void CIchthyosaur::SetYawSpeed( void )
7 years ago
{
pev->yaw_speed = 100;
}
//=========================================================
// Killed - overrides CFlyingMonster.
//
9 years ago
void CIchthyosaur::Killed( entvars_t *pevAttacker, int iGib )
7 years ago
{
CBaseMonster::Killed( pevAttacker, iGib );
pev->velocity = Vector( 0, 0, 0 );
}
void CIchthyosaur::BecomeDead( void )
{
pev->takedamage = DAMAGE_YES;// don't let autoaim aim at corpses.
// give the corpse half of the monster's original maximum health.
pev->health = pev->max_health / 2;
pev->max_health = 5; // max_health now becomes a counter for how many blood decals the corpse can place.
}
#define ICHTHYOSAUR_AE_SHAKE_RIGHT 1
#define ICHTHYOSAUR_AE_SHAKE_LEFT 2
//=========================================================
// HandleAnimEvent - catches the monster-specific messages
// that occur when tagged animation frames are played.
//=========================================================
9 years ago
void CIchthyosaur::HandleAnimEvent( MonsterEvent_t *pEvent )
7 years ago
{
int bDidAttack = FALSE;
switch( pEvent->event )
{
case ICHTHYOSAUR_AE_SHAKE_RIGHT:
case ICHTHYOSAUR_AE_SHAKE_LEFT:
{
if( m_hEnemy != 0 && FVisible( m_hEnemy ) )
7 years ago
{
CBaseEntity *pHurt = m_hEnemy;
9 years ago
if( m_flEnemyTouched < gpGlobals->time - 0.2 && ( m_hEnemy->BodyTarget( pev->origin ) - pev->origin).Length() > ( 32 + 16 + 32 ) )
7 years ago
break;
Vector vecShootDir = ShootAtEnemy( pev->origin );
9 years ago
UTIL_MakeAimVectors( pev->angles );
7 years ago
9 years ago
if( DotProduct( vecShootDir, gpGlobals->v_forward ) > 0.707 )
7 years ago
{
m_bOnAttack = TRUE;
pHurt->pev->punchangle.z = -18;
pHurt->pev->punchangle.x = 5;
pHurt->pev->velocity = pHurt->pev->velocity - gpGlobals->v_right * 300;
9 years ago
if( pHurt->IsPlayer() )
7 years ago
{
pHurt->pev->angles.x += RANDOM_FLOAT( -35, 35 );
pHurt->pev->angles.y += RANDOM_FLOAT( -90, 90 );
pHurt->pev->angles.z = 0;
pHurt->pev->fixangle = TRUE;
}
pHurt->TakeDamage( pev, pev, gSkillData.ichthyosaurDmgShake, DMG_SLASH );
}
}
BiteSound();
bDidAttack = TRUE;
}
break;
default:
CFlyingMonster::HandleAnimEvent( pEvent );
break;
}
9 years ago
if( bDidAttack )
7 years ago
{
Vector vecSrc = pev->origin + gpGlobals->v_forward * 32;
UTIL_Bubbles( vecSrc - Vector( 8, 8, 8 ), vecSrc + Vector( 8, 8, 8 ), 16 );
}
}
//=========================================================
// Spawn
//=========================================================
9 years ago
void CIchthyosaur::Spawn()
7 years ago
{
9 years ago
Precache();
7 years ago
if (pev->model)
SET_MODEL(ENT(pev), STRING(pev->model)); //LRC
else
SET_MODEL( ENT( pev ), "models/icky.mdl" );
7 years ago
UTIL_SetSize( pev, Vector( -32, -32, -32 ), Vector( 32, 32, 32 ) );
9 years ago
pev->solid = SOLID_BBOX;
7 years ago
pev->movetype = MOVETYPE_FLY;
m_bloodColor = BLOOD_COLOR_GREEN;
if (pev->health == 0)
pev->health = gSkillData.ichthyosaurHealth;
9 years ago
pev->view_ofs = Vector( 0, 0, 16 );
7 years ago
m_flFieldOfView = VIEW_FIELD_WIDE;
m_MonsterState = MONSTERSTATE_NONE;
SetBits(pev->flags, FL_SWIM);
SetFlyingSpeed( ICHTHYOSAUR_SPEED );
SetFlyingMomentum( 2.5 ); // Set momentum constant
m_afCapability = bits_CAP_RANGE_ATTACK1 | bits_CAP_SWIM;
MonsterInit();
9 years ago
SetTouch( &CIchthyosaur::BiteTouch );
SetUse( &CIchthyosaur::CombatUse );
7 years ago
m_idealDist = 384;
m_flMinSpeed = 80;
m_flMaxSpeed = 300;
m_flMaxDist = 384;
Vector Forward;
9 years ago
UTIL_MakeVectorsPrivate( pev->angles, Forward, 0, 0 );
7 years ago
pev->velocity = m_flightSpeed * Forward.Normalize();
m_SaveVelocity = pev->velocity;
}
//=========================================================
// Precache - precaches all resources this monster needs
//=========================================================
9 years ago
void CIchthyosaur::Precache()
7 years ago
{
if (pev->model)
PRECACHE_MODEL(STRING(pev->model)); //LRC
7 years ago
else
PRECACHE_MODEL( "models/icky.mdl" );
7 years ago
PRECACHE_SOUND_ARRAY( pIdleSounds );
PRECACHE_SOUND_ARRAY( pAlertSounds );
PRECACHE_SOUND_ARRAY( pAttackSounds );
PRECACHE_SOUND_ARRAY( pBiteSounds );
PRECACHE_SOUND_ARRAY( pDieSounds );
PRECACHE_SOUND_ARRAY( pPainSounds );
}
//=========================================================
// GetSchedule
//=========================================================
Schedule_t* CIchthyosaur::GetSchedule()
{
// ALERT( at_console, "GetSchedule( )\n" );
9 years ago
switch( m_MonsterState )
7 years ago
{
case MONSTERSTATE_IDLE:
m_flightSpeed = 80;
return GetScheduleOfType( SCHED_IDLE_WALK );
break;
case MONSTERSTATE_ALERT:
m_flightSpeed = 150;
return GetScheduleOfType( SCHED_IDLE_WALK );
break;
case MONSTERSTATE_COMBAT:
m_flMaxSpeed = 400;
// eat them
9 years ago
if( HasConditions( bits_COND_CAN_MELEE_ATTACK1 ) )
7 years ago
{
return GetScheduleOfType( SCHED_MELEE_ATTACK1 );
}
9 years ago
7 years ago
// chase them down and eat them
9 years ago
if( HasConditions( bits_COND_CAN_RANGE_ATTACK1 ) )
7 years ago
{
return GetScheduleOfType( SCHED_CHASE_ENEMY );
}
9 years ago
if( HasConditions( bits_COND_HEAVY_DAMAGE ) )
7 years ago
{
m_bOnAttack = TRUE;
}
9 years ago
if( pev->health < pev->max_health - 20 )
7 years ago
{
m_bOnAttack = TRUE;
}
9 years ago
7 years ago
return GetScheduleOfType( SCHED_STANDOFF );
break;
default:
break;
}
9 years ago
return CFlyingMonster::GetSchedule();
9 years ago
}
7 years ago
//=========================================================
//=========================================================
9 years ago
Schedule_t *CIchthyosaur::GetScheduleOfType( int Type )
7 years ago
{
// ALERT( at_console, "GetScheduleOfType( %d ) %d\n", Type, m_bOnAttack );
9 years ago
switch( Type )
7 years ago
{
case SCHED_IDLE_WALK:
return slSwimAround;
case SCHED_STANDOFF:
return slCircleEnemy;
case SCHED_FAIL:
return slSwimAgitated;
case SCHED_DIE:
return slTwitchDie;
case SCHED_CHASE_ENEMY:
9 years ago
AttackSound();
7 years ago
}
9 years ago
return CBaseMonster::GetScheduleOfType( Type );
7 years ago
}
//=========================================================
// Start task - selects the correct activity and performs
// any necessary calculations to start the next task on the
// schedule.
//=========================================================
9 years ago
void CIchthyosaur::StartTask( Task_t *pTask )
7 years ago
{
9 years ago
switch( pTask->iTask )
7 years ago
{
case TASK_ICHTHYOSAUR_CIRCLE_ENEMY:
break;
case TASK_ICHTHYOSAUR_SWIM:
break;
case TASK_SMALL_FLINCH:
9 years ago
if( m_idealDist > 128 )
7 years ago
{
m_flMaxDist = 512;
m_idealDist = 512;
}
else
{
m_bOnAttack = TRUE;
}
9 years ago
CFlyingMonster::StartTask( pTask );
7 years ago
break;
case TASK_ICHTHYOSAUR_FLOAT:
pev->skin = EYE_BASE;
SetSequenceByName( "bellyup" );
break;
default:
9 years ago
CFlyingMonster::StartTask( pTask );
7 years ago
break;
}
}
9 years ago
void CIchthyosaur::RunTask( Task_t *pTask )
7 years ago
{
9 years ago
switch( pTask->iTask )
7 years ago
{
case TASK_ICHTHYOSAUR_CIRCLE_ENEMY:
if( m_hEnemy == 0 )
7 years ago
{
9 years ago
TaskComplete();
7 years ago
}
9 years ago
else if( FVisible( m_hEnemy ) )
7 years ago
{
9 years ago
Vector vecFrom = m_hEnemy->EyePosition();
9 years ago
9 years ago
Vector vecDelta = ( pev->origin - vecFrom ).Normalize();
Vector vecSwim = CrossProduct( vecDelta, Vector( 0, 0, 1 ) ).Normalize();
7 years ago
9 years ago
if( DotProduct( vecSwim, m_SaveVelocity ) < 0 )
7 years ago
vecSwim = vecSwim * -1.0;
Vector vecPos = vecFrom + vecDelta * m_idealDist + vecSwim * 32;
// ALERT( at_console, "vecPos %.0f %.0f %.0f\n", vecPos.x, vecPos.y, vecPos.z );
TraceResult tr;
7 years ago
UTIL_TraceHull( vecFrom, vecPos, ignore_monsters, large_hull, m_hEnemy->edict(), &tr );
9 years ago
if( tr.flFraction > 0.5 )
7 years ago
vecPos = tr.vecEndPos;
9 years ago
m_SaveVelocity = m_SaveVelocity * 0.8 + 0.2 * ( vecPos - pev->origin ).Normalize() * m_flightSpeed;
7 years ago
// ALERT( at_console, "m_SaveVelocity %.2f %.2f %.2f\n", m_SaveVelocity.x, m_SaveVelocity.y, m_SaveVelocity.z );
9 years ago
if( HasConditions( bits_COND_ENEMY_FACING_ME ) && m_hEnemy->FVisible( this ) )
7 years ago
{
m_flNextAlert -= 0.1;
9 years ago
if( m_idealDist < m_flMaxDist )
7 years ago
{
m_idealDist += 4;
}
9 years ago
if( m_flightSpeed > m_flMinSpeed )
7 years ago
{
m_flightSpeed -= 2;
}
9 years ago
else if( m_flightSpeed < m_flMinSpeed )
7 years ago
{
m_flightSpeed += 2;
}
9 years ago
if( m_flMinSpeed < m_flMaxSpeed )
7 years ago
{
m_flMinSpeed += 0.5;
}
}
else
{
m_flNextAlert += 0.1;
9 years ago
if( m_idealDist > 128 )
7 years ago
{
m_idealDist -= 4;
}
9 years ago
if( m_flightSpeed < m_flMaxSpeed )
7 years ago
{
m_flightSpeed += 4;
}
}
// ALERT( at_console, "%.0f\n", m_idealDist );
}
else
{
m_flNextAlert = gpGlobals->time + 0.2;
}
9 years ago
if( m_flNextAlert < gpGlobals->time )
7 years ago
{
9 years ago
// ALERT( at_console, "AlertSound()\n" );
AlertSound();
7 years ago
m_flNextAlert = gpGlobals->time + RANDOM_FLOAT( 3, 5 );
}
break;
case TASK_ICHTHYOSAUR_SWIM:
9 years ago
if( m_fSequenceFinished )
7 years ago
{
9 years ago
TaskComplete();
7 years ago
}
break;
case TASK_DIE:
9 years ago
if( m_fSequenceFinished )
7 years ago
{
pev->deadflag = DEAD_DEAD;
9 years ago
TaskComplete();
7 years ago
}
break;
case TASK_ICHTHYOSAUR_FLOAT:
pev->angles.x = UTIL_ApproachAngle( 0, pev->angles.x, 20 );
pev->velocity = pev->velocity * 0.8;
if (pev->waterlevel > 1 && pev->watertype != CONTENT_FOG && pev->velocity.z < 64)
{
pev->velocity.z += 8;
}
else
{
pev->velocity.z -= 8;
}
// ALERT( at_console, "%f\n", pev->velocity.z );
break;
default:
9 years ago
CFlyingMonster::RunTask( pTask );
7 years ago
break;
}
}
float CIchthyosaur::VectorToPitch( const Vector &vec )
{
float pitch;
9 years ago
if( vec.z == 0 && vec.x == 0 )
7 years ago
pitch = 0;
else
{
9 years ago
pitch = (int) ( atan2( vec.z, sqrt( vec.x * vec.x + vec.y * vec.y ) ) * 180 / M_PI );
if( pitch < 0 )
7 years ago
pitch += 360;
}
return pitch;
}
//=========================================================
9 years ago
void CIchthyosaur::Move( float flInterval )
7 years ago
{
CFlyingMonster::Move( flInterval );
}
float CIchthyosaur::FlPitchDiff( void )
{
9 years ago
float flPitchDiff;
float flCurrentPitch;
7 years ago
flCurrentPitch = UTIL_AngleMod( pev->angles.z );
9 years ago
if( flCurrentPitch == pev->idealpitch )
7 years ago
{
return 0;
}
flPitchDiff = pev->idealpitch - flCurrentPitch;
9 years ago
if( pev->idealpitch > flCurrentPitch )
7 years ago
{
9 years ago
if( flPitchDiff >= 180 )
7 years ago
flPitchDiff = flPitchDiff - 360;
}
else
{
9 years ago
if( flPitchDiff <= -180 )
7 years ago
flPitchDiff = flPitchDiff + 360;
}
return flPitchDiff;
}
9 years ago
float CIchthyosaur::ChangePitch( int speed )
7 years ago
{
9 years ago
if( pev->movetype == MOVETYPE_FLY )
7 years ago
{
float diff = FlPitchDiff();
float target = 0;
9 years ago
if( m_IdealActivity != GetStoppedActivity() )
7 years ago
{
9 years ago
if( diff < -20 )
7 years ago
target = 45;
9 years ago
else if( diff > 20 )
7 years ago
target = -45;
}
pev->angles.x = UTIL_Approach(target, pev->angles.x, 220.0 * 0.1 );
}
return 0;
}
float CIchthyosaur::ChangeYaw( int speed )
{
9 years ago
if( pev->movetype == MOVETYPE_FLY )
7 years ago
{
float diff = FlYawDiff();
float target = 0;
9 years ago
if( m_IdealActivity != GetStoppedActivity() )
7 years ago
{
9 years ago
if( diff < -20 )
7 years ago
target = 20;
9 years ago
else if( diff > 20 )
7 years ago
target = -20;
}
pev->angles.z = UTIL_Approach( target, pev->angles.z, 220.0 * 0.1 );
}
return CFlyingMonster::ChangeYaw( speed );
}
9 years ago
Activity CIchthyosaur::GetStoppedActivity( void )
7 years ago
{
9 years ago
if( pev->movetype != MOVETYPE_FLY ) // UNDONE: Ground idle here, IDLE may be something else
7 years ago
return ACT_IDLE;
return ACT_WALK;
}
void CIchthyosaur::MoveExecute( CBaseEntity *pTargetEnt, const Vector &vecDir, float flInterval )
{
m_SaveVelocity = vecDir * m_flightSpeed;
}
9 years ago
void CIchthyosaur::MonsterThink( void )
7 years ago
{
9 years ago
CFlyingMonster::MonsterThink();
7 years ago
9 years ago
if( pev->deadflag == DEAD_NO )
7 years ago
{
9 years ago
if( m_MonsterState != MONSTERSTATE_SCRIPT )
7 years ago
{
9 years ago
Swim();
7 years ago
// blink the eye
9 years ago
if( m_flBlink < gpGlobals->time )
7 years ago
{
pev->skin = EYE_CLOSED;
9 years ago
if( m_flBlink + 0.2 < gpGlobals->time )
7 years ago
{
m_flBlink = gpGlobals->time + RANDOM_FLOAT( 3, 4 );
9 years ago
if( m_bOnAttack )
7 years ago
pev->skin = EYE_MAD;
else
pev->skin = EYE_BASE;
}
}
}
}
}
9 years ago
void CIchthyosaur::Stop( void )
7 years ago
{
9 years ago
if( !m_bOnAttack )
7 years ago
m_flightSpeed = 80.0;
}
9 years ago
void CIchthyosaur::Swim()
7 years ago
{
//int retValue = 0;
7 years ago
Vector start = pev->origin;
Vector Angles;
Vector Forward, Right, Up;
9 years ago
if( FBitSet( pev->flags, FL_ONGROUND ) )
7 years ago
{
pev->angles.x = 0;
pev->angles.y += RANDOM_FLOAT( -45, 45 );
ClearBits( pev->flags, FL_ONGROUND );
Angles = Vector( -pev->angles.x, pev->angles.y, pev->angles.z );
9 years ago
UTIL_MakeVectorsPrivate( Angles, Forward, Right, Up );
7 years ago
pev->velocity = Forward * 200 + Up * 200;
return;
}
9 years ago
if( m_bOnAttack && m_flightSpeed < m_flMaxSpeed )
7 years ago
{
m_flightSpeed += 40;
}
9 years ago
if( m_flightSpeed < 180 )
7 years ago
{
9 years ago
if( m_IdealActivity == ACT_RUN )
7 years ago
SetActivity( ACT_WALK );
9 years ago
if( m_IdealActivity == ACT_WALK )
7 years ago
pev->framerate = m_flightSpeed / 150.0;
// ALERT( at_console, "walk %.2f\n", pev->framerate );
}
else
{
9 years ago
if( m_IdealActivity == ACT_WALK )
7 years ago
SetActivity( ACT_RUN );
9 years ago
if( m_IdealActivity == ACT_RUN)
7 years ago
pev->framerate = m_flightSpeed / 150.0;
// ALERT( at_console, "run %.2f\n", pev->framerate );
}
/*
9 years ago
if( !m_pBeam )
7 years ago
{
m_pBeam = CBeam::BeamCreate( "sprites/laserbeam.spr", 80 );
9 years ago
m_pBeam->PointEntInit( pev->origin + m_SaveVelocity, entindex() );
7 years ago
m_pBeam->SetEndAttachment( 1 );
m_pBeam->SetColor( 255, 180, 96 );
m_pBeam->SetBrightness( 192 );
}
*/
#define PROBE_LENGTH 150
Angles = UTIL_VecToAngles( m_SaveVelocity );
Angles.x = -Angles.x;
9 years ago
UTIL_MakeVectorsPrivate( Angles, Forward, Right, Up );
7 years ago
Vector f, u, l, r, d;
9 years ago
f = DoProbe( start + PROBE_LENGTH * Forward );
r = DoProbe( start + PROBE_LENGTH / 3 * Forward + Right );
l = DoProbe( start + PROBE_LENGTH / 3 * Forward - Right );
u = DoProbe( start + PROBE_LENGTH / 3 * Forward + Up );
d = DoProbe( start + PROBE_LENGTH / 3 * Forward - Up );
7 years ago
9 years ago
Vector SteeringVector = f + r + l + u + d;
m_SaveVelocity = ( m_SaveVelocity + SteeringVector / 2 ).Normalize();
7 years ago
Angles = Vector( -pev->angles.x, pev->angles.y, pev->angles.z );
9 years ago
UTIL_MakeVectorsPrivate( Angles, Forward, Right, Up );
7 years ago
// ALERT( at_console, "%f : %f\n", Angles.x, Forward.z );
float flDot = DotProduct( Forward, m_SaveVelocity );
9 years ago
if( flDot > 0.5 )
7 years ago
pev->velocity = m_SaveVelocity = m_SaveVelocity * m_flightSpeed;
9 years ago
else if( flDot > 0 )
pev->velocity = m_SaveVelocity = m_SaveVelocity * m_flightSpeed * ( flDot + 0.5 );
7 years ago
else
pev->velocity = m_SaveVelocity = m_SaveVelocity * 80;
// ALERT( at_console, "%.0f %.0f\n", m_flightSpeed, pev->velocity.Length() );
// ALERT( at_console, "Steer %f %f %f\n", SteeringVector.x, SteeringVector.y, SteeringVector.z );
/*
m_pBeam->SetStartPos( pev->origin + pev->velocity );
9 years ago
m_pBeam->RelinkBeam();
7 years ago
*/
// ALERT( at_console, "speed %f\n", m_flightSpeed );
7 years ago
Angles = UTIL_VecToAngles( m_SaveVelocity );
// Smooth Pitch
//
9 years ago
if( Angles.x > 180 )
7 years ago
Angles.x = Angles.x - 360;
9 years ago
pev->angles.x = UTIL_Approach( Angles.x, pev->angles.x, 50 * 0.1 );
if( pev->angles.x < -80 )
pev->angles.x = -80;
if( pev->angles.x > 80 )
pev->angles.x = 80;
7 years ago
// Smooth Yaw and generate Roll
//
float turn = 360;
// ALERT( at_console, "Y %.0f %.0f\n", Angles.y, pev->angles.y );
9 years ago
if( fabs( Angles.y - pev->angles.y ) < fabs( turn ) )
7 years ago
{
turn = Angles.y - pev->angles.y;
}
9 years ago
if( fabs( Angles.y - pev->angles.y + 360 ) < fabs( turn ) )
7 years ago
{
turn = Angles.y - pev->angles.y + 360;
}
9 years ago
if( fabs( Angles.y - pev->angles.y - 360 ) < fabs( turn ) )
7 years ago
{
turn = Angles.y - pev->angles.y - 360;
}
float speed = m_flightSpeed * 0.1;
// ALERT( at_console, "speed %.0f %f\n", turn, speed );
9 years ago
if( fabs( turn ) > speed )
7 years ago
{
9 years ago
if( turn < 0.0 )
7 years ago
{
turn = -speed;
}
else
{
turn = speed;
}
}
pev->angles.y += turn;
pev->angles.z -= turn;
9 years ago
pev->angles.y = fmod( ( pev->angles.y + 360.0 ), 360.0 );
7 years ago
static float yaw_adj;
yaw_adj = yaw_adj * 0.8 + turn;
// ALERT( at_console, "yaw %f : %f\n", turn, yaw_adj );
SetBoneController( 0, -yaw_adj / 4.0 );
// Roll Smoothing
//
turn = 360;
9 years ago
if( fabs( Angles.z - pev->angles.z ) < fabs( turn ) )
7 years ago
{
turn = Angles.z - pev->angles.z;
}
9 years ago
if( fabs( Angles.z - pev->angles.z + 360 ) < fabs( turn ) )
7 years ago
{
turn = Angles.z - pev->angles.z + 360;
}
9 years ago
if( fabs( Angles.z - pev->angles.z - 360 ) < fabs( turn ) )
7 years ago
{
turn = Angles.z - pev->angles.z - 360;
}
9 years ago
speed = m_flightSpeed / 2 * 0.1;
if( fabs( turn ) < speed )
7 years ago
{
pev->angles.z += turn;
}
else
{
9 years ago
if( turn < 0.0 )
7 years ago
{
pev->angles.z -= speed;
}
else
{
pev->angles.z += speed;
}
}
9 years ago
if( pev->angles.z < -20 )
pev->angles.z = -20;
if( pev->angles.z > 20 )
pev->angles.z = 20;
7 years ago
9 years ago
UTIL_MakeVectorsPrivate( Vector( -Angles.x, Angles.y, Angles.z ), Forward, Right, Up );
7 years ago
9 years ago
// UTIL_MoveToOrigin ( ENT( pev ), pev->origin + Forward * speed, speed, MOVE_STRAFE );
9 years ago
}
7 years ago
9 years ago
Vector CIchthyosaur::DoProbe( const Vector &Probe )
7 years ago
{
9 years ago
Vector WallNormal = Vector( 0, 0, -1 ); // WATER normal is Straight Down for fish.
7 years ago
float frac;
9 years ago
BOOL bBumpedSomething = ProbeZ( pev->origin, Probe, &frac );
7 years ago
TraceResult tr;
9 years ago
TRACE_MONSTER_HULL( edict(), pev->origin, Probe, dont_ignore_monsters, edict(), &tr );
if( tr.fAllSolid || tr.flFraction < 0.99 )
7 years ago
{
9 years ago
if( tr.flFraction < 0.0 )
tr.flFraction = 0.0;
if( tr.flFraction > 1.0 )
tr.flFraction = 1.0;
if( tr.flFraction < frac )
7 years ago
{
frac = tr.flFraction;
bBumpedSomething = TRUE;
WallNormal = tr.vecPlaneNormal;
}
}
if( bBumpedSomething && ( m_hEnemy == 0 || tr.pHit != m_hEnemy->edict() ) )
7 years ago
{
Vector ProbeDir = Probe - pev->origin;
9 years ago
Vector NormalToProbeAndWallNormal = CrossProduct( ProbeDir, WallNormal );
Vector SteeringVector = CrossProduct( NormalToProbeAndWallNormal, ProbeDir );
7 years ago
9 years ago
float SteeringForce = m_flightSpeed * ( 1 -frac ) * ( DotProduct( WallNormal.Normalize(), m_SaveVelocity.Normalize() ) );
if( SteeringForce < 0.0 )
7 years ago
{
SteeringForce = -SteeringForce;
}
SteeringVector = SteeringForce * SteeringVector.Normalize();
return SteeringVector;
}
9 years ago
return Vector( 0, 0, 0 );
7 years ago
}
#endif