refactor: destroy ship_group item
This commit is contained in:
@@ -102,10 +102,14 @@ func (c *Cache) ShipGroupOwnerRace(groupIndex int) *game.Race {
|
|||||||
return &c.g.Race[c.ShipGroupOwnerRaceIndex(groupIndex)]
|
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.validateShipGroupIndex(i)
|
||||||
c.g.ShipGroups[i].Number = n
|
sg := &c.g.ShipGroups[i]
|
||||||
// FIXME: cargo load must be decreased proportionally
|
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) {
|
func (c *Cache) DeleteShipGroup(i int) {
|
||||||
|
|||||||
@@ -526,3 +526,16 @@ func TestDisassembleGroup(t *testing.T) {
|
|||||||
assert.Equal(t, uint(7), c.ShipGroup(2).Number)
|
assert.Equal(t, uint(7), c.ShipGroup(2).Number)
|
||||||
assert.Equal(t, 56.0, c.ShipGroup(2).Load.F())
|
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())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user