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
+6 -6
View File
@@ -21,7 +21,7 @@ func (c *Cache) CreateShips(ri int, shipTypeName string, planetNumber uint, quan
if !ok {
return e.NewEntityNotExistsError("planet #%d", planetNumber)
}
if p.Owner != c.g.Race[ri].ID {
if !p.OwnedBy(c.g.Race[ri].ID) {
return e.NewEntityNotOwnedError("planet #%d", planetNumber)
}
@@ -231,7 +231,7 @@ func (c *Cache) DisassembleGroup(ri int, groupIndex, quantity uint) error {
load := c.ShipGroup(sgi).Load.F()
switch ct {
case game.CargoColonist:
if p.Owner == c.g.Race[ri].ID {
if p.OwnedBy(c.g.Race[ri].ID) {
p = game.UnloadColonists(p, load)
}
case game.CargoMaterial:
@@ -281,7 +281,7 @@ func (c *Cache) LoadCargo(ri int, groupIndex uint, ct game.CargoType, ships uint
return e.NewGameStateError("planet #%d", c.ShipGroup(sgi).Destination)
}
if p.Owner != uuid.Nil && p.Owner != c.g.Race[ri].ID {
if p.Owned() && !p.OwnedBy(c.g.Race[ri].ID) {
return e.NewEntityNotOwnedError("planet #%d", p.Number)
}
st := c.ShipGroupShipClass(sgi)
@@ -366,7 +366,7 @@ func (c *Cache) UnloadCargo(ri int, groupIndex uint, ships uint, quantity float6
ct := *c.ShipGroup(sgi).CargoType
p := c.MustPlanet(c.ShipGroup(sgi).Destination)
if ct == game.CargoColonist && p.Owner != uuid.Nil && p.Owner != c.g.Race[ri].ID {
if ct == game.CargoColonist && p.Owned() && !p.OwnedBy(c.g.Race[ri].ID) {
return e.NewEntityNotOwnedError("planet #%d unload %v", p.Number, ct)
}
if ships > 0 && ships < c.ShipGroup(sgi).Number {
@@ -405,8 +405,8 @@ func (c *Cache) unsafeUnloadCargo(sgi int, q float64) {
switch ct {
case game.CargoColonist:
availableOnPlanet = &p.Colonists
if p.Owner == uuid.Nil {
p.Owner = c.ShipGroup(sgi).OwnerID
if !p.Owned() {
p.Own(c.ShipGroup(sgi).OwnerID)
p.Production = game.ProductionCapital.AsType(uuid.Nil)
}
case game.CargoMaterial: