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.

252 lines
6.5 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.
*
****/
//=========================================================
// GMan - misunderstood servant of the people
//=========================================================
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "monsters.h"
#include "schedule.h"
#include "weapons.h"
//=========================================================
// Monster's Anim Events Go Here
//=========================================================
class CGMan : public CBaseMonster
{
public:
void Spawn( void );
void Precache( void );
void SetYawSpeed( void );
8 years ago
int Classify ( void );
9 years ago
void HandleAnimEvent( MonsterEvent_t *pEvent );
int ISoundMask ( void );
8 years ago
int Save( CSave &save );
9 years ago
int Restore( CRestore &restore );
static TYPEDESCRIPTION m_SaveData[];
void StartTask( Task_t *pTask );
void RunTask( Task_t *pTask );
8 years ago
int TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType );
9 years ago
void TraceAttack( entvars_t *pevAttacker, float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType);
void PlayScriptedSentence( const char *pszSentence, float duration, float volume, float attenuation, BOOL bConcurrent, CBaseEntity *pListener );
EHANDLE m_hPlayer;
EHANDLE m_hTalkTarget;
float m_flTalkTime;
// modif de julien
int CanPlaySequence( BOOL fDisregardMonsterState, int interruptLevel );
9 years ago
};
LINK_ENTITY_TO_CLASS( monster_gman, CGMan )
9 years ago
8 years ago
TYPEDESCRIPTION CGMan::m_SaveData[] =
9 years ago
{
DEFINE_FIELD( CGMan, m_hTalkTarget, FIELD_EHANDLE ),
DEFINE_FIELD( CGMan, m_flTalkTime, FIELD_TIME ),
};
IMPLEMENT_SAVERESTORE( CGMan, CBaseMonster )
9 years ago
//---------------------
// modif de Julien
int CGMan :: CanPlaySequence( BOOL fDisregardMonsterState, int interruptLevel )
{
return TRUE;
}
9 years ago
//=========================================================
// Classify - indicates this monster's place in the
// relationship table.
//=========================================================
8 years ago
int CGMan::Classify( void )
9 years ago
{
8 years ago
return CLASS_NONE;
9 years ago
}
//=========================================================
// SetYawSpeed - allows each sequence to have a different
// turn rate associated with it.
//=========================================================
8 years ago
void CGMan::SetYawSpeed( void )
9 years ago
{
int ys;
8 years ago
switch( m_Activity )
9 years ago
{
case ACT_IDLE:
default:
ys = 90;
}
pev->yaw_speed = ys;
}
//=========================================================
// HandleAnimEvent - catches the monster-specific messages
// that occur when tagged animation frames are played.
//=========================================================
8 years ago
void CGMan::HandleAnimEvent( MonsterEvent_t *pEvent )
9 years ago
{
switch( pEvent->event )
{
case 0:
default:
CBaseMonster::HandleAnimEvent( pEvent );
break;
}
}
//=========================================================
// ISoundMask - generic monster can't hear.
//=========================================================
8 years ago
int CGMan::ISoundMask( void )
9 years ago
{
return 0;
9 years ago
}
//=========================================================
// Spawn
//=========================================================
8 years ago
void CGMan::Spawn()
9 years ago
{
Precache();
8 years ago
SET_MODEL( ENT( pev ), "models/gman.mdl" );
UTIL_SetSize( pev, VEC_HUMAN_HULL_MIN, VEC_HUMAN_HULL_MAX );
9 years ago
// pev->solid = SOLID_SLIDEBOX;
pev->solid = SOLID_NOT; // modif de Julien
9 years ago
pev->movetype = MOVETYPE_STEP;
m_bloodColor = DONT_BLEED;
8 years ago
pev->health = 100;
9 years ago
m_flFieldOfView = 0.5;// indicates the width of this monster's forward view cone ( as a dotproduct result )
m_MonsterState = MONSTERSTATE_NONE;
MonsterInit();
}
//=========================================================
// Precache - precaches all resources this monster needs
//=========================================================
8 years ago
void CGMan::Precache()
9 years ago
{
PRECACHE_MODEL( "models/gman.mdl" );
8 years ago
}
9 years ago
//=========================================================
// AI Schedules Specific to this monster
//=========================================================
8 years ago
void CGMan::StartTask( Task_t *pTask )
9 years ago
{
switch( pTask->iTask )
{
case TASK_WAIT:
if( m_hPlayer == 0 )
9 years ago
{
m_hPlayer = UTIL_FindEntityByClassname( NULL, "player" );
}
break;
}
CBaseMonster::StartTask( pTask );
}
8 years ago
void CGMan::RunTask( Task_t *pTask )
9 years ago
{
switch( pTask->iTask )
{
case TASK_WAIT:
// look at who I'm talking to
if( m_flTalkTime > gpGlobals->time && m_hTalkTarget != 0 )
9 years ago
{
8 years ago
float yaw = VecToYaw( m_hTalkTarget->pev->origin - pev->origin ) - pev->angles.y;
9 years ago
8 years ago
if( yaw > 180 )
yaw -= 360;
if( yaw < -180 )
yaw += 360;
9 years ago
// turn towards vector
SetBoneController( 0, yaw );
}
// look at player, but only if playing a "safe" idle animation
else if( m_hPlayer != 0 && pev->sequence == 0 )
9 years ago
{
8 years ago
float yaw = VecToYaw( m_hPlayer->pev->origin - pev->origin ) - pev->angles.y;
9 years ago
8 years ago
if( yaw > 180 )
yaw -= 360;
if( yaw < -180 )
yaw += 360;
9 years ago
// turn towards vector
SetBoneController( 0, yaw );
}
else
{
SetBoneController( 0, 0 );
}
CBaseMonster::RunTask( pTask );
break;
default:
SetBoneController( 0, 0 );
CBaseMonster::RunTask( pTask );
break;
}
}
//=========================================================
// Override all damage
//=========================================================
8 years ago
int CGMan::TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType )
9 years ago
{
pev->health = pev->max_health / 2; // always trigger the 50% damage aitrigger
8 years ago
if( flDamage > 0 )
9 years ago
{
8 years ago
SetConditions( bits_COND_LIGHT_DAMAGE );
9 years ago
}
8 years ago
if( flDamage >= 20 )
9 years ago
{
8 years ago
SetConditions( bits_COND_HEAVY_DAMAGE );
9 years ago
}
return TRUE;
}
void CGMan::TraceAttack( entvars_t *pevAttacker, float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType)
{
UTIL_Ricochet( ptr->vecEndPos, 1.0 );
AddMultiDamage( pevAttacker, this, flDamage, bitsDamageType );
}
void CGMan::PlayScriptedSentence( const char *pszSentence, float duration, float volume, float attenuation, BOOL bConcurrent, CBaseEntity *pListener )
{
CBaseMonster::PlayScriptedSentence( pszSentence, duration, volume, attenuation, bConcurrent, pListener );
m_flTalkTime = gpGlobals->time + duration;
m_hTalkTarget = pListener;
}