feat: store battles and bombings
This commit is contained in:
@@ -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)
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user