1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
//=========================================================
// GMan - misunderstood servant of the people
//=========================================================
#include "cbase.h"
#include "ai_default.h"
#include "ai_task.h"
#include "ai_schedule.h"
#include "ai_node.h"
#include "ai_hull.h"
#include "ai_hint.h"
#include "ai_memory.h"
#include "ai_route.h"
#include "ai_motor.h"
#include "soundent.h"
#include "game.h"
#include "npcevent.h"
#include "entitylist.h"
#include "activitylist.h"
#include "animation.h"
#include "IEffects.h"
#include "vstdlib/random.h"
#include "ai_baseactor.h"
//=========================================================
// Monster's Anim Events Go Here
//=========================================================
class CNPC_GMan : public CAI_BaseActor
{
DECLARE_CLASS( CNPC_GMan, CAI_BaseActor );
public:
void Spawn( void );
void Precache( void );
float MaxYawSpeed( void ){ return 90.0f; }
Class_T Classify ( void );
void HandleAnimEvent( animevent_t *pEvent );
int GetSoundInterests ( void );
bool IsInC5A1();
void StartTask( const Task_t *pTask );
void RunTask( const Task_t *pTask );
int OnTakeDamage_Alive( const CTakeDamageInfo &inputInfo );
void TraceAttack( CBaseEntity *pAttacker, float flDamage, const Vector &vecDir, trace_t *ptr, int bitsDamageType);
virtual int PlayScriptedSentence( const char *pszSentence, float duration, float volume, soundlevel_t soundlevel, bool bConcurrent, CBaseEntity *pListener );
EHANDLE m_hPlayer;
EHANDLE m_hTalkTarget;
float m_flTalkTime;
};
LINK_ENTITY_TO_CLASS( monster_gman, CNPC_GMan );
//=========================================================
// Hack that tells us whether the GMan is in the final map
//=========================================================
bool CNPC_GMan::IsInC5A1()
{
const char *pMapName = STRING(gpGlobals->mapname);
if( pMapName )
{
return !Q_strnicmp( pMapName, "c5a1", 4 );
}
return false;
}
//=========================================================
// Classify - indicates this monster's place in the
// relationship table.
//=========================================================
Class_T CNPC_GMan::Classify ( void )
{
return CLASS_NONE;
}
//=========================================================
// HandleAnimEvent - catches the monster-specific messages
// that occur when tagged animation frames are played.
//=========================================================
void CNPC_GMan::HandleAnimEvent( animevent_t *pEvent )
{
switch( pEvent->event )
{
case 1:
default:
BaseClass::HandleAnimEvent( pEvent );
break;
}
}
//=========================================================
// GetSoundInterests - generic monster can't hear.
//=========================================================
int CNPC_GMan::GetSoundInterests ( void )
{
return NULL;
}
//=========================================================
// Spawn
//=========================================================
void CNPC_GMan::Spawn()
{
Precache();
BaseClass::Spawn();
SetModel( "models/gman.mdl" );
SetHullType(HULL_HUMAN);
SetHullSizeNormal();
SetSolid( SOLID_BBOX );
AddSolidFlags( FSOLID_NOT_STANDABLE );
SetMoveType( MOVETYPE_STEP );
SetBloodColor( BLOOD_COLOR_MECH );
m_iHealth = 8;
m_flFieldOfView = 0.5;// indicates the width of this NPC's forward view cone ( as a dotproduct result )
m_NPCState = NPC_STATE_NONE;
CapabilitiesAdd( bits_CAP_MOVE_GROUND | bits_CAP_OPEN_DOORS | bits_CAP_USE_WEAPONS | bits_CAP_ANIMATEDFACE | bits_CAP_TURN_HEAD);
NPCInit();
}
//=========================================================
// Precache - precaches all resources this monster needs
//=========================================================
void CNPC_GMan::Precache()
{
PrecacheModel( "models/gman.mdl" );
}
//=========================================================
// AI Schedules Specific to this monster
//=========================================================
void CNPC_GMan::StartTask( const Task_t *pTask )
{
switch( pTask->iTask )
{
case TASK_WAIT:
if (m_hPlayer == NULL)
{
m_hPlayer = gEntList.FindEntityByClassname( NULL, "player" );
}
break;
}
BaseClass::StartTask( pTask );
}
void CNPC_GMan::RunTask( const Task_t *pTask )
{
switch( pTask->iTask )
{
case TASK_WAIT:
// look at who I'm talking to
if (m_flTalkTime > gpGlobals->curtime && m_hTalkTarget != NULL)
{
AddLookTarget( m_hTalkTarget->GetAbsOrigin(), 1.0, 2.0 );
}
// look at player, but only if playing a "safe" idle animation
else if (m_hPlayer != NULL && (GetSequence() == 0 || IsInC5A1()) )
{
AddLookTarget( m_hPlayer->EyePosition(), 1.0, 3.0 );
}
else
{
// Just center the head forward.
Vector forward;
GetVectors( &forward, NULL, NULL );
AddLookTarget( GetAbsOrigin() + forward * 12.0f, 1.0, 1.0 );
SetBoneController( 0, 0 );
}
BaseClass::RunTask( pTask );
break;
}
SetBoneController( 0, 0 );
BaseClass::RunTask( pTask );
}
//=========================================================
// Override all damage
//=========================================================
int CNPC_GMan::OnTakeDamage_Alive( const CTakeDamageInfo &inputInfo )
{
m_iHealth = m_iMaxHealth / 2; // always trigger the 50% damage aitrigger
if ( inputInfo.GetDamage() > 0 )
SetCondition( COND_LIGHT_DAMAGE );
if ( inputInfo.GetDamage() >= 20 )
SetCondition( COND_HEAVY_DAMAGE );
return TRUE;
}
void CNPC_GMan::TraceAttack( CBaseEntity *pAttacker, float flDamage, const Vector &vecDir, trace_t *ptr, int bitsDamageType)
{
g_pEffects->Ricochet( ptr->endpos, ptr->plane.normal );
// AddMultiDamage( pevAttacker, this, flDamage, bitsDamageType );
}
int CNPC_GMan::PlayScriptedSentence( const char *pszSentence, float delay, float volume, soundlevel_t soundlevel, bool bConcurrent, CBaseEntity *pListener )
{
BaseClass::PlayScriptedSentence( pszSentence, delay, volume, soundlevel, bConcurrent, pListener );
m_flTalkTime = gpGlobals->curtime + delay;
m_hTalkTarget = pListener;
return 1;
}
|