mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 09:41:24 +01:00
partially refactor BurgAndStates
This commit is contained in:
parent
456485c5e8
commit
ec468914e4
4 changed files with 40 additions and 35 deletions
|
|
@ -4524,6 +4524,7 @@
|
||||||
<script src="modules/resources-generator.js"></script>
|
<script src="modules/resources-generator.js"></script>
|
||||||
<script src="modules/burgs-and-states.js"></script>
|
<script src="modules/burgs-and-states.js"></script>
|
||||||
<script src="modules/production-generator.js"></script>
|
<script src="modules/production-generator.js"></script>
|
||||||
|
<script src="modules/trade-generator.js"></script>
|
||||||
<script src="modules/routes-generator.js"></script>
|
<script src="modules/routes-generator.js"></script>
|
||||||
<script src="modules/religions-generator.js"></script>
|
<script src="modules/religions-generator.js"></script>
|
||||||
<script src="modules/military-generator.js"></script>
|
<script src="modules/military-generator.js"></script>
|
||||||
|
|
|
||||||
|
|
@ -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() {
|
||||||
|
|
@ -72,7 +66,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'}];
|
||||||
|
|
@ -121,9 +115,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;
|
||||||
|
|
@ -149,10 +144,9 @@ window.BurgsAndStates = (function () {
|
||||||
// define burg coordinates, coa, port status and define details
|
// define burg coordinates, coa, port status and define details
|
||||||
const specifyBurgs = function () {
|
const specifyBurgs = function () {
|
||||||
TIME && console.time('specifyBurgs');
|
TIME && console.time('specifyBurgs');
|
||||||
const cells = pack.cells,
|
const {cells, features} = pack;
|
||||||
vertices = pack.vertices,
|
const temp = grid.cells.temp;
|
||||||
features = pack.features,
|
const POPULATION_MULTIPLIER = 0.15; // to keep urbanization at about 10% rate
|
||||||
temp = grid.cells.temp;
|
|
||||||
|
|
||||||
for (const b of pack.burgs) {
|
for (const b of pack.burgs) {
|
||||||
if (!b.i || b.lock) continue;
|
if (!b.i || b.lock) continue;
|
||||||
|
|
@ -167,8 +161,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) {
|
||||||
|
|
@ -230,19 +226,21 @@ window.BurgsAndStates = (function () {
|
||||||
};
|
};
|
||||||
|
|
||||||
const defineBurgFeatures = function (newburg) {
|
const defineBurgFeatures = function (newburg) {
|
||||||
const cells = pack.cells;
|
const {cells, burgs} = pack;
|
||||||
pack.burgs
|
|
||||||
.filter((b) => (newburg ? b.i == newburg.i : b.i && !b.removed))
|
for (const burg of burgs) {
|
||||||
.forEach((b) => {
|
if (!burg.i || burg.removed) continue;
|
||||||
const pop = b.population;
|
if (newburg && newburg.i !== burg.i) continue;
|
||||||
b.citadel = b.capital || (pop > 50 && P(0.75)) || P(0.5) ? 1 : 0;
|
const {cell, state, pop, capital} = burg;
|
||||||
b.plaza = pop > 50 || (pop > 30 && P(0.75)) || (pop > 10 && P(0.5)) || P(0.25) ? 1 : 0;
|
|
||||||
b.walls = b.capital || pop > 30 || (pop > 20 && P(0.75)) || (pop > 10 && P(0.5)) || P(0.2) ? 1 : 0;
|
burg.citadel = capital || (pop > 50 && P(0.75)) || P(0.5) ? 1 : 0;
|
||||||
b.shanty = pop > 30 || (pop > 20 && P(0.75)) || (b.walls && P(0.75)) ? 1 : 0;
|
burg.plaza = pop > 50 || (pop > 30 && P(0.75)) || (pop > 10 && P(0.5)) || P(0.25) ? 1 : 0;
|
||||||
const religion = cells.religion[b.cell];
|
burg.walls = capital || pop > 30 || (pop > 20 && P(0.75)) || (pop > 10 && P(0.5)) || P(0.2) ? 1 : 0;
|
||||||
const theocracy = pack.states[b.state].form === 'Theocracy';
|
burg.shanty = pop > 30 || (pop > 20 && P(0.75)) || (burg.walls && P(0.75)) ? 1 : 0;
|
||||||
b.temple = (religion && theocracy) || pop > 50 || (pop > 35 && P(0.75)) || (pop > 20 && P(0.5)) ? 1 : 0;
|
const religion = cells.religion[cell];
|
||||||
});
|
const theocracy = pack.states[state].form === 'Theocracy';
|
||||||
|
burg.temple = (religion && theocracy) || pop > 50 || (pop > 35 && P(0.75)) || (pop > 20 && P(0.5)) ? 1 : 0;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const drawBurgs = function () {
|
const drawBurgs = function () {
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
|
|
|
||||||
8
modules/trade-generator.js
Normal file
8
modules/trade-generator.js
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
window.Trade = (function () {
|
||||||
|
const defineTradeCenters = () => {
|
||||||
|
const {cells} = pack;
|
||||||
|
};
|
||||||
|
return {defineTradeCenters};
|
||||||
|
})();
|
||||||
Loading…
Add table
Add a link
Reference in a new issue