refactor: planet owner

This commit is contained in:
Ilia Denisov
2026-02-04 19:26:17 +02:00
parent 6a603ea9ad
commit c1d397c993
17 changed files with 170 additions and 183 deletions
+9 -6
View File
@@ -31,7 +31,7 @@ func (c *Cache) RenamePlanet(ri int, number int, name string) error {
if !ok {
return e.NewEntityNotExistsError("planet #%d", number)
}
if p.Owner != c.g.Race[ri].ID {
if !p.OwnedBy(c.g.Race[ri].ID) {
return e.NewEntityNotOwnedError("planet #%d", number)
}
c.g.Map.Planet[c.MustPlanetIndex(p.Number)].Name = n
@@ -76,7 +76,7 @@ func (c *Cache) PlanetProduction(ri int, number int, prod game.ProductionType, s
if !ok {
return e.NewEntityNotExistsError("planet #%d", number)
}
if p.Owner != c.g.Race[ri].ID {
if !p.OwnedBy(c.g.Race[ri].ID) {
return e.NewEntityNotOwnedError("planet #%d", number)
}
var subjectID *uuid.UUID
@@ -128,7 +128,10 @@ func (c *Cache) PlanetProduction(ri int, number int, prod game.ProductionType, s
// TODO: test
func (c *Cache) PlanetProductionDisplayName(pn uint) string {
p := c.MustPlanet(pn)
ri := c.RaceIndex(p.Owner)
if !p.Owned() {
return "-"
}
ri := c.RaceIndex(*p.Owner)
switch pt := p.Production.Type; pt {
case game.ResearchDrive:
return "Drive"
@@ -202,14 +205,14 @@ func (c *Cache) TurnPlanetProductions() {
// cancel upgrade for groups on wiped planets
for sgi := range c.ShipGroupsIndex() {
sg := c.ShipGroup(sgi)
if sg.State() == game.StateUpgrade && c.MustPlanet(sg.Destination).Owner == uuid.Nil {
if sg.State() == game.StateUpgrade && !c.MustPlanet(sg.Destination).Owned() {
sg.StateUpgrade = nil
}
}
for pn := range c.listProducingPlanets() {
p := c.MustPlanet(pn)
ri := c.RaceIndex(p.Owner)
ri := c.RaceIndex(*p.Owner)
r := &c.g.Race[ri]
// upgrade groups and return to in_orbit state
@@ -261,7 +264,7 @@ func (c *Cache) TurnPlanetProductions() {
func (c *Cache) listProducingPlanets() iter.Seq[uint] {
ordered := make([]int, 0)
for i := range c.g.Map.Planet {
if c.g.Map.Planet[i].Owner == uuid.Nil || c.g.Map.Planet[i].Production.Type == game.ProductionNone {
if !c.g.Map.Planet[i].Owned() || c.g.Map.Planet[i].Production.Type == game.ProductionNone {
continue
}
ordered = append(ordered, i)