class CBarniel: public CBarney//Наследуем класс
{
public:
void Spawn( void );
void Precache( void );
int Classify ( void );
void BarneyFirePistol ( void );
void TalkInit();
void PainSound ( void );
void DeathSound ( void );
void DeclineFollowing( void );
void AlertSound( void );
int TakeDamage( entvars_t* pevInflictor, entvars_t* pevAttacker, float flDamage, int bitsDamageType);
Schedule_t *GetSchedule ( void );
};
LINK_ENTITY_TO_CLASS( monster_barniel, CBarniel);
int CBarniel :: Classify ( void )
{
return CLASS_PLAYER_ALLY;
}
void CBarniel :: BarneyFirePistol ( void )
{
Vector vecShootOrigin;
UTIL_MakeVectors(pev->angles);
vecShootOrigin = pev->origin + Vector( 0, 0, 55 );
Vector vecShootDir = ShootAtEnemy( vecShootOrigin );
Vector angDir = UTIL_VecToAngles( vecShootDir );
SetBlending( 0, angDir.x );
pev->effects = EF_MUZZLEFLASH;
FireBullets(1, vecShootOrigin, vecShootDir, VECTOR_CONE_2DEGREES, 1024, BULLET_MONSTER_9MM );
int pitchShift = RANDOM_LONG( 0, 20 );
if ( pitchShift > 10 )
pitchShift = 0;
else
pitchShift -= 5;
EMIT_SOUND_DYN( ENT(pev), CHAN_WEAPON, "barniel/bn_attack2.wav", 1, ATTN_NORM, 0, 100 + pitchShift );
CSoundEnt::InsertSound ( bits_SOUND_COMBAT, pev->origin, 384, 0.3 );
m_cAmmoLoaded--;
}
void CBarniel :: Spawn()
{
Precache( );
if (pev->model)
SET_MODEL(ENT(pev), STRING(pev->model));
else
SET_MODEL(ENT(pev), "models/Barniel.mdl");
UTIL_SetSize(pev, VEC_HUMAN_HULL_MIN, VEC_HUMAN_HULL_MAX);
pev->solid = SOLID_SLIDEBOX;
pev->movetype = MOVETYPE_STEP;
m_bloodColor = BLOOD_COLOR_RED;
pev->health = gSkillData.barneyHealth;
pev->view_ofs = Vector ( 0, 0, 50 );
m_flFieldOfView = VIEW_FIELD_WIDE;
m_MonsterState = MONSTERSTATE_NONE;
pev->body = 0;
m_fGunDrawn = FALSE;
m_afCapability = bits_CAP_HEAR | bits_CAP_TURN_HEAD | bits_CAP_DOORS_GROUP;
MonsterInit();
SetUse( FollowerUse );
}
void CBarniel :: Precache()
{
if (pev->model)
PRECACHE_MODEL((char*)STRING(pev->model));
else
PRECACHE_MODEL("models/Barniel.mdl");
PRECACHE_SOUND("barniel/bn_attack1.wav" );
PRECACHE_SOUND("barniel/bn_attack2.wav" );
PRECACHE_SOUND("barney/ba_attack2.wav" );
PRECACHE_SOUND("barniel/bn_pain1.wav");
PRECACHE_SOUND("barniel/bn_die1.wav");
TalkInit();
CTalkMonster::Precache();
}
void CBarniel :: TalkInit()
{
CTalkMonster::TalkInit();
m_szGrp[TLK_ANSWER] = "BN_ANSWER";
m_szGrp[TLK_QUESTION] = "BN_QUESTION";
m_szGrp[TLK_IDLE] = "BN_IDLE";
m_szGrp[TLK_STARE] = "BN_STARE";
m_szGrp[TLK_USE] = "BN_OK";
m_szGrp[TLK_UNUSE] = "BN_WAIT";
m_szGrp[TLK_STOP] = "BN_STOP";
m_szGrp[TLK_NOSHOOT] = "BN_SCARED";
m_szGrp[TLK_HELLO] = "BN_HELLO";
m_szGrp[TLK_PLHURT1] = "!BN_CUREA";
m_szGrp[TLK_PLHURT2] = "!BN_CUREB";
m_szGrp[TLK_PLHURT3] = "!BN_CUREC";
m_szGrp[TLK_PHELLO] = NULL;
m_szGrp[TLK_PIDLE] = NULL;
m_szGrp[TLK_PQUESTION] = "BN_PQUEST";
m_szGrp[TLK_SMELL] = "BN_SMELL";
m_szGrp[TLK_WOUND] = "BN_WOUND";
m_szGrp[TLK_MORTAL] = "BN_MORTAL";
m_voicePitch = 100;
}
void CBarniel :: PainSound ( void )
{
if (gpGlobals->time < m_painTime)
return;
m_painTime = gpGlobals->time + RANDOM_FLOAT(0.5, 0.75);
EMIT_SOUND_DYN( ENT(pev), CHAN_VOICE, "barniel/bn_pain1.wav", 1, ATTN_NORM, 0, GetVoicePitch());
}
void CBarniel :: DeathSound ( void )
{
EMIT_SOUND_DYN( ENT(pev), CHAN_VOICE, "barniel/bn_die1.wav", 1, ATTN_NORM, 0, GetVoicePitch()); //ea?aou caoe
}
void CBarniel :: AlertSound( void )
{
if ( m_hEnemy != NULL )
{
if ( FOkToSpeak() )
{
PlaySentence( "BN_ATTACK", RANDOM_FLOAT(2.8, 3.2), VOL_NORM, ATTN_IDLE );
}
}
}
int CBarniel :: TakeDamage( entvars_t* pevInflictor, entvars_t* pevAttacker, float flDamage, int bitsDamageType)
{
int ret = CTalkMonster::TakeDamage(pevInflictor, pevAttacker, flDamage, bitsDamageType);
if ( !IsAlive() || pev->deadflag == DEAD_DYING )
return ret;
if ( m_MonsterState != MONSTERSTATE_PRONE && (pevAttacker->flags & FL_CLIENT) )
{
m_flPlayerDamage += flDamage;
if ( m_hEnemy == NULL )
{
if ( (m_afMemory & bits_MEMORY_SUSPICIOUS) || IsFacing( pevAttacker, pev->origin ) )
{
PlaySentence( "BN_MAD", 4, VOL_NORM, ATTN_NORM );
Remember( bits_MEMORY_PROVOKED );
StopFollowing( TRUE );
}
else
{
PlaySentence( "BN_SHOT", 4, VOL_NORM, ATTN_NORM );
Remember( bits_MEMORY_SUSPICIOUS );
}
}
else if ( !(m_hEnemy->IsPlayer()) && pev->deadflag == DEAD_NO )
{
PlaySentence( "BN_SHOT", 4, VOL_NORM, ATTN_NORM );
}
}
return ret;
}
Schedule_t *CBarniel :: GetSchedule ( void )
{
if ( HasConditions( bits_COND_HEAR_SOUND ) )
{
CSound *pSound;
pSound = PBestSound();
ASSERT( pSound != NULL );
if ( pSound && (pSound->m_iType & bits_SOUND_DANGER) )
return GetScheduleOfType( SCHED_TAKE_COVER_FROM_BEST_SOUND );
}
if ( HasConditions( bits_COND_ENEMY_DEAD ) && FOkToSpeak() )
{
PlaySentence( "BN_KILL", 4, VOL_NORM, ATTN_NORM );
}
switch( m_MonsterState )
{
case MONSTERSTATE_COMBAT:
{
if ( HasConditions( bits_COND_ENEMY_DEAD ) )
{
return CBaseMonster :: GetSchedule();
}
if ( HasConditions( bits_COND_NEW_ENEMY ) && HasConditions( bits_COND_LIGHT_DAMAGE) )
return GetScheduleOfType( SCHED_SMALL_FLINCH );
if (!m_fGunDrawn )
return GetScheduleOfType( SCHED_ARM_WEAPON );
if ( HasConditions( bits_COND_HEAVY_DAMAGE ) )
return GetScheduleOfType( SCHED_TAKE_COVER_FROM_ENEMY );
}
break;
case MONSTERSTATE_ALERT:
case MONSTERSTATE_IDLE:
if ( HasConditions(bits_COND_LIGHT_DAMAGE | bits_COND_HEAVY_DAMAGE))
{
return GetScheduleOfType( SCHED_SMALL_FLINCH );
}
if ( m_hEnemy == NULL && IsFollowing() )
{
if ( !m_hTargetEnt->IsAlive() )
{
StopFollowing( FALSE );
break;
}
else
{
if ( HasConditions( bits_COND_CLIENT_PUSH ) )
{
return GetScheduleOfType( SCHED_MOVE_AWAY_FOLLOW );
}
return GetScheduleOfType( SCHED_TARGET_FACE );
}
}
if ( HasConditions( bits_COND_CLIENT_PUSH ) )
{
return GetScheduleOfType( SCHED_MOVE_AWAY );
}
TrySmellTalk();
break;
}
return CTalkMonster::GetSchedule();
}
void CBarniel::DeclineFollowing( void )
{
PlaySentence( "BN_POK", 2, VOL_NORM, ATTN_NORM );
}