mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-22 03:51:23 +01:00
fix: #1041
This commit is contained in:
parent
c282ecbb37
commit
1faaee48e0
4 changed files with 154 additions and 37 deletions
|
|
@ -8045,7 +8045,7 @@
|
||||||
<script src="modules/burgs-and-states.js?v=1.92.00"></script>
|
<script src="modules/burgs-and-states.js?v=1.92.00"></script>
|
||||||
<script src="modules/routes-generator.js"></script>
|
<script src="modules/routes-generator.js"></script>
|
||||||
<script src="modules/religions-generator.js?v=1.93.08"></script>
|
<script src="modules/religions-generator.js?v=1.93.08"></script>
|
||||||
<script src="modules/military-generator.js"></script>
|
<script src="modules/military-generator.js?v=1.96.00"></script>
|
||||||
<script src="modules/markers-generator.js?v=1.93.04"></script>
|
<script src="modules/markers-generator.js?v=1.93.04"></script>
|
||||||
<script src="modules/coa-generator.js?v=1.91.05"></script>
|
<script src="modules/coa-generator.js?v=1.91.05"></script>
|
||||||
<script src="modules/submap.js?v=1.96.00"></script>
|
<script src="modules/submap.js?v=1.96.00"></script>
|
||||||
|
|
|
||||||
|
|
@ -815,5 +815,16 @@ export function resolveVersionConflicts(version) {
|
||||||
fitScaleBar(scaleBar, svgWidth, svgHeight);
|
fitScaleBar(scaleBar, svgWidth, svgHeight);
|
||||||
|
|
||||||
if (!layerIsOn("toggleScaleBar")) scaleBar.style("display", "none");
|
if (!layerIsOn("toggleScaleBar")) scaleBar.style("display", "none");
|
||||||
|
|
||||||
|
// v1.96.00 changed coloring approach for regiments
|
||||||
|
armies.selectAll(":scope > g").each(function () {
|
||||||
|
const fill = this.getAttribute("fill");
|
||||||
|
if (!fill) return;
|
||||||
|
const darkerColor = d3.color(fill).darker().hex();
|
||||||
|
this.setAttribute("color", darkerColor);
|
||||||
|
this.querySelectorAll("g > rect:nth-child(2)").forEach(rect => {
|
||||||
|
rect.setAttribute("fill", "currentColor");
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1394,6 +1394,7 @@ function openStateMergeDialog() {
|
||||||
|
|
||||||
function mergeStates(statesToMerge, rulingStateId) {
|
function mergeStates(statesToMerge, rulingStateId) {
|
||||||
const rulingState = pack.states[rulingStateId];
|
const rulingState = pack.states[rulingStateId];
|
||||||
|
const rulingStateArmy = byId("army" + rulingStateId);
|
||||||
|
|
||||||
// remove states to be merged
|
// remove states to be merged
|
||||||
statesToMerge.forEach(stateId => {
|
statesToMerge.forEach(stateId => {
|
||||||
|
|
@ -1410,27 +1411,25 @@ function openStateMergeDialog() {
|
||||||
emblems.select(`#stateEmblems > use[data-i='${stateId}']`).remove();
|
emblems.select(`#stateEmblems > use[data-i='${stateId}']`).remove();
|
||||||
|
|
||||||
// add merged state regiments to the ruling state
|
// add merged state regiments to the ruling state
|
||||||
state.military.forEach(m => {
|
state.military.forEach(regiment => {
|
||||||
const oldId = `regiment${stateId}-${m.i}`;
|
const oldId = `regiment${stateId}-${regiment.i}`;
|
||||||
|
const newIndex = rulingState.military.length;
|
||||||
const newRegiment = {...m, i: rulingState.military.length};
|
rulingState.military.push({...regiment, i: newIndex});
|
||||||
rulingState.military.push(newRegiment);
|
const newId = `regiment${rulingStateId}-${newIndex}`;
|
||||||
|
|
||||||
const newId = `regiment${rulingStateId}-${newRegiment.i}`;
|
|
||||||
|
|
||||||
const note = notes.find(n => n.id === oldId);
|
const note = notes.find(n => n.id === oldId);
|
||||||
if (note) note.id = newId;
|
if (note) note.id = newId;
|
||||||
|
|
||||||
const rulingStateArmy = armies.select("g#army" + rulingStateId);
|
const element = byId(oldId);
|
||||||
armies
|
if (element) {
|
||||||
.select("g#army" + stateId)
|
element.id = newId;
|
||||||
.selectAll("g")
|
element.dataset.state = rulingStateId;
|
||||||
.each(function () {
|
element.dataset.i = newIndex;
|
||||||
this.setAttribute("id", newId);
|
rulingStateArmy.appendChild(element);
|
||||||
rulingStateArmy.node().appendChild(this);
|
}
|
||||||
});
|
|
||||||
armies.select("g#army" + stateId).remove();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
armies.select("g#army" + stateId).remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
// reassing burgs
|
// reassing burgs
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,18 @@ window.Military = (function () {
|
||||||
|
|
||||||
const expn = d3.sum(valid.map(s => s.expansionism)); // total expansion
|
const expn = d3.sum(valid.map(s => s.expansionism)); // total expansion
|
||||||
const area = d3.sum(valid.map(s => s.area)); // total area
|
const area = d3.sum(valid.map(s => s.area)); // total area
|
||||||
const rate = {x: 0, Ally: -0.2, Friendly: -0.1, Neutral: 0, Suspicion: 0.1, Enemy: 1, Unknown: 0, Rival: 0.5, Vassal: 0.5, Suzerain: -0.5};
|
const rate = {
|
||||||
|
x: 0,
|
||||||
|
Ally: -0.2,
|
||||||
|
Friendly: -0.1,
|
||||||
|
Neutral: 0,
|
||||||
|
Suspicion: 0.1,
|
||||||
|
Enemy: 1,
|
||||||
|
Unknown: 0,
|
||||||
|
Rival: 0.5,
|
||||||
|
Vassal: 0.5,
|
||||||
|
Suzerain: -0.5
|
||||||
|
};
|
||||||
|
|
||||||
const stateModifier = {
|
const stateModifier = {
|
||||||
melee: {Nomadic: 0.5, Highland: 1.2, Lake: 1, Naval: 0.7, Hunting: 1.2, River: 1.1},
|
melee: {Nomadic: 0.5, Highland: 1.2, Lake: 1, Naval: 0.7, Hunting: 1.2, River: 1.1},
|
||||||
|
|
@ -24,14 +35,59 @@ window.Military = (function () {
|
||||||
};
|
};
|
||||||
|
|
||||||
const cellTypeModifier = {
|
const cellTypeModifier = {
|
||||||
nomadic: {melee: 0.2, ranged: 0.5, mounted: 3, machinery: 0.4, naval: 0.3, armored: 1.6, aviation: 1, magical: 0.5},
|
nomadic: {
|
||||||
wetland: {melee: 0.8, ranged: 2, mounted: 0.3, machinery: 1.2, naval: 1.0, armored: 0.2, aviation: 0.5, magical: 0.5},
|
melee: 0.2,
|
||||||
highland: {melee: 1.2, ranged: 1.6, mounted: 0.3, machinery: 3, naval: 1.0, armored: 0.8, aviation: 0.3, magical: 2}
|
ranged: 0.5,
|
||||||
|
mounted: 3,
|
||||||
|
machinery: 0.4,
|
||||||
|
naval: 0.3,
|
||||||
|
armored: 1.6,
|
||||||
|
aviation: 1,
|
||||||
|
magical: 0.5
|
||||||
|
},
|
||||||
|
wetland: {
|
||||||
|
melee: 0.8,
|
||||||
|
ranged: 2,
|
||||||
|
mounted: 0.3,
|
||||||
|
machinery: 1.2,
|
||||||
|
naval: 1.0,
|
||||||
|
armored: 0.2,
|
||||||
|
aviation: 0.5,
|
||||||
|
magical: 0.5
|
||||||
|
},
|
||||||
|
highland: {
|
||||||
|
melee: 1.2,
|
||||||
|
ranged: 1.6,
|
||||||
|
mounted: 0.3,
|
||||||
|
machinery: 3,
|
||||||
|
naval: 1.0,
|
||||||
|
armored: 0.8,
|
||||||
|
aviation: 0.3,
|
||||||
|
magical: 2
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const burgTypeModifier = {
|
const burgTypeModifier = {
|
||||||
nomadic: {melee: 0.3, ranged: 0.8, mounted: 3, machinery: 0.4, naval: 1.0, armored: 1.6, aviation: 1, magical: 0.5},
|
nomadic: {
|
||||||
wetland: {melee: 1, ranged: 1.6, mounted: 0.2, machinery: 1.2, naval: 1.0, armored: 0.2, aviation: 0.5, magical: 0.5},
|
melee: 0.3,
|
||||||
|
ranged: 0.8,
|
||||||
|
mounted: 3,
|
||||||
|
machinery: 0.4,
|
||||||
|
naval: 1.0,
|
||||||
|
armored: 1.6,
|
||||||
|
aviation: 1,
|
||||||
|
magical: 0.5
|
||||||
|
},
|
||||||
|
wetland: {
|
||||||
|
melee: 1,
|
||||||
|
ranged: 1.6,
|
||||||
|
mounted: 0.2,
|
||||||
|
machinery: 1.2,
|
||||||
|
naval: 1.0,
|
||||||
|
armored: 0.2,
|
||||||
|
aviation: 0.5,
|
||||||
|
magical: 0.5
|
||||||
|
},
|
||||||
highland: {melee: 1.2, ranged: 2, mounted: 0.3, machinery: 3, naval: 1.0, armored: 0.8, aviation: 0.3, magical: 2}
|
highland: {melee: 1.2, ranged: 2, mounted: 0.3, machinery: 3, naval: 1.0, armored: 0.8, aviation: 0.3, magical: 2}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -40,8 +96,16 @@ window.Military = (function () {
|
||||||
const d = s.diplomacy;
|
const d = s.diplomacy;
|
||||||
|
|
||||||
const expansionRate = minmax(s.expansionism / expn / (s.area / area), 0.25, 4); // how much state expansionism is realized
|
const expansionRate = minmax(s.expansionism / expn / (s.area / area), 0.25, 4); // how much state expansionism is realized
|
||||||
const diplomacyRate = d.some(d => d === "Enemy") ? 1 : d.some(d => d === "Rival") ? 0.8 : d.some(d => d === "Suspicion") ? 0.5 : 0.1; // peacefulness
|
const diplomacyRate = d.some(d => d === "Enemy")
|
||||||
const neighborsRateRaw = s.neighbors.map(n => (n ? pack.states[n].diplomacy[s.i] : "Suspicion")).reduce((s, r) => (s += rate[r]), 0.5);
|
? 1
|
||||||
|
: d.some(d => d === "Rival")
|
||||||
|
? 0.8
|
||||||
|
: d.some(d => d === "Suspicion")
|
||||||
|
? 0.5
|
||||||
|
: 0.1; // peacefulness
|
||||||
|
const neighborsRateRaw = s.neighbors
|
||||||
|
.map(n => (n ? pack.states[n].diplomacy[s.i] : "Suspicion"))
|
||||||
|
.reduce((s, r) => (s += rate[r]), 0.5);
|
||||||
const neighborsRate = minmax(neighborsRateRaw, 0.3, 3); // neighbors rate
|
const neighborsRate = minmax(neighborsRateRaw, 0.3, 3); // neighbors rate
|
||||||
s.alert = minmax(rn(expansionRate * diplomacyRate * neighborsRate, 2), 0.1, 5); // alert rate (area modifier)
|
s.alert = minmax(rn(expansionRate * diplomacyRate * neighborsRate, 2), 0.1, 5); // alert rate (area modifier)
|
||||||
s.temp.platoons = [];
|
s.temp.platoons = [];
|
||||||
|
|
@ -86,8 +150,10 @@ window.Military = (function () {
|
||||||
|
|
||||||
let modifier = cells.pop[i] / 100; // basic rural army in percentages
|
let modifier = cells.pop[i] / 100; // basic rural army in percentages
|
||||||
if (culture !== stateObj.culture) modifier = stateObj.form === "Union" ? modifier / 1.2 : modifier / 2; // non-dominant culture
|
if (culture !== stateObj.culture) modifier = stateObj.form === "Union" ? modifier / 1.2 : modifier / 2; // non-dominant culture
|
||||||
if (religion !== cells.religion[stateObj.center]) modifier = stateObj.form === "Theocracy" ? modifier / 2.2 : modifier / 1.4; // non-dominant religion
|
if (religion !== cells.religion[stateObj.center])
|
||||||
if (cells.f[i] !== cells.f[stateObj.center]) modifier = stateObj.type === "Naval" ? modifier / 1.2 : modifier / 1.8; // different landmass
|
modifier = stateObj.form === "Theocracy" ? modifier / 2.2 : modifier / 1.4; // non-dominant religion
|
||||||
|
if (cells.f[i] !== cells.f[stateObj.center])
|
||||||
|
modifier = stateObj.type === "Naval" ? modifier / 1.2 : modifier / 1.8; // different landmass
|
||||||
const type = getType(i);
|
const type = getType(i);
|
||||||
|
|
||||||
for (const unit of options.military) {
|
for (const unit of options.military) {
|
||||||
|
|
@ -111,7 +177,17 @@ window.Military = (function () {
|
||||||
n = 1;
|
n = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
stateObj.temp.platoons.push({cell: i, a: total, t: total, x, y, u: unit.name, n, s: unit.separate, type: unit.type});
|
stateObj.temp.platoons.push({
|
||||||
|
cell: i,
|
||||||
|
a: total,
|
||||||
|
t: total,
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
u: unit.name,
|
||||||
|
n,
|
||||||
|
s: unit.separate,
|
||||||
|
type: unit.type
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -153,7 +229,17 @@ window.Military = (function () {
|
||||||
n = 1;
|
n = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
stateObj.temp.platoons.push({cell: b.cell, a: total, t: total, x, y, u: unit.name, n, s: unit.separate, type: unit.type});
|
stateObj.temp.platoons.push({
|
||||||
|
cell: b.cell,
|
||||||
|
a: total,
|
||||||
|
t: total,
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
u: unit.name,
|
||||||
|
n,
|
||||||
|
s: unit.separate,
|
||||||
|
type: unit.type
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -261,7 +347,8 @@ window.Military = (function () {
|
||||||
const army = armies
|
const army = armies
|
||||||
.append("g")
|
.append("g")
|
||||||
.attr("id", "army" + s)
|
.attr("id", "army" + s)
|
||||||
.attr("fill", baseColor);
|
.attr("fill", baseColor)
|
||||||
|
.attr("color", darkerColor);
|
||||||
|
|
||||||
const g = army
|
const g = army
|
||||||
.selectAll("g")
|
.selectAll("g")
|
||||||
|
|
@ -282,7 +369,7 @@ window.Military = (function () {
|
||||||
.attr("y", d => d.y)
|
.attr("y", d => d.y)
|
||||||
.text(d => getTotal(d));
|
.text(d => getTotal(d));
|
||||||
g.append("rect")
|
g.append("rect")
|
||||||
.attr("fill", darkerColor)
|
.attr("fill", "currentColor")
|
||||||
.attr("x", d => x(d) - h)
|
.attr("x", d => x(d) - h)
|
||||||
.attr("y", d => y(d))
|
.attr("y", d => y(d))
|
||||||
.attr("width", h)
|
.attr("width", h)
|
||||||
|
|
@ -304,12 +391,13 @@ window.Military = (function () {
|
||||||
let army = armies.select("g#army" + s);
|
let army = armies.select("g#army" + s);
|
||||||
if (!army.size()) {
|
if (!army.size()) {
|
||||||
const baseColor = pack.states[s].color[0] === "#" ? pack.states[s].color : "#999";
|
const baseColor = pack.states[s].color[0] === "#" ? pack.states[s].color : "#999";
|
||||||
|
const darkerColor = d3.color(army.attr("fill")).darker().hex();
|
||||||
army = armies
|
army = armies
|
||||||
.append("g")
|
.append("g")
|
||||||
.attr("id", "army" + s)
|
.attr("id", "army" + s)
|
||||||
.attr("fill", baseColor);
|
.attr("fill", baseColor)
|
||||||
|
.attr("color", darkerColor);
|
||||||
}
|
}
|
||||||
const darkerColor = d3.color(army.attr("fill")).darker().hex();
|
|
||||||
|
|
||||||
const g = army
|
const g = army
|
||||||
.append("g")
|
.append("g")
|
||||||
|
|
@ -320,7 +408,7 @@ window.Military = (function () {
|
||||||
g.append("rect").attr("x", x1).attr("y", y1).attr("width", w).attr("height", h);
|
g.append("rect").attr("x", x1).attr("y", y1).attr("width", w).attr("height", h);
|
||||||
g.append("text").attr("x", reg.x).attr("y", reg.y).text(getTotal(reg));
|
g.append("text").attr("x", reg.x).attr("y", reg.y).text(getTotal(reg));
|
||||||
g.append("rect")
|
g.append("rect")
|
||||||
.attr("fill", darkerColor)
|
.attr("fill", "currentColor")
|
||||||
.attr("x", x1 - h)
|
.attr("x", x1 - h)
|
||||||
.attr("y", y1)
|
.attr("y", y1)
|
||||||
.attr("width", h)
|
.attr("width", h)
|
||||||
|
|
@ -379,7 +467,13 @@ window.Military = (function () {
|
||||||
// get default regiment emblem
|
// get default regiment emblem
|
||||||
const getEmblem = function (r) {
|
const getEmblem = function (r) {
|
||||||
if (!r.n && !Object.values(r.u).length) return "🔰"; // "Newbie" regiment without troops
|
if (!r.n && !Object.values(r.u).length) return "🔰"; // "Newbie" regiment without troops
|
||||||
if (!r.n && pack.states[r.state].form === "Monarchy" && pack.cells.burg[r.cell] && pack.burgs[pack.cells.burg[r.cell]].capital) return "👑"; // "Royal" regiment based in capital
|
if (
|
||||||
|
!r.n &&
|
||||||
|
pack.states[r.state].form === "Monarchy" &&
|
||||||
|
pack.cells.burg[r.cell] &&
|
||||||
|
pack.burgs[pack.cells.burg[r.cell]].capital
|
||||||
|
)
|
||||||
|
return "👑"; // "Royal" regiment based in capital
|
||||||
const mainUnit = Object.entries(r.u).sort((a, b) => b[1] - a[1])[0][0]; // unit with more troops in regiment
|
const mainUnit = Object.entries(r.u).sort((a, b) => b[1] - a[1])[0][0]; // unit with more troops in regiment
|
||||||
const unit = options.military.find(u => u.name === mainUnit);
|
const unit = options.military.find(u => u.name === mainUnit);
|
||||||
return unit.icon;
|
return unit.icon;
|
||||||
|
|
@ -400,7 +494,9 @@ window.Military = (function () {
|
||||||
.map(t => `— ${t}: ${r.u[t]}`)
|
.map(t => `— ${t}: ${r.u[t]}`)
|
||||||
.join("\r\n")
|
.join("\r\n")
|
||||||
: null;
|
: null;
|
||||||
const troops = composition ? `\r\n\r\nRegiment composition in ${options.year} ${options.eraShort}:\r\n${composition}.` : "";
|
const troops = composition
|
||||||
|
? `\r\n\r\nRegiment composition in ${options.year} ${options.eraShort}:\r\n${composition}.`
|
||||||
|
: "";
|
||||||
|
|
||||||
const campaign = s.campaigns ? ra(s.campaigns) : null;
|
const campaign = s.campaigns ? ra(s.campaigns) : null;
|
||||||
const year = campaign ? rand(campaign.start, campaign.end) : gauss(options.year - 100, 150, 1, options.year - 6);
|
const year = campaign ? rand(campaign.start, campaign.end) : gauss(options.year - 100, 150, 1, options.year - 6);
|
||||||
|
|
@ -409,5 +505,16 @@ window.Military = (function () {
|
||||||
notes.push({id: `regiment${s.i}-${r.i}`, name: `${r.icon} ${r.name}`, legend});
|
notes.push({id: `regiment${s.i}-${r.i}`, name: `${r.icon} ${r.name}`, legend});
|
||||||
};
|
};
|
||||||
|
|
||||||
return {generate, redraw, getDefaultOptions, getName, generateNote, drawRegiments, drawRegiment, moveRegiment, getTotal, getEmblem};
|
return {
|
||||||
|
generate,
|
||||||
|
redraw,
|
||||||
|
getDefaultOptions,
|
||||||
|
getName,
|
||||||
|
generateNote,
|
||||||
|
drawRegiments,
|
||||||
|
drawRegiment,
|
||||||
|
moveRegiment,
|
||||||
|
getTotal,
|
||||||
|
getEmblem
|
||||||
|
};
|
||||||
})();
|
})();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue