mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-01 15:53:37 +00:00
e554ffb1b0
## Description: This PR removes the nation strength. Reasoning: - It is currently unused. The backstory can be found in #2498 - It forces map-makers to do balancing work, which is probably not a good idea - It increases map-making work - It increases nation balancing complexity by a lot (we need to have all the json files in mind) - It makes humans avoid map areas completely because there is always that one, same, strong nation - The map lead Nikola123 wants to "not deal with the stupid nations and their balancing" If the goal of nation strength was to make them feel different I would suggest a nation personality system. Nations that love to boat, love to ally, love to nuke, love to fullsend, etc. Link to a discord discussion about nation strength: https://discord.com/channels/1359946986937258015/1360078040222142564/1450973197251117218 ## 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
91 lines
2.2 KiB
TypeScript
91 lines
2.2 KiB
TypeScript
import { GameMapSize, GameMapType } from "./Game";
|
|
import { GameMap, GameMapImpl } from "./GameMap";
|
|
import { GameMapLoader } from "./GameMapLoader";
|
|
|
|
export type TerrainMapData = {
|
|
nations: Nation[];
|
|
gameMap: GameMap;
|
|
miniGameMap: GameMap;
|
|
};
|
|
|
|
const loadedMaps = new Map<GameMapType, TerrainMapData>();
|
|
|
|
export interface MapMetadata {
|
|
width: number;
|
|
height: number;
|
|
num_land_tiles: number;
|
|
}
|
|
|
|
export interface MapManifest {
|
|
name: string;
|
|
map: MapMetadata;
|
|
map4x: MapMetadata;
|
|
map16x: MapMetadata;
|
|
nations: Nation[];
|
|
}
|
|
|
|
export interface Nation {
|
|
coordinates: [number, number];
|
|
flag: string;
|
|
name: string;
|
|
}
|
|
|
|
export async function loadTerrainMap(
|
|
map: GameMapType,
|
|
mapSize: GameMapSize,
|
|
terrainMapFileLoader: GameMapLoader,
|
|
): Promise<TerrainMapData> {
|
|
const cached = loadedMaps.get(map);
|
|
if (cached !== undefined) return cached;
|
|
const mapFiles = terrainMapFileLoader.getMapData(map);
|
|
const manifest = await mapFiles.manifest();
|
|
|
|
const gameMap =
|
|
mapSize === GameMapSize.Normal
|
|
? await genTerrainFromBin(manifest.map, await mapFiles.mapBin())
|
|
: await genTerrainFromBin(manifest.map4x, await mapFiles.map4xBin());
|
|
|
|
const miniMap =
|
|
mapSize === GameMapSize.Normal
|
|
? await genTerrainFromBin(
|
|
mapSize === GameMapSize.Normal ? manifest.map4x : manifest.map16x,
|
|
await mapFiles.map4xBin(),
|
|
)
|
|
: await genTerrainFromBin(manifest.map16x, await mapFiles.map16xBin());
|
|
|
|
if (mapSize === GameMapSize.Compact) {
|
|
manifest.nations.forEach((nation) => {
|
|
nation.coordinates = [
|
|
Math.floor(nation.coordinates[0] / 2),
|
|
Math.floor(nation.coordinates[1] / 2),
|
|
];
|
|
});
|
|
}
|
|
|
|
const result = {
|
|
nations: manifest.nations,
|
|
gameMap: gameMap,
|
|
miniGameMap: miniMap,
|
|
};
|
|
loadedMaps.set(map, result);
|
|
return result;
|
|
}
|
|
|
|
export async function genTerrainFromBin(
|
|
mapData: MapMetadata,
|
|
data: Uint8Array,
|
|
): Promise<GameMap> {
|
|
if (data.length !== mapData.width * mapData.height) {
|
|
throw new Error(
|
|
`Invalid data: buffer size ${data.length} incorrect for ${mapData.width}x${mapData.height} terrain plus 4 bytes for dimensions.`,
|
|
);
|
|
}
|
|
|
|
return new GameMapImpl(
|
|
mapData.width,
|
|
mapData.height,
|
|
data,
|
|
mapData.num_land_tiles,
|
|
);
|
|
}
|