mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-23 12:31:24 +01:00
Copy all visible military units from the old map.
This commit is contained in:
parent
9b618544e6
commit
385fdca868
4 changed files with 40 additions and 36 deletions
|
|
@ -3668,6 +3668,9 @@
|
|||
<p>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, <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 />
|
||||
<p>Remap (copy) the following features to the new map:</p>
|
||||
<div data-tip="Copy burgs from old map. Regenerate burgs if not checked." >
|
||||
|
|
@ -3678,10 +3681,6 @@
|
|||
<input id="submapCopyRivers" class="checkbox" type="checkbox">
|
||||
<label for="submapCopyRivers" class="checkbox-label">Rivers</label>
|
||||
</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." >
|
||||
<input id="submapCopyMarkers" class="checkbox" type="checkbox" checked>
|
||||
<label for="submapCopyMarkers" class="checkbox-label">Markers</label>
|
||||
|
|
|
|||
|
|
@ -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};
|
||||
})();
|
||||
|
|
|
|||
|
|
@ -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()) {
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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"),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue