feat(ui): Phase 30 ship-class calculator with goal-seek and reach circles
Fuse the standalone ship-class designer (Phases 17/18) into a sidebar calculator: live mass/speed/attack/defence/bombing results, a planet build-rate readout, single-target goal-seek, a modernization-cost mode, and auto reach circles on the map for the selected planet. pkg/calc becomes the single source for the new math (no mirroring): extract BombingPower from the engine model and the per-turn ship-production loop from controller.ProduceShip into pkg/calc (engine now delegates), and add inverse goal-seek solvers in pkg/calc/solve.go. Thin-bridge the combat, planet-build, and solver functions through ui/core/calc + ui/wasm and rebuild core.wasm. Remove the standalone designer view/route; the ship-classes table and the view/bottom menus open the calculator via a shared request store. Docs: rewrite ui/PLAN.md Phase 30, adjust Phase 34 (realistic forecast + CAP/COL ownership), add ui/docs/calculator-ux.md, extend calc-bridge.md, fix navigation.md; remove ui/CALCULATOR.md. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
+41
-4
@@ -22,10 +22,11 @@ func PlanetProduceShipMass(L, Mat, Res float64) float64 {
|
||||
// resources is expected to be positive in normal play; the helper
|
||||
// guards against a non-positive value by collapsing the material-
|
||||
// farming term to zero, which keeps callers numerically stable on
|
||||
// pathological synthetic data. Mirrors the per-iteration math inside
|
||||
// the engine's controller.ProduceShip so both surfaces — and the
|
||||
// legacy-report-to-json dev tool that needs to derive prod_used from
|
||||
// percent — share the same formula.
|
||||
// pathological synthetic data. [ProduceShipsInTurn] composes this cost
|
||||
// into the per-turn build loop that the engine's controller.ProduceShip
|
||||
// delegates to, so the engine, the calculator, and the
|
||||
// legacy-report-to-json dev tool (which derives prod_used from percent)
|
||||
// all share one formula.
|
||||
func ShipBuildCost(shipMass, material, resources float64) float64 {
|
||||
matNeed := shipMass - material
|
||||
if matNeed < 0 {
|
||||
@@ -37,3 +38,39 @@ func ShipBuildCost(shipMass, material, resources float64) float64 {
|
||||
}
|
||||
return ShipProductionCost(shipMass) + matFarm
|
||||
}
|
||||
|
||||
// ProduceShipsInTurn simulates one turn of ship production on a planet
|
||||
// that has productionAvailable production units to spend, a material
|
||||
// stockpile, a resources rating, building ships of empty mass shipMass.
|
||||
// It returns the number of whole ships completed this turn, the material
|
||||
// left afterwards, the production units spent on the next (still
|
||||
// incomplete) ship, and that ship's progress fraction in [0, 1).
|
||||
//
|
||||
// Each ship consumes shipMass units of material; any shortfall is farmed
|
||||
// through [ShipBuildCost] at the planet's resources rating, draining the
|
||||
// stockpile to zero before farming. The loop mirrors the engine's
|
||||
// per-turn build step so the calculator and the turn generator agree on
|
||||
// how many ships a planet yields. productionAvailable or shipMass that is
|
||||
// non-positive yields no ships and leaves the stockpile untouched.
|
||||
func ProduceShipsInTurn(
|
||||
productionAvailable, material, resources, shipMass float64,
|
||||
) (ships uint, materialLeft, productionUsed, progress float64) {
|
||||
if productionAvailable <= 0 || shipMass <= 0 {
|
||||
return 0, material, 0, 0
|
||||
}
|
||||
pa := productionAvailable
|
||||
mat := material
|
||||
for {
|
||||
matNeed := shipMass - mat
|
||||
if matNeed < 0 {
|
||||
matNeed = 0
|
||||
}
|
||||
totalCost := ShipBuildCost(shipMass, mat, resources)
|
||||
if pa < totalCost {
|
||||
return ships, mat, pa, pa / totalCost
|
||||
}
|
||||
pa -= totalCost
|
||||
mat = mat - shipMass + matNeed
|
||||
ships++
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user