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.

466 lines
13 KiB

7 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 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 );
8 years ago
CBaseEntity *TongueTouchEnt( float *pflLength );
int Classify( void );
7 years ago
void HandleAnimEvent( MonsterEvent_t *pEvent );
8 years ago
void EXPORT BarnacleThink( void );
void EXPORT WaitTillDead( void );
7 years ago
void Killed( entvars_t *pevAttacker, int iGib );
int TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType );
8 years ago
virtual int Save( CSave &save );
virtual int Restore( CRestore &restore );
static TYPEDESCRIPTION m_SaveData[];
7 years ago
float m_flAltitude;
9 years ago
float m_flCachedLength; // tongue cached length
7 years ago
float m_flKillVictimTime;
8 years ago
int m_cGibs; // barnacle loads up on gibs each time it kills something.
BOOL m_fTongueExtended;
BOOL m_fLiftingPrey;
7 years ago
float m_flTongueAdj;
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
7 years ago
};
LINK_ENTITY_TO_CLASS( monster_barnacle, CBarnacle )
9 years ago
8 years ago
TYPEDESCRIPTION CBarnacle::m_SaveData[] =
7 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 ),
9 years ago
DEFINE_FIELD( CBarnacle, m_flCachedLength, FIELD_FLOAT ),
7 years ago
};
IMPLEMENT_SAVERESTORE( CBarnacle, CBaseMonster )
7 years ago
//=========================================================
// Classify - indicates this monster's place in the
// relationship table.
//=========================================================
8 years ago
int CBarnacle::Classify( void )
7 years ago
{
return m_iClass?m_iClass:CLASS_ALIEN_MONSTER;
}
//=========================================================
// HandleAnimEvent - catches the monster-specific messages
// that occur when tagged animation frames are played.
//
// Returns number of events handled, 0 if none.
//=========================================================
8 years ago
void CBarnacle::HandleAnimEvent( MonsterEvent_t *pEvent )
7 years ago
{
switch( pEvent->event )
{
case BARNACLE_AE_PUKEGIB:
CGib::SpawnRandomGibs( pev, 1, 1 );
break;
default:
CBaseMonster::HandleAnimEvent( pEvent );
break;
}
}
//=========================================================
// Spawn
//=========================================================
8 years ago
void CBarnacle::Spawn()
7 years ago
{
8 years ago
Precache();
7 years ago
if (pev->model)
SET_MODEL(ENT(pev), STRING(pev->model)); //LRC
else
SET_MODEL( ENT( pev ), "models/mouth_monster.mdl" );
8 years ago
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 = DONT_BLEED;
8 years ago
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
8 years ago
m_cGibs = 0;
m_fLiftingPrey = FALSE;
m_flTongueAdj = -100;
7 years ago
InitBoneControllers();
8 years ago
SetActivity( ACT_IDLE );
7 years ago
9 years ago
SetThink( &CBarnacle::BarnacleThink );
7 years ago
SetNextThink( 0.5 );
UTIL_SetOrigin ( this, pev->origin );
}
int CBarnacle::TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType )
{
8 years ago
if( bitsDamageType & DMG_CLUB )
7 years ago
{
flDamage = pev->health;
}
return CBaseMonster::TakeDamage( pevInflictor, pevAttacker, flDamage, bitsDamageType );
}
//=========================================================
//=========================================================
8 years ago
void CBarnacle::BarnacleThink( void )
7 years ago
{
CBaseEntity *pTouchEnt;
CBaseMonster *pVictim;
float flLength;
9 years ago
#ifdef BARNACLE_FIX_VISIBILITY
8 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
8 years ago
m_flCachedLength = m_flAltitude + m_flTongueAdj;
9 years ago
UTIL_SetOrigin( pev, pev->origin );
}
#endif
7 years ago
SetNextThink( 0.1 );
if( m_hEnemy != 0 )
7 years ago
{
// barnacle has prey.
8 years ago
if( !m_hEnemy->IsAlive() )
7 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;
}
8 years ago
if( m_fLiftingPrey )
7 years ago
{
if( m_hEnemy != 0 && m_hEnemy->pev->deadflag != DEAD_NO )
7 years ago
{
// crap, someone killed the prey on the way up.
m_hEnemy = NULL;
m_fLiftingPrey = FALSE;
return;
}
// still pulling prey.
7 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
8 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 );
7 years ago
m_flAltitude -= BARNACLE_PULL_SPEED;
vecNewEnemyOrigin.z += BARNACLE_PULL_SPEED;
8 years ago
if( fabs( pev->origin.z - ( vecNewEnemyOrigin.z + m_hEnemy->pev->view_ofs.z - 8 ) ) < BARNACLE_BODY_HEIGHT )
7 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 )
7 years ago
m_fLiftingPrey = FALSE;
8 years ago
EMIT_SOUND( ENT( pev ), CHAN_WEAPON, "barnacle/bcl_bite3.wav", 1, ATTN_NORM );
7 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.
8 years ago
if( pVictim )
7 years ago
{
pVictim->BarnacleVictimBitten( pev );
8 years ago
SetActivity( ACT_EAT );
7 years ago
}
}
UTIL_SetOrigin ( m_hEnemy, vecNewEnemyOrigin );
}
else
{
// prey is lifted fully into feeding position and is dangling there.
7 years ago
pVictim = m_hEnemy->MyMonsterPointer();
8 years ago
if( m_flKillVictimTime != -1 && gpGlobals->time > m_flKillVictimTime )
7 years ago
{
// kill!
8 years ago
if( pVictim )
7 years ago
{
8 years ago
pVictim->TakeDamage( pev, pev, pVictim->pev->health, DMG_SLASH | DMG_ALWAYSGIB );
7 years ago
m_cGibs = 3;
}
return;
}
// bite prey every once in a while
8 years ago
if( pVictim && ( RANDOM_LONG( 0, 49 ) == 0 ) )
7 years ago
{
8 years ago
switch( RANDOM_LONG( 0, 2 ) )
7 years ago
{
8 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;
7 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.
7 years ago
// If idle and no nearby client, don't think so often
8 years ago
if( FNullEnt( FIND_CLIENT_IN_PVS( edict() ) ) )
7 years ago
SetNextThink( RANDOM_FLOAT(1,1.5) ); // Stagger a bit to keep barnacles from thinking on the same frame
8 years ago
if( m_fSequenceFinished )
{
// this is done so barnacle will fidget.
7 years ago
SetActivity ( ACT_IDLE );
m_flTongueAdj = -100;
}
8 years ago
if( m_cGibs && RANDOM_LONG( 0, 99 ) == 1 )
7 years ago
{
// cough up a gib.
CGib::SpawnRandomGibs( pev, 1, 1 );
m_cGibs--;
8 years ago
switch ( RANDOM_LONG( 0, 2 ) )
7 years ago
{
8 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;
7 years ago
}
}
pTouchEnt = TongueTouchEnt( &flLength );
8 years ago
if( pTouchEnt != NULL && m_fTongueExtended )
7 years ago
{
// tongue is fully extended, and is touching someone.
8 years ago
if( pTouchEnt->FBecomeProne() )
7 years ago
{
8 years ago
EMIT_SOUND( ENT( pev ), CHAN_WEAPON, "barnacle/bcl_alert2.wav", 1, ATTN_NORM );
7 years ago
8 years ago
SetSequenceByName( "attack1" );
7 years ago
m_flTongueAdj = -20;
m_hEnemy = pTouchEnt;
pTouchEnt->pev->movetype = MOVETYPE_FLY;
pTouchEnt->pev->velocity = pev->velocity; //LRC- make him come _with_ me
pTouchEnt->pev->basevelocity = pev->velocity; //LRC
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.
8 years ago
m_flAltitude = pev->origin.z - pTouchEnt->EyePosition().z;
7 years ago
}
}
else
{
// calculate a new length for the tongue to be clear of anything else that moves under it.
8 years ago
if( m_flAltitude < flLength )
7 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 );
8 years ago
SetBoneController( 0, -( m_flAltitude + m_flTongueAdj ) );
7 years ago
StudioFrameAdvance( 0.1 );
}
//=========================================================
// Killed.
//=========================================================
8 years ago
void CBarnacle::Killed( entvars_t *pevAttacker, int iGib )
7 years ago
{
CBaseMonster *pVictim;
pev->solid = SOLID_NOT;
pev->takedamage = DAMAGE_NO;
if( m_hEnemy != 0 )
7 years ago
{
pVictim = m_hEnemy->MyMonsterPointer();
8 years ago
if( pVictim )
7 years ago
{
pVictim->BarnacleVictimReleased();
}
}
8 years ago
//CGib::SpawnRandomGibs( pev, 4, 1 );
7 years ago
8 years ago
switch( RANDOM_LONG ( 0, 1 ) )
7 years ago
{
8 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;
7 years ago
}
8 years ago
SetActivity( ACT_DIESIMPLE );
7 years ago
SetBoneController( 0, 0 );
StudioFrameAdvance( 0.1 );
SetNextThink( 0.1 );
9 years ago
SetThink( &CBarnacle::WaitTillDead );
7 years ago
}
//=========================================================
//=========================================================
8 years ago
void CBarnacle::WaitTillDead( void )
7 years ago
{
SetNextThink( 0.1 );
float flInterval = StudioFrameAdvance( 0.1 );
8 years ago
DispatchAnimEvents( flInterval );
7 years ago
8 years ago
if( m_fSequenceFinished )
7 years ago
{
// death anim finished.
StopAnimation();
9 years ago
SetThink( NULL );
7 years ago
}
}
//=========================================================
// Precache - precaches all resources this monster needs
//=========================================================
8 years ago
void CBarnacle::Precache()
7 years ago
{
if (pev->model)
PRECACHE_MODEL(STRING(pev->model)); //LRC
7 years ago
else
PRECACHE_MODEL( "models/mouth_monster.mdl" );
8 years ago
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" );
7 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
8 years ago
CBaseEntity *CBarnacle::TongueTouchEnt( float *pflLength )
7 years ago
{
8 years ago
TraceResult tr;
float length;
7 years ago
// trace once to hit architecture and see if the tongue needs to change position.
8 years ago
UTIL_TraceLine( pev->origin, pev->origin - Vector ( 0, 0, 2048 ), ignore_monsters, ENT( pev ), &tr );
7 years ago
length = fabs( pev->origin.z - tr.vecEndPos.z );
8 years ago
if( pflLength )
7 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];
8 years ago
int count = UTIL_EntitiesInBox( pList, 10, mins, maxs, ( FL_CLIENT | FL_MONSTER ) );
if( count )
7 years ago
{
8 years ago
for( int i = 0; i < count; i++ )
7 years ago
{
// only clients and monsters
8 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.
7 years ago
{
return pList[i];
}
}
}
return NULL;
}