refactor: generate states cleanup

This commit is contained in:
max 2022-08-06 00:02:35 +03:00
parent c2fc0679ad
commit ff974a4fd0
16 changed files with 98 additions and 64 deletions

View file

@ -337,8 +337,9 @@ export function open({el}) {
let name = ""; let name = "";
if (elSelected.attr("id").slice(0, 10) === "stateLabel") { if (elSelected.attr("id").slice(0, 10) === "stateLabel") {
const id = +elSelected.attr("id").slice(10); const id = +elSelected.attr("id").slice(10);
const culture = pack.states[id].culture; const cultureId = pack.states[id].culture;
name = Names.getState(Names.getCulture(culture, 4, 7, ""), culture); const base = pack.cultures[cultureId].base;
name = Names.getState(Names.getBase(base, 4, 7, ""), base);
} else { } else {
const box = elSelected.node().getBBox(); const box = elSelected.node().getBBox();
const cell = findCell((box.x + box.width) / 2, (box.y + box.height) / 2); const cell = findCell((box.x + box.width) / 2, (box.y + box.height) / 2);

View file

@ -464,14 +464,15 @@ function editStateName(state) {
function regenerateShortNameCuture() { function regenerateShortNameCuture() {
const state = +stateNameEditor.dataset.state; const state = +stateNameEditor.dataset.state;
const culture = pack.states[state].culture; const cultureId = pack.states[state].culture;
const name = Names.getState(Names.getCultureShort(culture), culture); const base = pack.cultures[cultureId].base;
const name = Names.getState(Names.getBaseShort(base), base);
byId("stateNameEditorShort").value = name; byId("stateNameEditorShort").value = name;
} }
function regenerateShortNameRandom() { function regenerateShortNameRandom() {
const base = rand(nameBases.length - 1); const base = rand(nameBases.length - 1);
const name = Names.getState(Names.getBase(base), undefined, base); const name = Names.getState(Names.getBase(base), base);
byId("stateNameEditorShort").value = name; byId("stateNameEditorShort").value = name;
} }
@ -1156,7 +1157,8 @@ function adjustProvinces(affectedProvinces) {
const culture = cells.culture[center]; const culture = cells.culture[center];
const nameByBurg = burgCell && P(0.5); const nameByBurg = burgCell && P(0.5);
const name = nameByBurg ? burg.name : oldProvince.name || Names.getState(Names.getCultureShort(culture), culture); const base = pack.cultures[culture].base;
const name = nameByBurg ? burg.name : oldProvince.name || Names.getState(Names.getBaseShort(base), base);
const formOptions = ["Zone", "Area", "Territory", "Province"]; const formOptions = ["Zone", "Area", "Territory", "Province"];
const formName = burgCell && oldProvince.formName ? oldProvince.formName : ra(formOptions); const formName = burgCell && oldProvince.formName ? oldProvince.formName : ra(formOptions);
@ -1259,8 +1261,9 @@ function addState() {
if (d3.event.shiftKey === false) exitAddStateMode(); if (d3.event.shiftKey === false) exitAddStateMode();
const culture = cells.culture[center]; const culture = cells.culture[center];
const basename = center % 5 === 0 ? burgs[burg].name : Names.getCulture(culture); const base = pack.cultures[culture].base;
const name = Names.getState(basename, culture); const basename = center % 5 === 0 ? burgs[burg].name : Names.getBase(culture);
const name = Names.getState(basename, base);
const color = getRandomColor(); const color = getRandomColor();
const pole = cells.p[center]; const pole = cells.p[center];

View file

@ -106,8 +106,9 @@ window.BurgsAndStates = (function () {
// states data // states data
const expansionism = rn(Math.random() * powerInput.value + 1, 1); const expansionism = rn(Math.random() * powerInput.value + 1, 1);
const basename = b.name.length < 9 && each5th(b.cell) ? b.name : Names.getCultureShort(b.culture); const base = pack.cultures[b.culture].base;
const name = Names.getState(basename, b.culture); const basename = b.name.length < 9 && each5th(b.cell) ? b.name : Names.getBaseShort(base);
const name = Names.getState(basename, base);
const type = cultures[b.culture].type; const type = cultures[b.culture].type;
const coa = COA.generate(null, null, null, type); const coa = COA.generate(null, null, null, type);
@ -1200,9 +1201,11 @@ window.BurgsAndStates = (function () {
s.provinces.push(province); s.provinces.push(province);
const center = stateBurgs[i].cell; const center = stateBurgs[i].cell;
const burg = stateBurgs[i].i; const burg = stateBurgs[i].i;
const c = stateBurgs[i].culture; const cultureId = stateBurgs[i].culture;
const nameByBurg = P(0.5); const nameByBurg = P(0.5);
const name = nameByBurg ? stateBurgs[i].name : Names.getState(Names.getCultureShort(c), c);
const base = pack.cultures[cultureId].base;
const name = nameByBurg ? stateBurgs[i].name : Names.getState(Names.getBaseShort(base), base);
const formName = rw(form); const formName = rw(form);
form[formName] += 10; form[formName] += 10;
const fullName = name + " " + formName; const fullName = name + " " + formName;
@ -1210,7 +1213,7 @@ window.BurgsAndStates = (function () {
const kinship = nameByBurg ? 0.8 : 0.4; const kinship = nameByBurg ? 0.8 : 0.4;
const type = getType(center, burg.port); const type = getType(center, burg.port);
const coa = COA.generate(stateBurgs[i].coa, kinship, null, type); const coa = COA.generate(stateBurgs[i].coa, kinship, null, type);
coa.shield = COA.getShield(c, s.i); coa.shield = COA.getShield(cultureId, s.i);
provinces.push({i: province, state: s.i, center, burg, name, formName, fullName, color, coa}); provinces.push({i: province, state: s.i, center, burg, name, formName, fullName, color, coa});
} }
}); });
@ -1312,7 +1315,7 @@ window.BurgsAndStates = (function () {
} }
// generate "wild" province name // generate "wild" province name
const c = cells.culture[center]; const cultureId = cells.culture[center];
const f = pack.features[cells.f[center]]; const f = pack.features[cells.f[center]];
const color = getMixedColor(s.color); const color = getMixedColor(s.color);
@ -1325,7 +1328,9 @@ window.BurgsAndStates = (function () {
const colonyName = colony && P(0.8) && getColonyName(); const colonyName = colony && P(0.8) && getColonyName();
if (colonyName) return colonyName; if (colonyName) return colonyName;
if (burgCell && P(0.5)) return burgs[burg].name; if (burgCell && P(0.5)) return burgs[burg].name;
return Names.getState(Names.getCultureShort(c), c); const base = pack.cultures[cultureId].base;
return Names.getState(Names.getBaseShort(base), base);
})(); })();
const formName = (function () { const formName = (function () {
@ -1341,7 +1346,7 @@ window.BurgsAndStates = (function () {
const kinship = dominion ? 0 : 0.4; const kinship = dominion ? 0 : 0.4;
const type = getType(center, burgs[burg]?.port); const type = getType(center, burgs[burg]?.port);
const coa = COA.generate(s.coa, kinship, dominion, type); const coa = COA.generate(s.coa, kinship, dominion, type);
coa.shield = COA.getShield(c, s.i); coa.shield = COA.getShield(cultureId, s.i);
provinces.push({i: province, state: s.i, center, burg, name, formName, fullName, color, coa}); provinces.push({i: province, state: s.i, center, burg, name, formName, fullName, color, coa});
s.provinces.push(province); s.provinces.push(province);

View file

@ -1,3 +1,4 @@
import {pack} from "d3";
import {P, rw} from "utils/probabilityUtils"; import {P, rw} from "utils/probabilityUtils";
window.COA = (function () { window.COA = (function () {
@ -1038,14 +1039,14 @@ window.COA = (function () {
return coa; return coa;
}; };
const getShield = function (culture, state) { const getShield = function (cultureId, stateId, cultures = pack.cultures, states = pack.states) {
const emblemShape = document.getElementById("emblemShape"); const emblemShape = document.getElementById("emblemShape");
const shapeGroup = emblemShape.selectedOptions[0]?.parentNode.label || "Diversiform"; const shapeGroup = emblemShape.selectedOptions[0]?.parentNode.label || "Diversiform";
if (shapeGroup !== "Diversiform") return emblemShape.value; if (shapeGroup !== "Diversiform") return emblemShape.value;
if (emblemShape.value === "state" && state && pack.states[state].coa) return pack.states[state].coa.shield; if (emblemShape.value === "state" && stateId && states[stateId].coa) return states[stateId].coa.shield;
if (pack.cultures[culture].shield) return pack.cultures[culture].shield; if (cultures[cultureId].shield) return cultures[cultureId].shield;
ERROR && console.error("Shield shape is not defined on culture level", pack.cultures[culture]); ERROR && console.error("Shield shape is not defined on culture level", cultures[cultureId]);
return "heater"; return "heater";
}; };

View file

@ -15,7 +15,7 @@ export function defineSvg(width, height) {
texture = viewbox.append("g").attr("id", "texture"); texture = viewbox.append("g").attr("id", "texture");
terrs = viewbox.append("g").attr("id", "terrs"); terrs = viewbox.append("g").attr("id", "terrs");
biomes = viewbox.append("g").attr("id", "biomes"); biomes = viewbox.append("g").attr("id", "biomes");
cells = viewbox.append("g").attr("id", "cells"); // cells = viewbox.append("g").attr("id", "cells");
gridOverlay = viewbox.append("g").attr("id", "gridOverlay"); gridOverlay = viewbox.append("g").attr("id", "gridOverlay");
coordinates = viewbox.append("g").attr("id", "coordinates"); coordinates = viewbox.append("g").attr("id", "coordinates");
compass = viewbox.append("g").attr("id", "compass"); compass = viewbox.append("g").attr("id", "compass");

View file

@ -99,7 +99,7 @@ window.HeightmapGenerator = (function () {
if (tool === "Smooth") return smooth(a2); if (tool === "Smooth") return smooth(a2);
} }
function getBlobPower(cells) { function getBlobPower(cellsNumber) {
const blobPowerMap = { const blobPowerMap = {
1000: 0.93, 1000: 0.93,
2000: 0.95, 2000: 0.95,
@ -115,10 +115,10 @@ window.HeightmapGenerator = (function () {
90000: 0.9964, 90000: 0.9964,
100000: 0.9973 100000: 0.9973
}; };
return blobPowerMap[cells] || 0.98; return blobPowerMap[cellsNumber] || 0.98;
} }
function getLinePower() { function getLinePower(cellsNumber) {
const linePowerMap = { const linePowerMap = {
1000: 0.75, 1000: 0.75,
2000: 0.77, 2000: 0.77,
@ -135,7 +135,7 @@ window.HeightmapGenerator = (function () {
100000: 0.93 100000: 0.93
}; };
return linePowerMap[cells] || 0.81; return linePowerMap[cellsNumber] || 0.81;
} }
const addHill = (count, height, rangeX, rangeY) => { const addHill = (count, height, rangeX, rangeY) => {

View file

@ -162,10 +162,9 @@ window.Names = (function () {
}; };
// generate state name based on capital or random name and culture-specific suffix // generate state name based on capital or random name and culture-specific suffix
const getState = function (name, culture, base) { const getState = function (name, base) {
if (name === undefined) return ERROR && console.error("Please define a base name"); if (name === undefined) return ERROR && console.error("Please define a base name");
if (culture === undefined && base === undefined) return ERROR && console.error("Please define a culture"); if (base === undefined) return ERROR && console.error("Please define a namesbase");
if (base === undefined) base = pack.cultures[culture].base;
// exclude endings inappropriate for states name // exclude endings inappropriate for states name
if (name.includes(" ")) name = capitalize(name.replace(/ /g, "").toLowerCase()); // don't allow multiword state names if (name.includes(" ")) name = capitalize(name.replace(/ /g, "").toLowerCase()); // don't allow multiword state names

View file

@ -2,7 +2,7 @@ import * as d3 from "d3";
import {INFO} from "config/logging"; import {INFO} from "config/logging";
import {findCell} from "utils/graphUtils"; import {findCell} from "utils/graphUtils";
import {getMiddlePoint} from "utils/lineUtils"; import {getCommonEdgePoint} from "utils/lineUtils";
import {rn} from "utils/numberUtils"; import {rn} from "utils/numberUtils";
import {aleaPRNG} from "scripts/aleaPRNG"; import {aleaPRNG} from "scripts/aleaPRNG";
import {renderLayer} from "layers"; import {renderLayer} from "layers";

View file

@ -552,13 +552,15 @@ export function editProvinces() {
function regenerateShortNameCuture() { function regenerateShortNameCuture() {
const province = +provinceNameEditor.dataset.province; const province = +provinceNameEditor.dataset.province;
const culture = pack.cells.culture[pack.provinces[province].center]; const culture = pack.cells.culture[pack.provinces[province].center];
const name = Names.getState(Names.getCultureShort(culture), culture); const base = pack.cultures[culture].base;
const name = Names.getState(Names.getBaseShort(base), base);
byId("provinceNameEditorShort").value = name; byId("provinceNameEditorShort").value = name;
} }
function regenerateShortNameRandom() { function regenerateShortNameRandom() {
const base = rand(nameBases.length - 1); const base = rand(nameBases.length - 1);
const name = Names.getState(Names.getBase(base), undefined, base); const name = Names.getState(Names.getBase(base), base);
byId("provinceNameEditorShort").value = name; byId("provinceNameEditorShort").value = name;
} }
@ -1033,8 +1035,9 @@ export function editProvinces() {
const province = provinces.length; const province = provinces.length;
pack.states[state].provinces.push(province); pack.states[state].provinces.push(province);
const burg = cells.burg[center]; const burg = cells.burg[center];
const c = cells.culture[center]; const cultureId = cells.culture[center];
const name = burg ? pack.burgs[burg].name : Names.getState(Names.getCultureShort(c), c); const base = pack.cultures[cultureId].base;
const name = burg ? pack.burgs[burg].name : Names.getState(Names.getBaseShort(base), base);
const formName = oldProvince ? provinces[oldProvince].formName : "Province"; const formName = oldProvince ? provinces[oldProvince].formName : "Province";
const fullName = name + " " + formName; const fullName = name + " " + formName;
const stateColor = pack.states[state].color; const stateColor = pack.states[state].color;
@ -1046,7 +1049,7 @@ export function editProvinces() {
const parent = burg ? pack.burgs[burg].coa : pack.states[state].coa; const parent = burg ? pack.burgs[burg].coa : pack.states[state].coa;
const type = BurgsAndStates.getType(center, parent.port); const type = BurgsAndStates.getType(center, parent.port);
const coa = COA.generate(parent, kinship, P(0.1), type); const coa = COA.generate(parent, kinship, P(0.1), type);
coa.shield = COA.getShield(c, state); coa.shield = COA.getShield(cultureId, state);
COArenderer.add("province", province, coa, point[0], point[1]); COArenderer.add("province", province, coa, point[0], point[1]);
provinces.push({i: province, state, center, burg, name, formName, fullName, color, coa}); provinces.push({i: province, state, center, burg, name, formName, fullName, color, coa});

View file

@ -221,9 +221,11 @@ function regenerateStates() {
} }
const culture = capital.culture; const culture = capital.culture;
const base = pack.cultures[culture].base;
const basename = const basename =
capital.name.length < 9 && capital.cell % 5 === 0 ? capital.name : Names.getCulture(culture, 3, 6, "", 0); capital.name.length < 9 && capital.cell % 5 === 0 ? capital.name : Names.getCulture(culture, 3, 6, "", 0);
const name = Names.getState(basename, culture); const name = Names.getState(basename, base);
const nomadic = [1, 2, 3, 4].includes(pack.cells.biome[capital.cell]); const nomadic = [1, 2, 3, 4].includes(pack.cells.biome[capital.cell]);
const type = nomadic const type = nomadic
? "Nomadic" ? "Nomadic"

View file

@ -4,13 +4,22 @@ import {TIME, WARN} from "config/logging";
const {Names} = window; const {Names} = window;
export function createCapitals(statesNumber: number, scoredCellIds: UintArray, burgIds: Uint16Array) { export function createCapitals(
statesNumber: number,
scoredCellIds: UintArray,
burgIds: Uint16Array,
cultures: TCultures,
cells: Pick<IPack["cells"], "p" | "f" | "culture">
) {
TIME && console.time("createCapitals"); TIME && console.time("createCapitals");
const capitals = placeCapitals(statesNumber, scoredCellIds).map((cellId, index) => { const capitalCells = placeCapitals(statesNumber, scoredCellIds, cells.p);
const capitals = capitalCells.map((cellId, index) => {
const id = index + 1; const id = index + 1;
const cultureId = cells.culture[cellId]; const cultureId = cells.culture[cellId];
const name: string = Names.getCultureShort(cultureId); const nameBase = cultures[cultureId].base;
const name: string = Names.getBaseShort(nameBase);
const featureId = cells.f[cellId]; const featureId = cells.f[cellId];
return {i: id, cell: cellId, culture: cultureId, name, feature: featureId, capital: 1 as Logical}; return {i: id, cell: cellId, culture: cultureId, name, feature: featureId, capital: 1 as Logical};
@ -24,13 +33,13 @@ export function createCapitals(statesNumber: number, scoredCellIds: UintArray, b
return capitals; return capitals;
} }
function placeCapitals(statesNumber: number, scoredCellIds: UintArray) { function placeCapitals(statesNumber: number, scoredCellIds: UintArray, points: TPoints) {
function attemptToPlaceCapitals(spacing: number): number[] { function attemptToPlaceCapitals(spacing: number): number[] {
const capitalCells: number[] = []; const capitalCells: number[] = [];
const capitalsQuadtree = d3.quadtree(); const capitalsQuadtree = d3.quadtree();
for (const cellId of scoredCellIds) { for (const cellId of scoredCellIds) {
const [x, y] = cells.p[cellId]; const [x, y] = points[cellId];
if (capitalsQuadtree.find(x, y, spacing) === undefined) { if (capitalsQuadtree.find(x, y, spacing) === undefined) {
capitalCells.push(cellId); capitalCells.push(cellId);

View file

@ -14,22 +14,17 @@ export function createStates(capitals: TCapitals, cultures: TCultures) {
TIME && console.time("createStates"); TIME && console.time("createStates");
const colors = getColors(capitals.length); const colors = getColors(capitals.length);
const each5th = each(5); // select each 5th element
const powerInput = getInputNumber("powerInput"); const powerInput = getInputNumber("powerInput");
const states = capitals.map((capital, index) => { const states = capitals.map((capital, index) => {
const {cell: cellId, culture: cultureId, name: capitalName, i: capitalId} = capital; const {cell: cellId, culture: cultureId, name: capitalName, i: capitalId} = capital;
const id = index + 1; const id = index + 1;
const name = getStateName(cellId, capitalName, cultureId, cultures);
const useCapitalName = capitalName.length < 9 && each5th(cellId);
const basename = useCapitalName ? capitalName : Names.getCultureShort(cultureId);
const name: string = Names.getState(basename, cultureId);
const color = colors[index]; const color = colors[index];
const type = (cultures[cultureId] as ICulture).type; const type = (cultures[cultureId] as ICulture).type;
const expansionism = rn(Math.random() * powerInput + 1, 1); const expansionism = rn(Math.random() * powerInput + 1, 1);
const shield = COA.getShield(cultureId, null); const shield = COA.getShield(cultureId, null, cultures);
const coa = {...COA.generate(null, null, null, type), shield}; const coa = {...COA.generate(null, null, null, type), shield};
return {i: id, center: cellId, type, name, color, expansionism, capital: capitalId, culture: cultureId, coa}; return {i: id, center: cellId, type, name, color, expansionism, capital: capitalId, culture: cultureId, coa};
@ -38,3 +33,11 @@ export function createStates(capitals: TCapitals, cultures: TCultures) {
TIME && console.timeEnd("createStates"); TIME && console.timeEnd("createStates");
return [NEUTRALS, ...states]; return [NEUTRALS, ...states];
} }
function getStateName(cellId: number, capitalName: string, cultureId: number, cultures: TCultures) {
const useCapitalName = capitalName.length < 9 && each(5)(cellId);
const nameBase = cultures[cultureId].base;
const basename: string = useCapitalName ? capitalName : Names.getBaseShort(nameBase);
return Names.getState(basename, basename);
}

View file

@ -7,24 +7,31 @@ import {gauss} from "utils/probabilityUtils";
const {Names} = window; const {Names} = window;
export function createTowns(scoredCellIds: UintArray, burgIds: Uint16Array) { export function createTowns(
burgIds: Uint16Array,
cultures: TCultures,
cells: Pick<IPack["cells"], "p" | "i" | "f" | "s" | "culture">
) {
TIME && console.time("createTowns"); TIME && console.time("createTowns");
const townsNumber = getTownsNumber();
if (townsNumber === 0) return [];
// randomize cells score a bit for more natural towns placement // randomize cells score a bit for more natural towns placement
const randomizeScore = (suitability: number) => suitability * gauss(1, 3, 0, 20, 3); const randomizeScore = (suitability: number) => suitability * gauss(1, 3, 0, 20, 3);
const scores = new Int16Array(cells.s.map(randomizeScore)); const scores = new Int16Array(cells.s.map(randomizeScore));
// take populated cells without capitals // take populated cells without capitals
const scoredCellsIds = cells.i.filter(i => scores[i] > 0 && cells.culture[i] && !burgIds[i]); const scoredCellIds = cells.i.filter(i => scores[i] > 0 && cells.culture[i] && !burgIds[i]);
scoredCellsIds.sort((a, b) => scores[b] - scores[a]); // sort by randomized suitability score scoredCellIds.sort((a, b) => scores[b] - scores[a]); // sort by randomized suitability score
const towns = placeTowns(townsNumber, scoredCellIds).map((cellId, index) => { const townsNumber = getTownsNumber();
if (townsNumber === 0) return [];
const townCells = placeTowns(townsNumber, scoredCellIds, cells.p);
const towns = townCells.map((cellId, index) => {
const id = index + 1; const id = index + 1;
const cultureId = cells.culture[cellId]; const cultureId = cells.culture[cellId];
const name: string = Names.getCulture(cultureId); const namesbase = cultures[cultureId].base;
const name: string = Names.getBase(namesbase);
const featureId = cells.f[cellId]; const featureId = cells.f[cellId];
return {i: id, cell: cellId, culture: cultureId, name, feature: featureId, capital: 0 as Logical}; return {i: id, cell: cellId, culture: cultureId, name, feature: featureId, capital: 0 as Logical};
@ -40,13 +47,13 @@ export function createTowns(scoredCellIds: UintArray, burgIds: Uint16Array) {
function getTownsNumber() { function getTownsNumber() {
const inputTownsNumber = getInputNumber("manorsInput"); const inputTownsNumber = getInputNumber("manorsInput");
const shouldAutoDefine = inputTownsNumber === 1000; const shouldAutoDefine = inputTownsNumber === 1000;
const desiredTownsNumber = shouldAutoDefine ? rn(scoredCellsIds.length / 5 ** 0.8) : inputTownsNumber; const desiredTownsNumber = shouldAutoDefine ? rn(scoredCellIds.length / 5 ** 0.8) : inputTownsNumber;
return Math.min(desiredTownsNumber, scoredCellsIds.length); return Math.min(desiredTownsNumber, scoredCellIds.length);
} }
} }
function placeTowns(townsNumber: number, scoredCellIds: UintArray) { function placeTowns(townsNumber: number, scoredCellIds: UintArray, points: TPoints) {
function attemptToPlaceTowns(spacing: number): number[] { function attemptToPlaceTowns(spacing: number): number[] {
const townCells: number[] = []; const townCells: number[] = [];
const townsQuadtree = d3.quadtree(); const townsQuadtree = d3.quadtree();
@ -54,7 +61,7 @@ function placeTowns(townsNumber: number, scoredCellIds: UintArray) {
const randomizeScaping = (spacing: number) => spacing * gauss(1, 0.3, 0.2, 2, 2); const randomizeScaping = (spacing: number) => spacing * gauss(1, 0.3, 0.2, 2, 2);
for (const cellId of scoredCellIds) { for (const cellId of scoredCellIds) {
const [x, y] = cells.p[cellId]; const [x, y] = points[cellId];
// randomize min spacing a bit to make placement not that uniform // randomize min spacing a bit to make placement not that uniform
const currentSpacing = randomizeScaping(spacing); const currentSpacing = randomizeScaping(spacing);

View file

@ -1,4 +1,5 @@
import {WARN} from "config/logging"; import {WARN} from "config/logging";
import {pick} from "utils/functionUtils";
import {getInputNumber} from "utils/nodeUtils"; import {getInputNumber} from "utils/nodeUtils";
import {NEUTRALS, NO_BURG} from "./config"; import {NEUTRALS, NO_BURG} from "./config";
import {createCapitals} from "./createCapitals"; import {createCapitals} from "./createCapitals";
@ -25,9 +26,9 @@ export function generateBurgsAndStates(
const statesNumber = getStatesNumber(scoredCellIds.length); const statesNumber = getStatesNumber(scoredCellIds.length);
if (statesNumber === 0) return {burgIds, burgs: [NO_BURG], states: [NEUTRALS]}; if (statesNumber === 0) return {burgIds, burgs: [NO_BURG], states: [NEUTRALS]};
const capitals = createCapitals(statesNumber, scoredCellIds, burgIds); const capitals = createCapitals(statesNumber, scoredCellIds, burgIds, cultures, pick(cells, "p", "f", "culture"));
const states = createStates(capitals, cultures); const states = createStates(capitals, cultures);
const towns = createTowns(scoredCellIds, burgIds); const towns = createTowns(burgIds, cultures, pick(cells, "p", "i", "f", "s", "culture"));
expandStates(); expandStates();
// normalizeStates(); // normalizeStates();

View file

@ -103,7 +103,7 @@ export function specifyBurgs(capitals: TCapitals, towns: TTowns, roadScores: Uin
if (stateId === 0) { if (stateId === 0) {
const baseCoa = COA.generate(null, 0, null, coaType); const baseCoa = COA.generate(null, 0, null, coaType);
const shield = COA.getShield(cultureId, stateId); const shield = COA.getShield(cultureId, stateId, cultures, states);
return {...baseCoa, shield}; return {...baseCoa, shield};
} }
@ -111,7 +111,7 @@ export function specifyBurgs(capitals: TCapitals, towns: TTowns, roadScores: Uin
const kinship = defineKinshipToStateEmblem(); const kinship = defineKinshipToStateEmblem();
const baseCoa = COA.generate(stateCOA, kinship, null, coaType); const baseCoa = COA.generate(stateCOA, kinship, null, coaType);
const shield = COA.getShield(cultureId, stateId); const shield = COA.getShield(cultureId, stateId, cultures, states);
return {...baseCoa, shield}; return {...baseCoa, shield};
function defineKinshipToStateEmblem() { function defineKinshipToStateEmblem() {

View file

@ -49,7 +49,7 @@ let landmass: Selection<SVGGElement>;
let texture: Selection<SVGGElement>; let texture: Selection<SVGGElement>;
let terrs: Selection<SVGGElement>; let terrs: Selection<SVGGElement>;
let biomes: Selection<SVGGElement>; let biomes: Selection<SVGGElement>;
let cells: Selection<SVGGElement>; // let cells: Selection<SVGGElement>;
let gridOverlay: Selection<SVGGElement>; let gridOverlay: Selection<SVGGElement>;
let coordinates: Selection<SVGGElement>; let coordinates: Selection<SVGGElement>;
let compass: Selection<SVGGElement>; let compass: Selection<SVGGElement>;