3626998a33
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>
35 lines
911 B
Go
35 lines
911 B
Go
package calc_test
|
|
|
|
import (
|
|
"math"
|
|
"testing"
|
|
|
|
"galaxy/calc"
|
|
)
|
|
|
|
func TestBlockUpgradeCost(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
blockMass float64
|
|
currentTech float64
|
|
targetTech float64
|
|
want float64
|
|
}{
|
|
{"zero block mass returns zero", 0, 1.0, 2.0, 0},
|
|
{"target equal to current returns zero", 5, 2.0, 2.0, 0},
|
|
{"target below current returns zero", 5, 2.0, 1.0, 0},
|
|
{"doubling tech on mass 5 costs 25", 5, 1.0, 2.0, 25},
|
|
{"doubling tech on mass 10 costs 50", 10, 1.0, 2.0, 50},
|
|
{"partial step from 2.0 to 2.5 on mass 5", 5, 2.0, 2.5, 10},
|
|
}
|
|
for _, tc := range cases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
got := calc.BlockUpgradeCost(tc.blockMass, tc.currentTech, tc.targetTech)
|
|
if math.Abs(got-tc.want) > 1e-9 {
|
|
t.Errorf("BlockUpgradeCost(%v, %v, %v) = %v, want %v",
|
|
tc.blockMass, tc.currentTech, tc.targetTech, got, tc.want)
|
|
}
|
|
})
|
|
}
|
|
}
|