feat(burgs): defineFeatures

This commit is contained in:
Azgaar 2022-09-19 20:11:22 +03:00
parent 2bc008f52c
commit 3b1d47f8ec
6 changed files with 44 additions and 18 deletions

View file

@ -1,5 +1,8 @@
import * as d3 from "d3";
export function drawBurgLabels(burgs: TBurgs) { export function drawBurgLabels(burgs: TBurgs) {
// remove old data // remove old data
const burgLabels = d3.select("#burgLabels");
burgLabels.selectAll("text").remove(); burgLabels.selectAll("text").remove();
const validBurgs = burgs.filter(burg => burg.i && !(burg as IBurg).removed) as IBurg[]; const validBurgs = burgs.filter(burg => burg.i && !(burg as IBurg).removed) as IBurg[];

View file

@ -2,11 +2,11 @@ import * as d3 from "d3";
import {findCell} from "utils/graphUtils"; import {findCell} from "utils/graphUtils";
import {isLake, isState} from "utils/typeUtils"; import {isLake, isState} from "utils/typeUtils";
import {drawPath, drawPoint, drawPolyline} from "utils/debugUtils";
import {round, splitInTwo} from "utils/stringUtils"; import {round, splitInTwo} from "utils/stringUtils";
import {minmax, rn} from "utils/numberUtils"; import {minmax, rn} from "utils/numberUtils";
// increase step to 15 or 30 to make it faster and more horyzontal, decrease to 5 to improve accuracy // increase step to 15 or 30 to make it faster and more horyzontal
// decrease step to 5 to improve accuracy
const ANGLE_STEP = 9; const ANGLE_STEP = 9;
const raycast = precalculateAngles(ANGLE_STEP); const raycast = precalculateAngles(ANGLE_STEP);

View file

@ -32,24 +32,27 @@ export function specifyBurgs(
const burgs = [...capitals, ...towns].map((burgData, index) => { const burgs = [...capitals, ...towns].map((burgData, index) => {
const {cell, culture, capital} = burgData; const {cell, culture, capital} = burgData;
const isCapital = Boolean(capital);
const state = stateIds[cell]; const state = stateIds[cell];
const port = definePort(cell, capital); const port = definePort(cell, isCapital);
const population = definePopulation(cell, capital, port); const population = definePopulation(cell, isCapital, port);
const [x, y] = defineLocation(cell, port); const [x, y] = defineLocation(cell, port);
const type = defineType(cell, port, population); const type = defineType(cell, port, population);
const stateData = stateDataMap.get(state)!; const stateData = stateDataMap.get(state)!;
const coa: ICoa = defineEmblem(culture, port, capital, type, cultures, stateData); const coa: ICoa = defineEmblem(culture, port, isCapital, type, cultures, stateData);
const burg: IBurg = {i: index + 1, ...burgData, state, port, population, x, y, type, coa}; const features = defineFeatures(population, isCapital);
const burg: IBurg = {i: index + 1, ...burgData, state, port, population, x, y, type, coa, ...features};
return burg; return burg;
}); });
TIME && console.timeEnd("specifyBurgs"); TIME && console.timeEnd("specifyBurgs");
return [NO_BURG, ...burgs]; return [NO_BURG, ...burgs];
function definePort(cellId: number, capital: Logical) { function definePort(cellId: number, isCapital: boolean) {
if (!cells.haven[cellId]) return 0; // must be a coastal cell if (!cells.haven[cellId]) return 0; // must be a coastal cell
if (temp[cells.g[cellId]] <= 0) return 0; // temperature must be above zero °C if (temp[cells.g[cellId]] <= 0) return 0; // temperature must be above zero °C
@ -59,17 +62,17 @@ export function specifyBurgs(
if (feature.cells < 2) return 0; // water body must have at least 2 cells if (feature.cells < 2) return 0; // water body must have at least 2 cells
const isSafeHarbor = cells.harbor[cellId] === 1; const isSafeHarbor = cells.harbor[cellId] === 1;
if (!capital && !isSafeHarbor) return 0; // must be a capital or safe harbor if (!isCapital && !isSafeHarbor) return 0; // must be a capital or safe harbor
return havenFeatureId; return havenFeatureId;
} }
// get population in points, where 1 point = 1000 people by default // get population in points, where 1 point = 1000 people by default
function definePopulation(cellId: number, capital: Logical, port: number) { function definePopulation(cellId: number, isCapital: boolean, port: number) {
const basePopulation = cells.s[cellId] / 4; const basePopulation = cells.s[cellId] / 4;
const decimalPart = (cellId % 1000) / 1000; const decimalPart = (cellId % 1000) / 1000;
const capitalMultiplier = capital ? 1.3 : 1; const capitalMultiplier = isCapital ? 1.3 : 1;
const portMultiplier = port ? 1.3 : 1; const portMultiplier = port ? 1.3 : 1;
const randomMultiplier = gauss(1, 1.5, 0.3, 10, 3); const randomMultiplier = gauss(1, 1.5, 0.3, 10, 3);
@ -123,12 +126,12 @@ export function specifyBurgs(
function defineEmblem( function defineEmblem(
cultureId: number, cultureId: number,
port: number, port: number,
capital: Logical, isCapital: boolean,
type: TCultureType, type: TCultureType,
cultures: TCultures, cultures: TCultures,
stateData: TStateData stateData: TStateData
) { ) {
const coaType = capital && P(0.2) ? "Capital" : type === "Generic" ? "City" : type; const coaType = isCapital && P(0.2) ? "Capital" : type === "Generic" ? "City" : type;
const cultureShield = cultures[cultureId].shield; const cultureShield = cultures[cultureId].shield;
if (!stateData) { if (!stateData) {
@ -147,11 +150,29 @@ export function specifyBurgs(
function defineKinshipToStateEmblem() { function defineKinshipToStateEmblem() {
const baseKinship = 0.25; const baseKinship = 0.25;
const capitalModifier = capital ? 0.1 : 0; const capitalModifier = isCapital ? 0.1 : 0;
const portModifier = port ? -0.1 : 0; const portModifier = port ? -0.1 : 0;
const cultureModifier = cultureId === stateCultureId ? 0 : -0.25; const cultureModifier = cultureId === stateCultureId ? 0 : -0.25;
return baseKinship + capitalModifier + portModifier + cultureModifier; return baseKinship + capitalModifier + portModifier + cultureModifier;
} }
} }
// burg features used mainly in MFCG
function defineFeatures(population: number, isCapital: boolean) {
const citadel: Logical = isCapital || (population > 50 && P(0.75)) || P(0.5) ? 1 : 0;
const plaza: Logical =
population > 50 || (population > 30 && P(0.75)) || (population > 10 && P(0.5)) || P(0.25) ? 1 : 0;
const walls: Logical =
isCapital || population > 30 || (population > 20 && P(0.75)) || (population > 10 && P(0.5)) || P(0.2) ? 1 : 0;
const shanty: Logical =
population > 60 || (population > 40 && P(0.75)) || (population > 20 && walls && P(0.4)) ? 1 : 0;
const temple: Logical = population > 50 || (population > 35 && P(0.75)) || (population > 20 && P(0.5)) ? 1 : 0;
return {citadel, plaza, walls, shanty, temple};
}
} }

View file

@ -34,7 +34,7 @@ type TCellsData = Pick<
export function generateCultures(features: TPackFeatures, cells: TCellsData, temp: Int8Array): TCultures { export function generateCultures(features: TPackFeatures, cells: TCellsData, temp: Int8Array): TCultures {
TIME && console.time("generateCultures"); TIME && console.time("generateCultures");
const wildlands: TWilderness = {name: "Wildlands", i: 0, base: 1, origins: [null], shield: "round"}; const wildlands: TWilderness = {i: 0, name: "Wildlands", base: 1, origins: [null], shield: "round"};
const populatedCellIds = cells.i.filter(cellId => cells.pop[cellId] > 0); const populatedCellIds = cells.i.filter(cellId => cells.pop[cellId] > 0);
const maxSuitability = d3.max(cells.s)!; const maxSuitability = d3.max(cells.s)!;

View file

@ -155,8 +155,6 @@ export function createPack(grid: IGrid): IPack {
burg: burgIds burg: burgIds
}); });
// BurgsAndStates.generateProvinces();
// BurgsAndStates.defineBurgFeatures();
// Rivers.specify(); // Rivers.specify();
// const updatedFeatures = generateLakeNames(); // const updatedFeatures = generateLakeNames();

View file

@ -12,8 +12,12 @@ interface IBurg {
coa: ICoa | "string"; coa: ICoa | "string";
capital: Logical; // 1 - capital, 0 - burg capital: Logical; // 1 - capital, 0 - burg
port: number; // port feature id, 0 - not a port port: number; // port feature id, 0 - not a port
shanty?: number; citadel: Logical;
MFCG?: string | number; plaza: Logical;
walls: Logical;
shanty: Logical;
temple: Logical;
MFCG?: string | number; // MFCG link of seed
removed?: boolean; removed?: boolean;
} }