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
+33 -31
View File
@@ -5,6 +5,35 @@ import (
"github.com/iliadenisov/galaxy/internal/model/game"
)
func (c *Cache) ProduceBombings() []*game.Bombing {
report := make([]*game.Bombing, 0)
for pn, enemies := range c.collectBombingGroups() {
p := c.MustPlanet(pn)
if !p.Owned() {
continue
}
for ri, groups := range enemies {
br := c.bombingReport(p, ri, groups)
report = append(report, br)
if br.Wiped {
break
}
}
if p.Population == 0 {
// TODO: what aboul colonists left on planet?
p.Free()
clear(p.Route)
} else {
// Если на планете остались также и колонисты, то они превращаются в население,
// а накопленная промышленность возмещает потери производства.
p.UnpackColonists()
p.UnpackCapital()
}
}
return report
}
func (c *Cache) bombingReport(p *game.Planet, ri int, groups []int) *game.Bombing {
attackPower := 0.
for _, i := range groups {
@@ -14,10 +43,10 @@ func (c *Cache) bombingReport(p *game.Planet, ri int, groups []int) *game.Bombin
}
r := &game.Bombing{
ID: uuid.New(),
PlanetOwnedID: p.Owner,
PlanetOwnedID: *p.Owner,
Planet: p.Name,
Number: p.Number,
Owner: c.g.Race[c.RaceIndex(p.Owner)].Name,
Owner: c.g.Race[c.RaceIndex(*p.Owner)].Name,
Attacker: c.g.Race[ri].Name,
Production: c.PlanetProductionDisplayName(p.Number),
Industry: p.Industry,
@@ -32,33 +61,6 @@ func (c *Cache) bombingReport(p *game.Planet, ri int, groups []int) *game.Bombin
return r
}
func (c *Cache) ProduceBombings() []*game.Bombing {
report := make([]*game.Bombing, 0)
for pn, enemies := range c.collectBombingGroups() {
p := c.MustPlanet(pn)
for ri, groups := range enemies {
br := c.bombingReport(p, ri, groups)
report = append(report, br)
if br.Wiped {
break
}
}
if p.Population == 0 {
// TODO: what aboul colonists left on planet?
p.Owner = uuid.Nil
p.Production = game.ProductionNone.AsType(uuid.Nil)
clear(p.Route)
} else {
// Если на планете остались также и колонисты, то они превращаются в население,
// а накопленная промышленность возмещает потери производства.
p.UnpackColonists()
p.UnpackCapital()
}
}
return report
}
func bombPlanet(p *game.Planet, power float64) {
// Уничтожается население и колонисты в количестве равном [суммарной] мощности бомбардировки
if power > p.Population.F() {
@@ -94,11 +96,11 @@ func (c *Cache) collectBombingGroups() map[uint]map[int][]int {
continue
}
p := c.MustPlanet(sg.Destination)
if p.Owner == sg.OwnerID || p.Owner == uuid.Nil {
if p.OwnedBy(sg.OwnerID) || !p.Owned() {
continue
}
r1 := c.RaceIndex(sg.OwnerID)
r2 := c.RaceIndex(p.Owner)
r2 := c.RaceIndex(*p.Owner)
if c.Relation(r1, r2) == game.RelationPeace {
continue
}