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.

557 lines
13 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.
*
****/
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "animation.h"
#include "effects.h"
#define XEN_PLANT_GLOW_SPRITE "sprites/flare3.spr"
#define XEN_PLANT_HIDE_TIME 5
class CActAnimating : public CBaseAnimating
{
public:
8 years ago
void SetActivity( Activity act );
9 years ago
inline Activity GetActivity( void ) { return m_Activity; }
8 years ago
virtual int ObjectCaps( void ) { return CBaseAnimating::ObjectCaps() & ~FCAP_ACROSS_TRANSITION; }
9 years ago
8 years ago
virtual int Save( CSave &save );
virtual int Restore( CRestore &restore );
static TYPEDESCRIPTION m_SaveData[];
9 years ago
private:
8 years ago
Activity m_Activity;
9 years ago
};
TYPEDESCRIPTION CActAnimating::m_SaveData[] =
9 years ago
{
DEFINE_FIELD( CActAnimating, m_Activity, FIELD_INTEGER ),
};
IMPLEMENT_SAVERESTORE( CActAnimating, CBaseAnimating )
9 years ago
8 years ago
void CActAnimating::SetActivity( Activity act )
{
9 years ago
int sequence = LookupActivity( act );
8 years ago
if( sequence != ACTIVITY_NOT_AVAILABLE )
9 years ago
{
pev->sequence = sequence;
m_Activity = act;
pev->frame = 0;
8 years ago
ResetSequenceInfo();
9 years ago
}
}
class CXenPLight : public CActAnimating
{
public:
8 years ago
void Spawn( void );
void Precache( void );
void Touch( CBaseEntity *pOther );
void Think( void );
9 years ago
8 years ago
void LightOn( void );
void LightOff( void );
9 years ago
8 years ago
virtual int Save( CSave &save );
virtual int Restore( CRestore &restore );
static TYPEDESCRIPTION m_SaveData[];
9 years ago
private:
8 years ago
CSprite *m_pGlow;
9 years ago
};
LINK_ENTITY_TO_CLASS( xen_plantlight, CXenPLight )
9 years ago
TYPEDESCRIPTION CXenPLight::m_SaveData[] =
9 years ago
{
DEFINE_FIELD( CXenPLight, m_pGlow, FIELD_CLASSPTR ),
};
IMPLEMENT_SAVERESTORE( CXenPLight, CActAnimating )
9 years ago
8 years ago
void CXenPLight::Spawn( void )
9 years ago
{
Precache();
8 years ago
SET_MODEL( ENT( pev ), "models/light.mdl" );
pev->movetype = MOVETYPE_NONE;
pev->solid = SOLID_TRIGGER;
9 years ago
8 years ago
UTIL_SetSize( pev, Vector( -80, -80, 0 ), Vector( 80, 80, 32 ) );
9 years ago
SetActivity( ACT_IDLE );
pev->nextthink = gpGlobals->time + 0.1f;
8 years ago
pev->frame = RANDOM_FLOAT( 0, 255 );
9 years ago
m_pGlow = CSprite::SpriteCreate( XEN_PLANT_GLOW_SPRITE, pev->origin + Vector( 0, 0, ( pev->mins.z + pev->maxs.z ) * 0.5f ), FALSE );
m_pGlow->SetTransparency( kRenderGlow, (int)pev->rendercolor.x, (int)pev->rendercolor.y, (int)pev->rendercolor.z, (int)pev->renderamt, (int)pev->renderfx );
9 years ago
m_pGlow->SetAttachment( edict(), 1 );
}
8 years ago
void CXenPLight::Precache( void )
9 years ago
{
PRECACHE_MODEL( "models/light.mdl" );
PRECACHE_MODEL( XEN_PLANT_GLOW_SPRITE );
}
8 years ago
void CXenPLight::Think( void )
9 years ago
{
StudioFrameAdvance();
pev->nextthink = gpGlobals->time + 0.1f;
9 years ago
switch( GetActivity() )
{
case ACT_CROUCH:
8 years ago
if( m_fSequenceFinished )
9 years ago
{
SetActivity( ACT_CROUCHIDLE );
LightOff();
}
break;
case ACT_CROUCHIDLE:
8 years ago
if( gpGlobals->time > pev->dmgtime )
9 years ago
{
SetActivity( ACT_STAND );
LightOn();
}
break;
case ACT_STAND:
8 years ago
if( m_fSequenceFinished )
9 years ago
SetActivity( ACT_IDLE );
break;
case ACT_IDLE:
default:
break;
}
}
8 years ago
void CXenPLight::Touch( CBaseEntity *pOther )
9 years ago
{
8 years ago
if( pOther->IsPlayer() )
9 years ago
{
pev->dmgtime = gpGlobals->time + XEN_PLANT_HIDE_TIME;
8 years ago
if( GetActivity() == ACT_IDLE || GetActivity() == ACT_STAND )
9 years ago
{
SetActivity( ACT_CROUCH );
}
}
}
8 years ago
void CXenPLight::LightOn( void )
9 years ago
{
SUB_UseTargets( this, USE_ON, 0 );
8 years ago
if( m_pGlow )
9 years ago
m_pGlow->pev->effects &= ~EF_NODRAW;
}
8 years ago
void CXenPLight::LightOff( void )
9 years ago
{
SUB_UseTargets( this, USE_OFF, 0 );
8 years ago
if( m_pGlow )
9 years ago
m_pGlow->pev->effects |= EF_NODRAW;
}
class CXenHair : public CActAnimating
{
public:
8 years ago
void Spawn( void );
void Precache( void );
void Think( void );
9 years ago
};
LINK_ENTITY_TO_CLASS( xen_hair, CXenHair )
9 years ago
#define SF_HAIR_SYNC 0x0001
void CXenHair::Spawn( void )
{
Precache();
SET_MODEL( edict(), "models/hair.mdl" );
8 years ago
UTIL_SetSize( pev, Vector( -4, -4, 0 ), Vector( 4, 4, 32 ) );
9 years ago
pev->sequence = 0;
8 years ago
if( !( pev->spawnflags & SF_HAIR_SYNC ) )
9 years ago
{
8 years ago
pev->frame = RANDOM_FLOAT( 0, 255 );
pev->framerate = RANDOM_FLOAT( 0.7f, 1.4f );
9 years ago
}
8 years ago
ResetSequenceInfo();
9 years ago
pev->solid = SOLID_NOT;
pev->movetype = MOVETYPE_NONE;
pev->nextthink = gpGlobals->time + RANDOM_FLOAT( 0.1f, 0.4f ); // Load balance these a bit
9 years ago
}
void CXenHair::Think( void )
{
StudioFrameAdvance();
pev->nextthink = gpGlobals->time + 0.5f;
9 years ago
}
void CXenHair::Precache( void )
{
PRECACHE_MODEL( "models/hair.mdl" );
}
class CXenTreeTrigger : public CBaseEntity
{
public:
8 years ago
void Touch( CBaseEntity *pOther );
9 years ago
static CXenTreeTrigger *TriggerCreate( edict_t *pOwner, const Vector &position );
};
LINK_ENTITY_TO_CLASS( xen_ttrigger, CXenTreeTrigger )
9 years ago
8 years ago
CXenTreeTrigger *CXenTreeTrigger::TriggerCreate( edict_t *pOwner, const Vector &position )
9 years ago
{
CXenTreeTrigger *pTrigger = GetClassPtr( (CXenTreeTrigger *)NULL );
pTrigger->pev->origin = position;
8 years ago
pTrigger->pev->classname = MAKE_STRING( "xen_ttrigger" );
9 years ago
pTrigger->pev->solid = SOLID_TRIGGER;
pTrigger->pev->movetype = MOVETYPE_NONE;
pTrigger->pev->owner = pOwner;
return pTrigger;
}
void CXenTreeTrigger::Touch( CBaseEntity *pOther )
{
8 years ago
if( pev->owner )
9 years ago
{
8 years ago
CBaseEntity *pEntity = CBaseEntity::Instance( pev->owner );
if( pEntity )
{
pEntity->Touch( pOther );
return;
}
9 years ago
}
pev->flags |= FL_KILLME;
9 years ago
}
#define TREE_AE_ATTACK 1
class CXenTree : public CActAnimating
{
public:
8 years ago
void Spawn( void );
void Precache( void );
void Touch( CBaseEntity *pOther );
void Think( void );
int TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType ) { Attack(); return 0; }
void HandleAnimEvent( MonsterEvent_t *pEvent );
void Attack( void );
int Classify( void ) { return CLASS_BARNACLE; }
virtual int Save( CSave &save );
virtual int Restore( CRestore &restore );
static TYPEDESCRIPTION m_SaveData[];
9 years ago
static const char *pAttackHitSounds[];
static const char *pAttackMissSounds[];
private:
CXenTreeTrigger *m_pTrigger;
};
LINK_ENTITY_TO_CLASS( xen_tree, CXenTree )
9 years ago
TYPEDESCRIPTION CXenTree::m_SaveData[] =
9 years ago
{
DEFINE_FIELD( CXenTree, m_pTrigger, FIELD_CLASSPTR ),
};
IMPLEMENT_SAVERESTORE( CXenTree, CActAnimating )
9 years ago
8 years ago
void CXenTree::Spawn( void )
9 years ago
{
Precache();
8 years ago
SET_MODEL( ENT( pev ), "models/tree.mdl" );
pev->movetype = MOVETYPE_NONE;
pev->solid = SOLID_BBOX;
9 years ago
pev->takedamage = DAMAGE_YES;
8 years ago
UTIL_SetSize( pev, Vector( -30, -30, 0 ), Vector( 30, 30, 188 ) );
9 years ago
SetActivity( ACT_IDLE );
pev->nextthink = gpGlobals->time + 0.1f;
8 years ago
pev->frame = RANDOM_FLOAT( 0, 255 );
pev->framerate = RANDOM_FLOAT( 0.7f, 1.4f );
9 years ago
Vector triggerPosition;
UTIL_MakeVectorsPrivate( pev->angles, triggerPosition, NULL, NULL );
8 years ago
triggerPosition = pev->origin + ( triggerPosition * 64 );
9 years ago
// Create the trigger
m_pTrigger = CXenTreeTrigger::TriggerCreate( edict(), triggerPosition );
UTIL_SetSize( m_pTrigger->pev, Vector( -24, -24, 0 ), Vector( 24, 24, 128 ) );
}
const char *CXenTree::pAttackHitSounds[] =
9 years ago
{
"zombie/claw_strike1.wav",
"zombie/claw_strike2.wav",
"zombie/claw_strike3.wav",
};
const char *CXenTree::pAttackMissSounds[] =
9 years ago
{
"zombie/claw_miss1.wav",
"zombie/claw_miss2.wav",
};
8 years ago
void CXenTree::Precache( void )
9 years ago
{
PRECACHE_MODEL( "models/tree.mdl" );
PRECACHE_MODEL( XEN_PLANT_GLOW_SPRITE );
PRECACHE_SOUND_ARRAY( pAttackHitSounds );
PRECACHE_SOUND_ARRAY( pAttackMissSounds );
}
8 years ago
void CXenTree::Touch( CBaseEntity *pOther )
9 years ago
{
8 years ago
if( !pOther->IsPlayer() && FClassnameIs( pOther->pev, "monster_bigmomma" ) )
9 years ago
return;
Attack();
}
8 years ago
void CXenTree::Attack( void )
9 years ago
{
8 years ago
if( GetActivity() == ACT_IDLE )
9 years ago
{
SetActivity( ACT_MELEE_ATTACK1 );
pev->framerate = RANDOM_FLOAT( 1.0f, 1.4f );
9 years ago
EMIT_SOUND_ARRAY_DYN( CHAN_WEAPON, pAttackMissSounds );
}
}
8 years ago
void CXenTree::HandleAnimEvent( MonsterEvent_t *pEvent )
9 years ago
{
switch( pEvent->event )
{
case TREE_AE_ATTACK:
{
CBaseEntity *pList[8];
BOOL sound = FALSE;
8 years ago
int count = UTIL_EntitiesInBox( pList, 8, m_pTrigger->pev->absmin, m_pTrigger->pev->absmax, FL_MONSTER | FL_CLIENT );
9 years ago
Vector forward;
UTIL_MakeVectorsPrivate( pev->angles, forward, NULL, NULL );
8 years ago
for( int i = 0; i < count; i++ )
9 years ago
{
8 years ago
if( pList[i] != this )
9 years ago
{
8 years ago
if( pList[i]->pev->owner != edict() )
9 years ago
{
sound = TRUE;
pList[i]->TakeDamage( pev, pev, 25, DMG_CRUSH | DMG_SLASH );
pList[i]->pev->punchangle.x = 15;
pList[i]->pev->velocity = pList[i]->pev->velocity + forward * 100;
}
}
}
8 years ago
if( sound )
9 years ago
{
EMIT_SOUND_ARRAY_DYN( CHAN_WEAPON, pAttackHitSounds );
}
}
return;
}
CActAnimating::HandleAnimEvent( pEvent );
}
8 years ago
void CXenTree::Think( void )
9 years ago
{
float flInterval = StudioFrameAdvance();
pev->nextthink = gpGlobals->time + 0.1f;
9 years ago
DispatchAnimEvents( flInterval );
switch( GetActivity() )
{
case ACT_MELEE_ATTACK1:
8 years ago
if( m_fSequenceFinished )
9 years ago
{
SetActivity( ACT_IDLE );
pev->framerate = RANDOM_FLOAT( 0.6f, 1.4f );
9 years ago
}
break;
default:
case ACT_IDLE:
break;
}
}
// UNDONE: These need to smoke somehow when they take damage
// Touch behavior?
// Cause damage in smoke area
//
// Spores
//
class CXenSpore : public CActAnimating
{
public:
8 years ago
void Spawn( void );
void Precache( void );
void Touch( CBaseEntity *pOther );
void Think( void );
int TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType ) { Attack(); return 0; }
//void HandleAnimEvent( MonsterEvent_t *pEvent );
void Attack( void ) {}
9 years ago
static const char *pModelNames[];
};
class CXenSporeSmall : public CXenSpore
{
8 years ago
void Spawn( void );
9 years ago
};
class CXenSporeMed : public CXenSpore
{
8 years ago
void Spawn( void );
9 years ago
};
class CXenSporeLarge : public CXenSpore
{
8 years ago
void Spawn( void );
9 years ago
static const Vector m_hullSizes[];
};
// Fake collision box for big spores
class CXenHull : public CPointEntity
{
public:
static CXenHull *CreateHull( CBaseEntity *source, const Vector &mins, const Vector &maxs, const Vector &offset );
8 years ago
int Classify( void ) { return CLASS_BARNACLE; }
9 years ago
};
8 years ago
CXenHull *CXenHull::CreateHull( CBaseEntity *source, const Vector &mins, const Vector &maxs, const Vector &offset )
9 years ago
{
CXenHull *pHull = GetClassPtr( (CXenHull *)NULL );
UTIL_SetOrigin( pHull->pev, source->pev->origin + offset );
SET_MODEL( pHull->edict(), STRING( source->pev->model ) );
9 years ago
pHull->pev->solid = SOLID_BBOX;
pHull->pev->classname = MAKE_STRING( "xen_hull" );
9 years ago
pHull->pev->movetype = MOVETYPE_NONE;
pHull->pev->owner = source->edict();
UTIL_SetSize( pHull->pev, mins, maxs );
pHull->pev->renderamt = 0;
pHull->pev->rendermode = kRenderTransTexture;
// pHull->pev->effects = EF_NODRAW;
return pHull;
}
LINK_ENTITY_TO_CLASS( xen_spore_small, CXenSporeSmall )
LINK_ENTITY_TO_CLASS( xen_spore_medium, CXenSporeMed )
LINK_ENTITY_TO_CLASS( xen_spore_large, CXenSporeLarge )
LINK_ENTITY_TO_CLASS( xen_hull, CXenHull )
9 years ago
void CXenSporeSmall::Spawn( void )
{
pev->skin = 0;
CXenSpore::Spawn();
8 years ago
UTIL_SetSize( pev, Vector( -16, -16, 0 ), Vector( 16, 16, 64) );
9 years ago
}
9 years ago
void CXenSporeMed::Spawn( void )
{
pev->skin = 1;
CXenSpore::Spawn();
8 years ago
UTIL_SetSize( pev, Vector( -40, -40, 0 ), Vector( 40, 40, 120 ) );
9 years ago
}
// I just eyeballed these -- fill in hulls for the legs
const Vector CXenSporeLarge::m_hullSizes[] =
9 years ago
{
Vector( 90, -25, 0 ),
Vector( 25, 75, 0 ),
Vector( -15, -100, 0 ),
Vector( -90, -35, 0 ),
Vector( -90, 60, 0 ),
};
void CXenSporeLarge::Spawn( void )
{
pev->skin = 2;
CXenSpore::Spawn();
8 years ago
UTIL_SetSize( pev, Vector( -48, -48, 110 ), Vector( 48, 48, 240 ) );
9 years ago
Vector forward, right;
UTIL_MakeVectorsPrivate( pev->angles, forward, right, NULL );
// Rotate the leg hulls into position
for( int i = 0; i < (int)ARRAYSIZE( m_hullSizes ); i++ )
8 years ago
CXenHull::CreateHull( this, Vector( -12, -12, 0 ), Vector( 12, 12, 120 ), ( m_hullSizes[i].x * forward ) + ( m_hullSizes[i].y * right ) );
9 years ago
}
void CXenSpore :: Spawn( void )
{
Precache();
8 years ago
SET_MODEL( ENT( pev ), pModelNames[pev->skin] );
pev->movetype = MOVETYPE_NONE;
pev->solid = SOLID_BBOX;
9 years ago
pev->takedamage = DAMAGE_YES;
//SetActivity( ACT_IDLE );
9 years ago
pev->sequence = 0;
8 years ago
pev->frame = RANDOM_FLOAT( 0, 255 );
pev->framerate = RANDOM_FLOAT( 0.7f, 1.4f );
8 years ago
ResetSequenceInfo();
pev->nextthink = gpGlobals->time + RANDOM_FLOAT( 0.1f, 0.4f ); // Load balance these a bit
9 years ago
}
const char *CXenSpore::pModelNames[] =
9 years ago
{
"models/fungus(small).mdl",
"models/fungus.mdl",
"models/fungus(large).mdl",
};
8 years ago
void CXenSpore::Precache( void )
9 years ago
{
PRECACHE_MODEL( pModelNames[pev->skin] );
9 years ago
}
8 years ago
void CXenSpore::Touch( CBaseEntity *pOther )
9 years ago
{
}
8 years ago
void CXenSpore::Think( void )
9 years ago
{
StudioFrameAdvance();
pev->nextthink = gpGlobals->time + 0.1f;
9 years ago
#if 0
DispatchAnimEvents( flInterval );
switch( GetActivity() )
{
default:
case ACT_IDLE:
break;
}
#endif
}