File: dm_manager.h

package info (click to toggle)
openmohaa 0.82.1%2Bdfsg-1
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid
  • size: 34,192 kB
  • sloc: cpp: 315,720; ansic: 275,789; sh: 312; xml: 246; asm: 141; makefile: 7
file content (314 lines) | stat: -rw-r--r-- 7,666 bytes parent folder | download | duplicates (2)
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
/*
===========================================================================
Copyright (C) 2015 the OpenMoHAA team

This file is part of OpenMoHAA source code.

OpenMoHAA source code is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.

OpenMoHAA source code is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with OpenMoHAA source code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
===========================================================================
*/
// dm_manager.h: Deathmatch Manager.

#pragma once

#include "listener.h"
#include "Tow_Entities.h"

extern cvar_t *g_tempaxisscore;
extern cvar_t *g_tempaxiswinsinrow;
extern cvar_t *g_tempalliesscore;
extern cvar_t *g_tempallieswinsinrow;

class PlayerStart;
class Player;

class DM_Team : public Listener
{
public:
    Container<PlayerStart *> m_spawnpoints;
    Container<Player *>      m_players;
    int                      m_maxplayers;

    str m_teamname;
    int m_teamnumber;
    int m_index;

    int m_teamwins;
    int m_wins_in_a_row;

    int m_iKills;
    int m_iDeaths;

    qboolean m_bHasSpawnedPlayers;

public:
    CLASS_PROTOTYPE(DM_Team);

    DM_Team();
    ~DM_Team();

    void Reset(void);

    void AddPlayer(Player *player);
    void RemovePlayer(Player *player);

    void setName(str name);
    str  getName(void);
    void setNumber(int num);
    int  getNumber(void);
    void setIndex(int index);
    int  getIndex(void);

    void TeamWin(void);
    void TeamLoss(void);
    void AddDeaths(Player *player, int numDeaths);
    void AddKills(Player *player, int numKills);
    void UpdateTeamStatus(void);

    void TeamInvulnerable(void);
    void BeginFight(void);

    float PlayersRangeFromSpot(PlayerStart *spot);

    bool IsDead(void) const;
    bool IsEmpty(void) const;
    bool IsReady(void) const;

    int NumNotReady(void) const;
    int NumLivePlayers(void) const;
    int TotalPlayersKills(void) const;

    PlayerStart *GetRandomFfaSpawnpoint(Player *player);
    PlayerStart *GetRandomTeamSpawnpoint(Player *player);
    PlayerStart *GetRandomObjectiveSpawnpoint(Player *player);

protected:
    PlayerStart *FarthestSpawnPoint(void);
    PlayerStart *GetRandomSpawnpoint(void);
    PlayerStart *GetRandomSpawnpointWithMetric(
        Player *player, float (*MetricFunction)(const float *, DM_Team *dmTeam, const Player *player)
    );
};

using DM_TeamPtr = SafePtr<DM_Team>;

inline void DM_Team::setName(str name)
{
    m_teamname = name;
};

inline str DM_Team::getName(void)
{
    return m_teamname;
};

inline void DM_Team::setNumber(int num)
{
    m_teamnumber = num;
}

inline int DM_Team::getNumber(void)
{
    return m_teamnumber;
}

inline void DM_Team::setIndex(int index)
{
    m_index = index;
}

inline int DM_Team::getIndex(void)
{
    return m_index;
}

inline bool DM_Team::IsReady(void) const
{
    return g_forceready->integer || NumNotReady() == 0;
}

class SimpleAmmoType : public Class
{
public:
    str type;
    int amount;

public:
    SimpleAmmoType();
};

class Player;

class DM_Manager : public Listener
{
private:
    Container<Player *>   m_players;
    Container<DM_TeamPtr> m_teams;

    DM_Team m_team_spectator;
    DM_Team m_team_freeforall;
    DM_Team m_team_allies;
    DM_Team m_team_axis;

    float m_fRoundTime;
    float m_fRoundEndTime;

    bool m_bAllowRespawns;
    bool m_bRoundBasedGame;
    bool m_bIgnoringClockForBomb;
    int  m_iTeamWin;
    int  m_iDefaultRoundLimit;

    const_str m_csTeamClockSide;
    const_str m_csTeamBombPlantSide;

    int m_iNumTargetsToDestroy;
    int m_iNumTargetsDestroyed;
    int m_iNumBombsPlanted;
    int m_iTotalMapTime;

    bool m_bAllowAlliedRespawn;
    bool m_bAllowAxisRespawn;
    bool m_bRoundActive;

    // scoreboard data
    char   scoreString[MAX_STRING_CHARS];
    size_t scoreLength;
    int    scoreEntries;

private:
    void BuildTeamInfo(DM_Team *dmTeam);
    void BuildTeamInfo_ver6(DM_Team *dmTeam);
    void BuildTeamInfo_ver15(DM_Team *dmTeam);
    void BuildPlayerTeamInfo(DM_Team *dmTeam, int *iPlayerList, DM_Team *ignoreTeam = NULL);
    void InsertEntry(const char *entry);
    void InsertEntryNoCount(const char *entry);
    void InsertEmpty(void);
    bool IsAlivePlayer(Player* player) const;

public:
    CLASS_PROTOTYPE(DM_Manager);

    DM_Manager();
    ~DM_Manager();

    void InitGame(void);
    void AddPlayer(Player *player);
    bool JoinTeam(Player *player, teamtype_t teamType);
    void LeaveTeam(Player *player);
    void RebuildTeamConfigstrings(void);
    void RemovePlayer(Player *player);
    void PlayerKilled(Player *player);

    void Countdown(Event *ev);
    void Reset(void);
    void Score(Player *player);

    void       PrintAllClients(str s);
    bool       CheckEndMatch(void);
    bool       TeamHitScoreLimit(void);
    bool       PlayerHitScoreLimit(void);
    void       EventDoRoundTransition(Event *ev);
    void       EventFinishRoundTransition(Event *ev);
    void       TeamWin(int teamnum);
    void       StartRound(void);
    void       EndRound(void);
    bool       RoundActive(void) const;
    bool       GameHasRounds(void) const;
    bool       GameAllowsRespawns(void) const;
    void       SetGameAllowsRespawns(bool bAllow);
    bool       AllowRespawn(void) const;
    int        GetRoundLimit(void) const;
    void       SetDefaultRoundLimit(int round_limit);
    const_str  GetClockSide(void) const;
    void       SetClockSide(const_str s);
    const_str  GetBombPlantTeam(void) const;
    void       SetBombPlantTeam(const_str s);
    int        GetTargetsToDestroy(void) const;
    void       SetTargetsToDestroy(int);
    int        GetTargetsDestroyed(void) const;
    void       SetTargetsDestroyed(int);
    int        GetBombsPlanted(void) const;
    void       SetBombsPlanted(int);
    int        GetTeamWin(void);
    bool       WaitingForPlayers(void) const;
    bool       IsGameActive(void) const;
    int        PlayerCount(void) const;
    Player    *GetPlayer(int index) const;
    teamtype_t GetAutoJoinTeam(void);

    DM_Team *GetTeamAllies(void);
    DM_Team *GetTeamAxis(void);

    float GetMatchStartTime(void);
    void  StopTeamRespawn(eController controller);
    bool  AllowTeamRespawn(int teamnum) const;
    int   GetTeamSpawnTimeLeft() const;

    DM_Team *GetTeam(str name);
    DM_Team *GetTeam(teamtype_t team);

protected:
    static int compareScores(const void *elem1, const void *elem2);
};

inline int DM_Manager::GetTeamWin(void)
{
    return m_iTeamWin;
}

inline DM_Team *DM_Manager::GetTeamAllies(void)
{
    return &m_team_allies;
}

inline DM_Team *DM_Manager::GetTeamAxis(void)
{
    return &m_team_axis;
}

inline bool DM_Manager::RoundActive(void) const
{
    return m_bRoundActive;
}

inline bool DM_Manager::GameHasRounds(void) const
{
    return m_bRoundBasedGame;
}

inline bool DM_Manager::GameAllowsRespawns(void) const
{
    return m_bAllowRespawns;
}

inline void DM_Manager::SetGameAllowsRespawns(bool bAllow)
{
    m_bAllowRespawns = bAllow;
}

extern DM_Manager dmManager;

class CTeamSpawnClock {
private:
    float nextSpawnTime;

public:
    CTeamSpawnClock();
    void Reset();
    void Restart();

    int GetSecondsLeft();
};