aboutsummaryrefslogtreecommitdiff
path: root/sp/src/game/client/hl2/c_npc_antlionguard.cpp
blob: e2c7232a03f8f5b51e22a0a78b4caeb0ded333ac (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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Client side antlion guard. Used to create dlight for the cave guard.
//
//=============================================================================

#include "cbase.h"
#include "c_ai_basenpc.h"
#include "dlight.h"
#include "iefx.h"

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


#if HL2_EPISODIC
// When enabled, add code to have the antlion bleed profusely as it is badly injured.
#define ANTLIONGUARD_BLOOD_EFFECTS 2
#endif


class C_NPC_AntlionGuard : public C_AI_BaseNPC
{
public:
	C_NPC_AntlionGuard() {}

	DECLARE_CLASS( C_NPC_AntlionGuard, C_AI_BaseNPC );
	DECLARE_CLIENTCLASS();
 	DECLARE_DATADESC();

	virtual void OnDataChanged( DataUpdateType_t type );
	virtual void ClientThink();

private:

	bool m_bCavernBreed;
	bool m_bInCavern;
	dlight_t *m_dlight;

#if HL2_EPISODIC
	unsigned char m_iBleedingLevel; //< the version coming from the server
	unsigned char m_iPerformingBleedingLevel; //< the version we're currently performing (for comparison to one above)
	CNewParticleEffect *m_pBleedingFX;

	/// update the hemorrhage particle effect
	virtual void UpdateBleedingPerformance( void );
#endif

	C_NPC_AntlionGuard( const C_NPC_AntlionGuard & );
};


//-----------------------------------------------------------------------------
// Save/restore
//-----------------------------------------------------------------------------
BEGIN_DATADESC( C_NPC_AntlionGuard )
END_DATADESC()


//-----------------------------------------------------------------------------
// Networking
//-----------------------------------------------------------------------------
IMPLEMENT_CLIENTCLASS_DT(C_NPC_AntlionGuard, DT_NPC_AntlionGuard, CNPC_AntlionGuard)
	RecvPropBool( RECVINFO( m_bCavernBreed ) ),
	RecvPropBool( RECVINFO( m_bInCavern ) ),

#if ANTLIONGUARD_BLOOD_EFFECTS
	RecvPropInt(  RECVINFO( m_iBleedingLevel ) ),
#endif
END_RECV_TABLE()


//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void C_NPC_AntlionGuard::OnDataChanged( DataUpdateType_t type )
{
	BaseClass::OnDataChanged( type );

	if ( (type == DATA_UPDATE_CREATED) && m_bCavernBreed && m_bInCavern )
	{
		SetNextClientThink( CLIENT_THINK_ALWAYS );
	}


#if HL2_EPISODIC
	if (m_iBleedingLevel != m_iPerformingBleedingLevel)
	{
		UpdateBleedingPerformance();
	}
#endif

}

#if HL2_EPISODIC
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void C_NPC_AntlionGuard::UpdateBleedingPerformance()
{
	// get my particles
	CParticleProperty * pProp = ParticleProp();

	// squelch the prior effect if it exists
	if (m_pBleedingFX)
	{
		pProp->StopEmission(m_pBleedingFX);
		m_pBleedingFX = NULL;
	}

	// kick off a new effect
	switch (m_iBleedingLevel)
	{
	case 1: // light bleeding
		{
			m_pBleedingFX = pProp->Create( "blood_antlionguard_injured_light", PATTACH_ABSORIGIN_FOLLOW );
			AssertMsg1( m_pBleedingFX, "Particle system couldn't make %s", "blood_antlionguard_injured_light" );
			if ( m_pBleedingFX )
			{
				pProp->AddControlPoint( m_pBleedingFX, 1, this, PATTACH_ABSORIGIN_FOLLOW );
			}
		}
		break;

	case 2: // severe bleeding
		{
			m_pBleedingFX = pProp->Create( "blood_antlionguard_injured_heavy", PATTACH_ABSORIGIN_FOLLOW );
			AssertMsg1( m_pBleedingFX, "Particle system couldn't make %s", "blood_antlionguard_injured_heavy" );
			if ( m_pBleedingFX )
			{
				pProp->AddControlPoint( m_pBleedingFX, 1, this, PATTACH_ABSORIGIN_FOLLOW );
			}

		}
		break;
	}

	m_iPerformingBleedingLevel = m_iBleedingLevel;
}
#endif

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void C_NPC_AntlionGuard::ClientThink()
{
	// update the dlight. (always done because clienthink only exists for cavernguard)
	if (!m_dlight)
	{
		m_dlight = effects->CL_AllocDlight( index );
		m_dlight->color.r = 220;
		m_dlight->color.g = 255;
		m_dlight->color.b = 80;
		m_dlight->radius	= 180;
		m_dlight->minlight = 128.0 / 256.0f;
		m_dlight->flags = DLIGHT_NO_MODEL_ILLUMINATION;
	}

	m_dlight->origin	= GetAbsOrigin();
	// dl->die = gpGlobals->curtime + 0.1f;

	BaseClass::ClientThink();
}