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.

1250 lines
32 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 )
//=========================================================
// monster template
//=========================================================
8 years ago
9 years ago
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "monsters.h"
#include "schedule.h"
#include "decals.h"
#include "weapons.h"
#include "game.h"
7 years ago
//LRC brought in from animation.h
#define ACTIVITY_NOT_AVAILABLE -1
9 years ago
#define SF_INFOBM_RUN 0x0001
#define SF_INFOBM_WAIT 0x0002
// AI Nodes for Big Momma
class CInfoBM : public CPointEntity
{
public:
void Spawn( void );
void KeyValue( KeyValueData* pkvd );
// name in pev->targetname
// next in pev->target
// radius in pev->scale
// health in pev->health
// Reach target in pev->message
// Reach delay in pev->speed
// Reach sequence in pev->netname
8 years ago
virtual int Save( CSave &save );
virtual int Restore( CRestore &restore );
static TYPEDESCRIPTION m_SaveData[];
9 years ago
string_t m_preSequence;
9 years ago
};
LINK_ENTITY_TO_CLASS( info_bigmomma, CInfoBM )
9 years ago
8 years ago
TYPEDESCRIPTION CInfoBM::m_SaveData[] =
9 years ago
{
DEFINE_FIELD( CInfoBM, m_preSequence, FIELD_STRING ),
};
IMPLEMENT_SAVERESTORE( CInfoBM, CPointEntity )
9 years ago
void CInfoBM::Spawn( void )
{
}
void CInfoBM::KeyValue( KeyValueData* pkvd )
{
8 years ago
if( FStrEq( pkvd->szKeyName, "radius" ) )
9 years ago
{
8 years ago
pev->scale = atof( pkvd->szValue );
9 years ago
pkvd->fHandled = TRUE;
}
8 years ago
else if( FStrEq( pkvd->szKeyName, "reachdelay" ) )
9 years ago
{
8 years ago
pev->speed = atof( pkvd->szValue );
9 years ago
pkvd->fHandled = TRUE;
}
8 years ago
else if( FStrEq( pkvd->szKeyName, "reachtarget" ) )
9 years ago
{
8 years ago
pev->message = ALLOC_STRING( pkvd->szValue );
9 years ago
pkvd->fHandled = TRUE;
}
8 years ago
else if( FStrEq( pkvd->szKeyName, "reachsequence" ) )
9 years ago
{
8 years ago
pev->netname = ALLOC_STRING( pkvd->szValue );
9 years ago
pkvd->fHandled = TRUE;
}
8 years ago
else if( FStrEq( pkvd->szKeyName, "presequence" ) )
9 years ago
{
8 years ago
m_preSequence = ALLOC_STRING( pkvd->szValue );
9 years ago
pkvd->fHandled = TRUE;
}
else
CPointEntity::KeyValue( pkvd );
}
//=========================================================
// Mortar shot entity
//=========================================================
class CBMortar : public CBaseEntity
{
public:
void Spawn( void );
static CBMortar *Shoot( edict_t *pOwner, Vector vecStart, Vector vecVelocity );
void Touch( CBaseEntity *pOther );
void EXPORT Animate( void );
8 years ago
virtual int Save( CSave &save );
virtual int Restore( CRestore &restore );
static TYPEDESCRIPTION m_SaveData[];
9 years ago
8 years ago
int m_maxFrame;
9 years ago
};
LINK_ENTITY_TO_CLASS( bmortar, CBMortar )
9 years ago
8 years ago
TYPEDESCRIPTION CBMortar::m_SaveData[] =
9 years ago
{
DEFINE_FIELD( CBMortar, m_maxFrame, FIELD_INTEGER ),
};
IMPLEMENT_SAVERESTORE( CBMortar, CBaseEntity )
9 years ago
//=========================================================
// Monster's Anim Events Go Here
//=========================================================
8 years ago
#define BIG_AE_STEP1 1 // Footstep left
#define BIG_AE_STEP2 2 // Footstep right
#define BIG_AE_STEP3 3 // Footstep back left
#define BIG_AE_STEP4 4 // Footstep back right
#define BIG_AE_SACK 5 // Sack slosh
#define BIG_AE_DEATHSOUND 6 // Death sound
9 years ago
#define BIG_AE_MELEE_ATTACKBR 8 // Leg attack
#define BIG_AE_MELEE_ATTACKBL 9 // Leg attack
#define BIG_AE_MELEE_ATTACK1 10 // Leg attack
#define BIG_AE_MORTAR_ATTACK1 11 // Launch a mortar
8 years ago
#define BIG_AE_LAY_CRAB 12 // Lay a headcrab
#define BIG_AE_JUMP_FORWARD 13 // Jump up and forward
#define BIG_AE_SCREAM 14 // alert sound
#define BIG_AE_PAIN_SOUND 15 // pain sound
#define BIG_AE_ATTACK_SOUND 16 // attack sound
#define BIG_AE_BIRTH_SOUND 17 // birth sound
#define BIG_AE_EARLY_TARGET 50 // Fire target early
9 years ago
// User defined conditions
#define bits_COND_NODE_SEQUENCE ( bits_COND_SPECIAL1 ) // pev->netname contains the name of a sequence to play
// Attack distance constants
8 years ago
#define BIG_ATTACKDIST 170
#define BIG_MORTARDIST 800
#define BIG_MAXCHILDREN 20 // Max # of live headcrab children
9 years ago
8 years ago
#define bits_MEMORY_CHILDPAIR ( bits_MEMORY_CUSTOM1 )
#define bits_MEMORY_ADVANCE_NODE ( bits_MEMORY_CUSTOM2 )
#define bits_MEMORY_COMPLETED_NODE ( bits_MEMORY_CUSTOM3 )
#define bits_MEMORY_FIRED_NODE ( bits_MEMORY_CUSTOM4 )
9 years ago
int gSpitSprite, gSpitDebrisSprite;
Vector VecCheckSplatToss( entvars_t *pev, const Vector &vecSpot1, Vector vecSpot2, float maxHeight );
void MortarSpray( const Vector &position, const Vector &direction, int spriteModel, int count );
8 years ago
// UNDONE:
9 years ago
//
#define BIG_CHILDCLASS "monster_babycrab"
class CBigMomma : public CBaseMonster
{
public:
void Spawn( void );
void Precache( void );
void KeyValue( KeyValueData *pkvd );
void Activate( void );
int TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType );
8 years ago
void RunTask( Task_t *pTask );
void StartTask( Task_t *pTask );
Schedule_t *GetSchedule( void );
Schedule_t *GetScheduleOfType( int Type );
void TraceAttack( entvars_t *pevAttacker, float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType );
7 years ago
void SetActivity ( Activity NewActivity );
9 years ago
void NodeStart( int iszNextNode );
void NodeReach( void );
BOOL ShouldGoToNode( void );
void SetYawSpeed( void );
8 years ago
int Classify( void );
9 years ago
void HandleAnimEvent( MonsterEvent_t *pEvent );
void LayHeadcrab( void );
int GetNodeSequence( void )
{
CBaseEntity *pTarget = m_hTargetEnt;
8 years ago
if( pTarget )
9 years ago
{
return pTarget->pev->netname; // netname holds node sequence
}
return 0;
}
int GetNodePresequence( void )
{
CInfoBM *pTarget = (CInfoBM *)(CBaseEntity *)m_hTargetEnt;
8 years ago
if( pTarget )
9 years ago
{
return pTarget->m_preSequence;
}
return 0;
}
float GetNodeDelay( void )
{
CBaseEntity *pTarget = m_hTargetEnt;
8 years ago
if( pTarget )
9 years ago
{
return pTarget->pev->speed; // Speed holds node delay
}
return 0;
}
float GetNodeRange( void )
{
CBaseEntity *pTarget = m_hTargetEnt;
8 years ago
if( pTarget )
9 years ago
{
return pTarget->pev->scale; // Scale holds node delay
}
return 1e6;
}
float GetNodeYaw( void )
{
CBaseEntity *pTarget = m_hTargetEnt;
8 years ago
if( pTarget )
9 years ago
{
8 years ago
if( pTarget->pev->angles.y != 0 )
9 years ago
return pTarget->pev->angles.y;
}
return pev->angles.y;
}
8 years ago
9 years ago
// Restart the crab count on each new level
void OverrideReset( void )
{
m_crabCount = 0;
}
void DeathNotice( entvars_t *pevChild );
BOOL CanLayCrab( void )
{
8 years ago
if( m_crabTime < gpGlobals->time && m_crabCount < BIG_MAXCHILDREN )
9 years ago
{
// Don't spawn crabs inside each other
Vector mins = pev->origin - Vector( 32, 32, 0 );
Vector maxs = pev->origin + Vector( 32, 32, 0 );
CBaseEntity *pList[2];
int count = UTIL_EntitiesInBox( pList, 2, mins, maxs, FL_MONSTER );
8 years ago
for( int i = 0; i < count; i++ )
9 years ago
{
8 years ago
if( pList[i] != this ) // Don't hurt yourself!
9 years ago
return FALSE;
}
return TRUE;
}
return FALSE;
}
void LaunchMortar( void );
void SetObjectCollisionBox( void )
{
pev->absmin = pev->origin + Vector( -95, -95, 0 );
pev->absmax = pev->origin + Vector( 95, 95, 190 );
}
BOOL CheckMeleeAttack1( float flDot, float flDist ); // Slash
BOOL CheckMeleeAttack2( float flDot, float flDist ); // Lay a crab
BOOL CheckRangeAttack1( float flDot, float flDist ); // Mortar launch
8 years ago
virtual int Save( CSave &save );
virtual int Restore( CRestore &restore );
static TYPEDESCRIPTION m_SaveData[];
9 years ago
static const char *pChildDieSounds[];
static const char *pSackSounds[];
static const char *pDeathSounds[];
static const char *pAttackSounds[];
static const char *pAttackHitSounds[];
static const char *pBirthSounds[];
static const char *pAlertSounds[];
static const char *pPainSounds[];
static const char *pFootSounds[];
CUSTOM_SCHEDULES
9 years ago
private:
8 years ago
float m_nodeTime;
float m_crabTime;
float m_mortarTime;
float m_painSoundTime;
int m_crabCount;
9 years ago
};
LINK_ENTITY_TO_CLASS( monster_bigmomma, CBigMomma )
9 years ago
8 years ago
TYPEDESCRIPTION CBigMomma::m_SaveData[] =
9 years ago
{
DEFINE_FIELD( CBigMomma, m_nodeTime, FIELD_TIME ),
DEFINE_FIELD( CBigMomma, m_crabTime, FIELD_TIME ),
DEFINE_FIELD( CBigMomma, m_mortarTime, FIELD_TIME ),
DEFINE_FIELD( CBigMomma, m_painSoundTime, FIELD_TIME ),
DEFINE_FIELD( CBigMomma, m_crabCount, FIELD_INTEGER ),
};
IMPLEMENT_SAVERESTORE( CBigMomma, CBaseMonster )
9 years ago
8 years ago
const char *CBigMomma::pChildDieSounds[] =
9 years ago
{
"gonarch/gon_childdie1.wav",
"gonarch/gon_childdie2.wav",
"gonarch/gon_childdie3.wav",
};
8 years ago
const char *CBigMomma::pSackSounds[] =
9 years ago
{
"gonarch/gon_sack1.wav",
"gonarch/gon_sack2.wav",
"gonarch/gon_sack3.wav",
};
8 years ago
const char *CBigMomma::pDeathSounds[] =
9 years ago
{
"gonarch/gon_die1.wav",
};
const char *CBigMomma::pAttackSounds[] =
9 years ago
{
"gonarch/gon_attack1.wav",
"gonarch/gon_attack2.wav",
"gonarch/gon_attack3.wav",
};
const char *CBigMomma::pAttackHitSounds[] =
9 years ago
{
"zombie/claw_strike1.wav",
"zombie/claw_strike2.wav",
"zombie/claw_strike3.wav",
};
const char *CBigMomma::pBirthSounds[] =
9 years ago
{
"gonarch/gon_birth1.wav",
"gonarch/gon_birth2.wav",
"gonarch/gon_birth3.wav",
};
const char *CBigMomma::pAlertSounds[] =
9 years ago
{
"gonarch/gon_alert1.wav",
"gonarch/gon_alert2.wav",
"gonarch/gon_alert3.wav",
};
const char *CBigMomma::pPainSounds[] =
9 years ago
{
"gonarch/gon_pain2.wav",
"gonarch/gon_pain4.wav",
"gonarch/gon_pain5.wav",
};
const char *CBigMomma::pFootSounds[] =
9 years ago
{
"gonarch/gon_step1.wav",
"gonarch/gon_step2.wav",
"gonarch/gon_step3.wav",
};
8 years ago
void CBigMomma::KeyValue( KeyValueData *pkvd )
9 years ago
{
#if 0
8 years ago
if( FStrEq( pkvd->szKeyName, "volume" ) )
9 years ago
{
8 years ago
m_volume = atof( pkvd->szValue );
9 years ago
pkvd->fHandled = TRUE;
}
else
#endif
CBaseMonster::KeyValue( pkvd );
}
//=========================================================
// Classify - indicates this monster's place in the
// relationship table.
//=========================================================
8 years ago
int CBigMomma::Classify( void )
9 years ago
{
7 years ago
return m_iClass?m_iClass:CLASS_ALIEN_MONSTER;
9 years ago
}
//=========================================================
// SetYawSpeed - allows each sequence to have a different
// turn rate associated with it.
//=========================================================
8 years ago
void CBigMomma::SetYawSpeed( void )
9 years ago
{
int ys;
switch( m_Activity )
9 years ago
{
case ACT_IDLE:
ys = 100;
break;
default:
ys = 90;
}
pev->yaw_speed = ys;
}
//=========================================================
// 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 CBigMomma::HandleAnimEvent( MonsterEvent_t *pEvent )
9 years ago
{
switch( pEvent->event )
{
case BIG_AE_MELEE_ATTACKBR:
case BIG_AE_MELEE_ATTACKBL:
case BIG_AE_MELEE_ATTACK1:
{
Vector forward, right;
UTIL_MakeVectorsPrivate( pev->angles, forward, right, NULL );
Vector center = pev->origin + forward * 128;
Vector mins = center - Vector( 64, 64, 0 );
Vector maxs = center + Vector( 64, 64, 64 );
CBaseEntity *pList[8];
8 years ago
int count = UTIL_EntitiesInBox( pList, 8, mins, maxs, FL_MONSTER | FL_CLIENT );
9 years ago
CBaseEntity *pHurt = NULL;
8 years ago
for( int i = 0; i < count && !pHurt; 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
pHurt = pList[i];
}
}
8 years ago
if( pHurt )
9 years ago
{
pHurt->TakeDamage( pev, pev, gSkillData.bigmommaDmgSlash, DMG_CRUSH | DMG_SLASH );
pHurt->pev->punchangle.x = 15;
switch( pEvent->event )
{
case BIG_AE_MELEE_ATTACKBR:
8 years ago
pHurt->pev->velocity = pHurt->pev->velocity + ( forward * 150 ) + Vector( 0, 0, 250 ) - ( right * 200 );
break;
9 years ago
case BIG_AE_MELEE_ATTACKBL:
8 years ago
pHurt->pev->velocity = pHurt->pev->velocity + ( forward * 150 ) + Vector( 0, 0, 250 ) + ( right * 200 );
break;
9 years ago
case BIG_AE_MELEE_ATTACK1:
8 years ago
pHurt->pev->velocity = pHurt->pev->velocity + ( forward * 220 ) + Vector( 0, 0, 200 );
break;
9 years ago
}
pHurt->pev->flags &= ~FL_ONGROUND;
8 years ago
EMIT_SOUND_DYN( edict(), CHAN_WEAPON, RANDOM_SOUND_ARRAY( pAttackHitSounds ), 1.0, ATTN_NORM, 0, 100 + RANDOM_LONG( -5, 5 ) );
9 years ago
}
}
break;
case BIG_AE_SCREAM:
EMIT_SOUND_ARRAY_DYN( CHAN_VOICE, pAlertSounds );
break;
case BIG_AE_PAIN_SOUND:
EMIT_SOUND_ARRAY_DYN( CHAN_VOICE, pPainSounds );
break;
case BIG_AE_ATTACK_SOUND:
EMIT_SOUND_ARRAY_DYN( CHAN_WEAPON, pAttackSounds );
break;
case BIG_AE_BIRTH_SOUND:
EMIT_SOUND_ARRAY_DYN( CHAN_BODY, pBirthSounds );
break;
case BIG_AE_SACK:
8 years ago
if( RANDOM_LONG( 0, 100 ) < 30 )
9 years ago
EMIT_SOUND_ARRAY_DYN( CHAN_BODY, pSackSounds );
break;
case BIG_AE_DEATHSOUND:
EMIT_SOUND_ARRAY_DYN( CHAN_VOICE, pDeathSounds );
break;
case BIG_AE_STEP1: // Footstep left
case BIG_AE_STEP3: // Footstep back left
EMIT_SOUND_ARRAY_DYN( CHAN_ITEM, pFootSounds );
break;
case BIG_AE_STEP4: // Footstep back right
case BIG_AE_STEP2: // Footstep right
EMIT_SOUND_ARRAY_DYN( CHAN_BODY, pFootSounds );
break;
case BIG_AE_MORTAR_ATTACK1:
LaunchMortar();
break;
case BIG_AE_LAY_CRAB:
LayHeadcrab();
break;
case BIG_AE_JUMP_FORWARD:
ClearBits( pev->flags, FL_ONGROUND );
7 years ago
UTIL_SetOrigin (this, pev->origin + Vector ( 0 , 0 , 1) );// take her off ground so engine doesn't instantly reset onground
8 years ago
UTIL_MakeVectors( pev->angles );
9 years ago
7 years ago
pev->velocity = (gpGlobals->v_forward * 200) + gpGlobals->v_up * 500;
9 years ago
break;
case BIG_AE_EARLY_TARGET:
{
CBaseEntity *pTarget = m_hTargetEnt;
8 years ago
if( pTarget && pTarget->pev->message )
FireTargets( STRING( pTarget->pev->message ), this, this, USE_TOGGLE, 0 );
9 years ago
Remember( bits_MEMORY_FIRED_NODE );
}
break;
default:
CBaseMonster::HandleAnimEvent( pEvent );
break;
}
}
8 years ago
void CBigMomma::TraceAttack( entvars_t *pevAttacker, float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType )
9 years ago
{
// Bigmomma does not wear armor.
if( gpGlobals->time > m_painSoundTime )
9 years ago
{
8 years ago
m_painSoundTime = gpGlobals->time + RANDOM_LONG( 1, 3 );
9 years ago
EMIT_SOUND_ARRAY_DYN( CHAN_VOICE, pPainSounds );
}
CBaseMonster::TraceAttack( pevAttacker, flDamage, vecDir, ptr, bitsDamageType );
}
8 years ago
int CBigMomma::TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType )
9 years ago
{
// Don't take any acid damage -- BigMomma's mortar is acid
8 years ago
if( bitsDamageType & DMG_ACID )
9 years ago
flDamage = 0;
8 years ago
if( !HasMemory( bits_MEMORY_PATH_FINISHED ) )
9 years ago
{
8 years ago
if( pev->health <= flDamage )
9 years ago
{
pev->health = flDamage + 1;
Remember( bits_MEMORY_ADVANCE_NODE | bits_MEMORY_COMPLETED_NODE );
ALERT( at_aiconsole, "BM: Finished node health!!!\n" );
}
}
return CBaseMonster::TakeDamage( pevInflictor, pevAttacker, flDamage, bitsDamageType );
}
8 years ago
void CBigMomma::LayHeadcrab( void )
9 years ago
{
CBaseEntity *pChild = CBaseEntity::Create( BIG_CHILDCLASS, pev->origin, pev->angles, edict() );
pChild->pev->spawnflags |= SF_MONSTER_FALL_TO_GROUND;
// Is this the second crab in a pair?
8 years ago
if( HasMemory( bits_MEMORY_CHILDPAIR ) )
9 years ago
{
m_crabTime = gpGlobals->time + RANDOM_FLOAT( 5, 10 );
Forget( bits_MEMORY_CHILDPAIR );
}
else
{
m_crabTime = gpGlobals->time + RANDOM_FLOAT( 0.5, 2.5 );
Remember( bits_MEMORY_CHILDPAIR );
}
TraceResult tr;
8 years ago
UTIL_TraceLine( pev->origin, pev->origin - Vector( 0, 0, 100 ), ignore_monsters, edict(), &tr );
9 years ago
UTIL_DecalTrace( &tr, DECAL_MOMMABIRTH );
8 years ago
EMIT_SOUND_DYN( edict(), CHAN_WEAPON, RANDOM_SOUND_ARRAY( pBirthSounds ), 1.0, ATTN_NORM, 0, 100 + RANDOM_LONG( -5, 5 ) );
9 years ago
m_crabCount++;
}
void CBigMomma::DeathNotice( entvars_t *pevChild )
{
8 years ago
if( m_crabCount > 0 ) // Some babies may cross a transition, but we reset the count then
9 years ago
m_crabCount--;
8 years ago
if( IsAlive() )
9 years ago
{
// Make the "my baby's dead" noise!
EMIT_SOUND_ARRAY_DYN( CHAN_WEAPON, pChildDieSounds );
}
}
void CBigMomma::LaunchMortar( void )
{
m_mortarTime = gpGlobals->time + RANDOM_FLOAT( 2, 15 );
8 years ago
9 years ago
Vector startPos = pev->origin;
startPos.z += 180;
7 years ago
Vector vecLaunch = g_vecZero;
if (m_pCine) // is a scripted_action making me shoot?
{
if (m_hTargetEnt != 0) // don't check m_fTurnType- bigmomma can fire in any direction.
7 years ago
{
vecLaunch = VecCheckSplatToss( pev, startPos, m_hTargetEnt->pev->origin, RANDOM_FLOAT( 150, 500 ) );
}
if (vecLaunch == g_vecZero)
{
vecLaunch = pev->movedir;
}
}
else
{
vecLaunch = pev->movedir;
}
9 years ago
8 years ago
EMIT_SOUND_DYN( edict(), CHAN_WEAPON, RANDOM_SOUND_ARRAY( pSackSounds ), 1.0, ATTN_NORM, 0, 100 + RANDOM_LONG( -5, 5 ) );
7 years ago
CBMortar *pBomb = CBMortar::Shoot( edict(), startPos, vecLaunch );
9 years ago
pBomb->pev->gravity = 1.0;
8 years ago
MortarSpray( startPos, Vector( 0, 0, 1 ), gSpitSprite, 24 );
9 years ago
}
//=========================================================
// Spawn
//=========================================================
8 years ago
void CBigMomma::Spawn()
9 years ago
{
8 years ago
Precache();
9 years ago
7 years ago
if (pev->model)
SET_MODEL(ENT(pev), STRING(pev->model)); //LRC
else
SET_MODEL( ENT( pev ), "models/big_mom.mdl" );
9 years ago
UTIL_SetSize( pev, Vector( -32, -32, 0 ), Vector( 32, 32, 64 ) );
8 years ago
pev->solid = SOLID_SLIDEBOX;
pev->movetype = MOVETYPE_STEP;
// Bigmomma's blood color should be red.
m_bloodColor = BLOOD_COLOR_RED;
7 years ago
if (pev->health == 0)
pev->health = 150 * gSkillData.bigmommaHealthFactor;
8 years ago
pev->view_ofs = Vector( 0, 0, 128 );// position of the eyes relative to monster's origin.
m_flFieldOfView = 0.3;// indicates the width of this monster's forward view cone ( as a dotproduct result )
m_MonsterState = MONSTERSTATE_NONE;
9 years ago
MonsterInit();
}
//=========================================================
// Precache - precaches all resources this monster needs
//=========================================================
8 years ago
void CBigMomma::Precache()
9 years ago
{
7 years ago
if (pev->model)
PRECACHE_MODEL(STRING(pev->model)); //LRC
7 years ago
else
PRECACHE_MODEL( "models/big_mom.mdl" );
9 years ago
PRECACHE_SOUND_ARRAY( pChildDieSounds );
PRECACHE_SOUND_ARRAY( pSackSounds );
PRECACHE_SOUND_ARRAY( pDeathSounds );
PRECACHE_SOUND_ARRAY( pAttackSounds );
PRECACHE_SOUND_ARRAY( pAttackHitSounds );
PRECACHE_SOUND_ARRAY( pBirthSounds );
PRECACHE_SOUND_ARRAY( pAlertSounds );
PRECACHE_SOUND_ARRAY( pPainSounds );
PRECACHE_SOUND_ARRAY( pFootSounds );
UTIL_PrecacheOther( BIG_CHILDCLASS );
// TEMP: Squid
8 years ago
PRECACHE_MODEL( "sprites/mommaspit.spr" );// spit projectile.
gSpitSprite = PRECACHE_MODEL( "sprites/mommaspout.spr" );// client side spittle.
gSpitDebrisSprite = PRECACHE_MODEL( "sprites/mommablob.spr" );
9 years ago
PRECACHE_SOUND( "bullchicken/bc_acid1.wav" );
PRECACHE_SOUND( "bullchicken/bc_spithit1.wav" );
PRECACHE_SOUND( "bullchicken/bc_spithit2.wav" );
}
void CBigMomma::Activate( void )
{
if( m_hTargetEnt == 0 )
9 years ago
Remember( bits_MEMORY_ADVANCE_NODE ); // Start 'er up
7 years ago
CBaseMonster::Activate();
9 years ago
}
void CBigMomma::NodeStart( int iszNextNode )
{
pev->netname = iszNextNode;
CBaseEntity *pTarget = NULL;
8 years ago
if( pev->netname )
9 years ago
{
8 years ago
edict_t *pentTarget = FIND_ENTITY_BY_TARGETNAME( NULL, STRING( pev->netname ) );
9 years ago
8 years ago
if( !FNullEnt( pentTarget ) )
9 years ago
pTarget = Instance( pentTarget );
}
8 years ago
if( !pTarget )
9 years ago
{
ALERT( at_aiconsole, "BM: Finished the path!!\n" );
Remember( bits_MEMORY_PATH_FINISHED );
return;
}
Remember( bits_MEMORY_ON_PATH );
m_hTargetEnt = pTarget;
}
void CBigMomma::NodeReach( void )
{
CBaseEntity *pTarget = m_hTargetEnt;
Forget( bits_MEMORY_ADVANCE_NODE );
8 years ago
if( !pTarget )
9 years ago
return;
8 years ago
if( pTarget->pev->health )
9 years ago
pev->max_health = pev->health = pTarget->pev->health * gSkillData.bigmommaHealthFactor;
8 years ago
if( !HasMemory( bits_MEMORY_FIRED_NODE ) )
9 years ago
{
8 years ago
if( pTarget->pev->message )
FireTargets( STRING( pTarget->pev->message ), this, this, USE_TOGGLE, 0 );
9 years ago
}
Forget( bits_MEMORY_FIRED_NODE );
pev->netname = pTarget->pev->target;
8 years ago
if( pTarget->pev->health == 0 )
9 years ago
Remember( bits_MEMORY_ADVANCE_NODE ); // Move on if no health at this node
}
// Slash
9 years ago
BOOL CBigMomma::CheckMeleeAttack1( float flDot, float flDist )
{
8 years ago
if( flDot >= 0.7 )
9 years ago
{
8 years ago
if( flDist <= BIG_ATTACKDIST )
9 years ago
return TRUE;
}
return FALSE;
}
// Lay a crab
BOOL CBigMomma::CheckMeleeAttack2( float flDot, float flDist )
{
return CanLayCrab();
}
// Mortar launch
BOOL CBigMomma::CheckRangeAttack1( float flDot, float flDist )
{
8 years ago
if( flDist <= BIG_MORTARDIST && m_mortarTime < gpGlobals->time )
9 years ago
{
CBaseEntity *pEnemy = m_hEnemy;
8 years ago
if( pEnemy )
9 years ago
{
Vector startPos = pev->origin;
startPos.z += 180;
pev->movedir = VecCheckSplatToss( pev, startPos, pEnemy->BodyTarget( pev->origin ), RANDOM_FLOAT( 150, 500 ) );
8 years ago
if( pev->movedir != g_vecZero )
9 years ago
return TRUE;
}
}
return FALSE;
}
//=========================================================
// AI Schedules Specific to this monster
//=========================================================
enum
{
SCHED_BIG_NODE = LAST_COMMON_SCHEDULE + 1,
SCHED_NODE_FAIL
9 years ago
};
enum
{
TASK_MOVE_TO_NODE_RANGE = LAST_COMMON_TASK + 1, // Move within node range
TASK_FIND_NODE, // Find my next node
TASK_PLAY_NODE_PRESEQUENCE, // Play node pre-script
TASK_PLAY_NODE_SEQUENCE, // Play node script
TASK_PROCESS_NODE, // Fire targets, etc.
TASK_WAIT_NODE, // Wait at the node
TASK_NODE_DELAY, // Delay walking toward node for a bit. You've failed to get there
TASK_NODE_YAW // Get the best facing direction for this node
9 years ago
};
8 years ago
Task_t tlBigNode[] =
9 years ago
{
8 years ago
{ TASK_SET_FAIL_SCHEDULE, (float)SCHED_NODE_FAIL },
{ TASK_STOP_MOVING, (float)0 },
{ TASK_FIND_NODE, (float)0 }, // Find my next node
{ TASK_PLAY_NODE_PRESEQUENCE, (float)0 }, // Play the pre-approach sequence if any
{ TASK_MOVE_TO_NODE_RANGE, (float)0 }, // Move within node range
{ TASK_STOP_MOVING, (float)0 },
{ TASK_NODE_YAW, (float)0 },
{ TASK_FACE_IDEAL, (float)0 },
{ TASK_WAIT_NODE, (float)0 }, // Wait for node delay
{ TASK_PLAY_NODE_SEQUENCE, (float)0 }, // Play the sequence if one exists
{ TASK_PROCESS_NODE, (float)0 }, // Fire targets, etc.
{ TASK_SET_ACTIVITY, (float)ACT_IDLE },
9 years ago
};
8 years ago
Schedule_t slBigNode[] =
9 years ago
{
8 years ago
{
9 years ago
tlBigNode,
8 years ago
ARRAYSIZE( tlBigNode ),
9 years ago
0,
0,
"Big Node"
},
};
8 years ago
Task_t tlNodeFail[] =
9 years ago
{
8 years ago
{ TASK_NODE_DELAY, (float)10 }, // Try to do something else for 10 seconds
{ TASK_SET_ACTIVITY, (float)ACT_IDLE },
9 years ago
};
8 years ago
Schedule_t slNodeFail[] =
9 years ago
{
8 years ago
{
9 years ago
tlNodeFail,
8 years ago
ARRAYSIZE( tlNodeFail ),
9 years ago
0,
0,
"NodeFail"
},
};
DEFINE_CUSTOM_SCHEDULES( CBigMomma )
{
slBigNode,
slNodeFail,
};
IMPLEMENT_CUSTOM_SCHEDULES( CBigMomma, CBaseMonster )
9 years ago
Schedule_t *CBigMomma::GetScheduleOfType( int Type )
{
switch( Type )
{
case SCHED_BIG_NODE:
return slBigNode;
8 years ago
break;
9 years ago
case SCHED_NODE_FAIL:
return slNodeFail;
8 years ago
break;
9 years ago
}
return CBaseMonster::GetScheduleOfType( Type );
}
BOOL CBigMomma::ShouldGoToNode( void )
{
8 years ago
if( HasMemory( bits_MEMORY_ADVANCE_NODE ) )
9 years ago
{
8 years ago
if( m_nodeTime < gpGlobals->time )
9 years ago
return TRUE;
}
return FALSE;
}
7 years ago
// Overridden to make BigMomma jump on command; the model doesn't support it otherwise.
void CBigMomma :: SetActivity ( Activity NewActivity )
{
int iSequence;
if (NewActivity == ACT_HOP)
{
iSequence = LookupSequence( "jump" );
}
else
{
iSequence = LookupActivity ( NewActivity );
}
// Set to the desired anim, or default anim if the desired is not present
if ( iSequence > ACTIVITY_NOT_AVAILABLE )
{
if ( pev->sequence != iSequence || !m_fSequenceLoops )
{
// don't reset frame between walk and run
if ( !(m_Activity == ACT_WALK || m_Activity == ACT_RUN) || !(NewActivity == ACT_WALK || NewActivity == ACT_RUN))
pev->frame = 0;
}
pev->sequence = iSequence; // Set to the reset anim (if it's there)
ResetSequenceInfo( );
SetYawSpeed();
}
else
{
// Not available try to get default anim
ALERT ( at_aiconsole, "%s has no sequence for act:%d\n", STRING(pev->classname), NewActivity );
pev->sequence = 0; // Set to the reset anim (if it's there)
}
m_Activity = NewActivity; // Go ahead and set this so it doesn't keep trying when the anim is not present
// In case someone calls this with something other than the ideal activity
m_IdealActivity = m_Activity;
}
9 years ago
Schedule_t *CBigMomma::GetSchedule( void )
{
8 years ago
if( ShouldGoToNode() )
9 years ago
{
return GetScheduleOfType( SCHED_BIG_NODE );
}
return CBaseMonster::GetSchedule();
}
void CBigMomma::StartTask( Task_t *pTask )
{
8 years ago
switch( pTask->iTask )
9 years ago
{
case TASK_FIND_NODE:
{
CBaseEntity *pTarget = m_hTargetEnt;
8 years ago
if( !HasMemory( bits_MEMORY_ADVANCE_NODE ) )
9 years ago
{
8 years ago
if( pTarget )
9 years ago
pev->netname = m_hTargetEnt->pev->target;
}
NodeStart( pev->netname );
TaskComplete();
8 years ago
ALERT( at_aiconsole, "BM: Found node %s\n", STRING( pev->netname ) );
9 years ago
}
break;
case TASK_NODE_DELAY:
m_nodeTime = gpGlobals->time + pTask->flData;
TaskComplete();
ALERT( at_aiconsole, "BM: FAIL! Delay %.2f\n", pTask->flData );
break;
case TASK_PROCESS_NODE:
8 years ago
ALERT( at_aiconsole, "BM: Reached node %s\n", STRING( pev->netname ) );
9 years ago
NodeReach();
TaskComplete();
break;
case TASK_PLAY_NODE_PRESEQUENCE:
case TASK_PLAY_NODE_SEQUENCE:
{
int sequence;
8 years ago
if( pTask->iTask == TASK_PLAY_NODE_SEQUENCE )
9 years ago
sequence = GetNodeSequence();
else
sequence = GetNodePresequence();
8 years ago
ALERT( at_aiconsole, "BM: Playing node sequence %s\n", STRING( sequence ) );
if( sequence )
9 years ago
{
sequence = LookupSequence( STRING( sequence ) );
8 years ago
if( sequence != -1 )
9 years ago
{
pev->sequence = sequence;
pev->frame = 0;
8 years ago
ResetSequenceInfo();
ALERT( at_aiconsole, "BM: Sequence %s\n", STRING( GetNodeSequence() ) );
9 years ago
return;
}
}
TaskComplete();
}
break;
case TASK_NODE_YAW:
pev->ideal_yaw = GetNodeYaw();
TaskComplete();
break;
case TASK_WAIT_NODE:
m_flWait = gpGlobals->time + GetNodeDelay();
8 years ago
if( m_hTargetEnt->pev->spawnflags & SF_INFOBM_WAIT )
ALERT( at_aiconsole, "BM: Wait at node %s forever\n", STRING( pev->netname ) );
9 years ago
else
8 years ago
ALERT( at_aiconsole, "BM: Wait at node %s for %.2f\n", STRING( pev->netname ), GetNodeDelay() );
9 years ago
break;
case TASK_MOVE_TO_NODE_RANGE:
{
CBaseEntity *pTarget = m_hTargetEnt;
8 years ago
if( !pTarget )
9 years ago
TaskFail();
else
{
8 years ago
if( ( pTarget->pev->origin - pev->origin ).Length() < GetNodeRange() )
9 years ago
TaskComplete();
else
{
Activity act = ACT_WALK;
8 years ago
if( pTarget->pev->spawnflags & SF_INFOBM_RUN )
9 years ago
act = ACT_RUN;
m_vecMoveGoal = pTarget->pev->origin;
8 years ago
if( !MoveToTarget( act, 2 ) )
9 years ago
{
TaskFail();
}
}
}
}
8 years ago
ALERT( at_aiconsole, "BM: Moving to node %s\n", STRING( pev->netname ) );
9 years ago
break;
case TASK_MELEE_ATTACK1:
// Play an attack sound here
8 years ago
EMIT_SOUND_DYN( ENT( pev ), CHAN_VOICE, RANDOM_SOUND_ARRAY( pAttackSounds ), 1.0, ATTN_NORM, 0, PITCH_NORM );
9 years ago
CBaseMonster::StartTask( pTask );
break;
default:
CBaseMonster::StartTask( pTask );
break;
}
}
//=========================================================
// RunTask
//=========================================================
void CBigMomma::RunTask( Task_t *pTask )
{
8 years ago
switch( pTask->iTask )
9 years ago
{
case TASK_MOVE_TO_NODE_RANGE:
{
float distance;
if( m_hTargetEnt == 0 )
9 years ago
TaskFail();
else
{
distance = ( m_vecMoveGoal - pev->origin ).Length2D();
// Set the appropriate activity based on an overlapping range
// overlap the range to prevent oscillation
8 years ago
if( (distance < GetNodeRange() ) || MovementIsComplete() )
9 years ago
{
ALERT( at_aiconsole, "BM: Reached node!\n" );
TaskComplete();
RouteClear(); // Stop moving
}
}
}
break;
case TASK_WAIT_NODE:
if( m_hTargetEnt != 0 && ( m_hTargetEnt->pev->spawnflags & SF_INFOBM_WAIT ) )
9 years ago
return;
8 years ago
if( gpGlobals->time > m_flWaitFinished )
9 years ago
TaskComplete();
ALERT( at_aiconsole, "BM: The WAIT is over!\n" );
break;
case TASK_PLAY_NODE_PRESEQUENCE:
case TASK_PLAY_NODE_SEQUENCE:
8 years ago
if( m_fSequenceFinished )
9 years ago
{
m_Activity = ACT_RESET;
TaskComplete();
}
break;
default:
CBaseMonster::RunTask( pTask );
break;
}
}
Vector VecCheckSplatToss( entvars_t *pev, const Vector &vecSpot1, Vector vecSpot2, float maxHeight )
{
8 years ago
TraceResult tr;
Vector vecMidPoint;// halfway point between Spot1 and Spot2
Vector vecApex;// highest point
Vector vecScale;
Vector vecGrenadeVel;
Vector vecTemp;
float flGravity = g_psv_gravity->value;
9 years ago
// calculate the midpoint and apex of the 'triangle'
8 years ago
vecMidPoint = vecSpot1 + ( vecSpot2 - vecSpot1 ) * 0.5;
UTIL_TraceLine( vecMidPoint, vecMidPoint + Vector( 0, 0, maxHeight ), ignore_monsters, ENT( pev ), &tr );
9 years ago
vecApex = tr.vecEndPos;
8 years ago
UTIL_TraceLine( vecSpot1, vecApex, dont_ignore_monsters, ENT( pev ), &tr );
if( tr.flFraction != 1.0 )
9 years ago
{
// fail!
return g_vecZero;
}
// Don't worry about actually hitting the target, this won't hurt us!
// How high should the grenade travel (subtract 15 so the grenade doesn't hit the ceiling)?
8 years ago
float height = vecApex.z - vecSpot1.z - 15;
9 years ago
// How fast does the grenade need to travel to reach that height given gravity?
float speed = sqrt( 2 * flGravity * height );
// How much time does it take to get there?
float time = speed / flGravity;
8 years ago
vecGrenadeVel = vecSpot2 - vecSpot1;
9 years ago
vecGrenadeVel.z = 0;
// Travel half the distance to the target in that time (apex is at the midpoint)
vecGrenadeVel = vecGrenadeVel * ( 0.5 / time );
// Speed to offset gravity at the desired height
vecGrenadeVel.z = speed;
return vecGrenadeVel;
}
// ---------------------------------
//
// Mortar
//
// ---------------------------------
void MortarSpray( const Vector &position, const Vector &direction, int spriteModel, int count )
{
MESSAGE_BEGIN( MSG_PVS, SVC_TEMPENTITY, position );
WRITE_BYTE( TE_SPRITE_SPRAY );
8 years ago
WRITE_COORD( position.x ); // pos
WRITE_COORD( position.y );
WRITE_COORD( position.z );
WRITE_COORD( direction.x ); // dir
WRITE_COORD( direction.y );
WRITE_COORD( direction.z );
9 years ago
WRITE_SHORT( spriteModel ); // model
WRITE_BYTE ( count ); // count
WRITE_BYTE ( 130 ); // speed
WRITE_BYTE ( 80 ); // noise ( client will divide by 100 )
MESSAGE_END();
}
// UNDONE: right now this is pretty much a copy of the squid spit with minor changes to the way it does damage
8 years ago
void CBMortar::Spawn( void )
9 years ago
{
pev->movetype = MOVETYPE_TOSS;
pev->classname = MAKE_STRING( "bmortar" );
pev->solid = SOLID_BBOX;
pev->rendermode = kRenderTransAlpha;
pev->renderamt = 255;
8 years ago
SET_MODEL( ENT( pev ), "sprites/mommaspit.spr" );
9 years ago
pev->frame = 0;
pev->scale = 0.5;
8 years ago
UTIL_SetSize( pev, Vector( 0, 0, 0 ), Vector( 0, 0, 0 ) );
9 years ago
m_maxFrame = (float) MODEL_FRAMES( pev->modelindex ) - 1;
pev->dmgtime = gpGlobals->time + 0.4;
}
void CBMortar::Animate( void )
{
7 years ago
SetNextThink( 0.1 );
9 years ago
8 years ago
if( gpGlobals->time > pev->dmgtime )
9 years ago
{
pev->dmgtime = gpGlobals->time + 0.2;
MortarSpray( pev->origin, -pev->velocity.Normalize(), gSpitSprite, 3 );
}
8 years ago
if( pev->frame++ )
9 years ago
{
if ( pev->frame > m_maxFrame )
{
pev->frame = 0;
}
}
}
CBMortar *CBMortar::Shoot( edict_t *pOwner, Vector vecStart, Vector vecVelocity )
{
CBMortar *pSpit = GetClassPtr( (CBMortar *)NULL );
pSpit->Spawn();
7 years ago
UTIL_SetOrigin( pSpit, vecStart );
9 years ago
pSpit->pev->velocity = vecVelocity;
pSpit->pev->owner = pOwner;
pSpit->pev->scale = 2.5;
pSpit->SetThink( &CBMortar::Animate );
7 years ago
pSpit->SetNextThink( 0.1 );
9 years ago
return pSpit;
}
void CBMortar::Touch( CBaseEntity *pOther )
{
TraceResult tr;
8 years ago
int iPitch;
9 years ago
// splat sound
iPitch = RANDOM_FLOAT( 90, 110 );
8 years ago
EMIT_SOUND_DYN( ENT( pev ), CHAN_VOICE, "bullchicken/bc_acid1.wav", 1, ATTN_NORM, 0, iPitch );
9 years ago
8 years ago
switch( RANDOM_LONG( 0, 1 ) )
9 years ago
{
case 0:
8 years ago
EMIT_SOUND_DYN( ENT( pev ), CHAN_WEAPON, "bullchicken/bc_spithit1.wav", 1, ATTN_NORM, 0, iPitch );
9 years ago
break;
case 1:
8 years ago
EMIT_SOUND_DYN( ENT( pev ), CHAN_WEAPON, "bullchicken/bc_spithit2.wav", 1, ATTN_NORM, 0, iPitch );
9 years ago
break;
}
8 years ago
if( pOther->IsBSPModel() )
9 years ago
{
// make a splat on the wall
UTIL_TraceLine( pev->origin, pev->origin + pev->velocity * 10, dont_ignore_monsters, ENT( pev ), &tr );
8 years ago
UTIL_DecalTrace( &tr, DECAL_MOMMASPLAT );
9 years ago
}
else
{
tr.vecEndPos = pev->origin;
tr.vecPlaneNormal = -1 * pev->velocity.Normalize();
}
9 years ago
// make some flecks
MortarSpray( tr.vecEndPos, tr.vecPlaneNormal, gSpitSprite, 24 );
entvars_t *pevOwner = NULL;
8 years ago
if( pev->owner )
9 years ago
pevOwner = VARS(pev->owner);
RadiusDamage( pev->origin, pev, pevOwner, gSkillData.bigmommaDmgBlast, gSkillData.bigmommaRadiusBlast, CLASS_NONE, DMG_ACID );
UTIL_Remove( this );
}
#endif