ddnet/src/game/server/teams.h

208 lines
5.4 KiB
C
Raw Normal View History

/* (c) Shereef Marzouk. See "licence DDRace.txt" and the readme.txt in the root of the distribution for more information. */
2010-08-28 13:47:52 +00:00
#ifndef GAME_SERVER_TEAMS_H
#define GAME_SERVER_TEAMS_H
#include <engine/shared/config.h>
2010-08-28 13:47:52 +00:00
#include <game/server/gamecontext.h>
#include <game/server/score.h>
#include <game/teamscore.h>
2010-08-28 13:47:52 +00:00
2020-11-05 10:34:20 +00:00
#include <utility>
class CGameTeams
{
// `m_TeeStarted` is used to keep track whether a given tee has hit the
// start of the map yet. If a tee that leaves hasn't hit the start line
// yet, the team will be marked as "not allowed to finish"
// (`TEAMSTATE_STARTED_UNFINISHABLE`). If this were not the case, tees
// could go around the startline on a map, leave one tee behind at
// start, go to the finish line, let the tee start and kill, allowing
// the team to finish instantly.
bool m_TeeStarted[MAX_CLIENTS];
bool m_TeeFinished[MAX_CLIENTS];
int m_LastChat[MAX_CLIENTS];
int m_TeamState[NUM_TEAMS];
bool m_TeamLocked[NUM_TEAMS];
uint64_t m_Invited[NUM_TEAMS];
bool m_Practice[NUM_TEAMS];
std::shared_ptr<CScoreSaveResult> m_pSaveTeamResult[NUM_TEAMS];
uint64_t m_LastSwap[NUM_TEAMS];
bool m_TeamSentStartWarning[NUM_TEAMS];
// `m_TeamUnfinishableKillTick` is -1 by default and gets set when a
// team becomes unfinishable. If the team hasn't entered practice mode
// by that time, it'll get killed to prevent people not understanding
// the message from playing for a long time in an unfinishable team.
int m_TeamUnfinishableKillTick[NUM_TEAMS];
class CGameContext *m_pGameContext;
2021-11-01 15:44:59 +00:00
/**
* Kill the whole team.
* @param Team The team id to kill
* @param NewStrongID The player with that id will get strong hook on everyone else, -1 will set the normal spawning order
* @param ExceptID The player that should not get killed
*/
void KillTeam(int Team, int NewStrongID, int ExceptID = -1);
bool TeamFinished(int Team);
void OnTeamFinish(CPlayer **Players, unsigned int Size, float Time, const char *pTimestamp);
void OnFinish(CPlayer *Player, float Time, const char *pTimestamp);
2010-08-28 13:47:52 +00:00
public:
enum
{
TEAMSTATE_EMPTY,
TEAMSTATE_OPEN,
TEAMSTATE_STARTED,
// Happens when a tee that hasn't hit the start tiles leaves
// the team.
TEAMSTATE_STARTED_UNFINISHABLE,
TEAMSTATE_FINISHED
2010-08-28 13:47:52 +00:00
};
CTeamsCore m_Core;
CGameTeams(CGameContext *pGameContext);
// helper methods
CCharacter *Character(int ClientID)
{
return GameServer()->GetPlayerChar(ClientID);
}
CPlayer *GetPlayer(int ClientID)
{
return GameServer()->m_apPlayers[ClientID];
}
class CGameContext *GameServer()
{
return m_pGameContext;
}
class IServer *Server()
{
return m_pGameContext->Server();
}
void OnCharacterStart(int ClientID);
void OnCharacterFinish(int ClientID);
void OnCharacterSpawn(int ClientID);
void OnCharacterDeath(int ClientID, int Weapon);
void Tick();
// returns nullptr if successful, error string if failed
const char *SetCharacterTeam(int ClientID, int Team);
void CheckTeamFinished(int Team);
void ChangeTeamState(int Team, int State);
2021-06-23 05:05:49 +00:00
int64_t TeamMask(int Team, int ExceptID = -1, int Asker = -1);
2010-11-06 22:54:35 +00:00
int Count(int Team) const;
// need to be very careful using this method. SERIOUSLY...
void SetForceCharacterTeam(int ClientID, int Team);
void Reset();
void ResetRoundState(int Team);
void ResetSwitchers(int Team);
void SendTeamsState(int ClientID);
2013-11-15 23:44:49 +00:00
void SetTeamLock(int Team, bool Lock);
void ResetInvited(int Team);
void SetClientInvited(int Team, int ClientID, bool Invited);
int GetDDRaceState(CPlayer *Player);
int GetStartTime(CPlayer *Player);
float *GetCpCurrent(CPlayer *Player);
void SetDDRaceState(CPlayer *Player, int DDRaceState);
void SetStartTime(CPlayer *Player, int StartTime);
void SetCpActive(CPlayer *Player, int CpActive);
2020-06-02 14:27:31 +00:00
void KillSavedTeam(int ClientID, int Team);
void ResetSavedTeam(int ClientID, int Team);
2021-03-20 16:33:34 +00:00
void RequestTeamSwap(CPlayer *pPlayer, CPlayer *pTargetPlayer, int Team);
void SwapTeamCharacters(CPlayer *pPlayer, CPlayer *pTargetPlayer, int Team);
2020-06-02 14:27:31 +00:00
void ProcessSaveTeam();
2021-08-10 19:26:07 +00:00
int GetFirstEmptyTeam() const;
bool TeeStarted(int ClientID)
{
return m_TeeStarted[ClientID];
}
bool TeeFinished(int ClientID)
{
return m_TeeFinished[ClientID];
}
int GetTeamState(int Team)
{
return m_TeamState[Team];
}
2013-11-15 23:44:49 +00:00
bool TeamLocked(int Team)
{
if(Team <= TEAM_FLOCK || Team >= TEAM_SUPER)
2014-01-30 02:37:45 +00:00
return false;
2013-11-15 23:44:49 +00:00
return m_TeamLocked[Team];
}
bool IsInvited(int Team, int ClientID)
{
return m_Invited[Team] & 1LL << ClientID;
}
bool IsStarted(int Team)
{
return m_TeamState[Team] == CGameTeams::TEAMSTATE_STARTED;
}
void SetStarted(int ClientID, bool Started)
{
m_TeeStarted[ClientID] = Started;
}
void SetFinished(int ClientID, bool Finished)
2014-07-26 12:46:31 +00:00
{
m_TeeFinished[ClientID] = Finished;
2014-07-26 12:46:31 +00:00
}
void SetSaving(int TeamID, std::shared_ptr<CScoreSaveResult> &SaveResult)
{
m_pSaveTeamResult[TeamID] = SaveResult;
}
bool GetSaving(int TeamID)
{
if(TeamID < TEAM_FLOCK || TeamID >= TEAM_SUPER)
return false;
if(g_Config.m_SvTeam != SV_TEAM_FORCED_SOLO && TeamID == TEAM_FLOCK)
return false;
2020-06-02 14:27:31 +00:00
return m_pSaveTeamResult[TeamID] != nullptr;
}
void EnablePractice(int Team)
{
if(Team < TEAM_FLOCK || Team >= TEAM_SUPER)
return;
if(g_Config.m_SvTeam != SV_TEAM_FORCED_SOLO && Team == TEAM_FLOCK)
return;
m_Practice[Team] = true;
}
bool IsPractice(int Team)
{
if(Team < TEAM_FLOCK || Team >= TEAM_SUPER)
return false;
if(g_Config.m_SvTeam != SV_TEAM_FORCED_SOLO && Team == TEAM_FLOCK)
return false;
return m_Practice[Team];
}
2010-08-28 13:47:52 +00:00
};
#endif