aboutsummaryrefslogtreecommitdiff
path: root/mp/src/game/server/hl2/npc_alyx.cpp
blob: f9dc1286351cc67fb0e974941c05298951fcee6f (plain) (blame)
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Alyx, the female sidekick and love interest that's taking the world by storm!
//
//			Try the new Alyx Brite toothpaste!
//			Alyx lederhosen!
//
//			FIXME: need a better comment block
//
//=============================================================================//

#include "cbase.h"
#include "npcevent.h"
#include "ai_basenpc.h"
#include "ai_hull.h"
#include "ai_basehumanoid.h"
#include "npc_alyx.h"
#include "ai_senses.h"
#include "soundent.h"
#include "props.h"

// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"

LINK_ENTITY_TO_CLASS( npc_alyx, CNPC_Alyx );

BEGIN_DATADESC( CNPC_Alyx )

	DEFINE_FIELD( m_hEmpTool, FIELD_EHANDLE ),

END_DATADESC()

int AE_ALYX_EMPTOOL_ATTACHMENT;
int AE_ALYX_EMPTOOL_SEQUENCE;

//=========================================================
// Classify - indicates this NPC's place in the 
// relationship table.
//=========================================================
Class_T	CNPC_Alyx::Classify ( void )
{
	return	CLASS_PLAYER_ALLY_VITAL;
}


//=========================================================
// HandleAnimEvent - catches the NPC-specific messages
// that occur when tagged animation frames are played.
//=========================================================
void CNPC_Alyx::HandleAnimEvent( animevent_t *pEvent )
{
	if (pEvent->event == AE_ALYX_EMPTOOL_ATTACHMENT)
	{
		if (!m_hEmpTool)
		{
			// Old savegame?
			CreateEmpTool();
			if (!m_hEmpTool)
				return;
		}

		int iAttachment = LookupAttachment( pEvent->options );
		m_hEmpTool->SetParent(this, iAttachment);
		m_hEmpTool->SetLocalOrigin( Vector( 0, 0, 0 ) );
		m_hEmpTool->SetLocalAngles( QAngle( 0, 0, 0 ) );

		return;
	}
	else if (pEvent->event == AE_ALYX_EMPTOOL_SEQUENCE)
	{
		if (!m_hEmpTool)
			return;

		CDynamicProp *pEmpTool = dynamic_cast<CDynamicProp *>(m_hEmpTool.Get());

		if (!pEmpTool)
			return;

		int iSequence = pEmpTool->LookupSequence( pEvent->options );
		if (iSequence != ACT_INVALID)
		{
			pEmpTool->PropSetSequence( iSequence );
		}

		return;
	}

	switch( pEvent->event )
	{
	case 1:
	default:
		BaseClass::HandleAnimEvent( pEvent );
		break;
	}
}

//=========================================================
// 
//=========================================================
bool CNPC_Alyx::CreateBehaviors()
{
	return BaseClass::CreateBehaviors();
}


//=========================================================
// Spawn
//=========================================================
void CNPC_Alyx::Spawn()
{
	BaseClass::Spawn();

	// If Alyx has a parent, she's currently inside a pod. Prevent her from moving.
	if ( GetMoveParent() )
	{
		SetMoveType( MOVETYPE_NONE );
		CapabilitiesClear();

		CapabilitiesAdd( bits_CAP_ANIMATEDFACE | bits_CAP_TURN_HEAD );
		CapabilitiesAdd( bits_CAP_FRIENDLY_DMG_IMMUNE );
	}
	else
	{
		SetupAlyxWithoutParent();
		CreateEmpTool( );
	}

	AddEFlags( EFL_NO_DISSOLVE | EFL_NO_MEGAPHYSCANNON_RAGDOLL | EFL_NO_PHYSCANNON_INTERACTION );

	m_iHealth			= 80;

	NPCInit();
}

//=========================================================
// Precache - precaches all resources this NPC needs
//=========================================================
void CNPC_Alyx::Precache()
{
	BaseClass::Precache();
	PrecacheScriptSound( "npc_alyx.die" );
	PrecacheModel( STRING( GetModelName() ) );
	PrecacheModel( "models/alyx_emptool_prop.mdl" );
}	

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CNPC_Alyx::SelectModel()
{
	// Alyx is allowed to use multiple models, because she appears in the pod.
	// She defaults to her normal model.
	const char *szModel = STRING( GetModelName() );
	if (!szModel || !*szModel)
	{
		SetModelName( AllocPooledString("models/alyx.mdl") );
	}
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CNPC_Alyx::SetupAlyxWithoutParent( void )
{
	SetSolid( SOLID_BBOX );
	AddSolidFlags( FSOLID_NOT_STANDABLE );
	SetMoveType( MOVETYPE_STEP );

	CapabilitiesAdd( bits_CAP_MOVE_GROUND | bits_CAP_DOORS_GROUP | bits_CAP_TURN_HEAD | bits_CAP_DUCK | bits_CAP_SQUAD );
	CapabilitiesAdd( bits_CAP_USE_WEAPONS );
	CapabilitiesAdd( bits_CAP_ANIMATEDFACE );
	CapabilitiesAdd( bits_CAP_FRIENDLY_DMG_IMMUNE );
	CapabilitiesAdd( bits_CAP_AIM_GUN );
	CapabilitiesAdd( bits_CAP_MOVE_SHOOT );
	CapabilitiesAdd( bits_CAP_USE_SHOT_REGULATOR );
}


//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------

void CNPC_Alyx::CreateEmpTool( void )
{
	m_hEmpTool = (CBaseAnimating*)CreateEntityByName( "prop_dynamic" );
	if ( m_hEmpTool )
	{
		m_hEmpTool->SetModel( "models/alyx_emptool_prop.mdl" );
		m_hEmpTool->SetName( AllocPooledString("Alyx_Emptool") );
		int iAttachment = LookupAttachment( "Emp_Holster" );
		m_hEmpTool->SetParent(this, iAttachment);
		m_hEmpTool->SetOwnerEntity(this);
		m_hEmpTool->SetSolid( SOLID_NONE );
		m_hEmpTool->SetLocalOrigin( Vector( 0, 0, 0 ) );
		m_hEmpTool->SetLocalAngles( QAngle( 0, 0, 0 ) );
		m_hEmpTool->Spawn();
	}
}




//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CNPC_Alyx::PrescheduleThink( void )
{
	BaseClass::PrescheduleThink();

	// Figure out if Alyx has just been removed from her parent
	if ( GetMoveType() == MOVETYPE_NONE && !GetMoveParent() )
	{
		SetupAlyxWithoutParent();
		SetupVPhysicsHull();
	}

	if ( HasCondition( COND_TALKER_PLAYER_DEAD ) )
	{
		SpeakIfAllowed( TLK_PLDEAD );
	}
}

//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
Activity CNPC_Alyx::NPC_TranslateActivity( Activity activity )
{
	activity = BaseClass::NPC_TranslateActivity( activity );
	if ( activity == ACT_IDLE && (m_NPCState == NPC_STATE_COMBAT || m_NPCState == NPC_STATE_ALERT) )
	{
		if (gpGlobals->curtime - m_flLastAttackTime < 3 || gpGlobals->curtime - GetEnemyLastTimeSeen() < 8)
		{
			activity = ACT_IDLE_ANGRY;
		}
	}

	return activity;
}

//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------

void CNPC_Alyx::TraceAttack( const CTakeDamageInfo &info, const Vector &vecDir, trace_t *ptr, CDmgAccumulator *pAccumulator )
{
	BaseClass::TraceAttack( info, vecDir, ptr, pAccumulator );

	// FIXME: hack until some way of removing decals after healing
	m_fNoDamageDecal = true;
}

//-----------------------------------------------------------------------------

void CNPC_Alyx::DeathSound( const CTakeDamageInfo &info )
{
	// Sentences don't play on dead NPCs
	SentenceStop();

	EmitSound( "npc_alyx.die" );
}

//=========================================================
// AI Schedules Specific to this NPC
//=========================================================

AI_BEGIN_CUSTOM_NPC( npc_alyx, CNPC_Alyx )

	DECLARE_ANIMEVENT( AE_ALYX_EMPTOOL_ATTACHMENT )
	DECLARE_ANIMEVENT( AE_ALYX_EMPTOOL_SEQUENCE )

AI_END_CUSTOM_NPC()