engine

package
v0.0.0-...-b9fa8cb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 20, 2024 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDuplicateKey = errors.New("duplicate key")
View Source
var ErrInvalidField = errors.New("invalid field")
View Source
var ErrMissingField = errors.New("missing field")
View Source
var ErrNoConnection = errors.New("no connection")
View Source
var ErrNoEngine = errors.New("missing engine")
View Source
var ErrNoGame = errors.New("missing game")
View Source
var ErrNoNation = errors.New("missing nation")
View Source
var ErrNoStore = errors.New("missing store")
View Source
var ErrNoTurn = errors.New("missing turn")
View Source
var ErrNotImplemented = errors.New("not implemented")

Functions

func WithColonies

func WithColonies(colonies []*Colony) func(e *Engine) error

Types

type AssembleFactoryGroupOrder

type AssembleFactoryGroupOrder struct {
	CorS     string // id of ship or colony to assemble in
	Quantity int
	Unit     string
	Product  string
}

type AssembleMiningGroupOrder

type AssembleMiningGroupOrder struct {
	CorS     string // id of ship or colony to assemble in
	Quantity int
	Unit     string
	Product  string
}

type AssemblyPhaseOrder

type AssemblyPhaseOrder struct {
	FactoryGroup *AssembleFactoryGroupOrder
	MiningGroup  *AssembleMiningGroupOrder
}

type Colony

type Colony struct {
	Id           string  // key, format is always C# where # is an integer
	ControlledBy *Player // nil only if colony is not controlled
	Name         string
}

type ControlColonyOrder

type ControlColonyOrder struct {
	Id string // id of colony to take control of
}

func (*ControlColonyOrder) Execute

func (o *ControlColonyOrder) Execute(e *Engine, p *Player) error

Execute changes the controller of a colony to the player. Will fail if the colony is controlled by another player.

type ControlPhaseOrder

type ControlPhaseOrder struct {
	ControlColony *ControlColonyOrder
	ControlShip   *ControlShipOrder
	NameColony    *NameColonyOrder
	NameShip      *NameShipOrder
}

type ControlShipOrder

type ControlShipOrder struct {
	Id string // id of ship to take control of
}

func (*ControlShipOrder) Execute

func (o *ControlShipOrder) Execute(e *Engine, p *Player) error

Execute changes the controller of a ship to the player. Will fail if the ship is controlled by another player.

type Coordinates

type Coordinates struct {
	X int
	Y int
	Z int
}

Coordinates are the x,y,z coordinates of a system

type Engine

type Engine struct {
	Game     *models.Game
	Colonies map[string]*Colony // key is id
	Ships    map[string]*Ship   // key is id
	// contains filtered or unexported fields
}

func Open

func Open(r *models.Store, options ...Option) (e *Engine, err error)

Open returns an initialized engine

func (*Engine) Execute

func (e *Engine) Execute(pos []*PhaseOrders, phases ...string) error

Execute runs all the orders in the list of phases. If the list is empty, no phases will run.

func (*Engine) ExecuteAssemblyPhase

func (e *Engine) ExecuteAssemblyPhase(pos []*PhaseOrders) []error

ExecuteAssemblyPhase runs all the orders in the assembly phase.

func (*Engine) ExecuteControlPhase

func (e *Engine) ExecuteControlPhase(pos []*PhaseOrders) []error

ExecuteControlPhase runs all the orders in the control phase.

func (*Engine) ExecuteRetoolPhase

func (e *Engine) ExecuteRetoolPhase(pos []*PhaseOrders) []error

ExecuteRetoolPhase runs all the orders in the retool phase.

func (*Engine) LoadGame

func (e *Engine) LoadGame(shortName string) error

func (*Engine) Report

func (e *Engine) Report(w io.Writer, game string, nation, year, quarter int) error

func (*Engine) ReportWriter

func (e *Engine) ReportWriter(game *models.Game, nationNo int, w io.Writer) error

func (*Engine) Version

func (e *Engine) Version() string

type FactoryGroup

type FactoryGroup struct {
	Id             int // key in database
	No             int // factory group number
	BuildCode      string
	BuildTechLevel int
	Units          []*XGroupUnits
}

type Game

type Game struct {
	Id          int
	ShortName   string
	Name        string
	Descr       string
	Players     []*Player
	CurrentTurn string // formatted as yyyy/q
	Turn        int    // index to current game turn
	Turns       []*Turn
	Nations     []*Nation
	Systems     []*System
}

Game configuration

type Inventory

type Inventory struct {
	Name           string `json:"name"`
	Code           string `json:"code,omitempty"`
	TechLevel      int    `json:"tech-level,omitempty"`
	OperationalQty int    `json:"operational-qty,omitempty"`
	StowedQty      int    `json:"stowed-qty,omitempty"`
	MassUnits      int    `json:"mass-units,omitempty"`
	EnclosedUnits  int    `json:"enclosed-units,omitempty"`
}

type MiningGroup

type MiningGroup struct {
	Id      int // key in database
	No      int // mining group number
	Deposit *NaturalResource
	Units   []*XGroupUnits
}

type NameColonyOrder

type NameColonyOrder struct {
	Id   string // id of colony to name
	Name string // name to assign to colony
}

func (*NameColonyOrder) Execute

func (o *NameColonyOrder) Execute(e *Engine, p *Player) error

Execute changes the name of a colony controlled by a player. Will fail if the colony is not controlled by the player.

type NameShipOrder

type NameShipOrder struct {
	Id   string // id of ship to name
	Name string // name to assign to ship
}

func (*NameShipOrder) Execute

func (o *NameShipOrder) Execute(e *Engine, p *Player) error

Execute changes the name of a ship controlled by a player. Will fail if the ship is not controlled by the player.

type Nation

type Nation struct {
	Id          int // this is the PK in the database
	No          int
	Name        string
	Description string
	Speciality  string
	Government  struct {
		Kind string
		Name string
	}
	HomePlanet struct {
		Name     string
		Location *Planet
	}
	TechLevel    int
	ResearchPool int
	Skills       Skills
	Colonies     []*XColony
	Ships        []*XShip
	ControlledBy *Player
}

Nation configuration

type NaturalResource

type NaturalResource struct {
	Id                int // key in database
	No                int
	Kind              string
	YieldPct          float64
	InitialQuantity   int
	QuantityRemaining int
}

type Option

type Option func(e *Engine) error

type PhaseOrders

type PhaseOrders struct {
	Player *Player
	// orders sorted by phase
	Combat      []*orders.Order
	SetUp       []*orders.Order
	Disassembly []*orders.Order
	Retool      []*RetoolPhaseOrder
	Transfer    []*orders.Order
	Assembly    []*AssemblyPhaseOrder
	Trade       []*orders.Order
	Survey      []*orders.Order
	Espionage   []*orders.Order
	Movement    []*orders.Order
	Draft       []*orders.Order
	Pay         []*orders.Order
	Ration      []*orders.Order
	Control     []*ControlPhaseOrder
}

type Planet

type Planet struct {
	Id                 int
	Star               *Star // star the planet orbits
	Orbit              int
	Kind               string
	HomePlanet         bool
	HabitabilityNumber int
	Resources          []*NaturalResource
}

type Player

type Player struct {
	Id     int
	Handle string
	Nation struct {
		Name       string
		Speciality string
		HomeWorld  string
		GovtKind   string
		GovtName   string
	}
}

type ReportTurns

type ReportTurns struct {
	Store string       `json:"store"` // path to store data
	Index []TurnsIndex `json:"index"`
}

ReportTurns configuration

func CreateTurns

func CreateTurns(path string, overwrite bool) (*ReportTurns, error)

CreateTurns creates a new store. Assumes that the path to store the data already exists. It returns any errors.

func LoadTurns

func LoadTurns(path string) (*ReportTurns, error)

LoadTurns loads an existing store. It returns any errors.

func (*ReportTurns) Read

func (s *ReportTurns) Read() error

Read loads a store from a JSON file. It returns any errors.

func (*ReportTurns) Write

func (s *ReportTurns) Write() error

Write writes a store to a JSON file. It returns any errors.

type RetoolFactoryGroupOrder

type RetoolFactoryGroupOrder struct {
	CorS     string // id of ship or colony to assemble in
	Quantity int
	Unit     string
	Product  string
}

type RetoolMiningGroupOrder

type RetoolMiningGroupOrder struct {
	CorS     string // id of ship or colony to assemble in
	Quantity int
	Unit     string
	Product  string
}

type RetoolPhaseOrder

type RetoolPhaseOrder struct {
	FactoryGroup *RetoolFactoryGroupOrder
	MiningGroup  *RetoolMiningGroupOrder
}

type Ship

type Ship struct {
	Id           string  // key, format is always S# where # is an integer
	ControlledBy *Player // nil only if ship is not controlled
	Name         string
}

type Skills

type Skills struct {
	Biology       int `json:"biology"`
	Bureaucracy   int `json:"bureaucracy"`
	Gravitics     int `json:"gravitics"`
	LifeSupport   int `json:"life-support"`
	Manufacturing int `json:"manufacturing"`
	Military      int `json:"military"`
	Mining        int `json:"mining"`
	Shields       int `json:"shields"`
}

type Star

type Star struct {
	Id       int
	System   *System // system the star is in
	Sequence string
	Kind     string
	HomeStar bool
	Orbits   []*Planet
}

type System

type System struct {
	Id          int
	X           int
	Y           int
	Z           int
	HomeSystem  bool
	Singularity bool
	Ring        int
	Stars       []*Star
}

type Turn

type Turn struct {
	GameID  int
	Turn    string    // turn number as yyyy/q
	StartDt time.Time // date+time the turn starts
	EndDt   time.Time // date+time the turn ends
}

type TurnsIndex

type TurnsIndex struct {
	Id int `json:"id"` // unique turn number
}

type XColony

type XColony struct {
	Id         int // key for database
	No         int
	Name       string
	Kind       string
	Location   *Planet
	TechLevel  int
	Population struct {
		Professional      XPopulation
		Soldier           XPopulation
		Unskilled         XPopulation
		Unemployed        XPopulation
		ConstructionCrews int
		SpyTeams          int
		RebelPct          float64
		Births            int
		Deaths            int
	}
	Hull          []*Inventory // units used to build colony
	Inventory     []*Inventory // units stored in colony
	FactoryGroups []*FactoryGroup
	FarmGroups    []*XGroup
	MiningGroups  []*MiningGroup
}

type XGroup

type XGroup struct {
	Id    int
	Name  string
	Units []*XGroupUnits
}

type XGroupUnits

type XGroupUnits struct {
	TechLevel int
	Qty       int
	Stages    []int
}

type XPopulation

type XPopulation struct {
	Code   string
	Qty    int
	Pay    float64
	Ration float64
}

type XShip

type XShip struct {
	Id         int // key for database
	No         int
	Name       string
	Kind       string
	Location   *Planet
	TechLevel  int
	Population struct {
		Professional      XPopulation
		Soldier           XPopulation
		Unskilled         XPopulation
		Unemployed        XPopulation
		ConstructionCrews int
		SpyTeams          int
		RebelPct          float64
	}
	Hull          []*Inventory // units used to build ship
	Inventory     []*Inventory // units stored in ship
	FactoryGroups []*FactoryGroup
	FarmGroups    []*XGroup
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL