DDNet documentation
Loading...
Searching...
No Matches
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
6
7#include <game/race_state.h>
9#include <game/team_state.h>
10#include <game/teamscore.h>
11
12#include <memory>
13#include <optional>
14
15class CCharacter;
16class CPlayer;
17struct CScoreSaveResult;
18
20{
21 // `m_TeeStarted` is used to keep track whether a given tee has hit the
22 // start of the map yet. If a tee that leaves hasn't hit the start line
23 // yet, the team will be marked as "not allowed to finish"
24 // (`ETeamState::STARTED_UNFINISHABLE`). If this were not the case, tees
25 // could go around the startline on a map, leave one tee behind at
26 // start, go to the finish line, let the tee start and kill, allowing
27 // the team to finish instantly.
31
37 std::shared_ptr<CScoreSaveResult> m_apSaveTeamResult[NUM_DDRACE_TEAMS];
38 uint64_t m_aLastSwap[MAX_CLIENTS]; // index is id of player who initiated swap
40 // `m_aTeamUnfinishableKillTick` is -1 by default and gets set when a
41 // team becomes unfinishable. If the team hasn't entered practice mode
42 // by that time, it'll get killed to prevent people not understanding
43 // the message from playing for a long time in an unfinishable team.
45
46 // Team numbers as they are sent to clients before VERSION_DDNET_128_TEAMS, see UpdateLegacyTeamMap
49
51
58 void KillTeam(int Team, int NewStrongId, int ExceptId = -1);
59 bool TeamFinished(int Team);
60 void OnTeamFinish(int Team, CPlayer **Players, unsigned int Size, int TimeTicks, const char *pTimestamp);
61 void OnFinish(CPlayer *Player, int TimeTicks, const char *pTimestamp);
62
63public:
65
66 CGameTeams(CGameContext *pGameContext);
67
68 // helper methods
69 CCharacter *Character(int ClientId);
70 const CCharacter *Character(int ClientId) const;
71 CPlayer *GetPlayer(int ClientId);
73 const CGameContext *GameServer() const;
74 class IServer *Server();
75
81 int TeamForClient(int Team, int ClientId) const;
82
83 void OnCharacterStart(int ClientId);
84 void OnCharacterFinish(int ClientId);
85 void OnCharacterSpawn(int ClientId);
86 void OnCharacterDeath(int ClientId, int Weapon);
87 void Tick();
88
89 // sets pError to an empty string on success (true)
90 // and sets pError if it returns false
91 bool CanJoinTeam(int ClientId, int Team, char *pError, int ErrorSize) const;
92
93 // returns true if successful. Writes error into pError on failure
94 bool SetCharacterTeam(int ClientId, int Team, char *pError, int ErrorSize);
95 void CheckTeamFinished(int Team);
96
97 void ChangeTeamState(int Team, ETeamState State);
98
99 CClientMask TeamMask(int Team, int ExceptId = -1, int Asker = -1, int VersionFlags = CGameContext::FLAG_SIX | CGameContext::FLAG_SIXUP);
100
101 int TeamSize(int Team) const;
102
103 // need to be very careful using this method. SERIOUSLY...
104 void SetForceCharacterTeam(int ClientId, int Team);
105
106 void Reset();
107 void ResetRoundState(int Team);
108 void ResetSwitchers(int Team);
109
110 void SendTeamsState(int ClientId);
111 void SetTeamLock(int Team, bool Lock);
112 void SetTeamFlock(int Team, bool Mode);
113 void ResetInvited(int Team);
114 void SetClientInvited(int Team, int ClientId, bool Invited);
115
116 ERaceState GetDDRaceState(const CPlayer *Player) const;
117 int GetStartTime(CPlayer *Player);
118 float *GetCurrentTimeCp(CPlayer *Player);
119 void SetDDRaceState(CPlayer *Player, ERaceState DDRaceState);
120 void SetStartTime(CPlayer *Player, int StartTime);
121 void SetLastTimeCp(CPlayer *Player, int LastTimeCp);
122 void KillCharacterOrTeam(int ClientId, int Team);
123 void ResetSavedTeam(int ClientId, int Team);
124 void RequestTeamSwap(CPlayer *pPlayer, CPlayer *pTargetPlayer, int Team);
125 void SwapTeamCharacters(CPlayer *pPrimaryPlayer, CPlayer *pTargetPlayer, int Team);
126 void CancelTeamSwap(CPlayer *pPlayer, int Team);
127 void ProcessSaveTeam();
128 std::optional<int> GetFirstEmptyTeam() const;
129 bool TeeStarted(int ClientId) const;
130 bool TeeFinished(int ClientId) const;
131 ETeamState GetTeamState(int Team) const;
132 bool TeamLocked(int Team) const;
133 bool TeamFlock(int Team) const;
134 bool IsInvited(int Team, int ClientId) const;
135 bool IsStarted(int Team) const;
136 void SetStarted(int ClientId, bool Started);
137 void SetFinished(int ClientId, bool Finished);
138 void SetSaving(int TeamId, std::shared_ptr<CScoreSaveResult> &SaveResult);
139 bool GetSaving(int TeamId) const;
140 void SetPractice(int Team, bool Enabled);
141 bool IsPractice(int Team);
142 bool IsValidTeamNumber(int Team) const;
143};
144
145#endif
Definition character.h:24
Definition gamecontext.h:114
@ FLAG_SIXUP
Definition gamecontext.h:308
@ FLAG_SIX
Definition gamecontext.h:307
int TeamForClient(int Team, int ClientId) const
Definition teams.cpp:707
bool TeamLocked(int Team) const
Definition teams.cpp:1432
bool GetSaving(int TeamId) const
Definition teams.cpp:1474
void OnCharacterSpawn(int ClientId)
Definition teams.cpp:1240
CGameContext * m_pGameContext
Definition teams.h:50
float * GetCurrentTimeCp(CPlayer *Player)
Definition teams.cpp:770
bool IsPractice(int Team)
Definition teams.cpp:1498
void SetFinished(int ClientId, bool Finished)
Definition teams.cpp:1464
CTeamsCore m_Core
Definition teams.h:64
CGameTeams(CGameContext *pGameContext)
Definition teams.cpp:24
int GetStartTime(CPlayer *Player)
Definition teams.cpp:739
void OnTeamFinish(int Team, CPlayer **Players, unsigned int Size, int TimeTicks, const char *pTimestamp)
Definition teams.cpp:781
bool m_aTeeFinished[MAX_CLIENTS]
Definition teams.h:29
void CheckTeamFinished(int Team)
Definition teams.cpp:328
uint64_t m_aLastSwap[MAX_CLIENTS]
Definition teams.h:38
void Reset()
Definition teams.cpp:30
bool m_aTeamLocked[NUM_DDRACE_TEAMS]
Definition teams.h:33
void KillTeam(int Team, int NewStrongId, int ExceptId=-1)
Definition teams.cpp:528
void OnFinish(CPlayer *Player, int TimeTicks, const char *pTimestamp)
Definition teams.cpp:803
void SwapTeamCharacters(CPlayer *pPrimaryPlayer, CPlayer *pTargetPlayer, int Team)
Definition teams.cpp:1009
bool SetCharacterTeam(int ClientId, int Team, char *pError, int ErrorSize)
Definition teams.cpp:453
void ResetRoundState(int Team)
Definition teams.cpp:55
bool CanJoinTeam(int ClientId, int Team, char *pError, int ErrorSize) const
Definition teams.cpp:391
void ResetInvited(int Team)
Definition teams.cpp:1362
void SetStarted(int ClientId, bool Started)
Definition teams.cpp:1459
bool TeeStarted(int ClientId) const
Definition teams.cpp:1417
bool m_aTeamFlock[NUM_DDRACE_TEAMS]
Definition teams.h:34
bool m_aTeamSentStartWarning[NUM_DDRACE_TEAMS]
Definition teams.h:39
void RequestTeamSwap(CPlayer *pPlayer, CPlayer *pTargetPlayer, int Team)
Definition teams.cpp:962
void CancelTeamSwap(CPlayer *pPlayer, int Team)
Definition teams.cpp:1080
void ProcessSaveTeam()
Definition teams.cpp:1118
void SetDDRaceState(CPlayer *Player, ERaceState DDRaceState)
Definition teams.cpp:729
bool TeamFlock(int Team) const
Definition teams.cpp:1440
CClientMask m_aInvited[NUM_DDRACE_TEAMS]
Definition teams.h:35
void SetTeamFlock(int Team, bool Mode)
Definition teams.cpp:1356
void SetTeamLock(int Team, bool Lock)
Definition teams.cpp:1350
std::optional< int > GetFirstEmptyTeam() const
Definition teams.cpp:1409
void ChangeTeamState(int Team, ETeamState State)
Definition teams.cpp:523
ETeamState GetTeamState(int Team) const
Definition teams.cpp:1427
int m_aLegacyTeamMap[NUM_DDRACE_TEAMS]
Definition teams.h:47
int m_aLastChat[MAX_CLIENTS]
Definition teams.h:30
void OnCharacterStart(int ClientId)
Definition teams.cpp:85
bool TeeFinished(int ClientId) const
Definition teams.cpp:1422
void UpdateLegacyTeamMap()
Definition teams.cpp:673
CClientMask TeamMask(int Team, int ExceptId=-1, int Asker=-1, int VersionFlags=CGameContext::FLAG_SIX|CGameContext::FLAG_SIXUP)
Definition teams.cpp:577
void OnCharacterDeath(int ClientId, int Weapon)
Definition teams.cpp:1259
void SetLastTimeCp(CPlayer *Player, int LastTimeCp)
Definition teams.cpp:760
void SetStartTime(CPlayer *Player, int StartTime)
Definition teams.cpp:750
bool TeamFinished(int Team)
Definition teams.cpp:565
void SetClientInvited(int Team, int ClientId, bool Invited)
Definition teams.cpp:1367
void ResetSwitchers(int Team)
Definition teams.cpp:75
void Tick()
Definition teams.cpp:229
bool IsInvited(int Team, int ClientId) const
Definition teams.cpp:1449
void SetSaving(int TeamId, std::shared_ptr< CScoreSaveResult > &SaveResult)
Definition teams.cpp:1469
void OnCharacterFinish(int ClientId)
Definition teams.cpp:203
CPlayer * GetPlayer(int ClientId)
Definition teams.cpp:942
int TeamSize(int Team) const
Definition teams.cpp:509
ERaceState GetDDRaceState(const CPlayer *Player) const
Definition teams.cpp:718
CGameContext * GameServer()
Definition teams.cpp:947
bool IsValidTeamNumber(int Team) const
Definition teams.cpp:1513
ETeamState m_aTeamState[NUM_DDRACE_TEAMS]
Definition teams.h:32
bool m_aTeeStarted[MAX_CLIENTS]
Definition teams.h:28
CCharacter * Character(int ClientId)
Definition teams.cpp:932
void ResetSavedTeam(int ClientId, int Team)
Definition teams.cpp:1390
class IServer * Server()
Definition teams.cpp:957
std::shared_ptr< CScoreSaveResult > m_apSaveTeamResult[NUM_DDRACE_TEAMS]
Definition teams.h:37
void KillCharacterOrTeam(int ClientId, int Team)
Definition teams.cpp:1378
void SetPractice(int Team, bool Enabled)
Definition teams.cpp:1484
bool IsStarted(int Team) const
Definition teams.cpp:1454
void SendTeamsState(int ClientId)
Definition teams.cpp:614
void SetForceCharacterTeam(int ClientId, int Team)
Definition teams.cpp:462
int m_aTeamUnfinishableKillTick[NUM_DDRACE_TEAMS]
Definition teams.h:44
bool m_aPractice[NUM_DDRACE_TEAMS]
Definition teams.h:36
Definition player.h:26
Definition teamscore.h:26
Definition server.h:38
std::bitset< MAX_CLIENTS > CClientMask
Definition protocol.h:192
@ MAX_CLIENTS
Definition protocol.h:89
ERaceState
Definition race_state.h:5
Definition scoreworker.h:150
ETeamState
Definition team_state.h:5
@ NUM_DDRACE_TEAMS
Definition teamscore.h:11