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

100 lines
4.1 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 production per head. Once the fighting stops, production recovers by
// `recoveryPerDay` each day, starting `recoveryDelayDays` after the last battle.
export const BATTLE = {
populationLossPerDay: 0.3,
productionLossPerDay: 0.3,
recoveryDelayDays: 30,
recoveryPerDay: 100,
// Structures on a battlefield take this much damage each day of fighting.
structureDamagePerDay: 120,
};
// Pillaging: each unit removes this fraction of the tile's remaining
// population, cuts its production per head by this multiplier, and heals one
// hit point per this many people driven off.
export const PILLAGE = {
populationLoss: 0.1,
productionPenalty: 0.7,
healPerPeople: 1000,
};
// Trenches: infantry dug into a tile are much harder to dislodge, at the cost
// of the local production. The defense figures are multipliers on a unit's base
// defense; melee attackers get no bonus, artillery is heavily blunted.
export const TRENCH = {
productionMultiplier: 0.8,
meleeDefenseMultiplier: 2.0,
artilleryDefenseMultiplier: 3.0,
};
// Sustained bombardment: a ground or naval battery ordered onto a target fires
// one volley every in-game hour. Each volley deals this fraction of the damage
// a single strike would (attack minus the defender's effective defense), so a
// unit under fire is worn down over many hours instead of erased in one salvo.
export const BOMBARD = {
hourlyDamageFraction: 0.1,
};
// Bombarding a city that has no garrison left: each point of damage kills this
// many people and leaves the usual battle scar on its tile. A blow can also
// knock a building down a level; each building rolls its own chance per point
// of damage, scaled by its `destructionResistance` (wartime shelters resist
// almost all of it and never shield the rest of the city).
export const CITY_BOMBARD = {
populationPerDamage: 10,
buildingDestructionChancePerDamage: 0.0004,
};
// Aircraft sorties: a plane flies to its target, bombs once, returns to a
// friendly airport and then cannot strike again for `cooldownHours` (two days).
// Each attacking aircraft burns munitions from its nation's stores (see
// RESOURCE_RULES.combatConsumption.airStrike), charged up front so bombing
// cannot be spammed for free.
export const AIR_STRIKE = {
cooldownHours: 48,
};
// A city's air defense fires one volley at a hostile aircraft the moment it
// enters the city's tile. Damage scales with the building's level.
export const AIR_DEFENSE = {
damagePerLevel: 150,
};
// Taking a non-melee unit -- a gun, an aircraft -- is risky: four times in five
// the crew spikes or scuttles it rather than let it be turned around.
export const CAPTURE = {
destroyChance: 0.8,
};
// A nuclear detonation: nine people in ten on the tile are killed, every
// building and improvement there is flattened except the ones built to survive
// a bomb (bunkers, fortifications), and the horror costs every nation standing.
export const WMD = {
populationSurvivorFraction: 0.1,
popularityPenalty: 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 production 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, productionMultiplier: Math.pow(PILLAGE.productionPenalty, count) };
}