From bb5b064555f44cca7d88fa44a3369a5499190cc6 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Mon, 2 Jun 2025 14:31:10 -0400 Subject: [PATCH] Equalize team sizes (#992) ## Description: Ensure that team sizes are equal. Closes #841 ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced - [x] I understand that submitting code with bugs that could have been caught through manual testing blocks releases and new features for all contributors --------- Co-authored-by: Scott Anderson <662325+scottanderson@users.noreply.github.com> --- src/core/configuration/Config.ts | 6 +++++- src/core/configuration/DefaultConfig.ts | 12 ++++++++++-- src/server/MapPlaylist.ts | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/core/configuration/Config.ts b/src/core/configuration/Config.ts index 7da156e3b..56d3fa884 100644 --- a/src/core/configuration/Config.ts +++ b/src/core/configuration/Config.ts @@ -29,7 +29,11 @@ export enum GameEnv { export interface ServerConfig { turnIntervalMs(): number; gameCreationRate(): number; - lobbyMaxPlayers(map: GameMapType, mode: GameMode): number; + lobbyMaxPlayers( + map: GameMapType, + mode: GameMode, + numPlayerTeams: number | undefined, + ): number; numWorkers(): number; workerIndex(gameID: GameID): number; workerPath(gameID: GameID): string; diff --git a/src/core/configuration/DefaultConfig.ts b/src/core/configuration/DefaultConfig.ts index 1bb0ffbbc..909683f08 100644 --- a/src/core/configuration/DefaultConfig.ts +++ b/src/core/configuration/DefaultConfig.ts @@ -143,11 +143,19 @@ export abstract class DefaultServerConfig implements ServerConfig { return 60 * 1000; } - lobbyMaxPlayers(map: GameMapType, mode: GameMode): number { + lobbyMaxPlayers( + map: GameMapType, + mode: GameMode, + numPlayerTeams: number | undefined, + ): number { const [l, m, s] = numPlayersConfig[map] ?? [50, 30, 20]; const r = Math.random(); const base = r < 0.3 ? l : r < 0.6 ? m : s; - return Math.min(mode === GameMode.Team ? Math.ceil(base * 1.5) : base, 150); + let p = Math.min(mode === GameMode.Team ? Math.ceil(base * 1.5) : base, l); + if (numPlayerTeams !== undefined) { + p -= p % numPlayerTeams; + } + return p; } workerIndex(gameID: GameID): number { diff --git a/src/server/MapPlaylist.ts b/src/server/MapPlaylist.ts index dfec2aa3c..cebf4a0b8 100644 --- a/src/server/MapPlaylist.ts +++ b/src/server/MapPlaylist.ts @@ -51,7 +51,7 @@ export class MapPlaylist { // Create the default public game config (from your GameManager) return { gameMap: map, - maxPlayers: config.lobbyMaxPlayers(map, mode), + maxPlayers: config.lobbyMaxPlayers(map, mode, numPlayerTeams), gameType: GameType.Public, difficulty: Difficulty.Medium, infiniteGold: false,