DDraceNetwork Docs
teams.h
Go to the documentation of this file.
1/* (c) Shereef Marzouk. See "licence DDRace.txt" and the readme.txt in the root of the distribution for more information. */
2#ifndef GAME_SERVER_TEAMS_H
3#define GAME_SERVER_TEAMS_H
4
7#include <game/teamscore.h>
8
9class CCharacter;
10class CPlayer;
11struct CScoreSaveResult;
12
14{
15 // `m_TeeStarted` is used to keep track whether a given tee has hit the
16 // start of the map yet. If a tee that leaves hasn't hit the start line
17 // yet, the team will be marked as "not allowed to finish"
18 // (`TEAMSTATE_STARTED_UNFINISHABLE`). If this were not the case, tees
19 // could go around the startline on a map, leave one tee behind at
20 // start, go to the finish line, let the tee start and kill, allowing
21 // the team to finish instantly.
25
31 std::shared_ptr<CScoreSaveResult> m_apSaveTeamResult[NUM_DDRACE_TEAMS];
32 uint64_t m_aLastSwap[MAX_CLIENTS]; // index is id of player who initiated swap
34 // `m_aTeamUnfinishableKillTick` is -1 by default and gets set when a
35 // team becomes unfinishable. If the team hasn't entered practice mode
36 // by that time, it'll get killed to prevent people not understanding
37 // the message from playing for a long time in an unfinishable team.
39
41
48 void KillTeam(int Team, int NewStrongId, int ExceptId = -1);
49 bool TeamFinished(int Team);
50 void OnTeamFinish(int Team, CPlayer **Players, unsigned int Size, int TimeTicks, const char *pTimestamp);
51 void OnFinish(CPlayer *Player, int TimeTicks, const char *pTimestamp);
52
53public:
54 enum
55 {
59 // Happens when a tee that hasn't hit the start tiles leaves
60 // the team.
63 };
64
66
67 CGameTeams(CGameContext *pGameContext);
68
69 // helper methods
70 CCharacter *Character(int ClientId)
71 {
72 return GameServer()->GetPlayerChar(ClientId);
73 }
74 CPlayer *GetPlayer(int ClientId)
75 {
76 return GameServer()->m_apPlayers[ClientId];
77 }
78
80 {
81 return m_pGameContext;
82 }
83 class IServer *Server()
84 {
85 return m_pGameContext->Server();
86 }
87
88 void OnCharacterStart(int ClientId);
89 void OnCharacterFinish(int ClientId);
90 void OnCharacterSpawn(int ClientId);
91 void OnCharacterDeath(int ClientId, int Weapon);
92 void Tick();
93
94 // returns nullptr if successful, error string if failed
95 const char *SetCharacterTeam(int ClientId, int Team);
96 void CheckTeamFinished(int Team);
97
98 void ChangeTeamState(int Team, int State);
99
100 CClientMask TeamMask(int Team, int ExceptId = -1, int Asker = -1, int VersionFlags = CGameContext::FLAG_SIX | CGameContext::FLAG_SIXUP);
101
102 int Count(int Team) const;
103
104 // need to be very careful using this method. SERIOUSLY...
105 void SetForceCharacterTeam(int ClientId, int Team);
106
107 void Reset();
108 void ResetRoundState(int Team);
109 void ResetSwitchers(int Team);
110
111 void SendTeamsState(int ClientId);
112 void SetTeamLock(int Team, bool Lock);
113 void SetTeamFlock(int Team, bool Mode);
114 void ResetInvited(int Team);
115 void SetClientInvited(int Team, int ClientId, bool Invited);
116
117 int GetDDRaceState(CPlayer *Player);
118 int GetStartTime(CPlayer *Player);
119 float *GetCurrentTimeCp(CPlayer *Player);
120 void SetDDRaceState(CPlayer *Player, int DDRaceState);
121 void SetStartTime(CPlayer *Player, int StartTime);
122 void SetLastTimeCp(CPlayer *Player, int LastTimeCp);
123 void KillCharacterOrTeam(int ClientId, int Team);
124 void ResetSavedTeam(int ClientId, int Team);
125 void RequestTeamSwap(CPlayer *pPlayer, CPlayer *pTargetPlayer, int Team);
126 void SwapTeamCharacters(CPlayer *pPrimaryPlayer, CPlayer *pTargetPlayer, int Team);
127 void CancelTeamSwap(CPlayer *pPlayer, int Team);
128 void ProcessSaveTeam();
129
130 int GetFirstEmptyTeam() const;
131
132 bool TeeStarted(int ClientId)
133 {
134 return m_aTeeStarted[ClientId];
135 }
136
137 bool TeeFinished(int ClientId)
138 {
139 return m_aTeeFinished[ClientId];
140 }
141
142 int GetTeamState(int Team)
143 {
144 return m_aTeamState[Team];
145 }
146
147 bool TeamLocked(int Team)
148 {
149 if(Team <= TEAM_FLOCK || Team >= TEAM_SUPER)
150 return false;
151
152 return m_aTeamLocked[Team];
153 }
154
155 bool TeamFlock(int Team)
156 {
157 if(Team <= TEAM_FLOCK || Team >= TEAM_SUPER)
158 return false;
159
160 return m_aTeamFlock[Team];
161 }
162
163 bool IsInvited(int Team, int ClientId)
164 {
165 return m_aInvited[Team].test(ClientId);
166 }
167
168 bool IsStarted(int Team)
169 {
171 }
172
173 void SetStarted(int ClientId, bool Started)
174 {
175 m_aTeeStarted[ClientId] = Started;
176 }
177
178 void SetFinished(int ClientId, bool Finished)
179 {
180 m_aTeeFinished[ClientId] = Finished;
181 }
182
183 void SetSaving(int TeamId, std::shared_ptr<CScoreSaveResult> &SaveResult)
184 {
185 m_apSaveTeamResult[TeamId] = SaveResult;
186 }
187
188 bool GetSaving(int TeamId)
189 {
190 if(TeamId < TEAM_FLOCK || TeamId >= TEAM_SUPER)
191 return false;
192 if(g_Config.m_SvTeam != SV_TEAM_FORCED_SOLO && TeamId == TEAM_FLOCK)
193 return false;
194
195 return m_apSaveTeamResult[TeamId] != nullptr;
196 }
197
198 void SetPractice(int Team, bool Enabled)
199 {
200 if(Team < TEAM_FLOCK || Team >= TEAM_SUPER)
201 return;
202 if(g_Config.m_SvTeam != SV_TEAM_FORCED_SOLO && Team == TEAM_FLOCK)
203 return;
204
205 m_aPractice[Team] = Enabled;
206 }
207
208 bool IsPractice(int Team)
209 {
210 if(Team < TEAM_FLOCK || Team >= TEAM_SUPER)
211 return false;
212 if(g_Config.m_SvTeam != SV_TEAM_FORCED_SOLO && Team == TEAM_FLOCK)
213 {
215 return true;
216
217 return false;
218 }
219
220 return m_aPractice[Team];
221 }
222};
223
224#endif
Definition: character.h:24
Definition: gamecontext.h:74
bool PracticeByDefault() const
Definition: gamecontext.cpp:5038
@ FLAG_SIXUP
Definition: gamecontext.h:254
@ FLAG_SIX
Definition: gamecontext.h:253
CPlayer * m_apPlayers[MAX_CLIENTS]
Definition: gamecontext.h:176
IServer * Server() const
Definition: gamecontext.h:156
class CCharacter * GetPlayerChar(int ClientId)
Definition: gamecontext.cpp:211
Definition: teams.h:14
void OnCharacterSpawn(int ClientId)
Definition: teams.cpp:1106
int Count(int Team) const
Definition: teams.cpp:457
bool TeamFlock(int Team)
Definition: teams.h:155
float * GetCurrentTimeCp(CPlayer *Player)
Definition: teams.cpp:668
bool IsPractice(int Team)
Definition: teams.h:208
void SetFinished(int ClientId, bool Finished)
Definition: teams.h:178
class CGameContext * GameServer()
Definition: teams.h:79
CTeamsCore m_Core
Definition: teams.h:65
CGameTeams(CGameContext *pGameContext)
Definition: teams.cpp:14
bool IsInvited(int Team, int ClientId)
Definition: teams.h:163
bool IsStarted(int Team)
Definition: teams.h:168
int GetStartTime(CPlayer *Player)
Definition: teams.cpp:637
int GetFirstEmptyTeam() const
Definition: teams.cpp:1261
void OnTeamFinish(int Team, CPlayer **Players, unsigned int Size, int TimeTicks, const char *pTimestamp)
Definition: teams.cpp:679
bool m_aTeeFinished[MAX_CLIENTS]
Definition: teams.h:23
void CheckTeamFinished(int Team)
Definition: teams.cpp:317
uint64_t m_aLastSwap[MAX_CLIENTS]
Definition: teams.h:32
bool TeeStarted(int ClientId)
Definition: teams.h:132
void Reset()
Definition: teams.cpp:20
int m_aTeamState[NUM_DDRACE_TEAMS]
Definition: teams.h:26
bool m_aTeamLocked[NUM_DDRACE_TEAMS]
Definition: teams.h:27
void KillTeam(int Team, int NewStrongId, int ExceptId=-1)
Definition: teams.cpp:476
void OnFinish(CPlayer *Player, int TimeTicks, const char *pTimestamp)
Definition: teams.cpp:701
const char * SetCharacterTeam(int ClientId, int Team)
Definition: teams.cpp:380
@ TEAMSTATE_FINISHED
Definition: teams.h:62
@ TEAMSTATE_STARTED_UNFINISHABLE
Definition: teams.h:61
@ TEAMSTATE_STARTED
Definition: teams.h:58
@ TEAMSTATE_EMPTY
Definition: teams.h:56
@ TEAMSTATE_OPEN
Definition: teams.h:57
void SwapTeamCharacters(CPlayer *pPrimaryPlayer, CPlayer *pTargetPlayer, int Team)
Definition: teams.cpp:913
int GetDDRaceState(CPlayer *Player)
Definition: teams.cpp:616
int GetTeamState(int Team)
Definition: teams.h:142
class CGameContext * m_pGameContext
Definition: teams.h:40
void ResetRoundState(int Team)
Definition: teams.cpp:44
void ResetInvited(int Team)
Definition: teams.cpp:1214
bool TeamLocked(int Team)
Definition: teams.h:147
void SetStarted(int ClientId, bool Started)
Definition: teams.h:173
bool m_aTeamFlock[NUM_DDRACE_TEAMS]
Definition: teams.h:28
void ChangeTeamState(int Team, int State)
Definition: teams.cpp:471
bool m_aTeamSentStartWarning[NUM_DDRACE_TEAMS]
Definition: teams.h:33
void RequestTeamSwap(CPlayer *pPlayer, CPlayer *pTargetPlayer, int Team)
Definition: teams.cpp:866
void CancelTeamSwap(CPlayer *pPlayer, int Team)
Definition: teams.cpp:984
void ProcessSaveTeam()
Definition: teams.cpp:1022
CClientMask m_aInvited[NUM_DDRACE_TEAMS]
Definition: teams.h:29
void SetTeamFlock(int Team, bool Mode)
Definition: teams.cpp:1208
void SetTeamLock(int Team, bool Lock)
Definition: teams.cpp:1202
int m_aLastChat[MAX_CLIENTS]
Definition: teams.h:24
void OnCharacterStart(int ClientId)
Definition: teams.cpp:74
CClientMask TeamMask(int Team, int ExceptId=-1, int Asker=-1, int VersionFlags=CGameContext::FLAG_SIX|CGameContext::FLAG_SIXUP)
Definition: teams.cpp:513
void OnCharacterDeath(int ClientId, int Weapon)
Definition: teams.cpp:1125
void SetDDRaceState(CPlayer *Player, int DDRaceState)
Definition: teams.cpp:627
void SetLastTimeCp(CPlayer *Player, int LastTimeCp)
Definition: teams.cpp:658
void SetStartTime(CPlayer *Player, int StartTime)
Definition: teams.cpp:648
bool TeamFinished(int Team)
Definition: teams.cpp:501
void SetClientInvited(int Team, int ClientId, bool Invited)
Definition: teams.cpp:1219
void ResetSwitchers(int Team)
Definition: teams.cpp:64
void Tick()
Definition: teams.cpp:218
void SetSaving(int TeamId, std::shared_ptr< CScoreSaveResult > &SaveResult)
Definition: teams.h:183
void OnCharacterFinish(int ClientId)
Definition: teams.cpp:192
CPlayer * GetPlayer(int ClientId)
Definition: teams.h:74
bool m_aTeeStarted[MAX_CLIENTS]
Definition: teams.h:22
CCharacter * Character(int ClientId)
Definition: teams.h:70
bool GetSaving(int TeamId)
Definition: teams.h:188
void ResetSavedTeam(int ClientId, int Team)
Definition: teams.cpp:1242
class IServer * Server()
Definition: teams.h:83
std::shared_ptr< CScoreSaveResult > m_apSaveTeamResult[NUM_DDRACE_TEAMS]
Definition: teams.h:31
void KillCharacterOrTeam(int ClientId, int Team)
Definition: teams.cpp:1230
bool TeeFinished(int ClientId)
Definition: teams.h:137
void SetPractice(int Team, bool Enabled)
Definition: teams.h:198
void SendTeamsState(int ClientId)
Definition: teams.cpp:591
void SetForceCharacterTeam(int ClientId, int Team)
Definition: teams.cpp:411
int m_aTeamUnfinishableKillTick[NUM_DDRACE_TEAMS]
Definition: teams.h:38
bool m_aPractice[NUM_DDRACE_TEAMS]
Definition: teams.h:30
Definition: player.h:24
Definition: teamscore.h:25
Definition: server.h:31
CConfig g_Config
Definition: config.cpp:12
std::bitset< MAX_CLIENTS > CClientMask
Definition: protocol.h:140
@ MAX_CLIENTS
Definition: protocol.h:88
Definition: scoreworker.h:152
@ SV_TEAM_FORCED_SOLO
Definition: teamscore.h:21
@ TEAM_SUPER
Definition: teamscore.h:10
@ NUM_DDRACE_TEAMS
Definition: teamscore.h:11