ddnet/src/game/server/teams.h

163 lines
3.7 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/teamscore.h>
2010-08-28 13:47:52 +00:00
2020-11-05 10:34:20 +00:00
#include <utility>
class CGameTeams
{
int m_TeamState[MAX_CLIENTS];
bool m_TeeFinished[MAX_CLIENTS];
bool m_TeamLocked[MAX_CLIENTS];
uint64 m_Invited[MAX_CLIENTS];
bool m_Practice[MAX_CLIENTS];
std::shared_ptr<CScoreSaveResult> m_pSaveTeamResult[MAX_CLIENTS];
class CGameContext *m_pGameContext;
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,
TEAMSTATE_FINISHED
2010-08-28 13:47:52 +00:00
};
CTeamsCore m_Core;
CGameTeams(CGameContext *pGameContext);
2010-08-28 13:47:52 +00:00
//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);
bool SetCharacterTeam(int ClientID, int Team);
void CheckTeamFinished(int ClientID);
void ChangeTeamState(int Team, int State);
void onChangeTeamState(int Team, int State, int OldState);
int64 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 SetForceCharacterNewTeam(int ClientID, int Team);
void ForceLeaveTeam(int ClientID);
void Reset();
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 m_LastChat[MAX_CLIENTS];
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);
void ProcessSaveTeam();
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;
}
2014-07-26 12:46:31 +00:00
void SetFinished(int ClientID, bool finished)
{
m_TeeFinished[ClientID] = finished;
}
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 != 3 && 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 != 3 && 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 != 3 && Team == TEAM_FLOCK)
return false;
return m_Practice[Team];
}
2010-08-28 13:47:52 +00:00
};
#endif