Skip to content

Commit 7fbca9f

Browse files
committed
add initial support for bo3
1 parent 88d6817 commit 7fbca9f

7 files changed

Lines changed: 159 additions & 26 deletions

File tree

src/engine/shared/config_variables.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,7 @@ MACRO_CONFIG_STR(SvBannedVersions, sv_banned_versions, 128, "", CFGFLAG_SERVER,
657657
MACRO_CONFIG_INT(SvKoEliminations, sv_ko_eliminations, 1, 1, 20, CFGFLAG_SERVER, "Amount of eliminations per round (KO GAME)")
658658
MACRO_CONFIG_INT(SvKoTimeLimit, sv_ko_time_limit, 20, 1, 99999, CFGFLAG_SERVER, "time limit of 1 round, applies next round (KO GAME)")
659659
MACRO_CONFIG_INT(SvKoPublicChat, sv_ko_public_chat, 0, 0, 1, CFGFLAG_SERVER, "make players able to publicly chat during the game (KO GAME)")
660+
MACRO_CONFIG_INT(SvKoBo3, sv_ko_bo3, 0, 0, 1, CFGFLAG_SERVER, "Best of 3 wins (KO GAME)")
660661
MACRO_CONFIG_INT(SvForcePredictionMargin, sv_force_prediction_margin, 0, 0, 200, CFGFLAG_SERVER, "force players to have a higher prediction margin for more consistant gameplay")
661662

662663
// netlimit

src/game/server/ddracecommands.cpp

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,38 @@ void CGameContext::ConKO_Start(IConsole::IResult *pResult, void *pUserData)
8181
if(!CheckClientId(pResult->m_ClientId))
8282
return;
8383

84-
int time = pResult->GetInteger(0);
84+
int time = 200;
85+
86+
if(!g_Config.m_SvKoBo3)
87+
{
88+
if(pResult->NumArguments() == 0)
89+
return;
90+
time = pResult->GetInteger(0);
91+
}
92+
else
93+
{
94+
int playerCount = 0;
95+
for(int i = 0; i < MAX_CLIENTS; i++)
96+
{
97+
if(!pSelf->PlayerExists(i))
98+
{
99+
continue;
100+
}
101+
102+
if(pSelf->m_apPlayers[i]->GetTeam() == TEAM_SPECTATORS)
103+
continue;
104+
105+
playerCount++;
106+
}
107+
108+
if(playerCount < 2)
109+
{
110+
pSelf->SendChat(-1, TEAM_ALL, "Not enough players in game");
111+
return;
112+
}
113+
114+
g_Config.m_SvSpectatorSlots = g_Config.m_SvMaxClients - playerCount;
115+
}
85116

86117
for(int i = 0; i < MAX_CLIENTS; i++)
87118
{
@@ -95,6 +126,7 @@ void CGameContext::ConKO_Start(IConsole::IResult *pResult, void *pUserData)
95126

96127
pSelf->m_apPlayers[i]->m_player_eliminated = false;
97128
pSelf->m_apPlayers[i]->m_elimination = -1;
129+
pSelf->m_apPlayers[i]->m_ko_wins = 0;
98130
pSelf->m_apPlayers[i]->KillCharacter();
99131
}
100132

src/game/server/entities/character.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,9 +1011,12 @@ void CCharacter::Die(int Killer, int Weapon, bool SendKillMsg)
10111011
if(m_pPlayer->m_player_eliminated && GameServer()->ko_game)
10121012
{
10131013
m_pPlayer->m_ko_round = GameServer()->ko_round;
1014-
str_format(aBuf, sizeof(aBuf), "%s is eliminated!", Server()->ClientName(m_Core.m_Id));
1015-
GameServer()->SendBroadcast("You are eliminated!", m_pPlayer->GetCid(), true);
1016-
GameServer()->SendChat(-1, TEAM_ALL, aBuf);
1014+
if(!g_Config.m_SvKoBo3)
1015+
{
1016+
str_format(aBuf, sizeof(aBuf), "%s is eliminated!", Server()->ClientName(m_Core.m_Id));
1017+
GameServer()->SendBroadcast("You are eliminated!", m_pPlayer->GetCid(), true);
1018+
GameServer()->SendChat(-1, TEAM_ALL, aBuf);
1019+
}
10171020
GameServer()->ko_players_eliminated++;
10181021
m_pPlayer->m_elimination = GameServer()->ko_players_eliminated;
10191022
}

src/game/server/gamecontext.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3899,6 +3899,9 @@ void CGameContext::RegisterDDRaceCommands()
38993899
Console()->Register("save_dry", "", CFGFLAG_SERVER, ConDrySave, this, "Dump the current savestring");
39003900
Console()->Register("dump_log", "?i[seconds]", CFGFLAG_SERVER, ConDumpLog, this, "Show logs of the last i seconds");
39013901

3902+
Console()->Register("start", "", CFGFLAG_CHAT | CFGFLAG_SERVER | CMDFLAG_TEST, ConKO_Start, this, "Starts game");
3903+
3904+
39023905
Console()->Register("freezehammer", "v[id]", CFGFLAG_SERVER | CMDFLAG_TEST, ConFreezeHammer, this, "Gives a player Freeze Hammer");
39033906
Console()->Register("unfreezehammer", "v[id]", CFGFLAG_SERVER | CMDFLAG_TEST, ConUnFreezeHammer, this, "Removes Freeze Hammer from a player");
39043907
}

src/game/server/gamemodes/DDRace.cpp

Lines changed: 114 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ CGameControllerDDRace::CGameControllerDDRace(class CGameContext *pGameServer) :
1818
IGameController(pGameServer)
1919
{
2020
m_pGameType = g_Config.m_SvTestingCommands ? TEST_TYPE_NAME : GAME_TYPE_NAME;
21+
22+
if(g_Config.m_SvKoBo3)
23+
m_pGameType = "KO-Run";
2124
m_GameFlags = protocol7::GAMEFLAG_RACE;
2225
}
2326

@@ -27,9 +30,10 @@ CScore *CGameControllerDDRace::Score()
2730
{
2831
return GameServer()->Score();
2932
}
30-
33+
static bool has_finished = false;
3134
void CGameControllerDDRace::KO_Start()
3235
{
36+
has_finished = false;
3337
bool finished = (GameServer()->ko_player_count <= 1);
3438
if(finished)
3539
{
@@ -60,6 +64,62 @@ void CGameControllerDDRace::KO_Start()
6064
return;
6165
}
6266

67+
if(g_Config.m_SvKoBo3)
68+
{
69+
int wins = -1;
70+
GameServer()->ko_player_count = 0;
71+
for(int i = 0; i < MAX_CLIENTS; i++)
72+
{
73+
if(!GameServer()->PlayerExists(i))
74+
continue;
75+
76+
if(GameServer()->m_apPlayers[i]->GetTeam() == TEAM_SPECTATORS)
77+
continue;
78+
79+
GameServer()->ko_player_count++;
80+
81+
if(GameServer()->m_apPlayers[i]->m_player_eliminated)
82+
continue;
83+
84+
wins = GameServer()->m_apPlayers[i]->m_ko_wins;
85+
86+
if(wins >= 2)
87+
{
88+
char aBuf[256];
89+
str_format(aBuf, sizeof(aBuf), "%s wins!", Server()->ClientName(i));
90+
GameServer()->SendBroadcast(aBuf, -1, true);
91+
GameServer()->SendChat(-1, TEAM_ALL, aBuf);
92+
}
93+
}
94+
95+
char aBuf[256];
96+
for(int i = 0; i < MAX_CLIENTS; i++)
97+
{
98+
if(!GameServer()->PlayerExists(i))
99+
{
100+
continue;
101+
}
102+
103+
if(GameServer()->m_apPlayers[i]->GetTeam() == TEAM_SPECTATORS)
104+
continue;
105+
106+
GameServer()->m_apPlayers[i]->KillCharacter(WEAPON_WORLD);
107+
GameServer()->m_apPlayers[i]->m_player_eliminated = false;
108+
109+
str_format(aBuf, sizeof(aBuf), "%s : %i", Server()->ClientName(i), GameServer()->m_apPlayers[i]->m_ko_wins);
110+
GameServer()->SendChat(-1, TEAM_ALL, aBuf);
111+
}
112+
113+
if(wins >= 2)
114+
{
115+
GameServer()->ko_game = false;
116+
GameServer()->ko_round = 0;
117+
GameServer()->ko_player_count = 0;
118+
g_Config.m_SvSpectatorSlots = 0;
119+
return;
120+
}
121+
}
122+
63123
m_RoundStartTick = Server()->Tick();
64124

65125
GameServer()->ko_round++;
@@ -217,34 +277,64 @@ void CGameControllerDDRace::HandleCharacterTiles(CCharacter *pChr, int MapIndex)
217277

218278
pPlayer->KillCharacter(WEAPON_GAME, false);
219279

220-
if(GameServer()->ko_player_count <= 2 && GameServer()->ko_players_finished == 1)
221-
{
222-
str_format(aBuf, sizeof(aBuf), "%s Wins!", Server()->ClientName(pPlayer->GetCid()));
223-
pPlayer->m_elimination = -2;
224-
GameServer()->SendBroadcast(aBuf, -1, true);
225-
GameServer()->SendChat(-1, TEAM_ALL, aBuf);
280+
if(!has_finished)
281+
{
282+
pPlayer->m_ko_wins++;
283+
has_finished = true;
284+
}
226285

227-
for(int i = 0; i < MAX_CLIENTS; i++)
286+
if(GameServer()->ko_player_count <= 2 && GameServer()->ko_players_finished == 1)
287+
{
288+
if(pPlayer->m_ko_wins < 2 && g_Config.m_SvKoBo3)
228289
{
229-
if(!GameServer()->PlayerExists(i) || i == pPlayer->GetCid())
290+
for(int i = 0; i < MAX_CLIENTS; i++)
230291
{
231-
continue;
292+
if(!GameServer()->PlayerExists(i))
293+
{
294+
continue;
295+
}
296+
297+
if(GameServer()->m_apPlayers[i]->GetTeam() == TEAM_SPECTATORS)
298+
continue;
299+
300+
GameServer()->m_apPlayers[i]->KillCharacter(WEAPON_WORLD);
301+
GameServer()->m_apPlayers[i]->m_player_eliminated = false;
302+
303+
str_format(aBuf, sizeof(aBuf), "%s : %i", Server()->ClientName(i), GameServer()->m_apPlayers[i]->m_ko_wins);
304+
GameServer()->SendChat(-1, TEAM_ALL, aBuf);
232305
}
233-
234-
GameServer()->m_apPlayers[i]->KillCharacter(WEAPON_WORLD);
235-
if(GameServer()->m_apPlayers[i]->m_player_eliminated)
306+
}else
307+
{
308+
str_format(aBuf, sizeof(aBuf), "%s Wins!", Server()->ClientName(pPlayer->GetCid()));
309+
pPlayer->m_elimination = -2;
310+
GameServer()->SendBroadcast(aBuf, -1, true);
311+
GameServer()->SendChat(-1, TEAM_ALL, aBuf);
312+
313+
for(int i = 0; i < MAX_CLIENTS; i++)
236314
{
237-
str_format(aBuf, sizeof(aBuf), "you survived until round %i!", GameServer()->m_apPlayers[i]->m_ko_round);
238-
GameServer()->SendChatTarget(i, aBuf);
239-
continue;
315+
if(!GameServer()->PlayerExists(i) || i == pPlayer->GetCid())
316+
{
317+
continue;
318+
}
319+
320+
GameServer()->m_apPlayers[i]->KillCharacter(WEAPON_WORLD);
321+
if(GameServer()->m_apPlayers[i]->m_player_eliminated && !g_Config.m_SvKoBo3)
322+
{
323+
str_format(aBuf, sizeof(aBuf), "you survived until round %i!", GameServer()->m_apPlayers[i]->m_ko_round);
324+
GameServer()->SendChatTarget(i, aBuf);
325+
continue;
326+
}
240327
}
241-
}
242328

243-
GameServer()->ko_game = false;
244-
}else
329+
GameServer()->ko_game = false;
330+
}
331+
}else if(!g_Config.m_SvKoBo3)
245332
{
246-
str_format(aBuf, sizeof(aBuf), "%i spots left!", GameServer()->ko_player_count-GameServer()->ko_players_tobe_eliminated-GameServer()->ko_players_finished);
247-
GameServer()->SendChat(-1, TEAM_ALL, aBuf);
333+
if(GameServer()->ko_player_count-GameServer()->ko_players_tobe_eliminated-GameServer()->ko_players_finished >= 0)
334+
{
335+
str_format(aBuf, sizeof(aBuf), "%i spots left!", GameServer()->ko_player_count-GameServer()->ko_players_tobe_eliminated-GameServer()->ko_players_finished);
336+
GameServer()->SendChat(-1, TEAM_ALL, aBuf);
337+
}
248338
}
249339
}
250340

@@ -373,7 +463,9 @@ void CGameControllerDDRace::Tick()
373463

374464
if(playersIn < 1)
375465
{
376-
m_Warmup = 10 * Server()->TickSpeed();
466+
m_Warmup = 5 * Server()->TickSpeed();
467+
if(!g_Config.m_SvKoBo3)
468+
m_Warmup = 10 * Server()->TickSpeed();
377469
m_Timer = 1;
378470
}
379471
}

src/game/server/player.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ void CPlayer::Reset()
5656
m_ko_round = 0;
5757
m_elimination = -1;
5858
m_ko_fastest_round = -1;
59+
m_ko_wins = 0;
5960

6061
int *pIdMap = Server()->GetIdMap(m_ClientId);
6162
for(int i = 1; i < VANILLA_MAX_CLIENTS; i++)

src/game/server/player.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ class CPlayer
9393
int m_ko_round;
9494
int m_ko_round_timer;
9595
int m_ko_fastest_round;
96+
int m_ko_wins;
9697

9798
//
9899
int m_Vote;

0 commit comments

Comments
 (0)