models

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 ErrNoDataFound = errors.New("no data found")
View Source
var ErrNotImplemented = errors.New("not implemented")
View Source
var ErrUnauthorized = errors.New("unauthorized")

Functions

This section is empty.

Types

type CSDetail

type CSDetail struct {
	CS           *ColonyOrShip
	EffTurn      *Turn // turn record becomes active
	EndTurn      *Turn // turn record ceases to be active
	Name         string
	TechLevel    int
	ControlledBy *Player
}

CSDetail contains items that may change from turn to turn

type CSHull

type CSHull struct {
	CS              *ColonyOrShip
	EffTurn         *Turn // turn record becomes active
	EndTurn         *Turn // turn record ceases to be active
	Unit            *Unit
	TechLevel       int
	QtyOperational  int
	MassOperational int
	TotalMass       int
}

CSHull is the infrastructure and components of the ship or colony. Colonies are not allowed to add engines or drives to their hull.

type CSInventory

type CSInventory struct {
	CS              *ColonyOrShip
	EffTurn         *Turn // turn record becomes active
	EndTurn         *Turn // turn record ceases to be active
	Unit            *Unit
	TechLevel       int
	QtyOperational  int
	MassOperational int
	QtyStowed       int
	MassStowed      int
	TotalMass       int
	EnclosedMass    int
}

CSInventory is the contents of the ship or colony.

type CSLocation

type CSLocation struct {
	CS       *ColonyOrShip
	EffTurn  *Turn // turn record becomes active
	EndTurn  *Turn // turn record ceases to be active
	Location *Planet
}

CSLocation is the location of the colony or ship and may change from turn to turn

type CSPay

type CSPay struct {
	CS              *ColonyOrShip
	EffTurn         *Turn // turn record becomes active
	EndTurn         *Turn // turn record ceases to be active
	ProfessionalPct float64
	SoldierPct      float64
	UnskilledPct    float64
	UnemployedPct   float64
}

CSPay is the pay rate for the ship or colony.

type CSPopulation

type CSPopulation struct {
	CS                  *ColonyOrShip
	EffTurn             *Turn // turn record becomes active
	EndTurn             *Turn // turn record ceases to be active
	QtyProfessional     int
	QtySoldier          int
	QtyUnskilled        int
	QtyUnemployed       int
	QtyConstructionCrew int
	QtySpyTeam          int
	RebelPct            float64
	Births              int
	Deaths              int
}

CSPopulation is the population of the ship or colony.

type CSRations

type CSRations struct {
	CS              *ColonyOrShip
	EffTurn         *Turn // turn record becomes active
	EndTurn         *Turn // turn record ceases to be active
	ProfessionalPct float64
	SoldierPct      float64
	UnskilledPct    float64
	UnemployedPct   float64
}

CSRations is the rations rate for the ship or colony.

type Claim

type Claim struct {
	User       string
	PlayerId   int
	PlayerName string
	NationNo   int
}

type ColonyOrShip

type ColonyOrShip struct {
	Game       *Game
	Planet     *Planet
	Id         int    // unique identifier
	MSN        int    // manufacturer serial number; in game id for the colony or ship
	Kind       string // surface colony, enclosed colony, orbital colony, ship
	HomeColony bool
	BuiltBy    *Nation
	Details    []*CSDetail
	Locations  []*CSLocation
	Hull       []*CSHull
	Inventory  []*CSInventory
	Population []*CSPopulation
	Rations    []*CSRations
	Pay        []*CSPay
	Factories  []*FactoryGroup
	Farms      []*FarmGroup
	Mines      []*MiningGroup
}

ColonyOrShip is either a colony or a ship. Ships may change orbits; colonies may not.

type Coordinates

type Coordinates struct {
	X int
	Y int
	Z int
}

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

func (Coordinates) Less

func (c Coordinates) Less(d Coordinates) bool

func (Coordinates) String

func (c Coordinates) String() string

type FactoryGroup

type FactoryGroup struct {
	CS      *ColonyOrShip
	Id      int // unique identifier
	No      int
	EffTurn *Turn                // turn record becomes active
	EndTurn *Turn                // turn record ceases to be active
	Unit    *Unit                // unit being manufactured
	Units   []*FactoryGroupUnits // factory units in the group
	Stages  []*FactoryGroupStages
}

FactoryGroup is a group of factories on the ship or colony. Each group is dedicated to manufacturing one type of unit.

type FactoryGroupStages

type FactoryGroupStages struct {
	Group     *FactoryGroup
	Turn      *Turn
	QtyStage1 int
	QtyStage2 int
	QtyStage3 int
	QtyStage4 int
}

FactoryGroupStages is the number units in each stage of the group

type FactoryGroupUnits

type FactoryGroupUnits struct {
	Group          *FactoryGroup
	EffTurn        *Turn // turn record becomes active
	EndTurn        *Turn // turn record ceases to be active
	Unit           *Unit // factory unit doing the manufacturing
	QtyOperational int
}

FactoryGroupUnits is the number of factories working together in the group

type FarmGroup

type FarmGroup struct {
	CS      *ColonyOrShip
	Id      int // unique identifier
	No      int
	EffTurn *Turn             // turn record becomes active
	EndTurn *Turn             // turn record ceases to be active
	Unit    *Unit             // unit being farmed
	Units   []*FarmGroupUnits // farm units in the group
	Stages  []*FarmGroupStages
}

FarmGroup is a group of farms on the ship or colony.

type FarmGroupStages

type FarmGroupStages struct {
	Group     *FarmGroup
	Turn      *Turn
	QtyStage1 int
	QtyStage2 int
	QtyStage3 int
	QtyStage4 int
}

FarmGroupStages is the number units in each stage of the group

type FarmGroupUnits

type FarmGroupUnits struct {
	Group          *FarmGroup
	EffTurn        *Turn // turn record becomes active
	EndTurn        *Turn // turn record ceases to be active
	Unit           *Unit // farm unit
	QtyOperational int
}

FarmGroupUnits is the number of farms working together in the group

type Game

type Game struct {
	Id          int // unique identifier
	ShortName   string
	Name        string
	Description string
	CurrentTurn *Turn
	Colonies    map[int]*ColonyOrShip
	CorS        map[int]*ColonyOrShip
	Nations     map[int]*Nation
	Planets     map[int]*Planet
	Players     map[int]*Player
	Resources   map[int]*NaturalResource
	Ships       map[int]*ColonyOrShip
	Stars       map[int]*Star
	Systems     map[int]*System
	Turns       map[string]*Turn
	Units       map[int]*Unit
	Users       map[int]*User
}

Game is a single game

func (*Game) AllColonies

func (g *Game) AllColonies() []*ColonyOrShip

func (*Game) AllShips

func (g *Game) AllShips() []*ColonyOrShip

type GameClaim

type GameClaim struct {
	Id           int    // game id
	ShortName    string // game code
	EffTurn      *Turn  // game's turn that is effective as of the claim date
	PlayerId     int    // player id
	PlayerHandle string // player handle in game
	NationId     int    // nation id
	NationNo     int    // nation player is aligned with
	NationName   string // nation government name
}

type MiningGroup

type MiningGroup struct {
	CS      *ColonyOrShip
	Id      int // unique identifier
	No      int
	EffTurn *Turn // turn record becomes active
	EndTurn *Turn // turn record ceases to be active
	Deposit *NaturalResource
	Units   []*MiningGroupUnits // mine units in the group
	Stages  []*MiningGroupStages
}

MiningGroup is a group of mines working a single deposit.

type MiningGroupStages

type MiningGroupStages struct {
	Group     *MiningGroup
	Turn      *Turn
	QtyStage1 int
	QtyStage2 int
	QtyStage3 int
	QtyStage4 int
}

MiningGroupStages is the number units in each stage of the group

type MiningGroupUnits

type MiningGroupUnits struct {
	Group          *MiningGroup
	EffTurn        *Turn // turn record becomes active
	EndTurn        *Turn // turn record ceases to be active
	Unit           *Unit // unit mining
	QtyOperational int
}

MiningGroupUnits is the number of mines working together in the group

type Nation

type Nation struct {
	Game        *Game
	Id          int // unique identifier
	No          int // nation number in the game, starts at 1
	HomePlanet  *Planet
	Speciality  string
	Description string
	Details     []*NationDetail
	Research    []*NationResearch
	Skills      []*NationSkills
	Player      *Player // player currently controlling the nation
	CorS        []*ColonyOrShip
	Colonies    []*ColonyOrShip
	Ships       []*ColonyOrShip
	Players     []*Player
}

Nation is a single nation in the game. The "ruler" of the nation controls it, but may create viceroys or regents to control ships and colonies in the nation.

type NationDetail

type NationDetail struct {
	Nation       *Nation
	EffTurn      *Turn // turn record becomes active
	EndTurn      *Turn // turn record ceases to be active
	Name         string
	GovtName     string
	GovtKind     string
	ControlledBy *Player
}

NationDetail is items that can change value during the game.

type NationResearch

type NationResearch struct {
	Nation             *Nation
	EffTurn            *Turn // turn record becomes active
	EndTurn            *Turn // turn record ceases to be active
	TechLevel          int   //
	ResearchPointsPool int   //
}

NationResearch is the tech level and research level of the nation.

type NationSkills

type NationSkills struct {
	Nation        *Nation
	EffTurn       *Turn // turn record becomes active
	EndTurn       *Turn // turn record ceases to be active
	Biology       int   // not used currently
	Bureaucracy   int   // not used currently
	Gravitics     int   // not used currently
	LifeSupport   int   // not used currently
	Manufacturing int   // not used currently
	Military      int   // not used currently
	Mining        int   // not used currently
	Shields       int   // not used currently
}

NationSkills are the skills and tech levels of the nation.

type NaturalResource

type NaturalResource struct {
	Planet     *Planet
	Id         int     // unique identifier
	No         int     // number of deposit on planet
	Unit       *Unit   // fuel, gold, metallic, non-metallic
	QtyInitial int     // in mass units
	YieldPct   float64 // percentage of each mass unit that yields units
	Details    []*NaturalResourceDetail
}

NaturalResource is a deposit of fuel, gold, metal, or non-metals on a planet

type NaturalResourceDetail

type NaturalResourceDetail struct {
	NaturalResource *NaturalResource
	EffTurn         *Turn   // turn record becomes active
	EndTurn         *Turn   // turn record ceases to be active
	ControlledBy    *Nation // nation currently controlling the resource
	QtyRemaining    int     // in mass units
}

NaturalResourceDetail contains items that change from turn to turn

type Planet

type Planet struct {
	Star       *Star
	Id         int    // unique identifier
	OrbitNo    int    // 1..10
	Kind       string // asteroid belt, gas giant, terrestrial
	HomePlanet bool
	Deposits   []*NaturalResource
	Details    []*PlanetDetail
	Colonies   []*ColonyOrShip // colonies on or orbiting the planet
	Ships      []*ColonyOrShip // ships orbiting the planet
}

Planet is a non-empty orbit.

func (*Planet) String

func (p *Planet) String() string

type PlanetDetail

type PlanetDetail struct {
	Planet         *Planet
	EffTurn        *Turn   // turn record becomes active
	EndTurn        *Turn   // turn record ceases to be active
	ControlledBy   *Nation // nation currently controlling the planet
	HabitabilityNo int
}

PlanetDetail contains items that change from turn to turn

type Player

type Player struct {
	Game     *Game
	Id       int
	MemberOf *Nation
	Details  []*PlayerDetail
}

Player is a User's position in a Game

type PlayerDetail

type PlayerDetail struct {
	Player       *Player
	EffTurn      *Turn // turn record becomes active
	EndTurn      *Turn // turn record ceases to be active
	Handle       string
	ControlledBy *User
	SubjectOf    *Player // set if the player is a viceroy or regent
}

PlayerDetail is the handle of the player in the game

type PlayerPosition

type PlayerPosition struct {
	Id           int
	UserHandle   string
	PlayerHandle string
	Nation       struct {
		Name       string
		Speciality string
		HomeWorld  string
		GovtKind   string
		GovtName   string
	}
}

PlayerPosition maps json data into our users and players tables

type Star

type Star struct {
	System   *System
	Id       int    // unique identifier
	Sequence string // A, B, etc
	Kind     string
	HomeStar bool
	Orbits   []*Planet // each orbit may or may not contain a planet
}

Star is a stellar system in the game. It contains zero or more planets, with each planet assigned to an orbit ranging from 1...10

func (*Star) String

func (s *Star) String() string

type Store

type Store struct {
	// contains filtered or unexported fields
}

func Bootstrap

func Bootstrap(cfg *config.Global) (*Store, error)

Bootstrap creates a new store.

func Open

func Open(cfg *config.Global) (*Store, error)

func (*Store) AddSystem

func (s *Store) AddSystem(g Game, x, y, z int) (System, error)

func (*Store) Close

func (s *Store) Close()

func (*Store) CreateGame

func (s *Store) CreateGame(g *Game) error

CreateGame adds a new game to the store if it passes validation

func (*Store) CreateUnit

func (s *Store) CreateUnit(code, name, descr string, usesTech bool) error

func (*Store) CreateUser

func (s *Store) CreateUser(displayHandle, handle, email, secret string) error

CreateUser adds a new user to the store if it passes validation

func (*Store) DeleteGame

func (s *Store) DeleteGame(id int) error

DeleteGame removes a game from the store.

func (*Store) DeleteGameByName

func (s *Store) DeleteGameByName(shortName string) error

DeleteGameByName removes a game from the store.

func (*Store) FetchClaims

func (s *Store) FetchClaims(asOfTurn string) (map[string]*Claim, error)

func (*Store) FetchClusterListByGame

func (s *Store) FetchClusterListByGame(gameId int) ([]*SystemScan, error)

func (*Store) FetchCurrentTurn

func (s *Store) FetchCurrentTurn(userHandle, gameName string) (*Turn, error)

func (*Store) FetchGame

func (s *Store) FetchGame(id int) (*Game, error)

FetchGame fetches a game by id

func (*Store) FetchGameByName

func (s *Store) FetchGameByName(name string) (*Game, error)

FetchGameByName does just that

func (*Store) FetchGameByNameAsOf

func (s *Store) FetchGameByNameAsOf(name string, asOfTurn string) (*Game, error)

FetchGameByNameAsOf fetches a game by name and turn

func (*Store) FetchUnits

func (s *Store) FetchUnits() []*Unit

func (*Store) FetchUser

func (s *Store) FetchUser(id int) (*User, error)

func (*Store) FetchUserByCredentials

func (s *Store) FetchUserByCredentials(handle, secret string) (*User, error)

func (*Store) FetchUserByEmail

func (s *Store) FetchUserByEmail(email string) (*User, error)

FetchUserByEmail returns the user that matches the email

func (*Store) FetchUserByHandle

func (s *Store) FetchUserByHandle(handle string) (*User, error)

func (*Store) FetchUserClaimAsOf

func (s *Store) FetchUserClaimAsOf(id int, asOf time.Time) (*UserClaim, error)

func (*Store) FetchUserClaimsFromGameAsOf

func (s *Store) FetchUserClaimsFromGameAsOf(id int, asOf time.Time) ([]*UserClaim, error)

func (*Store) GenerateGame

func (s *Store) GenerateGame(shortName, name, descr string, radius int, startDt time.Time, positions []*PlayerPosition) (*Game, error)

func (*Store) GetDB

func (s *Store) GetDB() *sql.DB

func (*Store) LookupGame

func (s *Store) LookupGame(id int) (*Game, error)

LookupGame looks up a game by id

func (*Store) LookupGameByName

func (s *Store) LookupGameByName(name string) (*Game, error)

LookupGameByName does just that

func (*Store) OrdersPath

func (s *Store) OrdersPath() string

func (*Store) Ping

func (s *Store) Ping() error

func (*Store) SaveGame

func (s *Store) SaveGame(game *Game) error

func (*Store) UpdateUserSecret

func (s *Store) UpdateUserSecret(id int, secret string) error

func (*Store) Version

func (s *Store) Version() string

type System

type System struct {
	Game       *Game
	Id         int // unique identifier
	Coords     Coordinates
	HomeSystem bool
	Ring       int // ring is light years from the origin
	Stars      []*Star
}

System is a system in the game. It contains zero or more stars.

type SystemScan

type SystemScan struct {
	X, Y, Z  int
	QtyStars int
}

SystemScan is useful

type Turn

type Turn struct {
	No      int       // 0+
	Year    int       // 1...9999
	Quarter int       // 1...4
	StartDt time.Time // moment turn starts
	EndDt   time.Time // moment turn ends
}

Turn is a single turn in the game

func (*Turn) String

func (t *Turn) String() string

type Unit

type Unit struct {
	Id                  int // unique identifier
	Code                string
	TechLevel           int
	Name                string
	Description         string
	MassPerUnit         float64 // mass (in mass units) of a single unit
	VolumePerUnit       float64 // volume (in enclosed mass units) of a single unit
	Hudnut              bool    // true if unit can be disassembled for storage
	StowedVolumePerUnit float64 // half mass if unit is hudnut
}

Unit is a thing in the game.

type User

type User struct {
	Id           int    // unique identifier
	Handle       string // unique handle, forced to lower-case
	HashedSecret string
	Profiles     []*UserProfile
}

User is the person who owns the account used to access the game

type UserClaim

type UserClaim struct {
	Id     int       // user id
	Handle string    // user handle
	AsOf   time.Time // as of date for pulling claims
	Games  []*GameClaim
}

type UserProfile

type UserProfile struct {
	User   *User
	EffDt  time.Time // moment record becomes effective
	EndDt  time.Time // moment record ceases to be effective
	Email  string    // email, forced to lower-case
	Handle string    // display version of handle
}

UserProfile is the handle and email of the user

Jump to

Keyboard shortcuts

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