mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 09:41:24 +01:00
fix: states regeneration when some states are locked
This commit is contained in:
parent
04b6d479b2
commit
3f25484367
3 changed files with 28 additions and 16 deletions
|
|
@ -7871,7 +7871,7 @@
|
||||||
<script defer src="modules/relief-icons.js"></script>
|
<script defer src="modules/relief-icons.js"></script>
|
||||||
<script defer src="modules/ui/style.js"></script>
|
<script defer src="modules/ui/style.js"></script>
|
||||||
<script defer src="modules/ui/editors.js?v=1.89.12"></script>
|
<script defer src="modules/ui/editors.js?v=1.89.12"></script>
|
||||||
<script defer src="modules/ui/tools.js?v=1.89.24"></script>
|
<script defer src="modules/ui/tools.js?v=1.89.27"></script>
|
||||||
<script defer src="modules/ui/world-configurator.js"></script>
|
<script defer src="modules/ui/world-configurator.js"></script>
|
||||||
<script defer src="modules/ui/heightmap-editor.js?v=1.89.06"></script>
|
<script defer src="modules/ui/heightmap-editor.js?v=1.89.06"></script>
|
||||||
<script defer src="modules/ui/provinces-editor.js?v=1.89.00"></script>
|
<script defer src="modules/ui/provinces-editor.js?v=1.89.00"></script>
|
||||||
|
|
|
||||||
|
|
@ -137,7 +137,10 @@ function recalculatePopulation() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function regenerateStates() {
|
function regenerateStates() {
|
||||||
recreateStates();
|
const newStates = recreateStates();
|
||||||
|
if (!newStates) return;
|
||||||
|
|
||||||
|
pack.states = newStates;
|
||||||
BurgsAndStates.expandStates();
|
BurgsAndStates.expandStates();
|
||||||
BurgsAndStates.normalizeStates();
|
BurgsAndStates.normalizeStates();
|
||||||
BurgsAndStates.collectStatistics();
|
BurgsAndStates.collectStatistics();
|
||||||
|
|
@ -165,21 +168,32 @@ function recreateStates() {
|
||||||
Math.random = aleaPRNG(localSeed);
|
Math.random = aleaPRNG(localSeed);
|
||||||
|
|
||||||
const statesCount = +regionsOutput.value;
|
const statesCount = +regionsOutput.value;
|
||||||
|
if (!statesCount) {
|
||||||
|
tip(`<i>States Number</i> option value is zero. No counties are generated`, false, "error");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
const validBurgs = pack.burgs.filter(b => b.i && !b.removed);
|
const validBurgs = pack.burgs.filter(b => b.i && !b.removed);
|
||||||
|
if (!validBurgs.length) {
|
||||||
|
tip("There are no any burgs to generate states. Please create burgs first", false, "error");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (!validBurgs.length)
|
if (validBurgs.length < statesCount) {
|
||||||
return tip("There are no any burgs to generate states. Please create burgs first", false, "error");
|
const message = `Not enough burgs to generate ${statesCount} states. Will generate only ${validBurgs.length} states`;
|
||||||
if (validBurgs.length < statesCount)
|
tip(message, false, "warn");
|
||||||
tip(
|
}
|
||||||
`Not enough burgs to generate ${statesCount} states. Will generate only ${validBurgs.length} states`,
|
|
||||||
false,
|
|
||||||
"warn"
|
|
||||||
);
|
|
||||||
|
|
||||||
const lockedStates = pack.states.filter(s => s.i && !s.removed && s.lock);
|
const validStates = pack.states.filter(s => s.i && !s.removed);
|
||||||
|
const lockedStates = validStates.filter(s => s.lock);
|
||||||
const lockedStatesIds = lockedStates.map(s => s.i);
|
const lockedStatesIds = lockedStates.map(s => s.i);
|
||||||
const lockedStatesCapitals = lockedStates.map(s => s.capital);
|
const lockedStatesCapitals = lockedStates.map(s => s.capital);
|
||||||
|
|
||||||
|
if (lockedStates.length === validStates.length) {
|
||||||
|
tip("Unable to regenerate as all states are locked", false, "error");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// turn all old capitals into towns, except for the capitals of locked states
|
// turn all old capitals into towns, except for the capitals of locked states
|
||||||
for (const burg of validBurgs) {
|
for (const burg of validBurgs) {
|
||||||
if (!burg.capital) continue;
|
if (!burg.capital) continue;
|
||||||
|
|
@ -229,7 +243,7 @@ function recreateStates() {
|
||||||
// restore locked states
|
// restore locked states
|
||||||
lockedStates.forEach(state => {
|
lockedStates.forEach(state => {
|
||||||
const newId = newStates.length;
|
const newId = newStates.length;
|
||||||
const {x, y} = validBurgs[state.capital];
|
const {x, y} = pack.burgs[state.capital];
|
||||||
capitalsTree.add([x, y]);
|
capitalsTree.add([x, y]);
|
||||||
|
|
||||||
// update label id reference
|
// update label id reference
|
||||||
|
|
@ -300,9 +314,7 @@ function recreateStates() {
|
||||||
newStates.push({i, name, type, capital: capital.i, center: capital.cell, culture, expansionism, coa});
|
newStates.push({i, name, type, capital: capital.i, center: capital.cell, culture, expansionism, coa});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!statesCount) tip(`<i>States Number</i> option is set to zero. No counties are generated`, false, "warn");
|
return newStates;
|
||||||
|
|
||||||
pack.states = newStates;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function regenerateProvinces() {
|
function regenerateProvinces() {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
// version and caching control
|
// version and caching control
|
||||||
const version = "1.89.26"; // generator version, update each time
|
const version = "1.89.27"; // generator version, update each time
|
||||||
|
|
||||||
{
|
{
|
||||||
document.title += " v" + version;
|
document.title += " v" + version;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue