OpenMoHAA 0.82.0
Loading...
Searching...
No Matches
dm_manager.h
1/*
2===========================================================================
3Copyright (C) 2015 the OpenMoHAA team
4
5This file is part of OpenMoHAA source code.
6
7OpenMoHAA source code is free software; you can redistribute it
8and/or modify it under the terms of the GNU General Public License as
9published by the Free Software Foundation; either version 2 of the License,
10or (at your option) any later version.
11
12OpenMoHAA source code is distributed in the hope that it will be
13useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with OpenMoHAA source code; if not, write to the Free Software
19Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20===========================================================================
21*/
22// dm_manager.h: Deathmatch Manager.
23
24#pragma once
25
26#include "listener.h"
27#include "Tow_Entities.h"
28
29extern cvar_t *g_tempaxisscore;
30extern cvar_t *g_tempaxiswinsinrow;
31extern cvar_t *g_tempalliesscore;
32extern cvar_t *g_tempallieswinsinrow;
33
34class PlayerStart;
35class Player;
36
37class DM_Team : public Listener
38{
39public:
40 Container<PlayerStart *> m_spawnpoints;
41 Container<Player *> m_players;
42 int m_maxplayers;
43
44 str m_teamname;
45 int m_teamnumber;
46 int m_index;
47
48 int m_teamwins;
49 int m_wins_in_a_row;
50
51 int m_iKills;
52 int m_iDeaths;
53
54 qboolean m_bHasSpawnedPlayers;
55
56public:
57 CLASS_PROTOTYPE(DM_Team);
58
59 DM_Team();
60 ~DM_Team();
61
62 void Reset(void);
63
64 void AddPlayer(Player *player);
65 void RemovePlayer(Player *player);
66
67 void setName(str name);
68 str getName(void);
69 void setNumber(int num);
70 int getNumber(void);
71 void setIndex(int index);
72 int getIndex(void);
73
74 void TeamWin(void);
75 void TeamLoss(void);
76 void AddDeaths(Player *player, int numDeaths);
77 void AddKills(Player *player, int numKills);
78 void UpdateTeamStatus(void);
79
80 void TeamInvulnerable(void);
81 void BeginFight(void);
82
83 float PlayersRangeFromSpot(PlayerStart *spot);
84
85 bool IsDead(void) const;
86 bool IsEmpty(void) const;
87 bool IsReady(void) const;
88
89 int NumNotReady(void) const;
90 int NumLivePlayers(void) const;
91 int TotalPlayersKills(void) const;
92
93 PlayerStart *GetRandomFfaSpawnpoint(Player *player);
94 PlayerStart *GetRandomTeamSpawnpoint(Player *player);
95 PlayerStart *GetRandomObjectiveSpawnpoint(Player *player);
96
97protected:
98 PlayerStart *FarthestSpawnPoint(void);
99 PlayerStart *GetRandomSpawnpoint(void);
100 PlayerStart *GetRandomSpawnpointWithMetric(
101 Player *player, float (*MetricFunction)(const float *, DM_Team *dmTeam, const Player *player)
102 );
103};
104
105using DM_TeamPtr = SafePtr<DM_Team>;
106
107inline void DM_Team::setName(str name)
108{
109 m_teamname = name;
110};
111
112inline str DM_Team::getName(void)
113{
114 return m_teamname;
115};
116
117inline void DM_Team::setNumber(int num)
118{
119 m_teamnumber = num;
120}
121
122inline int DM_Team::getNumber(void)
123{
124 return m_teamnumber;
125}
126
127inline void DM_Team::setIndex(int index)
128{
129 m_index = index;
130}
131
132inline int DM_Team::getIndex(void)
133{
134 return m_index;
135}
136
137inline bool DM_Team::IsReady(void) const
138{
139 return g_forceready->integer || NumNotReady() == 0;
140}
141
142class SimpleAmmoType : public Class
143{
144public:
145 str type;
146 int amount;
147
148public:
149 SimpleAmmoType();
150};
151
152class Player;
153
154class DM_Manager : public Listener
155{
156private:
157 Container<Player *> m_players;
158 Container<DM_TeamPtr> m_teams;
159
160 DM_Team m_team_spectator;
161 DM_Team m_team_freeforall;
162 DM_Team m_team_allies;
163 DM_Team m_team_axis;
164
165 float m_fRoundTime;
166 float m_fRoundEndTime;
167
168 bool m_bAllowRespawns;
169 bool m_bRoundBasedGame;
170 bool m_bIgnoringClockForBomb;
171 int m_iTeamWin;
172 int m_iDefaultRoundLimit;
173
174 const_str m_csTeamClockSide;
175 const_str m_csTeamBombPlantSide;
176
177 int m_iNumTargetsToDestroy;
178 int m_iNumTargetsDestroyed;
179 int m_iNumBombsPlanted;
180 int m_iTotalMapTime;
181
182 bool m_bAllowAlliedRespawn;
183 bool m_bAllowAxisRespawn;
184 bool m_bRoundActive;
185
186 // scoreboard data
187 char scoreString[MAX_STRING_CHARS];
188 size_t scoreLength;
189 int scoreEntries;
190
191private:
192 void BuildTeamInfo(DM_Team *dmTeam);
193 void BuildTeamInfo_ver6(DM_Team *dmTeam);
194 void BuildTeamInfo_ver15(DM_Team *dmTeam);
195 void BuildPlayerTeamInfo(DM_Team *dmTeam, int *iPlayerList, DM_Team *ignoreTeam = NULL);
196 void InsertEntry(const char *entry);
197 void InsertEntryNoCount(const char *entry);
198 void InsertEmpty(void);
199 bool IsAlivePlayer(Player* player) const;
200
201public:
202 CLASS_PROTOTYPE(DM_Manager);
203
204 DM_Manager();
205 ~DM_Manager();
206
207 void InitGame(void);
208 void AddPlayer(Player *player);
209 bool JoinTeam(Player *player, teamtype_t teamType);
210 void LeaveTeam(Player *player);
211 void RebuildTeamConfigstrings(void);
212 void RemovePlayer(Player *player);
213 void PlayerKilled(Player *player);
214
215 void Countdown(Event *ev);
216 void Reset(void);
217 void Score(Player *player);
218
219 void PrintAllClients(str s);
220 bool CheckEndMatch(void);
221 bool TeamHitScoreLimit(void);
222 bool PlayerHitScoreLimit(void);
223 void EventDoRoundTransition(Event *ev);
224 void EventFinishRoundTransition(Event *ev);
225 void TeamWin(int teamnum);
226 void StartRound(void);
227 void EndRound(void);
228 bool RoundActive(void) const;
229 bool GameHasRounds(void) const;
230 bool GameAllowsRespawns(void) const;
231 void SetGameAllowsRespawns(bool bAllow);
232 bool AllowRespawn(void) const;
233 int GetRoundLimit(void) const;
234 void SetDefaultRoundLimit(int round_limit);
235 const_str GetClockSide(void) const;
236 void SetClockSide(const_str s);
237 const_str GetBombPlantTeam(void) const;
238 void SetBombPlantTeam(const_str s);
239 int GetTargetsToDestroy(void) const;
240 void SetTargetsToDestroy(int);
241 int GetTargetsDestroyed(void) const;
242 void SetTargetsDestroyed(int);
243 int GetBombsPlanted(void) const;
244 void SetBombsPlanted(int);
245 int GetTeamWin(void);
246 bool WaitingForPlayers(void) const;
247 bool IsGameActive(void) const;
248 int PlayerCount(void) const;
249 Player *GetPlayer(int index) const;
250 teamtype_t GetAutoJoinTeam(void);
251
252 DM_Team *GetTeamAllies(void);
253 DM_Team *GetTeamAxis(void);
254
255 float GetMatchStartTime(void);
256 void StopTeamRespawn(eController controller);
257 bool AllowTeamRespawn(int teamnum) const;
258 int GetTeamSpawnTimeLeft() const;
259
260 DM_Team *GetTeam(str name);
261 DM_Team *GetTeam(teamtype_t team);
262
263protected:
264 static int compareScores(const void *elem1, const void *elem2);
265};
266
267inline int DM_Manager::GetTeamWin(void)
268{
269 return m_iTeamWin;
270}
271
272inline DM_Team *DM_Manager::GetTeamAllies(void)
273{
274 return &m_team_allies;
275}
276
277inline DM_Team *DM_Manager::GetTeamAxis(void)
278{
279 return &m_team_axis;
280}
281
282inline bool DM_Manager::RoundActive(void) const
283{
284 return m_bRoundActive;
285}
286
287inline bool DM_Manager::GameHasRounds(void) const
288{
289 return m_bRoundBasedGame;
290}
291
292inline bool DM_Manager::GameAllowsRespawns(void) const
293{
294 return m_bAllowRespawns;
295}
296
297inline void DM_Manager::SetGameAllowsRespawns(bool bAllow)
298{
299 m_bAllowRespawns = bAllow;
300}
301
302extern DM_Manager dmManager;
303
304class CTeamSpawnClock {
305private:
306 float nextSpawnTime;
307
308public:
309 CTeamSpawnClock();
310 void Reset();
311 void Restart();
312
313 int GetSecondsLeft();
314};
Definition container.h:85
Definition dm_manager.h:155
Definition dm_manager.h:38
Definition listener.h:246
Definition playerstart.h:34
Definition player.h:127
Definition safeptr.h:160
Definition str.h:77