mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-18 18:11:24 +01:00
sky-burgs-sky-routes
This commit is contained in:
parent
2c3692f000
commit
73ab86b957
23 changed files with 919 additions and 49 deletions
|
|
@ -227,6 +227,52 @@ function moveBurgToGroup(id, g) {
|
|||
}
|
||||
}
|
||||
|
||||
// Ensure a dedicated locked Sky State exists; create if missing and return its id
|
||||
function ensureSkyState(anchorBurgId) {
|
||||
const {states, burgs, cultures, cells} = pack;
|
||||
|
||||
// Reuse existing sky state if present
|
||||
let sky = states.find(s => s && s.i && !s.removed && s.skyRealm);
|
||||
if (sky) return sky.i;
|
||||
|
||||
// Create a new locked Sky State
|
||||
const b = burgs[anchorBurgId];
|
||||
const i = states.length;
|
||||
const culture = (b && b.culture) || cells.culture?.[b?.cell] || 1;
|
||||
const type = "Generic";
|
||||
const name = "Sky Realm";
|
||||
const color = "#5b8bd4";
|
||||
const coa = COA.generate(null, null, null, cultures[culture]?.type || "Generic");
|
||||
coa.shield = COA.getShield(culture, null);
|
||||
|
||||
const newState = {
|
||||
i,
|
||||
name,
|
||||
type,
|
||||
color,
|
||||
capital: anchorBurgId,
|
||||
center: b.cell,
|
||||
culture,
|
||||
expansionism: 0.1,
|
||||
coa,
|
||||
lock: 1,
|
||||
skyRealm: 1
|
||||
};
|
||||
|
||||
states.push(newState);
|
||||
|
||||
// Assign the burg and its cell to the Sky State
|
||||
if (cells && typeof b.cell === "number") cells.state[b.cell] = i;
|
||||
if (b) {
|
||||
b.state = i;
|
||||
b.capital = 1;
|
||||
// Move to cities layer for capitals
|
||||
moveBurgToGroup(anchorBurgId, "cities");
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
function moveAllBurgsToGroup(fromGroup, toGroup) {
|
||||
const groupToMove = document.querySelector(`#burgIcons #${fromGroup}`);
|
||||
const burgsToMove = Array.from(groupToMove.children).map(x => x.dataset.id);
|
||||
|
|
@ -316,6 +362,9 @@ function togglePort(burg) {
|
|||
function getBurgLink(burg) {
|
||||
if (burg.link) return burg.link;
|
||||
|
||||
// Sky burgs: force MFCG with sky-friendly parameters
|
||||
if (burg.flying || burg.skyPort) return createMfcgLink(burg, true);
|
||||
|
||||
const population = burg.population * populationRate * urbanization;
|
||||
if (population >= options.villageMaxPopulation || burg.citadel || burg.walls || burg.temple || burg.shanty)
|
||||
return createMfcgLink(burg);
|
||||
|
|
@ -323,42 +372,42 @@ function getBurgLink(burg) {
|
|||
return createVillageGeneratorLink(burg);
|
||||
}
|
||||
|
||||
function createMfcgLink(burg) {
|
||||
function createMfcgLink(burg, isSky = false) {
|
||||
const {cells} = pack;
|
||||
const {i, name, population: burgPopulation, cell} = burg;
|
||||
const burgSeed = burg.MFCG || seed + String(burg.i).padStart(4, 0);
|
||||
|
||||
const sizeRaw = 2.13 * Math.pow((burgPopulation * populationRate) / urbanDensity, 0.385);
|
||||
const size = minmax(Math.ceil(sizeRaw), 6, 100);
|
||||
const size = isSky ? 25 : minmax(Math.ceil(sizeRaw), 6, 100);
|
||||
const population = rn(burgPopulation * populationRate * urbanization);
|
||||
|
||||
const river = cells.r[cell] ? 1 : 0;
|
||||
const coast = Number(burg.port > 0);
|
||||
const sea = (() => {
|
||||
if (!coast || !cells.haven[cell]) return null;
|
||||
const river = isSky ? 0 : (cells.r[cell] ? 1 : 0);
|
||||
const coast = isSky ? 0 : Number(burg.port > 0);
|
||||
|
||||
// calculate see direction: 0 = south, 0.5 = west, 1 = north, 1.5 = east
|
||||
const p1 = cells.p[cell];
|
||||
const p2 = cells.p[cells.haven[cell]];
|
||||
let deg = (Math.atan2(p2[1] - p1[1], p2[0] - p1[0]) * 180) / Math.PI - 90;
|
||||
if (deg < 0) deg += 360;
|
||||
return rn(normalize(deg, 0, 360) * 2, 2);
|
||||
})();
|
||||
const sea = !isSky && coast && cells.haven[cell]
|
||||
? (() => {
|
||||
const p1 = cells.p[cell];
|
||||
const p2 = cells.p[cells.haven[cell]];
|
||||
let deg = (Math.atan2(p2[1] - p1[1], p2[0] - p1[0]) * 180) / Math.PI - 90;
|
||||
if (deg < 0) deg += 360;
|
||||
return rn(normalize(deg, 0, 360) * 2, 2);
|
||||
})()
|
||||
: null;
|
||||
|
||||
const arableBiomes = river ? [1, 2, 3, 4, 5, 6, 7, 8] : [5, 6, 7, 8];
|
||||
const farms = +arableBiomes.includes(cells.biome[cell]);
|
||||
const farms = isSky ? 0 : +arableBiomes.includes(cells.biome[cell]);
|
||||
|
||||
const citadel = +burg.citadel;
|
||||
const urban_castle = +(citadel && each(2)(i));
|
||||
const citadel = isSky ? 1 : +burg.citadel;
|
||||
const urban_castle = isSky ? 1 : +(citadel && each(2)(i));
|
||||
const hub = isSky ? 0 : Routes.isCrossroad(cell);
|
||||
const walls = isSky ? 1 : +burg.walls;
|
||||
const plaza = isSky ? 1 : +burg.plaza;
|
||||
const temple = isSky ? 1 : +burg.temple;
|
||||
const shantytown = isSky ? 0 : +burg.shanty;
|
||||
const greens = isSky ? 1 : undefined;
|
||||
const gates = isSky ? 0 : -1;
|
||||
|
||||
const hub = Routes.isCrossroad(cell);
|
||||
const walls = +burg.walls;
|
||||
const plaza = +burg.plaza;
|
||||
const temple = +burg.temple;
|
||||
const shantytown = +burg.shanty;
|
||||
|
||||
const url = new URL("https://watabou.github.io/city-generator/");
|
||||
url.search = new URLSearchParams({
|
||||
const params = {
|
||||
name,
|
||||
population,
|
||||
size,
|
||||
|
|
@ -372,9 +421,13 @@ function createMfcgLink(burg) {
|
|||
plaza,
|
||||
temple,
|
||||
walls,
|
||||
shantytown,
|
||||
gates: -1
|
||||
});
|
||||
shantytown
|
||||
};
|
||||
if (greens !== undefined) params.greens = greens;
|
||||
if (gates !== undefined) params.gates = gates;
|
||||
|
||||
const url = new URL("https://watabou.github.io/city-generator/");
|
||||
url.search = new URLSearchParams(params);
|
||||
if (sea) url.searchParams.append("sea", sea);
|
||||
|
||||
return url.toString();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue