2
0
mirror of https://github.com/FWGS/hlsdk-xash3d synced 2024-11-11 12:49:49 +01:00
hlsdk-xash3d/dlls/controller.cpp

1362 lines
33 KiB
C++
Raw Normal View History

2016-06-04 15:24:23 +02:00
/***
*
* 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
//=========================================================
2016-07-31 15:48:50 +02:00
#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
2016-06-04 15:24:23 +02:00
#define CONTROLLER_FLINCH_DELAY 2 // at most one flinch every n secs
class CController : public CSquadMonster
{
public:
2016-07-31 15:48:50 +02:00
virtual int Save( CSave &save );
virtual int Restore( CRestore &restore );
static TYPEDESCRIPTION m_SaveData[];
2016-06-04 15:24:23 +02:00
void Spawn( void );
void Precache( void );
void SetYawSpeed( void );
2016-07-31 15:48:50 +02:00
int Classify( void );
2016-06-04 15:24:23 +02:00
void HandleAnimEvent( MonsterEvent_t *pEvent );
void RunAI( void );
2016-07-31 15:48:50 +02:00
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 );
2016-06-25 20:21:01 +02:00
CUSTOM_SCHEDULES
2016-06-04 15:24:23 +02:00
void Stop( void );
2016-07-31 15:48:50 +02:00
void Move( float flInterval );
int CheckLocalMove( const Vector &vecStart, const Vector &vecEnd, CBaseEntity *pTarget, float *pflDist );
2016-06-04 15:24:23 +02:00
void MoveExecute( CBaseEntity *pTargetEnt, const Vector &vecDir, float flInterval );
2016-07-31 15:48:50 +02:00
void SetActivity( Activity NewActivity );
2016-06-04 15:24:23 +02:00
BOOL ShouldAdvanceRoute( float flWaypointDist );
2016-07-31 15:48:50 +02:00
int LookupFloat();
2016-06-04 15:24:23 +02:00
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
2016-07-31 15:48:50 +02:00
int m_iBall[2]; // how bright it should be
2016-06-04 15:24:23 +02:00
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 )
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
TYPEDESCRIPTION CController::m_SaveData[] =
2016-06-04 15:24:23 +02:00
{
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 )
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
const char *CController::pAttackSounds[] =
2016-06-04 15:24:23 +02:00
{
"controller/con_attack1.wav",
"controller/con_attack2.wav",
"controller/con_attack3.wav",
};
2016-07-31 15:48:50 +02:00
const char *CController::pIdleSounds[] =
2016-06-04 15:24:23 +02:00
{
"controller/con_idle1.wav",
"controller/con_idle2.wav",
"controller/con_idle3.wav",
"controller/con_idle4.wav",
"controller/con_idle5.wav",
};
2016-07-31 15:48:50 +02:00
const char *CController::pAlertSounds[] =
2016-06-04 15:24:23 +02:00
{
"controller/con_alert1.wav",
"controller/con_alert2.wav",
"controller/con_alert3.wav",
};
2016-07-31 15:48:50 +02:00
const char *CController::pPainSounds[] =
2016-06-04 15:24:23 +02:00
{
"controller/con_pain1.wav",
"controller/con_pain2.wav",
"controller/con_pain3.wav",
};
2016-07-31 15:48:50 +02:00
const char *CController::pDeathSounds[] =
2016-06-04 15:24:23 +02:00
{
"controller/con_die1.wav",
"controller/con_die2.wav",
};
//=========================================================
// Classify - indicates this monster's place in the
// relationship table.
//=========================================================
2016-07-31 15:48:50 +02:00
int CController::Classify( void )
2016-06-04 15:24:23 +02:00
{
return CLASS_ALIEN_MILITARY;
}
//=========================================================
// SetYawSpeed - allows each sequence to have a different
// turn rate associated with it.
//=========================================================
2016-07-31 15:48:50 +02:00
void CController::SetYawSpeed( void )
2016-06-04 15:24:23 +02:00
{
int ys;
ys = 120;
#if 0
switch ( m_Activity )
{
}
#endif
pev->yaw_speed = ys;
}
2016-07-31 15:48:50 +02:00
int CController::TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType )
2016-06-04 15:24:23 +02:00
{
// HACK HACK -- until we fix this.
2016-07-31 15:48:50 +02:00
if( IsAlive() )
2016-06-04 15:24:23 +02:00
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
2016-07-31 15:48:50 +02:00
if( m_pBall[0] )
2016-06-04 15:24:23 +02:00
{
m_pBall[0]->SUB_StartFadeOut();
m_pBall[0] = NULL;
}
2016-07-31 15:48:50 +02:00
if( m_pBall[1] )
2016-06-04 15:24:23 +02:00
{
m_pBall[1]->SUB_StartFadeOut();
m_pBall[1] = NULL;
}
CSquadMonster::Killed( pevAttacker, iGib );
}
void CController::GibMonster( void )
{
// delete balls
2016-07-31 15:48:50 +02:00
if( m_pBall[0] )
2016-06-04 15:24:23 +02:00
{
UTIL_Remove( m_pBall[0] );
m_pBall[0] = NULL;
}
2016-07-31 15:48:50 +02:00
if( m_pBall[1] )
2016-06-04 15:24:23 +02:00
{
UTIL_Remove( m_pBall[1] );
m_pBall[1] = NULL;
}
2016-07-31 15:48:50 +02:00
CSquadMonster::GibMonster();
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
void CController::PainSound( void )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( RANDOM_LONG( 0, 5 ) < 2 )
2016-06-04 15:24:23 +02:00
EMIT_SOUND_ARRAY_DYN( CHAN_VOICE, pPainSounds );
}
2016-07-31 15:48:50 +02:00
void CController::AlertSound( void )
2016-06-04 15:24:23 +02:00
{
EMIT_SOUND_ARRAY_DYN( CHAN_VOICE, pAlertSounds );
}
2016-07-31 15:48:50 +02:00
void CController::IdleSound( void )
2016-06-04 15:24:23 +02:00
{
EMIT_SOUND_ARRAY_DYN( CHAN_VOICE, pIdleSounds );
}
2016-07-31 15:48:50 +02:00
void CController::AttackSound( void )
2016-06-04 15:24:23 +02:00
{
EMIT_SOUND_ARRAY_DYN( CHAN_VOICE, pAttackSounds );
}
2016-07-31 15:48:50 +02:00
void CController::DeathSound( void )
2016-06-04 15:24:23 +02:00
{
EMIT_SOUND_ARRAY_DYN( CHAN_VOICE, pDeathSounds );
}
//=========================================================
// HandleAnimEvent - catches the monster-specific messages
// that occur when tagged animation frames are played.
//=========================================================
2016-07-31 15:48:50 +02:00
void CController::HandleAnimEvent( MonsterEvent_t *pEvent )
2016-06-04 15:24:23 +02:00
{
switch( pEvent->event )
{
case CONTROLLER_AE_HEAD_OPEN:
{
Vector vecStart, angleGun;
2016-07-31 15:48:50 +02:00
2016-06-04 15:24:23 +02:00
GetAttachment( 0, vecStart, angleGun );
2016-07-31 15:48:50 +02:00
2016-06-04 15:24:23 +02:00
MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY );
WRITE_BYTE( TE_ELIGHT );
2016-07-31 15:48:50 +02:00
WRITE_SHORT( entindex() + 0x1000 ); // entity, attachment
2016-06-04 15:24:23 +02:00
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 );
2016-07-31 15:48:50 +02:00
WRITE_SHORT( entindex() + 0x1000 ); // entity, attachment
2016-06-04 15:24:23 +02:00
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:
{
2016-07-31 15:48:50 +02:00
AttackSound();
2016-06-04 15:24:23 +02:00
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
//=========================================================
2016-07-31 15:48:50 +02:00
void CController::Spawn()
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
Precache();
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
SET_MODEL( ENT( pev ), "models/controller.mdl" );
UTIL_SetSize( pev, Vector( -32, -32, 0 ), Vector( 32, 32, 64 ) );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
pev->solid = SOLID_SLIDEBOX;
2016-06-04 15:24:23 +02:00
pev->movetype = MOVETYPE_FLY;
2016-07-31 15:48:50 +02:00
pev->flags |= FL_FLY;
2016-06-04 15:24:23 +02:00
m_bloodColor = BLOOD_COLOR_GREEN;
2016-07-31 15:48:50 +02:00
pev->health = gSkillData.controllerHealth;
2016-06-04 15:24:23 +02:00
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
//=========================================================
2016-07-31 15:48:50 +02:00
void CController::Precache()
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
PRECACHE_MODEL( "models/controller.mdl" );
2016-06-04 15:24:23 +02:00
PRECACHE_SOUND_ARRAY( pAttackSounds );
PRECACHE_SOUND_ARRAY( pIdleSounds );
PRECACHE_SOUND_ARRAY( pAlertSounds );
PRECACHE_SOUND_ARRAY( pPainSounds );
PRECACHE_SOUND_ARRAY( pDeathSounds );
2016-07-31 15:48:50 +02:00
PRECACHE_MODEL( "sprites/xspark4.spr" );
2016-06-04 15:24:23 +02:00
UTIL_PrecacheOther( "controller_energy_ball" );
UTIL_PrecacheOther( "controller_head_ball" );
}
//=========================================================
// AI Schedules Specific to this monster
//=========================================================
// Chase enemy schedule
2016-07-31 15:48:50 +02:00
Task_t tlControllerChaseEnemy[] =
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
{ TASK_GET_PATH_TO_ENEMY, (float)128 },
{ TASK_WAIT_FOR_MOVEMENT, (float)0 },
2016-06-04 15:24:23 +02:00
};
Schedule_t slControllerChaseEnemy[] =
{
2016-07-31 15:48:50 +02:00
{
2016-06-04 15:24:23 +02:00
tlControllerChaseEnemy,
2016-07-31 15:48:50 +02:00
ARRAYSIZE( tlControllerChaseEnemy ),
bits_COND_NEW_ENEMY |
2016-06-04 15:24:23 +02:00
bits_COND_TASK_FAILED,
0,
"ControllerChaseEnemy"
},
};
2016-07-31 15:48:50 +02:00
Task_t tlControllerStrafe[] =
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
{ TASK_WAIT, (float)0.2 },
{ TASK_GET_PATH_TO_ENEMY, (float)128 },
{ TASK_WAIT_FOR_MOVEMENT, (float)0 },
{ TASK_WAIT, (float)1 },
2016-06-04 15:24:23 +02:00
};
2016-07-31 15:48:50 +02:00
Schedule_t slControllerStrafe[] =
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
{
2016-06-04 15:24:23 +02:00
tlControllerStrafe,
2016-07-31 15:48:50 +02:00
ARRAYSIZE( tlControllerStrafe ),
2016-06-04 15:24:23 +02:00
bits_COND_NEW_ENEMY,
0,
"ControllerStrafe"
},
};
2016-07-31 15:48:50 +02:00
Task_t tlControllerTakeCover[] =
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
{ TASK_WAIT, (float)0.2 },
{ TASK_FIND_COVER_FROM_ENEMY, (float)0 },
{ TASK_WAIT_FOR_MOVEMENT, (float)0 },
{ TASK_WAIT, (float)1 },
2016-06-04 15:24:23 +02:00
};
2016-07-31 15:48:50 +02:00
Schedule_t slControllerTakeCover[] =
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
{
2016-06-04 15:24:23 +02:00
tlControllerTakeCover,
2016-07-31 15:48:50 +02:00
ARRAYSIZE( tlControllerTakeCover ),
2016-06-04 15:24:23 +02:00
bits_COND_NEW_ENEMY,
0,
"ControllerTakeCover"
},
};
2016-07-31 15:48:50 +02:00
Task_t tlControllerFail[] =
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
{ TASK_STOP_MOVING, 0 },
{ TASK_SET_ACTIVITY, (float)ACT_IDLE },
{ TASK_WAIT, (float)2 },
{ TASK_WAIT_PVS, (float)0 },
2016-06-04 15:24:23 +02:00
};
2016-07-31 15:48:50 +02:00
Schedule_t slControllerFail[] =
2016-06-04 15:24:23 +02:00
{
{
tlControllerFail,
2016-07-31 15:48:50 +02:00
ARRAYSIZE( tlControllerFail ),
2016-06-04 15:24:23 +02:00
0,
0,
"ControllerFail"
},
};
DEFINE_CUSTOM_SCHEDULES( CController )
{
slControllerChaseEnemy,
slControllerStrafe,
slControllerTakeCover,
slControllerFail,
};
IMPLEMENT_CUSTOM_SCHEDULES( CController, CSquadMonster )
2016-06-04 15:24:23 +02:00
//=========================================================
// StartTask
//=========================================================
2016-07-31 15:48:50 +02:00
void CController::StartTask( Task_t *pTask )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
switch( pTask->iTask )
2016-06-04 15:24:23 +02:00
{
case TASK_RANGE_ATTACK1:
2016-07-31 15:48:50 +02:00
CSquadMonster::StartTask( pTask );
2016-06-04 15:24:23 +02:00
break;
case TASK_GET_PATH_TO_ENEMY_LKP:
{
2016-07-31 15:48:50 +02:00
if( BuildNearestRoute( m_vecEnemyLKP, pev->view_ofs, pTask->flData, (m_vecEnemyLKP - pev->origin).Length() + 1024 ) )
2016-06-04 15:24:23 +02:00
{
TaskComplete();
}
else
{
// no way to get there =(
2016-07-31 15:48:50 +02:00
ALERT( at_aiconsole, "GetPathToEnemyLKP failed!!\n" );
2016-06-04 15:24:23 +02:00
TaskFail();
}
break;
}
case TASK_GET_PATH_TO_ENEMY:
{
CBaseEntity *pEnemy = m_hEnemy;
2016-07-31 15:48:50 +02:00
if( pEnemy == NULL )
2016-06-04 15:24:23 +02:00
{
TaskFail();
return;
}
2016-07-31 15:48:50 +02:00
if( BuildNearestRoute( pEnemy->pev->origin, pEnemy->pev->view_ofs, pTask->flData, ( pEnemy->pev->origin - pev->origin).Length() + 1024 ) )
2016-06-04 15:24:23 +02:00
{
TaskComplete();
}
else
{
// no way to get there =(
2016-07-31 15:48:50 +02:00
ALERT( at_aiconsole, "GetPathToEnemy failed!!\n" );
2016-06-04 15:24:23 +02:00
TaskFail();
}
break;
}
default:
2016-07-31 15:48:50 +02:00
CSquadMonster::StartTask( pTask );
2016-06-04 15:24:23 +02:00
break;
}
}
Vector Intersect( Vector vecSrc, Vector vecDst, Vector vecMove, float flSpeed )
{
Vector vecTo = vecDst - vecSrc;
float a = DotProduct( vecMove, vecMove ) - flSpeed * flSpeed;
2016-07-31 15:48:50 +02:00
float b = 0 * DotProduct( vecTo, vecMove ); // why does this work?
2016-06-04 15:24:23 +02:00
float c = DotProduct( vecTo, vecTo );
float t;
2016-07-31 15:48:50 +02:00
if( a == 0 )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
t = c / ( flSpeed * flSpeed );
2016-06-04 15:24:23 +02:00
}
else
{
t = b * b - 4 * a * c;
2016-07-31 15:48:50 +02:00
t = sqrt( t ) / ( 2.0 * a );
2016-06-04 15:24:23 +02:00
float t1 = -b +t;
float t2 = -b -t;
2016-07-31 15:48:50 +02:00
if( t1 < 0 || t2 < t1 )
2016-06-04 15:24:23 +02:00
t = t2;
else
t = t1;
}
// ALERT( at_console, "Intersect %f\n", t );
2016-07-31 15:48:50 +02:00
if( t < 0.1 )
2016-06-04 15:24:23 +02:00
t = 0.1;
2016-07-31 15:48:50 +02:00
if( t > 10.0 )
2016-06-04 15:24:23 +02:00
t = 10.0;
Vector vecHit = vecTo + vecMove * t;
2016-07-31 15:48:50 +02:00
return vecHit.Normalize() * flSpeed;
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
int CController::LookupFloat()
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( m_velocity.Length() < 32.0 )
2016-06-04 15:24:23 +02:00
{
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 );
2016-07-31 15:48:50 +02:00
if( fabs( x ) > fabs( y ) && fabs( x ) > fabs( z ) )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( x > 0 )
return LookupSequence( "forward" );
2016-06-04 15:24:23 +02:00
else
2016-07-31 15:48:50 +02:00
return LookupSequence( "backward" );
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
else if( fabs( y ) > fabs( z ) )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( y > 0 )
return LookupSequence( "right" );
2016-06-04 15:24:23 +02:00
else
2016-07-31 15:48:50 +02:00
return LookupSequence( "left" );
2016-06-04 15:24:23 +02:00
}
else
{
2016-07-31 15:48:50 +02:00
if( z > 0 )
return LookupSequence( "up" );
2016-06-04 15:24:23 +02:00
else
2016-07-31 15:48:50 +02:00
return LookupSequence( "down" );
2016-06-04 15:24:23 +02:00
}
}
//=========================================================
// RunTask
//=========================================================
2016-07-31 15:48:50 +02:00
void CController::RunTask( Task_t *pTask )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( m_flShootEnd > gpGlobals->time )
2016-06-04 15:24:23 +02:00
{
Vector vecHand, vecAngle;
2016-07-31 15:48:50 +02:00
2016-06-04 15:24:23 +02:00
GetAttachment( 2, vecHand, vecAngle );
2016-07-31 15:48:50 +02:00
while( m_flShootTime < m_flShootEnd && m_flShootTime < gpGlobals->time )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
Vector vecSrc = vecHand + pev->velocity * ( m_flShootTime - gpGlobals->time );
2016-06-04 15:24:23 +02:00
Vector vecDir;
2016-07-31 15:48:50 +02:00
if( m_hEnemy != NULL )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( HasConditions( bits_COND_SEE_ENEMY ) )
2016-06-04 15:24:23 +02:00
{
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;
2016-07-31 15:48:50 +02:00
vecSrc = vecSrc + vecDir * ( gpGlobals->time - m_flShootTime );
2016-06-04 15:24:23 +02:00
CBaseMonster *pBall = (CBaseMonster*)Create( "controller_energy_ball", vecSrc, pev->angles, edict() );
pBall->pev->velocity = vecDir;
}
m_flShootTime += 0.2;
}
2016-07-31 15:48:50 +02:00
if( m_flShootTime > m_flShootEnd )
2016-06-04 15:24:23 +02:00
{
m_iBall[0] = 64;
m_iBallTime[0] = m_flShootEnd;
m_iBall[1] = 64;
m_iBallTime[1] = m_flShootEnd;
m_fInCombat = FALSE;
}
}
2016-07-31 15:48:50 +02:00
switch( pTask->iTask )
2016-06-04 15:24:23 +02:00
{
case TASK_WAIT_FOR_MOVEMENT:
case TASK_WAIT:
case TASK_WAIT_FACE_ENEMY:
case TASK_WAIT_PVS:
MakeIdealYaw( m_vecEnemyLKP );
ChangeYaw( pev->yaw_speed );
2016-07-31 15:48:50 +02:00
if( m_fSequenceFinished )
2016-06-04 15:24:23 +02:00
{
m_fInCombat = FALSE;
}
2016-07-31 15:48:50 +02:00
CSquadMonster::RunTask( pTask );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
if( !m_fInCombat )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( HasConditions( bits_COND_CAN_RANGE_ATTACK1 ) )
2016-06-04 15:24:23 +02:00
{
pev->sequence = LookupActivity( ACT_RANGE_ATTACK1 );
pev->frame = 0;
2016-07-31 15:48:50 +02:00
ResetSequenceInfo();
2016-06-04 15:24:23 +02:00
m_fInCombat = TRUE;
}
2016-07-31 15:48:50 +02:00
else if( HasConditions( bits_COND_CAN_RANGE_ATTACK2 ) )
2016-06-04 15:24:23 +02:00
{
pev->sequence = LookupActivity( ACT_RANGE_ATTACK2 );
pev->frame = 0;
2016-07-31 15:48:50 +02:00
ResetSequenceInfo();
2016-06-04 15:24:23 +02:00
m_fInCombat = TRUE;
}
else
{
2016-07-31 15:48:50 +02:00
int iFloat = LookupFloat();
if( m_fSequenceFinished || iFloat != pev->sequence )
2016-06-04 15:24:23 +02:00
{
pev->sequence = iFloat;
pev->frame = 0;
2016-07-31 15:48:50 +02:00
ResetSequenceInfo();
2016-06-04 15:24:23 +02:00
}
}
}
break;
default:
2016-07-31 15:48:50 +02:00
CSquadMonster::RunTask( pTask );
2016-06-04 15:24:23 +02:00
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.
//=========================================================
2016-07-31 15:48:50 +02:00
Schedule_t *CController::GetSchedule( void )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
switch( m_MonsterState )
2016-06-04 15:24:23 +02:00
{
case MONSTERSTATE_COMBAT:
{
Vector vecTmp = Intersect( Vector( 0, 0, 0 ), Vector( 100, 4, 7 ), Vector( 2, 10, -3 ), 20.0 );
// dead enemy
2016-07-31 15:48:50 +02:00
if( HasConditions( bits_COND_LIGHT_DAMAGE ) )
2016-06-04 15:24:23 +02:00
{
// m_iFrustration++;
}
2016-07-31 15:48:50 +02:00
if( HasConditions( bits_COND_HEAVY_DAMAGE ) )
2016-06-04 15:24:23 +02:00
{
// m_iFrustration++;
}
}
break;
2016-06-13 16:29:45 +02:00
case MONSTERSTATE_IDLE:
case MONSTERSTATE_ALERT:
break;
default:
break;
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
return CSquadMonster::GetSchedule();
2016-06-04 15:24:23 +02:00
}
//=========================================================
//=========================================================
2016-07-31 15:48:50 +02:00
Schedule_t *CController::GetScheduleOfType( int Type )
2016-06-04 15:24:23 +02:00
{
// ALERT( at_console, "%d\n", m_iFrustration );
2016-07-31 15:48:50 +02:00
switch( Type )
2016-06-04 15:24:23 +02:00
{
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;
}
2016-07-31 15:48:50 +02:00
return CBaseMonster::GetScheduleOfType( Type );
2016-06-04 15:24:23 +02:00
}
//=========================================================
// CheckRangeAttack1 - shoot a bigass energy ball out of their head
//
//=========================================================
2016-07-31 15:48:50 +02:00
BOOL CController::CheckRangeAttack1( float flDot, float flDist )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( flDot > 0.5 && flDist > 256 && flDist <= 2048 )
2016-06-04 15:24:23 +02:00
{
return TRUE;
}
return FALSE;
}
2016-07-31 15:48:50 +02:00
BOOL CController::CheckRangeAttack2( float flDot, float flDist )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( flDot > 0.5 && flDist > 64 && flDist <= 2048 )
2016-06-04 15:24:23 +02:00
{
return TRUE;
}
return FALSE;
}
2016-07-31 15:48:50 +02:00
BOOL CController::CheckMeleeAttack1( float flDot, float flDist )
2016-06-04 15:24:23 +02:00
{
return FALSE;
}
2016-07-31 15:48:50 +02:00
void CController::SetActivity( Activity NewActivity )
2016-06-04 15:24:23 +02:00
{
CBaseMonster::SetActivity( NewActivity );
2016-07-31 15:48:50 +02:00
switch( m_Activity )
2016-06-04 15:24:23 +02:00
{
case ACT_WALK:
m_flGroundSpeed = 100;
break;
default:
m_flGroundSpeed = 100;
break;
}
}
//=========================================================
// RunAI
//=========================================================
2016-07-31 15:48:50 +02:00
void CController::RunAI( void )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
CBaseMonster::RunAI();
2016-06-04 15:24:23 +02:00
Vector vecStart, angleGun;
2016-07-31 15:48:50 +02:00
if( HasMemory( bits_MEMORY_KILLED ) )
2016-06-04 15:24:23 +02:00
return;
2016-07-31 15:48:50 +02:00
for( int i = 0; i < 2; i++ )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( m_pBall[i] == NULL )
2016-06-04 15:24:23 +02:00
{
m_pBall[i] = CSprite::SpriteCreate( "sprites/xspark4.spr", pev->origin, TRUE );
m_pBall[i]->SetTransparency( kRenderGlow, 255, 255, 255, 255, kRenderFxNoDissipation );
2016-07-31 15:48:50 +02:00
m_pBall[i]->SetAttachment( edict(), ( i + 3 ) );
2016-06-04 15:24:23 +02:00
m_pBall[i]->SetScale( 1.0 );
}
float t = m_iBallTime[i] - gpGlobals->time;
2016-07-31 15:48:50 +02:00
if( t > 0.1 )
2016-06-04 15:24:23 +02:00
t = 0.1 / t;
else
t = 1.0;
2016-07-31 15:48:50 +02:00
m_iBallCurrent[i] += ( m_iBall[i] - m_iBallCurrent[i] ) * t;
2016-06-04 15:24:23 +02:00
m_pBall[i]->SetBrightness( m_iBallCurrent[i] );
GetAttachment( i + 2, vecStart, angleGun );
UTIL_SetOrigin( m_pBall[i]->pev, vecStart );
2016-07-31 15:48:50 +02:00
2016-06-04 15:24:23 +02:00
MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY );
WRITE_BYTE( TE_ELIGHT );
2016-07-31 15:48:50 +02:00
WRITE_SHORT( entindex() + 0x1000 * ( i + 3 ) ); // entity, attachment
2016-06-04 15:24:23 +02:00
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 );
2016-07-31 15:48:50 +02:00
void CController::Stop( void )
2016-06-04 15:24:23 +02:00
{
m_IdealActivity = GetStoppedActivity();
}
#define DIST_TO_CHECK 200
2016-07-31 15:48:50 +02:00
void CController::Move( float flInterval )
2016-06-04 15:24:23 +02:00
{
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
2016-07-31 15:48:50 +02:00
if( FRouteClear() )
2016-06-04 15:24:23 +02:00
{
ALERT( at_aiconsole, "Tried to move with no route!\n" );
TaskFail();
return;
}
2016-07-31 15:48:50 +02:00
if( m_flMoveWaitFinished > gpGlobals->time )
2016-06-04 15:24:23 +02:00
return;
// Debug, test movement code
#if 0
2016-07-31 15:48:50 +02:00
// if( CVAR_GET_FLOAT( "stopmove" ) != 0 )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( m_movementGoal == MOVEGOAL_ENEMY )
2016-06-04 15:24:23 +02:00
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;
2016-07-31 15:48:50 +02:00
if( m_flGroundSpeed == 0 )
2016-06-04 15:24:23 +02:00
{
m_flGroundSpeed = 100;
2016-07-31 15:48:50 +02:00
// TaskFail();
2016-06-04 15:24:23 +02:00
// return;
}
flMoveDist = m_flGroundSpeed * flInterval;
2016-07-31 15:48:50 +02:00
do
2016-06-04 15:24:23 +02:00
{
// local move to waypoint.
2016-07-31 15:48:50 +02:00
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 );
2016-06-04 15:24:23 +02:00
// if the waypoint is closer than CheckDist, CheckDist is the dist to waypoint
2016-07-31 15:48:50 +02:00
if( flWaypointDist < DIST_TO_CHECK )
2016-06-04 15:24:23 +02:00
{
flCheckDist = flWaypointDist;
}
else
{
flCheckDist = DIST_TO_CHECK;
}
2016-07-31 15:48:50 +02:00
if( ( m_Route[m_iRouteIndex].iType & ( ~bits_MF_NOT_TO_MASK ) ) == bits_MF_TO_ENEMY )
2016-06-04 15:24:23 +02:00
{
// only on a PURE move to enemy ( i.e., ONLY MF_TO_ENEMY set, not MF_TO_ENEMY and DETOUR )
pTargetEnt = m_hEnemy;
}
2016-07-31 15:48:50 +02:00
else if( ( m_Route[m_iRouteIndex].iType & ~bits_MF_NOT_TO_MASK ) == bits_MF_TO_TARGETENT )
2016-06-04 15:24:23 +02:00
{
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;
2016-07-31 15:48:50 +02:00
if( CheckLocalMove( pev->origin, pev->origin + vecDir * flCheckDist, pTargetEnt, &flDist ) != LOCALMOVE_VALID )
2016-06-04 15:24:23 +02:00
{
CBaseEntity *pBlocker;
// Can't move, stop
Stop();
// Blocking entity is in global trace_ent
pBlocker = CBaseEntity::Instance( gpGlobals->trace_ent );
2016-07-31 15:48:50 +02:00
if( pBlocker )
2016-06-04 15:24:23 +02:00
{
DispatchBlocked( edict(), pBlocker->edict() );
}
2016-07-31 15:48:50 +02:00
if( pBlocker && m_moveWaitTime > 0 && pBlocker->IsMoving() && !pBlocker->IsPlayer() && (gpGlobals->time-m_flMoveWaitFinished) > 3.0 )
2016-06-04 15:24:23 +02:00
{
// Can we still move toward our target?
2016-07-31 15:48:50 +02:00
if( flDist < m_flGroundSpeed )
2016-06-04 15:24:23 +02:00
{
// Wait for a second
m_flMoveWaitFinished = gpGlobals->time + m_moveWaitTime;
//ALERT( at_aiconsole, "Move %s!!!\n", STRING( pBlocker->pev->classname ) );
2016-06-04 15:24:23 +02:00
return;
}
}
2016-07-31 15:48:50 +02:00
else
2016-06-04 15:24:23 +02:00
{
// try to triangulate around whatever is in the way.
2016-07-31 15:48:50 +02:00
if( FTriangulate( pev->origin, m_Route[m_iRouteIndex].vecLocation, flDist, pTargetEnt, &vecApex ) )
2016-06-04 15:24:23 +02:00
{
InsertWaypoint( vecApex, bits_MF_TO_DETOUR );
RouteSimplify( pTargetEnt );
}
else
{
ALERT ( at_aiconsole, "Couldn't Triangulate\n" );
2016-06-04 15:24:23 +02:00
Stop();
2016-07-31 15:48:50 +02:00
if( m_moveWaitTime > 0 )
2016-06-04 15:24:23 +02:00
{
FRefreshRoute();
m_flMoveWaitFinished = gpGlobals->time + m_moveWaitTime * 0.5;
}
else
{
TaskFail();
ALERT( at_aiconsole, "Failed to move!\n" );
2016-07-31 15:48:50 +02:00
//ALERT( at_aiconsole, "%f, %f, %f\n", pev->origin.z, ( pev->origin + ( vecDir * flCheckDist ) ).z, m_Route[m_iRouteIndex].vecLocation.z );
2016-06-04 15:24:23 +02:00
}
return;
}
}
}
// UNDONE: this is a hack to quit moving farther than it has looked ahead.
2016-07-31 15:48:50 +02:00
if( flCheckDist < flMoveDist )
2016-06-04 15:24:23 +02:00
{
MoveExecute( pTargetEnt, vecDir, flCheckDist / m_flGroundSpeed );
// ALERT( at_console, "%.02f\n", flInterval );
AdvanceRoute( flWaypointDist );
flMoveDist -= flCheckDist;
}
else
{
MoveExecute( pTargetEnt, vecDir, flMoveDist / m_flGroundSpeed );
2016-07-31 15:48:50 +02:00
if( ShouldAdvanceRoute( flWaypointDist - flMoveDist ) )
2016-06-04 15:24:23 +02:00
{
AdvanceRoute( flWaypointDist );
}
flMoveDist = 0;
}
2016-07-31 15:48:50 +02:00
if( MovementIsComplete() )
2016-06-04 15:24:23 +02:00
{
Stop();
RouteClear();
}
2016-07-31 15:48:50 +02:00
} while( flMoveDist > 0 && flCheckDist > 0 );
2016-06-04 15:24:23 +02:00
// cut corner?
2016-07-31 15:48:50 +02:00
if( flWaypointDist < 128 )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( m_movementGoal == MOVEGOAL_ENEMY )
2016-06-04 15:24:23 +02:00
RouteSimplify( m_hEnemy );
else
RouteSimplify( m_hTargetEnt );
FRefreshRoute();
2016-07-31 15:48:50 +02:00
if( m_flGroundSpeed > 100 )
2016-06-04 15:24:23 +02:00
m_flGroundSpeed -= 40;
}
else
{
2016-07-31 15:48:50 +02:00
if( m_flGroundSpeed < 400 )
2016-06-04 15:24:23 +02:00
m_flGroundSpeed += 10;
}
}
2016-07-31 15:48:50 +02:00
BOOL CController::ShouldAdvanceRoute( float flWaypointDist )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( flWaypointDist <= 32 )
2016-06-04 15:24:23 +02:00
{
return TRUE;
}
return FALSE;
}
2016-07-31 15:48:50 +02:00
int CController::CheckLocalMove( const Vector &vecStart, const Vector &vecEnd, CBaseEntity *pTarget, float *pflDist )
2016-06-04 15:24:23 +02:00
{
TraceResult tr;
2016-07-31 15:48:50 +02:00
UTIL_TraceHull( vecStart + Vector( 0, 0, 32 ), vecEnd + Vector( 0, 0, 32 ), dont_ignore_monsters, large_hull, edict(), &tr );
2016-06-04 15:24:23 +02:00
// 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 );
2016-07-31 15:48:50 +02:00
if( pflDist )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
*pflDist = ( ( tr.vecEndPos - Vector( 0, 0, 32 ) ) - vecStart ).Length();// get the distance.
2016-06-04 15:24:23 +02:00
}
// ALERT( at_console, "check %d %d %f\n", tr.fStartSolid, tr.fAllSolid, tr.flFraction );
2016-07-31 15:48:50 +02:00
if( tr.fStartSolid || tr.flFraction < 1.0 )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
if( pTarget && pTarget->edict() == gpGlobals->trace_ent )
2016-06-04 15:24:23 +02:00
return LOCALMOVE_VALID;
return LOCALMOVE_INVALID;
}
return LOCALMOVE_VALID;
}
void CController::MoveExecute( CBaseEntity *pTargetEnt, const Vector &vecDir, float flInterval )
{
2016-07-31 15:48:50 +02:00
if( m_IdealActivity != m_movementActivity )
2016-06-04 15:24:23 +02:00
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;
2016-07-31 15:48:50 +02:00
// UTIL_MoveToOrigin ( ENT( pev ), m_Route[m_iRouteIndex].vecLocation, flTotal, MOVE_STRAFE );
2016-06-04 15:24:23 +02:00
m_velocity = m_velocity * 0.8 + m_flGroundSpeed * vecDir * 0.2;
2016-07-31 15:48:50 +02:00
UTIL_MoveToOrigin( ENT( pev ), pev->origin + m_velocity, m_velocity.Length() * flInterval, MOVE_STRAFE );
2016-06-04 15:24:23 +02:00
}
//=========================================================
// 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 )
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
void CControllerHeadBall::Spawn( void )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
Precache();
2016-06-04 15:24:23 +02:00
// motor
pev->movetype = MOVETYPE_FLY;
pev->solid = SOLID_BBOX;
2016-07-31 15:48:50 +02:00
SET_MODEL(ENT( pev ), "sprites/xspark4.spr" );
2016-06-04 15:24:23 +02:00
pev->rendermode = kRenderTransAdd;
pev->rendercolor.x = 255;
pev->rendercolor.y = 255;
pev->rendercolor.z = 255;
pev->renderamt = 255;
pev->scale = 2.0;
2016-07-31 15:48:50 +02:00
UTIL_SetSize(pev, Vector( 0, 0, 0 ), Vector( 0, 0, 0 ) );
2016-06-04 15:24:23 +02:00
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;
}
2016-07-31 15:48:50 +02:00
void CControllerHeadBall::Precache( void )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
PRECACHE_MODEL( "sprites/xspark1.spr" );
PRECACHE_SOUND( "debris/zap4.wav" );
PRECACHE_SOUND( "weapons/electro4.wav" );
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
void CControllerHeadBall::HuntThink( void )
2016-06-04 15:24:23 +02:00
{
pev->nextthink = gpGlobals->time + 0.1;
pev->renderamt -= 5;
MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY );
WRITE_BYTE( TE_ELIGHT );
2016-07-31 15:48:50 +02:00
WRITE_SHORT( entindex() ); // entity, attachment
2016-06-04 15:24:23 +02:00
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
2016-07-31 15:48:50 +02:00
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 )
2016-06-04 15:24:23 +02:00
{
SetTouch( NULL );
UTIL_Remove( this );
return;
}
2016-07-31 15:48:50 +02:00
MovetoTarget( m_hEnemy->Center() );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
if( ( m_hEnemy->Center() - pev->origin ).Length() < 64 )
2016-06-04 15:24:23 +02:00
{
TraceResult tr;
2016-07-31 15:48:50 +02:00
UTIL_TraceLine( pev->origin, m_hEnemy->Center(), dont_ignore_monsters, ENT( pev ), &tr );
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
CBaseEntity *pEntity = CBaseEntity::Instance( tr.pHit );
if( pEntity != NULL && pEntity->pev->takedamage )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
ClearMultiDamage();
2016-06-04 15:24:23 +02:00
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();
2016-07-31 15:48:50 +02:00
UTIL_EmitAmbientSound( ENT( pev ), tr.vecEndPos, "weapons/electro4.wav", 0.5, ATTN_NORM, 0, RANDOM_LONG( 140, 160 ) );
2016-06-04 15:24:23 +02:00
m_flNextAttack = gpGlobals->time + 3.0;
SetThink( &CControllerHeadBall::DieThink );
pev->nextthink = gpGlobals->time + 0.3;
}
2016-07-31 15:48:50 +02:00
//Crawl();
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
void CControllerHeadBall::DieThink( void )
2016-06-04 15:24:23 +02:00
{
UTIL_Remove( this );
}
2016-07-31 15:48:50 +02:00
void CControllerHeadBall::MovetoTarget( Vector vecTarget )
2016-06-04 15:24:23 +02:00
{
// accelerate
float flSpeed = m_vecIdeal.Length();
2016-07-31 15:48:50 +02:00
if( flSpeed == 0 )
2016-06-04 15:24:23 +02:00
{
m_vecIdeal = pev->velocity;
flSpeed = m_vecIdeal.Length();
}
2016-07-31 15:48:50 +02:00
if( flSpeed > 400 )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
m_vecIdeal = m_vecIdeal.Normalize() * 400;
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
m_vecIdeal = m_vecIdeal + ( vecTarget - pev->origin ).Normalize() * 100;
2016-06-04 15:24:23 +02:00
pev->velocity = m_vecIdeal;
}
2016-07-31 15:48:50 +02:00
void CControllerHeadBall::Crawl( void )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
Vector vecAim = Vector( RANDOM_FLOAT( -1, 1 ), RANDOM_FLOAT( -1, 1 ), RANDOM_FLOAT( -1, 1 ) ).Normalize();
2016-06-04 15:24:23 +02:00
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 )
{
2016-07-31 15:48:50 +02:00
Vector vecDir = m_vecIdeal.Normalize();
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
TraceResult tr = UTIL_GetGlobalTrace();
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
float n = -DotProduct( tr.vecPlaneNormal, vecDir );
2016-06-04 15:24:23 +02:00
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 )
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
void CControllerZapBall::Spawn( void )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
Precache();
2016-06-04 15:24:23 +02:00
// motor
pev->movetype = MOVETYPE_FLY;
pev->solid = SOLID_BBOX;
2016-07-31 15:48:50 +02:00
SET_MODEL( ENT( pev ), "sprites/xspark4.spr" );
2016-06-04 15:24:23 +02:00
pev->rendermode = kRenderTransAdd;
pev->rendercolor.x = 255;
pev->rendercolor.y = 255;
pev->rendercolor.z = 255;
pev->renderamt = 255;
pev->scale = 0.5;
2016-07-31 15:48:50 +02:00
UTIL_SetSize( pev, Vector( 0, 0, 0 ), Vector( 0, 0, 0 ) );
2016-06-04 15:24:23 +02:00
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;
}
2016-07-31 15:48:50 +02:00
void CControllerZapBall::Precache( void )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
PRECACHE_MODEL( "sprites/xspark4.spr" );
// PRECACHE_SOUND( "debris/zap4.wav" );
// PRECACHE_SOUND( "weapons/electro4.wav" );
2016-06-04 15:24:23 +02:00
}
2016-07-31 15:48:50 +02:00
void CControllerZapBall::AnimateThink( void )
2016-06-04 15:24:23 +02:00
{
pev->nextthink = gpGlobals->time + 0.1;
2016-07-31 15:48:50 +02:00
pev->frame = ( (int)pev->frame + 1 ) % 11;
if( gpGlobals->time - pev->dmgtime > 5 || pev->velocity.Length() < 10 )
2016-06-04 15:24:23 +02:00
{
SetTouch( NULL );
UTIL_Remove( this );
}
}
void CControllerZapBall::ExplodeTouch( CBaseEntity *pOther )
{
2016-07-31 15:48:50 +02:00
if( pOther->pev->takedamage )
2016-06-04 15:24:23 +02:00
{
2016-07-31 15:48:50 +02:00
TraceResult tr = UTIL_GetGlobalTrace();
entvars_t *pevOwner;
2016-06-04 15:24:23 +02:00
2016-07-31 15:48:50 +02:00
if( m_hOwner != NULL )
2016-06-04 15:24:23 +02:00
{
pevOwner = m_hOwner->pev;
}
else
{
pevOwner = pev;
}
2016-07-31 15:48:50 +02:00
ClearMultiDamage();
2016-06-04 15:24:23 +02:00
pOther->TraceAttack(pevOwner, gSkillData.controllerDmgBall, pev->velocity.Normalize(), &tr, DMG_ENERGYBEAM );
ApplyMultiDamage( pevOwner, pevOwner );
2016-07-31 15:48:50 +02:00
UTIL_EmitAmbientSound( ENT( pev ), tr.vecEndPos, "weapons/electro4.wav", 0.3, ATTN_NORM, 0, RANDOM_LONG( 90, 99 ) );
2016-06-04 15:24:23 +02:00
}
UTIL_Remove( this );
}
#endif //!OEM && !HLDEMO