${isEmpty
@@ -190,7 +208,7 @@ export class LobbyTeamView extends LitElement {
private getTeamList(): Team[] {
if (this.gameMode !== GameMode.Team) return [];
- const playerCount = this.clients.length;
+ const playerCount = this.clients.length + this.nationCount;
const config = this.teamCount;
if (config === HumansVsNations) {
@@ -230,13 +248,12 @@ export class LobbyTeamView extends LitElement {
}
}
- private computeTeamPreview() {
+ private computeTeamPreview(teams: Team[] = []) {
if (this.gameMode !== GameMode.Team) {
this.teamPreview = [];
this.teamMaxSize = 0;
return;
}
- const teams = this.getTeamList();
// HumansVsNations: show all clients under Humans initially
if (this.teamCount === HumansVsNations) {
@@ -252,7 +269,11 @@ export class LobbyTeamView extends LitElement {
(c) =>
new PlayerInfo(c.username, PlayerType.Human, c.clientID, c.clientID),
);
- const assignment = assignTeams(players, teams);
+ const assignment = assignTeamsLobbyPreview(
+ players,
+ teams,
+ this.nationCount,
+ );
const buckets = new Map
();
for (const t of teams) buckets.set(t, []);
@@ -260,9 +281,7 @@ export class LobbyTeamView extends LitElement {
if (team === "kicked") continue;
const bucket = buckets.get(team);
if (!bucket) continue;
- const client =
- this.clients.find((c) => c.clientID === p.clientID) ??
- this.clients.find((c) => c.username === p.name);
+ const client = this.clients.find((c) => c.clientID === p.clientID);
if (client) bucket.push(client);
}
@@ -277,7 +296,7 @@ export class LobbyTeamView extends LitElement {
// Fallback: divide players across teams; guard against 0 and empty lobbies
this.teamMaxSize = Math.max(
1,
- Math.ceil(this.clients.length / teams.length),
+ Math.ceil((this.clients.length + this.nationCount) / teams.length),
);
}
this.teamPreview = teams.map((t) => ({
diff --git a/src/core/game/TeamAssignment.ts b/src/core/game/TeamAssignment.ts
index 535626d7d..13e2f6c64 100644
--- a/src/core/game/TeamAssignment.ts
+++ b/src/core/game/TeamAssignment.ts
@@ -5,6 +5,7 @@ import { PlayerInfo, PlayerType, Team } from "./Game";
export function assignTeams(
players: PlayerInfo[],
teams: Team[],
+ maxTeamSize: number = getMaxTeamSize(players.length, teams.length),
): Map {
const result = new Map();
const teamPlayerCount = new Map();
@@ -25,8 +26,6 @@ export function assignTeams(
}
}
- const maxTeamSize = Math.ceil(players.length / teams.length);
-
// Sort clans by size (largest first)
const sortedClans = Array.from(clanGroups.entries()).sort(
(a, b) => b[1].length - a[1].length,
@@ -87,3 +86,19 @@ export function assignTeams(
return result;
}
+
+export function assignTeamsLobbyPreview(
+ players: PlayerInfo[],
+ teams: Team[],
+ nationCount: number,
+): Map {
+ const maxTeamSize = getMaxTeamSize(
+ players.length + nationCount,
+ teams.length,
+ );
+ return assignTeams(players, teams, maxTeamSize);
+}
+
+export function getMaxTeamSize(numPlayers: number, numTeams: number): number {
+ return Math.ceil(numPlayers / numTeams);
+}