game stats shows planes and population

This commit is contained in:
Ilia Denisov
2026-04-26 21:12:51 +02:00
parent fe829285a6
commit b4591cabd4
11 changed files with 84 additions and 22 deletions
+16 -1
View File
@@ -152,10 +152,25 @@ func GameState(configure func(*Param)) (s game.State, err error) {
Players: make([]game.PlayerState, len(g.Race)),
}
planetCount := make(map[uuid.UUID]uint)
population := make(map[uuid.UUID]game.Float)
for i := range g.Map.Planet {
p := &g.Map.Planet[i]
if p.Owner == nil {
continue
}
owner := *p.Owner
planetCount[owner] += 1
population[owner] += p.Population
}
for i := range g.Race {
r := &g.Race[i]
result.Players[i].ID = r.ID
result.Players[i].Name = r.Name
result.Players[i].RaceName = r.Name
result.Players[i].Planets = planetCount[r.ID]
result.Players[i].Population = population[r.ID]
result.Players[i].Extinct = r.Extinct
}