mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 17:51:24 +01:00
feat: split burgs to groups
This commit is contained in:
parent
f51f78a7a6
commit
63898d8fd8
15 changed files with 543 additions and 383 deletions
|
|
@ -17,6 +17,7 @@ window.Burgs = (() => {
|
|||
let quadtree = d3.quadtree();
|
||||
generateCapitals();
|
||||
generateTowns();
|
||||
shiftBurgs();
|
||||
|
||||
pack.burgs = burgs;
|
||||
TIME && console.timeEnd("generateBurgs");
|
||||
|
|
@ -108,137 +109,93 @@ window.Burgs = (() => {
|
|||
spacing *= 0.5;
|
||||
}
|
||||
}
|
||||
|
||||
// define port status and shift ports and burgs on rivers
|
||||
function shiftBurgs() {
|
||||
const {cells, features} = pack;
|
||||
const temp = grid.cells.temp;
|
||||
|
||||
// port is a capital with any harbor OR any burg with a safe harbor
|
||||
const featurePorts = {};
|
||||
for (const burg of burgs) {
|
||||
if (!burg.i || burg.lock) continue;
|
||||
const i = burg.cell;
|
||||
|
||||
const haven = cells.haven[i];
|
||||
const harbor = cells.harbor[i];
|
||||
|
||||
if (haven !== undefined && temp[cells.g[i]] > 0) {
|
||||
const featureId = cells.f[haven];
|
||||
const canBePort = features[featureId].cells > 1 && ((burg.capital && harbor) || harbor === 1);
|
||||
if (canBePort) {
|
||||
if (!featurePorts[featureId]) featurePorts[featureId] = [];
|
||||
featurePorts[featureId].push(burg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// shift ports to the edge of the water body. Only bodies with 2+ ports are considered
|
||||
Object.entries(featurePorts).forEach(([featureId, burgs]) => {
|
||||
if (burgs.length < 2) return;
|
||||
burgs.forEach(burg => {
|
||||
burg.port = featureId;
|
||||
const haven = cells.haven[burg.cell];
|
||||
const [x, y] = getCloseToEdgePoint(burg.cell, haven);
|
||||
burg.x = x;
|
||||
burg.y = y;
|
||||
});
|
||||
});
|
||||
|
||||
// shift non-port river burgs a bit
|
||||
for (const burg of burgs) {
|
||||
if (!burg.i || burg.lock || burg.port || !cells.r[burg.cell]) continue;
|
||||
const cellId = burg.cell;
|
||||
const shift = Math.min(cells.fl[cellId] / 150, 1);
|
||||
burg.x = cellId % 2 ? rn(burg.x + shift, 2) : rn(burg.x - shift, 2);
|
||||
burg.y = cells.r[cellId] % 2 ? rn(burg.y + shift, 2) : rn(burg.y - shift, 2);
|
||||
}
|
||||
|
||||
function getCloseToEdgePoint(cell1, cell2) {
|
||||
const {cells, vertices} = pack;
|
||||
|
||||
const [x0, y0] = cells.p[cell1];
|
||||
const commonVertices = cells.v[cell1].filter(vertex => vertices.c[vertex].some(cell => cell === cell2));
|
||||
const [x1, y1] = vertices.p[commonVertices[0]];
|
||||
const [x2, y2] = vertices.p[commonVertices[1]];
|
||||
const xEdge = (x1 + x2) / 2;
|
||||
const yEdge = (y1 + y2) / 2;
|
||||
|
||||
const x = rn(x0 + 0.95 * (xEdge - x0), 2);
|
||||
const y = rn(y0 + 0.95 * (yEdge - y0), 2);
|
||||
|
||||
return [x, y];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const getDefaultGroups = () => [
|
||||
{name: "capitals", active: true, features: {capital: true}, preview: "watabou-city-generator"},
|
||||
{name: "cities", active: true, percentile: 90, preview: "watabou-city-generator"},
|
||||
{
|
||||
name: "forts",
|
||||
active: true,
|
||||
features: {citadel: true, walls: false, plaza: false, port: false},
|
||||
population: [0, 1],
|
||||
preview: null
|
||||
},
|
||||
{
|
||||
name: "monasteries",
|
||||
active: true,
|
||||
features: {temple: true, walls: false, plaza: false, port: false},
|
||||
population: [0, 1],
|
||||
preview: null
|
||||
},
|
||||
{
|
||||
name: "caravanserais",
|
||||
active: true,
|
||||
features: {port: false},
|
||||
population: [0, 1],
|
||||
biomes: [1, 2, 3],
|
||||
preview: null
|
||||
},
|
||||
{
|
||||
name: "trading posts",
|
||||
active: true,
|
||||
features: {plaza: true},
|
||||
population: [0, 1],
|
||||
biomes: [1, 2, 3],
|
||||
preview: null
|
||||
},
|
||||
{name: "villages", active: true, population: [0.1, 2], preview: "watabou-village-generator"},
|
||||
{
|
||||
name: "hamlets",
|
||||
active: true,
|
||||
features: {plaza: true, walls: false, plaza: false},
|
||||
population: [0, 0.1],
|
||||
preview: "watabou-village-generator"
|
||||
},
|
||||
{name: "towns", active: true, isDefault: true, preview: "watabou-city-generator"}
|
||||
];
|
||||
|
||||
// define burg coordinates, coa, port status and define details
|
||||
const specifyBurgs = () => {
|
||||
const specify = () => {
|
||||
TIME && console.time("specifyBurgs");
|
||||
const {cells, features} = pack;
|
||||
const temp = grid.cells.temp;
|
||||
|
||||
for (const burg of pack.burgs) {
|
||||
if (!burg.i || burg.lock) continue;
|
||||
const i = burg.cell;
|
||||
pack.burgs.forEach(burg => {
|
||||
if (!burg.i || burg.removed || burg.lock) return;
|
||||
definePopulation(burg);
|
||||
defineEmblem(burg);
|
||||
defineFeatures(burg);
|
||||
});
|
||||
|
||||
// asign port status to some coastline burgs with temp > 0 °C
|
||||
const haven = cells.haven[i];
|
||||
if (haven && temp[cells.g[i]] > 0) {
|
||||
const f = cells.f[haven]; // water body id
|
||||
// port is a capital with any harbor OR town with good harbor
|
||||
const port = features[f].cells > 1 && ((burg.capital && cells.harbor[i]) || cells.harbor[i] === 1);
|
||||
burg.port = port ? f : 0; // port is defined by water body id it lays on
|
||||
} else burg.port = 0;
|
||||
const populations = pack.burgs
|
||||
.filter(b => b.i && !b.removed)
|
||||
.map(b => b.population)
|
||||
.sort((a, b) => a - b); // ascending
|
||||
|
||||
// define burg population (keep urbanization at about 10% rate)
|
||||
burg.population = rn(Math.max(cells.s[i] / 8 + burg.i / 1000 + (i % 100) / 1000, 0.1), 3);
|
||||
if (burg.capital) burg.population = rn(burg.population * 1.3, 3); // increase capital population
|
||||
|
||||
if (burg.port) {
|
||||
burg.population = burg.population * 1.3; // increase port population
|
||||
const [x, y] = getCloseToEdgePoint(i, haven);
|
||||
burg.x = x;
|
||||
burg.y = y;
|
||||
}
|
||||
|
||||
// add random factor
|
||||
burg.population = rn(burg.population * gauss(2, 3, 0.6, 20, 3), 3);
|
||||
|
||||
// shift burgs on rivers semi-randomly and just a bit
|
||||
if (!burg.port && cells.r[i]) {
|
||||
const shift = Math.min(cells.fl[i] / 150, 1);
|
||||
if (i % 2) burg.x = rn(burg.x + shift, 2);
|
||||
else burg.x = rn(burg.x - shift, 2);
|
||||
if (cells.r[i] % 2) burg.y = rn(burg.y + shift, 2);
|
||||
else burg.y = rn(burg.y - shift, 2);
|
||||
}
|
||||
|
||||
// define emblem
|
||||
const state = pack.states[burg.state];
|
||||
const stateCOA = state.coa;
|
||||
let kinship = 0.25;
|
||||
if (burg.capital) kinship += 0.1;
|
||||
else if (burg.port) kinship -= 0.1;
|
||||
if (burg.culture !== state.culture) kinship -= 0.25;
|
||||
burg.type = getType(i, burg.port);
|
||||
const type = burg.capital && P(0.2) ? "Capital" : burg.type === "Generic" ? "City" : burg.type;
|
||||
burg.coa = COA.generate(stateCOA, kinship, null, type);
|
||||
burg.coa.shield = COA.getShield(burg.culture, burg.state);
|
||||
}
|
||||
|
||||
// de-assign port status if it's the only one on feature
|
||||
const ports = pack.burgs.filter(b => !b.removed && b.port > 0);
|
||||
for (const f of features) {
|
||||
if (!f.i || f.land || f.border) continue;
|
||||
const featurePorts = ports.filter(b => b.port === f.i);
|
||||
if (featurePorts.length === 1) featurePorts[0].port = 0;
|
||||
}
|
||||
|
||||
pack.burgs.filter(b => b.i && !b.removed && !b.lock).forEach(defineBurgFeatures);
|
||||
pack.burgs.forEach(burg => {
|
||||
if (!burg.i || burg.removed || burg.lock) return;
|
||||
defineGroup(burg, populations);
|
||||
});
|
||||
|
||||
TIME && console.timeEnd("specifyBurgs");
|
||||
};
|
||||
|
||||
function getCloseToEdgePoint(cell1, cell2) {
|
||||
const {cells, vertices} = pack;
|
||||
|
||||
const [x0, y0] = cells.p[cell1];
|
||||
|
||||
const commonVertices = cells.v[cell1].filter(vertex => vertices.c[vertex].some(cell => cell === cell2));
|
||||
const [x1, y1] = vertices.p[commonVertices[0]];
|
||||
const [x2, y2] = vertices.p[commonVertices[1]];
|
||||
const xEdge = (x1 + x2) / 2;
|
||||
const yEdge = (y1 + y2) / 2;
|
||||
|
||||
const x = rn(x0 + 0.95 * (xEdge - x0), 2);
|
||||
const y = rn(y0 + 0.95 * (yEdge - y0), 2);
|
||||
|
||||
return [x, y];
|
||||
}
|
||||
|
||||
const getType = (cellId, port) => {
|
||||
const {cells, features} = pack;
|
||||
|
||||
|
|
@ -261,19 +218,180 @@ window.Burgs = (() => {
|
|||
return "Generic";
|
||||
};
|
||||
|
||||
const defineBurgFeatures = burg => {
|
||||
const {cells, states} = pack;
|
||||
function definePopulation(burg) {
|
||||
const cellId = burg.cell;
|
||||
let population = pack.cells.s[cellId] / 5;
|
||||
if (burg.capital) population *= 1.5;
|
||||
const connectivityRate = Routes.getConnectivityRate(cellId);
|
||||
if (connectivityRate) population *= connectivityRate;
|
||||
population *= gauss(1, 1, 0.25, 4, 5); // randomize
|
||||
population += ((burg.i % 100) - (cellId % 100)) / 1000; // unround
|
||||
burg.population = rn(Math.max(population, 0.01), 3);
|
||||
}
|
||||
|
||||
function defineEmblem(burg) {
|
||||
burg.type = getType(burg.cell, burg.port);
|
||||
|
||||
const state = pack.states[burg.state];
|
||||
const stateCOA = state.coa;
|
||||
|
||||
let kinship = 0.25;
|
||||
if (burg.capital) kinship += 0.1;
|
||||
else if (burg.port) kinship -= 0.1;
|
||||
if (burg.culture !== state.culture) kinship -= 0.25;
|
||||
|
||||
const type = burg.capital && P(0.2) ? "Capital" : burg.type === "Generic" ? "City" : burg.type;
|
||||
burg.coa = COA.generate(stateCOA, kinship, null, type);
|
||||
burg.coa.shield = COA.getShield(burg.culture, burg.state);
|
||||
}
|
||||
|
||||
function defineFeatures(burg) {
|
||||
const pop = burg.population;
|
||||
burg.citadel = Number(burg.capital || (pop > 50 && P(0.75)) || (pop > 15 && P(0.5)) || P(0.1));
|
||||
burg.plaza = Number(pop > 20 || (pop > 10 && P(0.8)) || (pop > 4 && P(0.7)) || P(0.6));
|
||||
burg.plaza = Number(
|
||||
Routes.isCrossroad(burg.cell) || (Routes.hasRoad(burg.cell) && P(0.7)) || pop > 20 || (pop > 10 && P(0.8))
|
||||
);
|
||||
burg.walls = Number(burg.capital || pop > 30 || (pop > 20 && P(0.75)) || (pop > 10 && P(0.5)) || P(0.1));
|
||||
burg.shanty = Number(pop > 60 || (pop > 40 && P(0.75)) || (pop > 20 && burg.walls && P(0.4)));
|
||||
const religion = cells.religion[burg.cell];
|
||||
const theocracy = states[burg.state].form === "Theocracy";
|
||||
const religion = pack.cells.religion[burg.cell];
|
||||
const theocracy = pack.states[burg.state].form === "Theocracy";
|
||||
burg.temple = Number(
|
||||
(religion && theocracy && P(0.5)) || pop > 50 || (pop > 35 && P(0.75)) || (pop > 20 && P(0.5))
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
return {generate, getDefaultGroups, specifyBurgs, getType, defineBurgFeatures};
|
||||
const getDefaultGroups = () => [
|
||||
{name: "capitals", active: true, features: {capital: true}, preview: "watabou-city-generator"},
|
||||
{name: "cities", active: true, percentile: 90, population: [5, Infinity], preview: "watabou-city-generator"},
|
||||
{
|
||||
name: "forts",
|
||||
active: true,
|
||||
features: {citadel: true, walls: false, plaza: false, port: false},
|
||||
population: [0, 1],
|
||||
preview: null
|
||||
},
|
||||
{
|
||||
name: "monasteries",
|
||||
active: true,
|
||||
features: {temple: true, walls: false, plaza: false, port: false},
|
||||
population: [0, 0.8],
|
||||
preview: null
|
||||
},
|
||||
{
|
||||
name: "caravanserais",
|
||||
active: true,
|
||||
features: {port: false, plaza: true},
|
||||
population: [0, 0.8],
|
||||
biomes: [1, 2, 3],
|
||||
preview: null
|
||||
},
|
||||
{
|
||||
name: "trading_posts",
|
||||
active: true,
|
||||
features: {plaza: true},
|
||||
population: [0, 0.8],
|
||||
biomes: [5, 6, 7, 8, 9, 10, 11, 12],
|
||||
preview: null
|
||||
},
|
||||
{
|
||||
name: "villages",
|
||||
active: true,
|
||||
population: [0.1, 2],
|
||||
features: {walls: false},
|
||||
preview: "watabou-village-generator"
|
||||
},
|
||||
{
|
||||
name: "hamlets",
|
||||
active: true,
|
||||
features: {walls: false, plaza: false},
|
||||
population: [0, 0.1],
|
||||
preview: "watabou-village-generator"
|
||||
},
|
||||
{name: "towns", active: true, isDefault: true, preview: "watabou-city-generator"}
|
||||
];
|
||||
|
||||
function defineGroup(burg, populations) {
|
||||
for (const group of options.burgs.groups) {
|
||||
if (!group.active) continue;
|
||||
|
||||
if (group.population) {
|
||||
const [min, max] = group.population;
|
||||
const isFit = burg.population >= min && burg.population <= max;
|
||||
if (!isFit) continue;
|
||||
}
|
||||
|
||||
if (group.features) {
|
||||
const isFit = Object.entries(group.features).every(([feature, value]) => Boolean(burg[feature]) === value);
|
||||
if (!isFit) continue;
|
||||
}
|
||||
|
||||
if (group.biomes) {
|
||||
const isFit = group.biomes.includes(pack.cells.biome[burg.cell]);
|
||||
if (!isFit) continue;
|
||||
}
|
||||
|
||||
if (group.percentile) {
|
||||
const index = populations.indexOf(burg.population);
|
||||
const isFit = index >= Math.floor((populations.length * group.percentile) / 100);
|
||||
if (!isFit) continue;
|
||||
}
|
||||
|
||||
// apply fitting or default group
|
||||
burg.group = group.name;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
function add([x, y]) {
|
||||
const {cells} = pack;
|
||||
|
||||
const burgId = pack.burgs.length;
|
||||
const cellId = findCell(x, y);
|
||||
const culture = cells.culture[cellId];
|
||||
const name = Names.getCulture(culture);
|
||||
const state = cells.state[cellId];
|
||||
const feature = cells.f[cellId];
|
||||
|
||||
const burg = {
|
||||
cell: cellId,
|
||||
x,
|
||||
y,
|
||||
i: burgId,
|
||||
state,
|
||||
culture,
|
||||
name,
|
||||
feature,
|
||||
capital: 0,
|
||||
port: 0
|
||||
};
|
||||
definePopulation(burg);
|
||||
defineEmblem(burg);
|
||||
defineFeatures(burg);
|
||||
|
||||
const populations = pack.burgs
|
||||
.filter(b => b.i && !b.removed)
|
||||
.map(b => b.population)
|
||||
.sort((a, b) => a - b); // ascending
|
||||
defineGroup(burg, populations);
|
||||
|
||||
pack.burgs.push(burg);
|
||||
cells.burg[cellId] = burgId;
|
||||
|
||||
const newRoute = Routes.connect(cellId);
|
||||
if (newRoute && layerIsOn("toggleRoutes")) {
|
||||
const path = Routes.getPath(newRoute);
|
||||
routes
|
||||
.select("#" + newRoute.group)
|
||||
.append("path")
|
||||
.attr("d", path)
|
||||
.attr("id", "route" + newRoute.i);
|
||||
}
|
||||
|
||||
drawBurgIcon(burg);
|
||||
drawBurgLabel(burg);
|
||||
|
||||
return burgId;
|
||||
}
|
||||
|
||||
return {generate, getDefaultGroups, specify, getType, add};
|
||||
})();
|
||||
|
|
|
|||
|
|
@ -968,8 +968,9 @@ export function resolveVersionConflicts(mapVersion) {
|
|||
// v1.106.0 change burg groups and added customizable icons
|
||||
icons.selectAll("circle, use").remove();
|
||||
|
||||
const groups = Array.from(document.querySelectorAll("#burgIcons > g")).map(g => g.id);
|
||||
options.burgs = {
|
||||
groups: Burgs.getDefaultGroups()
|
||||
groups: groups.map(name => ({name, active: true, preview: null}))
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1184,7 +1184,7 @@ function addState() {
|
|||
if (burg && burgs[burg].capital)
|
||||
return tip("Existing capital cannot be selected as a new state capital! Select other cell", false, "error");
|
||||
|
||||
if (!burg) burg = addBurg(point); // add new burg
|
||||
if (!burg) burg = Burgs.add(point);
|
||||
|
||||
const oldState = cells.state[center];
|
||||
const newState = states.length;
|
||||
|
|
|
|||
|
|
@ -5,65 +5,47 @@ function drawBurgIcons() {
|
|||
|
||||
icons.selectAll("circle, use").remove(); // cleanup
|
||||
|
||||
// capitals
|
||||
const capitals = pack.burgs.filter(b => b.capital && !b.removed);
|
||||
const capitalIcons = burgIcons.select("#cities");
|
||||
const capitalIcon = capitalIcons.attr("data-icon") || "#icon-circle";
|
||||
const capitalAnchors = anchors.selectAll("#cities");
|
||||
const capitalAnchorsSize = capitalAnchors.attr("size") || 2;
|
||||
for (const {name} of options.burgs.groups) {
|
||||
const burgsInGroup = pack.burgs.filter(b => b.group === name && !b.removed);
|
||||
if (!burgsInGroup.length) continue;
|
||||
|
||||
capitalIcons
|
||||
.selectAll("use")
|
||||
.data(capitals)
|
||||
.enter()
|
||||
.append("use")
|
||||
.attr("id", d => "burg" + d.i)
|
||||
.attr("href", capitalIcon)
|
||||
.attr("data-id", d => d.i)
|
||||
.attr("x", d => d.x)
|
||||
.attr("y", d => d.y);
|
||||
const g = burgIcons.select("#" + name);
|
||||
if (g.empty()) continue;
|
||||
|
||||
capitalAnchors
|
||||
.selectAll("use")
|
||||
.data(capitals.filter(c => c.port))
|
||||
.enter()
|
||||
.append("use")
|
||||
.attr("xlink:href", "#icon-anchor")
|
||||
.attr("data-id", d => d.i)
|
||||
.attr("x", d => rn(d.x - capitalAnchorsSize * 0.47, 2))
|
||||
.attr("y", d => rn(d.y - capitalAnchorsSize * 0.47, 2))
|
||||
.attr("width", capitalAnchorsSize)
|
||||
.attr("height", capitalAnchorsSize);
|
||||
const icon = g.attr("data-icon") || "#icon-circle";
|
||||
g.selectAll("use")
|
||||
.data(burgsInGroup)
|
||||
.enter()
|
||||
.append("use")
|
||||
.attr("href", icon)
|
||||
.attr("id", d => "burg" + d.i)
|
||||
.attr("data-id", d => d.i)
|
||||
.attr("x", d => d.x)
|
||||
.attr("y", d => d.y);
|
||||
|
||||
// towns
|
||||
const towns = pack.burgs.filter(b => b.i && !b.capital && !b.removed);
|
||||
const townIcons = burgIcons.select("#towns");
|
||||
const townIcon = townIcons.attr("data-icon") || "#icon-circle";
|
||||
const townsAnchors = anchors.selectAll("#towns");
|
||||
const townsAnchorsSize = townsAnchors.attr("size") || 1;
|
||||
|
||||
townIcons
|
||||
.selectAll("use")
|
||||
.data(towns)
|
||||
.enter()
|
||||
.append("use")
|
||||
.attr("id", d => "burg" + d.i)
|
||||
.attr("href", townIcon)
|
||||
.attr("data-id", d => d.i)
|
||||
.attr("x", d => d.x)
|
||||
.attr("y", d => d.y);
|
||||
|
||||
townsAnchors
|
||||
.selectAll("use")
|
||||
.data(towns.filter(c => c.port))
|
||||
.enter()
|
||||
.append("use")
|
||||
.attr("xlink:href", "#icon-anchor")
|
||||
.attr("data-id", d => d.i)
|
||||
.attr("x", d => rn(d.x - townsAnchorsSize * 0.47, 2))
|
||||
.attr("y", d => rn(d.y - townsAnchorsSize * 0.47, 2))
|
||||
.attr("width", townsAnchorsSize)
|
||||
.attr("height", townsAnchorsSize);
|
||||
// capitalAnchors
|
||||
// .selectAll("use")
|
||||
// .data(capitals.filter(c => c.port))
|
||||
// .enter()
|
||||
// .append("use")
|
||||
// .attr("xlink:href", "#icon-anchor")
|
||||
// .attr("data-id", d => d.i)
|
||||
// .attr("x", d => rn(d.x - capitalAnchorsSize * 0.47, 2))
|
||||
// .attr("y", d => rn(d.y - capitalAnchorsSize * 0.47, 2))
|
||||
// .attr("width", capitalAnchorsSize)
|
||||
// .attr("height", capitalAnchorsSize);
|
||||
}
|
||||
|
||||
TIME && console.timeEnd("drawBurgIcons");
|
||||
}
|
||||
|
||||
function drawBurgIcon(burg) {
|
||||
burgIcons
|
||||
.select("#" + burg.group)
|
||||
.append("use")
|
||||
.attr("href", "#icon-circle")
|
||||
.attr("id", "burg" + burg.i)
|
||||
.attr("data-id", burg.i)
|
||||
.attr("x", burg.x)
|
||||
.attr("y", burg.y);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,35 +5,37 @@ function drawBurgLabels() {
|
|||
|
||||
burgLabels.selectAll("text").remove(); // cleanup
|
||||
|
||||
const capitals = pack.burgs.filter(b => b.capital && !b.removed);
|
||||
const capitalSize = burgIcons.select("#cities").attr("size") || 1;
|
||||
burgLabels
|
||||
.select("#cities")
|
||||
.selectAll("text")
|
||||
.data(capitals)
|
||||
.enter()
|
||||
.append("text")
|
||||
.attr("id", d => "burgLabel" + d.i)
|
||||
.attr("data-id", d => d.i)
|
||||
.attr("x", d => d.x)
|
||||
.attr("y", d => d.y)
|
||||
.attr("dy", `${capitalSize * -1.5}px`)
|
||||
.text(d => d.name);
|
||||
for (const {name} of options.burgs.groups) {
|
||||
const burgsInGroup = pack.burgs.filter(b => b.group === name && !b.removed);
|
||||
if (!burgsInGroup.length) continue;
|
||||
|
||||
const towns = pack.burgs.filter(b => b.i && !b.capital && !b.removed);
|
||||
const townSize = burgIcons.select("#towns").attr("size") || 0.5;
|
||||
burgLabels
|
||||
.select("#towns")
|
||||
.selectAll("text")
|
||||
.data(towns)
|
||||
.enter()
|
||||
.append("text")
|
||||
.attr("id", d => "burgLabel" + d.i)
|
||||
.attr("data-id", d => d.i)
|
||||
.attr("x", d => d.x)
|
||||
.attr("y", d => d.y)
|
||||
.attr("dy", `${townSize * -2}px`)
|
||||
.text(d => d.name);
|
||||
const labelGroup = burgLabels.select("#" + name);
|
||||
if (labelGroup.empty()) continue;
|
||||
|
||||
labelGroup
|
||||
.selectAll("text")
|
||||
.data(burgsInGroup)
|
||||
.enter()
|
||||
.append("text")
|
||||
.attr("id", d => "burgLabel" + d.i)
|
||||
.attr("data-id", d => d.i)
|
||||
.attr("x", d => d.x)
|
||||
.attr("y", d => d.y)
|
||||
.attr("dy", "-0.4em")
|
||||
.text(d => d.name);
|
||||
}
|
||||
|
||||
TIME && console.timeEnd("drawBurgLabels");
|
||||
}
|
||||
|
||||
function drawBurgLabel(burg) {
|
||||
burgLabels
|
||||
.select("#" + burg.group)
|
||||
.append("text")
|
||||
.attr("id", "burgLabel" + burg.i)
|
||||
.attr("data-id", burg.i)
|
||||
.attr("x", burg.x)
|
||||
.attr("y", burg.y)
|
||||
.attr("dy", "-0.4em")
|
||||
.text(burg.name);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -537,6 +537,26 @@ window.Routes = (function () {
|
|||
return roadConnections.length > 2;
|
||||
}
|
||||
|
||||
const connectivityRates = {
|
||||
roads: 0.2,
|
||||
trails: 0.1,
|
||||
searoutes: 0.2,
|
||||
default: 0.1
|
||||
};
|
||||
|
||||
function getConnectivityRate(cellId) {
|
||||
const connections = pack.cells.routes[cellId];
|
||||
if (!connections) return 0;
|
||||
|
||||
const connectivity = Object.values(connections).reduce((acc, routeId) => {
|
||||
const route = pack.routes.find(route => route.i === routeId);
|
||||
const rate = connectivityRates[route.group] || connectivityRates.default;
|
||||
return acc + rate;
|
||||
}, 0.8);
|
||||
|
||||
return connectivity;
|
||||
}
|
||||
|
||||
// name generator data
|
||||
const models = {
|
||||
roads: {burg_suffix: 3, prefix_suffix: 6, the_descriptor_prefix_suffix: 2, the_descriptor_burg_suffix: 1},
|
||||
|
|
@ -749,6 +769,7 @@ window.Routes = (function () {
|
|||
getRoute,
|
||||
hasRoad,
|
||||
isCrossroad,
|
||||
getConnectivityRate,
|
||||
generateName,
|
||||
getPath,
|
||||
getLength,
|
||||
|
|
|
|||
|
|
@ -287,7 +287,7 @@ function overviewBurgs(settings = {stateId: null, cultureId: null}) {
|
|||
if (pack.cells.burg[cell])
|
||||
return tip("There is already a burg in this cell. Please select a free cell", false, "error");
|
||||
|
||||
addBurg(point); // add new burg
|
||||
Burgs.add(point); // add new burg
|
||||
|
||||
if (d3.event.shiftKey === false) {
|
||||
exitAddBurgMode();
|
||||
|
|
|
|||
|
|
@ -128,78 +128,6 @@ function applySorting(headers) {
|
|||
.forEach(line => list.appendChild(line));
|
||||
}
|
||||
|
||||
function addBurg(point) {
|
||||
const {cells, states} = pack;
|
||||
const x = rn(point[0], 2);
|
||||
const y = rn(point[1], 2);
|
||||
|
||||
const cellId = findCell(x, y);
|
||||
const i = pack.burgs.length;
|
||||
const culture = cells.culture[cellId];
|
||||
const name = Names.getCulture(culture);
|
||||
const state = cells.state[cellId];
|
||||
const feature = cells.f[cellId];
|
||||
|
||||
const population = Math.max(cells.s[cellId] / 3 + i / 1000 + (cellId % 100) / 1000, 0.1);
|
||||
const type = Burgs.getType(cellId, false);
|
||||
|
||||
// generate emblem
|
||||
const coa = COA.generate(states[state].coa, 0.25, null, type);
|
||||
coa.shield = COA.getShield(culture, state);
|
||||
COArenderer.add("burg", i, coa, x, y);
|
||||
|
||||
const burg = {
|
||||
name,
|
||||
cell: cellId,
|
||||
x,
|
||||
y,
|
||||
state,
|
||||
i,
|
||||
culture,
|
||||
feature,
|
||||
capital: 0,
|
||||
port: 0,
|
||||
temple: 0,
|
||||
population,
|
||||
coa,
|
||||
type
|
||||
};
|
||||
pack.burgs.push(burg);
|
||||
cells.burg[cellId] = i;
|
||||
|
||||
const townSize = burgIcons.select("#towns").attr("size") || 0.5;
|
||||
burgIcons
|
||||
.select("#towns")
|
||||
.append("circle")
|
||||
.attr("id", "burg" + i)
|
||||
.attr("data-id", i)
|
||||
.attr("cx", x)
|
||||
.attr("cy", y)
|
||||
.attr("r", townSize);
|
||||
burgLabels
|
||||
.select("#towns")
|
||||
.append("text")
|
||||
.attr("id", "burgLabel" + i)
|
||||
.attr("data-id", i)
|
||||
.attr("x", x)
|
||||
.attr("y", y)
|
||||
.attr("dy", `${townSize * -1.5}px`)
|
||||
.text(name);
|
||||
|
||||
Burgs.defineBurgFeatures(burg);
|
||||
|
||||
const newRoute = Routes.connect(cellId);
|
||||
if (newRoute && layerIsOn("toggleRoutes")) {
|
||||
routes
|
||||
.select("#" + newRoute.group)
|
||||
.append("path")
|
||||
.attr("d", Routes.getPath(newRoute))
|
||||
.attr("id", "route" + newRoute.i);
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
function moveBurgToGroup(id, g) {
|
||||
const label = document.querySelector("#burgLabels [data-id='" + id + "']");
|
||||
const icon = document.querySelector("#burgIcons [data-id='" + id + "']");
|
||||
|
|
|
|||
|
|
@ -250,7 +250,7 @@ function editHeightmap(options) {
|
|||
States.defineStateForms();
|
||||
Provinces.generate();
|
||||
Provinces.getPoles();
|
||||
Burgs.specifyBurgs();
|
||||
Burgs.specify();
|
||||
|
||||
Rivers.specify();
|
||||
Features.specify();
|
||||
|
|
|
|||
|
|
@ -342,8 +342,8 @@ function addStylePreset() {
|
|||
"stroke-dasharray",
|
||||
"stroke-linecap"
|
||||
];
|
||||
options.burgs.groups.forEach(group => {
|
||||
attributes[`#burgIcons > g[data-name='${group}']`] = burgIconsAttributes;
|
||||
options.burgs.groups.forEach(({name}) => {
|
||||
attributes[`#burgIcons > g.${name}`] = burgIconsAttributes;
|
||||
});
|
||||
|
||||
for (const selector in attributes) {
|
||||
|
|
|
|||
|
|
@ -1125,39 +1125,6 @@ styleScaleBar.on("input", function (event) {
|
|||
});
|
||||
|
||||
function updateElements() {
|
||||
// burgIcons to desired size
|
||||
burgIcons.selectAll("g").each(function () {
|
||||
const size = +this.getAttribute("size");
|
||||
d3.select(this)
|
||||
.selectAll("circle")
|
||||
.each(function () {
|
||||
this.setAttribute("r", size);
|
||||
});
|
||||
burgLabels
|
||||
.select("g#" + this.id)
|
||||
.selectAll("text")
|
||||
.each(function () {
|
||||
this.setAttribute("dy", `${size * -1.5}px`);
|
||||
});
|
||||
});
|
||||
|
||||
// anchor icons to desired size
|
||||
anchors.selectAll("g").each(function (d) {
|
||||
const size = +this.getAttribute("size");
|
||||
d3.select(this)
|
||||
.selectAll("use")
|
||||
.each(function () {
|
||||
const id = +this.dataset.id;
|
||||
const x = pack.burgs[id].x,
|
||||
y = pack.burgs[id].y;
|
||||
this.setAttribute("x", rn(x - size * 0.47, 2));
|
||||
this.setAttribute("y", rn(y - size * 0.47, 2));
|
||||
this.setAttribute("width", size);
|
||||
this.setAttribute("height", size);
|
||||
});
|
||||
});
|
||||
|
||||
// redraw elements
|
||||
if (layerIsOn("toggleHeight")) drawHeightmap();
|
||||
if (legend.selectAll("*").size() && window.redrawLegend) redrawLegend();
|
||||
oceanLayers.selectAll("path").remove();
|
||||
|
|
|
|||
|
|
@ -431,7 +431,7 @@ function regenerateBurgs() {
|
|||
.filter(s => s.i && !s.removed && !s.capital)
|
||||
.forEach(s => {
|
||||
const [x, y] = cells.p[s.center];
|
||||
const burgId = addBurg([x, y]);
|
||||
const burgId = Burgs.add([x, y]);
|
||||
s.capital = burgId;
|
||||
s.center = pack.burgs[burgId].cell;
|
||||
pack.burgs[burgId].capital = 1;
|
||||
|
|
@ -443,7 +443,7 @@ function regenerateBurgs() {
|
|||
if (f.port) f.port = 0; // reset features ports counter
|
||||
});
|
||||
|
||||
Burgs.specifyBurgs();
|
||||
Burgs.specify();
|
||||
regenerateRoutes();
|
||||
|
||||
drawBurgIcons();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue