Files
galaxy-game/pkg/model/report/report.go
T
2026-03-10 17:01:47 +02:00

77 lines
2.8 KiB
Go

package report
import (
"encoding/json"
u "galaxy/util"
"github.com/google/uuid"
)
type Float float64
func F(v float64) Float {
return Float(u.Fixed3(v))
}
type Report struct {
Version uint `json:"version"`
Turn uint `json:"turn"`
Width uint32 `json:"mapWidth"`
Height uint32 `json:"mapHeight"`
PlanetCount uint32 `json:"mapPlanets"`
Race string `json:"race"`
RaceID uuid.UUID `json:"-"`
Votes Float `json:"votes"`
VoteFor string `json:"voteFor"`
Player []Player `json:"player"`
LocalScience []Science `json:"localScience,omitempty"`
OtherScience []OtherScience `json:"otherScience,omitempty"`
LocalShipClass []ShipClass `json:"localShipClass,omitempty"`
OtherShipClass []OthersShipClass `json:"otherShipClass,omitempty"`
Battle []uuid.UUID `json:"battle,omitempty"`
Bombing []*Bombing `json:"bombing,omitempty"`
IncomingGroup []IncomingGroup `json:"incomingGroup,omitempty"`
LocalPlanet []LocalPlanet `json:"localPlanet,omitempty"`
ShipProduction []ShipProduction `json:"shipProduction,omitempty"`
Route []Route `json:"route,omitempty"`
OtherPlanet []OtherPlanet `json:"otherPlanet,omitempty"`
UninhabitedPlanet []UninhabitedPlanet `json:"uninhabitedPlanet,omitempty"`
UnidentifiedPlanet []UnidentifiedPlanet `json:"unidentifiedPlanet,omitempty"`
LocalFleet []LocalFleet `json:"localFleet,omitempty"`
LocalGroup []LocalGroup `json:"localGroup,omitempty"`
OtherGroup []OtherGroup `json:"otherGroup,omitempty"`
UnidentifiedGroup []UnidentifiedGroup `json:"unidentifiedGroup,omitempty"`
OnPlanetGroupCache map[uint][]int `json:"-"`
InSpaceGroupRangeCache map[int]map[uint]float64 `json:"-"`
}
type Route struct {
Planet uint `json:"planet"`
Route map[uint]string `json:"route"`
}
type Player struct {
ID uuid.UUID `json:"-"`
Name string `json:"name"`
Drive Float `json:"drive"`
Weapons Float `json:"weapons"`
Shields Float `json:"shields"`
Cargo Float `json:"cargo"`
Population Float `json:"population"`
Industry Float `json:"industry"`
Planets uint16 `json:"planets"`
Relation string `json:"relation"`
Votes Float `json:"votes"`
Extinct bool `json:"extinct"`
}
func (r Report) MarshalBinary() (data []byte, err error) {
return json.Marshal(&r)
}
func (r *Report) UnmarshalBinary(data []byte) error {
return json.Unmarshal(data, r)
}