aboutsummaryrefslogtreecommitdiff
path: root/mp/src/game/server/hl2/npc_barnacle.h
blob: bcb191cf01eb57bf17fd6e30a99cd7a4d075eb4f (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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
//=============================================================================//

#ifndef NPC_BARNACLE_H
#define NPC_BARNACLE_H
#ifdef _WIN32
#pragma once
#endif

#include "ai_basenpc.h"
#include "studio.h"
#include "physics_prop_ragdoll.h"

class CNPC_Barnacle;


#define BARNACLE_PULL_SPEED			80
#define BARNACLE_KILL_VICTIM_DELAY	5 // how many seconds after pulling prey in to gib them. 

// Tongue
#define BARNACLE_TONGUE_POINTS	8

#define BARNACLE_MIN_PULL_TIME	3.0f

#define NUM_BARNACLE_GIBS	4

#define	SF_BARNACLE_CHEAP_DEATH	(1<<16)	// Don't spawn as many gibs
#define	SF_BARNACLE_AMBUSH	(1<<17)	// Start with tongue retracted and wait for input.

// when true, causes the barnacle's visible tongue to offset
// from the physical one when pulling the player.
#define BARNACLE_USE_TONGUE_OFFSET 1


//-----------------------------------------------------------------------------
// Purpose: This is the entity we place at the top & bottom of the tongue, to create a vphysics spring
//-----------------------------------------------------------------------------
class CBarnacleTongueTip : public CBaseAnimating
{
	DECLARE_CLASS( CBarnacleTongueTip, CBaseAnimating );

public:
	DECLARE_DATADESC();

	virtual void Spawn( void );
	virtual void Precache( void );
	virtual void UpdateOnRemove( );
	virtual void VPhysicsUpdate( IPhysicsObject *pPhysics );

	virtual int	UpdateTransmitState( void );
	bool						CreateSpring( CBaseAnimating *pTongueRoot );
	static CBarnacleTongueTip	*CreateTongueTip( CNPC_Barnacle *pBarnacle, CBaseAnimating *pTongueRoot, const Vector &vecOrigin, const QAngle &vecAngles );
	static CBarnacleTongueTip	*CreateTongueRoot( const Vector &vecOrigin, const QAngle &vecAngles );

	IPhysicsSpring			*m_pSpring;

private:
	CHandle<CNPC_Barnacle>	m_hBarnacle;
};

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
class CNPC_Barnacle : public CAI_BaseNPC
{
	DECLARE_CLASS( CNPC_Barnacle, CAI_BaseNPC );
public:
	DECLARE_SERVERCLASS();
	DECLARE_DATADESC();

	CNPC_Barnacle();
	~CNPC_Barnacle();

	void			Spawn( void );
	virtual void	Activate( void );
	void			Precache( void );
	Class_T			Classify ( void );
	virtual void	ComputeWorldSpaceSurroundingBox( Vector *pVecWorldMins, Vector *pVecWorldMaxs );
	virtual void	HandleAnimEvent( animevent_t *pEvent );
	void			Event_Killed( const CTakeDamageInfo &info );
	int				OnTakeDamage_Alive( const CTakeDamageInfo &info );
	void			PlayerHasIlluminatedNPC( CBasePlayer *pPlayer, float flDot );

	// The tongue's vphysics updated
	void OnTongueTipUpdated();

private:
	void SetAltitude( float flAltitude );
	void SpawnDeathGibs( void );

	void InitTonguePosition( void );
	CBaseEntity* TongueTouchEnt ( float *pflLength );
	void BarnacleThink ( void );
	void SwallowPrey( void );
	void WaitTillDead ( void );
 	void AttachTongueToTarget( CBaseEntity *pTouchEnt, Vector vecGrabPos );
	CRagdollProp *AttachRagdollToTongue( CBaseAnimating *pAnimating );
	void RemoveRagdoll( bool bDestroyRagdoll );
	void LostPrey( bool bRemoveRagdoll );
	void BitePrey( void );

	// Updates the tongue length
	void UpdateTongue( void );

	// Spit out the prey; add physics force!
	void SpitPrey();

	void SprayBlood();

	// What type of enemy do we have?
	bool IsEnemyAPlayer();
	bool IsEnemyARagdoll();
	bool IsEnemyAPhysicsObject();
	bool IsEnemyAnNPC();

	bool CanPickup( CBaseCombatCharacter *pBCC );

	// Allows the ragdoll to settle before biting it
	bool WaitForRagdollToSettle( float flBiteZOffset );

	// Allows the physics prop to settle before biting it
	bool WaitForPhysicsObjectToSettle( float flBiteZOffset );

	// Play a scream right before biting
	void PlayLiftingScream( float flBiteZOffset );

	// Pulls the prey upward toward the mouth
	void PullEnemyTorwardsMouth( bool bAdjustEnemyOrigin );

	// Lift the prey stuck to our tongue up towards our mouth
	void LiftPrey( void );
	void LiftPlayer( float flBiteZOffset );
	void LiftRagdoll( float flBiteZOffset );
	void LiftPhysicsObject( float flBiteZOffset );
	void LiftNPC( float flBiteZOffset );

	void UpdatePlayerConstraint( void );

	void InputDropTongue( inputdata_t &inputdata );
	void InputSetDropTongueSpeed( inputdata_t &inputdata );
	void DropTongue( void );



#if HL2_EPISODIC
	/// Decides whether something should poison the barnacle upon eating
	static bool IsPoisonous( CBaseEntity *pVictim );

	void InputLetGo( inputdata_t &inputdata );
	COutputEHANDLE m_OnGrab, m_OnRelease;

	const impactdamagetable_t &GetPhysicsImpactDamageTable( void );
#endif

	CNetworkVar( float, m_flAltitude );
	int				m_cGibs;				// barnacle loads up on gibs each time it kills something.
	bool			m_bLiftingPrey;			// true when the prey's on the tongue and being lifted to the mouth
	bool			m_bSwallowingPrey;		// if it's a human, true while the barnacle chews it and swallows it whole. 
	float			m_flDigestFinish;		// time at which we've finished digesting something we chewed
	float			m_flVictimHeight;
	int				m_iGrabbedBoneIndex;
	bool			m_bPlayedPullSound;
	bool			m_bPlayerWasStanding;
	
	static const char	*m_szGibNames[NUM_BARNACLE_GIBS];

	// Tongue spline points
	CNetworkVar( Vector, m_vecRoot );
	CNetworkVar( Vector, m_vecTip );
	CNetworkVar( Vector, m_vecTipDrawOffset );

	// Tongue tip & root
	CHandle<CBarnacleTongueTip>	m_hTongueRoot;
	CHandle<CBarnacleTongueTip>	m_hTongueTip;
	CHandle<CRagdollProp>		m_hRagdoll;
	matrix3x4_t					m_pRagdollBones[MAXSTUDIOBONES];
	IPhysicsConstraint			*m_pConstraint;
	float						m_flRestUnitsAboveGround;
	int							m_nSpitAttachment;
	EHANDLE						m_hLastSpitEnemy;
	int							m_nShakeCount;

	float						m_flNextBloodTime;
#ifndef _XBOX
	int							m_nBloodColor;
#endif
	Vector						m_vecBloodPos;

	float						m_flBarnaclePullSpeed;
	float						m_flLocalTimer;

	Vector						m_vLastEnemyPos;
	float						m_flLastPull;
	CSimpleSimTimer				m_StuckTimer;
	bool						m_bSwallowingBomb;
#ifdef HL2_EPISODIC
	bool						m_bSwallowingPoison;
#endif
	
#if BARNACLE_USE_TONGUE_OFFSET
	// Static because only one barnacle can be holding the player
	// at a time, and because it's not really a big deal if it
	// resets to zero after reload.
	const static Vector				m_svPlayerHeldTipOffset;
#endif

	DEFINE_CUSTOM_AI;
};


//-----------------------------------------------------------------------------
// What type of enemy do we have?
//-----------------------------------------------------------------------------
inline bool CNPC_Barnacle::IsEnemyAPlayer()
{
	return GetEnemy() && GetEnemy()->IsPlayer();
}

inline bool CNPC_Barnacle::IsEnemyARagdoll()
{
	return m_hRagdoll != NULL;
}

inline bool CNPC_Barnacle::IsEnemyAPhysicsObject()
{
	return !m_hRagdoll && GetEnemy() && !GetEnemy()->IsPlayer() && 
		!GetEnemy()->MyNPCPointer() && (GetEnemy()->GetMoveType() == MOVETYPE_VPHYSICS);
}

inline bool CNPC_Barnacle::IsEnemyAnNPC()
{
	return !IsEnemyARagdoll() && (GetEnemy()->MyNPCPointer() != NULL);
}


#endif // NPC_BARNACLE_H