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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "tf_player.h"
#include "tf_team.h"
#include "tf_gamerules.h"
#include "tf_obj.h"
#include "tf_obj_rallyflag.h"
#include "ndebugoverlay.h"
BEGIN_DATADESC( CObjectRallyFlag )
DEFINE_THINKFUNC( RallyThink ),
END_DATADESC()
IMPLEMENT_SERVERCLASS_ST(CObjectRallyFlag, DT_ObjectRallyFlag)
END_SEND_TABLE();
LINK_ENTITY_TO_CLASS(obj_rallyflag, CObjectRallyFlag);
PRECACHE_REGISTER(obj_rallyflag);
ConVar obj_rallyflag_health( "obj_rallyflag_health","100", FCVAR_NONE, "Rally Flag health" );
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CObjectRallyFlag::CObjectRallyFlag()
{
UseClientSideAnimation();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CObjectRallyFlag::Spawn()
{
Precache();
SetModel( RALLYFLAG_MODEL );
SetSolid( SOLID_BBOX );
SetCollisionGroup( TFCOLLISION_GROUP_COMBATOBJECT );
UTIL_SetSize(this, RALLYFLAG_MINS, RALLYFLAG_MAXS);
m_takedamage = DAMAGE_YES;
m_iHealth = obj_rallyflag_health.GetInt();
SetThink( RallyThink );
SetNextThink( gpGlobals->curtime + 0.1f );
m_flExpiresAt = gpGlobals->curtime + RALLYFLAG_LIFETIME;
SetType( OBJ_RALLYFLAG );
m_fObjectFlags |= OF_SUPPRESS_NOTIFY_UNDER_ATTACK | OF_SUPPRESS_TECH_ANALYZER |
OF_DONT_AUTO_REPAIR | OF_DONT_PREVENT_BUILD_NEAR_OBJ | OF_DOESNT_NEED_POWER;
BaseClass::Spawn();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CObjectRallyFlag::Precache()
{
PrecacheModel( RALLYFLAG_MODEL );
}
//-----------------------------------------------------------------------------
// Purpose: Look for friendlies to rally
//-----------------------------------------------------------------------------
void CObjectRallyFlag::RallyThink( void )
{
if ( !GetTeam() )
return;
// Time to die?
if ( gpGlobals->curtime > m_flExpiresAt )
{
UTIL_Remove( this );
return;
}
// Look for nearby players to rally
for ( int i = 0; i < GetTFTeam()->GetNumPlayers(); i++ )
{
CBaseTFPlayer *pPlayer = (CBaseTFPlayer *)GetTFTeam()->GetPlayer(i);
assert(pPlayer);
// Is it within range?
if ( ((pPlayer->GetAbsOrigin() - GetAbsOrigin()).Length() < RALLYFLAG_RADIUS ) && pPlayer->IsAlive() )
{
// Can I see it?
trace_t tr;
UTIL_TraceLine( EyePosition(), pPlayer->EyePosition(), MASK_SOLID_BRUSHONLY, this, COLLISION_GROUP_NONE, &tr);
CBaseEntity *pEntity = tr.m_pEnt;
if ( (tr.fraction == 1.0) || ( pEntity == pPlayer ) )
{
pPlayer->AttemptToPowerup( POWERUP_RUSH, RALLYFLAG_ADRENALIN_TIME );
}
}
}
SetNextThink( gpGlobals->curtime + RALLYFLAG_RATE );
}
|