wip: generate report

This commit is contained in:
Ilia Denisov
2026-02-03 23:41:18 +02:00
parent a567229f8a
commit adbe605783
36 changed files with 1037 additions and 391 deletions
+25 -2
View File
@@ -1,12 +1,12 @@
package controller
import (
// "github.com/iliadenisov/galaxy/internal/game/battle"
"maps"
"slices"
"github.com/google/uuid"
"github.com/iliadenisov/galaxy/internal/model/game"
"github.com/iliadenisov/galaxy/internal/model/report"
)
func MakeTurn(c *Controller, r Repo) error {
@@ -54,13 +54,30 @@ func MakeTurn(c *Controller, r Repo) error {
/*** Last steps ***/
// Store bombings
bombingReport := make([]*report.Bombing, len(bombings))
if len(bombings) > 0 {
if err := r.SaveBombings(c.Cache.g.Turn, bombings); err != nil {
return err
}
for i := range bombings {
bombingReport[i].Planet = bombings[i].Planet
bombingReport[i].PlanetOwnedID = bombings[i].PlanetOwnedID
bombingReport[i].Number = bombings[i].Number
bombingReport[i].Owner = bombings[i].Owner
bombingReport[i].Attacker = bombings[i].Attacker
bombingReport[i].Production = bombings[i].Production
bombingReport[i].Industry = report.F(bombings[i].Industry.F())
bombingReport[i].Population = report.F(bombings[i].Population.F())
bombingReport[i].Colonists = report.F(bombings[i].Colonists.F())
bombingReport[i].Capital = report.F(bombings[i].Capital.F())
bombingReport[i].Material = report.F(bombings[i].Material.F())
bombingReport[i].AttackPower = report.F(bombings[i].AttackPower.F())
bombingReport[i].Wiped = bombings[i].Wiped
}
}
// Store battles
battleReport := make([]*report.BattleReport, len(battles))
if len(battles) > 0 {
battleMeta := make([]game.BattleMeta, len(battles))
for i := range battles {
@@ -82,15 +99,21 @@ func MakeTurn(c *Controller, r Repo) error {
if err := r.SaveBattle(c.Cache.g.Turn, report, &battleMeta[i]); err != nil {
return err
}
battleReport[i] = report
}
}
// Remove killed ship groups
c.Cache.DeleteKilledShipGroups()
// TODO: Store game state
// Store game state for the new turn and 'current' state as well
r.SaveTurn(c.Cache.g.Turn, c.Cache.g)
// TODO: Store individual reports
for ri := range c.Cache.g.Race {
_ = ri
// c.Cache.GenerateReport(ri)
}
_ = winners
// [ ] monitor memory consumption at this point?