Nuke Wars: enforce 2-team, separate spawn→preparation phase, block nukes during prep, and show prep+elapsed timers in HUD

This commit is contained in:
Restart2008
2025-10-24 20:35:57 -07:00
parent 4d528548c7
commit d3aa71321c
9 changed files with 142 additions and 41 deletions
+1
View File
@@ -656,6 +656,7 @@ export interface Game extends GameMap {
isOnMap(cell: Cell): boolean;
width(): number;
height(): number;
inPreparationPhase(): boolean;
map(): GameMap;
miniMap(): GameMap;
forEachTile(fn: (tile: TileRef) => void): void;
+21 -3
View File
@@ -96,8 +96,11 @@ export class GameImpl implements Game {
this._width = _map.width();
this._height = _map.height();
this.unitGrid = new UnitGrid(this._map);
if (_config.gameConfig().gameMode === GameMode.Team) {
// Treat Team and NukeWars as team-based games (Nuke Wars is 2-team only)
if (
_config.gameConfig().gameMode === GameMode.Team ||
_config.gameConfig().gameMode === GameMode.NukeWars
) {
this.populateTeams();
}
this.addPlayers();
@@ -105,6 +108,10 @@ export class GameImpl implements Game {
private populateTeams() {
let numPlayerTeams = this._config.playerTeams();
// Force 2 teams for NukeWars
if (this._config.gameConfig().gameMode === GameMode.NukeWars) {
numPlayerTeams = 2;
}
if (typeof numPlayerTeams !== "number") {
const players = this._humans.length + this._nations.length;
switch (numPlayerTeams) {
@@ -323,6 +330,14 @@ export class GameImpl implements Game {
return this._ticks <= this.config().numSpawnPhaseTurns();
}
inPreparationPhase(): boolean {
const spawn = this.config().numSpawnPhaseTurns();
const prep = this.config().numPreparationPhaseTurns?.()
? this.config().numPreparationPhaseTurns()
: 0;
return this._ticks > spawn && this._ticks <= spawn + prep;
}
ticks(): number {
return this._ticks;
}
@@ -666,7 +681,10 @@ export class GameImpl implements Game {
teams(): Team[] {
if (this._config.gameConfig().gameMode !== GameMode.Team) {
return [];
// Treat NukeWars as a team-based mode (2 teams)
if (this._config.gameConfig().gameMode !== GameMode.NukeWars) {
return [];
}
}
return [this.botTeam, ...this.playerTeams];
}
+6
View File
@@ -637,6 +637,12 @@ export class GameView implements GameMap {
inSpawnPhase(): boolean {
return this.ticks() <= this._config.numSpawnPhaseTurns();
}
inPreparationPhase(): boolean {
const spawn = this._config.numSpawnPhaseTurns();
const prep = this._config.numPreparationPhaseTurns();
return this.ticks() > spawn && this.ticks() <= spawn + prep;
}
config(): Config {
return this._config;
}
+6
View File
@@ -991,6 +991,12 @@ export class PlayerImpl implements Player {
}
nukeSpawn(tile: TileRef): TileRef | false {
// During the Nuke Wars preparation phase nukes cannot be launched across
// to enemy territory. Block all nuke launches while in the preparation phase.
const gc = this.mg.config().gameConfig();
if (gc.gameMode === GameMode.NukeWars && this.mg.inPreparationPhase()) {
return false;
}
const owner = this.mg.owner(tile);
if (owner.isPlayer()) {
if (this.isOnSameTeam(owner)) {