From e90218368c4a138fa4da7d7cf9233e356d2d86c5 Mon Sep 17 00:00:00 2001 From: Ilia Denisov Date: Wed, 4 Feb 2026 20:27:25 +0200 Subject: [PATCH] refactor: destroy ship_group item --- internal/controller/ship_group.go | 10 +++++++--- internal/controller/ship_group_test.go | 13 +++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/internal/controller/ship_group.go b/internal/controller/ship_group.go index 3b4252a..d942369 100644 --- a/internal/controller/ship_group.go +++ b/internal/controller/ship_group.go @@ -102,10 +102,14 @@ func (c *Cache) ShipGroupOwnerRace(groupIndex int) *game.Race { return &c.g.Race[c.ShipGroupOwnerRaceIndex(groupIndex)] } -func (c *Cache) ShipGroupNumber(i int, n uint) { +func (c *Cache) ShipGroupDestroyItem(i int) { c.validateShipGroupIndex(i) - c.g.ShipGroups[i].Number = n - // FIXME: cargo load must be decreased proportionally + sg := &c.g.ShipGroups[i] + if sg.Number == 0 { + panic("group has no ships") + } + sg.Load = game.F(sg.Load.F() / float64(sg.Number) * float64(sg.Number-1)) + sg.Number -= 1 } func (c *Cache) DeleteShipGroup(i int) { diff --git a/internal/controller/ship_group_test.go b/internal/controller/ship_group_test.go index 4365b10..94cd5da 100644 --- a/internal/controller/ship_group_test.go +++ b/internal/controller/ship_group_test.go @@ -526,3 +526,16 @@ func TestDisassembleGroup(t *testing.T) { assert.Equal(t, uint(7), c.ShipGroup(2).Number) assert.Equal(t, 56.0, c.ShipGroup(2).Load.F()) } + +func TestShipGroupDestroyItem(t *testing.T) { + c, _ := newCache() + + assert.NoError(t, c.CreateShips(Race_0_idx, Race_0_Freighter, R0_Planet_0_num, 10)) + c.ShipGroup(0).CargoType = game.CargoColonist.Ref() + c.ShipGroup(0).Load = 100.0 + + for c.ShipGroup(0).Number > 0 { + c.ShipGroupDestroyItem(0) + assert.Equal(t, float64(c.ShipGroup(0).Number)*10, c.ShipGroup(0).Load.F()) + } +}