From 385fdca8682008cd0dca34c774a2b67893c7d6a4 Mon Sep 17 00:00:00 2001 From: GoteGuru Date: Thu, 31 Mar 2022 00:31:28 +0000 Subject: [PATCH] Copy all visible military units from the old map. --- index.html | 7 +++--- modules/military-generator.js | 23 ++++++++++-------- modules/submap.js | 44 ++++++++++++++++++----------------- modules/ui/submap.js | 2 +- 4 files changed, 40 insertions(+), 36 deletions(-) diff --git a/index.html b/index.html index a3d44a19..a5c94c6a 100644 --- a/index.html +++ b/index.html @@ -3668,6 +3668,9 @@

Population rate (Units editor -> population) and map pixel size will be automatically updated according to the current scale factor. If you'd like to generate a new parent-map, don't forget to reset them! Options are interpreted as usual.

+

+ Automatically copied: Heightmap, Biome, Precipitation, Cultures, States, Provinces, Regiments (military). +


Remap (copy) the following features to the new map:

@@ -3678,10 +3681,6 @@
-
- - -
diff --git a/modules/military-generator.js b/modules/military-generator.js index c69dc1e3..648f5637 100644 --- a/modules/military-generator.js +++ b/modules/military-generator.js @@ -157,14 +157,6 @@ window.Military = (function () { } } - void (function removeExistingRegiments() { - armies.selectAll("g > g").each(function () { - const index = notes.findIndex(n => n.id === this.id); - if (index != -1) notes.splice(index, 1); - }); - armies.selectAll("g").remove(); - })(); - const expected = 3 * populationRate; // expected regiment size const mergeable = (n0, n1) => (!n0.s && !n1.s) || n0.u === n1.u; // check if regiments can be merged @@ -172,9 +164,10 @@ window.Military = (function () { valid.forEach(s => { s.military = createRegiments(s.temp.platoons, s); delete s.temp; // do not store temp data - drawRegiments(s.military, s.i); }); + redraw(); + function createRegiments(nodes, s) { if (!nodes.length) return []; @@ -236,6 +229,16 @@ window.Military = (function () { TIME && console.timeEnd("generateMilitaryForces"); }; + function redraw() { + const validStates = pack.states.filter(s => s.i && !s.removed); + armies.selectAll("g > g").each(function () { + const index = notes.findIndex(n => n.id === this.id); + if (index != -1) notes.splice(index, 1); + }); + armies.selectAll("g").remove(); + validStates.forEach(s => drawRegiments(s.military, s.i)); + } + const getDefaultOptions = function () { return [ {icon: "⚔️", name: "infantry", rural: 0.25, urban: 0.2, crew: 1, power: 1, type: "melee", separate: 0}, @@ -406,5 +409,5 @@ window.Military = (function () { notes.push({id: `regiment${s.i}-${r.i}`, name: `${r.icon} ${r.name}`, legend}); }; - return {generate, getDefaultOptions, getName, generateNote, drawRegiments, drawRegiment, moveRegiment, getTotal, getEmblem}; + return {generate, redraw, getDefaultOptions, getName, generateNote, drawRegiments, drawRegiment, moveRegiment, getTotal, getEmblem}; })(); diff --git a/modules/submap.js b/modules/submap.js index b5b2cd87..309782f4 100644 --- a/modules/submap.js +++ b/modules/submap.js @@ -27,7 +27,7 @@ window.Submap = (function () { applyMapSize(); placePoints(); calculateVoronoi(grid, grid.points); - drawScaleBar(); + drawScaleBar(scale); const resampler = (points, qtree, f) => { for(const [i,[x, y]] of points.entries()) { @@ -172,7 +172,7 @@ window.Submap = (function () { "newheight", grid.cells.h[cells.g[id]]) throw new Error("should be the same type.") } - const [oldpx, oldpy]= oldCells.p[oid]; + const [oldpx, oldpy] = oldCells.p[oid]; const nd = distance(projection(oldpx, oldpx, false)); if (!nd) { console.error("no distance!", nd, "old point", oldp) @@ -212,13 +212,14 @@ window.Submap = (function () { // transfer basemap cultures pack.cultures = parentMap.pack.cultures; + // fix culture centers const validCultures = new Set(pack.cells.culture); pack.cultures.forEach((c, i) => { if (!i) return // ignore wildlands if (!validCultures.has(i)) { c.removed = true; - c.center = undefined; + c.center = null; return } const newCenters = forwardMap[c.center] @@ -241,22 +242,11 @@ window.Submap = (function () { s.neighbors = s.neighbors.filter(n => validStates.has(n)); // find center - let capital - if (options.copyBurgs) // capital is the best bet - capital = pack.burgs[s.capital].cell; - - s.center = capital - ? capital - : pack.cells.state.findIndex(x => x===i); + s.center = (options.copyBurgs && pack.burgs[s.capital].cell) + ? pack.burgs[s.capital].cell // capital is the best bet + : pack.cells.state.findIndex(x => x===i); // otherwise use the first valid cell }); - /* probably not needed now - // fix extra coastline cells without state. - const newCoastCells = cells.t.reduce( - (a,c,i) => c === -1 && !cells.state[i] ? a.push(i) && a: a, [] - ); - */ - // transfer provinces, mark provinces without land as removed. stage("Porting provinces."); const validProvinces = new Set(pack.cells.province); @@ -279,7 +269,7 @@ window.Submap = (function () { BurgsAndStates.drawBurgs(); stage("Regenerating road network."); - Routes.regenerate(); + if (!options.copyRoads) Routes.regenerate(); drawStates(); drawBorders(); @@ -288,8 +278,20 @@ window.Submap = (function () { Rivers.specify(); Lakes.generateName(); - stage("Modelling military, markers and zones (if requested)."); - if (options.addMilitary) Military.generate(); + stage("Porting military."); + for (const s of pack.states) { + if (!s.military) continue; + for (const m of s.military) { + [m.x, m.y] = projection(m.x, m.y, false); + [m.bx, m.by] = projection(m.bx, m.by, false); + const cc = forwardMap[m.cell]; + m.cell = (cc && cc.length)? cc[0]: null; + } + s.military = s.military.filter(m=>m.cell).map((m, i) => ({...m, i})); + } + Military.redraw(); + + stage("markers and zones (if requested)."); if (options.addMarkers) Markers.generate(); if (options.addZones) addZones(); Names.getMapName(); @@ -336,7 +338,7 @@ window.Submap = (function () { // disable out-of-map (removed) burgs if (!inMap(b.x,b.y)) { b.removed = true; - b.cell = undefined; + b.cell = null; return; } diff --git a/modules/ui/submap.js b/modules/ui/submap.js index 5d044150..2ee0181b 100644 --- a/modules/ui/submap.js +++ b/modules/ui/submap.js @@ -22,10 +22,10 @@ const generateSubmap = debounce(async function () { const checked = id => Boolean(document.getElementById(id).checked) const options = { copyBurgs: checked("submapCopyBurgs"), - copyMilitary: checked("submapCopyMilitary"), copyMarkers: checked("submapCopyMarkers"), copyZones: checked("submapCopyZones"), copyZones: checked("submapCopyRivers"), + copyZones: checked("submapCopyRoads"), depressRivers: checked("submapDepressRivers"), addLakesInDepressions: checked("submapAddLakeInDepression"),