refactor: planet owner
This commit is contained in:
@@ -46,10 +46,10 @@ func (c *Cache) InitReport(t uint) *mr.Report {
|
||||
planets := make(map[int]uint16)
|
||||
for pi := range c.g.Map.Planet {
|
||||
p := &c.g.Map.Planet[pi]
|
||||
if p.Owner == uuid.Nil {
|
||||
if !p.Owned() {
|
||||
continue
|
||||
}
|
||||
ri := c.RaceIndex(p.Owner)
|
||||
ri := c.RaceIndex(*p.Owner)
|
||||
sumPop[ri] += p.Population.F()
|
||||
sumInd[ri] += p.Industry.F()
|
||||
planets[ri] = planets[ri] + 1
|
||||
@@ -206,10 +206,10 @@ func (c *Cache) ReportOtherScience(ri int, rep *mr.Report) {
|
||||
continue
|
||||
}
|
||||
p := c.MustPlanet(sg.Destination)
|
||||
if p.Owner == uuid.Nil || p.Owner == r.ID || p.Production.Type != game.ResearchScience {
|
||||
if !p.Owned() || p.OwnedBy(r.ID) || p.Production.Type != game.ResearchScience {
|
||||
continue
|
||||
}
|
||||
ownerIdx := c.RaceIndex(p.Owner)
|
||||
ownerIdx := c.RaceIndex(*p.Owner)
|
||||
owner := &c.g.Race[ownerIdx]
|
||||
sc := c.mustScience(ownerIdx, *p.Production.SubjectID)
|
||||
|
||||
@@ -296,7 +296,7 @@ func (c *Cache) ReportOtherShipClass(ri int, rep *mr.Report) {
|
||||
// add visible ships from owned and observed planets
|
||||
for pn := range rep.OnPlanetGroupCache {
|
||||
p := c.MustPlanet(pn)
|
||||
if p.Owner == r.ID ||
|
||||
if p.OwnedBy(r.ID) ||
|
||||
slices.IndexFunc(rep.OnPlanetGroupCache[pn], func(sgi int) bool { return c.ShipGroup(sgi).OwnerID == r.ID }) >= 0 {
|
||||
for _, sgi := range rep.OnPlanetGroupCache[pn] {
|
||||
sg := c.ShipGroup(sgi)
|
||||
@@ -389,7 +389,7 @@ func (c *Cache) ReportIncomingGroup(ri int, rep *mr.Report) {
|
||||
}
|
||||
p1 := c.MustPlanet(sg.StateInSpace.Origin)
|
||||
p2 := c.MustPlanet(sg.Destination)
|
||||
if p2.Owner != r.ID {
|
||||
if !p2.OwnedBy(r.ID) {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -420,7 +420,7 @@ func (c *Cache) ReportLocalPlanet(ri int, rep *mr.Report) {
|
||||
i := 0
|
||||
for pi := range c.g.Map.Planet {
|
||||
p := &c.g.Map.Planet[pi]
|
||||
if p.Owner != r.ID {
|
||||
if !p.OwnedBy(r.ID) {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -463,13 +463,13 @@ func (c *Cache) ReportOtherPlanet(ri int, rep *mr.Report) {
|
||||
continue
|
||||
}
|
||||
p := c.MustPlanet(sg.Destination)
|
||||
if p.Owner == r.ID || p.Owner == uuid.Nil {
|
||||
if !p.Owned() || p.OwnedBy(r.ID) {
|
||||
continue
|
||||
}
|
||||
|
||||
sliceIndexValidate(&rep.OtherPlanet, i)
|
||||
c.localPlanet(&rep.OtherPlanet[i].LocalPlanet, p, rep)
|
||||
rep.OtherPlanet[i].Owner = c.g.Race[c.RaceIndex(p.Owner)].Name
|
||||
rep.OtherPlanet[i].Owner = c.g.Race[c.RaceIndex(*p.Owner)].Name
|
||||
i++
|
||||
}
|
||||
}
|
||||
@@ -485,7 +485,7 @@ func (c *Cache) ReportUninhabitedPlanet(ri int, rep *mr.Report) {
|
||||
continue
|
||||
}
|
||||
p := c.MustPlanet(sg.Destination)
|
||||
if p.Owner != uuid.Nil {
|
||||
if p.Owned() {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -506,7 +506,7 @@ func (c *Cache) ReportUnidentifiedPlanet(ri int, rep *mr.Report) {
|
||||
p := &c.g.Map.Planet[pi]
|
||||
|
||||
// skip player's owned planets
|
||||
if p.Owner == r.ID {
|
||||
if p.OwnedBy(r.ID) {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -530,7 +530,7 @@ func (c *Cache) ReportShipProduction(ri int, rep *mr.Report) {
|
||||
i := 0
|
||||
for pi := range c.g.Map.Planet {
|
||||
p := &c.g.Map.Planet[pi]
|
||||
if p.Owner != r.ID || p.Production.Type != game.ProductionShip {
|
||||
if !p.OwnedBy(r.ID) || p.Production.Type != game.ProductionShip {
|
||||
continue
|
||||
}
|
||||
st := c.MustShipType(ri, *p.Production.SubjectID)
|
||||
@@ -557,7 +557,7 @@ func (c *Cache) ReportRoute(ri int, rep *mr.Report) {
|
||||
i := 0
|
||||
for pi := range c.g.Map.Planet {
|
||||
p := &c.g.Map.Planet[pi]
|
||||
if p.Owner != r.ID || len(p.Route) == 0 {
|
||||
if !p.OwnedBy(r.ID) || len(p.Route) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -662,7 +662,7 @@ func (c *Cache) ReportOtherGroup(ri int, rep *mr.Report) {
|
||||
// visible groups from owned and observed planets
|
||||
for pn := range rep.OnPlanetGroupCache {
|
||||
p := c.MustPlanet(pn)
|
||||
if p.Owner == r.ID ||
|
||||
if p.OwnedBy(r.ID) ||
|
||||
slices.IndexFunc(rep.OnPlanetGroupCache[pn], func(sgi int) bool { return c.ShipGroup(sgi).OwnerID == r.ID }) >= 0 {
|
||||
for _, sgi := range rep.OnPlanetGroupCache[pn] {
|
||||
sg := c.ShipGroup(sgi)
|
||||
@@ -697,7 +697,7 @@ func (c *Cache) ReportUnidentifiedGroup(ri int, rep *mr.Report) {
|
||||
}
|
||||
for pi := range c.g.Map.Planet {
|
||||
p := &c.g.Map.Planet[pi]
|
||||
if p.Owner != r.ID {
|
||||
if !p.OwnedBy(r.ID) {
|
||||
continue
|
||||
}
|
||||
if v, ok := rep.InSpaceGroupRangeCache[sgi][p.Number]; !ok {
|
||||
|
||||
Reference in New Issue
Block a user