mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-23 04:21:24 +01:00
Add files via upload
it can generate more buildings with calculated sizes
This commit is contained in:
parent
44b3911e65
commit
f0707c51a0
1 changed files with 320 additions and 142 deletions
|
|
@ -2,7 +2,8 @@
|
||||||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
||||||
typeof define === 'function' && define.amd ? define(factory) :
|
typeof define === 'function' && define.amd ? define(factory) :
|
||||||
(global.BurgsAndStates = factory());
|
(global.BurgsAndStates = factory());
|
||||||
}(this, (function () { 'use strict';
|
}(this, (function () {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
const generate = function () {
|
const generate = function () {
|
||||||
const cells = pack.cells, cultures = pack.cultures, n = cells.i.length;
|
const cells = pack.cells, cultures = pack.cultures, n = cells.i.length;
|
||||||
|
|
@ -52,7 +53,19 @@
|
||||||
const cell = sorted[i], x = cells.p[cell][0], y = cells.p[cell][1];
|
const cell = sorted[i], x = cells.p[cell][0], y = cells.p[cell][1];
|
||||||
|
|
||||||
if (burgsTree.find(x, y, spacing) === undefined) {
|
if (burgsTree.find(x, y, spacing) === undefined) {
|
||||||
burgs.push({cell, x, y});
|
let asd = { cell, x, y/*, _port: null */ };//we did some testing on when did the port value change
|
||||||
|
/*Object.defineProperty(asd, 'port', {
|
||||||
|
get: function () {
|
||||||
|
return this._port;
|
||||||
|
},
|
||||||
|
set: function (value) {
|
||||||
|
console.warn('changed options from:', this._port, 'to', value);
|
||||||
|
this._port = value;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
*/
|
||||||
|
burgs.push(asd);
|
||||||
|
|
||||||
burgsTree.add([x, y]);
|
burgsTree.add([x, y]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -145,7 +158,7 @@
|
||||||
const cells = pack.cells, vertices = pack.vertices, features = pack.features, temp = grid.cells.temp;
|
const cells = pack.cells, vertices = pack.vertices, features = pack.features, 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) continue;
|
||||||
const i = b.cell;
|
const i = b.cell;
|
||||||
|
|
||||||
// asign port status to some coastline burgs with temp > 0 °C
|
// asign port status to some coastline burgs with temp > 0 °C
|
||||||
|
|
@ -216,21 +229,183 @@
|
||||||
|
|
||||||
return "Generic";
|
return "Generic";
|
||||||
}
|
}
|
||||||
|
//i made some changes here
|
||||||
const defineBurgFeatures = function (newburg) {
|
const defineBurgFeatures = function (newburg) {
|
||||||
const cells = pack.cells;
|
const cells = pack.cells;
|
||||||
pack.burgs.filter(b => newburg ? b.i == newburg.i : (b.i && !b.removed)).forEach(b => {
|
pack.burgs.filter(b => newburg ? b.i == newburg.i : (b.i && !b.removed)).forEach(b => {
|
||||||
const pop = b.population;
|
const pop = b.population;
|
||||||
b.citadel = b.capital || pop > 50 && P(.75) || P(.5) ? 1 : 0;
|
b.citadel = citadelGeneration(b);
|
||||||
b.plaza = pop > 50 || pop > 30 && P(.75) || pop > 10 && P(.5) || P(.25) ? 1 : 0;
|
//b.plaza = pop > 50 || pop > 30 && P(.75) || pop > 10 && P(.5) || P(.25) ? 1 : 0;
|
||||||
b.walls = b.capital || pop > 30 || pop > 20 && P(.75) || pop > 10 && P(.5) || P(.2) ? 1 : 0;
|
b.plaza = Math.sqrt(cells.road[b.cell]);
|
||||||
|
b.plaza -= b.plaza % 1;
|
||||||
|
//b.walls = b.capital || pop > 30 || pop > 20 && P(.75) || pop > 10 && P(.5) || P(.2) ? 2 : 1;
|
||||||
|
b.walls = wallGenerator(b);
|
||||||
b.shanty = pop > 30 || pop > 20 && P(.75) || b.walls && P(.75) ? 1 : 0;
|
b.shanty = pop > 30 || pop > 20 && P(.75) || b.walls && P(.75) ? 1 : 0;
|
||||||
const religion = cells.religion[b.cell];
|
const religion = cells.religion[b.cell];
|
||||||
const theocracy = pack.states[b.state].form === "Theocracy";
|
const theocracy = pack.states[b.state].form === "Theocracy";
|
||||||
b.temple = religion && theocracy || pop > 50 || pop > 35 && P(.75) || pop > 20 && P(.5) ? 1 : 0;
|
//b.temple = religion && theocracy || pop > 50 || pop > 35 && P(.75) || pop > 20 && P(.5) ? 1 : 0;
|
||||||
|
b.port = generatePortSize(b);
|
||||||
|
b.library = libraryGenerator(b);
|
||||||
|
b.temple = templeGenerator(b, religion, theocracy);
|
||||||
|
b.hospital = hospitalGenerator(b);
|
||||||
|
b.manufactory = manufactoryGenerator(b);
|
||||||
|
b.labour = labourGenerator(b);
|
||||||
|
b.pasture = pastureGenerator(b);
|
||||||
|
b.industrial = b.manufactory * b.manufactory * 15;
|
||||||
|
b.food = b.pasture * b.pasture * 5 + b.port * 100;
|
||||||
|
b.landtrade = b.plaza * 20;
|
||||||
|
b.watertrade = 10 * b.port * b.port;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
function citadelGeneration(b) {
|
||||||
|
var citadel = 0;
|
||||||
|
/* for (let pop = b.population; pop >= 5;) {
|
||||||
|
citadel++;
|
||||||
|
pop = pop - 5;
|
||||||
|
} maybe i will use it for walls instead, that depends more on population*/
|
||||||
|
if (b.capital) {
|
||||||
|
citadel += 2;
|
||||||
|
}
|
||||||
|
if (b.port) {
|
||||||
|
citadel += 1;
|
||||||
|
}
|
||||||
|
citadel += pack.states[b.state].expansionism * Math.random();
|
||||||
|
if (citadel < 0) { citadel = 0; } else {
|
||||||
|
citadel = citadel - citadel % 1;
|
||||||
|
}
|
||||||
|
return citadel
|
||||||
|
}
|
||||||
|
|
||||||
|
function wallGenerator(b) {
|
||||||
|
let wall = 0;
|
||||||
|
if (b.type === "Nomadic") {
|
||||||
|
return 0;
|
||||||
|
} else if (b.type === "Highland" || b.type === "Hunting") {
|
||||||
|
for (let pop = b.population; pop >= 10;) {
|
||||||
|
wall++;
|
||||||
|
pop = pop - 5;
|
||||||
|
}
|
||||||
|
} else if (b.type === "Lake" || b.type === "River" || b.type === "Naval" || b.type === "Generic") {
|
||||||
|
for (let pop = b.population; pop >= 5;) {
|
||||||
|
wall++;
|
||||||
|
pop = pop - 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return wall;
|
||||||
|
}
|
||||||
|
function libraryGenerator(b) {
|
||||||
|
let lib = 0;
|
||||||
|
let multip = 1;
|
||||||
|
let culture = pack.cultures[b.culture];
|
||||||
|
let cul = pack.cultures[b.culture].type;
|
||||||
|
if (cul === "Nomadic" || cul === "Hunting") { return 0 }
|
||||||
|
if (pack.states[b.state].culture === culture) {
|
||||||
|
multip = multip * 1, 5;
|
||||||
|
}
|
||||||
|
if (cul === "Naval" || cul === "Lake") {
|
||||||
|
multip = multip * 1, 5;
|
||||||
|
}
|
||||||
|
for (let mark = b.plaza; mark >= 4; mark = mark - 4) {
|
||||||
|
multip = multip * 1, 5;
|
||||||
|
}
|
||||||
|
multip = multip / Math.sqrt(pack.states[b.state].expansionism);
|
||||||
|
for (let pop = b.population; pop >= 10;) {
|
||||||
|
lib += multip;
|
||||||
|
pop = pop - 5;
|
||||||
|
}
|
||||||
|
return lib - lib % 1;
|
||||||
|
}
|
||||||
|
function templeGenerator(b, religion, theocracy) {
|
||||||
|
let faith = pack.religions[pack.cells.religion[b.cell]];
|
||||||
|
const statereligion = religion === pack.states[b.state].religion;
|
||||||
|
|
||||||
|
let multip = 1;
|
||||||
|
let temple = 0;
|
||||||
|
if (statereligion) { multip += 0, 5 }
|
||||||
|
if (theocracy) { multip = multip * 1, 5 }
|
||||||
|
if (theocracy && !statereligion) { multip = multip / 3 }
|
||||||
|
if (pack.cultures[b.culture].center == pack.religions[pack.cells.religion[b.cell]].center) {
|
||||||
|
multip = multip * 1, 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (faith.type === "Organized" || faith.type === "Heresy") { multip = multip * 1, 2 }
|
||||||
|
if (faith.type === "Cult") { multip = multip / 1, 5 }
|
||||||
|
if (faith.type === "Folk") {
|
||||||
|
multip = multip / 1, 5;
|
||||||
|
temple++;
|
||||||
|
}
|
||||||
|
for (let pop = b.population; pop >= 3;) {
|
||||||
|
temple += multip;
|
||||||
|
pop = pop - 6;
|
||||||
|
}
|
||||||
|
return temple - temple % 1;
|
||||||
|
}
|
||||||
|
function generatePortSize(b) {
|
||||||
|
let multip = 1;
|
||||||
|
let portSize = 0;
|
||||||
|
let cul = pack.cultures[b.culture].type;
|
||||||
|
if (b.port == 0) { return 0 }
|
||||||
|
else {
|
||||||
|
if (cul === "Naval") {
|
||||||
|
multip++;
|
||||||
|
}
|
||||||
|
let tradep = b.population * b.plaza;
|
||||||
|
for (; tradep >= 4;) {
|
||||||
|
portSize += multip;
|
||||||
|
tradep = tradep - 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return portSize - portSize % 1;
|
||||||
|
}
|
||||||
|
function hospitalGenerator(b) {
|
||||||
|
let multip = 1;
|
||||||
|
let hospital = 0;
|
||||||
|
let faith = pack.religions[pack.cells.religion[b.cell]];
|
||||||
|
if (faith.type === "Organized") {
|
||||||
|
multip = 1, 5
|
||||||
|
}
|
||||||
|
for (let health = Math.sqrt(b.population * (b.library + 1)); health > 4; health -= 5) {
|
||||||
|
hospital += multip;
|
||||||
|
}
|
||||||
|
return hospital - hospital % 1;
|
||||||
|
}
|
||||||
|
function manufactoryGenerator(b) {
|
||||||
|
let manufactory = 0;
|
||||||
|
let height = pack.cells.h[b.cell];
|
||||||
|
let cul = pack.cultures[b.culture].type;
|
||||||
|
if (height >= 60) {
|
||||||
|
manufactory++;
|
||||||
|
}
|
||||||
|
if (cul === "Nomadic") { manufactory -= 4 }
|
||||||
|
for (let pop = b.population; pop >= 3;) {
|
||||||
|
manufactory++;
|
||||||
|
pop = pop - 6;
|
||||||
|
}
|
||||||
|
if (manufactory <= 0) { return 0; }
|
||||||
|
else { return manufactory; }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function labourGenerator(b) {
|
||||||
|
let science = ((b.library + b.manufactory) / 2) / 3;
|
||||||
|
return science - science % 1;
|
||||||
|
}
|
||||||
|
function pastureGenerator(b) {
|
||||||
|
let herd = 0;
|
||||||
|
let multip = 1;
|
||||||
|
let culture = pack.cultures[b.culture];
|
||||||
|
let cul = pack.cultures[b.culture].type;
|
||||||
|
if (cul === "Nomadic") { multip++; }
|
||||||
|
if (culture === "Nomadic") { multip++; }
|
||||||
|
if (cul === "Naval") { multip -= 0, 5; }
|
||||||
|
for (let pop = b.population; pop >= 3;) {
|
||||||
|
herd += multip;
|
||||||
|
pop = pop - 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
return herd - herd % 1;
|
||||||
|
}
|
||||||
const drawBurgs = function () {
|
const drawBurgs = function () {
|
||||||
TIME && console.time("drawBurgs");
|
TIME && console.time("drawBurgs");
|
||||||
|
|
||||||
|
|
@ -287,28 +462,25 @@
|
||||||
// growth algorithm to assign cells to states like we did for cultures
|
// growth algorithm to assign cells to states like we did for cultures
|
||||||
const expandStates = function () {
|
const expandStates = function () {
|
||||||
TIME && console.time("expandStates");
|
TIME && console.time("expandStates");
|
||||||
const {cells, states, cultures, burgs} = pack;
|
const cells = pack.cells, states = pack.states, cultures = pack.cultures, burgs = pack.burgs;
|
||||||
|
|
||||||
cells.state = new Uint16Array(cells.i.length);
|
cells.state = new Uint16Array(cells.i.length); // cell state
|
||||||
const queue = new PriorityQueue({ comparator: (a, b) => a.p - b.p });
|
const queue = new PriorityQueue({ comparator: (a, b) => a.p - b.p });
|
||||||
const cost = [];
|
const cost = [];
|
||||||
const neutral = cells.i.length / 5000 * 2500 * neutralInput.value * statesNeutral.value; // limit cost for state growth
|
states.filter(s => s.i && !s.removed).forEach(function (s) {
|
||||||
|
cells.state[burgs[s.capital].cell] = s.i;
|
||||||
states.filter(s => s.i && !s.removed).forEach(s => {
|
const b = cells.biome[cultures[s.culture].center]; // native biome
|
||||||
const capitalCell = burgs[s.capital].cell;
|
|
||||||
cells.state[capitalCell] = s.i;
|
|
||||||
const cultureCenter = cultures[s.culture].center;
|
|
||||||
const b = cells.biome[cultureCenter]; // state native biome
|
|
||||||
queue.queue({ e: s.center, p: 0, s: s.i, b });
|
queue.queue({ e: s.center, p: 0, s: s.i, b });
|
||||||
cost[s.center] = 1;
|
cost[s.center] = 1;
|
||||||
});
|
});
|
||||||
|
const neutral = cells.i.length / 5000 * 2500 * neutralInput.value * statesNeutral.value; // limit cost for state growth
|
||||||
|
|
||||||
while (queue.length) {
|
while (queue.length) {
|
||||||
const next = queue.dequeue();
|
const next = queue.dequeue(), n = next.e, p = next.p, s = next.s, b = next.b;
|
||||||
const {e, p, s, b} = next;
|
const type = states[s].type;
|
||||||
const {type, culture} = states[s];
|
const culture = states[s].culture;
|
||||||
|
|
||||||
cells.c[e].forEach(e => {
|
cells.c[n].forEach(function (e) {
|
||||||
if (cells.state[e] && e === states[cells.state[e]].center) return; // do not overwrite capital cells
|
if (cells.state[e] && e === states[cells.state[e]].center) return; // do not overwrite capital cells
|
||||||
|
|
||||||
const cultureCost = culture === cells.culture[e] ? -9 : 100;
|
const cultureCost = culture === cells.culture[e] ? -9 : 100;
|
||||||
|
|
@ -419,7 +591,7 @@
|
||||||
lineGen.curve(d3.curveBundle.beta(1));
|
lineGen.curve(d3.curveBundle.beta(1));
|
||||||
|
|
||||||
for (const s of states) {
|
for (const s of states) {
|
||||||
if (!s.i || s.removed || !s.cells || (list && !list.includes(s.i))) continue;
|
if (!s.i || s.removed || (list && !list.includes(s.i))) continue;
|
||||||
const used = [];
|
const used = [];
|
||||||
const visualCenter = findCell(s.pole[0], s.pole[1]);
|
const visualCenter = findCell(s.pole[0], s.pole[1]);
|
||||||
const start = cells.state[visualCenter] === s.i ? visualCenter : s.center;
|
const start = cells.state[visualCenter] === s.i ? visualCenter : s.center;
|
||||||
|
|
@ -752,16 +924,20 @@
|
||||||
states[defender].campaigns.push({ name: `${trimVowels(an)}ian War`, start, end });
|
states[defender].campaigns.push({ name: `${trimVowels(an)}ian War`, start, end });
|
||||||
|
|
||||||
// attacker vassals join the war
|
// attacker vassals join the war
|
||||||
ad.forEach((r, d) => {if (r === "Suzerain") {
|
ad.forEach((r, d) => {
|
||||||
|
if (r === "Suzerain") {
|
||||||
attackers.push(d);
|
attackers.push(d);
|
||||||
war.push(`${an}'s vassal ${states[d].name} joined the war on attackers side`);
|
war.push(`${an}'s vassal ${states[d].name} joined the war on attackers side`);
|
||||||
}});
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// defender vassals join the war
|
// defender vassals join the war
|
||||||
dd.forEach((r, d) => {if (r === "Suzerain") {
|
dd.forEach((r, d) => {
|
||||||
|
if (r === "Suzerain") {
|
||||||
defenders.push(d);
|
defenders.push(d);
|
||||||
war.push(`${dn}'s vassal ${states[d].name} joined the war on defenders side`);
|
war.push(`${dn}'s vassal ${states[d].name} joined the war on defenders side`);
|
||||||
}});
|
}
|
||||||
|
});
|
||||||
|
|
||||||
ap = d3.sum(attackers.map(a => states[a].area * states[a].expansionism)); // attackers joined power
|
ap = d3.sum(attackers.map(a => states[a].area * states[a].expansionism)); // attackers joined power
|
||||||
dp = d3.sum(defenders.map(d => states[d].area * states[d].expansionism)); // defender joined power
|
dp = d3.sum(defenders.map(d => states[d].area * states[d].expansionism)); // defender joined power
|
||||||
|
|
@ -1088,8 +1264,10 @@
|
||||||
TIME && console.timeEnd("generateProvinces");
|
TIME && console.timeEnd("generateProvinces");
|
||||||
}
|
}
|
||||||
|
|
||||||
return {generate, expandStates, normalizeStates, assignColors,
|
return {
|
||||||
|
generate, expandStates, normalizeStates, assignColors,
|
||||||
drawBurgs, specifyBurgs, defineBurgFeatures, getType, drawStateLabels, collectStatistics,
|
drawBurgs, specifyBurgs, defineBurgFeatures, getType, drawStateLabels, collectStatistics,
|
||||||
generateCampaigns, generateDiplomacy, defineStateForms, getFullName, generateProvinces, updateCultures};
|
generateCampaigns, generateDiplomacy, defineStateForms, getFullName, generateProvinces, updateCultures
|
||||||
|
};
|
||||||
|
|
||||||
})));
|
})));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue