From 63dc0eb3fa07e53498660969dce55f4d25c0901d Mon Sep 17 00:00:00 2001 From: Restart2008 Date: Sat, 25 Oct 2025 11:42:20 -0700 Subject: [PATCH] fix: clean up NukeWars mode implementation - Remove merge conflicts from all files - Fix WinCheckExecution.ts syntax issues - Properly separate NukeWars from Team mode - Clean implementation of preparation phase - Consistent checks for GameMode.NukeWars across codebase - Fix DefaultConfig numPreparationPhaseTurns implementation --- src/client/HostLobbyModal.ts | 24 +++++++++++++++++------- src/client/SinglePlayerModal.ts | 7 +++++++ src/core/configuration/Config.ts | 1 + src/core/configuration/DefaultConfig.ts | 6 ------ src/core/execution/WinCheckExecution.ts | 10 ++-------- src/core/game/GameImpl.ts | 18 +++++------------- 6 files changed, 32 insertions(+), 34 deletions(-) diff --git a/src/client/HostLobbyModal.ts b/src/client/HostLobbyModal.ts index 50c8dd936..5585746d7 100644 --- a/src/client/HostLobbyModal.ts +++ b/src/client/HostLobbyModal.ts @@ -53,13 +53,7 @@ export class HostLobbyModal extends LitElement { @state() private clients: ClientInfo[] = []; @state() private useRandomMap: boolean = false; @state() private disabledUnits: UnitType[] = []; -<<<<<<< Updated upstream -======= - - private readonly nukeWarsDisabledUnits = [ - UnitType.MIRV, - ]; ->>>>>>> Stashed changes + private readonly nukeWarsDisabledUnits = [UnitType.MIRV]; @state() private lobbyCreatorClientID: string = ""; @state() private lobbyIdVisible: boolean = true; @@ -278,6 +272,14 @@ export class HostLobbyModal extends LitElement { ${translateText("game_mode.teams")} +
this.handleGameModeSelection(GameMode.NukeWars)} + > +
+ ${translateText("game_mode.nukewars")} +
+
@@ -702,6 +704,14 @@ export class HostLobbyModal extends LitElement { private async handleGameModeSelection(value: GameMode) { this.gameMode = value; + if (value === GameMode.NukeWars) { + // Enforce Nuke Wars settings + this.selectedMap = GameMapType.Baikal; + this.teamCount = 2; + this.disabledUnits = Array.from(new Set([...this.disabledUnits, ...this.nukeWarsDisabledUnits])); + this.donateGold = true; + this.donateTroops = true; + } this.putGameConfig(); } diff --git a/src/client/SinglePlayerModal.ts b/src/client/SinglePlayerModal.ts index 3a550a72b..aa3c571f7 100644 --- a/src/client/SinglePlayerModal.ts +++ b/src/client/SinglePlayerModal.ts @@ -514,6 +514,13 @@ export class SinglePlayerModal extends LitElement { const selectedColor = this.userSettings.getSelectedColor(); + if (this.gameMode === GameMode.NukeWars) { + // Enforce Nuke Wars defaults for singleplayer + this.selectedMap = GameMapType.Baikal; + this.teamCount = 2; + this.disabledUnits = Array.from(new Set([...this.disabledUnits, ...this.nukeWarsDisabledUnits])); + } + this.dispatchEvent( new CustomEvent("join-lobby", { detail: { diff --git a/src/core/configuration/Config.ts b/src/core/configuration/Config.ts index 965f7c9bb..134e68967 100644 --- a/src/core/configuration/Config.ts +++ b/src/core/configuration/Config.ts @@ -89,6 +89,7 @@ export interface Config { donateTroops(): boolean; instantBuild(): boolean; numSpawnPhaseTurns(): number; + numPreparationPhaseTurns(): number; userSettings(): UserSettings; playerTeams(): TeamCountConfig; diff --git a/src/core/configuration/DefaultConfig.ts b/src/core/configuration/DefaultConfig.ts index 1d2679cf6..80814f48c 100644 --- a/src/core/configuration/DefaultConfig.ts +++ b/src/core/configuration/DefaultConfig.ts @@ -323,12 +323,9 @@ export class DefaultConfig implements Config { } isUnitDisabled(unitType: UnitType): boolean { -<<<<<<< Updated upstream -======= if (this._gameConfig.gameMode === GameMode.NukeWars) { return unitType === UnitType.MIRV; } ->>>>>>> Stashed changes return this._gameConfig.disabledUnits?.includes(unitType) ?? false; } @@ -622,8 +619,6 @@ export class DefaultConfig implements Config { numSpawnPhaseTurns(): number { return this._gameConfig.gameType === GameType.Singleplayer ? 100 : 300; } -<<<<<<< Updated upstream -======= numPreparationPhaseTurns(): number { if (this._gameConfig.gameMode === GameMode.NukeWars) { @@ -631,7 +626,6 @@ export class DefaultConfig implements Config { } return 0; } ->>>>>>> Stashed changes numBots(): number { return this.bots(); } diff --git a/src/core/execution/WinCheckExecution.ts b/src/core/execution/WinCheckExecution.ts index 66646d3b1..648e0a3ed 100644 --- a/src/core/execution/WinCheckExecution.ts +++ b/src/core/execution/WinCheckExecution.ts @@ -29,13 +29,10 @@ export class WinCheckExecution implements Execution { } if (this.mg === null) throw new Error("Not initialized"); - if (this.mg.config().gameConfig().gameMode === GameMode.FFA) { + const gameMode = this.mg.config().gameConfig().gameMode; + if (gameMode === GameMode.FFA) { this.checkWinnerFFA(); -<<<<<<< Updated upstream } else { -======= - } else if (gameMode === GameMode.NukeWars || gameMode === GameMode.Team) { ->>>>>>> Stashed changes this.checkWinnerTeam(); } } @@ -91,8 +88,6 @@ export class WinCheckExecution implements Execution { } } -<<<<<<< Updated upstream -======= private checkNukeWarsWinCondition(sorted: [Team, number][]): void { if (this.mg === null) throw new Error("Not initialized"); const numTilesWithoutFallout = @@ -153,7 +148,6 @@ export class WinCheckExecution implements Execution { return maxTimerValue !== undefined && timeElapsed >= maxTimerValue * 60; } ->>>>>>> Stashed changes isActive(): boolean { return this.active; } diff --git a/src/core/game/GameImpl.ts b/src/core/game/GameImpl.ts index 2ab9e10de..e9243b1f2 100644 --- a/src/core/game/GameImpl.ts +++ b/src/core/game/GameImpl.ts @@ -96,12 +96,10 @@ export class GameImpl implements Game { this._width = _map.width(); this._height = _map.height(); this.unitGrid = new UnitGrid(this._map); -<<<<<<< Updated upstream - if (_config.gameConfig().gameMode === GameMode.Team) { -======= - if (this.isTeamBasedGame()) { ->>>>>>> Stashed changes + // Handle team population for Team and NukeWars modes + const gameMode = _config.gameConfig().gameMode; + if (gameMode === GameMode.Team || gameMode === GameMode.NukeWars) { this.populateTeams(); } this.addPlayers(); @@ -338,15 +336,12 @@ export class GameImpl implements Game { return this._ticks <= this.config().numSpawnPhaseTurns(); } -<<<<<<< Updated upstream -======= inPreparationPhase(): boolean { const spawn = this.config().numSpawnPhaseTurns(); const prep = this.config().numPreparationPhaseTurns(); return this._ticks > spawn && this._ticks <= spawn + prep; } ->>>>>>> Stashed changes ticks(): number { return this._ticks; } @@ -689,11 +684,8 @@ export class GameImpl implements Game { } teams(): Team[] { -<<<<<<< Updated upstream - if (this._config.gameConfig().gameMode !== GameMode.Team) { -======= - if (!this.isTeamBasedGame()) { ->>>>>>> Stashed changes + const gameMode = this._config.gameConfig().gameMode; + if (gameMode !== GameMode.Team && gameMode !== GameMode.NukeWars) { return []; } return [this.botTeam, ...this.playerTeams];