Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

History Rewritten #2

Merged
merged 1 commit into from
Mar 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
name: "Rebase from DDNet"
name: "Fetch DDNet Upstream"

on:
schedule:
- cron: "0 0 * * *"
workflow_dispatch:
branches:
- upstream-ddnet

jobs:
rebase-ddnet:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "Rebase from Skeleton"
name: "Fetch Skeleton Upstream"

on:
schedule:
Expand Down
65 changes: 60 additions & 5 deletions src/game/server/gamecontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ bool IGameController::CanBeMovedOnBalance(int ClientID)
void IGameController::Tick()
{
// do warmup
if(m_Warmup)
if(!GameServer()->m_World.m_Paused && m_Warmup)
{
m_Warmup--;
if(!m_Warmup)
Expand All @@ -573,9 +573,16 @@ void IGameController::Tick()
}
}

DoWinCheck();
// game is Paused
if(GameServer()->m_World.m_Paused)
++m_RoundStartTick;

// do team-balancing
// SKELETON-TODO: DoTeamBalancingCheck()

DoActivityCheck();

DoWinCheck();
}

void IGameController::Snap(int SnappingClient)
Expand All @@ -595,8 +602,8 @@ void IGameController::Snap(int SnappingClient)
pGameInfoObj->m_RoundStartTick = m_RoundStartTick;
pGameInfoObj->m_WarmupTimer = m_Warmup;

// pGameInfoObj->m_ScoreLimit = 0;
// pGameInfoObj->m_TimeLimit = g_Config.m_SvTimeLimit;
pGameInfoObj->m_ScoreLimit = g_Config.m_SvScoreLimit;
pGameInfoObj->m_TimeLimit = g_Config.m_SvTimeLimit;

pGameInfoObj->m_RoundNum = (str_length(g_Config.m_SvMapRotation) && g_Config.m_SvRoundsPerMap) ? g_Config.m_SvRoundsPerMap : 0;
pGameInfoObj->m_RoundCurrent = m_RoundCount + 1;
Expand Down Expand Up @@ -764,6 +771,8 @@ int IGameController::GetAutoTeam(int NotThisID)
}

int Team = 0;
if(IsTeamplay())
Team = aNumplayers[TEAM_RED] > aNumplayers[TEAM_BLUE] ? TEAM_BLUE : TEAM_RED;

if(CanJoinTeam(Team, NotThisID))
return Team;
Expand Down Expand Up @@ -850,8 +859,53 @@ bool IGameController::IsTeamplay()

void IGameController::DoWinCheck()
{
if(m_GameOverTick != -1 || m_Warmup || !GameServer()->m_World.m_ResetRequested)
return;

// Time Limit check
if(g_Config.m_SvTimeLimit > 0 && (Server()->Tick() - m_RoundStartTick) >= g_Config.m_SvTimeLimit * Server()->TickSpeed() * 60)
EndRound();

// Score Limit check
if(IsTeamplay())
{
// check score win condition
if((g_Config.m_SvScoreLimit > 0 && (m_aTeamscore[TEAM_RED] >= g_Config.m_SvScoreLimit || m_aTeamscore[TEAM_BLUE] >= g_Config.m_SvScoreLimit)))
{
if(m_aTeamscore[TEAM_RED] != m_aTeamscore[TEAM_BLUE])
EndRound();
else
m_SuddenDeath = 1;
}
}
else
{
// gather some stats
int Topscore = 0;
int TopscoreCount = 0;
for(int i = 0; i < MAX_CLIENTS; i++)
{
if(GameServer()->m_apPlayers[i])
{
if(GameServer()->m_apPlayers[i]->m_Score > Topscore)
{
Topscore = GameServer()->m_apPlayers[i]->m_Score;
TopscoreCount = 1;
}
else if(GameServer()->m_apPlayers[i]->m_Score == Topscore)
TopscoreCount++;
}
}

// check score win condition
if((g_Config.m_SvScoreLimit > 0 && Topscore >= g_Config.m_SvScoreLimit))
{
if(TopscoreCount == 1)
EndRound();
else
m_SuddenDeath = 1;
}
}
}

void IGameController::QueueMap(const char *pToMap)
Expand Down Expand Up @@ -960,7 +1014,7 @@ void IGameController::CycleMap()
int Min = 0;
int Max = pMapRotationInfo.m_MapCount - 1;

RandInt = rand() % (Max - Min + 1) + Min; // TODO: USE A BETTER RANDOM INT
RandInt = rand() % (Max - Min + 1) + Min; // SKELETON-TODO: USE A BETTER RANDOM INT
GetWordFromList(aBuf, g_Config.m_SvMapRotation, pMapRotationInfo.m_MapNameIndices[RandInt]);
// int MinPlayers = Server()->GetMinPlayersForMap(aBuf);
// if (RandInt != pMapRotationInfo.m_CurrentMapNumber && PlayerCount >= MinPlayers)
Expand Down Expand Up @@ -1005,6 +1059,7 @@ void IGameController::CycleMap()
char aBufMsg[256];
str_format(aBufMsg, sizeof(aBufMsg), "rotating map to %s", aBuf);
GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "game", aBufMsg);

ChangeMap(aBuf);
}

Expand Down
2 changes: 2 additions & 0 deletions src/game/variables.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ MACRO_CONFIG_INT(SvSelfKill, sv_self_kill, 0, 0, 1, CFGFLAG_SERVER | CFGFLAG_GAM
MACRO_CONFIG_INT(SvSpectable, sv_spectable, 0, 0, 1, CFGFLAG_SERVER | CFGFLAG_GAME, "Whether players can specate in game or not")

MACRO_CONFIG_INT(SvTimeLimit, sv_time_limit, 0, 0, 1000, CFGFLAG_SERVER, "Time limit in minutes (0 disables)")
MACRO_CONFIG_INT(SvScoreLimit, sv_score_limit, 0, 0, 1000, CFGFLAG_SERVER, "Score limit (0 disables)")

MACRO_CONFIG_STR(SvMapRotation, sv_map_rotation, 768, "", CFGFLAG_SERVER, "Maps to rotate between")
MACRO_CONFIG_INT(SvMapRotationRandom, sv_map_rotation_random, 0, 0, 1, CFGFLAG_SERVER, "When enabled, next map in rotation will be chosen randomly")
MACRO_CONFIG_INT(SvRoundsPerMap, sv_rounds_per_map, 1, 1, 999, CFGFLAG_SERVER, "Number of rounds on each map before rotating")