Files
Battle-for-Tismo/shared/game_state/monthly.js
T
adrien ede258d39f Added warfare depth, focused research and a reworked HUD
- Tile improvements (fortifications, radar towers, coastal cannons), trenches,
  zone of control, support-unit capture and launch transports, with parabolic
  barrage arcs drawn between attacker and target.
- Focused research that pours points straight into the chosen technology, with
  per-technology progress kept when the focus changes, plus repeatable levels.
- Popularity reworked to integer points, war and pillage effects, minority
  policies and month-over-month arrows on the nation summary.
- City progress bars, square improvement buttons, a technology tab of wide
  short cards with progress bars, transport cargo readout and double-click to
  open a city panel.
2026-09-21 01:07:36 +02:00

50 lines
1.8 KiB
JavaScript

// Month-over-month tracking for the nation summary bar. Once a calendar month
// rolls over, the nation figures captured at the start of the month that just
// ended become the baseline the current month is compared against, so every
// indicator can show whether it rose or fell since "the past month". January
// 2000 has no baseline, so it carries no change indicator.
import { unixTime } from "../game_clock.js";
export const monthlyMethods = {
// The absolute month number of an in-game hour, so a rollover is a simple
// comparison even across a year boundary.
_monthIndexOf(totalHours) {
const date = new Date(unixTime(totalHours) * 1000);
return date.getUTCFullYear() * 12 + date.getUTCMonth();
},
// Captures the starting month once the world exists.
_initMonthly() {
this._monthIndexNow = this._monthIndexOf(this.totalHours);
this._currentMonthStats = this._captureMonthlyStats();
this.monthlyStats = null;
},
// Called every hour; only a calendar-month change does any work.
_tickMonthly() {
const index = this._monthIndexOf(this.totalHours);
if (index === this._monthIndexNow) return;
// What was current at the start of the month that just ended is now the
// baseline for the new month.
this.monthlyStats = this._currentMonthStats;
this._currentMonthStats = this._captureMonthlyStats();
this._monthIndexNow = index;
},
// One record per civilisation of the indicators the summary bar compares.
_captureMonthlyStats() {
return this.civilisations.map((_, civ) => {
const headline = this._civHeadline(civ);
return {
population: headline.population,
gdp: headline.gdp,
gdpPerCapita: headline.gdpPerCapita,
popularity: this.getCivPopularity(civ),
approval: this.getCivApproval(civ),
budget: this.getBudget(civ),
};
});
},
};