Skip to content

feat!: ship types, complete the models, and add production, flight and combat - #34

Merged
rolljee merged 1 commit into
masterfrom
feat/v4-types-fleets-research
Jul 25, 2026
Merged

feat!: ship types, complete the models, and add production, flight and combat#34
rolljee merged 1 commit into
masterfrom
feat/v4-types-fleets-research

Conversation

@rolljee

@rolljee rolljee commented Jul 25, 2026

Copy link
Copy Markdown
Owner

What

Takes the library from "mine cost calculators" to most of the maths a real OGame tool needs, and fixes the naming and data problems that had built up along the way.

This is a major. MIGRATION.md has the full upgrade path; every rename throws an error that points at its fix, so a test run finds the call sites for you.

The five gaps this closes

Gap What landed
No types Declarations generated from the JSDoc into types/, wired through the exports map, built by prepack. Verified against a strict TS consumer, ogamejs/types included.
Cost formula duplicated 5× metal/crystal/deut/solar-plant/fusion-reactor share cost.js and info.js. Same numbers, checked against the previous expectations.
Inconsistent signatures Every calculator takes Buildings[id], never Buildings[id].base.
base.energy was ambiguous Split into energyCost (paid to build), energyConsumption (consumed once built) and deuteriumConsumption. The energyIsCost workaround is gone.
Missing features Production bonuses, flight time, fuel, distance, speed, and a combat simulator.

Models

  • Buildings: 5 → 19 entries (storages, facilities, moon buildings).
  • New Research model, 16 technologies, with Astrophysics' 1.75 factor and its rounding to the hundred — getResearchCost(Research[124], 5) gives the exact in-game 37 600 / 75 100 / 37 600.
  • names: { en, fr } and ogameId on every entry.
  • Ships gained drive and driveUpgrades.

One data correction worth flagging: deutCost held exactly half the in-game fuel consumption on all 15 ships (light fighter 10 vs 20, cruiser 150 vs 300 — the factor of 2 was systematic). It is now fuelConsumption with the real values. If anything downstream compensated by doubling, that has to come out.

New API

// What a planet really makes per hour
Ogame.Building.getPlanetProduction(
  { metalMine: 30, crystalMine: 26, deutSynth: 24, position: 8, temperature: -23, universeSpeed: 6 },
  { plasmaTech: 15, geologist: true },
);
// → { metal: 117962, crystal: 44673, deuterium: 23668, energyConsumption: 13059, bonus: {...} }

// Is the raid worth flying?
Ogame.Fleets.getTrip(fleet, from, to, { drives: { combustion: 16, hyperspace: 12 } });
// → { distance, fleetSpeed, duration, fuel, cargo, cargoAfterFuel }

// How would it go? Seeded, so it replays and averages
Ogame.Fleets.simulateCombat(attacker, defender, { seed: 42 });
// → { winner, rounds, seed, attacker, defender, debris }

Plus getBuildingCost, getBuildTime, getStorage, getProductionBonus, getResearchTime, getDistance, getShipSpeed, getFleetSpeed, getActiveDrive, getFlightTime, getFuelConsumption.

Also fixed

  • The exports map only allowed the package root, so import Building from 'ogamejs/src/buildings/index.js' — which the 3.x README documented — never actually worked. Named subpaths added and verified by installing the tarball into a scratch project.
  • parseInfoCompteData reads its language from the report header, accepts custom labels for unsupported languages, throws readable errors instead of a bare TypeError, and returns planet mine levels as numbers (they were strings, while temperature in the same object was already a number).
  • Missiles moved from the defenses to the missiles category, which ATTRIBUTES.CATEGORIES.MISSILE had always been waiting for.

Tests

28 → 315. Expected values are derived by hand from the formulas rather than copied out of the implementation.

src/models/models.test.js asserts the invariants every model entry must hold — a complete base, a known category and drive, rapid-fire targets that resolve, structure === cost.metal + cost.crystal, no duplicate ogameId, both translations present. Adding an entry that breaks one of those fails CI.

CI runs lint, tests, and a new types job on every PR.

What I deliberately did not do

  • Lifeforms (2021) are not modelled. It is ~120 entries and I could not source the numbers; guessing them would be worse than shipping nothing. Called out under "Known gaps" in the README.
  • Drive upgrade fuel values for the three ships that switch drive (small cargo, recycler, bomber) come from community tables. The speeds are solid, the post-switch fuel figures deserve an in-game check.
  • Defense repair after combat, moon-creation odds, officers beyond the geologist, and alliance classes.

Verification

npm run lint   # clean
npm test       # 315 passed
npm run types  # clean

Also verified end to end by packing the tarball, installing it into a fresh project, and compiling a strict TypeScript consumer against it.

🤖 Generated with Claude Code

@rolljee
rolljee force-pushed the feat/v4-types-fleets-research branch from dc7257a to bb5eeec Compare July 25, 2026 07:04
…d combat

Rounds out the library from "mine costs" to most of the maths a calculator
needs, and fixes the naming and data problems that had accumulated.

Models
- Buildings goes from 5 to 19 entries: storages, facilities and moon buildings.
- New Research model with the 16 technologies, Astrophysics rounding included.
- Every entry carries `names: { en, fr }` and `ogameId`, the id the game uses.
- `base` fields are named after what they are: `energyCost` (paid to build),
  `energyConsumption` (consumed once built) and `deuteriumConsumption` replace
  the `energy`/`consumption` pair that meant different things per building.
- `deutCost` held half the real fuel consumption on all 15 ships; corrected and
  renamed `fuelConsumption`. Ships also gained `drive` and `driveUpgrades`.
- models.test.js asserts the invariants every entry must hold, so a future
  entry that is incomplete or inconsistent fails CI.

Calculators
- The five mine and plant calculators no longer reimplement
  `base * factor ** (level - 1)`; they share cost.js and info.js, and all
  return the same seven fields. Behaviour is unchanged, verified against the
  previous expectations.
- They take the whole entry instead of its `base`, like everything else, and
  throw a message pointing at the fix when handed a `base`.
- New: getBuildingCost, getBuildTime, getStorage, getPlanetProduction,
  getProductionBonus, getResearchCost, getResearchTime.

Fleets
- getDistance, getShipSpeed, getFleetSpeed, getActiveDrive, getFlightTime,
  getFuelConsumption, getTrip.
- simulateCombat: six rounds, rapid fire, shield bounce and explosion odds,
  seedable so a battle can be replayed and averaged.

Types
- TypeScript declarations generated from the JSDoc into types/, wired through
  the exports map and built by prepack. Verified against a strict TS consumer.

Also
- The exports map only allowed the package root, so the subpath import the
  README documented never worked. Named subpaths added.
- README and CONTRIBUTING rewritten for the new surface, and MIGRATION.md added.
- infocompte reads its language from the report, accepts custom labels, throws
  readable errors, and returns numbers for mine levels.

BREAKING CHANGE: mine and plant calculators now take `Buildings[id]` rather
than `Buildings[id].base`, and return `energyCost`/`energyConsumption`/
`deuteriumConsumption` instead of `energy`/`consumption`.

BREAKING CHANGE: model fields renamed — `entry.name` to `entry.names.fr`,
`base.deutrium` to `base.deuterium`, `base.energy` to `base.energyConsumption`
or `base.energyCost`, `base.consumption` to `base.deuteriumConsumption`,
`fret` to `cargo`, `cost.deut` to `cost.deuterium`, and `deutCost` to
`fuelConsumption` with corrected values (they were half the in-game figure).

BREAKING CHANGE: parseInfoCompteData returns planet mine levels as numbers
instead of strings, and getDebris returns an extra `deuterium` key.

See MIGRATION.md for the full upgrade path.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@rolljee
rolljee force-pushed the feat/v4-types-fleets-research branch from bb5eeec to af69541 Compare July 25, 2026 07:18
@rolljee
rolljee merged commit 59c7f46 into master Jul 25, 2026
3 checks passed
@rolljee
rolljee deleted the feat/v4-types-fleets-research branch July 25, 2026 07:19
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 4.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant