Files
galaxy-game/ui/core/calc/ship.go
T
Ilia Denisov 3626998a33 ui/phase-20: ship-group inspector actions
Eight ship-group operations land on the inspector behind a single
inline-form panel: split, send, load, unload, modernize, dismantle,
transfer, join fleet. Each action either appends a typed command to
the local order draft or surfaces a tooltip explaining the
disabled state. Partial-ship operations emit an implicit
breakShipGroup command before the targeted action so the engine
sees a clean (Break, Action) pair on the wire.

`pkg/calc.BlockUpgradeCost` migrates from
`game/internal/controller/ship_group_upgrade.go` so the calc
bridge can wrap a pure pkg/calc formula; the controller now
imports it. The bridge surfaces the function as
`core.blockUpgradeCost`, which the inspector calls once per ship
block to render the modernize cost preview.

`GameReport.otherRaces` is decoded from the report's player block
(non-extinct, ≠ self) and feeds the transfer-to-race picker. The
planet inspector's stationed-ship rows become clickable for own
groups so the actions panel is reachable from the standard click
flow (the renderer continues to hide on-planet groups).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-10 16:27:55 +02:00

68 lines
2.9 KiB
Go

// Package calc is the WASM-side bridge over `galaxy/calc`'s ship math.
// Each function is a one-line passthrough: signatures match the
// underlying `pkg/calc/ship.go` exactly so the bridge contains zero
// math beyond the call. Wrapping `pkg/calc` here keeps the JS/Go
// surface in one file and lets the canonical math live in a single
// upstream package shared with the engine.
package calc
import "galaxy/calc"
// DriveEffective wraps `calc.DriveEffective` (`pkg/calc/ship.go`):
// effective drive power equals the ship's drive block multiplied by
// the player's drive tech level.
func DriveEffective(drive, driveTech float64) float64 {
return calc.DriveEffective(drive, driveTech)
}
// EmptyMass wraps `calc.EmptyMass` (`pkg/calc/ship.go`): mass of the
// ship without cargo. Returns ok == false when the weapons/armament
// pair is invalid (one zero, the other non-zero).
func EmptyMass(drive, weapons float64, armament uint, shields, cargo float64) (float64, bool) {
return calc.EmptyMass(drive, weapons, armament, shields, cargo)
}
// WeaponsBlockMass wraps `calc.WeaponsBlockMass` (`pkg/calc/ship.go`):
// mass of the weapons sub-block. Returns ok == false on the same
// invalid pairing as EmptyMass.
func WeaponsBlockMass(weapons float64, armament uint) (float64, bool) {
return calc.WeaponsBlockMass(weapons, armament)
}
// FullMass wraps `calc.FullMass` (`pkg/calc/ship.go`): empty mass plus
// the mass of the carried cargo.
func FullMass(emptyMass, carryingMass float64) float64 {
return calc.FullMass(emptyMass, carryingMass)
}
// Speed wraps `calc.Speed` (`pkg/calc/ship.go`): light-years per turn,
// equal to effective drive times 20 divided by the ship's full mass.
// Zero when fullMass is non-positive.
func Speed(driveEffective, fullMass float64) float64 {
return calc.Speed(driveEffective, fullMass)
}
// CargoCapacity wraps `calc.CargoCapacity` (`pkg/calc/ship.go`):
// hold capacity of one ship in cargo units, scaled by the player's
// cargo tech.
func CargoCapacity(cargo, cargoTech float64) float64 {
return calc.CargoCapacity(cargo, cargoTech)
}
// CarryingMass wraps `calc.CarryingMass` (`pkg/calc/ship.go`): mass of
// a payload of `load` cargo units at the player's cargo tech. Used by
// the designer preview to derive full-load mass from CargoCapacity.
func CarryingMass(load, cargoTech float64) float64 {
return calc.CarryingMass(load, cargoTech)
}
// BlockUpgradeCost wraps `calc.BlockUpgradeCost` (`pkg/calc/ship.go`):
// production cost of upgrading a single ship block from currentBlockTech
// to targetBlockTech. Returns 0 when blockMass is zero or the target is
// not above the current level. Used by the ship-group inspector's
// modernize cost preview, with each of the four blocks (drive, weapons,
// shields, cargo) priced through a separate call.
func BlockUpgradeCost(blockMass, currentBlockTech, targetBlockTech float64) float64 {
return calc.BlockUpgradeCost(blockMass, currentBlockTech, targetBlockTech)
}