forked from borzh/botrix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod.h
167 lines (118 loc) · 4.89 KB
/
mod.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
#ifndef __BOTRIX_MOD_H__
#define __BOTRIX_MOD_H__
#include <stdlib.h> // rand().
#include "event.h"
#include "item.h"
//****************************************************************************************************************
/// Mod interface.
/**
* Used to get strings, colors from types or flags. TODO:
*/
//****************************************************************************************************************
abstract class IMod
{
public: // Methods.
///
virtual void LoadConfig(const good::string& sModName) = 0;
// ProcessUnknownSection(const good::inifile::inisection...);
/// Called when map is loaded, after waypoints and items has been loaded.
virtual void MapLoaded() = 0;
/// Get waypoint type count.
virtual int GetWaypointTypeCount() = 0;
/// Get waypoint type names.
virtual const good::string* GetWaypointTypeNames() = 0;
/// Get waypoint type colors.
virtual const int* GetWaypointTypeColors() = 0;
/// Get waypoint path count.
virtual int GetWaypointPathCount() = 0;
/// Get waypoints path names.
virtual const good::string* GetWaypointPathNames() = 0;
/// Get waypoints path colors.
virtual const int* GetWaypointPathColors() = 0;
/// Get bot's objective count.
virtual int GetObjectivesCount() = 0;
/// Get bot's objective names.
virtual const good::string* GetObjectiveNames() = 0;
/// Get chat count.
virtual int GetChatCount() = 0;
/// Get chat names.
virtual const good::string* GetChatNames() = 0;
/// Mod think function.
virtual void Think() = 0;
};
//****************************************************************************************************************
/// Class for Half Life 2 mod types. By default loads all needed stuff for Half-life 2 deathmatch mod.
//****************************************************************************************************************
class CMod
{
public: // Methods.
static IMod* pCurrentMod;
/// Get mod id for this game mod.
static TModId GetModId() { return m_iModId; }
/// Load all needed staff for mod.
static void Load( TModId iModId );
// Add event and start listening to it.
static void AddEvent( CEvent* pEvent );
/// Unload mod.
static void UnLoad()
{
m_iModId = EModId_Invalid;
sModName = "";
aTeamsNames.clear();
m_aBotNames.clear();
m_aModels.clear();
m_aEvents.clear();
}
/// Called when map finished loading items and waypoints.
static void MapLoaded();
/// Return true if map has items or waypoint's of given type.
static bool HasMapItems( TEntityType iEntityType ) { return m_bMapHas[iEntityType]; }
/// Get team index from team name.
static int GetTeamIndex( const good::string& sTeam )
{
for ( int i=0; i < aTeamsNames.size(); ++i )
if ( sTeam == aTeamsNames[i] )
return i;
return -1;
}
/// Get random bot name from [General] section, key bot_names.
static const good::string* GetRandomModel( int iTeam )
{
DebugAssert( iTeam != iSpectatorTeam );
if ( (iTeam == iUnassignedTeam) && (m_aModels[iTeam].size() == 0) )
{
do {
iTeam = rand() % m_aModels.size();
} while ( (iTeam == iUnassignedTeam) || (iTeam == iSpectatorTeam) );
}
return m_aModels[iTeam].size() ? &m_aModels[iTeam][rand() % m_aModels[iTeam].size()] : NULL;
}
/// Get random bot name from [General] section, key bot_names.
static const good::string& GetRandomBotName() { return m_aBotNames[rand() % m_aBotNames.size()]; }
/// Execute event.
static void ExecuteEvent( void* pEvent, TEventType iType );
public: // Static members.
static good::string sModName; ///< Mod name.
static StringVector aTeamsNames; ///< Name of teams.
static int iUnassignedTeam; ///< Index of unassigned (deathmatch) team.
static int iSpectatorTeam; ///< Index of spectator team.
static bool bIntelligenceInBotName; ///< Use bot's intelligence as part of his name.
protected: // Methods.
friend class CConfiguration; // Give access to next protected methods.
// Set bot names.
static void SetBotNames( const StringVector& aBotNames ) { m_aBotNames = aBotNames; }
// Set bot models for team index.
static void SetBotModels( const StringVector& aModels, int iTeam )
{
if ( iTeam >= m_aModels.size() )
m_aModels.resize(iTeam+1);
m_aModels[iTeam] = aModels;
}
protected: // Members.
static TModId m_iModId; // Mod id.
static StringVector m_aBotNames; // Available bot names.
static good::vector<StringVector> m_aModels; // Available models for teams.
static good::vector< good::auto_ptr<CEvent> > m_aEvents; // Events this mod handles.
static bool m_bMapHas[EEntityTypeTotal-1]; // To check if map has items or waypoints of types: health, armor, weapon, ammo.
};
#endif // __BOTRIX_MOD_H__