mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 14:38:18 +00:00
made it possible to automatically swap teams between rounds
This commit is contained in:
parent
11cc0e78d7
commit
ccaec79567
|
@ -387,6 +387,22 @@ void CGameContext::SendTuningParams(int ClientID)
|
|||
Server()->SendMsg(&Msg, MSGFLAG_VITAL, ClientID);
|
||||
}
|
||||
|
||||
void CGameContext::SwapTeams()
|
||||
{
|
||||
if(!m_pController->IsTeamplay())
|
||||
return;
|
||||
|
||||
SendChat(-1, CGameContext::CHAT_ALL, "Teams were swapped");
|
||||
|
||||
for(int i = 0; i < MAX_CLIENTS; ++i)
|
||||
{
|
||||
if(m_apPlayers[i] && m_apPlayers[i]->GetTeam() != TEAM_SPECTATORS)
|
||||
m_apPlayers[i]->SetTeam(m_apPlayers[i]->GetTeam()^1, false);
|
||||
}
|
||||
|
||||
(void)m_pController->CheckTeamBalance();
|
||||
}
|
||||
|
||||
void CGameContext::OnTick()
|
||||
{
|
||||
// check tuning
|
||||
|
@ -1044,17 +1060,14 @@ void CGameContext::ConSetTeam(IConsole::IResult *pResult, void *pUserData)
|
|||
CGameContext *pSelf = (CGameContext *)pUserData;
|
||||
int ClientID = clamp(pResult->GetInteger(0), 0, (int)MAX_CLIENTS-1);
|
||||
int Team = clamp(pResult->GetInteger(1), -1, 1);
|
||||
int Delay = 0;
|
||||
if(pResult->NumArguments() > 2)
|
||||
Delay = pResult->GetInteger(2);
|
||||
int Delay = pResult->NumArguments()>2 ? pResult->GetInteger(2) : 0;
|
||||
if(!pSelf->m_apPlayers[ClientID])
|
||||
return;
|
||||
|
||||
char aBuf[256];
|
||||
str_format(aBuf, sizeof(aBuf), "moved client %d to team %d", ClientID, Team);
|
||||
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf);
|
||||
|
||||
if(!pSelf->m_apPlayers[ClientID])
|
||||
return;
|
||||
|
||||
pSelf->m_apPlayers[ClientID]->m_TeamChangeTick = pSelf->Server()->Tick()+pSelf->Server()->TickSpeed()*Delay*60;
|
||||
pSelf->m_apPlayers[ClientID]->SetTeam(Team);
|
||||
(void)pSelf->m_pController->CheckTeamBalance();
|
||||
|
@ -1079,18 +1092,7 @@ void CGameContext::ConSetTeamAll(IConsole::IResult *pResult, void *pUserData)
|
|||
void CGameContext::ConSwapTeams(IConsole::IResult *pResult, void *pUserData)
|
||||
{
|
||||
CGameContext *pSelf = (CGameContext *)pUserData;
|
||||
if(!pSelf->m_pController->IsTeamplay())
|
||||
return;
|
||||
|
||||
pSelf->SendChat(-1, CGameContext::CHAT_ALL, "Teams were swapped");
|
||||
|
||||
for(int i = 0; i < MAX_CLIENTS; ++i)
|
||||
{
|
||||
if(pSelf->m_apPlayers[i] && pSelf->m_apPlayers[i]->GetTeam() != TEAM_SPECTATORS)
|
||||
pSelf->m_apPlayers[i]->SetTeam(pSelf->m_apPlayers[i]->GetTeam()^1, false);
|
||||
}
|
||||
|
||||
(void)pSelf->m_pController->CheckTeamBalance();
|
||||
pSelf->SwapTeams();
|
||||
}
|
||||
|
||||
void CGameContext::ConShuffleTeams(IConsole::IResult *pResult, void *pUserData)
|
||||
|
|
|
@ -143,6 +143,9 @@ public:
|
|||
void CheckPureTuning();
|
||||
void SendTuningParams(int ClientID);
|
||||
|
||||
//
|
||||
void SwapTeams();
|
||||
|
||||
// engine events
|
||||
virtual void OnInit();
|
||||
virtual void OnConsoleInit();
|
||||
|
|
|
@ -245,7 +245,11 @@ void IGameController::CycleMap()
|
|||
return;
|
||||
|
||||
if(m_RoundCount < g_Config.m_SvRoundsPerMap-1)
|
||||
{
|
||||
if(g_Config.m_SvRoundSwap)
|
||||
GameServer()->SwapTeams();
|
||||
return;
|
||||
}
|
||||
|
||||
// handle maprotation
|
||||
const char *pMapRotation = g_Config.m_SvMaprotation;
|
||||
|
|
|
@ -60,6 +60,7 @@ MACRO_CONFIG_STR(SvMotd, sv_motd, 900, "", CFGFLAG_SERVER, "Message of the day t
|
|||
MACRO_CONFIG_INT(SvTeamdamage, sv_teamdamage, 0, 0, 1, CFGFLAG_SERVER, "Team damage")
|
||||
MACRO_CONFIG_STR(SvMaprotation, sv_maprotation, 768, "", CFGFLAG_SERVER, "Maps to rotate between")
|
||||
MACRO_CONFIG_INT(SvRoundsPerMap, sv_rounds_per_map, 1, 1, 100, CFGFLAG_SERVER, "Number of rounds on each map before rotating")
|
||||
MACRO_CONFIG_INT(SvRoundSwap, sv_round_swap, 1, 0, 1, CFGFLAG_SERVER, "Swap teams between rounds")
|
||||
MACRO_CONFIG_INT(SvPowerups, sv_powerups, 1, 0, 1, CFGFLAG_SERVER, "Allow powerups like ninja")
|
||||
MACRO_CONFIG_INT(SvScorelimit, sv_scorelimit, 20, 0, 1000, CFGFLAG_SERVER, "Score limit (0 disables)")
|
||||
MACRO_CONFIG_INT(SvTimelimit, sv_timelimit, 0, 0, 1000, CFGFLAG_SERVER, "Time limit in minutes (0 disables)")
|
||||
|
|
Loading…
Reference in a new issue