mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 09:41:24 +01:00
generate state salesTax
This commit is contained in:
parent
0fb6363f2a
commit
c92862b316
4 changed files with 15 additions and 10 deletions
|
|
@ -74,6 +74,7 @@ window.BurgsAndStates = (function () {
|
|||
const states = [{i: 0, name: 'Neutrals'}];
|
||||
const colors = getColors(burgs.length - 1);
|
||||
const each5th = each(5);
|
||||
const maxExpansionism = +powerInput.value;
|
||||
|
||||
burgs.forEach(function (b, i) {
|
||||
if (!i) return; // skip first element
|
||||
|
|
@ -86,14 +87,15 @@ window.BurgsAndStates = (function () {
|
|||
b.capital = 1;
|
||||
|
||||
// states data
|
||||
const expansionism = rn(Math.random() * powerInput.value + 1, 1);
|
||||
const expansionism = rn(Math.random() * maxExpansionism + 1, 1);
|
||||
const basename = b.name.length < 9 && each5th(b.cell) ? b.name : Names.getCultureShort(b.culture);
|
||||
const name = Names.getState(basename, b.culture);
|
||||
const type = cultures[b.culture].type;
|
||||
const salesTax = rn(Math.random() * 0.3, 2);
|
||||
|
||||
const coa = COA.generate(null, null, null, type);
|
||||
coa.shield = COA.getShield(b.culture, null);
|
||||
states.push({i, color: colors[i - 1], name, expansionism, capital: i, type, center: b.cell, culture: b.culture, coa});
|
||||
states.push({i, color: colors[i - 1], name, expansionism, capital: i, type, center: b.cell, culture: b.culture, coa, salesTax});
|
||||
cells.burg[b.cell] = i;
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -761,6 +761,9 @@ function parseLoadedData(data) {
|
|||
rivers.attr('style', null);
|
||||
borders.attr('style', null);
|
||||
}
|
||||
|
||||
// ecomonics:
|
||||
// calculate salesTax for all states
|
||||
})();
|
||||
|
||||
void (function checkDataIntegrity() {
|
||||
|
|
|
|||
|
|
@ -65,25 +65,25 @@ window.Trade = (function () {
|
|||
|
||||
const distance = Math.hypot(x - x0, y - y0);
|
||||
const transportFee = (distance / DEFAULT_TRANSPORT_DIST) ** 0.8 || 0.02;
|
||||
const salesTax = states[state].salesTax || 0.1;
|
||||
const salesTax = states[state].salesTax || 0;
|
||||
|
||||
for (const resourceId in produced) {
|
||||
const production = produced[resourceId];
|
||||
const quantity = production - consumption;
|
||||
if (quantity < 1) continue;
|
||||
|
||||
const {value} = Resources.get(+resourceId);
|
||||
const {value, name} = Resources.get(+resourceId);
|
||||
|
||||
const basePrice = value * quantity;
|
||||
const transportCost = rn((value * quantity) ** 0.5 * transportFee, 2);
|
||||
const transportCost = rn((value * quantity) ** 0.5 * transportFee, 1);
|
||||
const netPrice = basePrice - transportCost;
|
||||
|
||||
const stateIncome = rn(netPrice * salesTax, 2);
|
||||
const burgIncome = rn(netPrice - stateIncome, 2);
|
||||
const stateIncome = rn(netPrice * salesTax, 1);
|
||||
const burgIncome = rn(netPrice - stateIncome, 1);
|
||||
|
||||
if (burgIncome < 1 || burgIncome < basePrice / 4) continue;
|
||||
|
||||
trade.deals.push({resourceId: +resourceId, quantity, exporter: i, tradeCenter: centerId, basePrice, transportCost, stateIncome, burgIncome});
|
||||
trade.deals.push({resourceId: +resourceId, name, quantity, exporter: i, tradeCenter: centerId, basePrice, transportCost, stateIncome, burgIncome});
|
||||
|
||||
if (!goods[resourceId]) goods[resourceId] = quantity;
|
||||
else goods[resourceId] += quantity;
|
||||
|
|
|
|||
|
|
@ -141,13 +141,13 @@ function editBurg(id) {
|
|||
function getExport(dealsArray) {
|
||||
if (!dealsArray.length) return 'no';
|
||||
|
||||
const totalIncome = d3.sum(dealsArray.map((deal) => deal.burgIncome));
|
||||
const totalIncome = rn(d3.sum(dealsArray.map((deal) => deal.burgIncome)));
|
||||
const exported = dealsArray.map((deal) => {
|
||||
const {resourceId, quantity, burgIncome} = deal;
|
||||
const {name, unit, icon} = Resources.get(resourceId);
|
||||
const unitName = quantity > 1 ? unit + 's' : unit;
|
||||
|
||||
return `<span data-tip="${name}: ${quantity} ${unitName}. Income: ${burgIncome}">
|
||||
return `<span data-tip="${name}: ${quantity} ${unitName}. Income: ${rn(burgIncome)}">
|
||||
<svg class="resIcon"><use href="#${icon}"></svg>
|
||||
<span style="margin: 0 0.2em 0 -0.2em">${quantity}</span>
|
||||
</span>`;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue