mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 17:51:24 +01:00
v1.4.09
This commit is contained in:
parent
bb0251c020
commit
617e8d4306
12 changed files with 86 additions and 163 deletions
|
|
@ -140,46 +140,15 @@
|
|||
// define burg coordinates, port status and define details
|
||||
const specifyBurgs = function() {
|
||||
console.time("specifyBurgs");
|
||||
const cells = pack.cells, vertices = pack.vertices, features = pack.features;
|
||||
|
||||
// separate arctic seas for correct searoutes generation
|
||||
void function checkAccessibility() {
|
||||
const oceanCells = cells.i.filter(i => cells.h[i] < 20 && features[cells.f[i]].type === "ocean");
|
||||
const marked = [];
|
||||
let firstCell = oceanCells.find(i => !marked[i]);
|
||||
|
||||
while (firstCell !== undefined) {
|
||||
const queue = [firstCell];
|
||||
const f = features[cells.f[firstCell]]; // old feature
|
||||
const i = last(features).i+1; // new feature id to assign
|
||||
const biome = cells.biome[firstCell];
|
||||
marked[firstCell] = 1;
|
||||
let cellNumber = 1;
|
||||
|
||||
while (queue.length) {
|
||||
for (const c of cells.c[queue.pop()]) {
|
||||
if (cells.biome[c] !== biome || cells.h[c] >= 20) continue;
|
||||
if (marked[c]) continue;
|
||||
queue.push(c);
|
||||
cells.f[c] = i;
|
||||
marked[c] = 1;
|
||||
cellNumber++;
|
||||
}
|
||||
}
|
||||
|
||||
const group = biome ? "frozen " + f.group : f.group;
|
||||
features.push({i, parent:f.i, land:false, border:f.border, type:"ocean", cells: cellNumber, firstCell, group});
|
||||
firstCell = oceanCells.find(i => !marked[i]);
|
||||
}
|
||||
}()
|
||||
const cells = pack.cells, vertices = pack.vertices, features = pack.features, temp = grid.cells.temp;
|
||||
|
||||
for (const b of pack.burgs) {
|
||||
if (!b.i) continue;
|
||||
const i = b.cell;
|
||||
|
||||
// asign port status
|
||||
// asign port status to some coastline burgs with temp > 0 °C
|
||||
const haven = cells.haven[i];
|
||||
if (haven && cells.biome[haven] === 0) {
|
||||
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 && ((b.capital && cells.harbor[i]) || cells.harbor[i] === 1);
|
||||
|
|
|
|||
|
|
@ -61,52 +61,35 @@
|
|||
|
||||
const getSearoutes = function() {
|
||||
console.time("generateSearoutes");
|
||||
const cells = pack.cells, allPorts = pack.burgs.filter(b => b.port > 0 && !b.removed);
|
||||
const allPorts = pack.burgs.filter(b => b.port > 0 && !b.removed);
|
||||
if (allPorts.length < 2) return [];
|
||||
|
||||
const bodies = new Set(allPorts.map(b => b.port)); // features with ports
|
||||
let paths = []; // array to store path segments
|
||||
const connected = []; // store cell id of connected burgs
|
||||
|
||||
bodies.forEach(function(f) {
|
||||
const ports = allPorts.filter(b => b.port === f);
|
||||
const ports = allPorts.filter(b => b.port === f); // all ports on the same feature
|
||||
if (ports.length < 2) return;
|
||||
const first = ports[0].cell;
|
||||
const farthest = ports[d3.scan(ports, (a, b) => ((b.y - ports[0].y) ** 2 + (b.x - ports[0].x) ** 2) - ((a.y - ports[0].y) ** 2 + (a.x - ports[0].x) ** 2))].cell;
|
||||
|
||||
// directly connect first port with the farthest one on the same island to remove gap
|
||||
void function() {
|
||||
if (!pack.features[f] || pack.features[f].type === "lake") return;
|
||||
const portsOnIsland = ports.filter(b => cells.f[b.cell] === cells.f[first]);
|
||||
if (portsOnIsland.length < 4) return;
|
||||
const opposite = ports[d3.scan(portsOnIsland, (a, b) => ((b.y - ports[0].y) ** 2 + (b.x - ports[0].x) ** 2) - ((a.y - ports[0].y) ** 2 + (a.x - ports[0].x) ** 2))].cell;
|
||||
//debug.append("circle").attr("cx", pack.cells.p[opposite][0]).attr("cy", pack.cells.p[opposite][1]).attr("r", 1);
|
||||
//debug.append("circle").attr("cx", pack.cells.p[first][0]).attr("cy", pack.cells.p[first][1]).attr("fill", "red").attr("r", 1);
|
||||
const [from, exit, passable] = findOceanPath(opposite, first);
|
||||
if (!passable) return;
|
||||
from[first] = cells.haven[first];
|
||||
const path = restorePath(opposite, first, "ocean", from);
|
||||
paths = paths.concat(path);
|
||||
}()
|
||||
for (let s=0; s < ports.length; s++) {
|
||||
const source = ports[s].cell;
|
||||
if (connected[source]) continue;
|
||||
|
||||
// directly connect first port with the farthest one
|
||||
void function() {
|
||||
const [from, exit, passable] = findOceanPath(farthest, first);
|
||||
if (!passable) return;
|
||||
from[first] = cells.haven[first];
|
||||
const path = restorePath(farthest, first, "ocean", from);
|
||||
paths = paths.concat(path);
|
||||
}()
|
||||
for (let t=s+1; t < ports.length; t++) {
|
||||
const target = ports[t].cell;
|
||||
if (connected[target]) continue;
|
||||
|
||||
// indirectly connect first port with all other ports
|
||||
void function() {
|
||||
if (ports.length < 3) return;
|
||||
for (const p of ports) {
|
||||
if (p.cell === first || p.cell === farthest) continue;
|
||||
const [from, exit, passable] = findOceanPath(p.cell, first, true);
|
||||
const [from, exit, passable] = findOceanPath(target, source, true);
|
||||
if (!passable) continue;
|
||||
const path = restorePath(p.cell, exit, "ocean", from);
|
||||
|
||||
const path = restorePath(target, exit, "ocean", from);
|
||||
paths = paths.concat(path);
|
||||
|
||||
connected[source] = 1;
|
||||
connected[target] = 1;
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
|
@ -235,7 +218,7 @@
|
|||
|
||||
// find water paths
|
||||
function findOceanPath(start, exit = null, toRoute = null) {
|
||||
const cells = pack.cells;
|
||||
const cells = pack.cells, temp = grid.cells.temp;
|
||||
const queue = new PriorityQueue({comparator: (a, b) => a.p - b.p});
|
||||
const cost = [], from = [];
|
||||
queue.queue({e: start, p: 0});
|
||||
|
|
@ -247,6 +230,7 @@
|
|||
for (const c of cells.c[n]) {
|
||||
if (c === exit) {from[c] = n; return [from, exit, true];}
|
||||
if (cells.h[c] >= 20) continue; // ignore land cells
|
||||
if (temp[cells.g[c]] <= -5) continue; // ignore cells with term <= -5
|
||||
const dist2 = (cells.p[c][1] - cells.p[n][1]) ** 2 + (cells.p[c][0] - cells.p[n][0]) ** 2;
|
||||
const totalCost = p + (cells.road[c] ? 1 + dist2 / 2 : dist2 + (cells.t[c] ? 1 : 100));
|
||||
|
||||
|
|
|
|||
|
|
@ -832,11 +832,9 @@ function parseLoadedData(data) {
|
|||
if (!markers.selectAll("*").size()) {addMarkers(); turnButtonOn("toggleMarkers");}
|
||||
|
||||
// 1.0 add fogging layer (state focus)
|
||||
fogging = viewbox.insert("g", "#ruler").attr("id", "fogging-cont").attr("mask", "url(#fog)")
|
||||
.append("g").attr("id", "fogging").style("display", "none");
|
||||
fogging = viewbox.insert("g", "#ruler").attr("id", "fogging-cont").attr("mask", "url(#fog)").append("g").attr("id", "fogging").style("display", "none");
|
||||
fogging.append("rect").attr("x", 0).attr("y", 0).attr("width", "100%").attr("height", "100%");
|
||||
defs.append("mask").attr("id", "fog").append("rect").attr("x", 0).attr("y", 0).attr("width", "100%")
|
||||
.attr("height", "100%").attr("fill", "white");
|
||||
defs.append("mask").attr("id", "fog").append("rect").attr("x", 0).attr("y", 0).attr("width", "100%").attr("height", "100%").attr("fill", "white");
|
||||
|
||||
// 1.0 changes states opacity bask to regions level
|
||||
if (statesBody.attr("opacity")) {
|
||||
|
|
|
|||
|
|
@ -527,11 +527,26 @@ function changePickerSpace() {
|
|||
openPicker.updateFill();
|
||||
}
|
||||
|
||||
// remove all fogging
|
||||
function unfog() {
|
||||
defs.select("#fog").selectAll("path").remove();
|
||||
fogging.selectAll("path").remove();
|
||||
fogging.style("display", "none");
|
||||
// add fogging
|
||||
function fog(id, path) {
|
||||
if (defs.select("#fog #"+id).size()) return;
|
||||
const fadeIn = d3.transition().duration(2000).ease(d3.easeSinInOut);
|
||||
if (defs.select("#fog path").size()) {
|
||||
defs.select("#fog").append("path").attr("d", path).attr("id", id).attr("opacity", 0).transition(fadeIn).attr("opacity", 1);
|
||||
} else {
|
||||
defs.select("#fog").append("path").attr("d", path).attr("id", id).attr("opacity", 1);
|
||||
const opacity = fogging.attr("opacity");
|
||||
fogging.style("display", "block").attr("opacity", 0).transition(fadeIn).attr("opacity", opacity);
|
||||
}
|
||||
}
|
||||
|
||||
// remove fogging
|
||||
function unfog(id) {
|
||||
let el = defs.select("#fog #"+id);
|
||||
if (!id || !el.size()) el = defs.select("#fog").selectAll("path");
|
||||
|
||||
el.remove();
|
||||
if (!defs.selectAll("#fog path").size()) fogging.style("display", "none");
|
||||
}
|
||||
|
||||
function getFileName(dataType) {
|
||||
|
|
|
|||
|
|
@ -185,7 +185,6 @@ function editHeightmap() {
|
|||
}
|
||||
|
||||
defineBiomes();
|
||||
|
||||
rankCells();
|
||||
Cultures.generate();
|
||||
Cultures.expand();
|
||||
|
|
@ -354,6 +353,8 @@ function editHeightmap() {
|
|||
if (!b.i || b.removed) continue;
|
||||
b.cell = findBurgCell(b.x, b.y);
|
||||
b.feature = pack.cells.f[b.cell];
|
||||
//if (b.port) b.port = pack.cells.f[pack.cells.haven[b.cell]]; // water body id
|
||||
|
||||
pack.cells.burg[b.cell] = b.i;
|
||||
if (!b.capital && pack.cells.h[b.cell] < 20) removeBurg(b.i);
|
||||
if (b.capital) pack.states[b.state].center = b.cell;
|
||||
|
|
|
|||
|
|
@ -460,6 +460,7 @@ function toggleIce() {
|
|||
if (!layerIsOn("toggleIce")) {
|
||||
turnButtonOn("toggleIce");
|
||||
$('#ice').fadeIn();
|
||||
if (!ice.selectAll("*").size()) drawIce();
|
||||
if (event && isCtrlClick(event)) editStyle("ice");
|
||||
} else {
|
||||
if (event && isCtrlClick(event)) {editStyle("ice"); return;}
|
||||
|
|
@ -473,7 +474,7 @@ function drawIce() {
|
|||
const used = new Uint8Array(cells.i.length);
|
||||
Math.seedrandom(seed);
|
||||
|
||||
const shieldMin = -6; // min temp to form ice shield (glacier)
|
||||
const shieldMin = -6; // max temp to form ice shield (glacier)
|
||||
const icebergMax = 2; // max temp to form an iceberg
|
||||
|
||||
for (const i of grid.cells.i) {
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ function editProvinces() {
|
|||
if (cl.contains("icon-star-empty")) capitalZoomIn(p); else
|
||||
if (cl.contains("icon-flag-empty")) triggerIndependencePromps(p); else
|
||||
if (cl.contains("culturePopulation")) changePopulation(p); else
|
||||
if (cl.contains("icon-pin")) focusOn(p, cl); else
|
||||
if (cl.contains("icon-pin")) toggleFog(p, cl); else
|
||||
if (cl.contains("icon-trash-empty")) removeProvince(p);
|
||||
});
|
||||
|
||||
|
|
@ -282,7 +282,7 @@ function editProvinces() {
|
|||
BurgsAndStates.drawStateLabels([newState, oldState]);
|
||||
|
||||
// remove old province
|
||||
unfocus(p);
|
||||
unfog("focusProvince"+p);
|
||||
if (states[oldState].provinces.includes(p)) states[oldState].provinces.splice(states[oldState].provinces.indexOf(p), 1);
|
||||
provinces[p].removed = true;
|
||||
|
||||
|
|
@ -347,24 +347,10 @@ function editProvinces() {
|
|||
|
||||
}
|
||||
|
||||
function focusOn(p, cl) {
|
||||
const inactive = cl.contains("inactive");
|
||||
function toggleFog(p, cl) {
|
||||
const path = provs.select("#province"+p).attr("d"), id = "focusProvince"+p;
|
||||
cl.contains("inactive") ? fog(id, path) : unfog(id);
|
||||
cl.toggle("inactive");
|
||||
|
||||
if (inactive) {
|
||||
if (defs.select("#fog #focusProvince"+p).size()) return;
|
||||
fogging.style("display", "block");
|
||||
const path = provs.select("#province"+p).attr("d");
|
||||
defs.select("#fog").append("path").attr("d", path).attr("fill", "black").attr("id", "focusProvince"+p);
|
||||
fogging.append("path").attr("d", path).attr("id", "focusProvinceHalo"+p)
|
||||
.attr("fill", "none").attr("stroke", pack.provinces[p].color).attr("filter", "url(#blur5)");
|
||||
} else unfocus(p);
|
||||
}
|
||||
|
||||
function unfocus(p) {
|
||||
defs.select("#focusProvince"+p).remove();
|
||||
fogging.select("#focusProvinceHalo"+p).remove();
|
||||
if (!defs.selectAll("#fog path").size()) fogging.style("display", "none"); // all items are de-focused
|
||||
}
|
||||
|
||||
function removeProvince(p) {
|
||||
|
|
@ -377,7 +363,7 @@ function editProvinces() {
|
|||
const state = pack.provinces[p].state;
|
||||
if (pack.states[state].provinces.includes(p)) pack.states[state].provinces.splice(pack.states[state].provinces.indexOf(p), 1);
|
||||
pack.provinces[p].removed = true;
|
||||
unfocus(p);
|
||||
unfog("focusProvince"+p);
|
||||
|
||||
const g = provs.select("#provincesBody");
|
||||
g.select("#province"+p).remove();
|
||||
|
|
@ -853,7 +839,7 @@ function editProvinces() {
|
|||
$(this).dialog("close");
|
||||
pack.provinces.filter(p => p.i).forEach(p => {
|
||||
p.removed = true;
|
||||
unfocus(p.i);
|
||||
unfog("focusProvince"+p.i);
|
||||
});
|
||||
pack.cells.i.forEach(i => pack.cells.province[i] = 0);
|
||||
pack.states.filter(s => s.i && !s.removed).forEach(s => s.provinces = []);
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ function editStates() {
|
|||
if (cl.contains("icon-coa")) stateOpenCOA(ev, state); else
|
||||
if (cl.contains("icon-star-empty")) stateCapitalZoomIn(state); else
|
||||
if (cl.contains("culturePopulation")) changePopulation(state); else
|
||||
if (cl.contains("icon-pin")) focusOnState(state, cl); else
|
||||
if (cl.contains("icon-pin")) toggleFog(state, cl); else
|
||||
if (cl.contains("icon-trash-empty")) stateRemovePrompt(state);
|
||||
});
|
||||
|
||||
|
|
@ -171,6 +171,8 @@ function editStates() {
|
|||
|
||||
function stateHighlightOn(event) {
|
||||
if (!layerIsOn("toggleStates")) return;
|
||||
if (defs.select("#fog path").size()) return;
|
||||
|
||||
const state = +event.target.dataset.id;
|
||||
if (customization || !state) return;
|
||||
const d = regions.select("#state"+state).attr("d");
|
||||
|
|
@ -405,26 +407,11 @@ function editStates() {
|
|||
recalculateStates();
|
||||
}
|
||||
|
||||
function focusOnState(state, cl) {
|
||||
function toggleFog(state, cl) {
|
||||
if (customization) return;
|
||||
|
||||
const inactive = cl.contains("inactive");
|
||||
const path = statesBody.select("#state"+state).attr("d"), id = "focusState"+state;
|
||||
cl.contains("inactive") ? fog(id, path) : unfog(id);
|
||||
cl.toggle("inactive");
|
||||
|
||||
if (inactive) {
|
||||
if (defs.select("#fog #focusState"+state).size()) return;
|
||||
fogging.style("display", "block");
|
||||
const path = statesBody.select("#state"+state).attr("d");
|
||||
defs.select("#fog").append("path").attr("d", path).attr("fill", "black").attr("id", "focusState"+state);
|
||||
fogging.append("path").attr("d", path).attr("id", "focusStateHalo"+state)
|
||||
.attr("fill", "none").attr("stroke", pack.states[state].color).attr("filter", "url(#blur5)");
|
||||
} else unfocus(state);
|
||||
}
|
||||
|
||||
function unfocus(s) {
|
||||
defs.select("#focusState"+s).remove();
|
||||
fogging.select("#focusStateHalo"+s).remove();
|
||||
if (!defs.selectAll("#fog path").size()) fogging.style("display", "none"); // all items are de-focused
|
||||
}
|
||||
|
||||
function stateRemovePrompt(state) {
|
||||
|
|
@ -446,7 +433,7 @@ function editStates() {
|
|||
statesBody.select("#state"+state).remove();
|
||||
statesBody.select("#state-gap"+state).remove();
|
||||
statesHalo.select("#state-border"+state).remove();
|
||||
unfocus(state);
|
||||
unfog("focusState"+state);
|
||||
const label = document.querySelector("#stateLabel"+state);
|
||||
if (label) label.remove();
|
||||
pack.burgs.forEach(b => {if(b.state === state) b.state = 0;});
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -30,7 +30,7 @@ function editZones() {
|
|||
if (cl.contains("culturePopulation")) {changePopulation(zone); return;}
|
||||
if (cl.contains("icon-trash-empty")) {zoneRemove(zone); return;}
|
||||
if (cl.contains("icon-eye")) {toggleVisibility(el); return;}
|
||||
if (cl.contains("icon-pin")) {focusOnZone(zone, cl); return;}
|
||||
if (cl.contains("icon-pin")) {toggleFog(zone, cl); return;}
|
||||
if (cl.contains("fillRect")) {changeFill(el); return;}
|
||||
if (customization) selectZone(el);
|
||||
});
|
||||
|
|
@ -194,7 +194,7 @@ function editZones() {
|
|||
zones.selectAll("g").each(function() {
|
||||
if (this.dataset.cells) return;
|
||||
// all zone cells are removed
|
||||
unfocus(this.id);
|
||||
unfog("focusZone"+this.id);
|
||||
this.style.display = "block";
|
||||
});
|
||||
|
||||
|
|
@ -253,24 +253,13 @@ function editZones() {
|
|||
el.classList.toggle("inactive");
|
||||
}
|
||||
|
||||
function focusOnZone(zone, cl) {
|
||||
const inactive = cl.contains("inactive");
|
||||
function toggleFog(z, cl) {
|
||||
const dataCells = zones.select("#"+z).attr("data-cells");
|
||||
if (!dataCells) return;
|
||||
|
||||
const path = "M" + dataCells.split(",").map(c => getPackPolygon(+c)).join("M") + "Z", id = "focusZone"+z;
|
||||
cl.contains("inactive") ? fog(id, path) : unfog(id);
|
||||
cl.toggle("inactive");
|
||||
|
||||
if (inactive) {
|
||||
if (defs.select("#fog #focus"+zone).size()) return;
|
||||
const dataCells = zones.select("#"+zone).attr("data-cells");
|
||||
if (!dataCells) return;
|
||||
const data = dataCells.split(",").map(c => +c);
|
||||
const g = defs.select("#fog").append("g").attr("fill", "black").attr("stroke", "black").attr("id", "focus"+zone);
|
||||
g.selectAll("path").data(data).enter().append("path").attr("d", d => "M" + getPackPolygon(d) + "Z");
|
||||
fogging.style("display", "block");
|
||||
} else unfocus(zone);
|
||||
}
|
||||
|
||||
function unfocus(z) {
|
||||
defs.select("#focus"+z).remove();
|
||||
if (!defs.selectAll("#fog path").size()) fogging.style("display", "none"); // all states are de-focused
|
||||
}
|
||||
|
||||
function toggleLegend() {
|
||||
|
|
@ -414,7 +403,7 @@ function editZones() {
|
|||
|
||||
function zoneRemove(zone) {
|
||||
zones.select("#"+zone).remove();
|
||||
unfocus(zone);
|
||||
unfog("focusZone"+zone);
|
||||
zonesEditorAddLines();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue