v1.5.04 - Emblems layer and on map placement

This commit is contained in:
Azgaar 2021-01-29 23:41:43 +03:00
parent 968182512c
commit 549eefe7ba
12 changed files with 276 additions and 47 deletions

View file

@ -17,7 +17,7 @@
count = Math.floor(populated.length / 50);
if (!count) {
WARN && console.warn(`There are no populated cells. Cannot generate cultures`);
pack.cultures = [{name:"Wildlands", i:0, base:1, shield:"moriaOrc"}];
pack.cultures = [{name:"Wildlands", i:0, base:1, shield:"round"}];
alertMessage.innerHTML = `
The climate is harsh and people cannot live in this world.<br>
No cultures, states and burgs will be created.<br>
@ -41,6 +41,7 @@
const cultures = pack.cultures = getRandomCultures(count);
const centers = d3.quadtree();
const colors = getColors(count);
const emblemShape = document.getElementById("emblemShape").value;
cultures.forEach(function(c, i) {
const cell = c.center = placeCenter(c.sort ? c.sort : (i) => cells.s[i]);
@ -54,8 +55,26 @@
c.origin = 0;
c.code = getCode(c.name);
cells.culture[cell] = i+1;
if (emblemShape === "random") c.shield = getRandomShiled();
else if (emblemShape !== "culture" && emblemShape !== "state") c.shield = emblemShape;
});
function getRandomShiled() {
const shields = {
types: {basic: 10, regional: 2, historical: 1, specific: 1, banner: 1, simple: 2, fantasy: 1, middleEarth: 0},
basic: {heater: 12, spanish: 6, french: 1},
regional: {horsehead: 1, horsehead2: 1, polish: 1, hessen: 1, swiss: 1},
historical: {boeotian: 1, roman: 2, kite: 1, oldFrench: 5, renaissance: 2, baroque: 2},
specific: {targe: 1, targe2: 0, pavise: 5, wedged: 10},
banner: {flag: 1, pennon: 0, guidon: 0, banner: 0, dovetail: 1, gonfalon: 5, pennant: 0},
simple: {round: 12, oval: 6, vesicaPiscis: 1, square: 1, diamond: 2, no: 0},
fantasy: {fantasy1: 2, fantasy2: 2, fantasy3: 1, fantasy4: 1, fantasy5: 3},
middleEarth: {noldor: 1, gondor: 1, easterling: 1, erebor: 1, ironHills: 1, urukHai: 1, moriaOrc: 1}
}
const type = rw(shields.types);
return rw(shields[type]);
}
function placeCenter(v) {
let c, spacing = (graphWidth + graphHeight) / 2 / count;
const sorted = [...populated].sort((a, b) => v(b) - v(a)), max = Math.floor(sorted.length / 2);
@ -65,10 +84,13 @@
}
// the first culture with id 0 is for wildlands
cultures.unshift({name:"Wildlands", i:0, base:1, origin:null});
cultures.unshift({name:"Wildlands", i:0, base:1, origin:null, shield:"round"});
// make sure all bases exist in nameBases
if (!nameBases.length) {ERROR && console.error("Name base is empty, default nameBases will be applied"); nameBases = Names.getNameBases();}
if (!nameBases.length) {
ERROR && console.error("Name base is empty, default nameBases will be applied");
nameBases = Names.getNameBases();
}
cultures.forEach(c => c.base = c.base % nameBases.length);
function getRandomCultures(c) {