From 651067623759fb86ba147cfd8cddff7cdf365e36 Mon Sep 17 00:00:00 2001 From: Ilia Denisov Date: Sun, 28 Sep 2025 09:17:17 +0300 Subject: [PATCH] well, fuck... --- pkg/game/generator.go | 44 +++++++++++++++++------- pkg/model/game/planet.go | 42 +++++++++++++++-------- pkg/model/game/race.go | 11 ++++-- pkg/model/game/report.go | 67 +++++++++++++++++++++++++++++++++++++ pkg/model/game/science.go | 21 ++++++++---- pkg/model/game/ship.go | 23 +++++++++---- pkg/model/game/ship_test.go | 48 +++++++++++++++----------- pkg/repo/game.go | 9 ++++- 8 files changed, 203 insertions(+), 62 deletions(-) create mode 100644 pkg/model/game/report.go diff --git a/pkg/game/generator.go b/pkg/game/generator.go index a547326..5113af7 100644 --- a/pkg/game/generator.go +++ b/pkg/game/generator.go @@ -51,6 +51,7 @@ func NewGameFromMap(r Repo, races []string, m generator.Map) (uuid.UUID, error) Weapons: 1, Shields: 1, Cargo: 1, + // TODO: fill Relation } gameMap.Planet = append(gameMap.Planet, newPlanet( planetCount, @@ -104,23 +105,42 @@ func NewGameFromMap(r Repo, races []string, m generator.Map) (uuid.UUID, error) g.Map = *gameMap - if err := r.SaveTurn(0, *g); err != nil { - return uuid.Nil, fmt.Errorf("persist: %s", err) + gg := *g + + if err := r.SaveTurn(0, gg); err != nil { + return uuid.Nil, fmt.Errorf("save_turn: %s", err) } + + // if err := r.SaveState(gg); err != nil { + // return uuid.Nil, fmt.Errorf("save_state: %s", err) + // } + + // TODO: save reports + // for i := range g.Race { + + // } + // TODO: save battles + return g.ID, nil } func newPlanet(num uint, name string, owner uuid.UUID, x, y, size, pop, ind, res float64, prod game.ProductionType) game.Planet { return game.Planet{ - Name: name, - Number: num, - Owner: owner, - X: x, - Y: y, - Size: size, - Population: pop, - Industry: ind, - Resources: res, - Production: prod, + Owner: owner, + PlanetReport: game.PlanetReport{ + UninhabitedPlanet: game.UninhabitedPlanet{ + UnidentifiedPlanet: game.UnidentifiedPlanet{ + X: x, + Y: y, + Number: num, + }, + Size: size, + Name: name, + Resources: res, + }, + Population: pop, + Industry: ind, + Production: prod, + }, } } diff --git a/pkg/model/game/planet.go b/pkg/model/game/planet.go index 58e3879..9d5e63e 100644 --- a/pkg/model/game/planet.go +++ b/pkg/model/game/planet.go @@ -6,26 +6,40 @@ import ( "github.com/google/uuid" ) -type Planet struct { - X float64 `json:"x"` - Y float64 `json:"y"` - Size float64 `json:"size"` - - Name string `json:"name"` - Number uint `json:"number"` - Owner uuid.UUID `json:"owner"` - - Production ProductionType `json:"production"` - Population float64 `json:"population"` // P - Население - Industry float64 `json:"industry"` // I - Промышленность - Resources float64 `json:"resources"` // R - Ресурсы / сырьё +type UnidentifiedPlanet struct { + X float64 `json:"x"` + Y float64 `json:"y"` + Number uint `json:"number"` +} +type UninhabitedPlanet struct { + UnidentifiedPlanet + Size float64 `json:"size"` + Name string `json:"name"` + Resources float64 `json:"resources"` // R - Ресурсы / сырьё Capital float64 `json:"capital"` // CAP $ - Запасы промышленности Material float64 `json:"material"` // MAT M - Запасы ресурсов / сырья - Colonists float64 `json:"colonists"` // COL C - Количество колонистов +} + +type PlanetReport struct { + UninhabitedPlanet + Industry float64 `json:"industry"` // I - Промышленность + Population float64 `json:"population"` // P - Население + Colonists float64 `json:"colonists"` // COL C - Количество колонистов + Production ProductionType `json:"production"` // TODO: internal/report format // Параметр "L" - Свободный производственный потенциал } +type Planet struct { + Owner uuid.UUID `json:"owner"` + PlanetReport +} + +type PlanetReportForeign struct { + RaceName string + PlanetReport +} + // Свободный производственный потенциал (L) // промышленность * 0.75 + население * 0.25 // TODO: за вычетом затрат, расходуемых в течение хода на модернизацию кораблей diff --git a/pkg/model/game/race.go b/pkg/model/game/race.go index 2321951..5067d7d 100644 --- a/pkg/model/game/race.go +++ b/pkg/model/game/race.go @@ -22,9 +22,16 @@ type Race struct { Fleets []Fleet `json:"fleet,omitempty"` } +type Relation string + +const ( + RelationWar = "War" + RelationPeace = "Peace" +) + type RaceRelation struct { - RaceID uuid.UUID `json:"raceId"` - Peace bool `json:"peace"` + RaceID uuid.UUID `json:"raceId"` + Relation Relation `json:"relation"` } func (r Race) FlightDistance() float64 { diff --git a/pkg/model/game/report.go b/pkg/model/game/report.go new file mode 100644 index 0000000..af8431e --- /dev/null +++ b/pkg/model/game/report.go @@ -0,0 +1,67 @@ +package game + +type Report struct { + Width, Height uint32 + PlanetCount uint32 // do we need that? + PlayersLeft uint32 // do we need that? + + Votes float64 + VoteFor string + + Statuses []PlayerStatus + + Sciences []ScienceReport + ForeignSciences []ScienceReportForeign + + ShipTypes []ShipTypeReport + ForeignShipTypes []ShipTypeReportForeign + + Battles []any // TODO: tbd + + Bombings []any // TODO: tbd + + IncomingGroups []IncomingGroup + + Planets []PlanetReport + ForeignPlanets []PlanetReportForeign + UninhabitedPlanets []UninhabitedPlanet + UnidentifiedPlanets []UnidentifiedPlanet + + ShipsInProduction []any // TODO: tbd + + Routes []any // TODO: tbd + + Fleets []any // TODO: tbd + + ShipGroups []any // TODO: tbd + + ForeignShipGroups []any // TODO: tbd + + UnidentifiedGroups []any // TODO: tbd +} + +type IncomingGroup struct { + SourcePlanetNumber uint + TargetPlanetNumber uint + Distance float64 + Speed float64 + Mass float64 +} + +type ReportRelation struct { + RaceName string + Relation string +} + +type PlayerStatus struct { + Name string + Drive float64 `json:"drive"` + Weapons float64 `json:"weapons"` + Shields float64 `json:"shields"` + Cargo float64 `json:"cargo"` + Population float64 + Industry float64 + Planets uint16 + Relation ReportRelation + Votes float64 +} diff --git a/pkg/model/game/science.go b/pkg/model/game/science.go index 1c7cec4..76a7b58 100644 --- a/pkg/model/game/science.go +++ b/pkg/model/game/science.go @@ -3,10 +3,19 @@ package game import "github.com/google/uuid" type Science struct { - ID uuid.UUID `json:"id"` - Name string `json:"name"` - Drive float64 `json:"drive"` - Weapons float64 `json:"weapons"` - Shields float64 `json:"shields"` - Cargo float64 `json:"cargo"` + ID uuid.UUID `json:"id"` + ScienceReport +} + +type ScienceReportForeign struct { + RaceName string + ScienceReport +} + +type ScienceReport struct { + Name string `json:"name"` + Drive float64 `json:"drive"` + Weapons float64 `json:"weapons"` + Shields float64 `json:"shields"` + Cargo float64 `json:"cargo"` } diff --git a/pkg/model/game/ship.go b/pkg/model/game/ship.go index 4c6e228..ab36d6f 100644 --- a/pkg/model/game/ship.go +++ b/pkg/model/game/ship.go @@ -7,14 +7,23 @@ import ( "github.com/iliadenisov/galaxy/pkg/number" ) +type ShipTypeReport struct { + Name string `json:"name"` + Drive float64 `json:"drive"` // [0], [1...] + Armament uint `json:"armament"` + Weapons float64 `json:"weapons"` // [0], [1...] + Shields float64 `json:"shields"` // [0], [1...] + Cargo float64 `json:"cargo"` // [0], [1...] +} + type ShipType struct { - ID uuid.UUID `json:"id"` - Name string `json:"name"` - Drive float64 `json:"drive"` // [0], [1...] - Armament uint `json:"armament"` - Weapons float64 `json:"weapons"` // [0], [1...] - Shields float64 `json:"shields"` // [0], [1...] - Cargo float64 `json:"cargo"` // [0], [1...] + ID uuid.UUID `json:"id"` + ShipTypeReport +} + +type ShipTypeReportForeign struct { + RaceName string + ShipTypeReport } type ShipGroup struct { diff --git a/pkg/model/game/ship_test.go b/pkg/model/game/ship_test.go index d3e1846..e402ea9 100644 --- a/pkg/model/game/ship_test.go +++ b/pkg/model/game/ship_test.go @@ -9,20 +9,24 @@ import ( func TestShipType(t *testing.T) { Gunship := game.ShipType{ - Drive: 4, - Armament: 2, - Weapons: 2, - Shields: 4, - Cargo: 0, + ShipTypeReport: game.ShipTypeReport{ + Drive: 4, + Armament: 2, + Weapons: 2, + Shields: 4, + Cargo: 0, + }, } assert.Equal(t, Gunship.EmptyMass(), 11.) Cruiser := game.ShipType{ - Drive: 15, - Armament: 1, - Weapons: 15, - Shields: 15, - Cargo: 0, + ShipTypeReport: game.ShipTypeReport{ + Drive: 15, + Armament: 1, + Weapons: 15, + Shields: 15, + Cargo: 0, + }, } assert.Equal(t, Cruiser.EmptyMass(), 45.) @@ -45,11 +49,13 @@ func TestShipType(t *testing.T) { func TestCargoCapacity(t *testing.T) { test := func(cargoSize float64, expectCapacity float64) { ship := game.ShipType{ - Drive: 1, - Armament: 1, - Weapons: 1, - Shields: 1, - Cargo: cargoSize, + ShipTypeReport: game.ShipTypeReport{ + Drive: 1, + Armament: 1, + Weapons: 1, + Shields: 1, + Cargo: cargoSize, + }, } sg := game.ShipGroup{ Type: ship, @@ -71,11 +77,13 @@ func TestCargoCapacity(t *testing.T) { func TestBombingPower(t *testing.T) { Gunship := game.ShipType{ - Drive: 60.0, - Armament: 3, - Weapons: 30.0, - Shields: 100.0, - Cargo: 0.0, + ShipTypeReport: game.ShipTypeReport{ + Drive: 60.0, + Armament: 3, + Weapons: 30.0, + Shields: 100.0, + Cargo: 0.0, + }, } sg := game.ShipGroup{ Type: Gunship, diff --git a/pkg/repo/game.go b/pkg/repo/game.go index 06b3604..c435caf 100644 --- a/pkg/repo/game.go +++ b/pkg/repo/game.go @@ -35,8 +35,15 @@ func saveTurn(s Storage, t uint, g game.Game) error { return NewStorageError(err) } // TODO: save reports + for i := range g.Race { + saveRace(s, g, i) + } // TODO: save battles - return saveState(s, g) + return saveState(s, g) // FIXME: either save it here, or in tre repo controller +} + +func saveRace(s Storage, g game.Game, i int) { + } func (r *repo) SaveState(g game.Game) error {