fix: ship send without any planets left

This commit is contained in:
Ilia Denisov
2026-02-17 19:57:08 +02:00
parent d42cee9df1
commit f394c105b0
4 changed files with 27 additions and 7 deletions
+11 -6
View File
@@ -7,12 +7,6 @@ import (
"github.com/iliadenisov/galaxy/internal/util"
)
/*
TODO: остались ли планеты у расы
Если у расы не осталось планет, то оставшиеся корабли не смогут
покинуть своего места пребывания.
*/
func (c *Cache) shipGroupSend(ri int, groupID uuid.UUID, planetNumber uint) error {
c.validateRaceIndex(ri)
@@ -22,6 +16,17 @@ func (c *Cache) shipGroupSend(ri int, groupID uuid.UUID, planetNumber uint) erro
}
st := c.ShipGroupShipClass(sgi)
pcount := 0
for i := range c.g.Map.Planet {
if c.g.Map.Planet[i].OwnedBy(c.g.Race[ri].ID) {
pcount++
break
}
}
if pcount == 0 {
return e.NewSendShipOwnerHasNoPlanetsError()
}
if st.DriveBlockMass() == 0 {
return e.NewSendShipHasNoDrivesError()
}
@@ -21,6 +21,11 @@ func TestShipGroupSend(t *testing.T) {
g.ShipClassCreate(Race_0.Name, "Fortress", 0, 50, 30, 100, 0)
assert.NoError(t, c.CreateShips(Race_0_idx, "Fortress", R0_Planet_0_num, 1))
shiplessRace := "Shipless"
ri, _ := c.AddRace(shiplessRace)
assert.NoError(t, c.ShipClassCreate(ri, "Drone", 1, 0, 0, 0, 0))
sgi := c.CreateShipsUnsafe_T(ri, c.MustShipClass(ri, "Drone").ID, R0_Planet_0_num, 1)
assert.ErrorContains(t,
g.ShipGroupSend(UnknownRace, c.ShipGroup(0).ID, 2),
e.GenericErrorText(e.ErrInputUnknownRace))
@@ -36,6 +41,9 @@ func TestShipGroupSend(t *testing.T) {
assert.ErrorContains(t,
g.ShipGroupSend(Race_0.Name, c.ShipGroup(1).ID, 1),
e.GenericErrorText(e.ErrShipsBusy))
assert.ErrorContains(t,
g.ShipGroupSend(shiplessRace, c.ShipGroup(sgi).ID, 2),
e.GenericErrorText(e.ErrSendShipOwnerHasNoPlanets))
assert.ErrorContains(t,
g.ShipGroupSend(Race_0.Name, c.ShipGroup(2).ID, 2),
e.GenericErrorText(e.ErrSendShipHasNoDrives))