Files
Battle-for-Tismo/shared/data/combat.js
T
adrien 1a9d48cdc9 Added aircraft sorties, artillery bombardment and local testing mode
- aircraft attack orders fly a sortie to the target, bomb once, return to a
  friendly airport and re-arm (two-day cooldown, charged per aircraft); rebasing
  is bounded by fuel rather than the 10-tile combat radius
- artillery and warships open a sustained hourly bombardment on a standing
  target, drawn as a red dashed line and ring while either endpoint is selected
- a game launched from localhost can enable a testing mode whose train and build
  rows offer free, instant orders; the server only honours them for a loopback
  admin in a testing game
- an open city panel now unlocks aircraft as soon as an airport finishes
2026-09-18 21:55:30 +02:00

59 lines
2.4 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,
};
// 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,
};
// 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 costs `cost` from its nation's budget, charged up
// front so bombing cannot be spammed for free.
export const AIR_STRIKE = {
cost: 10_000_000,
cooldownHours: 48,
};
// 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) };
}