well, fuck...

This commit is contained in:
Ilia Denisov
2025-09-28 09:17:17 +03:00
parent 66eeefc65d
commit 6510676237
8 changed files with 203 additions and 62 deletions
+32 -12
View File
@@ -51,6 +51,7 @@ func NewGameFromMap(r Repo, races []string, m generator.Map) (uuid.UUID, error)
Weapons: 1, Weapons: 1,
Shields: 1, Shields: 1,
Cargo: 1, Cargo: 1,
// TODO: fill Relation
} }
gameMap.Planet = append(gameMap.Planet, newPlanet( gameMap.Planet = append(gameMap.Planet, newPlanet(
planetCount, planetCount,
@@ -104,23 +105,42 @@ func NewGameFromMap(r Repo, races []string, m generator.Map) (uuid.UUID, error)
g.Map = *gameMap g.Map = *gameMap
if err := r.SaveTurn(0, *g); err != nil { gg := *g
return uuid.Nil, fmt.Errorf("persist: %s", err)
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 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 { func newPlanet(num uint, name string, owner uuid.UUID, x, y, size, pop, ind, res float64, prod game.ProductionType) game.Planet {
return game.Planet{ return game.Planet{
Name: name, Owner: owner,
Number: num, PlanetReport: game.PlanetReport{
Owner: owner, UninhabitedPlanet: game.UninhabitedPlanet{
X: x, UnidentifiedPlanet: game.UnidentifiedPlanet{
Y: y, X: x,
Size: size, Y: y,
Population: pop, Number: num,
Industry: ind, },
Resources: res, Size: size,
Production: prod, Name: name,
Resources: res,
},
Population: pop,
Industry: ind,
Production: prod,
},
} }
} }
+28 -14
View File
@@ -6,26 +6,40 @@ import (
"github.com/google/uuid" "github.com/google/uuid"
) )
type Planet struct { type UnidentifiedPlanet struct {
X float64 `json:"x"` X float64 `json:"x"`
Y float64 `json:"y"` Y float64 `json:"y"`
Size float64 `json:"size"` Number uint `json:"number"`
}
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 UninhabitedPlanet struct {
UnidentifiedPlanet
Size float64 `json:"size"`
Name string `json:"name"`
Resources float64 `json:"resources"` // R - Ресурсы / сырьё
Capital float64 `json:"capital"` // CAP $ - Запасы промышленности Capital float64 `json:"capital"` // CAP $ - Запасы промышленности
Material float64 `json:"material"` // MAT M - Запасы ресурсов / сырья 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" - Свободный производственный потенциал // Параметр "L" - Свободный производственный потенциал
} }
type Planet struct {
Owner uuid.UUID `json:"owner"`
PlanetReport
}
type PlanetReportForeign struct {
RaceName string
PlanetReport
}
// Свободный производственный потенциал (L) // Свободный производственный потенциал (L)
// промышленность * 0.75 + население * 0.25 // промышленность * 0.75 + население * 0.25
// TODO: за вычетом затрат, расходуемых в течение хода на модернизацию кораблей // TODO: за вычетом затрат, расходуемых в течение хода на модернизацию кораблей
+9 -2
View File
@@ -22,9 +22,16 @@ type Race struct {
Fleets []Fleet `json:"fleet,omitempty"` Fleets []Fleet `json:"fleet,omitempty"`
} }
type Relation string
const (
RelationWar = "War"
RelationPeace = "Peace"
)
type RaceRelation struct { type RaceRelation struct {
RaceID uuid.UUID `json:"raceId"` RaceID uuid.UUID `json:"raceId"`
Peace bool `json:"peace"` Relation Relation `json:"relation"`
} }
func (r Race) FlightDistance() float64 { func (r Race) FlightDistance() float64 {
+67
View File
@@ -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
}
+15 -6
View File
@@ -3,10 +3,19 @@ package game
import "github.com/google/uuid" import "github.com/google/uuid"
type Science struct { type Science struct {
ID uuid.UUID `json:"id"` ID uuid.UUID `json:"id"`
Name string `json:"name"` ScienceReport
Drive float64 `json:"drive"` }
Weapons float64 `json:"weapons"`
Shields float64 `json:"shields"` type ScienceReportForeign struct {
Cargo float64 `json:"cargo"` 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"`
} }
+16 -7
View File
@@ -7,14 +7,23 @@ import (
"github.com/iliadenisov/galaxy/pkg/number" "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 { type ShipType struct {
ID uuid.UUID `json:"id"` ID uuid.UUID `json:"id"`
Name string `json:"name"` ShipTypeReport
Drive float64 `json:"drive"` // [0], [1...] }
Armament uint `json:"armament"`
Weapons float64 `json:"weapons"` // [0], [1...] type ShipTypeReportForeign struct {
Shields float64 `json:"shields"` // [0], [1...] RaceName string
Cargo float64 `json:"cargo"` // [0], [1...] ShipTypeReport
} }
type ShipGroup struct { type ShipGroup struct {
+28 -20
View File
@@ -9,20 +9,24 @@ import (
func TestShipType(t *testing.T) { func TestShipType(t *testing.T) {
Gunship := game.ShipType{ Gunship := game.ShipType{
Drive: 4, ShipTypeReport: game.ShipTypeReport{
Armament: 2, Drive: 4,
Weapons: 2, Armament: 2,
Shields: 4, Weapons: 2,
Cargo: 0, Shields: 4,
Cargo: 0,
},
} }
assert.Equal(t, Gunship.EmptyMass(), 11.) assert.Equal(t, Gunship.EmptyMass(), 11.)
Cruiser := game.ShipType{ Cruiser := game.ShipType{
Drive: 15, ShipTypeReport: game.ShipTypeReport{
Armament: 1, Drive: 15,
Weapons: 15, Armament: 1,
Shields: 15, Weapons: 15,
Cargo: 0, Shields: 15,
Cargo: 0,
},
} }
assert.Equal(t, Cruiser.EmptyMass(), 45.) assert.Equal(t, Cruiser.EmptyMass(), 45.)
@@ -45,11 +49,13 @@ func TestShipType(t *testing.T) {
func TestCargoCapacity(t *testing.T) { func TestCargoCapacity(t *testing.T) {
test := func(cargoSize float64, expectCapacity float64) { test := func(cargoSize float64, expectCapacity float64) {
ship := game.ShipType{ ship := game.ShipType{
Drive: 1, ShipTypeReport: game.ShipTypeReport{
Armament: 1, Drive: 1,
Weapons: 1, Armament: 1,
Shields: 1, Weapons: 1,
Cargo: cargoSize, Shields: 1,
Cargo: cargoSize,
},
} }
sg := game.ShipGroup{ sg := game.ShipGroup{
Type: ship, Type: ship,
@@ -71,11 +77,13 @@ func TestCargoCapacity(t *testing.T) {
func TestBombingPower(t *testing.T) { func TestBombingPower(t *testing.T) {
Gunship := game.ShipType{ Gunship := game.ShipType{
Drive: 60.0, ShipTypeReport: game.ShipTypeReport{
Armament: 3, Drive: 60.0,
Weapons: 30.0, Armament: 3,
Shields: 100.0, Weapons: 30.0,
Cargo: 0.0, Shields: 100.0,
Cargo: 0.0,
},
} }
sg := game.ShipGroup{ sg := game.ShipGroup{
Type: Gunship, Type: Gunship,
+8 -1
View File
@@ -35,8 +35,15 @@ func saveTurn(s Storage, t uint, g game.Game) error {
return NewStorageError(err) return NewStorageError(err)
} }
// TODO: save reports // TODO: save reports
for i := range g.Race {
saveRace(s, g, i)
}
// TODO: save battles // 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 { func (r *repo) SaveState(g game.Game) error {