fix: ship send without any planets left
This commit is contained in:
@@ -7,12 +7,6 @@ import (
|
|||||||
"github.com/iliadenisov/galaxy/internal/util"
|
"github.com/iliadenisov/galaxy/internal/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
|
||||||
TODO: остались ли планеты у расы
|
|
||||||
|
|
||||||
Если у расы не осталось планет, то оставшиеся корабли не смогут
|
|
||||||
покинуть своего места пребывания.
|
|
||||||
*/
|
|
||||||
func (c *Cache) shipGroupSend(ri int, groupID uuid.UUID, planetNumber uint) error {
|
func (c *Cache) shipGroupSend(ri int, groupID uuid.UUID, planetNumber uint) error {
|
||||||
c.validateRaceIndex(ri)
|
c.validateRaceIndex(ri)
|
||||||
|
|
||||||
@@ -22,6 +16,17 @@ func (c *Cache) shipGroupSend(ri int, groupID uuid.UUID, planetNumber uint) erro
|
|||||||
}
|
}
|
||||||
st := c.ShipGroupShipClass(sgi)
|
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 {
|
if st.DriveBlockMass() == 0 {
|
||||||
return e.NewSendShipHasNoDrivesError()
|
return e.NewSendShipHasNoDrivesError()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,11 @@ func TestShipGroupSend(t *testing.T) {
|
|||||||
g.ShipClassCreate(Race_0.Name, "Fortress", 0, 50, 30, 100, 0)
|
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))
|
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,
|
assert.ErrorContains(t,
|
||||||
g.ShipGroupSend(UnknownRace, c.ShipGroup(0).ID, 2),
|
g.ShipGroupSend(UnknownRace, c.ShipGroup(0).ID, 2),
|
||||||
e.GenericErrorText(e.ErrInputUnknownRace))
|
e.GenericErrorText(e.ErrInputUnknownRace))
|
||||||
@@ -36,6 +41,9 @@ func TestShipGroupSend(t *testing.T) {
|
|||||||
assert.ErrorContains(t,
|
assert.ErrorContains(t,
|
||||||
g.ShipGroupSend(Race_0.Name, c.ShipGroup(1).ID, 1),
|
g.ShipGroupSend(Race_0.Name, c.ShipGroup(1).ID, 1),
|
||||||
e.GenericErrorText(e.ErrShipsBusy))
|
e.GenericErrorText(e.ErrShipsBusy))
|
||||||
|
assert.ErrorContains(t,
|
||||||
|
g.ShipGroupSend(shiplessRace, c.ShipGroup(sgi).ID, 2),
|
||||||
|
e.GenericErrorText(e.ErrSendShipOwnerHasNoPlanets))
|
||||||
assert.ErrorContains(t,
|
assert.ErrorContains(t,
|
||||||
g.ShipGroupSend(Race_0.Name, c.ShipGroup(2).ID, 2),
|
g.ShipGroupSend(Race_0.Name, c.ShipGroup(2).ID, 2),
|
||||||
e.GenericErrorText(e.ErrSendShipHasNoDrives))
|
e.GenericErrorText(e.ErrSendShipHasNoDrives))
|
||||||
|
|||||||
@@ -27,7 +27,8 @@ const (
|
|||||||
ErrUpgradeInsufficientResources = 5011
|
ErrUpgradeInsufficientResources = 5011
|
||||||
ErrSendShipHasNoDrives = 5012
|
ErrSendShipHasNoDrives = 5012
|
||||||
ErrSendUnreachableDestination = 5013
|
ErrSendUnreachableDestination = 5013
|
||||||
ErrRaceExinct = 5014
|
ErrSendShipOwnerHasNoPlanets = 5014
|
||||||
|
ErrRaceExinct = 5015
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -165,6 +166,8 @@ func GenericErrorText(code int) string {
|
|||||||
return "One or more ships are not equipped with hyperdrive and cannot be moved"
|
return "One or more ships are not equipped with hyperdrive and cannot be moved"
|
||||||
case ErrSendUnreachableDestination:
|
case ErrSendUnreachableDestination:
|
||||||
return "Destination planet is too far for current Drive level"
|
return "Destination planet is too far for current Drive level"
|
||||||
|
case ErrSendShipOwnerHasNoPlanets:
|
||||||
|
return "Race is not owning any planet, all flights impossible"
|
||||||
case ErrRaceExinct:
|
case ErrRaceExinct:
|
||||||
return "Race is extinct"
|
return "Race is extinct"
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -167,3 +167,7 @@ func NewSendShipHasNoDrivesError(arg ...any) error {
|
|||||||
func NewSendUnreachableDestinationError(arg ...any) error {
|
func NewSendUnreachableDestinationError(arg ...any) error {
|
||||||
return newGenericError(ErrSendUnreachableDestination, arg...)
|
return newGenericError(ErrSendUnreachableDestination, arg...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewSendShipOwnerHasNoPlanetsError(arg ...any) error {
|
||||||
|
return newGenericError(ErrSendShipOwnerHasNoPlanets, arg...)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user