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.

484 lines
14 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.
*
****/
//=========================================================
// barnacle - stationary ceiling mounted 'fishing' monster
//=========================================================
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "monsters.h"
#include "schedule.h"
#define SF_BARNACLE_SPAWN_XENCANDY 1
9 years ago
#define BARNACLE_BODY_HEIGHT 44 // how 'tall' the barnacle's model is.
#define BARNACLE_PULL_SPEED 8
#define BARNACLE_KILL_VICTIM_DELAY 5 // how many seconds after pulling prey in to gib them.
//=========================================================
// Monster's Anim Events Go Here
//=========================================================
#define BARNACLE_AE_PUKEGIB 2
class CBarnacle : public CBaseMonster
{
public:
void Spawn( void );
void Precache( void );
9 years ago
CBaseEntity *TongueTouchEnt( float *pflLength );
int Classify( void );
9 years ago
void HandleAnimEvent( MonsterEvent_t *pEvent );
9 years ago
void EXPORT BarnacleThink( void );
void EXPORT WaitTillDead( void );
9 years ago
void Killed( entvars_t *pevAttacker, int iGib );
int TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType );
9 years ago
virtual int Save( CSave &save );
virtual int Restore( CRestore &restore );
static TYPEDESCRIPTION m_SaveData[];
9 years ago
float m_flAltitude;
float m_flCachedLength; // tongue cached length
float m_flKillVictimTime;
9 years ago
int m_cGibs; // barnacle loads up on gibs each time it kills something.
BOOL m_fTongueExtended;
BOOL m_fLiftingPrey;
9 years ago
float m_flTongueAdj;
BOOL m_fXenCandySpawned;
9 years ago
// FIXME: need a custom barnacle model with non-generic hitgroup
// otherwise we can apply to damage to tongue instead of body
#ifdef BARNACLE_FIX_VISIBILITY
void SetObjectCollisionBox( void )
{
pev->absmin = pev->origin + Vector( -16, -16, -m_flCachedLength );
pev->absmax = pev->origin + Vector( 16, 16, 0 );
}
#endif
};
LINK_ENTITY_TO_CLASS( monster_barnacle, CBarnacle )
9 years ago
9 years ago
TYPEDESCRIPTION CBarnacle::m_SaveData[] =
9 years ago
{
DEFINE_FIELD( CBarnacle, m_flAltitude, FIELD_FLOAT ),
DEFINE_FIELD( CBarnacle, m_flKillVictimTime, FIELD_TIME ),
DEFINE_FIELD( CBarnacle, m_cGibs, FIELD_INTEGER ),// barnacle loads up on gibs each time it kills something.
DEFINE_FIELD( CBarnacle, m_fTongueExtended, FIELD_BOOLEAN ),
DEFINE_FIELD( CBarnacle, m_fLiftingPrey, FIELD_BOOLEAN ),
DEFINE_FIELD( CBarnacle, m_flTongueAdj, FIELD_FLOAT ),
DEFINE_FIELD( CBarnacle, m_flCachedLength, FIELD_FLOAT ),
DEFINE_FIELD( CBarnacle, m_fXenCandySpawned, FIELD_BOOLEAN ),
9 years ago
};
IMPLEMENT_SAVERESTORE( CBarnacle, CBaseMonster )
9 years ago
//=========================================================
// Classify - indicates this monster's place in the
// relationship table.
//=========================================================
9 years ago
int CBarnacle::Classify( void )
9 years ago
{
9 years ago
return CLASS_ALIEN_MONSTER;
9 years ago
}
//=========================================================
// HandleAnimEvent - catches the monster-specific messages
// that occur when tagged animation frames are played.
//
// Returns number of events handled, 0 if none.
//=========================================================
9 years ago
void CBarnacle::HandleAnimEvent( MonsterEvent_t *pEvent )
9 years ago
{
switch( pEvent->event )
{
case BARNACLE_AE_PUKEGIB:
CGib::SpawnRandomGibs( pev, 1, 1 );
if( ( pev->spawnflags & SF_BARNACLE_SPAWN_XENCANDY ) && !m_fXenCandySpawned )
{
Vector vecSrc = pev->origin + Vector( 0, 0, -16 );
Vector vecAngles = pev->angles;
vecAngles.x = vecAngles.z = 0;
vecAngles.y = RANDOM_LONG(0, 36) * 10;
CBaseEntity*pItem = DropItem( "ammo_xencandy", vecSrc, vecAngles );
if( pItem )
{
pItem->pev->owner = edict();
m_fXenCandySpawned = TRUE;
}
}
9 years ago
break;
default:
CBaseMonster::HandleAnimEvent( pEvent );
break;
}
}
//=========================================================
// Spawn
//=========================================================
9 years ago
void CBarnacle::Spawn()
9 years ago
{
9 years ago
Precache();
SET_MODEL( ENT( pev ), "models/barnacle.mdl" );
UTIL_SetSize( pev, Vector( -16, -16, -32 ), Vector( 16, 16, 0 ) );
pev->solid = SOLID_SLIDEBOX;
pev->movetype = MOVETYPE_NONE;
pev->takedamage = DAMAGE_AIM;
m_bloodColor = BLOOD_COLOR_RED;
pev->effects = EF_INVLIGHT; // take light from the ceiling
pev->health = 25;
m_flFieldOfView = 0.5;// indicates the width of this monster's forward view cone ( as a dotproduct result )
m_MonsterState = MONSTERSTATE_NONE;
m_flKillVictimTime = 0;
9 years ago
m_flCachedLength = 32; // mins.z
9 years ago
m_cGibs = 0;
m_fLiftingPrey = FALSE;
m_flTongueAdj = -100;
9 years ago
InitBoneControllers();
9 years ago
SetActivity( ACT_IDLE );
9 years ago
SetThink( &CBarnacle::BarnacleThink );
pev->nextthink = gpGlobals->time + 0.5;
9 years ago
UTIL_SetOrigin( pev, pev->origin );
m_fXenCandySpawned = FALSE;
9 years ago
}
int CBarnacle::TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType )
{
9 years ago
if( bitsDamageType & DMG_CLUB )
9 years ago
{
flDamage = pev->health;
}
return CBaseMonster::TakeDamage( pevInflictor, pevAttacker, flDamage, bitsDamageType );
}
//=========================================================
//=========================================================
9 years ago
void CBarnacle::BarnacleThink( void )
9 years ago
{
CBaseEntity *pTouchEnt;
CBaseMonster *pVictim;
float flLength;
#ifdef BARNACLE_FIX_VISIBILITY
9 years ago
if( m_flCachedLength != ( m_flAltitude + m_flTongueAdj ) || ( pev->absmin.z != pev->origin.z + -m_flCachedLength ) )
9 years ago
{
// recalc collision box here to avoid barnacle disappears bug
9 years ago
m_flCachedLength = m_flAltitude + m_flTongueAdj;
9 years ago
UTIL_SetOrigin( pev, pev->origin );
}
#endif
pev->nextthink = gpGlobals->time + 0.1;
if( m_hEnemy != 0 )
9 years ago
{
// barnacle has prey.
9 years ago
if( !m_hEnemy->IsAlive() )
9 years ago
{
// someone (maybe even the barnacle) killed the prey. Reset barnacle.
m_fLiftingPrey = FALSE;// indicate that we're not lifting prey.
m_hEnemy = NULL;
return;
}
9 years ago
if( m_fLiftingPrey )
9 years ago
{
if( m_hEnemy != 0 && m_hEnemy->pev->deadflag != DEAD_NO )
9 years ago
{
// crap, someone killed the prey on the way up.
m_hEnemy = NULL;
m_fLiftingPrey = FALSE;
return;
}
// still pulling prey.
9 years ago
Vector vecNewEnemyOrigin = m_hEnemy->pev->origin;
vecNewEnemyOrigin.x = pev->origin.x;
vecNewEnemyOrigin.y = pev->origin.y;
// guess as to where their neck is
9 years ago
vecNewEnemyOrigin.x -= 6 * cos( m_hEnemy->pev->angles.y * M_PI / 180.0 );
vecNewEnemyOrigin.y -= 6 * sin( m_hEnemy->pev->angles.y * M_PI / 180.0 );
9 years ago
m_flAltitude -= BARNACLE_PULL_SPEED;
vecNewEnemyOrigin.z += BARNACLE_PULL_SPEED;
9 years ago
if( fabs( pev->origin.z - ( vecNewEnemyOrigin.z + m_hEnemy->pev->view_ofs.z - 8 ) ) < BARNACLE_BODY_HEIGHT )
9 years ago
{
// prey has just been lifted into position ( if the victim origin + eye height + 8 is higher than the bottom of the barnacle, it is assumed that the head is within barnacle's body )
9 years ago
m_fLiftingPrey = FALSE;
9 years ago
EMIT_SOUND( ENT( pev ), CHAN_WEAPON, "barnacle/bcl_bite3.wav", 1, ATTN_NORM );
9 years ago
pVictim = m_hEnemy->MyMonsterPointer();
m_flKillVictimTime = gpGlobals->time + 10;// now that the victim is in place, the killing bite will be administered in 10 seconds.
9 years ago
if( pVictim )
9 years ago
{
pVictim->BarnacleVictimBitten( pev );
9 years ago
SetActivity( ACT_EAT );
9 years ago
}
}
9 years ago
UTIL_SetOrigin( m_hEnemy->pev, vecNewEnemyOrigin );
9 years ago
}
else
{
// prey is lifted fully into feeding position and is dangling there.
9 years ago
pVictim = m_hEnemy->MyMonsterPointer();
9 years ago
if( m_flKillVictimTime != -1 && gpGlobals->time > m_flKillVictimTime )
9 years ago
{
// kill!
9 years ago
if( pVictim )
9 years ago
{
9 years ago
pVictim->TakeDamage( pev, pev, pVictim->pev->health, DMG_SLASH | DMG_ALWAYSGIB );
9 years ago
m_cGibs = 3;
}
return;
}
// bite prey every once in a while
9 years ago
if( pVictim && ( RANDOM_LONG( 0, 49 ) == 0 ) )
9 years ago
{
9 years ago
switch( RANDOM_LONG( 0, 2 ) )
9 years ago
{
9 years ago
case 0:
EMIT_SOUND( ENT( pev ), CHAN_WEAPON, "barnacle/bcl_chew1.wav", 1, ATTN_NORM );
break;
case 1:
EMIT_SOUND( ENT( pev ), CHAN_WEAPON, "barnacle/bcl_chew2.wav", 1, ATTN_NORM );
break;
case 2:
EMIT_SOUND( ENT( pev ), CHAN_WEAPON, "barnacle/bcl_chew3.wav", 1, ATTN_NORM );
break;
9 years ago
}
pVictim->BarnacleVictimBitten( pev );
}
}
}
else
{
// barnacle has no prey right now, so just idle and check to see if anything is touching the tongue.
9 years ago
// If idle and no nearby client, don't think so often
9 years ago
if( FNullEnt( FIND_CLIENT_IN_PVS( edict() ) ) )
pev->nextthink = gpGlobals->time + RANDOM_FLOAT( 1, 1.5 ); // Stagger a bit to keep barnacles from thinking on the same frame
9 years ago
9 years ago
if( m_fSequenceFinished )
{
// this is done so barnacle will fidget.
9 years ago
SetActivity ( ACT_IDLE );
m_flTongueAdj = -100;
}
9 years ago
if( m_cGibs && RANDOM_LONG( 0, 99 ) == 1 )
9 years ago
{
// cough up a gib.
CGib::SpawnRandomGibs( pev, 1, 1 );
m_cGibs--;
9 years ago
switch ( RANDOM_LONG( 0, 2 ) )
9 years ago
{
9 years ago
case 0:
EMIT_SOUND( ENT( pev ), CHAN_WEAPON, "barnacle/bcl_chew1.wav", 1, ATTN_NORM );
break;
case 1:
EMIT_SOUND( ENT( pev ), CHAN_WEAPON, "barnacle/bcl_chew2.wav", 1, ATTN_NORM );
break;
case 2:
EMIT_SOUND( ENT( pev ), CHAN_WEAPON, "barnacle/bcl_chew3.wav", 1, ATTN_NORM );
break;
9 years ago
}
}
pTouchEnt = TongueTouchEnt( &flLength );
9 years ago
if( pTouchEnt != NULL && m_fTongueExtended )
9 years ago
{
// tongue is fully extended, and is touching someone.
9 years ago
if( pTouchEnt->FBecomeProne() )
9 years ago
{
9 years ago
EMIT_SOUND( ENT( pev ), CHAN_WEAPON, "barnacle/bcl_alert2.wav", 1, ATTN_NORM );
9 years ago
9 years ago
SetSequenceByName( "attack1" );
9 years ago
m_flTongueAdj = -20;
m_hEnemy = pTouchEnt;
pTouchEnt->pev->movetype = MOVETYPE_FLY;
pTouchEnt->pev->velocity = g_vecZero;
pTouchEnt->pev->basevelocity = g_vecZero;
pTouchEnt->pev->origin.x = pev->origin.x;
pTouchEnt->pev->origin.y = pev->origin.y;
m_fLiftingPrey = TRUE;// indicate that we should be lifting prey.
m_flKillVictimTime = -1;// set this to a bogus time while the victim is lifted.
9 years ago
m_flAltitude = pev->origin.z - pTouchEnt->EyePosition().z;
9 years ago
}
}
else
{
// calculate a new length for the tongue to be clear of anything else that moves under it.
9 years ago
if( m_flAltitude < flLength )
9 years ago
{
// if tongue is higher than is should be, lower it kind of slowly.
m_flAltitude += BARNACLE_PULL_SPEED;
m_fTongueExtended = FALSE;
}
else
{
m_flAltitude = flLength;
m_fTongueExtended = TRUE;
}
}
}
// ALERT( at_console, "tounge %f\n", m_flAltitude + m_flTongueAdj );
9 years ago
SetBoneController( 0, -( m_flAltitude + m_flTongueAdj ) );
9 years ago
StudioFrameAdvance( 0.1 );
}
//=========================================================
// Killed.
//=========================================================
9 years ago
void CBarnacle::Killed( entvars_t *pevAttacker, int iGib )
9 years ago
{
CBaseMonster *pVictim;
pev->solid = SOLID_NOT;
pev->takedamage = DAMAGE_NO;
if( m_hEnemy != 0 )
9 years ago
{
pVictim = m_hEnemy->MyMonsterPointer();
9 years ago
if( pVictim )
9 years ago
{
pVictim->BarnacleVictimReleased();
}
}
9 years ago
//CGib::SpawnRandomGibs( pev, 4, 1 );
9 years ago
9 years ago
switch( RANDOM_LONG ( 0, 1 ) )
9 years ago
{
9 years ago
case 0:
EMIT_SOUND( ENT( pev ), CHAN_WEAPON, "barnacle/bcl_die1.wav", 1, ATTN_NORM );
break;
case 1:
EMIT_SOUND( ENT( pev ), CHAN_WEAPON, "barnacle/bcl_die3.wav", 1, ATTN_NORM );
break;
9 years ago
}
9 years ago
SetActivity( ACT_DIESIMPLE );
9 years ago
SetBoneController( 0, 0 );
StudioFrameAdvance( 0.1 );
pev->nextthink = gpGlobals->time + 0.1;
SetThink( &CBarnacle::WaitTillDead );
}
//=========================================================
//=========================================================
9 years ago
void CBarnacle::WaitTillDead( void )
9 years ago
{
pev->nextthink = gpGlobals->time + 0.1;
float flInterval = StudioFrameAdvance( 0.1 );
9 years ago
DispatchAnimEvents( flInterval );
9 years ago
9 years ago
if( m_fSequenceFinished )
9 years ago
{
// death anim finished.
StopAnimation();
SetThink( NULL );
}
}
//=========================================================
// Precache - precaches all resources this monster needs
//=========================================================
9 years ago
void CBarnacle::Precache()
9 years ago
{
9 years ago
PRECACHE_MODEL( "models/barnacle.mdl" );
PRECACHE_SOUND( "barnacle/bcl_alert2.wav" );//happy, lifting food up
PRECACHE_SOUND( "barnacle/bcl_bite3.wav" );//just got food to mouth
PRECACHE_SOUND( "barnacle/bcl_chew1.wav" );
PRECACHE_SOUND( "barnacle/bcl_chew2.wav" );
PRECACHE_SOUND( "barnacle/bcl_chew3.wav" );
PRECACHE_SOUND( "barnacle/bcl_die1.wav" );
PRECACHE_SOUND( "barnacle/bcl_die3.wav" );
UTIL_PrecacheOther( "ammo_xencandy" );
}
9 years ago
//=========================================================
// TongueTouchEnt - does a trace along the barnacle's tongue
// to see if any entity is touching it. Also stores the length
// of the trace in the int pointer provided.
//=========================================================
#define BARNACLE_CHECK_SPACING 8
9 years ago
CBaseEntity *CBarnacle::TongueTouchEnt( float *pflLength )
9 years ago
{
9 years ago
TraceResult tr;
float length;
9 years ago
// trace once to hit architecture and see if the tongue needs to change position.
9 years ago
UTIL_TraceLine( pev->origin, pev->origin - Vector ( 0, 0, 2048 ), ignore_monsters, ENT( pev ), &tr );
9 years ago
length = fabs( pev->origin.z - tr.vecEndPos.z );
9 years ago
if( pflLength )
9 years ago
{
*pflLength = length;
}
Vector delta = Vector( BARNACLE_CHECK_SPACING, BARNACLE_CHECK_SPACING, 0 );
Vector mins = pev->origin - delta;
Vector maxs = pev->origin + delta;
maxs.z = pev->origin.z;
mins.z -= length;
CBaseEntity *pList[10];
9 years ago
int count = UTIL_EntitiesInBox( pList, 10, mins, maxs, ( FL_CLIENT | FL_MONSTER ) );
if( count )
9 years ago
{
9 years ago
for( int i = 0; i < count; i++ )
9 years ago
{
// only clients and monsters
9 years ago
if( pList[i] != this && IRelationship( pList[i] ) > R_NO && pList[ i ]->pev->deadflag == DEAD_NO ) // this ent is one of our enemies. Barnacle tries to eat it.
9 years ago
{
return pList[i];
}
}
}
return NULL;
}