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.

1819 lines
46 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 )
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "monsters.h"
#include "weapons.h"
#include "nodes.h"
#include "effects.h"
#define N_SCALE 15
#define N_SPHERES 20
class CNihilanth : public CBaseMonster
{
public:
9 years ago
int Save( CSave &save );
int Restore( CRestore &restore );
static TYPEDESCRIPTION m_SaveData[];
9 years ago
void Spawn( void );
void Precache( void );
void UpdateOnRemove();
9 years ago
int Classify( void ) { return CLASS_ALIEN_MILITARY; };
int BloodColor( void ) { return BLOOD_COLOR_YELLOW; }
9 years ago
void Killed( entvars_t *pevAttacker, int iGib );
void GibMonster( void );
void SetObjectCollisionBox( void )
{
pev->absmin = pev->origin + Vector( -16 * N_SCALE, -16 * N_SCALE, -48 * N_SCALE );
pev->absmax = pev->origin + Vector( 16 * N_SCALE, 16 * N_SCALE, 28 * N_SCALE );
}
void HandleAnimEvent( MonsterEvent_t *pEvent );
void EXPORT StartupThink( void );
void EXPORT HuntThink( void );
void EXPORT CrashTouch( CBaseEntity *pOther );
void EXPORT DyingThink( void );
void EXPORT StartupUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
void EXPORT NullThink( void );
void EXPORT CommandUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
void FloatSequence( void );
void NextActivity( void );
void Flight( void );
BOOL AbsorbSphere( void );
BOOL EmitSphere( void );
void TargetSphere( USE_TYPE useType, float value );
CBaseEntity *RandomTargetname( const char *szName );
void ShootBalls( void );
void MakeFriend( Vector vecPos );
9 years ago
int TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType );
void TraceAttack( entvars_t *pevAttacker, float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType );
9 years ago
void PainSound( void );
void DeathSound( void );
static const char *pAttackSounds[]; // vocalization: play sometimes when he launches an attack
static const char *pBallSounds[]; // the sound of the lightening ball launch
static const char *pShootSounds[]; // grunting vocalization: play sometimes when he launches an attack
static const char *pRechargeSounds[]; // vocalization: play when he recharges
static const char *pLaughSounds[]; // vocalization: play sometimes when hit and still has lots of health
static const char *pPainSounds[]; // vocalization: play sometimes when hit and has much less health and no more chargers
static const char *pDeathSounds[]; // vocalization: play as he dies
9 years ago
// x_teleattack1.wav the looping sound of the teleport attack ball.
float m_flForce;
float m_flNextPainSound;
Vector m_velocity;
Vector m_avelocity;
Vector m_vecTarget;
Vector m_posTarget;
Vector m_vecDesired;
Vector m_posDesired;
float m_flMinZ;
float m_flMaxZ;
Vector m_vecGoal;
float m_flLastSeen;
float m_flPrevSeen;
int m_irritation;
int m_iLevel;
int m_iTeleport;
EHANDLE m_hRecharger;
EHANDLE m_hSphere[N_SPHERES];
9 years ago
int m_iActiveSpheres;
9 years ago
float m_flAdj;
CSprite *m_pBall;
char m_szRechargerTarget[64];
char m_szDrawUse[64];
char m_szTeleportUse[64];
char m_szTeleportTouch[64];
char m_szDeadUse[64];
char m_szDeadTouch[64];
float m_flShootEnd;
float m_flShootTime;
EHANDLE m_hFriend[3];
};
LINK_ENTITY_TO_CLASS( monster_nihilanth, CNihilanth )
9 years ago
TYPEDESCRIPTION CNihilanth::m_SaveData[] =
9 years ago
{
DEFINE_FIELD( CNihilanth, m_flForce, FIELD_FLOAT ),
DEFINE_FIELD( CNihilanth, m_flNextPainSound, FIELD_TIME ),
DEFINE_FIELD( CNihilanth, m_velocity, FIELD_VECTOR ),
DEFINE_FIELD( CNihilanth, m_avelocity, FIELD_VECTOR ),
DEFINE_FIELD( CNihilanth, m_vecTarget, FIELD_VECTOR ),
DEFINE_FIELD( CNihilanth, m_posTarget, FIELD_POSITION_VECTOR ),
DEFINE_FIELD( CNihilanth, m_vecDesired, FIELD_VECTOR ),
DEFINE_FIELD( CNihilanth, m_posDesired, FIELD_POSITION_VECTOR ),
DEFINE_FIELD( CNihilanth, m_flMinZ, FIELD_FLOAT ),
DEFINE_FIELD( CNihilanth, m_flMaxZ, FIELD_FLOAT ),
DEFINE_FIELD( CNihilanth, m_vecGoal, FIELD_VECTOR ),
DEFINE_FIELD( CNihilanth, m_flLastSeen, FIELD_TIME ),
DEFINE_FIELD( CNihilanth, m_flPrevSeen, FIELD_TIME ),
DEFINE_FIELD( CNihilanth, m_irritation, FIELD_INTEGER ),
DEFINE_FIELD( CNihilanth, m_iLevel, FIELD_INTEGER ),
DEFINE_FIELD( CNihilanth, m_iTeleport, FIELD_INTEGER ),
DEFINE_FIELD( CNihilanth, m_hRecharger, FIELD_EHANDLE ),
DEFINE_ARRAY( CNihilanth, m_hSphere, FIELD_EHANDLE, N_SPHERES ),
DEFINE_FIELD( CNihilanth, m_iActiveSpheres, FIELD_INTEGER ),
DEFINE_FIELD( CNihilanth, m_flAdj, FIELD_FLOAT ),
DEFINE_FIELD( CNihilanth, m_pBall, FIELD_CLASSPTR ),
DEFINE_ARRAY( CNihilanth, m_szRechargerTarget, FIELD_CHARACTER, 64 ),
DEFINE_ARRAY( CNihilanth, m_szDrawUse, FIELD_CHARACTER, 64 ),
DEFINE_ARRAY( CNihilanth, m_szTeleportUse, FIELD_CHARACTER, 64 ),
DEFINE_ARRAY( CNihilanth, m_szTeleportTouch, FIELD_CHARACTER, 64 ),
DEFINE_ARRAY( CNihilanth, m_szDeadUse, FIELD_CHARACTER, 64 ),
DEFINE_ARRAY( CNihilanth, m_szDeadTouch, FIELD_CHARACTER, 64 ),
DEFINE_FIELD( CNihilanth, m_flShootEnd, FIELD_TIME ),
DEFINE_FIELD( CNihilanth, m_flShootTime, FIELD_TIME ),
DEFINE_ARRAY( CNihilanth, m_hFriend, FIELD_EHANDLE, 3 ),
};
IMPLEMENT_SAVERESTORE( CNihilanth, CBaseMonster )
9 years ago
class CNihilanthHVR : public CBaseMonster
{
public:
9 years ago
int Save( CSave &save );
int Restore( CRestore &restore );
static TYPEDESCRIPTION m_SaveData[];
9 years ago
void Spawn( void );
void Precache( void );
void CircleInit( CBaseEntity *pTarget );
void AbsorbInit( void );
void TeleportInit( CNihilanth *pOwner, CBaseEntity *pEnemy, CBaseEntity *pTarget, CBaseEntity *pTouch );
void GreenBallInit( void );
void ZapInit( CBaseEntity *pEnemy );
void EXPORT HoverThink( void );
BOOL CircleTarget( Vector vecTarget );
void EXPORT DissipateThink( void );
void EXPORT ZapThink( void );
void EXPORT TeleportThink( void );
void EXPORT TeleportTouch( CBaseEntity *pOther );
9 years ago
9 years ago
void EXPORT RemoveTouch( CBaseEntity *pOther );
void EXPORT BounceTouch( CBaseEntity *pOther );
void EXPORT ZapTouch( CBaseEntity *pOther );
CBaseEntity *RandomClassname( const char *szName );
// void EXPORT SphereUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value );
void MovetoTarget( Vector vecTarget );
virtual void Crawl( void );
void Zap( void );
void Teleport( void );
float m_flIdealVel;
Vector m_vecIdeal;
CNihilanth *m_pNihilanth;
EHANDLE m_hTouch;
int m_nFrames;
};
LINK_ENTITY_TO_CLASS( nihilanth_energy_ball, CNihilanthHVR )
9 years ago
TYPEDESCRIPTION CNihilanthHVR::m_SaveData[] =
9 years ago
{
DEFINE_FIELD( CNihilanthHVR, m_flIdealVel, FIELD_FLOAT ),
DEFINE_FIELD( CNihilanthHVR, m_vecIdeal, FIELD_VECTOR ),
DEFINE_FIELD( CNihilanthHVR, m_pNihilanth, FIELD_CLASSPTR ),
DEFINE_FIELD( CNihilanthHVR, m_hTouch, FIELD_EHANDLE ),
DEFINE_FIELD( CNihilanthHVR, m_nFrames, FIELD_INTEGER ),
};
IMPLEMENT_SAVERESTORE( CNihilanthHVR, CBaseMonster )
9 years ago
//=========================================================
// Nihilanth, final Boss monster
//=========================================================
9 years ago
const char *CNihilanth::pAttackSounds[] =
9 years ago
{
"X/x_attack1.wav",
"X/x_attack2.wav",
"X/x_attack3.wav",
};
9 years ago
const char *CNihilanth::pBallSounds[] =
9 years ago
{
"X/x_ballattack1.wav",
};
9 years ago
const char *CNihilanth::pShootSounds[] =
9 years ago
{
"X/x_shoot1.wav",
};
9 years ago
const char *CNihilanth::pRechargeSounds[] =
9 years ago
{
"X/x_recharge1.wav",
"X/x_recharge2.wav",
"X/x_recharge3.wav",
};
9 years ago
const char *CNihilanth::pLaughSounds[] =
9 years ago
{
"X/x_laugh1.wav",
"X/x_laugh2.wav",
};
9 years ago
const char *CNihilanth::pPainSounds[] =
9 years ago
{
"X/x_pain1.wav",
"X/x_pain2.wav",
};
9 years ago
const char *CNihilanth::pDeathSounds[] =
9 years ago
{
"X/x_die1.wav",
};
9 years ago
void CNihilanth::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( edict(), "models/nihilanth.mdl" );
9 years ago
// UTIL_SetSize(pev, Vector( -300, -300, 0), Vector(300, 300, 512));
9 years ago
UTIL_SetSize( pev, Vector( -32, -32, 0 ), Vector( 32, 32, 64 ) );
9 years ago
UTIL_SetOrigin( pev, pev->origin );
9 years ago
pev->flags |= FL_MONSTER;
9 years ago
pev->takedamage = DAMAGE_AIM;
9 years ago
pev->health = gSkillData.nihilanthHealth;
9 years ago
pev->view_ofs = Vector( 0, 0, 300 );
m_flFieldOfView = -1; // 360 degrees
pev->sequence = 0;
9 years ago
ResetSequenceInfo();
9 years ago
InitBoneControllers();
SetThink( &CNihilanth::StartupThink );
pev->nextthink = gpGlobals->time + 0.1;
m_vecDesired = Vector( 1, 0, 0 );
m_posDesired = Vector( pev->origin.x, pev->origin.y, 512 );
m_iLevel = 1;
m_iTeleport = 1;
9 years ago
if( m_szRechargerTarget[0] == '\0' )
strcpy( m_szRechargerTarget, "n_recharger" );
if( m_szDrawUse[0] == '\0' )
strcpy( m_szDrawUse, "n_draw" );
if( m_szTeleportUse[0] == '\0' )
strcpy( m_szTeleportUse, "n_leaving" );
if( m_szTeleportTouch[0] == '\0' )
strcpy( m_szTeleportTouch, "n_teleport" );
if( m_szDeadUse[0] == '\0' )
strcpy( m_szDeadUse, "n_dead" );
if( m_szDeadTouch[0] == '\0' )
strcpy( m_szDeadTouch, "n_ending" );
9 years ago
// near death
/*
m_iTeleport = 10;
m_iLevel = 10;
m_irritation = 2;
pev->health = 100;
*/
}
void CNihilanth::Precache( void )
{
9 years ago
PRECACHE_MODEL( "models/nihilanth.mdl" );
PRECACHE_MODEL( "sprites/lgtning.spr" );
9 years ago
UTIL_PrecacheOther( "nihilanth_energy_ball" );
UTIL_PrecacheOther( "monster_alien_controller" );
UTIL_PrecacheOther( "monster_alien_slave" );
PRECACHE_SOUND_ARRAY( pAttackSounds );
PRECACHE_SOUND_ARRAY( pBallSounds );
PRECACHE_SOUND_ARRAY( pShootSounds );
PRECACHE_SOUND_ARRAY( pRechargeSounds );
PRECACHE_SOUND_ARRAY( pLaughSounds );
PRECACHE_SOUND_ARRAY( pPainSounds );
PRECACHE_SOUND_ARRAY( pDeathSounds );
9 years ago
PRECACHE_SOUND( "debris/beamstart7.wav" );
9 years ago
}
void CNihilanth::UpdateOnRemove()
{
CBaseEntity::UpdateOnRemove();
if( m_pBall )
{
UTIL_Remove( m_pBall );
m_pBall = 0;
}
8 years ago
for( int i = 0; i < N_SPHERES; i++ )
{
if( CBaseEntity* pSphere = (CBaseEntity *)m_hSphere[i] )
{
UTIL_Remove( pSphere );
m_hSphere[i] = 0;
}
}
}
9 years ago
void CNihilanth::PainSound( void )
9 years ago
{
9 years ago
if( m_flNextPainSound > gpGlobals->time )
9 years ago
return;
9 years ago
9 years ago
m_flNextPainSound = gpGlobals->time + RANDOM_FLOAT( 2, 5 );
9 years ago
if( pev->health > gSkillData.nihilanthHealth / 2 )
9 years ago
{
EMIT_SOUND( edict(), CHAN_VOICE, RANDOM_SOUND_ARRAY( pLaughSounds ), 1.0, 0.2 );
}
9 years ago
else if( m_irritation >= 2 )
9 years ago
{
EMIT_SOUND( edict(), CHAN_VOICE, RANDOM_SOUND_ARRAY( pPainSounds ), 1.0, 0.2 );
}
9 years ago
}
9 years ago
9 years ago
void CNihilanth::DeathSound( void )
9 years ago
{
EMIT_SOUND( edict(), CHAN_VOICE, RANDOM_SOUND_ARRAY( pDeathSounds ), 1.0, 0.1 );
}
void CNihilanth::NullThink( void )
{
9 years ago
StudioFrameAdvance();
9 years ago
pev->nextthink = gpGlobals->time + 0.5;
}
void CNihilanth::StartupUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
{
SetThink( &CNihilanth::HuntThink );
pev->nextthink = gpGlobals->time + 0.1;
SetUse( &CNihilanth::CommandUse );
}
void CNihilanth::StartupThink( void )
{
m_irritation = 0;
m_flAdj = 512;
CBaseEntity *pEntity;
9 years ago
pEntity = UTIL_FindEntityByTargetname( NULL, "n_min" );
if( pEntity )
9 years ago
m_flMinZ = pEntity->pev->origin.z;
else
m_flMinZ = -4096;
9 years ago
pEntity = UTIL_FindEntityByTargetname( NULL, "n_max" );
if( pEntity )
9 years ago
m_flMaxZ = pEntity->pev->origin.z;
else
m_flMaxZ = 4096;
m_hRecharger = this;
9 years ago
for( int i = 0; i < N_SPHERES; i++ )
9 years ago
{
9 years ago
EmitSphere();
9 years ago
}
m_hRecharger = NULL;
9 years ago
SetThink( &CNihilanth::HuntThink );
9 years ago
SetUse( &CNihilanth::CommandUse );
pev->nextthink = gpGlobals->time + 0.1;
}
9 years ago
void CNihilanth::Killed( entvars_t *pevAttacker, int iGib )
9 years ago
{
CBaseMonster::Killed( pevAttacker, iGib );
}
9 years ago
void CNihilanth::DyingThink( void )
9 years ago
{
pev->nextthink = gpGlobals->time + 0.1;
9 years ago
DispatchAnimEvents();
StudioFrameAdvance();
9 years ago
9 years ago
if( pev->deadflag == DEAD_NO )
9 years ago
{
9 years ago
DeathSound();
9 years ago
pev->deadflag = DEAD_DYING;
m_posDesired.z = m_flMaxZ;
}
9 years ago
if( pev->deadflag == DEAD_DYING )
9 years ago
{
9 years ago
Flight();
9 years ago
9 years ago
if( fabs( pev->origin.z - m_flMaxZ ) < 16 )
9 years ago
{
pev->velocity = Vector( 0, 0, 0 );
FireTargets( m_szDeadUse, this, this, USE_ON, 1.0 );
pev->deadflag = DEAD_DEAD;
}
}
9 years ago
if( m_fSequenceFinished )
9 years ago
{
pev->avelocity.y += RANDOM_FLOAT( -100, 100 );
9 years ago
if( pev->avelocity.y < -100 )
9 years ago
pev->avelocity.y = -100;
9 years ago
if( pev->avelocity.y > 100 )
9 years ago
pev->avelocity.y = 100;
pev->sequence = LookupSequence( "die1" );
}
9 years ago
if( m_pBall )
9 years ago
{
9 years ago
if( m_pBall->pev->renderamt > 0 )
9 years ago
{
m_pBall->pev->renderamt = Q_max( 0, m_pBall->pev->renderamt - 2 );
9 years ago
}
else
{
UTIL_Remove( m_pBall );
m_pBall = NULL;
}
}
Vector vecDir, vecSrc, vecAngles;
UTIL_MakeAimVectors( pev->angles );
int iAttachment = RANDOM_LONG( 1, 4 );
do {
9 years ago
vecDir = Vector( RANDOM_FLOAT( -1, 1 ), RANDOM_FLOAT( -1, 1 ), RANDOM_FLOAT( -1, 1 ) );
} while( DotProduct( vecDir, vecDir ) > 1.0 );
9 years ago
9 years ago
switch( RANDOM_LONG( 1, 4 ) )
9 years ago
{
9 years ago
case 1:
// head
9 years ago
vecDir.z = fabs( vecDir.z ) * 0.5;
vecDir = vecDir + 2 * gpGlobals->v_up;
break;
9 years ago
case 2:
// eyes
if( DotProduct( vecDir, gpGlobals->v_forward ) < 0 )
9 years ago
vecDir = vecDir * -1;
vecDir = vecDir + 2 * gpGlobals->v_forward;
break;
9 years ago
case 3:
// left hand
if( DotProduct( vecDir, gpGlobals->v_right ) > 0 )
9 years ago
vecDir = vecDir * -1;
vecDir = vecDir - 2 * gpGlobals->v_right;
break;
9 years ago
case 4:
// right hand
if( DotProduct( vecDir, gpGlobals->v_right ) < 0 )
9 years ago
vecDir = vecDir * -1;
vecDir = vecDir + 2 * gpGlobals->v_right;
break;
}
GetAttachment( iAttachment - 1, vecSrc, vecAngles );
TraceResult tr;
9 years ago
UTIL_TraceLine( vecSrc, vecSrc + vecDir * 4096, ignore_monsters, ENT( pev ), &tr );
9 years ago
MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY );
WRITE_BYTE( TE_BEAMENTPOINT );
WRITE_SHORT( entindex() + 0x1000 * iAttachment );
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( 5 ); // life
WRITE_BYTE( 100 ); // width
WRITE_BYTE( 120 ); // noise
WRITE_BYTE( 64 ); // r, g, b
WRITE_BYTE( 128 ); // r, g, b
WRITE_BYTE( 255); // r, g, b
WRITE_BYTE( 255 ); // brightness
WRITE_BYTE( 10 ); // speed
MESSAGE_END();
GetAttachment( 0, vecSrc, vecAngles );
CNihilanthHVR *pEntity = (CNihilanthHVR *)Create( "nihilanth_energy_ball", vecSrc, pev->angles, edict() );
9 years ago
pEntity->pev->velocity = Vector( RANDOM_FLOAT( -0.7, 0.7 ), RANDOM_FLOAT( -0.7, 0.7 ), 1.0 ) * 600.0;
pEntity->GreenBallInit();
9 years ago
return;
}
void CNihilanth::CrashTouch( CBaseEntity *pOther )
{
// only crash if we hit something solid
9 years ago
if( pOther->pev->solid == SOLID_BSP )
9 years ago
{
SetTouch( NULL );
pev->nextthink = gpGlobals->time;
}
}
9 years ago
void CNihilanth::GibMonster( void )
9 years ago
{
9 years ago
// EMIT_SOUND_DYN( edict(), CHAN_VOICE, "common/bodysplat.wav", 0.75, ATTN_NORM, 0, 200 );
9 years ago
}
9 years ago
void CNihilanth::FloatSequence( void )
9 years ago
{
9 years ago
if( m_irritation >= 2 )
9 years ago
{
pev->sequence = LookupSequence( "float_open" );
}
9 years ago
else if( m_avelocity.y > 30 )
9 years ago
{
pev->sequence = LookupSequence( "walk_r" );
}
9 years ago
else if( m_avelocity.y < -30 )
9 years ago
{
pev->sequence = LookupSequence( "walk_l" );
}
9 years ago
else if( m_velocity.z > 30 )
9 years ago
{
pev->sequence = LookupSequence( "walk_u" );
}
9 years ago
else if( m_velocity.z < -30 )
9 years ago
{
pev->sequence = LookupSequence( "walk_d" );
}
else
{
pev->sequence = LookupSequence( "float" );
}
}
9 years ago
void CNihilanth::ShootBalls( void )
9 years ago
{
9 years ago
if( m_flShootEnd > gpGlobals->time )
9 years ago
{
Vector vecHand, vecAngle;
9 years ago
while( m_flShootTime < m_flShootEnd && m_flShootTime < gpGlobals->time )
9 years ago
{
if( m_hEnemy != 0 )
9 years ago
{
Vector vecSrc, vecDir;
CNihilanthHVR *pEntity;
GetAttachment( 2, vecHand, vecAngle );
9 years ago
vecSrc = vecHand + pev->velocity * ( m_flShootTime - gpGlobals->time );
// vecDir = ( m_posTarget - vecSrc ).Normalize();
vecDir = ( m_posTarget - pev->origin ).Normalize();
vecSrc = vecSrc + vecDir * ( gpGlobals->time - m_flShootTime );
9 years ago
pEntity = (CNihilanthHVR *)Create( "nihilanth_energy_ball", vecSrc, pev->angles, edict() );
pEntity->pev->velocity = vecDir * 200.0;
pEntity->ZapInit( m_hEnemy );
GetAttachment( 3, vecHand, vecAngle );
9 years ago
vecSrc = vecHand + pev->velocity * ( m_flShootTime - gpGlobals->time );
// vecDir = ( m_posTarget - vecSrc ).Normalize();
vecDir = ( m_posTarget - pev->origin ).Normalize();
vecSrc = vecSrc + vecDir * ( gpGlobals->time - m_flShootTime );
9 years ago
pEntity = (CNihilanthHVR *)Create( "nihilanth_energy_ball", vecSrc, pev->angles, edict() );
pEntity->pev->velocity = vecDir * 200.0;
pEntity->ZapInit( m_hEnemy );
}
m_flShootTime += 0.2;
}
}
}
9 years ago
void CNihilanth::MakeFriend( Vector vecStart )
9 years ago
{
int i;
9 years ago
9 years ago
for( i = 0; i < 3; i++ )
9 years ago
{
if( m_hFriend[i] != 0 && !m_hFriend[i]->IsAlive() )
9 years ago
{
9 years ago
if( pev->rendermode == kRenderNormal ) // don't do it if they are already fading
m_hFriend[i]->MyMonsterPointer()->FadeMonster();
9 years ago
m_hFriend[i] = NULL;
}
if( m_hFriend[i] == 0 )
9 years ago
{
9 years ago
if( RANDOM_LONG( 0, 1 ) == 0 )
9 years ago
{
9 years ago
int iNode = WorldGraph.FindNearestNode( vecStart, bits_NODE_AIR );
if( iNode != NO_NODE )
9 years ago
{
CNode &node = WorldGraph.Node( iNode );
TraceResult tr;
UTIL_TraceHull( node.m_vecOrigin + Vector( 0, 0, 32 ), node.m_vecOrigin + Vector( 0, 0, 32 ), dont_ignore_monsters, large_hull, NULL, &tr );
9 years ago
if( tr.fStartSolid == 0 )
m_hFriend[i] = Create( "monster_alien_controller", node.m_vecOrigin, pev->angles );
9 years ago
}
}
else
{
9 years ago
int iNode = WorldGraph.FindNearestNode( vecStart, bits_NODE_LAND | bits_NODE_WATER );
if( iNode != NO_NODE )
9 years ago
{
CNode &node = WorldGraph.Node( iNode );
TraceResult tr;
UTIL_TraceHull( node.m_vecOrigin + Vector( 0, 0, 36 ), node.m_vecOrigin + Vector( 0, 0, 36 ), dont_ignore_monsters, human_hull, NULL, &tr );
9 years ago
if( tr.fStartSolid == 0 )
m_hFriend[i] = Create( "monster_alien_slave", node.m_vecOrigin, pev->angles );
9 years ago
}
}
if( m_hFriend[i] != 0 )
9 years ago
{
EMIT_SOUND( m_hFriend[i]->edict(), CHAN_WEAPON, "debris/beamstart7.wav", 1.0, ATTN_NORM );
}
return;
}
}
}
9 years ago
void CNihilanth::NextActivity()
9 years ago
{
UTIL_MakeAimVectors( pev->angles );
9 years ago
if( m_irritation >= 2 )
9 years ago
{
9 years ago
if( m_pBall == NULL )
9 years ago
{
m_pBall = CSprite::SpriteCreate( "sprites/tele1.spr", pev->origin, TRUE );
9 years ago
if( m_pBall )
9 years ago
{
m_pBall->SetTransparency( kRenderTransAdd, 255, 255, 255, 255, kRenderFxNoDissipation );
m_pBall->SetAttachment( edict(), 1 );
m_pBall->SetScale( 4.0 );
m_pBall->pev->framerate = 10.0;
9 years ago
m_pBall->TurnOn();
9 years ago
}
}
9 years ago
if( m_pBall )
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( pev->origin.x ); // origin
WRITE_COORD( pev->origin.y );
WRITE_COORD( pev->origin.z );
WRITE_COORD( 256 ); // radius
WRITE_BYTE( 255 ); // R
WRITE_BYTE( 192 ); // G
WRITE_BYTE( 64 ); // B
WRITE_BYTE( 200 ); // life * 10
WRITE_COORD( 0 ); // decay
MESSAGE_END();
}
}
if( ( pev->health < gSkillData.nihilanthHealth / 2 || m_iActiveSpheres < N_SPHERES / 2 ) && m_hRecharger == 0 && m_iLevel <= 9 )
9 years ago
{
char szName[64];
CBaseEntity *pEnt = NULL;
CBaseEntity *pRecharger = NULL;
float flDist = 8192;
9 years ago
sprintf( szName, "%s%d", m_szRechargerTarget, m_iLevel );
9 years ago
9 years ago
while( ( pEnt = UTIL_FindEntityByTargetname( pEnt, szName ) ) != NULL )
9 years ago
{
9 years ago
float flLocal = (pEnt->pev->origin - pev->origin ).Length();
if( flLocal < flDist )
9 years ago
{
flDist = flLocal;
pRecharger = pEnt;
9 years ago
}
9 years ago
}
9 years ago
if( pRecharger )
9 years ago
{
m_hRecharger = pRecharger;
m_posDesired = Vector( pev->origin.x, pev->origin.y, pRecharger->pev->origin.z );
9 years ago
m_vecDesired = ( pRecharger->pev->origin - m_posDesired ).Normalize();
9 years ago
m_vecDesired.z = 0;
m_vecDesired = m_vecDesired.Normalize();
}
else
{
m_hRecharger = NULL;
ALERT( at_aiconsole, "nihilanth can't find %s\n", szName );
m_iLevel++;
9 years ago
if( m_iLevel > 9 )
9 years ago
m_irritation = 2;
}
}
9 years ago
float flDist = ( m_posDesired - pev->origin ).Length();
9 years ago
float flDot = DotProduct( m_vecDesired, gpGlobals->v_forward );
if( m_hRecharger != 0 )
9 years ago
{
// at we at power up yet?
9 years ago
if( flDist < 128.0 )
9 years ago
{
int iseq = LookupSequence( "recharge" );
9 years ago
if( iseq != pev->sequence )
9 years ago
{
char szText[64];
sprintf( szText, "%s%d", m_szDrawUse, m_iLevel );
FireTargets( szText, this, this, USE_ON, 1.0 );
ALERT( at_console, "fireing %s\n", szText );
}
pev->sequence = LookupSequence( "recharge" );
}
else
{
9 years ago
FloatSequence();
9 years ago
}
return;
}
if( m_hEnemy != 0 && !m_hEnemy->IsAlive() )
9 years ago
{
m_hEnemy = 0;
9 years ago
}
9 years ago
if( m_flLastSeen + 15 < gpGlobals->time )
9 years ago
{
m_hEnemy = 0;
9 years ago
}
if( m_hEnemy == 0 )
9 years ago
{
Look( 4096 );
9 years ago
m_hEnemy = BestVisibleEnemy();
9 years ago
}
if( m_hEnemy != 0 && m_irritation != 0 )
9 years ago
{
9 years ago
if( m_flLastSeen + 5 > gpGlobals->time && flDist < 256 && flDot > 0 )
9 years ago
{
9 years ago
if( m_irritation >= 2 && pev->health < gSkillData.nihilanthHealth / 2.0 )
9 years ago
{
pev->sequence = LookupSequence( "attack1_open" );
}
else
{
9 years ago
if( RANDOM_LONG( 0, 1 ) == 0 )
9 years ago
{
pev->sequence = LookupSequence( "attack1" ); // zap
}
else
{
char szText[64];
sprintf( szText, "%s%d", m_szTeleportTouch, m_iTeleport );
CBaseEntity *pTouch = UTIL_FindEntityByTargetname( NULL, szText );
sprintf( szText, "%s%d", m_szTeleportUse, m_iTeleport );
CBaseEntity *pTrigger = UTIL_FindEntityByTargetname( NULL, szText );
9 years ago
if( pTrigger != NULL || pTouch != NULL )
9 years ago
{
pev->sequence = LookupSequence( "attack2" ); // teleport
}
else
{
m_iTeleport++;
pev->sequence = LookupSequence( "attack1" ); // zap
}
}
}
return;
}
}
9 years ago
FloatSequence();
9 years ago
}
9 years ago
void CNihilanth::HuntThink( void )
9 years ago
{
pev->nextthink = gpGlobals->time + 0.1;
9 years ago
DispatchAnimEvents();
StudioFrameAdvance();
9 years ago
9 years ago
ShootBalls();
9 years ago
// if dead, force cancelation of current animation
9 years ago
if( pev->health <= 0 )
9 years ago
{
SetThink( &CNihilanth::DyingThink );
m_fSequenceFinished = TRUE;
return;
}
// ALERT( at_console, "health %.0f\n", pev->health );
// if damaged, try to abosorb some spheres
9 years ago
if( pev->health < gSkillData.nihilanthHealth && AbsorbSphere() )
9 years ago
{
pev->health += gSkillData.nihilanthHealth / N_SPHERES;
}
// get new sequence
9 years ago
if( m_fSequenceFinished )
9 years ago
{
9 years ago
// if ( !m_fSequenceLoops )
9 years ago
pev->frame = 0;
9 years ago
NextActivity();
ResetSequenceInfo();
pev->framerate = 2.0 - 1.0 * ( pev->health / gSkillData.nihilanthHealth );
9 years ago
}
// look for current enemy
if( m_hEnemy != 0 && m_hRecharger == 0 )
9 years ago
{
9 years ago
if( FVisible( m_hEnemy ) )
9 years ago
{
9 years ago
if( m_flLastSeen < gpGlobals->time - 5 )
9 years ago
m_flPrevSeen = gpGlobals->time;
m_flLastSeen = gpGlobals->time;
m_posTarget = m_hEnemy->pev->origin;
9 years ago
m_vecTarget = ( m_posTarget - pev->origin ).Normalize();
9 years ago
m_vecDesired = m_vecTarget;
m_posDesired = Vector( pev->origin.x, pev->origin.y, m_posTarget.z + m_flAdj );
}
else
{
m_flAdj = Q_min( m_flAdj + 10, 1000 );
9 years ago
}
}
// don't go too high
9 years ago
if( m_posDesired.z > m_flMaxZ )
9 years ago
m_posDesired.z = m_flMaxZ;
// don't go too low
9 years ago
if( m_posDesired.z < m_flMinZ )
9 years ago
m_posDesired.z = m_flMinZ;
9 years ago
Flight();
9 years ago
}
9 years ago
void CNihilanth::Flight( void )
9 years ago
{
// estimate where I'll be facing in one seconds
UTIL_MakeAimVectors( pev->angles + m_avelocity );
// Vector vecEst1 = pev->origin + m_velocity + gpGlobals->v_up * m_flForce - Vector( 0, 0, 384 );
// float flSide = DotProduct( m_posDesired - vecEst1, gpGlobals->v_right );
float flSide = DotProduct( m_vecDesired, gpGlobals->v_right );
9 years ago
if( flSide < 0 )
9 years ago
{
9 years ago
if( m_avelocity.y < 180 )
9 years ago
{
9 years ago
m_avelocity.y += 6; // 9 * ( 3.0 / 2.0 );
9 years ago
}
}
else
{
9 years ago
if( m_avelocity.y > -180 )
9 years ago
{
9 years ago
m_avelocity.y -= 6; // 9 * ( 3.0 / 2.0 );
9 years ago
}
}
m_avelocity.y *= 0.98;
// estimate where I'll be in two seconds
Vector vecEst = pev->origin + m_velocity * 2.0 + gpGlobals->v_up * m_flForce * 20;
// add immediate force
UTIL_MakeAimVectors( pev->angles );
m_velocity.x += gpGlobals->v_up.x * m_flForce;
m_velocity.y += gpGlobals->v_up.y * m_flForce;
m_velocity.z += gpGlobals->v_up.z * m_flForce;
float flSpeed = m_velocity.Length();
float flDir = DotProduct( Vector( gpGlobals->v_forward.x, gpGlobals->v_forward.y, 0 ), Vector( m_velocity.x, m_velocity.y, 0 ) );
9 years ago
if( flDir < 0 )
9 years ago
flSpeed = -flSpeed;
//float flDist = DotProduct( m_posDesired - vecEst, gpGlobals->v_forward );
9 years ago
// sideways drag
9 years ago
m_velocity.x = m_velocity.x * ( 1.0 - fabs( gpGlobals->v_right.x ) * 0.05 );
m_velocity.y = m_velocity.y * ( 1.0 - fabs( gpGlobals->v_right.y ) * 0.05 );
m_velocity.z = m_velocity.z * ( 1.0 - fabs( gpGlobals->v_right.z ) * 0.05 );
9 years ago
// general drag
m_velocity = m_velocity * 0.995;
9 years ago
// apply power to stay correct height
9 years ago
if( m_flForce < 100 && vecEst.z < m_posDesired.z )
9 years ago
{
m_flForce += 10;
}
9 years ago
else if( m_flForce > -100 && vecEst.z > m_posDesired.z )
9 years ago
{
9 years ago
if( vecEst.z > m_posDesired.z )
9 years ago
m_flForce -= 10;
}
UTIL_SetOrigin( pev, pev->origin + m_velocity * 0.1 );
pev->angles = pev->angles + m_avelocity * 0.1;
// ALERT( at_console, "%5.0f %5.0f : %4.0f : %3.0f : %2.0f\n", m_posDesired.z, pev->origin.z, m_velocity.z, m_avelocity.y, m_flForce );
}
9 years ago
BOOL CNihilanth::AbsorbSphere( void )
9 years ago
{
9 years ago
for( int i = 0; i < N_SPHERES; i++ )
9 years ago
{
if( m_hSphere[i] != 0 )
9 years ago
{
9 years ago
CNihilanthHVR *pSphere = (CNihilanthHVR *)( (CBaseEntity *)m_hSphere[i] );
pSphere->AbsorbInit();
9 years ago
m_hSphere[i] = NULL;
m_iActiveSpheres--;
return TRUE;
}
}
return FALSE;
}
9 years ago
BOOL CNihilanth::EmitSphere( void )
9 years ago
{
m_iActiveSpheres = 0;
int empty = 0;
9 years ago
for( int i = 0; i < N_SPHERES; i++ )
9 years ago
{
if( m_hSphere[i] != 0 )
9 years ago
{
m_iActiveSpheres++;
}
else
{
empty = i;
}
}
9 years ago
if( m_iActiveSpheres >= N_SPHERES )
9 years ago
return FALSE;
Vector vecSrc = m_hRecharger->pev->origin;
CNihilanthHVR *pEntity = (CNihilanthHVR *)Create( "nihilanth_energy_ball", vecSrc, pev->angles, edict() );
pEntity->pev->velocity = pev->origin - vecSrc;
pEntity->CircleInit( this );
m_hSphere[empty] = pEntity;
return TRUE;
}
9 years ago
void CNihilanth::TargetSphere( USE_TYPE useType, float value )
9 years ago
{
int i;
CBaseMonster *pSphere;
9 years ago
for( i = 0; i < N_SPHERES; i++ )
9 years ago
{
if( m_hSphere[i] != 0 )
9 years ago
{
pSphere = m_hSphere[i]->MyMonsterPointer();
if( pSphere->m_hEnemy == 0 )
9 years ago
break;
}
}
9 years ago
if( i == N_SPHERES )
9 years ago
{
return;
}
Vector vecSrc, vecAngles;
GetAttachment( 2, vecSrc, vecAngles );
UTIL_SetOrigin( pSphere->pev, vecSrc );
pSphere->Use( this, this, useType, value );
pSphere->pev->velocity = m_vecDesired * RANDOM_FLOAT( 50, 100 ) + Vector( RANDOM_FLOAT( -50, 50 ), RANDOM_FLOAT( -50, 50 ), RANDOM_FLOAT( -50, 50 ) );
}
9 years ago
void CNihilanth::HandleAnimEvent( MonsterEvent_t *pEvent )
9 years ago
{
switch( pEvent->event )
{
9 years ago
case 1:
// shoot
9 years ago
break;
9 years ago
case 2:
// zen
if( m_hEnemy != 0 )
9 years ago
{
9 years ago
if( RANDOM_LONG( 0, 4 ) == 0 )
9 years ago
EMIT_SOUND( edict(), CHAN_VOICE, RANDOM_SOUND_ARRAY( pAttackSounds ), 1.0, 0.2 );
EMIT_SOUND( edict(), CHAN_WEAPON, RANDOM_SOUND_ARRAY( pBallSounds ), 1.0, 0.2 );
MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY );
WRITE_BYTE( TE_ELIGHT );
9 years ago
WRITE_SHORT( entindex() + 0x3000 ); // entity, attachment
9 years ago
WRITE_COORD( pev->origin.x ); // origin
WRITE_COORD( pev->origin.y );
WRITE_COORD( pev->origin.z );
WRITE_COORD( 256 ); // radius
WRITE_BYTE( 128 ); // R
WRITE_BYTE( 128 ); // G
WRITE_BYTE( 255 ); // B
WRITE_BYTE( 10 ); // life * 10
WRITE_COORD( 128 ); // decay
MESSAGE_END();
MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY );
WRITE_BYTE( TE_ELIGHT );
9 years ago
WRITE_SHORT( entindex() + 0x4000 ); // entity, attachment
9 years ago
WRITE_COORD( pev->origin.x ); // origin
WRITE_COORD( pev->origin.y );
WRITE_COORD( pev->origin.z );
WRITE_COORD( 256 ); // radius
WRITE_BYTE( 128 ); // R
WRITE_BYTE( 128 ); // G
WRITE_BYTE( 255 ); // B
WRITE_BYTE( 10 ); // life * 10
WRITE_COORD( 128 ); // decay
MESSAGE_END();
9 years ago
m_flShootTime = gpGlobals->time;
m_flShootEnd = gpGlobals->time + 1.0;
}
break;
9 years ago
case 3:
// prayer
if( m_hEnemy != 0 )
9 years ago
{
char szText[32];
sprintf( szText, "%s%d", m_szTeleportTouch, m_iTeleport );
CBaseEntity *pTouch = UTIL_FindEntityByTargetname( NULL, szText );
sprintf( szText, "%s%d", m_szTeleportUse, m_iTeleport );
CBaseEntity *pTrigger = UTIL_FindEntityByTargetname( NULL, szText );
9 years ago
if( pTrigger != NULL || pTouch != NULL )
9 years ago
{
EMIT_SOUND( edict(), CHAN_VOICE, RANDOM_SOUND_ARRAY( pAttackSounds ), 1.0, 0.2 );
Vector vecSrc, vecAngles;
GetAttachment( 2, vecSrc, vecAngles );
CNihilanthHVR *pEntity = (CNihilanthHVR *)Create( "nihilanth_energy_ball", vecSrc, pev->angles, edict() );
pEntity->pev->velocity = pev->origin - vecSrc;
pEntity->TeleportInit( this, m_hEnemy, pTrigger, pTouch );
}
else
{
m_iTeleport++; // unexpected failure
EMIT_SOUND( edict(), CHAN_WEAPON, RANDOM_SOUND_ARRAY( pBallSounds ), 1.0, 0.2 );
ALERT( at_aiconsole, "nihilanth can't target %s\n", szText );
MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY );
WRITE_BYTE( TE_ELIGHT );
9 years ago
WRITE_SHORT( entindex() + 0x3000 ); // entity, attachment
9 years ago
WRITE_COORD( pev->origin.x ); // origin
WRITE_COORD( pev->origin.y );
WRITE_COORD( pev->origin.z );
WRITE_COORD( 256 ); // radius
WRITE_BYTE( 128 ); // R
WRITE_BYTE( 128 ); // G
WRITE_BYTE( 255 ); // B
WRITE_BYTE( 10 ); // life * 10
WRITE_COORD( 128 ); // decay
MESSAGE_END();
MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY );
WRITE_BYTE( TE_ELIGHT );
9 years ago
WRITE_SHORT( entindex() + 0x4000 ); // entity, attachment
9 years ago
WRITE_COORD( pev->origin.x ); // origin
WRITE_COORD( pev->origin.y );
WRITE_COORD( pev->origin.z );
WRITE_COORD( 256 ); // radius
WRITE_BYTE( 128 ); // R
WRITE_BYTE( 128 ); // G
WRITE_BYTE( 255 ); // B
WRITE_BYTE( 10 ); // life * 10
WRITE_COORD( 128 ); // decay
MESSAGE_END();
m_flShootTime = gpGlobals->time;
m_flShootEnd = gpGlobals->time + 1.0;
}
}
break;
9 years ago
case 4:
// get a sphere
9 years ago
{
if( m_hRecharger != 0 )
9 years ago
{
9 years ago
if( !EmitSphere() )
9 years ago
{
m_hRecharger = NULL;
}
}
}
break;
9 years ago
case 5:
// start up sphere machine
9 years ago
{
9 years ago
EMIT_SOUND( edict(), CHAN_VOICE, RANDOM_SOUND_ARRAY( pRechargeSounds ), 1.0, 0.2 );
9 years ago
}
break;
case 6:
if( m_hEnemy != 0 )
9 years ago
{
Vector vecSrc, vecAngles;
GetAttachment( 2, vecSrc, vecAngles );
CNihilanthHVR *pEntity = (CNihilanthHVR *)Create( "nihilanth_energy_ball", vecSrc, pev->angles, edict() );
pEntity->pev->velocity = pev->origin - vecSrc;
pEntity->ZapInit( m_hEnemy );
}
break;
case 7:
/*
Vector vecSrc, vecAngles;
GetAttachment( 0, vecSrc, vecAngles );
CNihilanthHVR *pEntity = (CNihilanthHVR *)Create( "nihilanth_energy_ball", vecSrc, pev->angles, edict() );
9 years ago
pEntity->pev->velocity = Vector( RANDOM_FLOAT( -0.7, 0.7 ), RANDOM_FLOAT( -0.7, 0.7 ), 1.0 ) * 600.0;
pEntity->GreenBallInit();
9 years ago
*/
break;
}
}
void CNihilanth::CommandUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
{
9 years ago
switch( useType )
9 years ago
{
case USE_OFF:
{
9 years ago
CBaseEntity *pTouch = UTIL_FindEntityByTargetname( NULL, m_szDeadTouch );
if( pTouch )
{
if( m_hEnemy != 0 )
{
pTouch->Touch( m_hEnemy );
}
// if the player is using "notarget", the ending sequence won't fire unless we catch it here
else
{
CBaseEntity *pEntity = UTIL_FindEntityByClassname( NULL, "player" );
if( pEntity != NULL && pEntity->IsAlive() )
{
pTouch->Touch( pEntity );
}
}
}
9 years ago
}
break;
case USE_ON:
9 years ago
if( m_irritation == 0 )
9 years ago
{
m_irritation = 1;
}
break;
case USE_SET:
break;
case USE_TOGGLE:
break;
}
}
9 years ago
int CNihilanth::TakeDamage( entvars_t* pevInflictor, entvars_t* pevAttacker, float flDamage, int bitsDamageType )
9 years ago
{
9 years ago
if( pevInflictor->owner == edict() )
9 years ago
return 0;
9 years ago
if( flDamage >= pev->health )
9 years ago
{
pev->health = 1;
9 years ago
if( m_irritation != 3 )
9 years ago
return 0;
}
9 years ago
PainSound();
9 years ago
pev->health -= flDamage;
return 0;
}
9 years ago
void CNihilanth::TraceAttack( entvars_t *pevAttacker, float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType )
9 years ago
{
9 years ago
if( m_irritation == 3 )
9 years ago
m_irritation = 2;
9 years ago
if( m_irritation == 2 && ptr->iHitgroup == 2 && flDamage > 2 )
9 years ago
m_irritation = 3;
9 years ago
if( m_irritation != 3 )
9 years ago
{
9 years ago
Vector vecBlood = ( ptr->vecEndPos - pev->origin ).Normalize();
9 years ago
9 years ago
UTIL_BloodStream( ptr->vecEndPos, vecBlood, BloodColor(), flDamage + ( 100 - 100 * ( pev->health / gSkillData.nihilanthHealth ) ) );
9 years ago
}
9 years ago
// SpawnBlood( ptr->vecEndPos, BloodColor(), flDamage * 5.0 );// a little surface blood.
9 years ago
AddMultiDamage( pevAttacker, this, flDamage, bitsDamageType );
}
CBaseEntity *CNihilanth::RandomTargetname( const char *szName )
{
int total = 0;
CBaseEntity *pEntity = NULL;
CBaseEntity *pNewEntity = NULL;
9 years ago
while( ( pNewEntity = UTIL_FindEntityByTargetname( pNewEntity, szName ) ) != NULL )
9 years ago
{
total++;
9 years ago
if( RANDOM_LONG( 0, total - 1 ) < 1 )
9 years ago
pEntity = pNewEntity;
}
return pEntity;
}
//=========================================================
// Controller bouncy ball attack
//=========================================================
9 years ago
void CNihilanthHVR::Spawn( void )
9 years ago
{
9 years ago
Precache();
9 years ago
pev->rendermode = kRenderTransAdd;
pev->renderamt = 255;
pev->scale = 3.0;
}
9 years ago
void CNihilanthHVR::Precache( void )
9 years ago
{
9 years ago
PRECACHE_MODEL( "sprites/flare6.spr" );
PRECACHE_MODEL( "sprites/nhth1.spr" );
PRECACHE_MODEL( "sprites/exit1.spr" );
PRECACHE_MODEL( "sprites/tele1.spr" );
PRECACHE_MODEL( "sprites/animglow01.spr" );
PRECACHE_MODEL( "sprites/xspark4.spr" );
PRECACHE_MODEL( "sprites/muzzleflash3.spr" );
PRECACHE_SOUND( "debris/zap4.wav" );
PRECACHE_SOUND( "weapons/electro4.wav" );
PRECACHE_SOUND( "x/x_teleattack1.wav" );
9 years ago
}
9 years ago
void CNihilanthHVR::CircleInit( CBaseEntity *pTarget )
9 years ago
{
pev->movetype = MOVETYPE_NOCLIP;
pev->solid = SOLID_NOT;
9 years ago
// SET_MODEL( edict(), "sprites/flare6.spr" );
9 years ago
// pev->scale = 3.0;
9 years ago
// SET_MODEL( edict(), "sprites/xspark4.spr" );
SET_MODEL( edict(), "sprites/muzzleflash3.spr" );
9 years ago
pev->rendercolor.x = 255;
pev->rendercolor.y = 224;
pev->rendercolor.z = 192;
pev->scale = 2.0;
m_nFrames = 1;
pev->renderamt = 255;
9 years ago
UTIL_SetSize( pev, Vector( 0, 0, 0 ), Vector( 0, 0, 0 ) );
9 years ago
UTIL_SetOrigin( pev, pev->origin );
SetThink( &CNihilanthHVR::HoverThink );
SetTouch( &CNihilanthHVR::BounceTouch );
pev->nextthink = gpGlobals->time + 0.1;
m_hTargetEnt = pTarget;
}
CBaseEntity *CNihilanthHVR::RandomClassname( const char *szName )
{
int total = 0;
CBaseEntity *pEntity = NULL;
CBaseEntity *pNewEntity = NULL;
9 years ago
while( ( pNewEntity = UTIL_FindEntityByClassname( pNewEntity, szName ) ) != NULL )
9 years ago
{
total++;
9 years ago
if( RANDOM_LONG( 0, total - 1 ) < 1 )
9 years ago
pEntity = pNewEntity;
}
return pEntity;
}
9 years ago
void CNihilanthHVR::HoverThink( void )
9 years ago
{
pev->nextthink = gpGlobals->time + 0.1;
if( m_hTargetEnt != 0 )
9 years ago
{
CircleTarget( m_hTargetEnt->pev->origin + Vector( 0, 0, 16 * N_SCALE ) );
}
else
{
UTIL_Remove( this );
}
9 years ago
if( RANDOM_LONG( 0, 99 ) < 5 )
9 years ago
{
/*
9 years ago
CBaseEntity *pOther = RandomClassname( STRING( pev->classname ) );
9 years ago
9 years ago
if( pOther && pOther != this )
9 years ago
{
MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY );
WRITE_BYTE( TE_BEAMENTS );
WRITE_SHORT( this->entindex() );
WRITE_SHORT( pOther->entindex() );
WRITE_SHORT( g_sModelIndexLaser );
WRITE_BYTE( 0 ); // framestart
WRITE_BYTE( 0 ); // framerate
WRITE_BYTE( 10 ); // life
WRITE_BYTE( 80 ); // width
WRITE_BYTE( 80 ); // noise
WRITE_BYTE( 255 ); // r, g, b
WRITE_BYTE( 128 ); // r, g, b
WRITE_BYTE( 64 ); // r, g, b
WRITE_BYTE( 255 ); // brightness
WRITE_BYTE( 30 ); // speed
MESSAGE_END();
}
*/
/*
MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY );
WRITE_BYTE( TE_BEAMENTS );
WRITE_SHORT( this->entindex() );
WRITE_SHORT( m_hTargetEnt->entindex() + 0x1000 );
WRITE_SHORT( g_sModelIndexLaser );
WRITE_BYTE( 0 ); // framestart
WRITE_BYTE( 0 ); // framerate
WRITE_BYTE( 10 ); // life
WRITE_BYTE( 80 ); // width
WRITE_BYTE( 80 ); // noise
WRITE_BYTE( 255 ); // r, g, b
WRITE_BYTE( 128 ); // r, g, b
WRITE_BYTE( 64 ); // r, g, b
WRITE_BYTE( 255 ); // brightness
WRITE_BYTE( 30 ); // speed
MESSAGE_END();
*/
}
9 years ago
pev->frame = ( (int)pev->frame + 1 ) % m_nFrames;
9 years ago
}
9 years ago
void CNihilanthHVR::ZapInit( CBaseEntity *pEnemy )
9 years ago
{
pev->movetype = MOVETYPE_FLY;
pev->solid = SOLID_BBOX;
9 years ago
SET_MODEL( edict(), "sprites/nhth1.spr" );
9 years ago
pev->rendercolor.x = 255;
pev->rendercolor.y = 255;
pev->rendercolor.z = 255;
pev->scale = 2.0;
9 years ago
pev->velocity = ( pEnemy->pev->origin - pev->origin ).Normalize() * 200;
9 years ago
m_hEnemy = pEnemy;
SetThink( &CNihilanthHVR::ZapThink );
SetTouch( &CNihilanthHVR::ZapTouch );
pev->nextthink = gpGlobals->time + 0.1;
EMIT_SOUND_DYN( edict(), CHAN_WEAPON, "debris/zap4.wav", 1, ATTN_NORM, 0, 100 );
}
9 years ago
void CNihilanthHVR::ZapThink( void )
9 years ago
{
pev->nextthink = gpGlobals->time + 0.05;
// check world boundaries
if( m_hEnemy == 0 || 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
if( pev->velocity.Length() < 2000 )
9 years ago
{
pev->velocity = pev->velocity * 1.2;
}
9 years ago
// MovetoTarget( m_hEnemy->Center() );
9 years ago
9 years ago
if( ( m_hEnemy->Center() - pev->origin ).Length() < 256 )
9 years ago
{
TraceResult tr;
UTIL_TraceLine( pev->origin, m_hEnemy->Center(), dont_ignore_monsters, edict(), &tr );
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( pev, gSkillData.nihilanthZap, pev->velocity, &tr, DMG_SHOCK );
ApplyMultiDamage( pev, 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( 20 ); // noise
WRITE_BYTE( 64 ); // r, g, b
WRITE_BYTE( 196 ); // r, g, b
WRITE_BYTE( 255); // r, g, b
WRITE_BYTE( 255 ); // brightness
WRITE_BYTE( 10 ); // speed
MESSAGE_END();
UTIL_EmitAmbientSound( edict(), tr.vecEndPos, "weapons/electro4.wav", 0.5, ATTN_NORM, 0, RANDOM_LONG( 140, 160 ) );
SetTouch( NULL );
UTIL_Remove( this );
pev->nextthink = gpGlobals->time + 0.2;
return;
}
9 years ago
pev->frame = (int)( pev->frame + 1 ) % 11;
9 years ago
MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY );
WRITE_BYTE( TE_ELIGHT );
WRITE_SHORT( entindex( ) ); // entity, attachment
WRITE_COORD( pev->origin.x ); // origin
WRITE_COORD( pev->origin.y );
WRITE_COORD( pev->origin.z );
WRITE_COORD( 128 ); // radius
WRITE_BYTE( 128 ); // R
WRITE_BYTE( 128 ); // G
WRITE_BYTE( 255 ); // B
WRITE_BYTE( 10 ); // life * 10
WRITE_COORD( 128 ); // decay
MESSAGE_END();
9 years ago
// Crawl();
9 years ago
}
void CNihilanthHVR::ZapTouch( CBaseEntity *pOther )
{
UTIL_EmitAmbientSound( edict(), pev->origin, "weapons/electro4.wav", 1.0, ATTN_NORM, 0, RANDOM_LONG( 90, 95 ) );
RadiusDamage( pev, pev, 50, CLASS_NONE, DMG_SHOCK );
pev->velocity = pev->velocity * 0;
/*
9 years ago
for( int i = 0; i < 10; i++ )
9 years ago
{
9 years ago
Crawl();
9 years ago
}
*/
SetTouch( NULL );
UTIL_Remove( this );
pev->nextthink = gpGlobals->time + 0.2;
}
9 years ago
void CNihilanthHVR::TeleportInit( CNihilanth *pOwner, CBaseEntity *pEnemy, CBaseEntity *pTarget, CBaseEntity *pTouch )
9 years ago
{
pev->movetype = MOVETYPE_FLY;
pev->solid = SOLID_BBOX;
pev->rendercolor.x = 255;
pev->rendercolor.y = 255;
pev->rendercolor.z = 255;
pev->velocity.z *= 0.2;
9 years ago
SET_MODEL( edict(), "sprites/exit1.spr" );
9 years ago
m_pNihilanth = pOwner;
m_hEnemy = pEnemy;
m_hTargetEnt = pTarget;
m_hTouch = pTouch;
SetThink( &CNihilanthHVR::TeleportThink );
SetTouch( &CNihilanthHVR::TeleportTouch );
pev->nextthink = gpGlobals->time + 0.1;
EMIT_SOUND_DYN( edict(), CHAN_WEAPON, "x/x_teleattack1.wav", 1, 0.2, 0, 100 );
}
9 years ago
void CNihilanthHVR::GreenBallInit()
9 years ago
{
pev->movetype = MOVETYPE_FLY;
pev->solid = SOLID_BBOX;
pev->rendercolor.x = 255;
pev->rendercolor.y = 255;
pev->rendercolor.z = 255;
pev->scale = 1.0;
9 years ago
SET_MODEL( edict(), "sprites/exit1.spr" );
9 years ago
SetTouch( &CNihilanthHVR::RemoveTouch );
}
9 years ago
void CNihilanthHVR::TeleportThink( void )
9 years ago
{
pev->nextthink = gpGlobals->time + 0.1;
// check world boundaries
if( m_hEnemy == 0 || !m_hEnemy->IsAlive() || 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
{
9 years ago
STOP_SOUND( edict(), CHAN_WEAPON, "x/x_teleattack1.wav" );
9 years ago
UTIL_Remove( this );
return;
}
9 years ago
if( ( m_hEnemy->Center() - pev->origin).Length() < 128 )
9 years ago
{
9 years ago
STOP_SOUND( edict(), CHAN_WEAPON, "x/x_teleattack1.wav" );
9 years ago
UTIL_Remove( this );
if( m_hTargetEnt != 0 )
9 years ago
m_hTargetEnt->Use( m_hEnemy, m_hEnemy, USE_ON, 1.0 );
if( m_hTouch != 0 && m_hEnemy != 0 )
9 years ago
m_hTouch->Touch( m_hEnemy );
}
else
{
9 years ago
MovetoTarget( m_hEnemy->Center() );
9 years ago
}
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( 256 ); // radius
WRITE_BYTE( 0 ); // R
WRITE_BYTE( 255 ); // G
WRITE_BYTE( 0 ); // B
WRITE_BYTE( 10 ); // life * 10
WRITE_COORD( 256 ); // decay
MESSAGE_END();
9 years ago
pev->frame = (int)( pev->frame + 1 ) % 20;
9 years ago
}
9 years ago
void CNihilanthHVR::AbsorbInit( void )
9 years ago
{
SetThink( &CNihilanthHVR::DissipateThink );
pev->renderamt = 255;
MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY );
WRITE_BYTE( TE_BEAMENTS );
WRITE_SHORT( this->entindex() );
WRITE_SHORT( m_hTargetEnt->entindex() + 0x1000 );
WRITE_SHORT( g_sModelIndexLaser );
WRITE_BYTE( 0 ); // framestart
WRITE_BYTE( 0 ); // framerate
WRITE_BYTE( 50 ); // life
WRITE_BYTE( 80 ); // width
WRITE_BYTE( 80 ); // noise
WRITE_BYTE( 255 ); // r, g, b
WRITE_BYTE( 128 ); // r, g, b
WRITE_BYTE( 64 ); // r, g, b
WRITE_BYTE( 255 ); // brightness
WRITE_BYTE( 30 ); // speed
MESSAGE_END();
}
void CNihilanthHVR::TeleportTouch( CBaseEntity *pOther )
{
CBaseEntity *pEnemy = m_hEnemy;
9 years ago
if( pOther == pEnemy )
9 years ago
{
if( m_hTargetEnt != 0 )
9 years ago
m_hTargetEnt->Use( pEnemy, pEnemy, USE_ON, 1.0 );
if( m_hTouch != 0 && pEnemy != NULL )
9 years ago
m_hTouch->Touch( pEnemy );
}
else
{
m_pNihilanth->MakeFriend( pev->origin );
}
SetTouch( NULL );
STOP_SOUND(edict(), CHAN_WEAPON, "x/x_teleattack1.wav" );
UTIL_Remove( this );
}
9 years ago
void CNihilanthHVR::DissipateThink( void )
9 years ago
{
pev->nextthink = gpGlobals->time + 0.1;
9 years ago
if( pev->scale > 5.0 )
9 years ago
UTIL_Remove( this );
pev->renderamt -= 2;
pev->scale += 0.1;
if( m_hTargetEnt != 0 )
9 years ago
{
CircleTarget( m_hTargetEnt->pev->origin + Vector( 0, 0, 4096 ) );
}
else
{
UTIL_Remove( this );
}
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 ); // radius
WRITE_BYTE( 255 ); // R
WRITE_BYTE( 192 ); // G
WRITE_BYTE( 64 ); // B
WRITE_BYTE( 2 ); // life * 10
WRITE_COORD( 0 ); // decay
MESSAGE_END();
}
9 years ago
BOOL CNihilanthHVR::CircleTarget( Vector vecTarget )
9 years ago
{
BOOL fClose = FALSE;
Vector vecDest = vecTarget;
Vector vecEst = pev->origin + pev->velocity * 0.5;
Vector vecSrc = pev->origin;
vecDest.z = 0;
vecEst.z = 0;
vecSrc.z = 0;
9 years ago
float d1 = ( vecDest - vecSrc ).Length() - 24 * N_SCALE;
float d2 = ( vecDest - vecEst ).Length() - 24 * N_SCALE;
9 years ago
9 years ago
if( m_vecIdeal == Vector( 0, 0, 0 ) )
9 years ago
{
m_vecIdeal = pev->velocity;
}
9 years ago
if( d1 < 0 && d2 <= d1 )
9 years ago
{
9 years ago
// ALERT( at_console, "too close\n" );
m_vecIdeal = m_vecIdeal - ( vecDest - vecSrc ).Normalize() * 50;
9 years ago
}
9 years ago
else if( d1 > 0 && d2 >= d1 )
9 years ago
{
9 years ago
// ALERT( at_console, "too far\n" );
m_vecIdeal = m_vecIdeal + ( vecDest - vecSrc ).Normalize() * 50;
9 years ago
}
pev->avelocity.z = d1 * 20;
9 years ago
if( d1 < 32 )
9 years ago
{
fClose = TRUE;
}
m_vecIdeal = m_vecIdeal + Vector( RANDOM_FLOAT( -2, 2 ), RANDOM_FLOAT( -2, 2 ), RANDOM_FLOAT( -2, 2 ));
9 years ago
m_vecIdeal = Vector( m_vecIdeal.x, m_vecIdeal.y, 0 ).Normalize() * 200
/* + Vector( -m_vecIdeal.y, m_vecIdeal.x, 0 ).Normalize() * 32 */
9 years ago
+ Vector( 0, 0, m_vecIdeal.z );
9 years ago
// m_vecIdeal = m_vecIdeal + Vector( -m_vecIdeal.y, m_vecIdeal.x, 0 ).Normalize() * 2;
9 years ago
// move up/down
d1 = vecTarget.z - pev->origin.z;
9 years ago
if( d1 > 0 && m_vecIdeal.z < 200 )
9 years ago
m_vecIdeal.z += 20;
9 years ago
else if( d1 < 0 && m_vecIdeal.z > -200 )
9 years ago
m_vecIdeal.z -= 20;
pev->velocity = m_vecIdeal;
// ALERT( at_console, "%.0f %.0f %.0f\n", m_vecIdeal.x, m_vecIdeal.y, m_vecIdeal.z );
return fClose;
}
9 years ago
void CNihilanthHVR::MovetoTarget( Vector vecTarget )
9 years ago
{
9 years ago
if( m_vecIdeal == Vector( 0, 0, 0 ) )
9 years ago
{
m_vecIdeal = pev->velocity;
}
// accelerate
float flSpeed = m_vecIdeal.Length();
9 years ago
if( flSpeed > 300 )
9 years ago
{
9 years ago
m_vecIdeal = m_vecIdeal.Normalize() * 300;
9 years ago
}
m_vecIdeal = m_vecIdeal + (vecTarget - pev->origin).Normalize() * 300;
pev->velocity = m_vecIdeal;
}
9 years ago
void CNihilanthHVR::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.2 + vecAim * 128;
MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY );
WRITE_BYTE( TE_BEAMENTPOINT );
WRITE_SHORT( entindex() );
9 years ago
WRITE_COORD( vecPnt.x );
WRITE_COORD( vecPnt.y );
WRITE_COORD( vecPnt.z );
9 years ago
WRITE_SHORT( g_sModelIndexLaser );
WRITE_BYTE( 0 ); // frame start
WRITE_BYTE( 10 ); // framerate
WRITE_BYTE( 3 ); // life
WRITE_BYTE( 20 ); // width
WRITE_BYTE( 80 ); // noise
WRITE_BYTE( 64 ); // r, g, b
WRITE_BYTE( 128 ); // r, g, b
WRITE_BYTE( 255); // r, g, b
WRITE_BYTE( 255 ); // brightness
WRITE_BYTE( 10 ); // speed
MESSAGE_END();
}
void CNihilanthHVR::RemoveTouch( CBaseEntity *pOther )
{
9 years ago
STOP_SOUND( edict(), CHAN_WEAPON, "x/x_teleattack1.wav" );
9 years ago
UTIL_Remove( this );
}
void CNihilanthHVR::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();
}
#endif