game stats shows planes and population
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user