Files
OpenFrontIO/tests/core/executions/PlayerExecution.test.ts
Aotumuri f1d162825e feat: remove spawn timer on singleplayer (#3199)
Resolves #1041 

## Description:

Remove the singleplayer spawn countdown so the game starts when the
player spawns, spawn nations immediately after player spawn, and align
game timer/max-timer timing with the new start point.

Added a singleplayer regression test for spawn-immunity timing
(GameImpl.test.ts) and updated spawn-phase loop tests to use gameType:
GameType.Public where singleplayer behavior is not under test (e.g.
MIRV/AI/Spawn/WinCheck-related suites), eliminating inSpawnPhase()
timeout hangs after the new singleplayer start logic.


https://github.com/user-attachments/assets/c07a585f-1153-490e-88ca-a91fc7ae5756

## 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

## Please put your Discord username so you can be contacted if a bug or
regression is found:
aotumuri
2026-05-11 12:44:44 -07:00

89 lines
2.7 KiB
TypeScript

import { PlayerExecution } from "../../../src/core/execution/PlayerExecution";
import {
Game,
Player,
PlayerInfo,
PlayerType,
UnitType,
} from "../../../src/core/game/Game";
import { setup } from "../../util/Setup";
import { executeTicks } from "../../util/utils";
let game: Game;
let player: Player;
let otherPlayer: Player;
describe("PlayerExecution", () => {
beforeEach(async () => {
game = await setup(
"big_plains",
{ infiniteGold: true, instantBuild: true },
[
new PlayerInfo("player", PlayerType.Human, "client_id1", "player_id"),
new PlayerInfo("other", PlayerType.Human, "client_id2", "other_id"),
],
);
player = game.player("player_id");
otherPlayer = game.player("other_id");
game.addExecution(new PlayerExecution(player));
game.addExecution(new PlayerExecution(otherPlayer));
});
test("DefensePost lv. 1 is destroyed when tile owner changes", () => {
const tile = game.ref(50, 50);
player.conquer(tile);
const defensePost = player.buildUnit(UnitType.DefensePost, tile, {});
game.executeNextTick();
expect(game.unitCount(UnitType.DefensePost)).toBe(1);
expect(defensePost.level()).toBe(1);
otherPlayer.conquer(tile);
executeTicks(game, 2);
expect(game.unitCount(UnitType.DefensePost)).toBe(0);
});
test("DefensePost lv. 2+ is downgraded when tile owner changes", () => {
const tile = game.ref(50, 50);
player.conquer(tile);
const defensePost = player.buildUnit(UnitType.DefensePost, tile, {});
defensePost.increaseLevel();
expect(defensePost.level()).toBe(2);
expect(game.unitCount(UnitType.DefensePost)).toBe(2); // unitCount sums levels
expect(player.units(UnitType.DefensePost)).toHaveLength(1);
expect(defensePost.isActive()).toBe(true);
otherPlayer.conquer(tile);
executeTicks(game, 2);
expect(defensePost.level()).toBe(1);
expect(game.unitCount(UnitType.DefensePost)).toBe(1);
expect(otherPlayer.units(UnitType.DefensePost)).toHaveLength(1);
expect(defensePost.owner()).toBe(otherPlayer);
expect(defensePost.isActive()).toBe(true);
});
test("Non-DefensePost structures are transferred (not downgraded) when tile owner changes", () => {
const tile = game.ref(50, 50);
player.conquer(tile);
const city = player.buildUnit(UnitType.City, tile, {});
expect(game.unitCount(UnitType.City)).toBe(1);
expect(city.level()).toBe(1);
expect(city.owner()).toBe(player);
expect(city.isActive()).toBe(true);
otherPlayer.conquer(tile);
executeTicks(game, 2);
expect(game.unitCount(UnitType.City)).toBe(1);
expect(city.level()).toBe(1);
expect(city.owner()).toBe(otherPlayer);
expect(city.isActive()).toBe(true);
});
});