Copy all visible military units from the old map.

This commit is contained in:
GoteGuru 2022-03-31 00:31:28 +00:00
parent 9b618544e6
commit 385fdca868
4 changed files with 40 additions and 36 deletions

View file

@ -3668,6 +3668,9 @@
<p>Population rate (Units editor -> population) and map pixel size will <p>Population rate (Units editor -> population) and map pixel size will
be automatically updated according to the current scale factor. If you'd like be automatically updated according to the current scale factor. If you'd like
to generate a new parent-map, <b>don't forget to reset them!</b> Options are interpreted as usual.</p> to generate a new parent-map, <b>don't forget to reset them!</b> Options are interpreted as usual.</p>
<p>
Automatically copied: Heightmap, Biome, Precipitation, Cultures, States, Provinces, Regiments (military).
</p>
<hr /> <hr />
<p>Remap (copy) the following features to the new map:</p> <p>Remap (copy) the following features to the new map:</p>
<div data-tip="Copy burgs from old map. Regenerate burgs if not checked." > <div data-tip="Copy burgs from old map. Regenerate burgs if not checked." >
@ -3678,10 +3681,6 @@
<input id="submapCopyRivers" class="checkbox" type="checkbox"> <input id="submapCopyRivers" class="checkbox" type="checkbox">
<label for="submapCopyRivers" class="checkbox-label">Rivers</label> <label for="submapCopyRivers" class="checkbox-label">Rivers</label>
</div> </div>
<div data-tip="Copy military data from the original map. Regenerate military if not checked." >
<input id="submapCopyMilitary" class="checkbox" type="checkbox">
<label for="submapCopyMilitary" class="checkbox-label">Military</label>
</div>
<div data-tip="Copy markers from the original map. Regenerate markers if not checked." > <div data-tip="Copy markers from the original map. Regenerate markers if not checked." >
<input id="submapCopyMarkers" class="checkbox" type="checkbox" checked> <input id="submapCopyMarkers" class="checkbox" type="checkbox" checked>
<label for="submapCopyMarkers" class="checkbox-label">Markers</label> <label for="submapCopyMarkers" class="checkbox-label">Markers</label>

View file

@ -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 expected = 3 * populationRate; // expected regiment size
const mergeable = (n0, n1) => (!n0.s && !n1.s) || n0.u === n1.u; // check if regiments can be merged 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 => { valid.forEach(s => {
s.military = createRegiments(s.temp.platoons, s); s.military = createRegiments(s.temp.platoons, s);
delete s.temp; // do not store temp data delete s.temp; // do not store temp data
drawRegiments(s.military, s.i);
}); });
redraw();
function createRegiments(nodes, s) { function createRegiments(nodes, s) {
if (!nodes.length) return []; if (!nodes.length) return [];
@ -236,6 +229,16 @@ window.Military = (function () {
TIME && console.timeEnd("generateMilitaryForces"); 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 () { const getDefaultOptions = function () {
return [ return [
{icon: "⚔️", name: "infantry", rural: 0.25, urban: 0.2, crew: 1, power: 1, type: "melee", separate: 0}, {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}); 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};
})(); })();

View file

@ -27,7 +27,7 @@ window.Submap = (function () {
applyMapSize(); applyMapSize();
placePoints(); placePoints();
calculateVoronoi(grid, grid.points); calculateVoronoi(grid, grid.points);
drawScaleBar(); drawScaleBar(scale);
const resampler = (points, qtree, f) => { const resampler = (points, qtree, f) => {
for(const [i,[x, y]] of points.entries()) { for(const [i,[x, y]] of points.entries()) {
@ -212,13 +212,14 @@ window.Submap = (function () {
// transfer basemap cultures // transfer basemap cultures
pack.cultures = parentMap.pack.cultures; pack.cultures = parentMap.pack.cultures;
// fix culture centers // fix culture centers
const validCultures = new Set(pack.cells.culture); const validCultures = new Set(pack.cells.culture);
pack.cultures.forEach((c, i) => { pack.cultures.forEach((c, i) => {
if (!i) return // ignore wildlands if (!i) return // ignore wildlands
if (!validCultures.has(i)) { if (!validCultures.has(i)) {
c.removed = true; c.removed = true;
c.center = undefined; c.center = null;
return return
} }
const newCenters = forwardMap[c.center] const newCenters = forwardMap[c.center]
@ -241,22 +242,11 @@ window.Submap = (function () {
s.neighbors = s.neighbors.filter(n => validStates.has(n)); s.neighbors = s.neighbors.filter(n => validStates.has(n));
// find center // find center
let capital s.center = (options.copyBurgs && pack.burgs[s.capital].cell)
if (options.copyBurgs) // capital is the best bet ? pack.burgs[s.capital].cell // capital is the best bet
capital = pack.burgs[s.capital].cell; : pack.cells.state.findIndex(x => x===i); // otherwise use the first valid cell
s.center = capital
? capital
: pack.cells.state.findIndex(x => x===i);
}); });
/* 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. // transfer provinces, mark provinces without land as removed.
stage("Porting provinces."); stage("Porting provinces.");
const validProvinces = new Set(pack.cells.province); const validProvinces = new Set(pack.cells.province);
@ -279,7 +269,7 @@ window.Submap = (function () {
BurgsAndStates.drawBurgs(); BurgsAndStates.drawBurgs();
stage("Regenerating road network."); stage("Regenerating road network.");
Routes.regenerate(); if (!options.copyRoads) Routes.regenerate();
drawStates(); drawStates();
drawBorders(); drawBorders();
@ -288,8 +278,20 @@ window.Submap = (function () {
Rivers.specify(); Rivers.specify();
Lakes.generateName(); Lakes.generateName();
stage("Modelling military, markers and zones (if requested)."); stage("Porting military.");
if (options.addMilitary) Military.generate(); 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.addMarkers) Markers.generate();
if (options.addZones) addZones(); if (options.addZones) addZones();
Names.getMapName(); Names.getMapName();
@ -336,7 +338,7 @@ window.Submap = (function () {
// disable out-of-map (removed) burgs // disable out-of-map (removed) burgs
if (!inMap(b.x,b.y)) { if (!inMap(b.x,b.y)) {
b.removed = true; b.removed = true;
b.cell = undefined; b.cell = null;
return; return;
} }

View file

@ -22,10 +22,10 @@ const generateSubmap = debounce(async function () {
const checked = id => Boolean(document.getElementById(id).checked) const checked = id => Boolean(document.getElementById(id).checked)
const options = { const options = {
copyBurgs: checked("submapCopyBurgs"), copyBurgs: checked("submapCopyBurgs"),
copyMilitary: checked("submapCopyMilitary"),
copyMarkers: checked("submapCopyMarkers"), copyMarkers: checked("submapCopyMarkers"),
copyZones: checked("submapCopyZones"), copyZones: checked("submapCopyZones"),
copyZones: checked("submapCopyRivers"), copyZones: checked("submapCopyRivers"),
copyZones: checked("submapCopyRoads"),
depressRivers: checked("submapDepressRivers"), depressRivers: checked("submapDepressRivers"),
addLakesInDepressions: checked("submapAddLakeInDepression"), addLakesInDepressions: checked("submapAddLakeInDepression"),