blob: 84b1d98ad7aa9a1a8b41a446ef2f14d61288b962 (
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: tf_populator_spawners
// Implementations of NPC Spawning Code for PvE related game modes (MvM)
//=============================================================================//
#ifndef TF_POPULATORS_H
#define TF_POPULATORS_H
#include "tf_population_manager.h"
class KeyValues;
class IPopulator;
class IPopulationSpawner;
class CPopulationManager;
class CWave;
class CSpawnLocation;
//-----------------------------------------------------------------------
class CSpawnLocation
{
public:
CSpawnLocation();
bool Parse( KeyValues *data );
bool IsValid( void ) const;
SpawnLocationResult FindSpawnLocation( Vector& vSpawnPosition );
private:
CTFNavArea *SelectSpawnArea( void ) const;
RelativePositionType m_relative;
TFTeamSpawnVector_t m_teamSpawnVector;
int m_nSpawnCount;
int m_nRandomSeed;
bool m_bClosestPointOnNav;
};
inline bool CSpawnLocation::IsValid( void ) const
{
return m_relative != UNDEFINED || m_teamSpawnVector.Count() > 0;
}
//-----------------------------------------------------------------------
// For spawning bots/players at a specific position
class CPopulatorInternalSpawnPoint : public CPointEntity
{
DECLARE_CLASS( CPopulatorInternalSpawnPoint, CPointEntity );
};
extern CHandle< CPopulatorInternalSpawnPoint > g_internalSpawnPoint;
//-----------------------------------------------------------------------
// A Populator manages the populating of entities in the environment.
class IPopulator
{
public:
IPopulator( CPopulationManager *manager )
{
m_manager = manager;
m_spawner = NULL;
}
virtual ~IPopulator()
{
if ( m_spawner )
{
delete m_spawner;
}
m_spawner = NULL;
}
virtual bool Parse( KeyValues *data ) = 0;
virtual void PostInitialize( void ) { } // create initial population at start of scenario
virtual void Update( void ) { } // continuously invoked to modify population over time
virtual void UnpauseSpawning() {}
virtual void OnPlayerKilled( CTFPlayer *corpse ) { }
CPopulationManager *GetManager( void ) const { return m_manager; }
virtual bool HasEventChangeAttributes( const char* pszEventName ) const
{
if ( m_spawner )
{
return m_spawner->HasEventChangeAttributes( pszEventName );
}
return false;
}
IPopulationSpawner *m_spawner;
private:
CPopulationManager *m_manager;
};
//-----------------------------------------------------------------------
// Invokes its spawner when mission conditions are met
class CMissionPopulator : public IPopulator
{
public:
CMissionPopulator( CPopulationManager *manager );
virtual ~CMissionPopulator() { }
virtual bool Parse( KeyValues *data );
virtual void Update( void ); // continuously invoked to modify population over time
virtual void UnpauseSpawning( void );
int BeginAtWave( void ) { return m_beginAtWaveIndex; }
int StopAtWave( void ) { return m_stopAtWaveIndex; }
CTFBot::MissionType GetMissionType( void ){ return m_mission; }
private:
CTFBot::MissionType m_mission;
CSpawnLocation m_where;
bool UpdateMissionDestroySentries( void );
bool UpdateMission( CTFBot::MissionType mission );
enum StateType
{
NOT_STARTED,
INITIAL_COOLDOWN,
RUNNING
};
StateType m_state;
float m_initialCooldown;
float m_cooldownDuration;
CountdownTimer m_cooldownTimer;
CountdownTimer m_checkForDangerousSentriesTimer;
int m_desiredCount;
int m_beginAtWaveIndex; // this mission becomes active at this wave number
int m_stopAtWaveIndex; // stop when this wave becomes active
};
//-----------------------------------------------------------------------
// Invokes its spawner at random positions scattered throughout
// the environment at PostInitialize()
class CRandomPlacementPopulator : public IPopulator
{
public:
CRandomPlacementPopulator( CPopulationManager *manager );
virtual ~CRandomPlacementPopulator() { }
virtual bool Parse( KeyValues *data );
virtual void PostInitialize( void ); // create initial population at start of scenario
int m_count;
float m_minSeparation;
unsigned int m_navAreaFilter;
};
//-----------------------------------------------------------------------
// Invokes its spawner periodically
class CPeriodicSpawnPopulator : public IPopulator
{
public:
CPeriodicSpawnPopulator( CPopulationManager *manager );
virtual ~CPeriodicSpawnPopulator() { }
virtual bool Parse( KeyValues *data );
virtual void PostInitialize( void ); // create initial population at start of scenario
virtual void Update( void ); // continuously invoked to modify population over time
virtual void UnpauseSpawning( void );
CSpawnLocation m_where;
float m_minInterval;
float m_maxInterval;
private:
CountdownTimer m_timer;
};
//-----------------------------------------------------------------------
// Spawns a group of entities within a Wave
class CWaveSpawnPopulator : public IPopulator
{
public:
CWaveSpawnPopulator( CPopulationManager *manager );
virtual ~CWaveSpawnPopulator();
virtual bool Parse( KeyValues *data );
virtual void Update( void ); // continuously invoked to modify population over time
virtual void OnPlayerKilled( CTFPlayer *corpse );
CSpawnLocation m_where;
int m_totalCount;
int m_remainingCount;
int m_nClassCounts;
int m_maxActive; // the maximum number of entities active at one time
int m_spawnCount; // the number of entities to spawn at once
float m_waitBeforeStarting;
float m_waitBetweenSpawns; // between spawns of mobs
bool m_bWaitBetweenSpawnAfterDeath;
CFmtStr m_startWaveWarningSound;
EventInfo *m_startWaveOutput;
CFmtStr m_firstSpawnWarningSound;
EventInfo *m_firstSpawnOutput;
CFmtStr m_lastSpawnWarningSound;
EventInfo *m_lastSpawnOutput;
CFmtStr m_doneWarningSound;
EventInfo *m_doneOutput;
int m_totalCurrency;
int m_unallocatedCurrency;
CUtlString m_name;
CUtlString m_waitForAllSpawned;
CUtlString m_waitForAllDead;
bool IsDone( void ) const
{
return m_state == DONE;
}
bool IsDoneSpawningBots( void ) const
{
return m_state > SPAWNING;
}
// Invoked by td_setnextwave to finish off a wave
void ForceFinish( void );
void ForceReset( void )
{
m_unallocatedCurrency = m_totalCurrency;
m_remainingCount = m_totalCount;
m_state = PENDING;
}
bool IsSupportWave( void ) const { return m_bSupportWave; }
bool IsLimitedSupportWave( void ) const { return m_bLimitedSupport; }
void SetParent( CWave *pParent ) { m_pParent = pParent; }
int GetCurrencyAmountPerDeath( void );
void OnNonSupportWavesDone( void );
private:
bool IsFinishedSpawning( void );
CountdownTimer m_timer;
EntityHandleVector_t m_activeVector;
int m_countSpawnedSoFar;
int m_myReservedSlotCount;
bool m_bSupportWave;
bool m_bLimitedSupport;
CWave *m_pParent;
enum InternalStateType
{
PENDING,
PRE_SPAWN_DELAY,
SPAWNING,
WAIT_FOR_ALL_DEAD,
DONE
};
InternalStateType m_state;
void SetState( InternalStateType eState );
int ReservePlayerSlots( int count ); // reserve 'count' player slots so other WaveSpawns don't take them
void ReleasePlayerSlots( int count ); // release 'count' player slots that have been previously reserved
static int m_reservedPlayerSlotCount;
bool m_bRandomSpawn;
SpawnLocationResult m_spawnLocationResult;
Vector m_vSpawnPosition;
};
struct WaveClassCount_t
{
int nClassCount;
string_t iszClassIconName;
unsigned int iFlags;
};
//-----------------------------------------------------------------------
// Spawns sequential "waves" of entities over time.
// A wave consists of one or more WaveSpawns that all run concurrently.
// The wave is done when all contained WaveSpawns are done.
class CWave : public IPopulator
{
public:
CWave( CPopulationManager *manager );
virtual ~CWave();
virtual bool Parse( KeyValues *data );
virtual void Update( void );
virtual void OnPlayerKilled( CTFPlayer *corpse );
virtual bool HasEventChangeAttributes( const char* pszEventName ) const OVERRIDE;
void ForceFinish(); // used when forcing a wave to finish
void ForceReset(); // used when forcing a wave to start
CWaveSpawnPopulator *FindWaveSpawnPopulator( const char *name ); // find a CWaveSpawnPopulator by name
void AddClassType( string_t iszClassIconName, int nCount, unsigned int iFlags );
int GetNumClassTypes( void ) const { return m_nWaveClassCounts.Count(); }
void StartUpgradesAlertTimer ( float flTime ) { m_GetUpgradesAlertTimer.Start( flTime ); }
void SetStartTime (float flTime) { m_flStartTime = flTime; }
// inline
bool IsCheckpoint( void ) const;
CWave *GetNextWave( void ) const;
void SetNextWave( CWave *wave );
const char *GetDescription( void ) const;
int GetTotalCurrency( void ) const;
int GetEnemyCount( void ) const;
int GetClassCount( int nIndex ) const;
string_t GetClassIconName( int nIndex ) const;
unsigned int GetClassFlags( int nIndex ) const;
int NumTanksSpawned( void ) const;
void IncrementTanksSpawned( void );
int NumSentryBustersSpawned( void ) const;
void IncrementSentryBustersSpawned( void );
int NumSentryBustersKilled( void ) const;
void IncrementSentryBustersKilled( void );
void ResetSentryBustersKilled( void );
int NumEngineersTeleportSpawned( void ) const;
void IncrementEngineerTeleportSpawned( void );
private:
bool IsDoneWithNonSupportWaves( void );
void ActiveWaveUpdate();
void WaveCompleteUpdate();
void WaveIntermissionUpdate();
CUtlVector< CWaveSpawnPopulator * > m_waveSpawnVector;
bool m_isStarted;
bool m_bFiredInitWaveOutput;
int m_iEnemyCount;
int m_nTanksSpawned;
int m_nSentryBustersSpawned;
int m_nNumEngineersTeleportSpawned;
int m_nNumSentryBustersKilled;
CUtlVector< WaveClassCount_t > m_nWaveClassCounts;
int m_totalCurrency;
EventInfo *m_startOutput;
EventInfo *m_doneOutput;
EventInfo *m_initOutput;
CFmtStr m_description;
CFmtStr m_soundName;
float m_waitWhenDone;
CountdownTimer m_doneTimer;
bool m_bCheckBonusCreditsMin;
bool m_bCheckBonusCreditsMax;
float m_flBonusCreditsTime;
bool m_bPlayedUpgradeAlert;
CountdownTimer m_GetUpgradesAlertTimer;
bool m_isEveryContainedWaveSpawnDone;
float m_flStartTime;
};
inline const char *CWave::GetDescription( void ) const
{
return m_description;
}
inline int CWave::GetTotalCurrency( void ) const
{
return m_totalCurrency;
}
inline int CWave::GetEnemyCount( void ) const
{
return m_iEnemyCount;
}
inline int CWave::GetClassCount( int nIndex ) const
{
return m_nWaveClassCounts[ nIndex ].nClassCount;
}
inline string_t CWave::GetClassIconName( int nIndex ) const
{
return m_nWaveClassCounts[ nIndex ].iszClassIconName;
}
inline unsigned int CWave::GetClassFlags( int nIndex ) const
{
return m_nWaveClassCounts[ nIndex ].iFlags;
}
inline int CWave::NumTanksSpawned( void ) const
{
return m_nTanksSpawned;
}
inline void CWave::IncrementTanksSpawned( void )
{
m_nTanksSpawned++;
}
inline int CWave::NumSentryBustersSpawned( void ) const
{
return m_nSentryBustersSpawned;
}
inline void CWave::IncrementSentryBustersSpawned( void )
{
m_nSentryBustersSpawned++;
}
inline int CWave::NumSentryBustersKilled( void ) const
{
return m_nNumSentryBustersKilled;
}
inline void CWave::IncrementSentryBustersKilled( void )
{
m_nNumSentryBustersKilled++;
}
inline void CWave::ResetSentryBustersKilled( void )
{
m_nNumSentryBustersKilled = 0;
}
inline int CWave::NumEngineersTeleportSpawned( void ) const
{
return m_nNumEngineersTeleportSpawned;
}
inline void CWave::IncrementEngineerTeleportSpawned( void )
{
m_nNumEngineersTeleportSpawned++;
}
#endif // TF_POPULATORS_H
|