fix(burgs): don't put burgs on border cells

This commit is contained in:
Azgaar 2022-08-29 00:59:30 +03:00
parent 7a3a87e935
commit 538ad3512e
4 changed files with 14 additions and 12 deletions

View file

@ -8,8 +8,8 @@ import {gauss} from "utils/probabilityUtils";
const {Names} = window;
export function createTowns(
capitalCells: Map<number, boolean>,
cultures: TCultures,
scoredCellIds: UintArray,
cells: Pick<IPack["cells"], "p" | "i" | "f" | "s" | "culture">
) {
TIME && console.time("createTowns");
@ -17,9 +17,6 @@ export function createTowns(
// randomize cells score a bit for more natural towns placement
const randomizeScore = (suitability: number) => suitability * gauss(1, 3, 0, 20, 3);
const scores = new Int16Array(cells.s.map(randomizeScore));
// take populated cells without capitals
const scoredCellIds = cells.i.filter(i => scores[i] > 0 && cells.culture[i] && !capitalCells.has(i));
scoredCellIds.sort((a, b) => scores[b] - scores[a]); // sort by randomized suitability score
const townsNumber = getTownsNumber();

View file

@ -16,7 +16,7 @@ export function generateBurgsAndStates(
vertices: IGraphVertices,
cells: Pick<
IPack["cells"],
"v" | "c" | "p" | "i" | "g" | "h" | "f" | "t" | "haven" | "harbor" | "r" | "fl" | "biome" | "s" | "culture"
"v" | "c" | "p" | "b" | "i" | "g" | "h" | "f" | "t" | "haven" | "harbor" | "r" | "fl" | "biome" | "s" | "culture"
>
): {burgIds: Uint16Array; stateIds: Uint16Array; burgs: TBurgs; states: TStates} {
const cellsNumber = cells.i.length;
@ -34,9 +34,13 @@ export function generateBurgsAndStates(
const capitals = createCapitals(statesNumber, scoredCellIds, cultures, pick(cells, "p", "f", "culture"));
const capitalCells = new Map(capitals.map(({cell}) => [cell, true]));
const states = createStates(capitals, cultures);
const towns = createTowns(capitalCells, cultures, pick(cells, "p", "i", "f", "s", "culture"));
const towns = createTowns(
cultures,
scoredCellIds.filter(i => !capitalCells.has(i)),
pick(cells, "p", "i", "f", "s", "culture")
);
const stateIds = expandStates(
capitalCells,
@ -63,11 +67,12 @@ export function generateBurgsAndStates(
return {burgIds, stateIds, burgs, states};
function getScoredCellIds() {
// cell score for capitals placement
const score = new Int16Array(cells.s.map(s => s * Math.random()));
// filtered and sorted array of indexes
const sorted = cells.i.filter(i => score[i] > 0 && cells.culture[i]).sort((a, b) => score[b] - score[a]);
// filtered and sorted array of indexes: only populated cells not on map edge
const sorted = cells.i
.filter(i => !cells.b[i] && score[i] > 0 && cells.culture[i])
.sort((a, b) => score[b] - score[a]);
return sorted;
}

View file

@ -104,7 +104,7 @@ export function createPack(grid: IGrid): IPack {
rawRivers,
vertices,
{
...pick(cells, "v", "c", "p", "i", "g"),
...pick(cells, "v", "c", "p", "b", "i", "g"),
h: heights,
f: featureIds,
t: distanceField,

View file

@ -58,7 +58,7 @@ export function drawText(text: string | number, [x, y]: TPoint, {size = 6, color
}
export function drawPolygons(
values: TypedArray,
values: TypedArray | number[],
cellVertices: number[][],
vertexPoints: TPoints,
{