summaryrefslogtreecommitdiff
path: root/game/server/tf2/tf_player_death.cpp
blob: da90f9e906634f235e1772bebd6fe7dd7db2de47 (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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: CBaseTFPlayer functions dealing with death and reinforcement
//
// $Workfile:     $
// $Date:         $
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "player.h"
#include "tf_player.h"
#include "gamerules.h"
#include "basecombatweapon.h"
#include "EntityList.h"
#include "tf_shareddefs.h"
#include "tf_team.h"
#include "baseviewmodel.h"
#include "tf_class_infiltrator.h"
#include "in_buttons.h"
#include "globals.h"

int				g_iNumberOfCorpses;

//-----------------------------------------------------------------------------
// Purpose: The player was just killed
//-----------------------------------------------------------------------------
void CBaseTFPlayer::Event_Killed( const CTakeDamageInfo &info )
{
	// TODO don't use temp entities to transmit messages
	CPASFilter filter( GetLocalOrigin() );
	te->KillPlayerAttachments( filter, 0.0, entindex() );

	// Remove the player from any vehicle they're in
	if ( IsInAVehicle() )
	{
		LeaveVehicle();
	}

	// Holster weapon immediately, to allow it to cleanup
	if (GetActiveWeapon())
	{
		GetActiveWeapon()->Holster( );
	}

	// Stop attaching sappers
	if ( IsAttachingSapper() )
	{
		StopAttaching();
	}

	// stop them touching anything
	AddFlag( FL_DONTTOUCH );

	g_pGameRules->PlayerKilled( this, info );

	ClearUseEntity();

	// If I'm ragdolling due to a knockdown, don't play any animations
	if ( m_hRagdollShadow == NULL )
	{
		if ( PlayerClass() != TFCLASS_INFILTRATOR )
		{
			// Calculate death force
			Vector forceVector = CalcDamageForceVector( info );

			BecomeRagdollOnClient( forceVector );
		}
		else
		{
			SetAnimation( PLAYER_DIE );
		}
	}

	DeathSound( info );

	SetViewOffset( VEC_DEAD_VIEWHEIGHT_SCALED( this ) );
	m_lifeState		= LIFE_DYING;
	pl.deadflag = true;

	// Enter dying state
	AddSolidFlags( FSOLID_NOT_SOLID );
	SetMoveType( MOVETYPE_NONE );
	QAngle angles = GetLocalAngles();
	angles.x = angles.z = 0;
	SetLocalAngles( angles );
	m_takedamage = DAMAGE_NO;

	// clear out the suit message cache so we don't keep chattering
	SetSuitUpdate(NULL, false, 0);

	// reset FOV
	SetFOV( this, 0 );

	// Setup for respawn
	m_flTimeOfDeath = gpGlobals->curtime;

	SetThink(TFPlayerDeathThink);
	SetNextThink( gpGlobals->curtime + 0.1f );

	SetPowerup(POWERUP_EMP,false);

	// Tell the playerclass that the player died
	if ( GetPlayerClass()  )
	{
		GetPlayerClass()->PlayerDied( info.GetAttacker() );
	}

	// Tell the attacker's playerclass that he killed someone
	if ( info.GetAttacker() && info.GetAttacker()->IsPlayer() )
	{
		CBaseTFPlayer *pPlayerAttacker = (CBaseTFPlayer*)info.GetAttacker();
		pPlayerAttacker->KilledPlayer( this );
	}

	DropAllResourceChunks();

	// Tell all teams to update their orders
	COrderEvent_PlayerKilled order( this );
	GlobalOrderEvent( &order );
}

//-----------------------------------------------------------------------------
// Purpose: Think function for dead/dying players.
//			Play their death animation, then set up for reinforcement.
//-----------------------------------------------------------------------------
void CBaseTFPlayer::TFPlayerDeathThink(void)
{
	float flForward;

	SetNextThink( gpGlobals->curtime + 0.1f );

	if ( GetFlags() & FL_ONGROUND )
	{
		flForward = GetAbsVelocity().Length() - 20;
		if (flForward <= 0)
		{
			SetAbsVelocity( vec3_origin );
		}
		else
		{
			Vector vecNewVelocity = GetAbsVelocity();
			VectorNormalize( vecNewVelocity );
			vecNewVelocity *= flForward;
			SetAbsVelocity( vecNewVelocity );
		}
	}

	StudioFrameAdvance();

	if (GetModelIndex() && (!IsSequenceFinished()) && (m_lifeState == LIFE_DYING))
	{
		m_iRespawnFrames++;
		if ( m_iRespawnFrames < 60 )  // animations should be no longer than this
			return;
	}

	// Start looping dying state
	SetAnimation( PLAYER_DIE );

	// ROBIN: Everyone respawns immediately now. Maps will define respawns in the future.

	if ( (gpGlobals->curtime - m_flTimeOfDeath) < 3 ) 
		return;

	m_lifeState = LIFE_RESPAWNABLE;
		
	// Respawn on button press, but not if they're checking the scores
	// Also respawn if they're not looking at scores, and they've been dead for over 5 seconds
	bool bButtonDown = (m_nButtons & ~IN_SCORE) > 0;
	if ( (bButtonDown || (gpGlobals->curtime - m_flTimeOfDeath) > 5 ) )
	{
		PlayerRespawn();
	}

	/*
	// Aliens become respawnable immediately, because they're waiting for a reinforcement wave.
	// Humans have to wait a short time.
	if ( (GetTeamNumber() == TEAM_HUMANS) && (gpGlobals->curtime - m_flTimeOfDeath) < 3 ) 
		return;
	if ( (GetTeamNumber() == TEAM_ALIENS) && (gpGlobals->curtime - m_flTimeOfDeath) < 1 ) 
		return;

	// Humans can respawn, Aliens can't (reinforcement wave for their kind)
	// Aliens stop thinking now and wait for the reinforcement wave
	if ( GetTeamNumber() == TEAM_ALIENS )
	{
		m_lifeState = LIFE_RESPAWNABLE;
		SetThink( NULL );
	}
	else
	{
		m_lifeState = LIFE_RESPAWNABLE;
		
		// Respawn on button press
		if ( m_nButtons & ~IN_SCORE )
		{
			PlayerRespawn();
		}
	}
	*/
}

//-----------------------------------------------------------------------------
// Purpose: Return true if this player is ready to reinforce
//-----------------------------------------------------------------------------
bool CBaseTFPlayer::IsReadyToReinforce( void )
{
	// Only Aliens reinforce in waves, humans respawn normally
	if ( (GetTeamNumber() == TEAM_ALIENS) && (m_lifeState == LIFE_RESPAWNABLE) )
		return true;

	return false;
}

//-----------------------------------------------------------------------------
// Purpose: Bring the player back to life in a reinforcement wave
//-----------------------------------------------------------------------------
void CBaseTFPlayer::Reinforce( void )
{
	// Tell all teams to update their orders
	COrderEvent_PlayerRespawned order( this );
	GlobalOrderEvent( &order );

	StopAnimation();
	IncrementInterpolationFrame();
	m_flPlaybackRate = 0.0;

	PlayerRespawn();
}