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. ============//
// tf_spawner_boss.cpp
// Entity to spawn a Boss
// Michael Booth, February 2011
#include "cbase.h"
#ifdef OBSOLETE_USE_BOSS_ALPHA
#ifdef TF_RAID_MODE
#include "tf_gamerules.h"
#include "tf_spawner_boss.h"
#include "bot_npc/bot_npc.h"
//------------------------------------------------------------------------------
BEGIN_DATADESC( CTFSpawnerBoss )
DEFINE_KEYFIELD( m_spawnCount, FIELD_INTEGER, "count" ),
DEFINE_KEYFIELD( m_maxActiveCount, FIELD_INTEGER, "maxActive" ),
DEFINE_KEYFIELD( m_spawnInterval, FIELD_FLOAT, "interval" ),
DEFINE_KEYFIELD( m_teamName, FIELD_STRING, "team" ),
DEFINE_INPUTFUNC( FIELD_VOID, "Enable", InputEnable ),
DEFINE_INPUTFUNC( FIELD_VOID, "Disable", InputDisable ),
DEFINE_OUTPUT( m_onSpawned, "OnSpawned" ),
DEFINE_OUTPUT( m_onExpended, "OnExpended" ),
DEFINE_OUTPUT( m_onBotKilled, "OnBotKilled" ),
DEFINE_OUTPUT( m_onBotStunned, "OnBotStunned" ),
DEFINE_THINKFUNC( SpawnerThink ),
END_DATADESC()
LINK_ENTITY_TO_CLASS( tf_spawner_boss, CTFSpawnerBoss );
//------------------------------------------------------------------------------
CTFSpawnerBoss::CTFSpawnerBoss( void )
{
m_isExpended = false;
m_spawnCountRemaining = 0;
SetThink( NULL );
}
//------------------------------------------------------------------------------
void CTFSpawnerBoss::InputEnable( inputdata_t &inputdata )
{
if ( m_isExpended )
{
return;
}
SetThink( &CTFSpawnerBoss::SpawnerThink );
if ( m_spawnCountRemaining )
{
// already generating - don't restart count
return;
}
SetNextThink( gpGlobals->curtime );
m_spawnCountRemaining = m_spawnCount;
}
//------------------------------------------------------------------------------
void CTFSpawnerBoss::InputDisable( inputdata_t &inputdata )
{
// just stop thinking
SetThink( NULL );
}
//------------------------------------------------------------------------------
void CTFSpawnerBoss::OnBotKilled( CBotNPC *pBot )
{
m_onBotKilled.FireOutput( pBot, this );
}
//------------------------------------------------------------------------------
void CTFSpawnerBoss::OnBotStunned( CBotNPC *pBot )
{
m_onBotStunned.FireOutput( pBot, this );
}
//------------------------------------------------------------------------------
void CTFSpawnerBoss::SpawnerThink( void )
{
// still waiting for the real game to start?
gamerules_roundstate_t roundState = TFGameRules()->State_Get();
if ( roundState >= GR_STATE_TEAM_WIN || roundState < GR_STATE_PREROUND || TFGameRules()->IsInWaitingForPlayers() )
{
SetNextThink( gpGlobals->curtime + 1.0f );
return;
}
// remove invalid handles from our collection
int i = 0;
while( i < m_spawnedBotVector.Count() )
{
CHandle< CBotNPC > hBot = m_spawnedBotVector[i];
if ( hBot == NULL )
{
m_spawnedBotVector.FastRemove(i);
continue;
}
++i;
}
if ( m_spawnedBotVector.Count() >= m_maxActiveCount )
{
// maximum count reached - can't spawn any more
SetNextThink( gpGlobals->curtime + 0.1f );
return;
}
// spawn a bot
CBotNPC *bot = (CBotNPC *)CreateEntityByName( "bot_boss" );
if ( bot )
{
m_spawnedBotVector.AddToTail( bot );
int iTeam = TEAM_UNASSIGNED;
if ( FStrEq( m_teamName.ToCStr(), "red" ) )
{
iTeam = TF_TEAM_RED;
}
else if ( FStrEq( m_teamName.ToCStr(), "blue" ) )
{
iTeam = TF_TEAM_BLUE;
}
bot->ChangeTeam( iTeam );
// match bot facing to that of spawner
bot->SetAbsAngles( GetAbsAngles() );
bot->SetAbsOrigin( GetAbsOrigin() );
bot->SetSpawner( this );
DispatchSpawn( bot );
m_onSpawned.FireOutput( bot, this );
--m_spawnCountRemaining;
if ( m_spawnCountRemaining )
{
SetNextThink( gpGlobals->curtime + m_spawnInterval );
}
else
{
SetThink( NULL );
m_onExpended.FireOutput( this, this );
m_isExpended = true;
}
}
}
#endif // TF_RAID_MODE
#endif // #ifdef OBSOLETE_USE_BOSS_ALPHA
|