summaryrefslogtreecommitdiff
path: root/game/server/tf2/tf_obj_respawn_station.cpp
blob: 2888679416365f85b9a173e7df82efbc3072ef0b (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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Medic's resupply beacon
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "tf_obj.h"
#include "tf_player.h"
#include "tf_team.h"
#include "techtree.h"
#include "tf_shield.h"
#include "tf_obj_respawn_station.h"

IMPLEMENT_SERVERCLASS_ST(CObjectRespawnStation, DT_ObjectRespawnStation)
END_SEND_TABLE();

BEGIN_DATADESC( CObjectRespawnStation )

	// keys 
	DEFINE_KEYFIELD_NOT_SAVED( m_bIsInitialSpawnPoint,	FIELD_BOOLEAN, "InitialSpawn" ),

END_DATADESC()

LINK_ENTITY_TO_CLASS(obj_respawn_station, CObjectRespawnStation);
PRECACHE_REGISTER(obj_respawn_station);

ConVar	obj_respawnstation_health( "obj_respawnstation_health","300", FCVAR_NONE, "Respawn Station health" );

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
CObjectRespawnStation::CObjectRespawnStation()
{
	m_bIsInitialSpawnPoint = false;
	UseClientSideAnimation();
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CObjectRespawnStation::Precache()
{
	PrecacheModel( "models/objects/obj_respawn_station.mdl" );
	m_iSpriteTexture = PrecacheModel( "sprites/laserbeam.vmt" );
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CObjectRespawnStation::Spawn()
{
	Precache();
	SetMoveType( MOVETYPE_NONE );
	SetSolid( SOLID_BBOX );

	SetModel( "models/objects/obj_respawn_station.mdl" );

	UTIL_SetSize(this, RESPAWN_STATION_MINS, RESPAWN_STATION_MAXS);

	m_iHealth = m_iMaxHealth = obj_respawnstation_health.GetInt();
	m_takedamage = DAMAGE_YES;
	m_fLastRespawnTime = -99999;

	SetType( OBJ_RESPAWN_STATION );

	BaseClass::Spawn();
}


//-----------------------------------------------------------------------------
// Object using!
//-----------------------------------------------------------------------------
void CObjectRespawnStation::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
{
	// Sapper removal
	if ( RemoveEnemyAttachments( pActivator ) )
		return;

	// See if the activator is a player
	if ( pActivator->IsPlayer() )
	{
		CBaseTFPlayer *player = static_cast< CBaseTFPlayer * >( pActivator );
		player->SetRespawnStation( this );
	}

	BaseClass::Use( pActivator, pCaller, useType, value );
}



//-----------------------------------------------------------------------------
// Gets called when someone respawns on this station
//-----------------------------------------------------------------------------
void CObjectRespawnStation::PerformRespawnEffect()
{
	if (gpGlobals->curtime - m_fLastRespawnTime > RESPAWN_EFFECT_TIME)
	{
		Vector vecEnd;
		VectorAdd( GetAbsOrigin(), Vector( 0, 0, RESPAWN_BEAM_HEIGHT ), vecEnd );

		CBroadcastRecipientFilter filter;
		te->BeamPoints( filter, 0.0,
			&GetAbsOrigin(), 
			&vecEnd, 
			m_iSpriteTexture, 
			0,		// Halo index
			0,		// Start frame
			15,		// Frame rate
			3.0,	// Life
			50,		// Width
			50,		// EndWidth
			0,		// FadeLength
			0,		// Amplitude
			100,	// r
			200,	// g
			255,	// b
			255,	// a
			20	);	// speed

		m_fLastRespawnTime = gpGlobals->curtime;
	}
}


//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
CObjectRespawnStation* CObjectRespawnStation::Create(const Vector &vOrigin, const QAngle &vAngles )
{
	CObjectRespawnStation *pRet = (CObjectRespawnStation*)CreateEntityByName("obj_respawn_station");
	if(pRet)
	{
		pRet->SetLocalOrigin( vOrigin );
		pRet->SetLocalAngles( vAngles );
		pRet->Spawn();
	}
	
	return pRet;
}


//-----------------------------------------------------------------------------
// Plays a respawn effect on a respawn station...
//-----------------------------------------------------------------------------
void PlayRespawnEffect(CBaseEntity *pRespawnStation)
{
	// ROBIN: Removed this for now
	return;

	// Check last respawn time; wait a couple seconds
	if (!FClassnameIs(pRespawnStation, "obj_respawn_station"))
		return;

	CObjectRespawnStation* pStation = static_cast<CObjectRespawnStation*>(pRespawnStation);
	pStation->PerformRespawnEffect();
}

//-----------------------------------------------------------------------------
// Purpose: Returns true if this spawnpoint is the map specified initial spawnpoint for its team
//-----------------------------------------------------------------------------
bool CObjectRespawnStation::IsInitialSpawnPoint( void )
{
	return m_bIsInitialSpawnPoint;
}