refactor: planet owner
This commit is contained in:
@@ -8,7 +8,6 @@ import (
|
||||
"math/rand/v2"
|
||||
"slices"
|
||||
|
||||
"github.com/google/uuid"
|
||||
e "github.com/iliadenisov/galaxy/internal/error"
|
||||
"github.com/iliadenisov/galaxy/internal/model/game"
|
||||
"github.com/iliadenisov/galaxy/internal/util"
|
||||
@@ -32,7 +31,7 @@ func (c *Cache) SetRoute(ri int, rt game.RouteType, origin, destination uint) er
|
||||
if !ok {
|
||||
return e.NewEntityNotExistsError("origin planet #%d", origin)
|
||||
}
|
||||
if p1.Owner != c.g.Race[ri].ID {
|
||||
if !p1.OwnedBy(c.g.Race[ri].ID) {
|
||||
return e.NewEntityNotOwnedError("planet #%d", origin)
|
||||
}
|
||||
p2, ok := c.Planet(destination)
|
||||
@@ -67,7 +66,7 @@ func (c *Cache) RemoveRoute(ri int, rt game.RouteType, origin uint) error {
|
||||
if !ok {
|
||||
return e.NewEntityNotExistsError("origin planet #%d", origin)
|
||||
}
|
||||
if p1.Owner != c.g.Race[ri].ID {
|
||||
if !p1.OwnedBy(c.g.Race[ri].ID) {
|
||||
return e.NewEntityNotOwnedError("planet #%d", origin)
|
||||
}
|
||||
|
||||
@@ -177,7 +176,7 @@ func (c *Cache) listRoutedSendGroupIds(pn uint) iter.Seq[int] {
|
||||
for i := range c.ShipGroupsIndex() {
|
||||
sg := c.ShipGroup(i)
|
||||
st := c.ShipGroupShipClass(i)
|
||||
if sg.OwnerID != p.Owner || // Planet must be owned by ships owner
|
||||
if !p.OwnedBy(sg.OwnerID) || // Planet must be owned by ships owner
|
||||
sg.FleetID != nil || // Ships must not be part of a Fleet
|
||||
sg.State() != game.StateInOrbit || // Ships must be only In_Orbit state
|
||||
st.CargoBlockMass() == 0 || // Ship Class must have Cargo bays
|
||||
@@ -208,10 +207,10 @@ func (c *Cache) TurnUnloadEnroutedGroups() {
|
||||
func (c *Cache) RemoveUnreachableRoutes() {
|
||||
for i := range c.g.Map.Planet {
|
||||
p1 := &c.g.Map.Planet[i]
|
||||
if p1.Owner == uuid.Nil {
|
||||
if !p1.Owned() {
|
||||
continue
|
||||
}
|
||||
ri := c.RaceIndex(p1.Owner)
|
||||
ri := c.RaceIndex(*p1.Owner)
|
||||
for rt, destination := range p1.Route {
|
||||
p2 := c.MustPlanet(destination)
|
||||
rangeToDestination := util.ShortDistance(c.g.Map.Width, c.g.Map.Height, p1.X.F(), p1.Y.F(), p2.X.F(), p2.Y.F())
|
||||
@@ -231,13 +230,13 @@ func (c *Cache) doUnload(groups iter.Seq[int]) {
|
||||
func (c *Cache) unloadRoutedColonists(pn uint, groups iter.Seq[int]) iter.Seq[int] {
|
||||
p := c.MustPlanet(pn)
|
||||
gr := slices.Collect(groups)
|
||||
if p.Owner == uuid.Nil {
|
||||
if !p.Owned() {
|
||||
return c.selectColUnloadGroup(gr)
|
||||
}
|
||||
return func(yield func(int) bool) {
|
||||
for _, sgi := range gr {
|
||||
sg := c.ShipGroup(sgi)
|
||||
if p.Owner != sg.OwnerID {
|
||||
if !p.OwnedBy(sg.OwnerID) {
|
||||
continue
|
||||
}
|
||||
if !yield(sgi) {
|
||||
|
||||
Reference in New Issue
Block a user