summaryrefslogtreecommitdiff
path: root/game/server/tf2/info_input_respawnplayers.cpp
blob: 4b9917ffa864e987ebb54b4ba81878d7c1a2a4f6 (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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "EntityOutput.h"
#include "EntityList.h"
#include "tf_team.h"
#include "baseentity.h"

// Spawnflags
const int SF_RESPAWNPLAYERS_RESETALL		= 0x01;	// Respawned players have their inventory completely reset
const int SF_RESPAWNPLAYERS_RESETAMMO		= 0x02;	// Respawned players have their ammo counts reset

//-----------------------------------------------------------------------------
// Purpose: Map entity that respawns players
//-----------------------------------------------------------------------------
class CInfoInputRespawnPlayers : public CBaseEntity
{
	DECLARE_CLASS( CInfoInputRespawnPlayers, CBaseEntity );
public:
	DECLARE_DATADESC();

	// Inputs
	void InputRespawnAll( inputdata_t &inputdata );
	void InputRespawnTeam1( inputdata_t &inputdata );
	void InputRespawnTeam2( inputdata_t &inputdata );
	void InputRespawnPlayer( inputdata_t &inputdata );

	// Respawning
	void RespawnPlayer( CBaseTFPlayer *pPlayer );
	void RespawnTeam( CTFTeam *pTeam );
};

BEGIN_DATADESC( CInfoInputRespawnPlayers )

	// inputs
	DEFINE_INPUTFUNC( FIELD_VOID, "RespawnAll", InputRespawnAll ),
	DEFINE_INPUTFUNC( FIELD_VOID, "RespawnTeam1", InputRespawnTeam1 ),
	DEFINE_INPUTFUNC( FIELD_VOID, "RespawnTeam2", InputRespawnTeam2 ),
	DEFINE_INPUTFUNC( FIELD_EHANDLE, "RespawnPlayer", InputRespawnPlayer ),

END_DATADESC()

LINK_ENTITY_TO_CLASS( info_input_respawnplayers, CInfoInputRespawnPlayers );

//-----------------------------------------------------------------------------
// Purpose: Respawn all the players
//-----------------------------------------------------------------------------
void CInfoInputRespawnPlayers::InputRespawnAll( inputdata_t &inputdata )
{
	for ( int i = 0; i < MAX_TF_TEAMS; i++ )
	{
		RespawnTeam( GetGlobalTFTeam(i+1) );
	}
}

//-----------------------------------------------------------------------------
// Purpose: Respawn all of team 1's players
//-----------------------------------------------------------------------------
void CInfoInputRespawnPlayers::InputRespawnTeam1( inputdata_t &inputdata )
{
	RespawnTeam( GetGlobalTFTeam(1) );
}

//-----------------------------------------------------------------------------
// Purpose: Respawn all of team 2's players
//-----------------------------------------------------------------------------
void CInfoInputRespawnPlayers::InputRespawnTeam2( inputdata_t &inputdata )
{
	RespawnTeam( GetGlobalTFTeam(2) );
}

//-----------------------------------------------------------------------------
// Purpose: Respawn a specific player
//-----------------------------------------------------------------------------
void CInfoInputRespawnPlayers::InputRespawnPlayer( inputdata_t &inputdata )
{
	CBaseEntity *pEntity = (inputdata.value.Entity()).Get();
	if ( pEntity && pEntity->IsPlayer() )
	{
		CBaseTFPlayer *pPlayer = (CBaseTFPlayer *)pEntity;
		RespawnPlayer( pPlayer );
	}
}

//-----------------------------------------------------------------------------
// Purpose: Respawn the team
//-----------------------------------------------------------------------------
void CInfoInputRespawnPlayers::RespawnTeam( CTFTeam *pTeam )
{
	Assert( pTeam );
	if ( !pTeam )
		return;

	// Respawn all the players
	for ( int i = 0; i < pTeam->GetNumPlayers(); i++ )
	{
		RespawnPlayer( (CBaseTFPlayer*)pTeam->GetPlayer(i) );
	}
}

//-----------------------------------------------------------------------------
// Purpose: Respawn the player
//-----------------------------------------------------------------------------
void CInfoInputRespawnPlayers::RespawnPlayer( CBaseTFPlayer *pPlayer )
{
	// Reset ammo if the spawnflag's set
	if ( HasSpawnFlags( SF_RESPAWNPLAYERS_RESETALL ) )
	{
		pPlayer->ResupplyAmmo( 1.0, RESUPPLY_ALL_FROM_STATION );
	}
	else if ( HasSpawnFlags( SF_RESPAWNPLAYERS_RESETAMMO ) )
	{
		pPlayer->ResupplyAmmo( 1.0, RESUPPLY_RESPAWN );
	}

	pPlayer->ForceRespawn();
}