towards generation
This commit is contained in:
@@ -1,30 +1,7 @@
|
|||||||
package server
|
package game
|
||||||
|
|
||||||
import "math"
|
import "math"
|
||||||
|
|
||||||
type GameIdentifier string
|
|
||||||
type RaceIdentifier string
|
|
||||||
|
|
||||||
type Game struct {
|
|
||||||
Id GameIdentifier
|
|
||||||
Name string
|
|
||||||
Schedule string // TODO: implement somehow
|
|
||||||
Turn uint
|
|
||||||
Races []Race
|
|
||||||
Planets []Planet
|
|
||||||
warState map[uint]uint
|
|
||||||
}
|
|
||||||
|
|
||||||
type Race struct {
|
|
||||||
Id RaceIdentifier
|
|
||||||
Name string
|
|
||||||
Drive float64
|
|
||||||
Weapons float64
|
|
||||||
Shields float64
|
|
||||||
Cargo float64
|
|
||||||
Planets []Planet
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r Race) FlightDistance() float64 {
|
func (r Race) FlightDistance() float64 {
|
||||||
return r.Drive * 40
|
return r.Drive * 40
|
||||||
}
|
}
|
||||||
@@ -33,26 +10,6 @@ func (r Race) VisibilityDistance() float64 {
|
|||||||
return r.Drive * 30
|
return r.Drive * 30
|
||||||
}
|
}
|
||||||
|
|
||||||
type Coordinate struct {
|
|
||||||
X, Y float64
|
|
||||||
}
|
|
||||||
|
|
||||||
type Planet struct {
|
|
||||||
Number uint
|
|
||||||
Name string
|
|
||||||
Position Coordinate
|
|
||||||
Size float64
|
|
||||||
Production string // TODO: kinda enum
|
|
||||||
Resources float64 // Сырьё
|
|
||||||
Industry float64 // Промышленность
|
|
||||||
Population float64 // Население
|
|
||||||
|
|
||||||
Capital float64 // CAP $ - Запасы промышленности
|
|
||||||
Material float64 // MAT M - Запасы сырья
|
|
||||||
Colonists float64 // COL C - Количество колонистов
|
|
||||||
// Параметр "L" означает количество свободных производственных единиц.
|
|
||||||
}
|
|
||||||
|
|
||||||
// Производственный потенциал (I)
|
// Производственный потенциал (I)
|
||||||
// промышленность * 0.75 + население * 0.25
|
// промышленность * 0.75 + население * 0.25
|
||||||
func (p Planet) ProductionCapacity() float64 {
|
func (p Planet) ProductionCapacity() float64 {
|
||||||
@@ -87,23 +44,6 @@ func (p *Planet) IncreasePopulation() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type Science struct {
|
|
||||||
Name string
|
|
||||||
Drive float64
|
|
||||||
Weapons float64
|
|
||||||
Shields float64
|
|
||||||
Cargo float64
|
|
||||||
}
|
|
||||||
|
|
||||||
type ShipType struct {
|
|
||||||
Name string
|
|
||||||
Drive float64 // [0], [1...]
|
|
||||||
Armament uint
|
|
||||||
Weapons float64 // [0], [1...]
|
|
||||||
Shields float64 // [0], [1...]
|
|
||||||
Cargo float64 // [0], [1...]
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: test on real values
|
// TODO: test on real values
|
||||||
func (st ShipType) EmptyMass() float64 {
|
func (st ShipType) EmptyMass() float64 {
|
||||||
shipMass := st.DriveMass() + st.ShieldsMass() + st.CargoMass() + st.WeaponsMass()
|
shipMass := st.DriveMass() + st.ShieldsMass() + st.CargoMass() + st.WeaponsMass()
|
||||||
@@ -126,17 +66,6 @@ func (st ShipType) WeaponsMass() float64 {
|
|||||||
return float64(st.Armament)*(st.Weapons/2) + st.Weapons/2
|
return float64(st.Armament)*(st.Weapons/2) + st.Weapons/2
|
||||||
}
|
}
|
||||||
|
|
||||||
type ShipGroup struct {
|
|
||||||
Type ShipType
|
|
||||||
Number uint
|
|
||||||
State string // TODO: kinda enum: In_Orbit, In_Space, Transfer_State, Upgrade
|
|
||||||
Load float64 // Cargo loaded - "Масса груза"
|
|
||||||
Drive float64
|
|
||||||
Weapons float64
|
|
||||||
Shields float64
|
|
||||||
Cargo float64
|
|
||||||
}
|
|
||||||
|
|
||||||
// Грузоподъёмность
|
// Грузоподъёмность
|
||||||
func (sg ShipGroup) CargoCapacity() float64 {
|
func (sg ShipGroup) CargoCapacity() float64 {
|
||||||
return sg.Drive * (sg.Type.Cargo + (sg.Type.Cargo*sg.Type.Cargo)/20)
|
return sg.Drive * (sg.Type.Cargo + (sg.Type.Cargo*sg.Type.Cargo)/20)
|
||||||
@@ -191,10 +120,6 @@ func (sg ShipGroup) BombingPower() float64 {
|
|||||||
return toFixed3(result)
|
return toFixed3(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Fleet struct {
|
|
||||||
ShipGroups []ShipGroup
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: test this
|
// TODO: test this
|
||||||
func (fl Fleet) Speed() float64 {
|
func (fl Fleet) Speed() float64 {
|
||||||
result := math.MaxFloat64
|
result := math.MaxFloat64
|
||||||
@@ -0,0 +1,100 @@
|
|||||||
|
package game
|
||||||
|
|
||||||
|
type GameIdentifier string
|
||||||
|
type RaceIdentifier string
|
||||||
|
|
||||||
|
type Game struct {
|
||||||
|
Id GameIdentifier
|
||||||
|
Name string
|
||||||
|
Schedule string // TODO: implement somehow
|
||||||
|
Turn uint
|
||||||
|
Races []Race
|
||||||
|
Planets []Planet
|
||||||
|
WarState map[RaceIdentifier]RaceIdentifier
|
||||||
|
}
|
||||||
|
|
||||||
|
type Race struct {
|
||||||
|
Id RaceIdentifier
|
||||||
|
Name string
|
||||||
|
Drive float64
|
||||||
|
Weapons float64
|
||||||
|
Shields float64
|
||||||
|
Cargo float64
|
||||||
|
}
|
||||||
|
|
||||||
|
type PlanetProduction string
|
||||||
|
|
||||||
|
const (
|
||||||
|
ProductionMaterial PlanetProduction = "MAT"
|
||||||
|
ProductionCapital PlanetProduction = "CAP"
|
||||||
|
ProductionDrive PlanetProduction = "DRIVE"
|
||||||
|
ProductionWeapons PlanetProduction = "WEAPONS"
|
||||||
|
ProductionShields PlanetProduction = "SHIELDS"
|
||||||
|
ProductionCargo PlanetProduction = "CARGO"
|
||||||
|
|
||||||
|
ProductionScience PlanetProduction = "SCIENCE"
|
||||||
|
ProductionShip PlanetProduction = "SHIP"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ProductionType struct {
|
||||||
|
Production PlanetProduction
|
||||||
|
SubjectName string
|
||||||
|
}
|
||||||
|
|
||||||
|
type Planet struct {
|
||||||
|
Number uint
|
||||||
|
Name string
|
||||||
|
Position Coordinate
|
||||||
|
Size float64
|
||||||
|
|
||||||
|
Owner RaceIdentifier
|
||||||
|
Production ProductionType
|
||||||
|
Resources float64 // Сырьё
|
||||||
|
Industry float64 // Промышленность
|
||||||
|
Population float64 // Население
|
||||||
|
|
||||||
|
Capital float64 // CAP $ - Запасы промышленности
|
||||||
|
Material float64 // MAT M - Запасы сырья
|
||||||
|
Colonists float64 // COL C - Количество колонистов
|
||||||
|
// Параметр "L" означает количество свободных производственных единиц.
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Planet) setOwner(id RaceIdentifier) {
|
||||||
|
p.Owner = id
|
||||||
|
}
|
||||||
|
|
||||||
|
type Coordinate struct {
|
||||||
|
X, Y float64
|
||||||
|
}
|
||||||
|
|
||||||
|
type Science struct {
|
||||||
|
Name string
|
||||||
|
Drive float64
|
||||||
|
Weapons float64
|
||||||
|
Shields float64
|
||||||
|
Cargo float64
|
||||||
|
}
|
||||||
|
|
||||||
|
type ShipType struct {
|
||||||
|
Name string
|
||||||
|
Drive float64 // [0], [1...]
|
||||||
|
Armament uint
|
||||||
|
Weapons float64 // [0], [1...]
|
||||||
|
Shields float64 // [0], [1...]
|
||||||
|
Cargo float64 // [0], [1...]
|
||||||
|
}
|
||||||
|
|
||||||
|
type ShipGroup struct {
|
||||||
|
Type ShipType
|
||||||
|
Number uint
|
||||||
|
State string // TODO: kinda enum: In_Orbit, In_Space, Transfer_State, Upgrade
|
||||||
|
Load float64 // Cargo loaded - "Масса груза"
|
||||||
|
Drive float64
|
||||||
|
Weapons float64
|
||||||
|
Shields float64
|
||||||
|
Cargo float64
|
||||||
|
}
|
||||||
|
|
||||||
|
type Fleet struct {
|
||||||
|
ShipGroups []ShipGroup
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package game
|
||||||
|
|
||||||
|
func CreateGame(id GameIdentifier, name string, races []Race, planets []Planet) Game {
|
||||||
|
return Game{
|
||||||
|
Id: id,
|
||||||
|
Name: name,
|
||||||
|
Turn: 0,
|
||||||
|
Races: races,
|
||||||
|
Planets: planets,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func CreateRace(id RaceIdentifier, name string) Race {
|
||||||
|
return Race{
|
||||||
|
Id: id,
|
||||||
|
Name: name,
|
||||||
|
Drive: 1.0,
|
||||||
|
Weapons: 1.0,
|
||||||
|
Shields: 1.0,
|
||||||
|
Cargo: 1.0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func CreatePlanet(number uint, name string, position Coordinate, size float64, res float64, pop float64) Planet {
|
||||||
|
return Planet{
|
||||||
|
Number: number,
|
||||||
|
Name: name,
|
||||||
|
Position: position,
|
||||||
|
Size: size,
|
||||||
|
Production: ProductionType{ProductionDrive, ""},
|
||||||
|
Resources: res,
|
||||||
|
Population: pop,
|
||||||
|
|
||||||
|
Industry: 0,
|
||||||
|
Capital: 0,
|
||||||
|
Material: 0,
|
||||||
|
Colonists: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package game
|
||||||
|
|
||||||
|
type GameParameter struct {
|
||||||
|
Series string
|
||||||
|
Players uint
|
||||||
|
Public bool
|
||||||
|
}
|
||||||
@@ -1,13 +1,13 @@
|
|||||||
package server_test
|
package game_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/iliadenisov/galaxy/pkg/server"
|
"github.com/iliadenisov/galaxy/pkg/game"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_ShipType(t *testing.T) {
|
func Test_ShipType(t *testing.T) {
|
||||||
Gunship := server.ShipType{
|
Gunship := game.ShipType{
|
||||||
Drive: 4,
|
Drive: 4,
|
||||||
Armament: 2,
|
Armament: 2,
|
||||||
Weapons: 2,
|
Weapons: 2,
|
||||||
@@ -19,7 +19,7 @@ func Test_ShipType(t *testing.T) {
|
|||||||
t.Errorf("Cruiser mass expected %.3f but %.3f given", 11., Gunship.EmptyMass())
|
t.Errorf("Cruiser mass expected %.3f but %.3f given", 11., Gunship.EmptyMass())
|
||||||
}
|
}
|
||||||
|
|
||||||
Cruiser := server.ShipType{
|
Cruiser := game.ShipType{
|
||||||
Drive: 15,
|
Drive: 15,
|
||||||
Armament: 1,
|
Armament: 1,
|
||||||
Weapons: 15,
|
Weapons: 15,
|
||||||
@@ -31,7 +31,7 @@ func Test_ShipType(t *testing.T) {
|
|||||||
t.Errorf("Cruiser mass expected %.3f but %.3f given", 45., Cruiser.EmptyMass())
|
t.Errorf("Cruiser mass expected %.3f but %.3f given", 45., Cruiser.EmptyMass())
|
||||||
}
|
}
|
||||||
|
|
||||||
sg := server.ShipGroup{
|
sg := game.ShipGroup{
|
||||||
Type: Cruiser,
|
Type: Cruiser,
|
||||||
Number: 1,
|
Number: 1,
|
||||||
State: "In_Orbit",
|
State: "In_Orbit",
|
||||||
@@ -53,14 +53,14 @@ func Test_ShipType(t *testing.T) {
|
|||||||
|
|
||||||
func Test_CargoCapacity(t *testing.T) {
|
func Test_CargoCapacity(t *testing.T) {
|
||||||
test := func(cargoSize float64, expectCapacity float64) {
|
test := func(cargoSize float64, expectCapacity float64) {
|
||||||
ship := server.ShipType{
|
ship := game.ShipType{
|
||||||
Drive: 1,
|
Drive: 1,
|
||||||
Armament: 1,
|
Armament: 1,
|
||||||
Weapons: 1,
|
Weapons: 1,
|
||||||
Shields: 1,
|
Shields: 1,
|
||||||
Cargo: cargoSize,
|
Cargo: cargoSize,
|
||||||
}
|
}
|
||||||
sg := server.ShipGroup{
|
sg := game.ShipGroup{
|
||||||
Type: ship,
|
Type: ship,
|
||||||
Number: 1,
|
Number: 1,
|
||||||
State: "In_Orbit",
|
State: "In_Orbit",
|
||||||
@@ -81,14 +81,14 @@ func Test_CargoCapacity(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Test_BombingPower(t *testing.T) {
|
func Test_BombingPower(t *testing.T) {
|
||||||
Gunship := server.ShipType{
|
Gunship := game.ShipType{
|
||||||
Drive: 60.0,
|
Drive: 60.0,
|
||||||
Armament: 3,
|
Armament: 3,
|
||||||
Weapons: 30.0,
|
Weapons: 30.0,
|
||||||
Shields: 100.0,
|
Shields: 100.0,
|
||||||
Cargo: 0.0,
|
Cargo: 0.0,
|
||||||
}
|
}
|
||||||
sg := server.ShipGroup{
|
sg := game.ShipGroup{
|
||||||
Type: Gunship,
|
Type: Gunship,
|
||||||
Number: 1,
|
Number: 1,
|
||||||
State: "In_Orbit",
|
State: "In_Orbit",
|
||||||
@@ -37,7 +37,7 @@ type Plotter struct {
|
|||||||
sectors draw.Plane
|
sectors draw.Plane
|
||||||
}
|
}
|
||||||
|
|
||||||
func Generate(param MapParameters) (result Map) {
|
func Generate(param MapParameter) (result Map) {
|
||||||
pl := func(c Coordinate, param UninhabitedPlanetParameters) Planet {
|
pl := func(c Coordinate, param UninhabitedPlanetParameters) Planet {
|
||||||
return Planet{
|
return Planet{
|
||||||
Position: c,
|
Position: c,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package generator
|
package generator
|
||||||
|
|
||||||
type MapParameters struct {
|
type MapParameter struct {
|
||||||
Players uint
|
Players uint
|
||||||
HW_Size uint
|
HW_Size uint
|
||||||
HW_Resources uint
|
HW_Resources uint
|
||||||
@@ -27,8 +27,8 @@ type UninhabitedPlanetParameters struct {
|
|||||||
Probability float64
|
Probability float64
|
||||||
}
|
}
|
||||||
|
|
||||||
func DefaultMapParameters() MapParameters {
|
func DefaultMapParameters() MapParameter {
|
||||||
return MapParameters{
|
return MapParameter{
|
||||||
Players: 25,
|
Players: 25,
|
||||||
HW_Size: 1000,
|
HW_Size: 1000,
|
||||||
HW_Resources: 10,
|
HW_Resources: 10,
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"github.com/iliadenisov/galaxy/pkg/game"
|
||||||
|
"github.com/iliadenisov/galaxy/pkg/generator"
|
||||||
|
"github.com/iliadenisov/galaxy/pkg/storage"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Server struct {
|
||||||
|
storage storage.Storage
|
||||||
|
}
|
||||||
|
|
||||||
|
func New(storage storage.Storage) Server {
|
||||||
|
return Server{storage: storage}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s Server) CreateGame(gameParam game.GameParameter, mapParam generator.MapParameter) (game.Game, error) {
|
||||||
|
_ = generator.Generate(mapParam)
|
||||||
|
return game.Game{}, errors.New("not yet implemented")
|
||||||
|
}
|
||||||
+11
-7
@@ -1,11 +1,11 @@
|
|||||||
package storage
|
package storage
|
||||||
|
|
||||||
import "github.com/iliadenisov/galaxy/pkg/server"
|
import "github.com/iliadenisov/galaxy/pkg/game"
|
||||||
|
|
||||||
// games/
|
// games/
|
||||||
// data.json - id, name, turn, schedule, status
|
// data.json - id, name, turn, schedule, status
|
||||||
// game123/
|
// game123/
|
||||||
// racelist/<race_id>/data.json - account_id, name, status, war/peace(?), last_order, etc.
|
// race/<race_id>/data.json - account_id, name, status, war/peace(?), last_order, etc.
|
||||||
// order/<turn>/<race_id>/0.json - incoming orders
|
// order/<turn>/<race_id>/0.json - incoming orders
|
||||||
// turn/12/log/ - ?
|
// turn/12/log/ - ?
|
||||||
// turn/12/order/<race_id>/0.json - processed orders
|
// turn/12/order/<race_id>/0.json - processed orders
|
||||||
@@ -16,11 +16,15 @@ import "github.com/iliadenisov/galaxy/pkg/server"
|
|||||||
// turn/12/battle/<planet_id>/<battle_number>.json
|
// turn/12/battle/<planet_id>/<battle_number>.json
|
||||||
|
|
||||||
type Storage interface {
|
type Storage interface {
|
||||||
ListGames() ([]server.GameIdentifier, error)
|
GenerateRaceId() game.RaceIdentifier
|
||||||
|
GenerateGameId() game.GameIdentifier
|
||||||
|
|
||||||
LoadRace(game_id server.GameIdentifier, race_id server.RaceIdentifier) (server.Race, error)
|
CreateGame(game.GameParameter) (game.Game, error)
|
||||||
SaveRace(game_id server.GameIdentifier, race server.Race) error
|
ListGames() ([]game.GameIdentifier, error)
|
||||||
|
|
||||||
LoadState(game_id server.GameIdentifier) (server.Game, error)
|
LoadRace(game_id game.GameIdentifier, race_id game.RaceIdentifier) (game.Race, error)
|
||||||
SaveState(game server.Game) error
|
SaveRace(game_id game.GameIdentifier, race game.Race) error
|
||||||
|
|
||||||
|
LoadState(game_id game.GameIdentifier) (game.Game, error)
|
||||||
|
SaveState(game game.Game) error
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user