mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-22 12:01:23 +01:00
partially refactor BurgAndStates
This commit is contained in:
parent
ecdb536f95
commit
899c83fc65
2 changed files with 13 additions and 18 deletions
|
|
@ -5,28 +5,22 @@ window.BurgsAndStates = (function () {
|
||||||
const {cells, cultures} = pack;
|
const {cells, cultures} = pack;
|
||||||
const n = cells.i.length;
|
const n = cells.i.length;
|
||||||
|
|
||||||
cells.burg = new Uint16Array(n); // cell burg
|
cells.burg = new Uint16Array(n);
|
||||||
cells.road = new Uint16Array(n); // cell road power
|
pack.burgs = placeCapitals();
|
||||||
cells.crossroad = new Uint16Array(n); // cell crossroad power
|
const {burgs} = pack;
|
||||||
|
|
||||||
const burgs = (pack.burgs = placeCapitals());
|
|
||||||
pack.states = createStates();
|
pack.states = createStates();
|
||||||
const capitalRoutes = Routes.getRoads();
|
|
||||||
|
|
||||||
placeTowns();
|
placeTowns();
|
||||||
expandStates();
|
expandStates();
|
||||||
normalizeStates();
|
normalizeStates();
|
||||||
const townRoutes = Routes.getTrails();
|
|
||||||
specifyBurgs();
|
specifyBurgs();
|
||||||
|
|
||||||
const oceanRoutes = Routes.getSearoutes();
|
|
||||||
|
|
||||||
collectStatistics();
|
collectStatistics();
|
||||||
assignColors();
|
assignColors();
|
||||||
|
|
||||||
generateCampaigns();
|
generateCampaigns();
|
||||||
generateDiplomacy();
|
generateDiplomacy();
|
||||||
Routes.draw(capitalRoutes, townRoutes, oceanRoutes);
|
|
||||||
drawBurgs();
|
drawBurgs();
|
||||||
|
|
||||||
function placeCapitals() {
|
function placeCapitals() {
|
||||||
|
|
@ -74,7 +68,7 @@ window.BurgsAndStates = (function () {
|
||||||
return burgs;
|
return burgs;
|
||||||
}
|
}
|
||||||
|
|
||||||
// For each capital create a state
|
// for each capital create a state
|
||||||
function createStates() {
|
function createStates() {
|
||||||
TIME && console.time("createStates");
|
TIME && console.time("createStates");
|
||||||
const states = [{i: 0, name: "Neutrals"}];
|
const states = [{i: 0, name: "Neutrals"}];
|
||||||
|
|
@ -138,9 +132,10 @@ window.BurgsAndStates = (function () {
|
||||||
while (burgsAdded < burgsNumber && spacing > 1) {
|
while (burgsAdded < burgsNumber && spacing > 1) {
|
||||||
for (let i = 0; burgsAdded < burgsNumber && i < sorted.length; i++) {
|
for (let i = 0; burgsAdded < burgsNumber && i < sorted.length; i++) {
|
||||||
if (cells.burg[sorted[i]]) continue;
|
if (cells.burg[sorted[i]]) continue;
|
||||||
const cell = sorted[i],
|
|
||||||
x = cells.p[cell][0],
|
const cell = sorted[i];
|
||||||
y = cells.p[cell][1];
|
const [x, y] = cells.p[cell];
|
||||||
|
|
||||||
const s = spacing * gauss(1, 0.3, 0.2, 2, 2); // randomize to make placement not uniform
|
const s = spacing * gauss(1, 0.3, 0.2, 2, 2); // randomize to make placement not uniform
|
||||||
if (burgsTree.find(x, y, s) !== undefined) continue; // to close to existing burg
|
if (burgsTree.find(x, y, s) !== undefined) continue; // to close to existing burg
|
||||||
const burg = burgs.length;
|
const burg = burgs.length;
|
||||||
|
|
@ -184,8 +179,10 @@ window.BurgsAndStates = (function () {
|
||||||
b.port = port ? f : 0; // port is defined by water body id it lays on
|
b.port = port ? f : 0; // port is defined by water body id it lays on
|
||||||
} else b.port = 0;
|
} else b.port = 0;
|
||||||
|
|
||||||
// define burg population (keep urbanization at about 10% rate)
|
// define burg population
|
||||||
b.population = rn(Math.max((cells.s[i] + cells.road[i] / 2) / 8 + b.i / 1000 + (i % 100) / 1000, 0.1), 3);
|
const primaryPopulation = cells.s[i] * POPULATION_MULTIPLIER;
|
||||||
|
const secondaryPopulation = b.i / 1000 + (i % 100) / 1000;
|
||||||
|
b.population = rn(Math.max(primaryPopulation + secondaryPopulation, 0.1), 3);
|
||||||
if (b.capital) b.population = rn(b.population * 1.3, 3); // increase capital population
|
if (b.capital) b.population = rn(b.population * 1.3, 3); // increase capital population
|
||||||
|
|
||||||
if (b.port) {
|
if (b.port) {
|
||||||
|
|
|
||||||
|
|
@ -111,9 +111,7 @@ window.Production = (function () {
|
||||||
};
|
};
|
||||||
|
|
||||||
const defineExport = () => {
|
const defineExport = () => {
|
||||||
const {cells, burgs} = pack;
|
for (const burg of pack.burgs) {
|
||||||
|
|
||||||
for (const burg of burgs) {
|
|
||||||
if (!burg.i || burg.removed) continue;
|
if (!burg.i || burg.removed) continue;
|
||||||
const {population, production: resourcePool} = burg;
|
const {population, production: resourcePool} = burg;
|
||||||
const localUsage = Math.ceil(population);
|
const localUsage = Math.ceil(population);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue