mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 20:16:44 +00:00
0b9d43cb46
## Description: I hope we can get this into v30? The nation count is configurable now, just like the bot count. Replaced the "Disable Nations" toggle with a nations slider (0–400) in SinglePlayer and Host Lobby modals. <img width="710" height="121" alt="Screenshot 2026-03-03 021952" src="https://github.com/user-attachments/assets/c8d0f0c3-db51-4303-95fa-dbc770460ec2" /> Public games are staying exactly the same, this is just for singleplayer and private lobby fun. Youtubers could play HvN against 400 nations, for example. Singleplayer enjoyers no longer have to play against 1 nation in HvN, they can freely choose. `GameConfig.disableNations: boolean` got replaced by `nations: number (0-400, optional)` `undefined` = map default, `0` = disabled, number = custom count Nations slider defaults to the map's nation count, shows "(MAP DEFAULT)" label when unchanged Compact map toggle reduces nations to 25% when at default, restores when toggled off (just like we already do with bots) The nation count for HvN no longer automatically matches the human count in singleplayer and private games, only in public games. **What if there aren't enough nations configured for the map?** We just use the HvN logic (Generate random nations) ### Warning **This infra PR also needs to get merged: https://github.com/openfrontio/infra/pull/263 Otherwise players can set 0 nations and get achievements.** ## 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: FloPinguin
181 lines
4.4 KiB
TypeScript
181 lines
4.4 KiB
TypeScript
// Minimal test maps for pathfinding unit tests
|
|
|
|
import {
|
|
Difficulty,
|
|
Game,
|
|
GameMapSize,
|
|
GameMapType,
|
|
GameMode,
|
|
GameType,
|
|
} from "../../../src/core/game/Game";
|
|
import { createGame as createGameImpl } from "../../../src/core/game/GameImpl";
|
|
import { GameMapImpl } from "../../../src/core/game/GameMap";
|
|
import { UserSettings } from "../../../src/core/game/UserSettings";
|
|
import { GameConfig } from "../../../src/core/Schemas";
|
|
import { TestConfig } from "../../util/TestConfig";
|
|
import { TestServerConfig } from "../../util/TestServerConfig";
|
|
|
|
export const W = "W"; // Water
|
|
export const L = "L"; // Land
|
|
|
|
// Terrain encoding
|
|
const WATER_BIT = 0x20;
|
|
const LAND_BIT = 0x80;
|
|
const SHORELINE_BIT = 6;
|
|
|
|
export type TestMapData = {
|
|
width: number;
|
|
height: number;
|
|
grid: string[];
|
|
};
|
|
|
|
// Compute shoreline bit for tiles adjacent to opposite terrain
|
|
function computeShoreline(
|
|
terrain: Uint8Array,
|
|
width: number,
|
|
height: number,
|
|
): void {
|
|
for (let y = 0; y < height; y++) {
|
|
for (let x = 0; x < width; x++) {
|
|
const idx = y * width + x;
|
|
const isLand = (terrain[idx] & LAND_BIT) !== 0;
|
|
const neighbors = [
|
|
[x - 1, y],
|
|
[x + 1, y],
|
|
[x, y - 1],
|
|
[x, y + 1],
|
|
];
|
|
|
|
for (const [nx, ny] of neighbors) {
|
|
if (nx < 0 || nx >= width || ny < 0 || ny >= height) continue;
|
|
const neighborIsLand = (terrain[ny * width + nx] & LAND_BIT) !== 0;
|
|
if (isLand !== neighborIsLand) {
|
|
terrain[idx] |= 1 << SHORELINE_BIT;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// 5x5 simple island
|
|
export function createIslandMap(): TestMapData {
|
|
// prettier-ignore
|
|
const grid = [
|
|
W, W, W, W, W,
|
|
W, L, L, L, W,
|
|
W, L, L, L, W,
|
|
W, L, L, L, W,
|
|
W, W, W, W, W,
|
|
];
|
|
return { width: 5, height: 5, grid };
|
|
}
|
|
|
|
// Create Game from test map data (computes shoreline bits)
|
|
export function createGame(data: TestMapData): Game {
|
|
const { width, height, grid } = data;
|
|
|
|
// Convert string grid to terrain bytes
|
|
const terrain = new Uint8Array(width * height);
|
|
let numLand = 0;
|
|
|
|
for (let i = 0; i < grid.length; i++) {
|
|
if (grid[i] === L) {
|
|
terrain[i] = LAND_BIT;
|
|
numLand++;
|
|
} else {
|
|
terrain[i] = WATER_BIT;
|
|
}
|
|
}
|
|
|
|
computeShoreline(terrain, width, height);
|
|
|
|
const gameMap = new GameMapImpl(width, height, terrain, numLand);
|
|
|
|
// Create miniMap (2x2→1, water if ANY water)
|
|
const miniWidth = Math.ceil(width / 2);
|
|
const miniHeight = Math.ceil(height / 2);
|
|
const miniTerrain = new Uint8Array(miniWidth * miniHeight);
|
|
let miniNumLand = 0;
|
|
|
|
for (let my = 0; my < miniHeight; my++) {
|
|
for (let mx = 0; mx < miniWidth; mx++) {
|
|
const mIdx = my * miniWidth + mx;
|
|
let hasWater = false;
|
|
|
|
for (let dy = 0; dy < 2; dy++) {
|
|
for (let dx = 0; dx < 2; dx++) {
|
|
const x = mx * 2 + dx;
|
|
const y = my * 2 + dy;
|
|
if (x < width && y < height && !(terrain[y * width + x] & LAND_BIT)) {
|
|
hasWater = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (hasWater) {
|
|
miniTerrain[mIdx] = WATER_BIT;
|
|
} else {
|
|
miniTerrain[mIdx] = LAND_BIT;
|
|
miniNumLand++;
|
|
}
|
|
}
|
|
}
|
|
|
|
computeShoreline(miniTerrain, miniWidth, miniHeight);
|
|
|
|
const miniGameMap = new GameMapImpl(
|
|
miniWidth,
|
|
miniHeight,
|
|
miniTerrain,
|
|
miniNumLand,
|
|
);
|
|
|
|
const serverConfig = new TestServerConfig();
|
|
const gameConfig: GameConfig = {
|
|
gameMap: GameMapType.Asia,
|
|
gameMapSize: GameMapSize.Normal,
|
|
gameMode: GameMode.FFA,
|
|
gameType: GameType.Singleplayer,
|
|
difficulty: Difficulty.Medium,
|
|
nations: "default",
|
|
donateGold: false,
|
|
donateTroops: false,
|
|
bots: 0,
|
|
infiniteGold: false,
|
|
infiniteTroops: false,
|
|
instantBuild: false,
|
|
disableNavMesh: false,
|
|
randomSpawn: false,
|
|
};
|
|
const config = new TestConfig(
|
|
serverConfig,
|
|
gameConfig,
|
|
new UserSettings(),
|
|
false,
|
|
);
|
|
|
|
return createGameImpl([], [], gameMap, miniGameMap, config);
|
|
}
|
|
|
|
// Create GameMapImpl from test map data (for map-only tests)
|
|
export function createGameMap(data: TestMapData): GameMapImpl {
|
|
const { width, height, grid } = data;
|
|
|
|
const terrain = new Uint8Array(width * height);
|
|
let numLand = 0;
|
|
|
|
for (let i = 0; i < grid.length; i++) {
|
|
if (grid[i] === L) {
|
|
terrain[i] = LAND_BIT;
|
|
numLand++;
|
|
} else {
|
|
terrain[i] = WATER_BIT;
|
|
}
|
|
}
|
|
|
|
computeShoreline(terrain, width, height);
|
|
|
|
return new GameMapImpl(width, height, terrain, numLand);
|
|
}
|