Files
OpenFrontIO/tests/WarshipMultiSelection.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

144 lines
4.4 KiB
TypeScript

import { MoveWarshipExecution } from "../src/core/execution/MoveWarshipExecution";
import { WarshipExecution } from "../src/core/execution/WarshipExecution";
import {
Game,
Player,
PlayerInfo,
PlayerType,
UnitType,
} from "../src/core/game/Game";
import { setup } from "./util/Setup";
import { executeTicks } from "./util/utils";
const coastX = 7;
let game: Game;
let player1: Player;
let player2: Player;
describe("Warship multi-selection (MoveWarshipExecution)", () => {
beforeEach(async () => {
game = await setup(
"half_land_half_ocean",
{ infiniteGold: true, instantBuild: true },
[
new PlayerInfo("p1", PlayerType.Human, null, "p1"),
new PlayerInfo("p2", PlayerType.Human, null, "p2"),
],
);
player1 = game.player("p1");
player2 = game.player("p2");
});
test("moving multiple warships via array MoveWarshipExecution updates all patrol tiles", () => {
const w1 = player1.buildUnit(UnitType.Warship, game.ref(coastX + 1, 10), {
patrolTile: game.ref(coastX + 1, 10),
});
const w2 = player1.buildUnit(UnitType.Warship, game.ref(coastX + 2, 10), {
patrolTile: game.ref(coastX + 2, 10),
});
const w3 = player1.buildUnit(UnitType.Warship, game.ref(coastX + 3, 10), {
patrolTile: game.ref(coastX + 3, 10),
});
game.addExecution(new WarshipExecution(w1));
game.addExecution(new WarshipExecution(w2));
game.addExecution(new WarshipExecution(w3));
const sharedTarget = game.ref(coastX + 5, 15);
// Single execution with array of ids — the new unified API
game.addExecution(
new MoveWarshipExecution(
player1,
[w1.id(), w2.id(), w3.id()],
sharedTarget,
),
);
executeTicks(game, 5);
expect(w1.warshipState().patrolTile).toBe(sharedTarget);
expect(w2.warshipState().patrolTile).toBe(sharedTarget);
expect(w3.warshipState().patrolTile).toBe(sharedTarget);
});
test("moving multiple warships to different targets works independently", () => {
const w1 = player1.buildUnit(UnitType.Warship, game.ref(coastX + 1, 10), {
patrolTile: game.ref(coastX + 1, 10),
});
const w2 = player1.buildUnit(UnitType.Warship, game.ref(coastX + 2, 10), {
patrolTile: game.ref(coastX + 2, 10),
});
game.addExecution(new WarshipExecution(w1));
game.addExecution(new WarshipExecution(w2));
const target1 = game.ref(coastX + 3, 12);
const target2 = game.ref(coastX + 4, 14);
game.addExecution(new MoveWarshipExecution(player1, [w1.id()], target1));
game.addExecution(new MoveWarshipExecution(player1, [w2.id()], target2));
executeTicks(game, 5);
expect(w1.warshipState().patrolTile).toBe(target1);
expect(w2.warshipState().patrolTile).toBe(target2);
});
test("enemy cannot move player's warships via MoveWarshipExecution", () => {
const originalTile = game.ref(coastX + 1, 10);
const w1 = player1.buildUnit(UnitType.Warship, originalTile, {
patrolTile: originalTile,
});
game.addExecution(new WarshipExecution(w1));
new MoveWarshipExecution(player2, [w1.id()], game.ref(coastX + 5, 15)).init(
game,
0,
);
expect(w1.warshipState().patrolTile).toBe(originalTile);
});
test("MoveWarshipExecution on destroyed warship does not throw", () => {
const w1 = player1.buildUnit(UnitType.Warship, game.ref(coastX + 1, 10), {
patrolTile: game.ref(coastX + 1, 10),
});
w1.delete();
const exec = new MoveWarshipExecution(
player1,
[w1.id()],
game.ref(coastX + 5, 15),
);
expect(() => exec.init(game, 0)).not.toThrow();
expect(exec.isActive()).toBe(false);
});
test("batch move does not affect warships owned by other players", () => {
const p1tile = game.ref(coastX + 1, 10);
const p2tile = game.ref(coastX + 2, 10);
const w1 = player1.buildUnit(UnitType.Warship, p1tile, {
patrolTile: p1tile,
});
const w2 = player2.buildUnit(UnitType.Warship, p2tile, {
patrolTile: p2tile,
});
game.addExecution(new WarshipExecution(w1));
game.addExecution(new WarshipExecution(w2));
const target = game.ref(coastX + 5, 15);
// player1 sends both IDs — but w2 belongs to player2
game.addExecution(
new MoveWarshipExecution(player1, [w1.id(), w2.id()], target),
);
executeTicks(game, 5);
expect(w1.warshipState().patrolTile).toBe(target);
expect(w2.warshipState().patrolTile).toBe(p2tile); // unchanged — wrong owner
});
});