Files
Battle-for-Tismo/shared/data/combat.js
T

42 lines
1.7 KiB
JavaScript

// Combat, garrison and pillage rules. Shared so the server (which applies them)
// and the browser (which forecasts them) compute the same numbers.
// Units garrisoned in a friendly city regain this many hit points each hour.
export const CITY_GARRISON_HEAL_PER_HOUR = 1;
// Combat is fought on a single tile: the attacking stack charges onto the
// defending stack's tile and the two share it until one side is wiped out.
// Every day a battle lasts the tile loses this fraction of its population and
// of its GDP per capita. Once the fighting stops, GDP per capita recovers by
// `recoveryPerDay` each day, starting `recoveryDelayDays` after the last battle.
export const BATTLE = {
populationLossPerDay: 0.3,
gdpPerCapitaLossPerDay: 0.3,
recoveryDelayDays: 30,
recoveryPerDay: 100,
};
// Pillaging: each unit removes this fraction of the tile's remaining
// population, cuts its GDP per capita by this multiplier, and heals one hit
// point per this many people driven off.
export const PILLAGE = {
populationLoss: 0.1,
gdpPenalty: 0.7,
healPerPeople: 1000,
};
// The result of pillaging a tile with `count` units in sequence, starting from
// its current population. Each step removes a tenth of what is left and heals
// for the people it removed; the GDP-per-capita multiplier compounds. Shared so
// the server and the forecast tooltip compute the same numbers.
export function pillageSteps(population, count) {
const steps = [];
let remaining = population;
for (let i = 0; i < count; i++) {
const removed = remaining * PILLAGE.populationLoss;
remaining -= removed;
steps.push({ removed, remaining, heal: removed / PILLAGE.healPerPeople });
}
return { steps, gdpMultiplier: Math.pow(PILLAGE.gdpPenalty, count) };
}