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.

1362 lines
33 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.
*
****/
#if !defined( OEM_BUILD ) && !defined( HLDEMO_BUILD )
//=========================================================
// CONTROLLER
//=========================================================
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "monsters.h"
#include "effects.h"
#include "schedule.h"
#include "weapons.h"
#include "squadmonster.h"
//=========================================================
// Monster's Anim Events Go Here
//=========================================================
9 years ago
#define CONTROLLER_AE_HEAD_OPEN 1
#define CONTROLLER_AE_BALL_SHOOT 2
#define CONTROLLER_AE_SMALL_SHOOT 3
#define CONTROLLER_AE_POWERUP_FULL 4
#define CONTROLLER_AE_POWERUP_HALF 5
9 years ago
#define CONTROLLER_FLINCH_DELAY 2 // at most one flinch every n secs
class CController : public CSquadMonster
{
public:
9 years ago
virtual int Save( CSave &save );
virtual int Restore( CRestore &restore );
static TYPEDESCRIPTION m_SaveData[];
9 years ago
void Spawn( void );
void Precache( void );
void SetYawSpeed( void );
9 years ago
int Classify( void );
9 years ago
void HandleAnimEvent( MonsterEvent_t *pEvent );
void RunAI( void );
9 years ago
BOOL CheckRangeAttack1( float flDot, float flDist ); // balls
BOOL CheckRangeAttack2( float flDot, float flDist ); // head
BOOL CheckMeleeAttack1( float flDot, float flDist ); // block, throw
Schedule_t *GetSchedule( void );
Schedule_t *GetScheduleOfType( int Type );
void StartTask( Task_t *pTask );
void RunTask( Task_t *pTask );
CUSTOM_SCHEDULES
9 years ago
void Stop( void );
9 years ago
void Move( float flInterval );
int CheckLocalMove( const Vector &vecStart, const Vector &vecEnd, CBaseEntity *pTarget, float *pflDist );
9 years ago
void MoveExecute( CBaseEntity *pTargetEnt, const Vector &vecDir, float flInterval );
9 years ago
void SetActivity( Activity NewActivity );
9 years ago
BOOL ShouldAdvanceRoute( float flWaypointDist );
9 years ago
int LookupFloat();
9 years ago
float m_flNextFlinch;
float m_flShootTime;
float m_flShootEnd;
void PainSound( void );
void AlertSound( void );
void IdleSound( void );
void AttackSound( void );
void DeathSound( void );
static const char *pAttackSounds[];
static const char *pIdleSounds[];
static const char *pAlertSounds[];
static const char *pPainSounds[];
static const char *pDeathSounds[];
int TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType );
void Killed( entvars_t *pevAttacker, int iGib );
void GibMonster( void );
CSprite *m_pBall[2]; // hand balls
9 years ago
int m_iBall[2]; // how bright it should be
9 years ago
float m_iBallTime[2]; // when it should be that color
int m_iBallCurrent[2]; // current brightness
Vector m_vecEstVelocity;
Vector m_velocity;
int m_fInCombat;
};
LINK_ENTITY_TO_CLASS( monster_alien_controller, CController )
9 years ago
9 years ago
TYPEDESCRIPTION CController::m_SaveData[] =
9 years ago
{
DEFINE_ARRAY( CController, m_pBall, FIELD_CLASSPTR, 2 ),
DEFINE_ARRAY( CController, m_iBall, FIELD_INTEGER, 2 ),
DEFINE_ARRAY( CController, m_iBallTime, FIELD_TIME, 2 ),
DEFINE_ARRAY( CController, m_iBallCurrent, FIELD_INTEGER, 2 ),
DEFINE_FIELD( CController, m_vecEstVelocity, FIELD_VECTOR ),
};
IMPLEMENT_SAVERESTORE( CController, CSquadMonster )
9 years ago
9 years ago
const char *CController::pAttackSounds[] =
9 years ago
{
"controller/con_attack1.wav",
"controller/con_attack2.wav",
"controller/con_attack3.wav",
};
9 years ago
const char *CController::pIdleSounds[] =
9 years ago
{
"controller/con_idle1.wav",
"controller/con_idle2.wav",
"controller/con_idle3.wav",
"controller/con_idle4.wav",
"controller/con_idle5.wav",
};
9 years ago
const char *CController::pAlertSounds[] =
9 years ago
{
"controller/con_alert1.wav",
"controller/con_alert2.wav",
"controller/con_alert3.wav",
};
9 years ago
const char *CController::pPainSounds[] =
9 years ago
{
"controller/con_pain1.wav",
"controller/con_pain2.wav",
"controller/con_pain3.wav",
};
9 years ago
const char *CController::pDeathSounds[] =
9 years ago
{
"controller/con_die1.wav",
"controller/con_die2.wav",
};
//=========================================================
// Classify - indicates this monster's place in the
// relationship table.
//=========================================================
9 years ago
int CController::Classify( void )
9 years ago
{
return CLASS_ALIEN_MILITARY;
}
//=========================================================
// SetYawSpeed - allows each sequence to have a different
// turn rate associated with it.
//=========================================================
9 years ago
void CController::SetYawSpeed( void )
9 years ago
{
int ys;
ys = 120;
#if 0
switch ( m_Activity )
{
}
#endif
pev->yaw_speed = ys;
}
9 years ago
int CController::TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType )
9 years ago
{
// HACK HACK -- until we fix this.
9 years ago
if( IsAlive() )
9 years ago
PainSound();
return CBaseMonster::TakeDamage( pevInflictor, pevAttacker, flDamage, bitsDamageType );
}
void CController::Killed( entvars_t *pevAttacker, int iGib )
{
// shut off balls
/*
m_iBall[0] = 0;
m_iBallTime[0] = gpGlobals->time + 4.0;
m_iBall[1] = 0;
m_iBallTime[1] = gpGlobals->time + 4.0;
*/
// fade balls
9 years ago
if( m_pBall[0] )
9 years ago
{
m_pBall[0]->SUB_StartFadeOut();
m_pBall[0] = NULL;
}
9 years ago
if( m_pBall[1] )
9 years ago
{
m_pBall[1]->SUB_StartFadeOut();
m_pBall[1] = NULL;
}
CSquadMonster::Killed( pevAttacker, iGib );
}
void CController::GibMonster( void )
{
// delete balls
9 years ago
if( m_pBall[0] )
9 years ago
{
UTIL_Remove( m_pBall[0] );
m_pBall[0] = NULL;
}
9 years ago
if( m_pBall[1] )
9 years ago
{
UTIL_Remove( m_pBall[1] );
m_pBall[1] = NULL;
}
9 years ago
CSquadMonster::GibMonster();
9 years ago
}
9 years ago
void CController::PainSound( void )
9 years ago
{
9 years ago
if( RANDOM_LONG( 0, 5 ) < 2 )
9 years ago
EMIT_SOUND_ARRAY_DYN( CHAN_VOICE, pPainSounds );
}
9 years ago
void CController::AlertSound( void )
9 years ago
{
EMIT_SOUND_ARRAY_DYN( CHAN_VOICE, pAlertSounds );
}
9 years ago
void CController::IdleSound( void )
9 years ago
{
EMIT_SOUND_ARRAY_DYN( CHAN_VOICE, pIdleSounds );
}
9 years ago
void CController::AttackSound( void )
9 years ago
{
EMIT_SOUND_ARRAY_DYN( CHAN_VOICE, pAttackSounds );
}
9 years ago
void CController::DeathSound( void )
9 years ago
{
EMIT_SOUND_ARRAY_DYN( CHAN_VOICE, pDeathSounds );
}
//=========================================================
// HandleAnimEvent - catches the monster-specific messages
// that occur when tagged animation frames are played.
//=========================================================
9 years ago
void CController::HandleAnimEvent( MonsterEvent_t *pEvent )
9 years ago
{
switch( pEvent->event )
{
case CONTROLLER_AE_HEAD_OPEN:
{
Vector vecStart, angleGun;
9 years ago
9 years ago
GetAttachment( 0, vecStart, angleGun );
9 years ago
9 years ago
MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY );
WRITE_BYTE( TE_ELIGHT );
9 years ago
WRITE_SHORT( entindex() + 0x1000 ); // entity, attachment
9 years ago
WRITE_COORD( vecStart.x ); // origin
WRITE_COORD( vecStart.y );
WRITE_COORD( vecStart.z );
WRITE_COORD( 1 ); // radius
WRITE_BYTE( 255 ); // R
WRITE_BYTE( 192 ); // G
WRITE_BYTE( 64 ); // B
WRITE_BYTE( 20 ); // life * 10
WRITE_COORD( -32 ); // decay
MESSAGE_END();
m_iBall[0] = 192;
m_iBallTime[0] = gpGlobals->time + atoi( pEvent->options ) / 15.0;
m_iBall[1] = 255;
m_iBallTime[1] = gpGlobals->time + atoi( pEvent->options ) / 15.0;
}
break;
case CONTROLLER_AE_BALL_SHOOT:
{
Vector vecStart, angleGun;
GetAttachment( 0, vecStart, angleGun );
MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY );
WRITE_BYTE( TE_ELIGHT );
9 years ago
WRITE_SHORT( entindex() + 0x1000 ); // entity, attachment
9 years ago
WRITE_COORD( 0 ); // origin
WRITE_COORD( 0 );
WRITE_COORD( 0 );
WRITE_COORD( 32 ); // radius
WRITE_BYTE( 255 ); // R
WRITE_BYTE( 192 ); // G
WRITE_BYTE( 64 ); // B
WRITE_BYTE( 10 ); // life * 10
WRITE_COORD( 32 ); // decay
MESSAGE_END();
CBaseMonster *pBall = (CBaseMonster*)Create( "controller_head_ball", vecStart, pev->angles, edict() );
pBall->pev->velocity = Vector( 0, 0, 32 );
pBall->m_hEnemy = m_hEnemy;
m_iBall[0] = 0;
m_iBall[1] = 0;
}
break;
case CONTROLLER_AE_SMALL_SHOOT:
{
9 years ago
AttackSound();
9 years ago
m_flShootTime = gpGlobals->time;
m_flShootEnd = m_flShootTime + atoi( pEvent->options ) / 15.0;
}
break;
case CONTROLLER_AE_POWERUP_FULL:
{
m_iBall[0] = 255;
m_iBallTime[0] = gpGlobals->time + atoi( pEvent->options ) / 15.0;
m_iBall[1] = 255;
m_iBallTime[1] = gpGlobals->time + atoi( pEvent->options ) / 15.0;
}
break;
case CONTROLLER_AE_POWERUP_HALF:
{
m_iBall[0] = 192;
m_iBallTime[0] = gpGlobals->time + atoi( pEvent->options ) / 15.0;
m_iBall[1] = 192;
m_iBallTime[1] = gpGlobals->time + atoi( pEvent->options ) / 15.0;
}
break;
default:
CBaseMonster::HandleAnimEvent( pEvent );
break;
}
}
//=========================================================
// Spawn
//=========================================================
9 years ago
void CController::Spawn()
9 years ago
{
9 years ago
Precache();
9 years ago
9 years ago
SET_MODEL( ENT( pev ), "models/controller.mdl" );
UTIL_SetSize( pev, Vector( -32, -32, 0 ), Vector( 32, 32, 64 ) );
9 years ago
9 years ago
pev->solid = SOLID_SLIDEBOX;
9 years ago
pev->movetype = MOVETYPE_FLY;
9 years ago
pev->flags |= FL_FLY;
9 years ago
m_bloodColor = BLOOD_COLOR_GREEN;
9 years ago
pev->health = gSkillData.controllerHealth;
9 years ago
pev->view_ofs = Vector( 0, 0, -2 );// position of the eyes relative to monster's origin.
m_flFieldOfView = VIEW_FIELD_FULL;// indicates the width of this monster's forward view cone ( as a dotproduct result )
m_MonsterState = MONSTERSTATE_NONE;
MonsterInit();
}
//=========================================================
// Precache - precaches all resources this monster needs
//=========================================================
9 years ago
void CController::Precache()
9 years ago
{
9 years ago
PRECACHE_MODEL( "models/controller.mdl" );
9 years ago
PRECACHE_SOUND_ARRAY( pAttackSounds );
PRECACHE_SOUND_ARRAY( pIdleSounds );
PRECACHE_SOUND_ARRAY( pAlertSounds );
PRECACHE_SOUND_ARRAY( pPainSounds );
PRECACHE_SOUND_ARRAY( pDeathSounds );
9 years ago
PRECACHE_MODEL( "sprites/xspark4.spr" );
9 years ago
UTIL_PrecacheOther( "controller_energy_ball" );
UTIL_PrecacheOther( "controller_head_ball" );
}
//=========================================================
// AI Schedules Specific to this monster
//=========================================================
// Chase enemy schedule
9 years ago
Task_t tlControllerChaseEnemy[] =
9 years ago
{
9 years ago
{ TASK_GET_PATH_TO_ENEMY, (float)128 },
{ TASK_WAIT_FOR_MOVEMENT, (float)0 },
9 years ago
};
Schedule_t slControllerChaseEnemy[] =
{
9 years ago
{
9 years ago
tlControllerChaseEnemy,
9 years ago
ARRAYSIZE( tlControllerChaseEnemy ),
bits_COND_NEW_ENEMY |
9 years ago
bits_COND_TASK_FAILED,
0,
"ControllerChaseEnemy"
},
};
9 years ago
Task_t tlControllerStrafe[] =
9 years ago
{
9 years ago
{ TASK_WAIT, (float)0.2 },
{ TASK_GET_PATH_TO_ENEMY, (float)128 },
{ TASK_WAIT_FOR_MOVEMENT, (float)0 },
{ TASK_WAIT, (float)1 },
9 years ago
};
9 years ago
Schedule_t slControllerStrafe[] =
9 years ago
{
9 years ago
{
9 years ago
tlControllerStrafe,
9 years ago
ARRAYSIZE( tlControllerStrafe ),
9 years ago
bits_COND_NEW_ENEMY,
0,
"ControllerStrafe"
},
};
9 years ago
Task_t tlControllerTakeCover[] =
9 years ago
{
9 years ago
{ TASK_WAIT, (float)0.2 },
{ TASK_FIND_COVER_FROM_ENEMY, (float)0 },
{ TASK_WAIT_FOR_MOVEMENT, (float)0 },
{ TASK_WAIT, (float)1 },
9 years ago
};
9 years ago
Schedule_t slControllerTakeCover[] =
9 years ago
{
9 years ago
{
9 years ago
tlControllerTakeCover,
9 years ago
ARRAYSIZE( tlControllerTakeCover ),
9 years ago
bits_COND_NEW_ENEMY,
0,
"ControllerTakeCover"
},
};
9 years ago
Task_t tlControllerFail[] =
9 years ago
{
9 years ago
{ TASK_STOP_MOVING, 0 },
{ TASK_SET_ACTIVITY, (float)ACT_IDLE },
{ TASK_WAIT, (float)2 },
{ TASK_WAIT_PVS, (float)0 },
9 years ago
};
9 years ago
Schedule_t slControllerFail[] =
9 years ago
{
{
tlControllerFail,
9 years ago
ARRAYSIZE( tlControllerFail ),
9 years ago
0,
0,
"ControllerFail"
},
};
DEFINE_CUSTOM_SCHEDULES( CController )
{
slControllerChaseEnemy,
slControllerStrafe,
slControllerTakeCover,
slControllerFail,
};
IMPLEMENT_CUSTOM_SCHEDULES( CController, CSquadMonster )
9 years ago
//=========================================================
// StartTask
//=========================================================
9 years ago
void CController::StartTask( Task_t *pTask )
9 years ago
{
9 years ago
switch( pTask->iTask )
9 years ago
{
case TASK_RANGE_ATTACK1:
9 years ago
CSquadMonster::StartTask( pTask );
9 years ago
break;
case TASK_GET_PATH_TO_ENEMY_LKP:
{
9 years ago
if( BuildNearestRoute( m_vecEnemyLKP, pev->view_ofs, pTask->flData, (m_vecEnemyLKP - pev->origin).Length() + 1024 ) )
9 years ago
{
TaskComplete();
}
else
{
// no way to get there =(
9 years ago
ALERT( at_aiconsole, "GetPathToEnemyLKP failed!!\n" );
9 years ago
TaskFail();
}
break;
}
case TASK_GET_PATH_TO_ENEMY:
{
CBaseEntity *pEnemy = m_hEnemy;
9 years ago
if( pEnemy == NULL )
9 years ago
{
TaskFail();
return;
}
9 years ago
if( BuildNearestRoute( pEnemy->pev->origin, pEnemy->pev->view_ofs, pTask->flData, ( pEnemy->pev->origin - pev->origin).Length() + 1024 ) )
9 years ago
{
TaskComplete();
}
else
{
// no way to get there =(
9 years ago
ALERT( at_aiconsole, "GetPathToEnemy failed!!\n" );
9 years ago
TaskFail();
}
break;
}
default:
9 years ago
CSquadMonster::StartTask( pTask );
9 years ago
break;
}
}
Vector Intersect( Vector vecSrc, Vector vecDst, Vector vecMove, float flSpeed )
{
Vector vecTo = vecDst - vecSrc;
float a = DotProduct( vecMove, vecMove ) - flSpeed * flSpeed;
9 years ago
float b = 0 * DotProduct( vecTo, vecMove ); // why does this work?
9 years ago
float c = DotProduct( vecTo, vecTo );
float t;
9 years ago
if( a == 0 )
9 years ago
{
9 years ago
t = c / ( flSpeed * flSpeed );
9 years ago
}
else
{
t = b * b - 4 * a * c;
9 years ago
t = sqrt( t ) / ( 2.0 * a );
9 years ago
float t1 = -b +t;
float t2 = -b -t;
9 years ago
if( t1 < 0 || t2 < t1 )
9 years ago
t = t2;
else
t = t1;
}
// ALERT( at_console, "Intersect %f\n", t );
9 years ago
if( t < 0.1 )
9 years ago
t = 0.1;
9 years ago
if( t > 10.0 )
9 years ago
t = 10.0;
Vector vecHit = vecTo + vecMove * t;
9 years ago
return vecHit.Normalize() * flSpeed;
9 years ago
}
9 years ago
int CController::LookupFloat()
9 years ago
{
9 years ago
if( m_velocity.Length() < 32.0 )
9 years ago
{
return LookupSequence( "up" );
}
UTIL_MakeAimVectors( pev->angles );
float x = DotProduct( gpGlobals->v_forward, m_velocity );
float y = DotProduct( gpGlobals->v_right, m_velocity );
float z = DotProduct( gpGlobals->v_up, m_velocity );
9 years ago
if( fabs( x ) > fabs( y ) && fabs( x ) > fabs( z ) )
9 years ago
{
9 years ago
if( x > 0 )
return LookupSequence( "forward" );
9 years ago
else
9 years ago
return LookupSequence( "backward" );
9 years ago
}
9 years ago
else if( fabs( y ) > fabs( z ) )
9 years ago
{
9 years ago
if( y > 0 )
return LookupSequence( "right" );
9 years ago
else
9 years ago
return LookupSequence( "left" );
9 years ago
}
else
{
9 years ago
if( z > 0 )
return LookupSequence( "up" );
9 years ago
else
9 years ago
return LookupSequence( "down" );
9 years ago
}
}
//=========================================================
// RunTask
//=========================================================
9 years ago
void CController::RunTask( Task_t *pTask )
9 years ago
{
9 years ago
if( m_flShootEnd > gpGlobals->time )
9 years ago
{
Vector vecHand, vecAngle;
9 years ago
9 years ago
GetAttachment( 2, vecHand, vecAngle );
9 years ago
while( m_flShootTime < m_flShootEnd && m_flShootTime < gpGlobals->time )
9 years ago
{
9 years ago
Vector vecSrc = vecHand + pev->velocity * ( m_flShootTime - gpGlobals->time );
9 years ago
Vector vecDir;
9 years ago
if( m_hEnemy != NULL )
9 years ago
{
9 years ago
if( HasConditions( bits_COND_SEE_ENEMY ) )
9 years ago
{
m_vecEstVelocity = m_vecEstVelocity * 0.5 + m_hEnemy->pev->velocity * 0.5;
}
else
{
m_vecEstVelocity = m_vecEstVelocity * 0.8;
}
vecDir = Intersect( vecSrc, m_hEnemy->BodyTarget( pev->origin ), m_vecEstVelocity, gSkillData.controllerSpeedBall );
float delta = 0.03490; // +-2 degree
vecDir = vecDir + Vector( RANDOM_FLOAT( -delta, delta ), RANDOM_FLOAT( -delta, delta ), RANDOM_FLOAT( -delta, delta ) ) * gSkillData.controllerSpeedBall;
9 years ago
vecSrc = vecSrc + vecDir * ( gpGlobals->time - m_flShootTime );
9 years ago
CBaseMonster *pBall = (CBaseMonster*)Create( "controller_energy_ball", vecSrc, pev->angles, edict() );
pBall->pev->velocity = vecDir;
}
m_flShootTime += 0.2;
}
9 years ago
if( m_flShootTime > m_flShootEnd )
9 years ago
{
m_iBall[0] = 64;
m_iBallTime[0] = m_flShootEnd;
m_iBall[1] = 64;
m_iBallTime[1] = m_flShootEnd;
m_fInCombat = FALSE;
}
}
9 years ago
switch( pTask->iTask )
9 years ago
{
case TASK_WAIT_FOR_MOVEMENT:
case TASK_WAIT:
case TASK_WAIT_FACE_ENEMY:
case TASK_WAIT_PVS:
MakeIdealYaw( m_vecEnemyLKP );
ChangeYaw( pev->yaw_speed );
9 years ago
if( m_fSequenceFinished )
9 years ago
{
m_fInCombat = FALSE;
}
9 years ago
CSquadMonster::RunTask( pTask );
9 years ago
9 years ago
if( !m_fInCombat )
9 years ago
{
9 years ago
if( HasConditions( bits_COND_CAN_RANGE_ATTACK1 ) )
9 years ago
{
pev->sequence = LookupActivity( ACT_RANGE_ATTACK1 );
pev->frame = 0;
9 years ago
ResetSequenceInfo();
9 years ago
m_fInCombat = TRUE;
}
9 years ago
else if( HasConditions( bits_COND_CAN_RANGE_ATTACK2 ) )
9 years ago
{
pev->sequence = LookupActivity( ACT_RANGE_ATTACK2 );
pev->frame = 0;
9 years ago
ResetSequenceInfo();
9 years ago
m_fInCombat = TRUE;
}
else
{
9 years ago
int iFloat = LookupFloat();
if( m_fSequenceFinished || iFloat != pev->sequence )
9 years ago
{
pev->sequence = iFloat;
pev->frame = 0;
9 years ago
ResetSequenceInfo();
9 years ago
}
}
}
break;
default:
9 years ago
CSquadMonster::RunTask( pTask );
9 years ago
break;
}
}
//=========================================================
// GetSchedule - Decides which type of schedule best suits
// the monster's current state and conditions. Then calls
// monster's member function to get a pointer to a schedule
// of the proper type.
//=========================================================
9 years ago
Schedule_t *CController::GetSchedule( void )
9 years ago
{
9 years ago
switch( m_MonsterState )
9 years ago
{
case MONSTERSTATE_COMBAT:
{
Vector vecTmp = Intersect( Vector( 0, 0, 0 ), Vector( 100, 4, 7 ), Vector( 2, 10, -3 ), 20.0 );
// dead enemy
9 years ago
if( HasConditions( bits_COND_LIGHT_DAMAGE ) )
9 years ago
{
// m_iFrustration++;
}
9 years ago
if( HasConditions( bits_COND_HEAVY_DAMAGE ) )
9 years ago
{
// m_iFrustration++;
}
}
break;
case MONSTERSTATE_IDLE:
case MONSTERSTATE_ALERT:
break;
default:
break;
9 years ago
}
9 years ago
return CSquadMonster::GetSchedule();
9 years ago
}
//=========================================================
//=========================================================
9 years ago
Schedule_t *CController::GetScheduleOfType( int Type )
9 years ago
{
// ALERT( at_console, "%d\n", m_iFrustration );
9 years ago
switch( Type )
9 years ago
{
case SCHED_CHASE_ENEMY:
return slControllerChaseEnemy;
case SCHED_RANGE_ATTACK1:
return slControllerStrafe;
case SCHED_RANGE_ATTACK2:
case SCHED_MELEE_ATTACK1:
case SCHED_MELEE_ATTACK2:
case SCHED_TAKE_COVER_FROM_ENEMY:
return slControllerTakeCover;
case SCHED_FAIL:
return slControllerFail;
}
9 years ago
return CBaseMonster::GetScheduleOfType( Type );
9 years ago
}
//=========================================================
// CheckRangeAttack1 - shoot a bigass energy ball out of their head
//
//=========================================================
9 years ago
BOOL CController::CheckRangeAttack1( float flDot, float flDist )
9 years ago
{
9 years ago
if( flDot > 0.5 && flDist > 256 && flDist <= 2048 )
9 years ago
{
return TRUE;
}
return FALSE;
}
9 years ago
BOOL CController::CheckRangeAttack2( float flDot, float flDist )
9 years ago
{
9 years ago
if( flDot > 0.5 && flDist > 64 && flDist <= 2048 )
9 years ago
{
return TRUE;
}
return FALSE;
}
9 years ago
BOOL CController::CheckMeleeAttack1( float flDot, float flDist )
9 years ago
{
return FALSE;
}
9 years ago
void CController::SetActivity( Activity NewActivity )
9 years ago
{
CBaseMonster::SetActivity( NewActivity );
9 years ago
switch( m_Activity )
9 years ago
{
case ACT_WALK:
m_flGroundSpeed = 100;
break;
default:
m_flGroundSpeed = 100;
break;
}
}
//=========================================================
// RunAI
//=========================================================
9 years ago
void CController::RunAI( void )
9 years ago
{
9 years ago
CBaseMonster::RunAI();
9 years ago
Vector vecStart, angleGun;
9 years ago
if( HasMemory( bits_MEMORY_KILLED ) )
9 years ago
return;
9 years ago
for( int i = 0; i < 2; i++ )
9 years ago
{
9 years ago
if( m_pBall[i] == NULL )
9 years ago
{
m_pBall[i] = CSprite::SpriteCreate( "sprites/xspark4.spr", pev->origin, TRUE );
m_pBall[i]->SetTransparency( kRenderGlow, 255, 255, 255, 255, kRenderFxNoDissipation );
9 years ago
m_pBall[i]->SetAttachment( edict(), ( i + 3 ) );
9 years ago
m_pBall[i]->SetScale( 1.0 );
}
float t = m_iBallTime[i] - gpGlobals->time;
9 years ago
if( t > 0.1 )
9 years ago
t = 0.1 / t;
else
t = 1.0;
9 years ago
m_iBallCurrent[i] += ( m_iBall[i] - m_iBallCurrent[i] ) * t;
9 years ago
m_pBall[i]->SetBrightness( m_iBallCurrent[i] );
GetAttachment( i + 2, vecStart, angleGun );
UTIL_SetOrigin( m_pBall[i]->pev, vecStart );
9 years ago
9 years ago
MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY );
WRITE_BYTE( TE_ELIGHT );
9 years ago
WRITE_SHORT( entindex() + 0x1000 * ( i + 3 ) ); // entity, attachment
9 years ago
WRITE_COORD( vecStart.x ); // origin
WRITE_COORD( vecStart.y );
WRITE_COORD( vecStart.z );
WRITE_COORD( m_iBallCurrent[i] / 8 ); // radius
WRITE_BYTE( 255 ); // R
WRITE_BYTE( 192 ); // G
WRITE_BYTE( 64 ); // B
WRITE_BYTE( 5 ); // life * 10
WRITE_COORD( 0 ); // decay
MESSAGE_END();
}
}
extern void DrawRoute( entvars_t *pev, WayPoint_t *m_Route, int m_iRouteIndex, int r, int g, int b );
9 years ago
void CController::Stop( void )
9 years ago
{
m_IdealActivity = GetStoppedActivity();
}
#define DIST_TO_CHECK 200
9 years ago
void CController::Move( float flInterval )
9 years ago
{
float flWaypointDist;
float flCheckDist;
float flDist;// how far the lookahead check got before hitting an object.
float flMoveDist;
Vector vecDir;
Vector vecApex;
CBaseEntity *pTargetEnt;
// Don't move if no valid route
9 years ago
if( FRouteClear() )
9 years ago
{
ALERT( at_aiconsole, "Tried to move with no route!\n" );
TaskFail();
return;
}
9 years ago
if( m_flMoveWaitFinished > gpGlobals->time )
9 years ago
return;
// Debug, test movement code
#if 0
9 years ago
// if( CVAR_GET_FLOAT( "stopmove" ) != 0 )
9 years ago
{
9 years ago
if( m_movementGoal == MOVEGOAL_ENEMY )
9 years ago
RouteSimplify( m_hEnemy );
else
RouteSimplify( m_hTargetEnt );
FRefreshRoute();
return;
}
#else
// Debug, draw the route
// DrawRoute( pev, m_Route, m_iRouteIndex, 0, 0, 255 );
#endif
// if the monster is moving directly towards an entity (enemy for instance), we'll set this pointer
// to that entity for the CheckLocalMove and Triangulate functions.
pTargetEnt = NULL;
9 years ago
if( m_flGroundSpeed == 0 )
9 years ago
{
m_flGroundSpeed = 100;
9 years ago
// TaskFail();
9 years ago
// return;
}
flMoveDist = m_flGroundSpeed * flInterval;
9 years ago
do
9 years ago
{
// local move to waypoint.
9 years ago
vecDir = ( m_Route[m_iRouteIndex].vecLocation - pev->origin ).Normalize();
flWaypointDist = ( m_Route[m_iRouteIndex].vecLocation - pev->origin ).Length();
// MakeIdealYaw( m_Route[m_iRouteIndex].vecLocation );
// ChangeYaw( pev->yaw_speed );
9 years ago
// if the waypoint is closer than CheckDist, CheckDist is the dist to waypoint
9 years ago
if( flWaypointDist < DIST_TO_CHECK )
9 years ago
{
flCheckDist = flWaypointDist;
}
else
{
flCheckDist = DIST_TO_CHECK;
}
9 years ago
if( ( m_Route[m_iRouteIndex].iType & ( ~bits_MF_NOT_TO_MASK ) ) == bits_MF_TO_ENEMY )
9 years ago
{
// only on a PURE move to enemy ( i.e., ONLY MF_TO_ENEMY set, not MF_TO_ENEMY and DETOUR )
pTargetEnt = m_hEnemy;
}
9 years ago
else if( ( m_Route[m_iRouteIndex].iType & ~bits_MF_NOT_TO_MASK ) == bits_MF_TO_TARGETENT )
9 years ago
{
pTargetEnt = m_hTargetEnt;
}
// !!!BUGBUG - CheckDist should be derived from ground speed.
// If this fails, it should be because of some dynamic entity blocking this guy.
// We've already checked this path, so we should wait and time out if the entity doesn't move
flDist = 0;
9 years ago
if( CheckLocalMove( pev->origin, pev->origin + vecDir * flCheckDist, pTargetEnt, &flDist ) != LOCALMOVE_VALID )
9 years ago
{
CBaseEntity *pBlocker;
// Can't move, stop
Stop();
// Blocking entity is in global trace_ent
pBlocker = CBaseEntity::Instance( gpGlobals->trace_ent );
9 years ago
if( pBlocker )
9 years ago
{
DispatchBlocked( edict(), pBlocker->edict() );
}
9 years ago
if( pBlocker && m_moveWaitTime > 0 && pBlocker->IsMoving() && !pBlocker->IsPlayer() && (gpGlobals->time-m_flMoveWaitFinished) > 3.0 )
9 years ago
{
// Can we still move toward our target?
9 years ago
if( flDist < m_flGroundSpeed )
9 years ago
{
// Wait for a second
m_flMoveWaitFinished = gpGlobals->time + m_moveWaitTime;
//ALERT( at_aiconsole, "Move %s!!!\n", STRING( pBlocker->pev->classname ) );
9 years ago
return;
}
}
9 years ago
else
9 years ago
{
// try to triangulate around whatever is in the way.
9 years ago
if( FTriangulate( pev->origin, m_Route[m_iRouteIndex].vecLocation, flDist, pTargetEnt, &vecApex ) )
9 years ago
{
InsertWaypoint( vecApex, bits_MF_TO_DETOUR );
RouteSimplify( pTargetEnt );
}
else
{
ALERT ( at_aiconsole, "Couldn't Triangulate\n" );
9 years ago
Stop();
9 years ago
if( m_moveWaitTime > 0 )
9 years ago
{
FRefreshRoute();
m_flMoveWaitFinished = gpGlobals->time + m_moveWaitTime * 0.5;
}
else
{
TaskFail();
ALERT( at_aiconsole, "Failed to move!\n" );
9 years ago
//ALERT( at_aiconsole, "%f, %f, %f\n", pev->origin.z, ( pev->origin + ( vecDir * flCheckDist ) ).z, m_Route[m_iRouteIndex].vecLocation.z );
9 years ago
}
return;
}
}
}
// UNDONE: this is a hack to quit moving farther than it has looked ahead.
9 years ago
if( flCheckDist < flMoveDist )
9 years ago
{
MoveExecute( pTargetEnt, vecDir, flCheckDist / m_flGroundSpeed );
// ALERT( at_console, "%.02f\n", flInterval );
AdvanceRoute( flWaypointDist );
flMoveDist -= flCheckDist;
}
else
{
MoveExecute( pTargetEnt, vecDir, flMoveDist / m_flGroundSpeed );
9 years ago
if( ShouldAdvanceRoute( flWaypointDist - flMoveDist ) )
9 years ago
{
AdvanceRoute( flWaypointDist );
}
flMoveDist = 0;
}
9 years ago
if( MovementIsComplete() )
9 years ago
{
Stop();
RouteClear();
}
9 years ago
} while( flMoveDist > 0 && flCheckDist > 0 );
9 years ago
// cut corner?
9 years ago
if( flWaypointDist < 128 )
9 years ago
{
9 years ago
if( m_movementGoal == MOVEGOAL_ENEMY )
9 years ago
RouteSimplify( m_hEnemy );
else
RouteSimplify( m_hTargetEnt );
FRefreshRoute();
9 years ago
if( m_flGroundSpeed > 100 )
9 years ago
m_flGroundSpeed -= 40;
}
else
{
9 years ago
if( m_flGroundSpeed < 400 )
9 years ago
m_flGroundSpeed += 10;
}
}
9 years ago
BOOL CController::ShouldAdvanceRoute( float flWaypointDist )
9 years ago
{
9 years ago
if( flWaypointDist <= 32 )
9 years ago
{
return TRUE;
}
return FALSE;
}
9 years ago
int CController::CheckLocalMove( const Vector &vecStart, const Vector &vecEnd, CBaseEntity *pTarget, float *pflDist )
9 years ago
{
TraceResult tr;
9 years ago
UTIL_TraceHull( vecStart + Vector( 0, 0, 32 ), vecEnd + Vector( 0, 0, 32 ), 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 );
9 years ago
if( pflDist )
9 years ago
{
9 years ago
*pflDist = ( ( tr.vecEndPos - Vector( 0, 0, 32 ) ) - vecStart ).Length();// get the distance.
9 years ago
}
// ALERT( at_console, "check %d %d %f\n", tr.fStartSolid, tr.fAllSolid, tr.flFraction );
9 years ago
if( tr.fStartSolid || tr.flFraction < 1.0 )
9 years ago
{
9 years ago
if( pTarget && pTarget->edict() == gpGlobals->trace_ent )
9 years ago
return LOCALMOVE_VALID;
return LOCALMOVE_INVALID;
}
return LOCALMOVE_VALID;
}
void CController::MoveExecute( CBaseEntity *pTargetEnt, const Vector &vecDir, float flInterval )
{
9 years ago
if( m_IdealActivity != m_movementActivity )
9 years ago
m_IdealActivity = m_movementActivity;
// ALERT( at_console, "move %.4f %.4f %.4f : %f\n", vecDir.x, vecDir.y, vecDir.z, flInterval );
// float flTotal = m_flGroundSpeed * pev->framerate * flInterval;
9 years ago
// UTIL_MoveToOrigin ( ENT( pev ), m_Route[m_iRouteIndex].vecLocation, flTotal, MOVE_STRAFE );
9 years ago
m_velocity = m_velocity * 0.8 + m_flGroundSpeed * vecDir * 0.2;
9 years ago
UTIL_MoveToOrigin( ENT( pev ), pev->origin + m_velocity, m_velocity.Length() * flInterval, MOVE_STRAFE );
9 years ago
}
//=========================================================
// Controller bouncy ball attack
//=========================================================
class CControllerHeadBall : public CBaseMonster
{
void Spawn( void );
void Precache( void );
void EXPORT HuntThink( void );
void EXPORT DieThink( void );
void EXPORT BounceTouch( CBaseEntity *pOther );
void MovetoTarget( Vector vecTarget );
void Crawl( void );
int m_iTrail;
int m_flNextAttack;
Vector m_vecIdeal;
EHANDLE m_hOwner;
};
LINK_ENTITY_TO_CLASS( controller_head_ball, CControllerHeadBall )
9 years ago
9 years ago
void CControllerHeadBall::Spawn( void )
9 years ago
{
9 years ago
Precache();
9 years ago
// motor
pev->movetype = MOVETYPE_FLY;
pev->solid = SOLID_BBOX;
9 years ago
SET_MODEL(ENT( pev ), "sprites/xspark4.spr" );
9 years ago
pev->rendermode = kRenderTransAdd;
pev->rendercolor.x = 255;
pev->rendercolor.y = 255;
pev->rendercolor.z = 255;
pev->renderamt = 255;
pev->scale = 2.0;
9 years ago
UTIL_SetSize(pev, Vector( 0, 0, 0 ), Vector( 0, 0, 0 ) );
9 years ago
UTIL_SetOrigin( pev, pev->origin );
SetThink( &CControllerHeadBall::HuntThink );
SetTouch( &CControllerHeadBall::BounceTouch );
m_vecIdeal = Vector( 0, 0, 0 );
pev->nextthink = gpGlobals->time + 0.1;
m_hOwner = Instance( pev->owner );
pev->dmgtime = gpGlobals->time;
}
9 years ago
void CControllerHeadBall::Precache( void )
9 years ago
{
9 years ago
PRECACHE_MODEL( "sprites/xspark1.spr" );
PRECACHE_SOUND( "debris/zap4.wav" );
PRECACHE_SOUND( "weapons/electro4.wav" );
9 years ago
}
9 years ago
void CControllerHeadBall::HuntThink( void )
9 years ago
{
pev->nextthink = gpGlobals->time + 0.1;
pev->renderamt -= 5;
MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY );
WRITE_BYTE( TE_ELIGHT );
9 years ago
WRITE_SHORT( entindex() ); // entity, attachment
9 years ago
WRITE_COORD( pev->origin.x ); // origin
WRITE_COORD( pev->origin.y );
WRITE_COORD( pev->origin.z );
WRITE_COORD( pev->renderamt / 16 ); // radius
WRITE_BYTE( 255 ); // R
WRITE_BYTE( 255 ); // G
WRITE_BYTE( 255 ); // B
WRITE_BYTE( 2 ); // life * 10
WRITE_COORD( 0 ); // decay
MESSAGE_END();
// check world boundaries
9 years ago
if( gpGlobals->time - pev->dmgtime > 5 || pev->renderamt < 64 || m_hEnemy == NULL || m_hOwner == NULL || pev->origin.x < -4096 || pev->origin.x > 4096 || pev->origin.y < -4096 || pev->origin.y > 4096 || pev->origin.z < -4096 || pev->origin.z > 4096 )
9 years ago
{
SetTouch( NULL );
UTIL_Remove( this );
return;
}
9 years ago
MovetoTarget( m_hEnemy->Center() );
9 years ago
9 years ago
if( ( m_hEnemy->Center() - pev->origin ).Length() < 64 )
9 years ago
{
TraceResult tr;
9 years ago
UTIL_TraceLine( pev->origin, m_hEnemy->Center(), dont_ignore_monsters, ENT( pev ), &tr );
9 years ago
9 years ago
CBaseEntity *pEntity = CBaseEntity::Instance( tr.pHit );
if( pEntity != NULL && pEntity->pev->takedamage )
9 years ago
{
9 years ago
ClearMultiDamage();
9 years ago
pEntity->TraceAttack( m_hOwner->pev, gSkillData.controllerDmgZap, pev->velocity, &tr, DMG_SHOCK );
ApplyMultiDamage( pev, m_hOwner->pev );
}
MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY );
WRITE_BYTE( TE_BEAMENTPOINT );
WRITE_SHORT( entindex() );
WRITE_COORD( tr.vecEndPos.x );
WRITE_COORD( tr.vecEndPos.y );
WRITE_COORD( tr.vecEndPos.z );
WRITE_SHORT( g_sModelIndexLaser );
WRITE_BYTE( 0 ); // frame start
WRITE_BYTE( 10 ); // framerate
WRITE_BYTE( 3 ); // life
WRITE_BYTE( 20 ); // width
WRITE_BYTE( 0 ); // noise
WRITE_BYTE( 255 ); // r, g, b
WRITE_BYTE( 255 ); // r, g, b
WRITE_BYTE( 255 ); // r, g, b
WRITE_BYTE( 255 ); // brightness
WRITE_BYTE( 10 ); // speed
MESSAGE_END();
9 years ago
UTIL_EmitAmbientSound( ENT( pev ), tr.vecEndPos, "weapons/electro4.wav", 0.5, ATTN_NORM, 0, RANDOM_LONG( 140, 160 ) );
9 years ago
m_flNextAttack = gpGlobals->time + 3.0;
SetThink( &CControllerHeadBall::DieThink );
pev->nextthink = gpGlobals->time + 0.3;
}
9 years ago
//Crawl();
9 years ago
}
9 years ago
void CControllerHeadBall::DieThink( void )
9 years ago
{
UTIL_Remove( this );
}
9 years ago
void CControllerHeadBall::MovetoTarget( Vector vecTarget )
9 years ago
{
// accelerate
float flSpeed = m_vecIdeal.Length();
9 years ago
if( flSpeed == 0 )
9 years ago
{
m_vecIdeal = pev->velocity;
flSpeed = m_vecIdeal.Length();
}
9 years ago
if( flSpeed > 400 )
9 years ago
{
9 years ago
m_vecIdeal = m_vecIdeal.Normalize() * 400;
9 years ago
}
9 years ago
m_vecIdeal = m_vecIdeal + ( vecTarget - pev->origin ).Normalize() * 100;
9 years ago
pev->velocity = m_vecIdeal;
}
9 years ago
void CControllerHeadBall::Crawl( void )
9 years ago
{
9 years ago
Vector vecAim = Vector( RANDOM_FLOAT( -1, 1 ), RANDOM_FLOAT( -1, 1 ), RANDOM_FLOAT( -1, 1 ) ).Normalize();
9 years ago
Vector vecPnt = pev->origin + pev->velocity * 0.3 + vecAim * 64;
MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY );
WRITE_BYTE( TE_BEAMENTPOINT );
WRITE_SHORT( entindex() );
WRITE_COORD( vecPnt.x);
WRITE_COORD( vecPnt.y);
WRITE_COORD( vecPnt.z);
WRITE_SHORT( g_sModelIndexLaser );
WRITE_BYTE( 0 ); // frame start
WRITE_BYTE( 10 ); // framerate
WRITE_BYTE( 3 ); // life
WRITE_BYTE( 20 ); // width
WRITE_BYTE( 0 ); // noise
WRITE_BYTE( 255 ); // r, g, b
WRITE_BYTE( 255 ); // r, g, b
WRITE_BYTE( 255 ); // r, g, b
WRITE_BYTE( 255 ); // brightness
WRITE_BYTE( 10 ); // speed
MESSAGE_END();
}
void CControllerHeadBall::BounceTouch( CBaseEntity *pOther )
{
9 years ago
Vector vecDir = m_vecIdeal.Normalize();
9 years ago
9 years ago
TraceResult tr = UTIL_GetGlobalTrace();
9 years ago
9 years ago
float n = -DotProduct( tr.vecPlaneNormal, vecDir );
9 years ago
vecDir = 2.0 * tr.vecPlaneNormal * n + vecDir;
m_vecIdeal = vecDir * m_vecIdeal.Length();
}
class CControllerZapBall : public CBaseMonster
{
void Spawn( void );
void Precache( void );
void EXPORT AnimateThink( void );
void EXPORT ExplodeTouch( CBaseEntity *pOther );
EHANDLE m_hOwner;
};
LINK_ENTITY_TO_CLASS( controller_energy_ball, CControllerZapBall )
9 years ago
9 years ago
void CControllerZapBall::Spawn( void )
9 years ago
{
9 years ago
Precache();
9 years ago
// motor
pev->movetype = MOVETYPE_FLY;
pev->solid = SOLID_BBOX;
9 years ago
SET_MODEL( ENT( pev ), "sprites/xspark4.spr" );
9 years ago
pev->rendermode = kRenderTransAdd;
pev->rendercolor.x = 255;
pev->rendercolor.y = 255;
pev->rendercolor.z = 255;
pev->renderamt = 255;
pev->scale = 0.5;
9 years ago
UTIL_SetSize( pev, Vector( 0, 0, 0 ), Vector( 0, 0, 0 ) );
9 years ago
UTIL_SetOrigin( pev, pev->origin );
SetThink( &CControllerZapBall::AnimateThink );
SetTouch( &CControllerZapBall::ExplodeTouch );
m_hOwner = Instance( pev->owner );
pev->dmgtime = gpGlobals->time; // keep track of when ball spawned
pev->nextthink = gpGlobals->time + 0.1;
}
9 years ago
void CControllerZapBall::Precache( void )
9 years ago
{
9 years ago
PRECACHE_MODEL( "sprites/xspark4.spr" );
// PRECACHE_SOUND( "debris/zap4.wav" );
// PRECACHE_SOUND( "weapons/electro4.wav" );
9 years ago
}
9 years ago
void CControllerZapBall::AnimateThink( void )
9 years ago
{
pev->nextthink = gpGlobals->time + 0.1;
9 years ago
pev->frame = ( (int)pev->frame + 1 ) % 11;
if( gpGlobals->time - pev->dmgtime > 5 || pev->velocity.Length() < 10 )
9 years ago
{
SetTouch( NULL );
UTIL_Remove( this );
}
}
void CControllerZapBall::ExplodeTouch( CBaseEntity *pOther )
{
9 years ago
if( pOther->pev->takedamage )
9 years ago
{
9 years ago
TraceResult tr = UTIL_GetGlobalTrace();
entvars_t *pevOwner;
9 years ago
9 years ago
if( m_hOwner != NULL )
9 years ago
{
pevOwner = m_hOwner->pev;
}
else
{
pevOwner = pev;
}
9 years ago
ClearMultiDamage();
9 years ago
pOther->TraceAttack(pevOwner, gSkillData.controllerDmgBall, pev->velocity.Normalize(), &tr, DMG_ENERGYBEAM );
ApplyMultiDamage( pevOwner, pevOwner );
9 years ago
UTIL_EmitAmbientSound( ENT( pev ), tr.vecEndPos, "weapons/electro4.wav", 0.3, ATTN_NORM, 0, RANDOM_LONG( 90, 99 ) );
9 years ago
}
UTIL_Remove( this );
}
#endif //!OEM && !HLDEMO