2011-12-25 13:33:05 +00:00
|
|
|
/* (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
|
|
|
|
|
2020-06-30 18:22:17 +00:00
|
|
|
#include <engine/shared/config.h>
|
2010-08-28 13:47:52 +00:00
|
|
|
#include <game/server/gamecontext.h>
|
2020-09-26 19:41:58 +00:00
|
|
|
#include <game/teamscore.h>
|
2010-08-28 13:47:52 +00:00
|
|
|
|
2022-06-17 17:54:10 +00:00
|
|
|
class CCharacter;
|
|
|
|
class CPlayer;
|
|
|
|
struct CScoreSaveResult;
|
|
|
|
|
2011-01-06 05:30:19 +00:00
|
|
|
class CGameTeams
|
|
|
|
{
|
2021-07-20 11:37:02 +00:00
|
|
|
// `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.
|
2022-06-30 22:36:32 +00:00
|
|
|
bool m_aTeeStarted[MAX_CLIENTS];
|
|
|
|
bool m_aTeeFinished[MAX_CLIENTS];
|
|
|
|
int m_aLastChat[MAX_CLIENTS];
|
|
|
|
|
|
|
|
int m_aTeamState[NUM_TEAMS];
|
|
|
|
bool m_aTeamLocked[NUM_TEAMS];
|
2023-11-21 22:38:45 +00:00
|
|
|
bool m_aTeamMode[NUM_TEAMS];
|
2023-01-24 08:27:29 +00:00
|
|
|
CClientMask m_aInvited[NUM_TEAMS];
|
2022-06-30 22:36:32 +00:00
|
|
|
bool m_aPractice[NUM_TEAMS];
|
|
|
|
std::shared_ptr<CScoreSaveResult> m_apSaveTeamResult[NUM_TEAMS];
|
2022-12-17 22:56:08 +00:00
|
|
|
uint64_t m_aLastSwap[MAX_CLIENTS]; // index is id of player who initiated swap
|
2022-06-30 22:36:32 +00:00
|
|
|
bool m_aTeamSentStartWarning[NUM_TEAMS];
|
|
|
|
// `m_aTeamUnfinishableKillTick` is -1 by default and gets set when a
|
2021-09-10 16:14:16 +00:00
|
|
|
// 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.
|
2022-06-30 22:36:32 +00:00
|
|
|
int m_aTeamUnfinishableKillTick[NUM_TEAMS];
|
2011-12-25 13:51:04 +00:00
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
class CGameContext *m_pGameContext;
|
2011-12-25 13:51:04 +00:00
|
|
|
|
2021-11-01 15:44:59 +00:00
|
|
|
/**
|
|
|
|
* Kill the whole team.
|
|
|
|
* @param Team The team id to kill
|
2024-03-05 14:44:09 +00:00
|
|
|
* @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
|
2021-11-01 15:44:59 +00:00
|
|
|
*/
|
2024-03-05 14:44:09 +00:00
|
|
|
void KillTeam(int Team, int NewStrongId, int ExceptId = -1);
|
2019-01-10 08:32:23 +00:00
|
|
|
bool TeamFinished(int Team);
|
2020-09-26 19:41:58 +00:00
|
|
|
void OnTeamFinish(CPlayer **Players, unsigned int Size, float Time, const char *pTimestamp);
|
|
|
|
void OnFinish(CPlayer *Player, float Time, const char *pTimestamp);
|
2019-01-10 08:32:23 +00:00
|
|
|
|
2010-08-28 13:47:52 +00:00
|
|
|
public:
|
2011-03-16 13:14:25 +00:00
|
|
|
enum
|
2011-01-06 05:30:19 +00:00
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
TEAMSTATE_EMPTY,
|
|
|
|
TEAMSTATE_OPEN,
|
|
|
|
TEAMSTATE_STARTED,
|
2021-07-20 11:37:02 +00:00
|
|
|
// Happens when a tee that hasn't hit the start tiles leaves
|
|
|
|
// the team.
|
|
|
|
TEAMSTATE_STARTED_UNFINISHABLE,
|
2020-09-26 19:41:58 +00:00
|
|
|
TEAMSTATE_FINISHED
|
2010-08-28 13:47:52 +00:00
|
|
|
};
|
2011-12-25 13:51:04 +00:00
|
|
|
|
2010-08-30 12:13:43 +00:00
|
|
|
CTeamsCore m_Core;
|
2011-12-25 13:51:04 +00:00
|
|
|
|
2010-08-30 12:13:43 +00:00
|
|
|
CGameTeams(CGameContext *pGameContext);
|
2011-12-25 13:51:04 +00:00
|
|
|
|
2021-01-23 14:45:07 +00:00
|
|
|
// helper methods
|
2024-03-05 14:44:09 +00:00
|
|
|
CCharacter *Character(int ClientId)
|
2011-12-25 13:51:04 +00:00
|
|
|
{
|
2024-03-05 14:44:09 +00:00
|
|
|
return GameServer()->GetPlayerChar(ClientId);
|
2011-12-25 13:51:04 +00:00
|
|
|
}
|
2024-03-05 14:44:09 +00:00
|
|
|
CPlayer *GetPlayer(int ClientId)
|
2011-12-25 13:51:04 +00:00
|
|
|
{
|
2024-03-05 14:44:09 +00:00
|
|
|
return GameServer()->m_apPlayers[ClientId];
|
2011-12-25 13:51:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class CGameContext *GameServer()
|
|
|
|
{
|
|
|
|
return m_pGameContext;
|
|
|
|
}
|
|
|
|
class IServer *Server()
|
|
|
|
{
|
|
|
|
return m_pGameContext->Server();
|
|
|
|
}
|
2010-08-28 20:53:42 +00:00
|
|
|
|
2024-03-05 14:44:09 +00:00
|
|
|
void OnCharacterStart(int ClientId);
|
|
|
|
void OnCharacterFinish(int ClientId);
|
|
|
|
void OnCharacterSpawn(int ClientId);
|
|
|
|
void OnCharacterDeath(int ClientId, int Weapon);
|
2021-07-20 20:34:09 +00:00
|
|
|
void Tick();
|
2011-12-25 13:51:04 +00:00
|
|
|
|
2021-01-23 14:45:07 +00:00
|
|
|
// returns nullptr if successful, error string if failed
|
2024-03-05 14:44:09 +00:00
|
|
|
const char *SetCharacterTeam(int ClientId, int Team);
|
2022-01-22 13:12:59 +00:00
|
|
|
void CheckTeamFinished(int Team);
|
2011-12-25 13:51:04 +00:00
|
|
|
|
2011-03-16 13:14:25 +00:00
|
|
|
void ChangeTeamState(int Team, int State);
|
2011-12-25 13:51:04 +00:00
|
|
|
|
2024-03-05 14:44:09 +00:00
|
|
|
CClientMask TeamMask(int Team, int ExceptId = -1, int Asker = -1);
|
2011-12-25 13:51:04 +00:00
|
|
|
|
2010-11-06 22:54:35 +00:00
|
|
|
int Count(int Team) const;
|
2011-12-25 13:51:04 +00:00
|
|
|
|
2021-01-23 14:45:07 +00:00
|
|
|
// need to be very careful using this method. SERIOUSLY...
|
2024-03-05 14:44:09 +00:00
|
|
|
void SetForceCharacterTeam(int ClientId, int Team);
|
2011-12-25 13:51:04 +00:00
|
|
|
|
2010-09-24 13:37:13 +00:00
|
|
|
void Reset();
|
2021-03-16 22:31:16 +00:00
|
|
|
void ResetRoundState(int Team);
|
2020-07-01 06:49:51 +00:00
|
|
|
void ResetSwitchers(int Team);
|
2011-12-25 13:51:04 +00:00
|
|
|
|
2024-03-05 14:44:09 +00:00
|
|
|
void SendTeamsState(int ClientId);
|
2013-11-15 23:44:49 +00:00
|
|
|
void SetTeamLock(int Team, bool Lock);
|
2023-11-21 22:38:45 +00:00
|
|
|
void SetTeamMode(int Team, bool Mode);
|
2017-04-23 20:50:07 +00:00
|
|
|
void ResetInvited(int Team);
|
2024-03-05 14:44:09 +00:00
|
|
|
void SetClientInvited(int Team, int ClientId, bool Invited);
|
2010-12-19 03:48:16 +00:00
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
int GetDDRaceState(CPlayer *Player);
|
|
|
|
int GetStartTime(CPlayer *Player);
|
2022-07-05 14:13:48 +00:00
|
|
|
float *GetCurrentTimeCp(CPlayer *Player);
|
2020-09-26 19:41:58 +00:00
|
|
|
void SetDDRaceState(CPlayer *Player, int DDRaceState);
|
|
|
|
void SetStartTime(CPlayer *Player, int StartTime);
|
2022-07-05 14:13:48 +00:00
|
|
|
void SetLastTimeCp(CPlayer *Player, int LastTimeCp);
|
2024-03-05 14:44:09 +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);
|
2022-06-20 16:12:54 +00:00
|
|
|
void SwapTeamCharacters(CPlayer *pPrimaryPlayer, CPlayer *pTargetPlayer, int Team);
|
2020-06-02 14:27:31 +00:00
|
|
|
void ProcessSaveTeam();
|
2014-12-17 19:38:05 +00:00
|
|
|
|
2021-08-10 19:26:07 +00:00
|
|
|
int GetFirstEmptyTeam() const;
|
|
|
|
|
2024-03-05 14:44:09 +00:00
|
|
|
bool TeeStarted(int ClientId)
|
2021-07-20 20:16:40 +00:00
|
|
|
{
|
2024-03-05 14:44:09 +00:00
|
|
|
return m_aTeeStarted[ClientId];
|
2021-07-20 20:16:40 +00:00
|
|
|
}
|
|
|
|
|
2024-03-05 14:44:09 +00:00
|
|
|
bool TeeFinished(int ClientId)
|
2011-12-25 13:51:04 +00:00
|
|
|
{
|
2024-03-05 14:44:09 +00:00
|
|
|
return m_aTeeFinished[ClientId];
|
2011-12-25 13:51:04 +00:00
|
|
|
}
|
2014-12-17 19:38:05 +00:00
|
|
|
|
2011-12-25 13:51:04 +00:00
|
|
|
int GetTeamState(int Team)
|
|
|
|
{
|
2022-06-30 22:36:32 +00:00
|
|
|
return m_aTeamState[Team];
|
2011-12-25 13:51:04 +00:00
|
|
|
}
|
2014-12-17 19:38:05 +00:00
|
|
|
|
2013-11-15 23:44:49 +00:00
|
|
|
bool TeamLocked(int Team)
|
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
if(Team <= TEAM_FLOCK || Team >= TEAM_SUPER)
|
2014-01-30 02:37:45 +00:00
|
|
|
return false;
|
|
|
|
|
2022-06-30 22:36:32 +00:00
|
|
|
return m_aTeamLocked[Team];
|
2013-11-15 23:44:49 +00:00
|
|
|
}
|
2014-12-17 19:38:05 +00:00
|
|
|
|
2023-11-21 22:38:45 +00:00
|
|
|
bool TeamMode(int Team)
|
|
|
|
{
|
|
|
|
if(Team <= TEAM_FLOCK || Team >= TEAM_SUPER)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return m_aTeamMode[Team];
|
|
|
|
}
|
|
|
|
|
2024-03-05 14:44:09 +00:00
|
|
|
bool IsInvited(int Team, int ClientId)
|
2017-04-23 20:50:07 +00:00
|
|
|
{
|
2024-03-05 14:44:09 +00:00
|
|
|
return m_aInvited[Team].test(ClientId);
|
2017-04-23 20:50:07 +00:00
|
|
|
}
|
|
|
|
|
2021-03-16 22:31:16 +00:00
|
|
|
bool IsStarted(int Team)
|
|
|
|
{
|
2022-06-30 22:36:32 +00:00
|
|
|
return m_aTeamState[Team] == CGameTeams::TEAMSTATE_STARTED;
|
2021-03-16 22:31:16 +00:00
|
|
|
}
|
|
|
|
|
2024-03-05 14:44:09 +00:00
|
|
|
void SetStarted(int ClientId, bool Started)
|
2021-07-20 20:16:40 +00:00
|
|
|
{
|
2024-03-05 14:44:09 +00:00
|
|
|
m_aTeeStarted[ClientId] = Started;
|
2021-07-20 20:16:40 +00:00
|
|
|
}
|
|
|
|
|
2024-03-05 14:44:09 +00:00
|
|
|
void SetFinished(int ClientId, bool Finished)
|
2014-07-26 12:46:31 +00:00
|
|
|
{
|
2024-03-05 14:44:09 +00:00
|
|
|
m_aTeeFinished[ClientId] = Finished;
|
2014-07-26 12:46:31 +00:00
|
|
|
}
|
2020-06-24 21:14:09 +00:00
|
|
|
|
2024-03-05 14:44:09 +00:00
|
|
|
void SetSaving(int TeamId, std::shared_ptr<CScoreSaveResult> &SaveResult)
|
2014-12-17 19:38:05 +00:00
|
|
|
{
|
2024-03-05 14:44:09 +00:00
|
|
|
m_apSaveTeamResult[TeamId] = SaveResult;
|
2014-12-17 19:38:05 +00:00
|
|
|
}
|
|
|
|
|
2024-03-05 14:44:09 +00:00
|
|
|
bool GetSaving(int TeamId)
|
2014-12-17 19:38:05 +00:00
|
|
|
{
|
2024-03-05 14:44:09 +00:00
|
|
|
if(TeamId < TEAM_FLOCK || TeamId >= TEAM_SUPER)
|
2020-06-30 18:22:17 +00:00
|
|
|
return false;
|
2024-03-05 14:44:09 +00:00
|
|
|
if(g_Config.m_SvTeam != SV_TEAM_FORCED_SOLO && TeamId == TEAM_FLOCK)
|
2020-06-28 11:25:39 +00:00
|
|
|
return false;
|
|
|
|
|
2024-03-05 14:44:09 +00:00
|
|
|
return m_apSaveTeamResult[TeamId] != nullptr;
|
2014-12-17 19:38:05 +00:00
|
|
|
}
|
2020-05-22 21:59:47 +00:00
|
|
|
|
2022-03-25 09:09:45 +00:00
|
|
|
void SetPractice(int Team, bool Enabled)
|
2020-05-22 21:59:47 +00:00
|
|
|
{
|
2020-06-30 18:22:17 +00:00
|
|
|
if(Team < TEAM_FLOCK || Team >= TEAM_SUPER)
|
|
|
|
return;
|
2022-02-19 14:20:32 +00:00
|
|
|
if(g_Config.m_SvTeam != SV_TEAM_FORCED_SOLO && Team == TEAM_FLOCK)
|
2020-05-22 21:59:47 +00:00
|
|
|
return;
|
|
|
|
|
2022-06-30 22:36:32 +00:00
|
|
|
m_aPractice[Team] = Enabled;
|
2020-05-22 21:59:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool IsPractice(int Team)
|
|
|
|
{
|
2020-06-30 18:22:17 +00:00
|
|
|
if(Team < TEAM_FLOCK || Team >= TEAM_SUPER)
|
|
|
|
return false;
|
2022-02-19 14:20:32 +00:00
|
|
|
if(g_Config.m_SvTeam != SV_TEAM_FORCED_SOLO && Team == TEAM_FLOCK)
|
2020-05-22 21:59:47 +00:00
|
|
|
return false;
|
|
|
|
|
2022-06-30 22:36:32 +00:00
|
|
|
return m_aPractice[Team];
|
2020-05-22 21:59:47 +00:00
|
|
|
}
|
2010-08-28 13:47:52 +00:00
|
|
|
};
|
|
|
|
|
2010-09-08 16:22:11 +00:00
|
|
|
#endif
|