feat: store battles and bombings

This commit is contained in:
Ilia Denisov
2026-01-30 18:57:43 +03:00
parent 824f6609ab
commit 4c14234afb
16 changed files with 274 additions and 103 deletions
-32
View File
@@ -1,32 +0,0 @@
package game
import (
"encoding/json"
"github.com/google/uuid"
)
type BattleReport struct {
ID uuid.UUID `json:"id"`
Planet uint `json:"planet"`
PlanetName string `json:"planet_name"`
Races map[int]string `json:"races"`
Ships map[int]string `json:"ships"`
Protocol []BattleActionReport `json:"protocol"`
}
type BattleActionReport struct {
Attacker int `json:"r1"`
AttackerShipClass int `json:"s1"`
Defender int `json:"r2"`
DefenderShipClass int `json:"s2"`
Destroyed bool `json:"d"`
}
func (b BattleReport) MarshalBinary() (data []byte, err error) {
return json.Marshal(&b)
}
func (b *BattleReport) UnmarshalBinary(data []byte) error {
return json.Unmarshal(data, b)
}
+22 -1
View File
@@ -6,6 +6,7 @@ import (
"maps"
"github.com/google/uuid"
"github.com/iliadenisov/galaxy/internal/model/report"
)
type TechSet map[Tech]float64
@@ -26,7 +27,7 @@ func (ts TechSet) Set(t Tech, v float64) TechSet {
type Game struct {
ID uuid.UUID `json:"id"`
Age uint `json:"turn"` // Game's turn number
Turn uint `json:"turn"`
Map Map `json:"map"`
Race []Race `json:"races"`
Votes float64 `json:"votes"`
@@ -34,6 +35,18 @@ type Game struct {
Fleets []Fleet `json:"fleet,omitempty"`
}
type GameMeta struct {
Battles []BattleMeta `json:"battles,omitempty"`
Bombings []report.BombingPlanetReport `json:"bombings,omitempty"`
}
type BattleMeta struct {
Turn uint `json:"turn"`
Planet uint `json:"planet"`
BattleID uuid.UUID `json:"battle_id"`
ObserverIDs []uuid.UUID `json:"observer_ids"`
}
// TODO: remove if not needed
func (g Game) RaceVotes(raceID uuid.UUID) float64 {
var result float64
@@ -52,3 +65,11 @@ func (g Game) MarshalBinary() (data []byte, err error) {
func (g *Game) UnmarshalBinary(data []byte) error {
return json.Unmarshal(data, g)
}
func (b GameMeta) MarshalBinary() (data []byte, err error) {
return json.Marshal(&b)
}
func (b *GameMeta) UnmarshalBinary(data []byte) error {
return json.Unmarshal(data, b)
}
+7
View File
@@ -233,3 +233,10 @@ func (sg ShipGroup) BombingPower(st *ShipType) float64 {
float64(st.Armament) *
float64(sg.Number)
}
func (sg ShipGroup) CargoString() string {
if sg.CargoType == nil {
return "-"
}
return sg.CargoType.String()
}
+47
View File
@@ -0,0 +1,47 @@
package report
import (
"encoding/json"
"github.com/google/uuid"
)
type BattleReport struct {
ID uuid.UUID `json:"id"`
Turn uint `json:"turn"`
Planet uint `json:"planet"`
PlanetName string `json:"planet_name"`
Races map[int]uuid.UUID `json:"races"`
Ships map[int]BattleReportGroup `json:"ships"`
Protocol []BattleActionReport `json:"protocol"`
}
type BattleReportGroup struct {
OwnerID uuid.UUID `json:"ownerId"`
InBattle bool `json:"inBattle"`
Number uint `json:"num"`
NumberLeft uint `json:"numLeft"`
ClassName string `json:"className"`
LoadType string `json:"loadType"`
LoadQuantity float64 `json:"loadQuantity"`
Drive float64 `json:"drive"`
Weapons float64 `json:"wwapons"`
Shields float64 `json:"shields"`
Cargo float64 `json:"cargo"`
}
type BattleActionReport struct {
Attacker int `json:"a"`
AttackerShipClass int `json:"sa"`
Defender int `json:"d"`
DefenderShipClass int `json:"sd"`
Destroyed bool `json:"x"`
}
func (b BattleReport) MarshalBinary() (data []byte, err error) {
return json.Marshal(&b)
}
func (b *BattleReport) UnmarshalBinary(data []byte) error {
return json.Unmarshal(data, b)
}
+19
View File
@@ -0,0 +1,19 @@
package report
import "github.com/google/uuid"
type BombingPlanetReport struct {
ID uuid.UUID `json:"id"`
Planet string `json:"name"`
Number uint `json:"number"`
Owner string `json:"owner"`
Attacker string `json:"attacker"`
Production string `json:"production"`
Industry float64 `json:"industry"` // I - Промышленность
Population float64 `json:"population"` // P - Население
Colonists float64 `json:"colonists"` // COL C - Количество колонистов
Capital float64 `json:"capital"` // CAP $ - Запасы промышленности
Material float64 `json:"material"` // MAT M - Запасы ресурсов / сырья
AttackPower float64 `json:"attack"`
Wiped bool `json:"wiped"`
}