-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathNextBotManager.h
211 lines (163 loc) · 5.76 KB
/
NextBotManager.h
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
// NextBotManager.h
// Author: Michael Booth, May 2006
//========= Copyright Valve Corporation, All rights reserved. ============//
#ifndef _NEXT_BOT_MANAGER_H_
#define _NEXT_BOT_MANAGER_H_
#include "NextBotInterface.h"
class CTerrorPlayer;
//----------------------------------------------------------------------------------------------------------------
/**
* The NextBotManager manager
*/
class NextBotManager
{
public:
NextBotManager( void );
virtual ~NextBotManager();
void Reset( void ); // reset to initial state
virtual void Update( void );
bool ShouldUpdate( INextBot *bot );
void NotifyBeginUpdate( INextBot *bot );
void NotifyEndUpdate( INextBot *bot );
int GetNextBotCount( void ) const; // How many nextbots are alive right now?
/**
* Populate given vector with all bots in the system
*/
void CollectAllBots( CUtlVector< INextBot * > *botVector );
/**
* DEPRECATED: Use CollectAllBots().
* Execute functor for each NextBot in the system.
* If a functor returns false, stop iteration early
* and return false.
*/
template < typename Functor >
bool ForEachBot( Functor &func )
{
for( int i=m_botList.Head(); i != m_botList.InvalidIndex(); i = m_botList.Next( i ) )
{
if ( !func( m_botList[i] ) )
{
return false;
}
}
return true;
}
/**
* DEPRECATED: Use CollectAllBots().
* Execute functor for each NextBot in the system as
* a CBaseCombatCharacter.
* If a functor returns false, stop iteration early
* and return false.
*/
template < typename Functor >
bool ForEachCombatCharacter( Functor &func )
{
for( int i=m_botList.Head(); i != m_botList.InvalidIndex(); i = m_botList.Next( i ) )
{
if ( !func( m_botList[i]->GetEntity() ) )
{
return false;
}
}
return true;
}
/**
* Return closest bot to given point that passes the given filter
*/
template < typename Filter >
INextBot *GetClosestBot( const Vector &pos, Filter &filter )
{
INextBot *close = NULL;
float closeRangeSq = FLT_MAX;
for( int i=m_botList.Head(); i != m_botList.InvalidIndex(); i = m_botList.Next( i ) )
{
float rangeSq = ( m_botList[i]->GetEntity()->GetAbsOrigin() - pos ).LengthSqr();
if ( rangeSq < closeRangeSq && filter( m_botList[i] ) )
{
closeRangeSq = rangeSq;
close = m_botList[i];
}
}
return close;
}
/**
* Event propagators
*/
virtual void OnMapLoaded( void ); // when the server has changed maps
virtual void OnRoundRestart( void ); // when the scenario restarts
virtual void OnBeginChangeLevel( void ); // when the server is about to change maps
virtual void OnKilled( CBaseCombatCharacter *victim, const CTakeDamageInfo &info ); // when an actor is killed
virtual void OnSound( CBaseEntity *source, const Vector &pos, KeyValues *keys ); // when an entity emits a sound
virtual void OnSpokeConcept( CBaseCombatCharacter *who, AIConcept_t concept, AI_Response *response ); // when an Actor speaks a concept
virtual void OnWeaponFired( CBaseCombatCharacter *whoFired, CBaseCombatWeapon *weapon ); // when someone fires a weapon
/**
* Debugging
*/
bool IsDebugging( unsigned int type ) const; // return true if debugging system is on for the given type(s)
void SetDebugTypes( NextBotDebugType type ); // start displaying debug info of the given type(s)
void DebugFilterAdd( int index ); // add given entindex to the debug filter
void DebugFilterAdd( const char *name ); // add given name to the debug filter
void DebugFilterRemove( int index ); // remove given entindex from the debug filter
void DebugFilterRemove( const char *name ); // remove given name from the debug filter
void DebugFilterClear( void ); // clear the debug filter (remove all entries)
bool IsDebugFilterMatch( const INextBot *bot ) const; // return true if the given bot matches the debug filter
void Select( INextBot *bot ); // mark bot as selected for further operations
void DeselectAll( void );
INextBot *GetSelected( void ) const;
INextBot *GetBotUnderCrosshair( CBasePlayer *picker ); // Get the bot under the given player's crosshair
//
// Put these in a derived class
//
void OnSurvivorVomitedUpon( CTerrorPlayer *victim ); // when a Survivor has been hit by Boomer Vomit
static void SetInstance( NextBotManager *pInstance ) { sInstance = pInstance; };
static NextBotManager* GetInstance() { return sInstance; }
protected:
static NextBotManager* sInstance;
friend class INextBot;
int Register( INextBot *bot );
void UnRegister( INextBot *bot );
CUtlLinkedList< INextBot * > m_botList; // list of all active NextBots
int m_iUpdateTickrate;
double m_CurUpdateStartTime;
double m_SumFrameTime;
unsigned int m_debugType; // debug flags
struct DebugFilter
{
int index; // entindex
enum { MAX_DEBUG_NAME_SIZE = 128 };
char name[ MAX_DEBUG_NAME_SIZE ];
};
CUtlVector< DebugFilter > m_debugFilterList;
INextBot *m_selectedBot; // selected bot for further debug operations
};
inline int NextBotManager::GetNextBotCount( void ) const
{
return m_botList.Count();
}
inline bool NextBotManager::IsDebugging( unsigned int type ) const
{
if ( type & m_debugType )
{
return true;
}
return false;
}
inline void NextBotManager::SetDebugTypes( NextBotDebugType type )
{
m_debugType = (unsigned int)type;
}
inline void NextBotManager::Select( INextBot *bot )
{
m_selectedBot = bot;
}
inline void NextBotManager::DeselectAll( void )
{
m_selectedBot = NULL;
}
inline INextBot *NextBotManager::GetSelected( void ) const
{
return m_selectedBot;
}
// singleton accessor
extern NextBotManager &TheNextBots( void );
#endif // _NEXT_BOT_MANAGER_H_