well, fuck...
This commit is contained in:
+25
-5
@@ -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,
|
||||
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,
|
||||
Resources: res,
|
||||
Production: prod,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,26 +6,40 @@ import (
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type Planet struct {
|
||||
type UnidentifiedPlanet 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 - Промышленность
|
||||
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 - Запасы ресурсов / сырья
|
||||
}
|
||||
|
||||
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: за вычетом затрат, расходуемых в течение хода на модернизацию кораблей
|
||||
|
||||
@@ -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"`
|
||||
Relation Relation `json:"relation"`
|
||||
}
|
||||
|
||||
func (r Race) FlightDistance() float64 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -4,6 +4,15 @@ import "github.com/google/uuid"
|
||||
|
||||
type Science struct {
|
||||
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"`
|
||||
|
||||
+11
-2
@@ -7,8 +7,7 @@ import (
|
||||
"github.com/iliadenisov/galaxy/pkg/number"
|
||||
)
|
||||
|
||||
type ShipType struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
type ShipTypeReport struct {
|
||||
Name string `json:"name"`
|
||||
Drive float64 `json:"drive"` // [0], [1...]
|
||||
Armament uint `json:"armament"`
|
||||
@@ -17,6 +16,16 @@ type ShipType struct {
|
||||
Cargo float64 `json:"cargo"` // [0], [1...]
|
||||
}
|
||||
|
||||
type ShipType struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
ShipTypeReport
|
||||
}
|
||||
|
||||
type ShipTypeReportForeign struct {
|
||||
RaceName string
|
||||
ShipTypeReport
|
||||
}
|
||||
|
||||
type ShipGroup struct {
|
||||
TypeID uuid.UUID `json:"id"`
|
||||
Type ShipType `json:"-"` // TODO: fill upon load from store
|
||||
|
||||
@@ -9,20 +9,24 @@ import (
|
||||
|
||||
func TestShipType(t *testing.T) {
|
||||
Gunship := game.ShipType{
|
||||
ShipTypeReport: game.ShipTypeReport{
|
||||
Drive: 4,
|
||||
Armament: 2,
|
||||
Weapons: 2,
|
||||
Shields: 4,
|
||||
Cargo: 0,
|
||||
},
|
||||
}
|
||||
assert.Equal(t, Gunship.EmptyMass(), 11.)
|
||||
|
||||
Cruiser := game.ShipType{
|
||||
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{
|
||||
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{
|
||||
ShipTypeReport: game.ShipTypeReport{
|
||||
Drive: 60.0,
|
||||
Armament: 3,
|
||||
Weapons: 30.0,
|
||||
Shields: 100.0,
|
||||
Cargo: 0.0,
|
||||
},
|
||||
}
|
||||
sg := game.ShipGroup{
|
||||
Type: Gunship,
|
||||
|
||||
+8
-1
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user