diff --git a/main.js b/main.js
index 7e740baa..7a5ae7a5 100644
--- a/main.js
+++ b/main.js
@@ -1169,15 +1169,26 @@ function reGraph() {
for (const i of gridCells.i) {
const height = gridCells.h[i];
const type = gridCells.t[i];
- if (height < 20 && type !== -1 && type !== -2) continue; // exclude all deep ocean points
- if (type === -2 && (i % 4 === 0 || features[gridCells.f[i]].type === "lake")) continue; // exclude non-coastal lake points
- const [x, y] = points[i];
+ const isOnBorder = gridCells.b[i];
+ // exclude most of ocean points
+ if (height < 20) {
+ const isLake = features[gridCells.f[i]].type === "lake";
+ if (isLake && type !== -1) continue;
+
+ if (type === 0) continue;
+ if (type < -4 && !each(24)(i)) continue;
+ if (type === -4 && !each(12)(i)) continue;
+ if (type === -3 && !each(6)(i)) continue;
+ if (type === -2 && !each(3)(i)) continue;
+ }
+
+ const [x, y] = points[i];
addNewPoint(i, x, y, height);
// add additional points for cells along coast
if (type === 1 || type === -1) {
- if (gridCells.b[i]) continue; // not for near-border cells
+ if (isOnBorder) continue; // not for near-border cells
gridCells.c[i].forEach(function (e) {
if (i > e) return;
if (gridCells.t[e] === type) {
@@ -1402,8 +1413,8 @@ function reMarkFeatures() {
queue[0] = cells.f.findIndex(f => !f); // find unmarked cell
}
- // markupPackLand
- markup(pack.cells, 3, 1, 0);
+ markup(pack.cells, 3, 1, 0); // markupPackLand
+ markup(pack.cells, -2, -1, -10); // markupPackWater
function defineHaven(i) {
const water = cells.c[i].filter(c => cells.h[c] < 20);
diff --git a/modules/dynamic/editors/states-editor.js b/modules/dynamic/editors/states-editor.js
index 70a45017..83480f17 100644
--- a/modules/dynamic/editors/states-editor.js
+++ b/modules/dynamic/editors/states-editor.js
@@ -966,7 +966,7 @@ function dragStateBrush() {
const p = d3.mouse(this);
moveCircle(p[0], p[1], r);
- const found = r > 5 ? findAll(p[0], p[1], r) : [findCell(p[0], p[1], r)];
+ const found = r > 5 ? findAll(p[0], p[1], r) : [findCell(p[0], p[1])];
const selection = found.filter(isLand);
if (selection) changeStateForSelection(selection);
});
diff --git a/modules/routes-generator.js b/modules/routes-generator.js
index 84c88eb4..44b33f66 100644
--- a/modules/routes-generator.js
+++ b/modules/routes-generator.js
@@ -7,7 +7,6 @@ window.Routes = (function () {
function generate() {
const {cells, burgs} = pack;
-
const cellRoutes = new Uint8Array(cells.h.length);
const {capitalsByFeature, burgsByFeature, portsByFeature} = sortBurgsByFeature(burgs);
@@ -53,7 +52,7 @@ window.Routes = (function () {
const start = featureCapitals[fromId].cell;
const exit = featureCapitals[toId].cell;
- const segments = findPathSegments({isWater: false, cellRoutes, connections, start, exit});
+ const segments = findPathSegments({isWater: false, connections, start, exit});
for (const segment of segments) {
addConnections(segment, ROUTES.MAIN_ROAD);
mainRoads.push({feature: Number(key), cells: segment});
@@ -67,7 +66,6 @@ window.Routes = (function () {
function generateTrails() {
TIME && console.time("generateTrails");
-
const trails = [];
for (const [key, featureBurgs] of Object.entries(burgsByFeature)) {
@@ -77,7 +75,7 @@ window.Routes = (function () {
const start = featureBurgs[fromId].cell;
const exit = featureBurgs[toId].cell;
- const segments = findPathSegments({isWater: false, cellRoutes, connections, start, exit});
+ const segments = findPathSegments({isWater: false, connections, start, exit});
for (const segment of segments) {
addConnections(segment, ROUTES.TRAIL);
trails.push({feature: Number(key), cells: segment});
@@ -90,39 +88,43 @@ window.Routes = (function () {
}
function generateSeaRoutes() {
- TIME && console.time("generateSearoutes");
- const mainRoads = [];
+ TIME && console.time("generateSeaRoutes");
+ const seaRoutes = [];
- for (const [key, featurePorts] of Object.entries(portsByFeature)) {
+ for (const [featureId, featurePorts] of Object.entries(portsByFeature)) {
const points = featurePorts.map(burg => [burg.x, burg.y]);
const urquhartEdges = calculateUrquhartEdges(points);
+ console.log(urquhartEdges);
urquhartEdges.forEach(([fromId, toId]) => {
const start = featurePorts[fromId].cell;
const exit = featurePorts[toId].cell;
- const segments = findPathSegments({isWater: true, cellRoutes, connections, start, exit});
+ const segments = findPathSegments({isWater: true, connections, start, exit});
for (const segment of segments) {
addConnections(segment, ROUTES.SEA_ROUTE);
- mainRoads.push({feature: Number(key), cells: segment});
+ seaRoutes.push({feature: Number(featureId), cells: segment});
}
});
}
- TIME && console.timeEnd("generateSearoutes");
- return mainRoads;
+ TIME && console.timeEnd("generateSeaRoutes");
+ return seaRoutes;
}
- function addConnections(segment, roadTypeId) {
+ function addConnections(segment, routeTypeId) {
for (let i = 0; i < segment.length; i++) {
const cellId = segment[i];
const nextCellId = segment[i + 1];
- if (nextCellId) connections.set(`${cellId}-${nextCellId}`, true);
- if (!cellRoutes[cellId]) cellRoutes[cellId] = roadTypeId;
+ if (nextCellId) {
+ connections.set(`${cellId}-${nextCellId}`, true);
+ connections.set(`${nextCellId}-${cellId}`, true);
+ }
+ if (!cellRoutes[cellId]) cellRoutes[cellId] = routeTypeId;
}
}
- function findPathSegments({isWater, cellRoutes, connections, start, exit}) {
- const from = findPath(isWater, cellRoutes, start, exit, connections);
+ function findPathSegments({isWater, connections, start, exit}) {
+ const from = findPath(isWater, start, exit, connections);
if (!from) return [];
const pathCells = restorePath(start, exit, from);
@@ -149,7 +151,17 @@ window.Routes = (function () {
}
}
- function findPath(isWater, cellRoutes, start, exit, connections) {
+ const MIN_PASSABLE_SEA_TEMP = -4;
+
+ const TYPE_MODIFIERS = {
+ "-1": 1, // coastline
+ "-2": 1.8, // sea
+ "-3": 3, // open sea
+ "-4": 5, // ocean
+ default: 8 // far ocean
+ };
+
+ function findPath(isWater, start, exit, connections) {
const {temp} = grid.cells;
const {cells} = pack;
@@ -174,11 +186,11 @@ window.Routes = (function () {
const distanceCost = dist2(cells.p[next], cells.p[neibCellId]);
const habitabilityModifier = 1 + Math.max(100 - habitability, 0) / 1000; // [1, 1.1];
- const heightModifier = 1 + Math.max(cells.h[neibCellId] - 50, 0) / 50; // [1, 2];
- const roadModifier = cellRoutes[neibCellId] ? 1 : 2;
+ const heightModifier = 1 + Math.max(cells.h[neibCellId] - 25, 25) / 25; // [1, 3];
+ const connectionModifier = connections.has(`${next}-${neibCellId}`) ? 1 : 3;
const burgModifier = cells.burg[neibCellId] ? 1 : 2;
- const cellsCost = distanceCost * habitabilityModifier * heightModifier * roadModifier * burgModifier;
+ const cellsCost = distanceCost * habitabilityModifier * heightModifier * connectionModifier * burgModifier;
const totalCost = priority + cellsCost;
if (from[neibCellId] || totalCost >= cost[neibCellId]) continue;
@@ -195,8 +207,6 @@ window.Routes = (function () {
}
function findWaterPath() {
- const MIN_PASSABLE_TEMP = -4;
-
while (queue.length) {
const priority = queue.peekValue();
const next = queue.pop();
@@ -208,15 +218,13 @@ window.Routes = (function () {
}
if (cells.h[neibCellId] >= 20) continue; // ignore land cells
- if (temp[cells.g[neibCellId]] < MIN_PASSABLE_TEMP) continue; // ignore to cold cells
+ if (temp[cells.g[neibCellId]] < MIN_PASSABLE_SEA_TEMP) continue; // ignore too cold cells
const distanceCost = dist2(cells.p[next], cells.p[neibCellId]);
- const typeModifier = Math.abs(cells.t[neibCellId]); // 1 for coastline, 2 for deep ocean, 3 for deeper ocean
- const routeModifier = cellRoutes[neibCellId] ? 1 : 2;
- const connectionModifier =
- connections.has(`${next}-${neibCellId}`) || connections.has(`${neibCellId}-${next}`) ? 1 : 3;
+ const typeModifier = TYPE_MODIFIERS[cells.t[neibCellId]] || TYPE_MODIFIERS.default;
+ const connectionModifier = connections.has(`${next}-${neibCellId}`) ? 1 : 2;
- const cellsCost = distanceCost * typeModifier * routeModifier * connectionModifier;
+ const cellsCost = distanceCost * typeModifier * connectionModifier;
const totalCost = priority + cellsCost;
if (from[neibCellId] || totalCost >= cost[neibCellId]) continue;
diff --git a/modules/ui/biomes-editor.js b/modules/ui/biomes-editor.js
index bcb6c206..8f2400f0 100644
--- a/modules/ui/biomes-editor.js
+++ b/modules/ui/biomes-editor.js
@@ -390,7 +390,7 @@ function editBiomes() {
const p = d3.mouse(this);
moveCircle(p[0], p[1], r);
- const found = r > 5 ? findAll(p[0], p[1], r) : [findCell(p[0], p[1], r)];
+ const found = r > 5 ? findAll(p[0], p[1], r) : [findCell(p[0], p[1])];
const selection = found.filter(isLand);
if (selection) changeBiomeForSelection(selection);
});
diff --git a/modules/ui/heightmap-editor.js b/modules/ui/heightmap-editor.js
index 3a89fe89..c99e4bdd 100644
--- a/modules/ui/heightmap-editor.js
+++ b/modules/ui/heightmap-editor.js
@@ -246,6 +246,7 @@ function editHeightmap(options) {
Cultures.expand();
BurgsAndStates.generate();
+ Routes.generate();
Religions.generate();
BurgsAndStates.defineStateForms();
BurgsAndStates.generateProvinces();
diff --git a/modules/ui/layers.js b/modules/ui/layers.js
index e48afffa..b018ed10 100644
--- a/modules/ui/layers.js
+++ b/modules/ui/layers.js
@@ -1637,7 +1637,6 @@ function toggleRoutes(event) {
function drawRoutes() {
TIME && console.time("drawRoutes");
const {cells, burgs} = pack;
- const lineGen = d3.line();
const SHARP_ANGLE = 135;
const VERY_SHARP_ANGLE = 115;
@@ -1645,10 +1644,11 @@ function drawRoutes() {
const points = adjustBurgPoints(); // mutable array of points
const routePaths = {};
- const lineGenMap = {
+ const lineGen = d3.line();
+ const curves = {
roads: d3.curveCatmullRom.alpha(0.1),
trails: d3.curveCatmullRom.alpha(0.1),
- searoutes: d3.curveBasis,
+ searoutes: d3.curveCatmullRom.alpha(0.5),
default: d3.curveCatmullRom.alpha(0.1)
};
@@ -1656,7 +1656,24 @@ function drawRoutes() {
if (group !== "searoutes") straightenPathAngles(cells); // mutates points
const pathPoints = getPathPoints(cells);
- lineGen.curve(lineGenMap[group] || lineGenMap.default);
+ // TODO: temporary view for searoutes
+ if (group === "searoutes2") {
+ const pathPoints = cells.map(cellId => points[cellId]);
+ const color = getMixedColor("#000000", 0.6);
+ const line = "M" + pathPoints.join("L");
+ pathPoints.forEach(([x, y]) =>
+ debug.append("circle").attr("r", 0.7).attr("cx", x).attr("cy", y).attr("fill", color)
+ );
+ if (!routePaths[group]) routePaths[group] = [];
+ routePaths[group].push(`
Total population: ${l(total)} ⇒ ${l(total)} (100%)
`; + +Total population: ${l(total)} ⇒ ${l( + total + )} (100%)
`; const update = function () { const totalNew = ruralPop.valueAsNumber + urbanPop.valueAsNumber;