mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-04 07:56:14 +00:00
Quads (#1347)
## Description: - Add trios and quads - Add translations for duos, trios, quads - Add duos, trios, quads to the public lobby rotation - Increase the frequency of team games   ## 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
This commit is contained in:
+11
-1
@@ -9,6 +9,8 @@ import {
|
||||
GameMode,
|
||||
GameType,
|
||||
PlayerType,
|
||||
Quads,
|
||||
Trios,
|
||||
UnitType,
|
||||
} from "./game/Game";
|
||||
import { PatternDecoder } from "./PatternDecoder";
|
||||
@@ -131,6 +133,14 @@ export enum LogSeverity {
|
||||
// Utility types
|
||||
//
|
||||
|
||||
const TeamCountConfigSchema = z.union([
|
||||
z.number(),
|
||||
z.literal(Duos),
|
||||
z.literal(Trios),
|
||||
z.literal(Quads),
|
||||
]);
|
||||
export type TeamCountConfig = z.infer<typeof TeamCountConfigSchema>;
|
||||
|
||||
export const GameConfigSchema = z.object({
|
||||
gameMap: z.enum(GameMapType),
|
||||
difficulty: z.enum(Difficulty),
|
||||
@@ -143,7 +153,7 @@ export const GameConfigSchema = z.object({
|
||||
instantBuild: z.boolean(),
|
||||
maxPlayers: z.number().optional(),
|
||||
disabledUnits: z.enum(UnitType).array().optional(),
|
||||
playerTeams: z.union([z.number(), z.literal(Duos)]).optional(),
|
||||
playerTeams: TeamCountConfigSchema.optional(),
|
||||
});
|
||||
|
||||
export const TeamSchema = z.string();
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { Colord } from "colord";
|
||||
import { JWK } from "jose";
|
||||
import { GameConfig, GameID } from "../Schemas";
|
||||
import { GameConfig, GameID, TeamCountConfig } from "../Schemas";
|
||||
import {
|
||||
Difficulty,
|
||||
Duos,
|
||||
Game,
|
||||
GameMapType,
|
||||
GameMode,
|
||||
@@ -32,7 +31,7 @@ export interface ServerConfig {
|
||||
lobbyMaxPlayers(
|
||||
map: GameMapType,
|
||||
mode: GameMode,
|
||||
numPlayerTeams: number | undefined,
|
||||
numPlayerTeams: TeamCountConfig | undefined,
|
||||
): number;
|
||||
numWorkers(): number;
|
||||
workerIndex(gameID: GameID): number;
|
||||
@@ -87,7 +86,7 @@ export interface Config {
|
||||
instantBuild(): boolean;
|
||||
numSpawnPhaseTurns(): number;
|
||||
userSettings(): UserSettings;
|
||||
playerTeams(): number | typeof Duos;
|
||||
playerTeams(): TeamCountConfig;
|
||||
|
||||
startManpower(playerInfo: PlayerInfo): number;
|
||||
populationIncreaseRate(player: Player | PlayerView): number;
|
||||
|
||||
@@ -2,7 +2,6 @@ import { JWK } from "jose";
|
||||
import { z } from "zod/v4";
|
||||
import {
|
||||
Difficulty,
|
||||
Duos,
|
||||
Game,
|
||||
GameMapType,
|
||||
GameMode,
|
||||
@@ -20,7 +19,7 @@ import {
|
||||
import { TileRef } from "../game/GameMap";
|
||||
import { PlayerView } from "../game/GameView";
|
||||
import { UserSettings } from "../game/UserSettings";
|
||||
import { GameConfig, GameID } from "../Schemas";
|
||||
import { GameConfig, GameID, TeamCountConfig } from "../Schemas";
|
||||
import { assertNever, simpleHash, within } from "../Util";
|
||||
import { Config, GameEnv, NukeMagnitude, ServerConfig, Theme } from "./Config";
|
||||
import { PastelTheme } from "./PastelTheme";
|
||||
@@ -167,13 +166,13 @@ export abstract class DefaultServerConfig implements ServerConfig {
|
||||
lobbyMaxPlayers(
|
||||
map: GameMapType,
|
||||
mode: GameMode,
|
||||
numPlayerTeams: number | undefined,
|
||||
numPlayerTeams: TeamCountConfig | 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;
|
||||
let p = Math.min(mode === GameMode.Team ? Math.ceil(base * 1.5) : base, l);
|
||||
if (numPlayerTeams !== undefined) {
|
||||
if (typeof numPlayerTeams === "number") {
|
||||
p -= p % numPlayerTeams;
|
||||
}
|
||||
return p;
|
||||
@@ -279,7 +278,7 @@ export class DefaultConfig implements Config {
|
||||
defensePostDefenseBonus(): number {
|
||||
return 5;
|
||||
}
|
||||
playerTeams(): number | typeof Duos {
|
||||
playerTeams(): TeamCountConfig {
|
||||
return this._gameConfig.playerTeams ?? 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,8 @@ export enum Difficulty {
|
||||
export type Team = string;
|
||||
|
||||
export const Duos = "Duos" as const;
|
||||
export const Trios = "Trios" as const;
|
||||
export const Quads = "Quads" as const;
|
||||
|
||||
export const ColoredTeams: Record<string, Team> = {
|
||||
Red: "Red",
|
||||
|
||||
+28
-14
@@ -21,9 +21,11 @@ import {
|
||||
PlayerID,
|
||||
PlayerInfo,
|
||||
PlayerType,
|
||||
Quads,
|
||||
Team,
|
||||
TerrainType,
|
||||
TerraNullius,
|
||||
Trios,
|
||||
Unit,
|
||||
UnitInfo,
|
||||
UnitType,
|
||||
@@ -74,7 +76,7 @@ export class GameImpl implements Game {
|
||||
private updates: GameUpdates = createGameUpdatesMap();
|
||||
private unitGrid: UnitGrid;
|
||||
|
||||
private playerTeams: Team[] = [ColoredTeams.Red, ColoredTeams.Blue];
|
||||
private playerTeams: Team[];
|
||||
private botTeam: Team = ColoredTeams.Bot;
|
||||
private _railNetwork: RailNetwork = createRailNetwork(this);
|
||||
|
||||
@@ -101,25 +103,37 @@ export class GameImpl implements Game {
|
||||
}
|
||||
|
||||
private populateTeams() {
|
||||
if (this._config.playerTeams() === Duos) {
|
||||
this.playerTeams = [];
|
||||
const numTeams = Math.ceil(
|
||||
(this._humans.length + this._nations.length) / 2,
|
||||
);
|
||||
for (let i = 0; i < numTeams; i++) {
|
||||
this.playerTeams.push("Team " + (i + 1));
|
||||
let numPlayerTeams = this._config.playerTeams();
|
||||
if (typeof numPlayerTeams !== "number") {
|
||||
const players = this._humans.length + this._nations.length;
|
||||
switch (numPlayerTeams) {
|
||||
case Duos:
|
||||
numPlayerTeams = Math.ceil(players / 2);
|
||||
break;
|
||||
case Trios:
|
||||
numPlayerTeams = Math.ceil(players / 3);
|
||||
break;
|
||||
case Quads:
|
||||
numPlayerTeams = Math.ceil(players / 4);
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unknown TeamCountConfig ${numPlayerTeams}`);
|
||||
}
|
||||
} else {
|
||||
const numPlayerTeams = this._config.playerTeams() as number;
|
||||
if (numPlayerTeams < 2)
|
||||
throw new Error(`Too few teams: ${numPlayerTeams}`);
|
||||
}
|
||||
if (numPlayerTeams < 2) {
|
||||
throw new Error(`Too few teams: ${numPlayerTeams}`);
|
||||
} else if (numPlayerTeams < 8) {
|
||||
this.playerTeams = [ColoredTeams.Red, ColoredTeams.Blue];
|
||||
if (numPlayerTeams >= 3) this.playerTeams.push(ColoredTeams.Yellow);
|
||||
if (numPlayerTeams >= 4) this.playerTeams.push(ColoredTeams.Green);
|
||||
if (numPlayerTeams >= 5) this.playerTeams.push(ColoredTeams.Purple);
|
||||
if (numPlayerTeams >= 6) this.playerTeams.push(ColoredTeams.Orange);
|
||||
if (numPlayerTeams >= 7) this.playerTeams.push(ColoredTeams.Teal);
|
||||
if (numPlayerTeams >= 8)
|
||||
throw new Error(`Too many teams: ${numPlayerTeams}`);
|
||||
} else {
|
||||
this.playerTeams = [];
|
||||
for (let i = 1; i <= numPlayerTeams; i++) {
|
||||
this.playerTeams.push(`Team ${i}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user