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.

447 lines
11 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.
*
* Use, distribution, and modification of this source code and/or resulting
* object code is restricted to non-commercial enhancements to products from
* Valve LLC. All other use, distribution, or modification is prohibited
* without written permission from Valve LLC.
*
****/
//=========================================================
// Hornets
//=========================================================
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "monsters.h"
#include "weapons.h"
#include "soundent.h"
#include "hornet.h"
#include "gamerules.h"
#include "game.h"
9 years ago
int iHornetTrail;
int iHornetPuff;
LINK_ENTITY_TO_CLASS( hornet, CHornet )
9 years ago
//=========================================================
// Save/Restore
//=========================================================
TYPEDESCRIPTION CHornet::m_SaveData[] =
9 years ago
{
DEFINE_FIELD( CHornet, m_flStopAttack, FIELD_TIME ),
DEFINE_FIELD( CHornet, m_iHornetType, FIELD_INTEGER ),
DEFINE_FIELD( CHornet, m_flFlySpeed, FIELD_FLOAT ),
};
IMPLEMENT_SAVERESTORE( CHornet, CBaseMonster )
9 years ago
//=========================================================
// don't let hornets gib, ever.
//=========================================================
8 years ago
int CHornet::TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType )
9 years ago
{
// filter these bits a little.
8 years ago
bitsDamageType &= ~( DMG_ALWAYSGIB );
9 years ago
bitsDamageType |= DMG_NEVERGIB;
8 years ago
return CBaseMonster::TakeDamage( pevInflictor, pevAttacker, flDamage, bitsDamageType );
9 years ago
}
//=========================================================
//=========================================================
8 years ago
void CHornet::Spawn( void )
9 years ago
{
Precache();
8 years ago
pev->movetype = MOVETYPE_FLY;
pev->solid = SOLID_BBOX;
9 years ago
pev->takedamage = DAMAGE_YES;
8 years ago
pev->flags |= FL_MONSTER;
pev->health = 1;// weak!
if( g_pGameRules->IsMultiplayer() )
9 years ago
{
// hornets don't live as long in multiplayer
m_flStopAttack = gpGlobals->time + 3.5;
}
else
{
m_flStopAttack = gpGlobals->time + 5.0;
}
m_flFieldOfView = 0.9; // +- 25 degrees
8 years ago
if( RANDOM_LONG( 1, 5 ) <= 2 )
9 years ago
{
m_iHornetType = HORNET_TYPE_RED;
m_flFlySpeed = HORNET_RED_SPEED;
}
else
{
m_iHornetType = HORNET_TYPE_ORANGE;
m_flFlySpeed = HORNET_ORANGE_SPEED;
}
8 years ago
SET_MODEL( ENT( pev ), "models/hornet.mdl" );
9 years ago
UTIL_SetSize( pev, Vector( -4, -4, -4 ), Vector( 4, 4, 4 ) );
SetTouch( &CHornet::DieTouch );
SetThink( &CHornet::StartTrack );
edict_t *pSoundEnt = pev->owner;
8 years ago
if( !pSoundEnt )
9 years ago
pSoundEnt = edict();
8 years ago
if( !FNullEnt( pev->owner ) && ( pev->owner->v.flags & FL_CLIENT ) )
9 years ago
{
pev->dmg = gSkillData.plrDmgHornet;
}
else
{
// no real owner, or owner isn't a client.
pev->dmg = gSkillData.monDmgHornet;
}
8 years ago
9 years ago
pev->nextthink = gpGlobals->time + 0.1;
8 years ago
ResetSequenceInfo();
9 years ago
}
8 years ago
void CHornet::Precache()
9 years ago
{
8 years ago
PRECACHE_MODEL( "models/hornet.mdl" );
9 years ago
PRECACHE_SOUND( "agrunt/ag_fire1.wav" );
PRECACHE_SOUND( "agrunt/ag_fire2.wav" );
PRECACHE_SOUND( "agrunt/ag_fire3.wav" );
PRECACHE_SOUND( "hornet/ag_buzz1.wav" );
PRECACHE_SOUND( "hornet/ag_buzz2.wav" );
PRECACHE_SOUND( "hornet/ag_buzz3.wav" );
PRECACHE_SOUND( "hornet/ag_hornethit1.wav" );
PRECACHE_SOUND( "hornet/ag_hornethit2.wav" );
PRECACHE_SOUND( "hornet/ag_hornethit3.wav" );
iHornetPuff = PRECACHE_MODEL( "sprites/muz1.spr" );
8 years ago
iHornetTrail = PRECACHE_MODEL( "sprites/laserbeam.spr" );
}
9 years ago
//=========================================================
// hornets will never get mad at each other, no matter who the owner is.
//=========================================================
8 years ago
int CHornet::IRelationship( CBaseEntity *pTarget )
9 years ago
{
8 years ago
if( pTarget->pev->modelindex == pev->modelindex )
9 years ago
{
return R_NO;
}
8 years ago
return CBaseMonster::IRelationship( pTarget );
9 years ago
}
//=========================================================
// ID's Hornet as their owner
//=========================================================
8 years ago
int CHornet::Classify( void )
9 years ago
{
8 years ago
if( pev->owner && pev->owner->v.flags & FL_CLIENT )
9 years ago
{
return CLASS_PLAYER_BIOWEAPON;
}
return CLASS_ALIEN_BIOWEAPON;
}
//=========================================================
// StartTrack - starts a hornet out tracking its target
//=========================================================
8 years ago
void CHornet::StartTrack( void )
9 years ago
{
IgniteTrail();
SetTouch( &CHornet::TrackTouch );
SetThink( &CHornet::TrackTarget );
pev->nextthink = gpGlobals->time + 0.1;
}
//=========================================================
// StartDart - starts a hornet out just flying straight.
//=========================================================
8 years ago
void CHornet::StartDart( void )
9 years ago
{
IgniteTrail();
SetTouch( &CHornet::DartTouch );
SetThink( &CBaseEntity::SUB_Remove );
pev->nextthink = gpGlobals->time + 4;
}
void CHornet::IgniteTrail( void )
{
/*
ted's suggested trail colors:
r161
g25
b97
r173
g39
b14
old colors
case HORNET_TYPE_RED:
WRITE_BYTE( 255 ); // r, g, b
WRITE_BYTE( 128 ); // r, g, b
WRITE_BYTE( 0 ); // r, g, b
break;
case HORNET_TYPE_ORANGE:
8 years ago
WRITE_BYTE( 0 ); // r, g, b
9 years ago
WRITE_BYTE( 100 ); // r, g, b
WRITE_BYTE( 255 ); // r, g, b
break;
8 years ago
9 years ago
*/
// trail
MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY );
8 years ago
WRITE_BYTE( TE_BEAMFOLLOW );
9 years ago
WRITE_SHORT( entindex() ); // entity
WRITE_SHORT( iHornetTrail ); // model
WRITE_BYTE( 10 ); // life
WRITE_BYTE( 2 ); // width
8 years ago
switch( m_iHornetType )
9 years ago
{
case HORNET_TYPE_RED:
WRITE_BYTE( 179 ); // r, g, b
WRITE_BYTE( 39 ); // r, g, b
WRITE_BYTE( 14 ); // r, g, b
break;
case HORNET_TYPE_ORANGE:
WRITE_BYTE( 255 ); // r, g, b
WRITE_BYTE( 128 ); // r, g, b
WRITE_BYTE( 0 ); // r, g, b
break;
}
WRITE_BYTE( 128 ); // brightness
MESSAGE_END();
}
//=========================================================
// Hornet is flying, gently tracking target
//=========================================================
8 years ago
void CHornet::TrackTarget( void )
9 years ago
{
Vector vecFlightDir;
Vector vecDirToEnemy;
float flDelta;
8 years ago
StudioFrameAdvance();
9 years ago
8 years ago
if( gpGlobals->time > m_flStopAttack )
9 years ago
{
SetTouch( NULL );
SetThink( &CBaseEntity::SUB_Remove );
pev->nextthink = gpGlobals->time + 0.1;
return;
}
// UNDONE: The player pointer should come back after returning from another level
8 years ago
if( m_hEnemy == NULL )
{
// enemy is dead.
9 years ago
Look( 512 );
8 years ago
m_hEnemy = BestVisibleEnemy();
9 years ago
}
8 years ago
if( m_hEnemy != NULL && FVisible( m_hEnemy ) )
9 years ago
{
m_vecEnemyLKP = m_hEnemy->BodyTarget( pev->origin );
}
else
{
m_vecEnemyLKP = m_vecEnemyLKP + pev->velocity * m_flFlySpeed * 0.1;
}
vecDirToEnemy = ( m_vecEnemyLKP - pev->origin ).Normalize();
8 years ago
if( pev->velocity.Length() < 0.1 )
9 years ago
vecFlightDir = vecDirToEnemy;
else
vecFlightDir = pev->velocity.Normalize();
// measure how far the turn is, the wider the turn, the slow we'll go this time.
8 years ago
flDelta = DotProduct( vecFlightDir, vecDirToEnemy );
if( flDelta < 0.5 )
{
// hafta turn wide again. play sound
8 years ago
switch( RANDOM_LONG( 0, 2 ) )
9 years ago
{
8 years ago
case 0:
EMIT_SOUND( ENT( pev ), CHAN_VOICE, "hornet/ag_buzz1.wav", HORNET_BUZZ_VOLUME, ATTN_NORM );
break;
case 1:
EMIT_SOUND( ENT( pev ), CHAN_VOICE, "hornet/ag_buzz2.wav", HORNET_BUZZ_VOLUME, ATTN_NORM );
break;
case 2:
EMIT_SOUND( ENT( pev ), CHAN_VOICE, "hornet/ag_buzz3.wav", HORNET_BUZZ_VOLUME, ATTN_NORM );
break;
9 years ago
}
}
8 years ago
if( flDelta <= 0 && m_iHornetType == HORNET_TYPE_RED )
{
// no flying backwards, but we don't want to invert this, cause we'd go fast when we have to turn REAL far.
9 years ago
flDelta = 0.25;
}
8 years ago
pev->velocity = ( vecFlightDir + vecDirToEnemy ).Normalize();
9 years ago
8 years ago
if( pev->owner && ( pev->owner->v.flags & FL_MONSTER ) )
9 years ago
{
// random pattern only applies to hornets fired by monsters, not players.
8 years ago
pev->velocity.x += RANDOM_FLOAT( -0.10, 0.10 );// scramble the flight dir a bit.
pev->velocity.y += RANDOM_FLOAT( -0.10, 0.10 );
pev->velocity.z += RANDOM_FLOAT( -0.10, 0.10 );
9 years ago
}
8 years ago
switch( m_iHornetType )
9 years ago
{
case HORNET_TYPE_RED:
pev->velocity = pev->velocity * ( m_flFlySpeed * flDelta );// scale the dir by the ( speed * width of turn )
pev->nextthink = gpGlobals->time + RANDOM_FLOAT( 0.1, 0.3 );
break;
case HORNET_TYPE_ORANGE:
pev->velocity = pev->velocity * m_flFlySpeed;// do not have to slow down to turn.
pev->nextthink = gpGlobals->time + 0.1;// fixed think time
break;
}
8 years ago
pev->angles = UTIL_VecToAngles( pev->velocity );
9 years ago
pev->solid = SOLID_BBOX;
// if hornet is close to the enemy, jet in a straight line for a half second.
// (only in the single player game)
8 years ago
if( m_hEnemy != NULL && !g_pGameRules->IsMultiplayer() )
9 years ago
{
8 years ago
if( flDelta >= 0.4 && ( pev->origin - m_vecEnemyLKP ).Length() <= 300 )
9 years ago
{
MESSAGE_BEGIN( MSG_PVS, SVC_TEMPENTITY, pev->origin );
WRITE_BYTE( TE_SPRITE );
8 years ago
WRITE_COORD( pev->origin.x ); // pos
WRITE_COORD( pev->origin.y );
WRITE_COORD( pev->origin.z );
9 years ago
WRITE_SHORT( iHornetPuff ); // model
// WRITE_BYTE( 0 ); // life * 10
WRITE_BYTE( 2 ); // size * 10
WRITE_BYTE( 128 ); // brightness
MESSAGE_END();
8 years ago
switch( RANDOM_LONG( 0, 2 ) )
9 years ago
{
8 years ago
case 0:
EMIT_SOUND( ENT( pev ), CHAN_VOICE, "hornet/ag_buzz1.wav", HORNET_BUZZ_VOLUME, ATTN_NORM );
break;
case 1:
EMIT_SOUND( ENT( pev ), CHAN_VOICE, "hornet/ag_buzz2.wav", HORNET_BUZZ_VOLUME, ATTN_NORM );
break;
case 2:
EMIT_SOUND( ENT( pev ), CHAN_VOICE, "hornet/ag_buzz3.wav", HORNET_BUZZ_VOLUME, ATTN_NORM );
break;
9 years ago
}
pev->velocity = pev->velocity * 2;
pev->nextthink = gpGlobals->time + 1.0;
// don't attack again
m_flStopAttack = gpGlobals->time;
}
}
}
//=========================================================
// Tracking Hornet hit something
//=========================================================
8 years ago
void CHornet::TrackTouch( CBaseEntity *pOther )
9 years ago
{
8 years ago
if( pOther->edict() == pev->owner || pOther->pev->modelindex == pev->modelindex )
{
// bumped into the guy that shot it.
9 years ago
pev->solid = SOLID_NOT;
return;
}
8 years ago
if( IRelationship( pOther ) <= R_NO )
9 years ago
{
// hit something we don't want to hurt, so turn around.
pev->velocity = pev->velocity.Normalize();
pev->velocity.x *= -1;
pev->velocity.y *= -1;
pev->origin = pev->origin + pev->velocity * 4; // bounce the hornet off a bit.
pev->velocity = pev->velocity * m_flFlySpeed;
return;
}
DieTouch( pOther );
}
void CHornet::DartTouch( CBaseEntity *pOther )
{
DieTouch( pOther );
}
8 years ago
void CHornet::DieTouch( CBaseEntity *pOther )
9 years ago
{
if( pOther && pOther->pev->takedamage && gpGlobals->time > pev->dmgtime )
{
// do the damage
8 years ago
switch( RANDOM_LONG( 0, 2 ) )
{
// buzz when you plug someone
8 years ago
case 0:
EMIT_SOUND( ENT( pev ), CHAN_VOICE, "hornet/ag_hornethit1.wav", 1, ATTN_NORM );
break;
case 1:
EMIT_SOUND( ENT( pev ), CHAN_VOICE, "hornet/ag_hornethit2.wav", 1, ATTN_NORM );
break;
case 2:
EMIT_SOUND( ENT( pev ), CHAN_VOICE, "hornet/ag_hornethit3.wav", 1, ATTN_NORM );
break;
9 years ago
}
8 years ago
8 years ago
if( !pev->owner )
pev->owner = edict();
if( mp_fixhornetbug.value )
{
pev->dmgtime = gpGlobals->time + 0.1;
// !finitef( pev->dmf )
if( ((*(int *)&( pev->dmg ) & 0x7f800000L) == 0x7f800000L) )
pev->dmg = 0;
}
9 years ago
pOther->TakeDamage( pev, VARS( pev->owner ), pev->dmg, DMG_BULLET );
9 years ago
}
pev->modelindex = 0;// so will disappear for the 0.1 secs we wait until NEXTTHINK gets rid
pev->solid = SOLID_NOT;
SetThink( &CBaseEntity::SUB_Remove );
pev->nextthink = gpGlobals->time + 1;// stick around long enough for the sound to finish!
}