simulation

package
v0.7.7 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2019 License: GPL-2.0 Imports: 12 Imported by: 0

Documentation

Overview

package simulation contains core logic of ts2

Index

Constants

View Source
const NoMorePlace = 9999

NoMorePlace is a large float used to represent a non existent service line index

View Source
const Version = "0.7"

Version of the software, mostly used for file format

View Source
const VeryHighSpeed = 999

VeryHighSpeed is the speed limit set when there are no speed limits. It is higher than the highest possible train speed ever.

Variables

View Source
var (
	Logger log.Logger
)

Functions

func InitializeLogger

func InitializeLogger(parentLogger log.Logger)

InitializeLogger creates the Logger for the simulation module

func RegisterLineItemManager

func RegisterLineItemManager(lim LineItemManager)

RegisterLineItemManager registers the given line manager in the simulation.

If a line manager was already registered, it is replaced by lim.

func RegisterPointsItemManager

func RegisterPointsItemManager(pim PointsItemManager)

RegisterPointsItemManager registers the given points manager in the simulation.

If a points manager was already registered, it is replaced by pim.

func RegisterRoutesManager

func RegisterRoutesManager(rm RoutesManager)

RegisterRoutesManager registers the given route manager in the simulation.

When several routes managers are registered, all of them are called in turn. If all of them respond true, then the response is true. If one responds false, the response is false.

func RegisterSignalItemManager

func RegisterSignalItemManager(sim SignalItemManager)

RegisterSignalItemManager registers the signal manager in the simulation.

If a signals manager was already registered, it is replaced by sim.

func RegisterTrainsManager

func RegisterTrainsManager(tm TrainsManager)

RegisterTrainsManager registers the given trains manager in the simulation.

There can be several trains managers registered, but each train will use only one. If a train has not been explicitly set to a trains manager, it will use the default one. Default trains manager is the first registered manager.

Types

type ActionTarget

type ActionTarget uint8

ActionTarget defines when a speed limit associated with a signal aspect must be applied.

const (
	ASAP             ActionTarget = 0
	BeforeThisSignal ActionTarget = 1
	BeforeNextSignal ActionTarget = 2
)

Possible action targets for trains to apply signal actions

type BoolObject

type BoolObject struct {
	Value bool `json:"value"`
}

An BoolObject is a SimObject that wraps a single boolean value

func (BoolObject) ID

func (bo BoolObject) ID() string

ID method to implement SimObject. Returns an empty string.

type Color

type Color struct {
	R, G, B uint8
}

A Colour stored as RGB values

func FromHex

func FromHex(scol string) (Color, error)

FromHex() parses a "css/html" hex color-string, either in the 3 "#f0c" or 6 "#ff1034" digits form.

func (Color) Hex

func (c Color) Hex() string

Color.Hex() returns the hex "html" representation of the color, as in #ff0080.

func (*Color) MarshalJSON

func (c *Color) MarshalJSON() ([]byte, error)

MarshalJSON for the Color Type

func (Color) RGBA

func (c Color) RGBA() (r, g, b, a uint32)

Implement the Go color.Color interface.

func (*Color) UnmarshalJSON

func (c *Color) UnmarshalJSON(data []byte) error

UnmarshalJSON for the Color type

type Condition

type Condition struct {
	Type   ConditionType
	Values []string
}

A Condition on the current simulation context used for defining signal state.

func (Condition) IsMet

func (c Condition) IsMet(item *SignalItem, params []string) bool

IsMet returns true if this condition is met for the given SignalItem

type ConditionType

type ConditionType interface {
	// Code of the ConditionType, uniquely defines this ConditionType
	Code() string
	// SetupTriggers installs needed triggers for the given SignalItem, with the
	// given parameters.
	SetupTriggers(*SignalItem, []string)
	// Solve returns if the condition is met for the given SignalItem and parameters
	Solve(*SignalItem, []string, []string) bool
}

A ConditionType is a type of condition that can be used for defining a signal state.

type CustomProperty

type CustomProperty map[string][]string

A CustomProperty is a map to hold track item properties that are defined by the user.

type DelayGenerator

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

DelayGenerator is a probability distribution for a duration in seconds and is used to generate random delays for trains.

  • The `data` field is a list of tuplets (an array of 3 integers).

  • Each tuple defines in order:

  • A lower bound

  • An upper bound

  • A probability in percent of the value to be inside the defined bounds.

    e.g. [[0 100 80] [100 500 20]] means that when a value will be yielded by this DelayGenerator, it will have 80% chance of being between 0 and 100, and 20% chance of being between 100 and 500.

func (DelayGenerator) IsNull

func (dg DelayGenerator) IsNull() bool

IsNull returns true if this is a [[0, 0, 100]] generator

func (DelayGenerator) MarshalJSON

func (dg DelayGenerator) MarshalJSON() ([]byte, error)

MarshalJSON for the DelayGenerator type

func (*DelayGenerator) UnmarshalJSON

func (dg *DelayGenerator) UnmarshalJSON(data []byte) error

UnmarshalJSON method for the DelayGenerator type

func (DelayGenerator) Yield

func (dg DelayGenerator) Yield() time.Duration

Yield a delay from this DelayGenerator

type EndItem

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

An EndItem is an invisible item to which the free ends of other Trackitem instances must be connected to prevent the simulation from crashing.

End items are single point items.

func (*EndItem) ActiveRoute

func (t *EndItem) ActiveRoute() *Route

ActiveRoute returns a pointer to the route currently active on this item

func (*EndItem) ActiveRoutePreviousItem

func (t *EndItem) ActiveRoutePreviousItem() TrackItem

ActiveRoutePreviousItem returns the previous item in the active route direction

func (*EndItem) ConflictItem

func (t *EndItem) ConflictItem() TrackItem

ConflictItem returns the conflicting item of this TrackItem. The conflicting item is another item of the scenery on which a route must not be set if one is already active on this TrackItem (and vice-versa). This is particularly the case when two TrackItems cross over with no points.

func (*EndItem) CustomProperty

func (t *EndItem) CustomProperty(key string) CustomProperty

CustomProperty returns the custom property with the given key

func (*EndItem) DistanceToTrainEnd

func (t *EndItem) DistanceToTrainEnd(pos Position) (float64, bool)

DistanceToTrainEnd returns the distance to the closest end (either train head or train tail) of the closest train when on pos. If no train is on this item, the distance will be 0, and the second argument will be false.

func (*EndItem) End

func (t *EndItem) End() Point

End are the two coordinates (xf, yf) of the end point of this TrackItem.

func (*EndItem) Equals

func (t *EndItem) Equals(ti TrackItem) bool

Equals returns true if this track item and the given one are the same (i.e. they have the same routeID)

func (*EndItem) FollowingItem

func (t *EndItem) FollowingItem(precedingItem TrackItem, dir PointDirection) (TrackItem, error)

FollowingItem returns the following TrackItem linked to this one, knowing we come from precedingItem(). Returned is either NextItem or PreviousItem, depending which way we come from.

The second argument will return a ItemsNotLinkedError if the given precedingItem is not linked to this item.

func (*EndItem) ID

func (t *EndItem) ID() string

routeID returns the unique routeID of this TrackItem, which is the index of this item in the Simulation's TrackItems map.

func (*EndItem) IsConnected

func (t *EndItem) IsConnected(oti TrackItem) bool

IsConnected returns true if this TrackItem is connected to the given TrackItem, false otherwise

func (*EndItem) IsOnPosition

func (t *EndItem) IsOnPosition(pos Position) bool

IsOnPosition returns true if this track item is the track item of the given position.

func (*EndItem) MarshalJSON

func (ei *EndItem) MarshalJSON() ([]byte, error)

MarshalJSON method for the end item

func (*EndItem) MaxSpeed

func (t *EndItem) MaxSpeed() float64

MaxSpeed is the maximum allowed speed on this TrackItem in meters per second.

func (*EndItem) Name

func (t *EndItem) Name() string

Name returns the human readable name of this item

func (*EndItem) NextItem

func (t *EndItem) NextItem() TrackItem

NextItem returns the next item of this TrackItem.

The next item is usually the item connected to the end of the item that is not the Origin

func (*EndItem) Origin

func (t *EndItem) Origin() Point

Origin are the two coordinates (x, y) of the origin point of this TrackItem.

func (*EndItem) Place

func (t *EndItem) Place() *Place

Place returns the TrackItem of type Place associated with this item (as defined by PlaceCode).

func (*EndItem) PreviousItem

func (t *EndItem) PreviousItem() TrackItem

PreviousItem returns the previous item of this TrackItem.

The previous item is usually the item connected to the Origin() of this item.

func (*EndItem) RealLength

func (ei *EndItem) RealLength() float64

RealLength() is the length in meters that this TrackItem has in real life track length

func (*EndItem) Simulation

func (t *EndItem) Simulation() *Simulation

Simulation returns the Simulation object that this TrackItem belongs to.

func (*EndItem) TrackCode

func (t *EndItem) TrackCode() string

TrackCode returns the track number of this LineItem, if it is part of a TypePlace and if it has one.

func (*EndItem) TrainPresent

func (t *EndItem) TrainPresent() bool

TrainPresent returns true if at least one train is present on this TrackItem

func (*EndItem) Type

func (ei *EndItem) Type() TrackItemType

Type returns the name of the type of this item

type Event

type Event struct {
	Name   EventName
	Object SimObject
}

Event is a wrapper around an object that is sent to the server hub to notify clients of a change.

type EventName

type EventName string

An EventName is the name of a event

const (
	ClockEvent                    EventName = "clock"
	StateChangedEvent             EventName = "stateChanged"
	OptionsChangedEvent           EventName = "optionsChanged"
	RouteActivatedEvent           EventName = "routeActivated"
	RouteDeactivatedEvent         EventName = "routeDeactivated"
	TrainStoppedAtStationEvent    EventName = "trainStoppedAtStation"
	TrainDepartedFromStationEvent EventName = "trainDepartedFromStation"
	TrainChangedEvent             EventName = "trainChanged"
	SignalaspectChangedEvent      EventName = "signalAspectChanged"
	TrackItemChangedEvent         EventName = "trackItemChanged"
	MessageReceivedEvent          EventName = "messageReceived"
)

Events that can be send to clients that add a listener to them.

type IntObject

type IntObject struct {
	Value int `json:"value"`
}

An IntObject is a SimObject that wraps a single integer value

func (IntObject) ID

func (io IntObject) ID() string

ID method to implement SimObject. Returns an empty string.

type InvisibleLinkItem

type InvisibleLinkItem struct {
	LineItem
}

InvisibleLinkItem behave like line items, but clients are encouraged not to represented them on the scenery. They are used to make links between lines or to represent bridges and tunnels.

func (*InvisibleLinkItem) ActiveRoute

func (t *InvisibleLinkItem) ActiveRoute() *Route

ActiveRoute returns a pointer to the route currently active on this item

func (*InvisibleLinkItem) ActiveRoutePreviousItem

func (t *InvisibleLinkItem) ActiveRoutePreviousItem() TrackItem

ActiveRoutePreviousItem returns the previous item in the active route direction

func (*InvisibleLinkItem) ConflictItem

func (t *InvisibleLinkItem) ConflictItem() TrackItem

ConflictItem returns the conflicting item of this TrackItem. The conflicting item is another item of the scenery on which a route must not be set if one is already active on this TrackItem (and vice-versa). This is particularly the case when two TrackItems cross over with no points.

func (*InvisibleLinkItem) CustomProperty

func (t *InvisibleLinkItem) CustomProperty(key string) CustomProperty

CustomProperty returns the custom property with the given key

func (*InvisibleLinkItem) DistanceToTrainEnd

func (t *InvisibleLinkItem) DistanceToTrainEnd(pos Position) (float64, bool)

DistanceToTrainEnd returns the distance to the closest end (either train head or train tail) of the closest train when on pos. If no train is on this item, the distance will be 0, and the second argument will be false.

func (*InvisibleLinkItem) Equals

func (t *InvisibleLinkItem) Equals(ti TrackItem) bool

Equals returns true if this track item and the given one are the same (i.e. they have the same routeID)

func (*InvisibleLinkItem) FollowingItem

func (t *InvisibleLinkItem) FollowingItem(precedingItem TrackItem, dir PointDirection) (TrackItem, error)

FollowingItem returns the following TrackItem linked to this one, knowing we come from precedingItem(). Returned is either NextItem or PreviousItem, depending which way we come from.

The second argument will return a ItemsNotLinkedError if the given precedingItem is not linked to this item.

func (*InvisibleLinkItem) ID

func (t *InvisibleLinkItem) ID() string

routeID returns the unique routeID of this TrackItem, which is the index of this item in the Simulation's TrackItems map.

func (*InvisibleLinkItem) IsConnected

func (t *InvisibleLinkItem) IsConnected(oti TrackItem) bool

IsConnected returns true if this TrackItem is connected to the given TrackItem, false otherwise

func (*InvisibleLinkItem) IsOnPosition

func (t *InvisibleLinkItem) IsOnPosition(pos Position) bool

IsOnPosition returns true if this track item is the track item of the given position.

func (*InvisibleLinkItem) MaxSpeed

func (t *InvisibleLinkItem) MaxSpeed() float64

MaxSpeed is the maximum allowed speed on this TrackItem in meters per second.

func (*InvisibleLinkItem) Name

func (t *InvisibleLinkItem) Name() string

Name returns the human readable name of this item

func (*InvisibleLinkItem) NextItem

func (t *InvisibleLinkItem) NextItem() TrackItem

NextItem returns the next item of this TrackItem.

The next item is usually the item connected to the end of the item that is not the Origin

func (*InvisibleLinkItem) Origin

func (t *InvisibleLinkItem) Origin() Point

Origin are the two coordinates (x, y) of the origin point of this TrackItem.

func (*InvisibleLinkItem) Place

func (t *InvisibleLinkItem) Place() *Place

Place returns the TrackItem of type Place associated with this item (as defined by PlaceCode).

func (*InvisibleLinkItem) PreviousItem

func (t *InvisibleLinkItem) PreviousItem() TrackItem

PreviousItem returns the previous item of this TrackItem.

The previous item is usually the item connected to the Origin() of this item.

func (*InvisibleLinkItem) RealLength

func (t *InvisibleLinkItem) RealLength() float64

RealLength is the length in meters that this TrackItem has in real life track length

func (*InvisibleLinkItem) Simulation

func (t *InvisibleLinkItem) Simulation() *Simulation

Simulation returns the Simulation object that this TrackItem belongs to.

func (*InvisibleLinkItem) TrackCode

func (t *InvisibleLinkItem) TrackCode() string

TrackCode returns the track number of this LineItem, if it is part of a TypePlace and if it has one.

func (*InvisibleLinkItem) TrainPresent

func (t *InvisibleLinkItem) TrainPresent() bool

TrainPresent returns true if at least one train is present on this TrackItem

func (*InvisibleLinkItem) Type

func (ili *InvisibleLinkItem) Type() TrackItemType

Type returns the name of the type of this item

type ItemInconsistentLinkError

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

ItemInconsistentLinkError is returned when a TrackItem is linked to another one, but the latter is not linked to the former.

func (ItemInconsistentLinkError) Error

Error method for the ItemInconsistentLinkError

type ItemNotLinkedAtError

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

An ItemNotLinkedAtError is returned when a TrackItem instance has no connected item at the given end.

func (ItemNotLinkedAtError) Error

func (i ItemNotLinkedAtError) Error() string

Error method for the ItemsNotLinkedError

type ItemsNotLinkedError

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

An ItemsNotLinkedError is returned when two TrackItem instances that are assumed to be linked are not.

func (ItemsNotLinkedError) Error

func (e ItemsNotLinkedError) Error() string

Error method for the ItemsNotLinkedError

type LineItem

type LineItem struct {
	Xf float64 `json:"xf"`
	Yf float64 `json:"yf"`
	// contains filtered or unexported fields
}

A LineItem is a resizable TrackItem that represent a simple railway line and is used to connect two TrackItem's together.

func (*LineItem) ActiveRoute

func (t *LineItem) ActiveRoute() *Route

ActiveRoute returns a pointer to the route currently active on this item

func (*LineItem) ActiveRoutePreviousItem

func (t *LineItem) ActiveRoutePreviousItem() TrackItem

ActiveRoutePreviousItem returns the previous item in the active route direction

func (*LineItem) ConflictItem

func (t *LineItem) ConflictItem() TrackItem

ConflictItem returns the conflicting item of this TrackItem. The conflicting item is another item of the scenery on which a route must not be set if one is already active on this TrackItem (and vice-versa). This is particularly the case when two TrackItems cross over with no points.

func (*LineItem) CustomProperty

func (t *LineItem) CustomProperty(key string) CustomProperty

CustomProperty returns the custom property with the given key

func (*LineItem) DistanceToTrainEnd

func (t *LineItem) DistanceToTrainEnd(pos Position) (float64, bool)

DistanceToTrainEnd returns the distance to the closest end (either train head or train tail) of the closest train when on pos. If no train is on this item, the distance will be 0, and the second argument will be false.

func (*LineItem) End

func (li *LineItem) End() Point

End returns the two coordinates (Xf, Yf) of the end point of this item

func (*LineItem) Equals

func (t *LineItem) Equals(ti TrackItem) bool

Equals returns true if this track item and the given one are the same (i.e. they have the same routeID)

func (*LineItem) FollowingItem

func (t *LineItem) FollowingItem(precedingItem TrackItem, dir PointDirection) (TrackItem, error)

FollowingItem returns the following TrackItem linked to this one, knowing we come from precedingItem(). Returned is either NextItem or PreviousItem, depending which way we come from.

The second argument will return a ItemsNotLinkedError if the given precedingItem is not linked to this item.

func (*LineItem) ID

func (t *LineItem) ID() string

routeID returns the unique routeID of this TrackItem, which is the index of this item in the Simulation's TrackItems map.

func (*LineItem) IsConnected

func (t *LineItem) IsConnected(oti TrackItem) bool

IsConnected returns true if this TrackItem is connected to the given TrackItem, false otherwise

func (*LineItem) IsOnPosition

func (t *LineItem) IsOnPosition(pos Position) bool

IsOnPosition returns true if this track item is the track item of the given position.

func (*LineItem) MarshalJSON

func (li *LineItem) MarshalJSON() ([]byte, error)

MarshalJSON method for LineItem

func (*LineItem) MaxSpeed

func (t *LineItem) MaxSpeed() float64

MaxSpeed is the maximum allowed speed on this TrackItem in meters per second.

func (*LineItem) Name

func (t *LineItem) Name() string

Name returns the human readable name of this item

func (*LineItem) NextItem

func (t *LineItem) NextItem() TrackItem

NextItem returns the next item of this TrackItem.

The next item is usually the item connected to the end of the item that is not the Origin

func (*LineItem) Origin

func (t *LineItem) Origin() Point

Origin are the two coordinates (x, y) of the origin point of this TrackItem.

func (*LineItem) Place

func (t *LineItem) Place() *Place

Place returns the TrackItem of type Place associated with this item (as defined by PlaceCode).

func (*LineItem) PreviousItem

func (t *LineItem) PreviousItem() TrackItem

PreviousItem returns the previous item of this TrackItem.

The previous item is usually the item connected to the Origin() of this item.

func (*LineItem) RealLength

func (t *LineItem) RealLength() float64

RealLength is the length in meters that this TrackItem has in real life track length

func (*LineItem) Simulation

func (t *LineItem) Simulation() *Simulation

Simulation returns the Simulation object that this TrackItem belongs to.

func (*LineItem) TrackCode

func (t *LineItem) TrackCode() string

TrackCode returns the track number of this LineItem, if it is part of a TypePlace and if it has one.

func (*LineItem) TrainPresent

func (t *LineItem) TrainPresent() bool

TrainPresent returns true if at least one train is present on this TrackItem

func (*LineItem) Type

func (li *LineItem) Type() TrackItemType

Type returns the name of the type of this item

type LineItemManager

type LineItemManager interface {
	// Name returns a description of this lineItemManager that is used for the UI.
	Name() string
	// IsFailed returns true if the given LineItem has a track circuit failure
	IsFailed(*LineItem) bool
}

A LineItemManager manages breakdowns of line track circuits

type Message

type Message struct {
	MsgType MessageType `json:"msgType"`
	MsgText string      `json:"msgText"`
}

Message is one message emitted to the MessageLogger of the simulation.

func (Message) ID

func (m Message) ID() string

ID method exists so that a Message satisfies the Object interface and can be sent as a notification. Simply returns the message's text.

type MessageLogger

type MessageLogger struct {
	Messages []Message `json:"messages"`
	// contains filtered or unexported fields
}

MessageLogger holds all Message instances that have been emitted to it.

type MessageType

type MessageType uint8

MessageType defines the type of message of the Logger

type NextActiveRoute

type NextActiveRoute struct{}

nextActiveRoute is true if a route starting from this Signal is active

func (NextActiveRoute) Code

func (nar NextActiveRoute) Code() string

Code of the ConditionType, uniquely defines this ConditionType

func (NextActiveRoute) SetupTriggers

func (nar NextActiveRoute) SetupTriggers(item *SignalItem, params []string)

SetupTriggers installs needed triggers for the given SignalItem, with the given Condition.

func (NextActiveRoute) Solve

func (nar NextActiveRoute) Solve(item *SignalItem, values []string, params []string) bool

Solve returns if the condition is met for the given SignalItem and parameters

type NextSignalAspects

type NextSignalAspects struct{}

NextSignalAspects is true if the next signal is showing one of the aspects given.

If one of the aspect names finishes with a '!' and the next signal aspect matches this aspect, then the next signal aspect is ignored and the aspect further on the line is checked with the same data.

func (NextSignalAspects) Code

func (nsa NextSignalAspects) Code() string

Code of the ConditionType, uniquely defines this ConditionType

func (NextSignalAspects) SetupTriggers

func (nsa NextSignalAspects) SetupTriggers(item *SignalItem, params []string)

SetupTriggers installs needed triggers for the given SignalItem, with the given Condition.

func (NextSignalAspects) Solve

func (nsa NextSignalAspects) Solve(item *SignalItem, values []string, params []string) bool

Solve returns if the condition is met for the given SignalItem and parameters

type Options

type Options struct {
	TrackCircuitBased       bool           `json:"trackCircuitBased"`
	ClientToken             string         `json:"clientToken"`
	CurrentScore            int            `json:"currentScore"`
	CurrentTime             Time           `json:"currentTime"`
	DefaultDelayAtEntry     DelayGenerator `json:"defaultDelayAtEntry"`
	DefaultMaxSpeed         float64        `json:"defaultMaxSpeed"`
	DefaultMinimumStopTime  DelayGenerator `json:"defaultMinimumStopTime"`
	DefaultSignalVisibility float64        `json:"defaultSignalVisibility"`
	Description             string         `json:"description"`
	TimeFactor              int            `json:"timeFactor"`
	Title                   string         `json:"title"`
	Version                 string         `json:"version"`
	WarningSpeed            float64        `json:"warningSpeed"`
	WrongPlatformPenalty    int            `json:"wrongPlatformPenalty"`
	WrongDestinationPenalty int            `json:"wrongDestinationPenalty"`
	LatePenalty             int            `json:"latePenalty"`
	// contains filtered or unexported fields
}

Options struct for the simulation

func (Options) ID

func (o Options) ID() string

ID func for options to that it implements SimObject. Returns an empty string.

func (*Options) Set

func (o *Options) Set(option string, value interface{}) error

Set the given option with the given value.

option can be either the struct field name or the json key of the struct field.

type Place

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

A Place is a special TrackItem representing a physical location such as a station or a passing point. Note that Place items are not linked to other items.

func (*Place) ActiveRoute

func (t *Place) ActiveRoute() *Route

ActiveRoute returns a pointer to the route currently active on this item

func (*Place) ActiveRoutePreviousItem

func (t *Place) ActiveRoutePreviousItem() TrackItem

ActiveRoutePreviousItem returns the previous item in the active route direction

func (*Place) ConflictItem

func (t *Place) ConflictItem() TrackItem

ConflictItem returns the conflicting item of this TrackItem. The conflicting item is another item of the scenery on which a route must not be set if one is already active on this TrackItem (and vice-versa). This is particularly the case when two TrackItems cross over with no points.

func (*Place) CustomProperty

func (t *Place) CustomProperty(key string) CustomProperty

CustomProperty returns the custom property with the given key

func (*Place) DistanceToTrainEnd

func (t *Place) DistanceToTrainEnd(pos Position) (float64, bool)

DistanceToTrainEnd returns the distance to the closest end (either train head or train tail) of the closest train when on pos. If no train is on this item, the distance will be 0, and the second argument will be false.

func (*Place) End

func (t *Place) End() Point

End are the two coordinates (xf, yf) of the end point of this TrackItem.

func (*Place) Equals

func (t *Place) Equals(ti TrackItem) bool

Equals returns true if this track item and the given one are the same (i.e. they have the same routeID)

func (*Place) FollowingItem

func (t *Place) FollowingItem(precedingItem TrackItem, dir PointDirection) (TrackItem, error)

FollowingItem returns the following TrackItem linked to this one, knowing we come from precedingItem(). Returned is either NextItem or PreviousItem, depending which way we come from.

The second argument will return a ItemsNotLinkedError if the given precedingItem is not linked to this item.

func (*Place) ID

func (t *Place) ID() string

routeID returns the unique routeID of this TrackItem, which is the index of this item in the Simulation's TrackItems map.

func (*Place) IsConnected

func (t *Place) IsConnected(oti TrackItem) bool

IsConnected returns true if this TrackItem is connected to the given TrackItem, false otherwise

func (*Place) IsOnPosition

func (t *Place) IsOnPosition(pos Position) bool

IsOnPosition returns true if this track item is the track item of the given position.

func (*Place) MarshalJSON

func (t *Place) MarshalJSON() ([]byte, error)

MarshalJSON method for trackStruct

func (*Place) MaxSpeed

func (t *Place) MaxSpeed() float64

MaxSpeed is the maximum allowed speed on this TrackItem in meters per second.

func (*Place) Name

func (t *Place) Name() string

Name returns the human readable name of this item

func (*Place) NextItem

func (t *Place) NextItem() TrackItem

NextItem returns the next item of this TrackItem.

The next item is usually the item connected to the end of the item that is not the Origin

func (*Place) Origin

func (t *Place) Origin() Point

Origin are the two coordinates (x, y) of the origin point of this TrackItem.

func (*Place) Place

func (t *Place) Place() *Place

Place returns the TrackItem of type Place associated with this item (as defined by PlaceCode).

func (*Place) PreviousItem

func (t *Place) PreviousItem() TrackItem

PreviousItem returns the previous item of this TrackItem.

The previous item is usually the item connected to the Origin() of this item.

func (*Place) RealLength

func (t *Place) RealLength() float64

RealLength is the length in meters that this TrackItem has in real life track length

func (*Place) Simulation

func (t *Place) Simulation() *Simulation

Simulation returns the Simulation object that this TrackItem belongs to.

func (*Place) TrackCode

func (t *Place) TrackCode() string

TrackCode returns the track number of this LineItem, if it is part of a TypePlace and if it has one.

func (*Place) TrainPresent

func (t *Place) TrainPresent() bool

TrainPresent returns true if at least one train is present on this TrackItem

func (*Place) Type

func (pl *Place) Type() TrackItemType

Type returns the name of the type of this item

type PlatformItem

type PlatformItem struct {
	LineItem
}

PlatformItem's are usually represented as a colored rectangle on the scene to symbolise the platform. This colored rectangle can permit user interaction.

func (*PlatformItem) ActiveRoute

func (t *PlatformItem) ActiveRoute() *Route

ActiveRoute returns a pointer to the route currently active on this item

func (*PlatformItem) ActiveRoutePreviousItem

func (t *PlatformItem) ActiveRoutePreviousItem() TrackItem

ActiveRoutePreviousItem returns the previous item in the active route direction

func (*PlatformItem) ConflictItem

func (t *PlatformItem) ConflictItem() TrackItem

ConflictItem returns the conflicting item of this TrackItem. The conflicting item is another item of the scenery on which a route must not be set if one is already active on this TrackItem (and vice-versa). This is particularly the case when two TrackItems cross over with no points.

func (*PlatformItem) CustomProperty

func (t *PlatformItem) CustomProperty(key string) CustomProperty

CustomProperty returns the custom property with the given key

func (*PlatformItem) DistanceToTrainEnd

func (t *PlatformItem) DistanceToTrainEnd(pos Position) (float64, bool)

DistanceToTrainEnd returns the distance to the closest end (either train head or train tail) of the closest train when on pos. If no train is on this item, the distance will be 0, and the second argument will be false.

func (*PlatformItem) Equals

func (t *PlatformItem) Equals(ti TrackItem) bool

Equals returns true if this track item and the given one are the same (i.e. they have the same routeID)

func (*PlatformItem) FollowingItem

func (t *PlatformItem) FollowingItem(precedingItem TrackItem, dir PointDirection) (TrackItem, error)

FollowingItem returns the following TrackItem linked to this one, knowing we come from precedingItem(). Returned is either NextItem or PreviousItem, depending which way we come from.

The second argument will return a ItemsNotLinkedError if the given precedingItem is not linked to this item.

func (*PlatformItem) ID

func (t *PlatformItem) ID() string

routeID returns the unique routeID of this TrackItem, which is the index of this item in the Simulation's TrackItems map.

func (*PlatformItem) IsConnected

func (t *PlatformItem) IsConnected(oti TrackItem) bool

IsConnected returns true if this TrackItem is connected to the given TrackItem, false otherwise

func (*PlatformItem) IsOnPosition

func (t *PlatformItem) IsOnPosition(pos Position) bool

IsOnPosition returns true if this track item is the track item of the given position.

func (*PlatformItem) MaxSpeed

func (t *PlatformItem) MaxSpeed() float64

MaxSpeed is the maximum allowed speed on this TrackItem in meters per second.

func (*PlatformItem) Name

func (t *PlatformItem) Name() string

Name returns the human readable name of this item

func (*PlatformItem) NextItem

func (t *PlatformItem) NextItem() TrackItem

NextItem returns the next item of this TrackItem.

The next item is usually the item connected to the end of the item that is not the Origin

func (*PlatformItem) Origin

func (t *PlatformItem) Origin() Point

Origin are the two coordinates (x, y) of the origin point of this TrackItem.

func (*PlatformItem) Place

func (t *PlatformItem) Place() *Place

Place returns the TrackItem of type Place associated with this item (as defined by PlaceCode).

func (*PlatformItem) PreviousItem

func (t *PlatformItem) PreviousItem() TrackItem

PreviousItem returns the previous item of this TrackItem.

The previous item is usually the item connected to the Origin() of this item.

func (*PlatformItem) RealLength

func (t *PlatformItem) RealLength() float64

RealLength is the length in meters that this TrackItem has in real life track length

func (*PlatformItem) Simulation

func (t *PlatformItem) Simulation() *Simulation

Simulation returns the Simulation object that this TrackItem belongs to.

func (*PlatformItem) TrackCode

func (t *PlatformItem) TrackCode() string

TrackCode returns the track number of this LineItem, if it is part of a TypePlace and if it has one.

func (*PlatformItem) TrainPresent

func (t *PlatformItem) TrainPresent() bool

TrainPresent returns true if at least one train is present on this TrackItem

func (*PlatformItem) Type

func (pfi *PlatformItem) Type() TrackItemType

Type returns the name of the type of this item

type Point

type Point struct {
	X float64
	Y float64
}

Point type represents a point on the scenery

func (Point) Add

func (p Point) Add(p2 Point) Point

Add returns the Point which is the application of Point p2 as a vector on Point p1.

type PointDirection

type PointDirection int8

PointDirection are constants that represent the "physical state" of a PointsItem

const (
	// DirectionCurrent : special position used in functions so as not to change points position
	DirectionCurrent PointDirection = -1

	// DirectionNormal : Point is set at normal
	DirectionNormal PointDirection = 0

	// DirectionReversed : Point is set for cross over
	DirectionReversed PointDirection = 1

	// DirectionUnknown : No direction is returned by the points sensors.
	// Usually means points are moving
	DirectionUnknown PointDirection = 2

	// DirectionFailed : Points or points sensors have a failure
	DirectionFailed PointDirection = 3
)

type PointsItem

type PointsItem struct {
	Xc          float64 `json:"xf"`
	Yc          float64 `json:"yf"`
	Xn          float64 `json:"xn"`
	Yn          float64 `json:"yn"`
	Xr          float64 `json:"xr"`
	Yr          float64 `json:"yr"`
	ReverseTiId string  `json:"reverseTiId"`
	PairedTiId  string  `json:"pairedTiId"`
	// contains filtered or unexported fields
}

A PointsItem is a three-way railway junction (known as Point, Switch, Turnout..)

The three ends are called `common end`, `normal end` and `reverse end`

                    ____________ reverse
                   /
common ___________/______________normal

Trains can go from the common end to normal or reverse ends depending on the state of the points, but they cannot go from the normal end to reverse end.

Usually, the normal end is aligned with the common end and the reverse end is sideways, but this is not mandatory.

Geometric points are represented on a 10 x 10 square centered on Center() point. CommonEnd, NormalEnd and ReverseEnd are points on the side of this square (i.e. they have at least one coordinate which is 5 or -5)

func (*PointsItem) ActiveRoute

func (t *PointsItem) ActiveRoute() *Route

ActiveRoute returns a pointer to the route currently active on this item

func (*PointsItem) ActiveRoutePreviousItem

func (t *PointsItem) ActiveRoutePreviousItem() TrackItem

ActiveRoutePreviousItem returns the previous item in the active route direction

func (*PointsItem) Center

func (pi *PointsItem) Center() Point

Center point of this PointsItem in the scene coordinates

func (*PointsItem) CommonEnd

func (pi *PointsItem) CommonEnd() Point

CommonEnd return the common end point in the item's coordinates

func (*PointsItem) ConflictItem

func (t *PointsItem) ConflictItem() TrackItem

ConflictItem returns the conflicting item of this TrackItem. The conflicting item is another item of the scenery on which a route must not be set if one is already active on this TrackItem (and vice-versa). This is particularly the case when two TrackItems cross over with no points.

func (*PointsItem) CustomProperty

func (t *PointsItem) CustomProperty(key string) CustomProperty

CustomProperty returns the custom property with the given key

func (*PointsItem) DistanceToTrainEnd

func (t *PointsItem) DistanceToTrainEnd(pos Position) (float64, bool)

DistanceToTrainEnd returns the distance to the closest end (either train head or train tail) of the closest train when on pos. If no train is on this item, the distance will be 0, and the second argument will be false.

func (*PointsItem) End

func (pi *PointsItem) End() Point

End returns the two coordinates (Xf, Yf) of the end, i.e. the absolute coordinates of the normal end.

func (*PointsItem) Equals

func (t *PointsItem) Equals(ti TrackItem) bool

Equals returns true if this track item and the given one are the same (i.e. they have the same routeID)

func (*PointsItem) FollowingItem

func (pi *PointsItem) FollowingItem(precedingItem TrackItem, dir PointDirection) (TrackItem, error)

FollowingItem returns the following TrackItem linked to this one, knowing we come from precedingItem(). Returned is either NextItem or PreviousItem, depending which way we come from.

The second argument will return a ItemsNotLinkedError if the given precedingItem is not linked to this item.

func (*PointsItem) ID

func (t *PointsItem) ID() string

routeID returns the unique routeID of this TrackItem, which is the index of this item in the Simulation's TrackItems map.

func (*PointsItem) IsConnected

func (pi *PointsItem) IsConnected(oti TrackItem) bool

IsConnected returns true if this TrackItem is connected to the given TrackItem, false otherwise

func (*PointsItem) IsOnPosition

func (t *PointsItem) IsOnPosition(pos Position) bool

IsOnPosition returns true if this track item is the track item of the given position.

func (*PointsItem) MarshalJSON

func (pi *PointsItem) MarshalJSON() ([]byte, error)

MarshalJSON method for PointsItem

func (*PointsItem) MaxSpeed

func (t *PointsItem) MaxSpeed() float64

MaxSpeed is the maximum allowed speed on this TrackItem in meters per second.

func (*PointsItem) Name

func (t *PointsItem) Name() string

Name returns the human readable name of this item

func (*PointsItem) NextItem

func (t *PointsItem) NextItem() TrackItem

NextItem returns the next item of this TrackItem.

The next item is usually the item connected to the end of the item that is not the Origin

func (*PointsItem) NormalEnd

func (pi *PointsItem) NormalEnd() Point

NormalEnd return the normal end point in the item's coordinates

func (*PointsItem) Origin

func (pi *PointsItem) Origin() Point

Origin are the two coordinates (x, y) of the origin, i.e. the absolute coordinates of the common end.

func (*PointsItem) PairedItem added in v0.7.7

func (pi *PointsItem) PairedItem() *PointsItem

PairedItem returns the points item that must change simultaneously with this one. It return nil if there is no such item.

func (*PointsItem) Place

func (t *PointsItem) Place() *Place

Place returns the TrackItem of type Place associated with this item (as defined by PlaceCode).

func (*PointsItem) PreviousItem

func (t *PointsItem) PreviousItem() TrackItem

PreviousItem returns the previous item of this TrackItem.

The previous item is usually the item connected to the Origin() of this item.

func (*PointsItem) RealLength

func (t *PointsItem) RealLength() float64

RealLength is the length in meters that this TrackItem has in real life track length

func (*PointsItem) Reverse

func (pi *PointsItem) Reverse() Point

Reverse returns the two (Xr, Yr) absolute coordinates of the reverse end.

func (*PointsItem) ReverseEnd

func (pi *PointsItem) ReverseEnd() Point

ReverseEnd return the reverse end point in the item's coordinates

func (*PointsItem) ReverseItem

func (pi *PointsItem) ReverseItem() TrackItem

ReverseItem returns the item linked to the reverse end of these points

func (*PointsItem) Reversed

func (pi *PointsItem) Reversed() bool

Reversed returns true if the points are in the reversed position, false otherwise

func (*PointsItem) Simulation

func (t *PointsItem) Simulation() *Simulation

Simulation returns the Simulation object that this TrackItem belongs to.

func (*PointsItem) TrackCode

func (t *PointsItem) TrackCode() string

TrackCode returns the track number of this LineItem, if it is part of a TypePlace and if it has one.

func (*PointsItem) TrainPresent

func (t *PointsItem) TrainPresent() bool

TrainPresent returns true if at least one train is present on this TrackItem

func (*PointsItem) Type

func (pi *PointsItem) Type() TrackItemType

Type returns the name of the type of this item

type PointsItemManager

type PointsItemManager interface {
	// Name returns a description of this PointsItemManager that is used for the UI.
	Name() string
	// Direction returns the direction of the points
	Direction(*PointsItem) PointDirection
	// SetDirection tries to set the given PointsItem to the given direction
	//
	// You should not assume that the direction has been set, since this can be
	// delayed or failed. Call Direction to check.
	SetDirection(*PointsItem, PointDirection)
}

A PointsItemManager simulates the physical points, in particular delay in points position and breakdowns

type Position

type Position struct {
	TrackItemID    string  `json:"trackItem"`
	PreviousItemID string  `json:"previousTI"`
	PositionOnTI   float64 `json:"positionOnTI"`
	// contains filtered or unexported fields
}

A Position object is a point on a TrackItem.

A Position is defined as being positionOnTI meters away from the end of this TrackItem that is connected to PreviousItem.

Note that a Position has a direction, so that for any point on a TrackItem, there are two Positions that can be defined:

  • one starting from one end of the TrackItem.
  • the other starting from the other end.

You can get the other Position by calling Reversed()

func NewPosition

func NewPosition(sim *Simulation, trackItemID, previousTI string, positionOnTI float64) Position

func NextSignalPosition

func NextSignalPosition(pos Position) Position

NextSignalPosition returns the position of the next signal in front of the given position.

Returns a null position if there is no signal ahead.

func (Position) Add

func (pos Position) Add(length float64) Position

Add returns the Position that is length ahead of this position. If length is negative, find the position backwards.

func (Position) Equals

func (pos Position) Equals(pos2 Position) bool

Equals returns true if this position is the same as pos2.

func (Position) IsNull

func (pos Position) IsNull() bool

IsNull returns true if this Position is null.

func (Position) IsOut

func (pos Position) IsOut() bool

IsOut is true if this position is out of the scene and moving forward

func (Position) IsValid

func (pos Position) IsValid() bool

IsValid returns true if this is a valid position (i.e. items are connected, and distance is positive), false otherwise.

func (Position) Next

func (pos Position) Next(dir PointDirection) Position

Next is the first Position on the next TrackItem with regard to this Position

func (Position) Previous

func (pos Position) Previous() Position

Previous is the last Position on the previous TrackItem with regard to this Position

func (Position) PreviousItem

func (pos Position) PreviousItem() TrackItem

PreviousItem of this Position

func (Position) Reversed

func (pos Position) Reversed() Position

Reversed returns the position that is at the same position but in the opposite direction.

func (Position) String

func (pos Position) String() string

String method for the Position type

func (Position) Sub

func (pos Position) Sub(orig Position) (float64, error)

Sub returns the distance between orig and this position.

It returns an error if both pos is not ahead of orig, and in the same direction

func (Position) TrackItem

func (pos Position) TrackItem() TrackItem

TrackItem of this Position

type PreviousActiveRoute

type PreviousActiveRoute struct{}

previousActiveRoute is true if a route ending at this Signal is active

func (PreviousActiveRoute) Code

func (par PreviousActiveRoute) Code() string

Code of the ConditionType, uniquely defines this ConditionType

func (PreviousActiveRoute) SetupTriggers

func (par PreviousActiveRoute) SetupTriggers(item *SignalItem, params []string)

SetupTriggers installs needed triggers for the given SignalItem, with the given Condition.

func (PreviousActiveRoute) Solve

func (par PreviousActiveRoute) Solve(item *SignalItem, values []string, params []string) bool

Solve returns if the condition is met for the given SignalItem and parameters

type Route

type Route struct {
	BeginSignalId string                    `json:"beginSignal"`
	EndSignalId   string                    `json:"endSignal"`
	InitialState  RouteState                `json:"initialState"`
	Directions    map[string]PointDirection `json:"directions"`
	Persistent    bool                      `json:"persistent"`
	Positions     []Position                `json:"-"`
	// contains filtered or unexported fields
}

A Route is a path between two signals.

If a route is Activated, the path is selected, and the signals at the beginning and the end of the route are changed and the conflicting possible other routes are inhibited. Routes are static and defined in the game file. The player can only activate or deactivate them.

func (*Route) Activate

func (r *Route) Activate(persistent bool) error

Activate the given route. If the route cannot be Activated, an error is returned.

func (*Route) BeginSignal

func (r *Route) BeginSignal() *SignalItem

BeginSignal returns the SignalItem at which this Route starts.

func (*Route) Deactivate

func (r *Route) Deactivate() error

Deactivate the given route. If the route cannot be Deactivated, an error is returned.

func (*Route) EndSignal

func (r *Route) EndSignal() *SignalItem

EndSignal returns the SignalItem at which this Route ends.

func (*Route) Equals

func (r *Route) Equals(other *Route) bool

Equals returns true if this Route is the same as other, that is they have the same routeID.

func (*Route) ID

func (r *Route) ID() string

ID returns the unique identifier of this route

func (*Route) IsActive

func (r *Route) IsActive() bool

IsActive returns true if this Route is active

func (*Route) MarshalJSON

func (r *Route) MarshalJSON() ([]byte, error)

MarshalJSON for the Route type

func (*Route) State

func (r *Route) State() RouteState

State returns the current state of this route

func (*Route) UnmarshalJSON

func (r *Route) UnmarshalJSON(data []byte) error

UnmarshalJSON for the Route type

type RouteExitSignalAspects added in v0.7.3

type RouteExitSignalAspects struct{}

RouteExitSignalAspects is true if the exit signal of the route starting at this signal is showing one of the aspects given. If no route is set from this signal, the condition is always false.

func (RouteExitSignalAspects) Code added in v0.7.3

func (resa RouteExitSignalAspects) Code() string

Code of the ConditionType, uniquely defines this ConditionType

func (RouteExitSignalAspects) SetupTriggers added in v0.7.3

func (resa RouteExitSignalAspects) SetupTriggers(item *SignalItem, params []string)

SetupTriggers installs needed triggers for the given SignalItem, with the given Condition.

func (RouteExitSignalAspects) Solve added in v0.7.3

func (resa RouteExitSignalAspects) Solve(item *SignalItem, values []string, params []string) bool

Solve returns if the condition is met for the given SignalItem and parameters

type RouteSet

type RouteSet struct{}

RouteSet is true if at least one of the routes, the id of which is defined by custom property is active. These routes don't have to start at this signal.

func (RouteSet) Code

func (rs RouteSet) Code() string

Code of the ConditionType, uniquely defines this ConditionType

func (RouteSet) SetupTriggers

func (rs RouteSet) SetupTriggers(item *SignalItem, params []string)

SetupTriggers installs needed triggers for the given SignalItem, with the given Condition.

func (RouteSet) Solve

func (rs RouteSet) Solve(item *SignalItem, values []string, params []string) bool

Solve returns if the condition is met for the given SignalItem and parameters

type RouteSetAcross

type RouteSetAcross struct{}

RouteSetAcross is true if a route is active across this signal, in the same direction but neither starting nor ending at this signal.

func (RouteSetAcross) Code

func (rsa RouteSetAcross) Code() string

Code of the ConditionType, uniquely defines this ConditionType

func (RouteSetAcross) SetupTriggers

func (rsa RouteSetAcross) SetupTriggers(item *SignalItem, params []string)

SetupTriggers installs needed triggers for the given SignalItem, with the given Condition.

func (RouteSetAcross) Solve

func (rsa RouteSetAcross) Solve(item *SignalItem, values []string, params []string) bool

Solve returns if the condition is met for the given SignalItem and parameters

type RouteState

type RouteState uint8

RouteState represents the state of a Route at a given time and instance

const (
	// Deactivated = The route is not active
	Deactivated RouteState = 0

	// Activated = The route is active but will be destroyed by the first train using it
	Activated RouteState = 1

	// Persistent = The route is set and will remain after train passage
	Persistent RouteState = 2

	// Destroying = The route is currently being destroyed by a train
	Destroying RouteState = 3
)

type RoutesManager

type RoutesManager interface {
	// Name returns a description of this routesManager that can be displayed
	// to the user if one of this managers method returns false.
	Name() string
	// CanActivate returns an error if the given route cannot be Activated
	CanActivate(r *Route) error
	// CanDeactivate returns an error if the given route cannot be Deactivated
	CanDeactivate(r *Route) error
}

A RoutesManager checks if a route is activable or deactivable.

type Service

type Service struct {
	Description          string           `json:"description"`
	Lines                []*ServiceLine   `json:"lines"`
	PlannedTrainTypeCode string           `json:"plannedTrainType"`
	PostActions          []*ServiceAction `json:"postActions"`
	// contains filtered or unexported fields
}

A Service is mainly a predefined schedule that trains are supposed to follow with a few additional informations.

The schedule is composed of several "lines" of type ServiceLine

func (*Service) ID

func (s *Service) ID() string

ID returns the unique identifier of this service: its code

func (*Service) MarshalJSON

func (s *Service) MarshalJSON() ([]byte, error)

MarshalJSON for the Service type

func (*Service) PlannedTrainType

func (s *Service) PlannedTrainType() *TrainType

PlannedTrainType returns a pointer to the planned TrainType for this Service.

type ServiceAction

type ServiceAction struct {
	ActionCode  serviceActionCode `json:"actionCode"`
	ActionParam string            `json:"actionParam"`
}

A ServiceAction is an action that can be performed on a train

type ServiceLine

type ServiceLine struct {
	MustStop               bool   `json:"mustStop"`
	PlaceCode              string `json:"placeCode"`
	ScheduledArrivalTime   Time   `json:"scheduledArrivalTime"`
	ScheduledDepartureTime Time   `json:"scheduledDepartureTime"`
	TrackCode              string `json:"trackCode"`
	// contains filtered or unexported fields
}

ServiceLine is a line of the definition of the Service.

It consists of a TypePlace (usually a station) with a track number and scheduled times to arrive at and depart from this station.

func (*ServiceLine) Place

func (sl *ServiceLine) Place() *Place

Place associated with this service line

type SignalAction

type SignalAction struct {
	Target   ActionTarget
	Speed    float64
	Duration time.Duration
}

SignalAction defines an action that must be performed by a train when seeing a SignalAspect.

func (*SignalAction) MarshalJSON

func (sa *SignalAction) MarshalJSON() ([]byte, error)

MarshalJSON for the SignalAction Type

func (*SignalAction) UnmarshalJSON

func (sa *SignalAction) UnmarshalJSON(data []byte) error

UnmarshalJSON for the SignalAction Type

type SignalAspect

type SignalAspect struct {
	Name         string          `json:"name"`
	LineStyle    signalLineStyle `json:"lineStyle"`
	OuterShapes  [6]signalShape  `json:"outerShapes"`
	OuterColors  [6]Color        `json:"outerColors"`
	Shapes       [6]signalShape  `json:"shapes"`
	ShapesColors [6]Color        `json:"shapesColors"`
	Blink        [6]bool         `json:"blink"`
	Actions      []SignalAction  `json:"actions"`
}

SignalAspect class represents an aspect of a signal, that is a combination of on and off lights with a meaning for the train driver.

func (*SignalAspect) Equals

func (sa *SignalAspect) Equals(other *SignalAspect) bool

Equals returns true if this aspect is the same as the other aspect, i.e. they have the same name.

func (*SignalAspect) MeansProceed

func (sa *SignalAspect) MeansProceed() bool

MeansProceed returns true if this aspect is a proceed aspect, returns false if this aspect requires to stop

type SignalItem

type SignalItem struct {
	Xb             float64 `json:"xn"`
	Yb             float64 `json:"yn"`
	SignalTypeCode string  `json:"signalType"`
	Reverse        bool    `json:"reverse"`
	// contains filtered or unexported fields
}

SignalItem is the "logical" item for signals. It holds the logic of a signal defined by its SignalType. A signal is the item from and to which routes are created.

func (*SignalItem) ActiveAspect

func (si *SignalItem) ActiveAspect() *SignalAspect

ActiveAspect returns the current aspect of the signal

func (*SignalItem) ActiveRoute

func (t *SignalItem) ActiveRoute() *Route

ActiveRoute returns a pointer to the route currently active on this item

func (*SignalItem) ActiveRoutePreviousItem

func (t *SignalItem) ActiveRoutePreviousItem() TrackItem

ActiveRoutePreviousItem returns the previous item in the active route direction

func (*SignalItem) BerthOrigin

func (si *SignalItem) BerthOrigin() Point

BerthOrigin is the Point at which the berth of this signal must be displayed by clients. Berths are where train descriptors are displayed.

func (*SignalItem) ConflictItem

func (t *SignalItem) ConflictItem() TrackItem

ConflictItem returns the conflicting item of this TrackItem. The conflicting item is another item of the scenery on which a route must not be set if one is already active on this TrackItem (and vice-versa). This is particularly the case when two TrackItems cross over with no points.

func (*SignalItem) CustomProperty

func (t *SignalItem) CustomProperty(key string) CustomProperty

CustomProperty returns the custom property with the given key

func (*SignalItem) DistanceToTrainEnd

func (t *SignalItem) DistanceToTrainEnd(pos Position) (float64, bool)

DistanceToTrainEnd returns the distance to the closest end (either train head or train tail) of the closest train when on pos. If no train is on this item, the distance will be 0, and the second argument will be false.

func (*SignalItem) End

func (t *SignalItem) End() Point

End are the two coordinates (xf, yf) of the end point of this TrackItem.

func (*SignalItem) Equals

func (t *SignalItem) Equals(ti TrackItem) bool

Equals returns true if this track item and the given one are the same (i.e. they have the same routeID)

func (*SignalItem) FollowingItem

func (t *SignalItem) FollowingItem(precedingItem TrackItem, dir PointDirection) (TrackItem, error)

FollowingItem returns the following TrackItem linked to this one, knowing we come from precedingItem(). Returned is either NextItem or PreviousItem, depending which way we come from.

The second argument will return a ItemsNotLinkedError if the given precedingItem is not linked to this item.

func (*SignalItem) ID

func (t *SignalItem) ID() string

routeID returns the unique routeID of this TrackItem, which is the index of this item in the Simulation's TrackItems map.

func (*SignalItem) IsConnected

func (t *SignalItem) IsConnected(oti TrackItem) bool

IsConnected returns true if this TrackItem is connected to the given TrackItem, false otherwise

func (*SignalItem) IsOnPosition

func (si *SignalItem) IsOnPosition(pos Position) bool

IsOnPosition returns true if this signal item is the track item of the given position and the position is in the direction of the signal.

func (*SignalItem) MarshalJSON

func (si *SignalItem) MarshalJSON() ([]byte, error)

MarshalJSON method for SignalItem

func (*SignalItem) MaxSpeed

func (t *SignalItem) MaxSpeed() float64

MaxSpeed is the maximum allowed speed on this TrackItem in meters per second.

func (*SignalItem) Name

func (t *SignalItem) Name() string

Name returns the human readable name of this item

func (*SignalItem) NextItem

func (t *SignalItem) NextItem() TrackItem

NextItem returns the next item of this TrackItem.

The next item is usually the item connected to the end of the item that is not the Origin

func (*SignalItem) Origin

func (t *SignalItem) Origin() Point

Origin are the two coordinates (x, y) of the origin point of this TrackItem.

func (*SignalItem) Place

func (t *SignalItem) Place() *Place

Place returns the TrackItem of type Place associated with this item (as defined by PlaceCode).

func (*SignalItem) Position

func (si *SignalItem) Position() Position

Position returns the position of the origin of this signal

func (*SignalItem) PreviousItem

func (t *SignalItem) PreviousItem() TrackItem

PreviousItem returns the previous item of this TrackItem.

The previous item is usually the item connected to the Origin() of this item.

func (*SignalItem) RealLength

func (t *SignalItem) RealLength() float64

RealLength is the length in meters that this TrackItem has in real life track length

func (*SignalItem) Reversed

func (si *SignalItem) Reversed() bool

Reversed() return true if the SignalItem is for trains coming from the right

func (*SignalItem) SignalType

func (si *SignalItem) SignalType() *SignalType

SignalType returns a pointer to the SignalType of this signal

func (*SignalItem) Simulation

func (t *SignalItem) Simulation() *Simulation

Simulation returns the Simulation object that this TrackItem belongs to.

func (*SignalItem) TrackCode

func (t *SignalItem) TrackCode() string

TrackCode returns the track number of this LineItem, if it is part of a TypePlace and if it has one.

func (*SignalItem) TrainPresent

func (t *SignalItem) TrainPresent() bool

TrainPresent returns true if at least one train is present on this TrackItem

func (*SignalItem) Type

func (si *SignalItem) Type() TrackItemType

Type returns the name of the type of this item

type SignalItemManager

type SignalItemManager interface {
	// Name returns a description of this signalItemManager that is used for the UI.
	Name() string
	// GetAspect returns the aspect of the given signal that should be active
	GetAspect(*SignalItem) *SignalAspect
}

A SignalItemManager is in charge of computing the aspect of a signal

type SignalLibrary

type SignalLibrary struct {
	Aspects map[string]*SignalAspect `json:"signalAspects"`
	Types   map[string]*SignalType   `json:"signalTypes"`
}

SignalLibrary holds the information about the signal types and signal aspects available in the simulation.

type SignalState

type SignalState struct {
	AspectName string
	Aspect     *SignalAspect
	Conditions map[string]Condition
}

A SignalState is an aspect of a signal with a set of conditions to display this aspect.

func (*SignalState) MarshalJSON

func (s *SignalState) MarshalJSON() ([]byte, error)

MarshalJSON for the SignalState type

func (*SignalState) UnmarshalJSON

func (s *SignalState) UnmarshalJSON(data []byte) error

UnmarshalJSON for the SignalState Type

type SignalType

type SignalType struct {
	Name   string        `json:"name"`
	States []SignalState `json:"states"`
}

A SignalType describes a type of signals which can have different aspects and the logic for displaying aspects.

func (*SignalType) GetAspect

func (st *SignalType) GetAspect(signal *SignalItem) *SignalAspect

GetAspect returns the aspect that signal should show according to this SignalType logic.

type SimObject

type SimObject interface {
	ID() string
}

A SimObject can be serialized in an event

type Simulation

type Simulation struct {
	SignalLib     SignalLibrary
	TrackItems    map[string]TrackItem
	Places        map[string]*Place
	Options       Options
	Routes        map[string]*Route
	TrainTypes    map[string]*TrainType
	Services      map[string]*Service
	Trains        []*Train
	MessageLogger *MessageLogger
	EventChan     chan *Event
	// contains filtered or unexported fields
}

Simulation holds all the game logic.

func (*Simulation) Initialize

func (sim *Simulation) Initialize() error

Initialize initializes the simulation. This method must be called before Start.

func (*Simulation) IsStarted

func (sim *Simulation) IsStarted() bool

IsStarted returns true if the simulation clock is running.

func (Simulation) MarshalJSON

func (sim Simulation) MarshalJSON() ([]byte, error)

MarshalJSON for the Simulation type

func (*Simulation) Pause

func (sim *Simulation) Pause()

Pause holds the simulation by stopping the clock ticker. Call Start again to restart the simulation.

func (*Simulation) Start

func (sim *Simulation) Start()

Start runs the main loop of the simulation by making the clock tick and process each object.

func (*Simulation) UnmarshalJSON

func (sim *Simulation) UnmarshalJSON(data []byte) error

UnmarshalJSON for the Simulation type

type TextItem

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

TextItem "displays simple text" on the scenery layout

func (*TextItem) ActiveRoute

func (t *TextItem) ActiveRoute() *Route

ActiveRoute returns a pointer to the route currently active on this item

func (*TextItem) ActiveRoutePreviousItem

func (t *TextItem) ActiveRoutePreviousItem() TrackItem

ActiveRoutePreviousItem returns the previous item in the active route direction

func (*TextItem) ConflictItem

func (t *TextItem) ConflictItem() TrackItem

ConflictItem returns the conflicting item of this TrackItem. The conflicting item is another item of the scenery on which a route must not be set if one is already active on this TrackItem (and vice-versa). This is particularly the case when two TrackItems cross over with no points.

func (*TextItem) CustomProperty

func (t *TextItem) CustomProperty(key string) CustomProperty

CustomProperty returns the custom property with the given key

func (*TextItem) DistanceToTrainEnd

func (t *TextItem) DistanceToTrainEnd(pos Position) (float64, bool)

DistanceToTrainEnd returns the distance to the closest end (either train head or train tail) of the closest train when on pos. If no train is on this item, the distance will be 0, and the second argument will be false.

func (*TextItem) End

func (t *TextItem) End() Point

End are the two coordinates (xf, yf) of the end point of this TrackItem.

func (*TextItem) Equals

func (t *TextItem) Equals(ti TrackItem) bool

Equals returns true if this track item and the given one are the same (i.e. they have the same routeID)

func (*TextItem) FollowingItem

func (t *TextItem) FollowingItem(precedingItem TrackItem, dir PointDirection) (TrackItem, error)

FollowingItem returns the following TrackItem linked to this one, knowing we come from precedingItem(). Returned is either NextItem or PreviousItem, depending which way we come from.

The second argument will return a ItemsNotLinkedError if the given precedingItem is not linked to this item.

func (*TextItem) ID

func (t *TextItem) ID() string

routeID returns the unique routeID of this TrackItem, which is the index of this item in the Simulation's TrackItems map.

func (*TextItem) IsConnected

func (t *TextItem) IsConnected(oti TrackItem) bool

IsConnected returns true if this TrackItem is connected to the given TrackItem, false otherwise

func (*TextItem) IsOnPosition

func (t *TextItem) IsOnPosition(pos Position) bool

IsOnPosition returns true if this track item is the track item of the given position.

func (*TextItem) MarshalJSON

func (t *TextItem) MarshalJSON() ([]byte, error)

MarshalJSON method for trackStruct

func (*TextItem) MaxSpeed

func (t *TextItem) MaxSpeed() float64

MaxSpeed is the maximum allowed speed on this TrackItem in meters per second.

func (*TextItem) Name

func (t *TextItem) Name() string

Name returns the human readable name of this item

func (*TextItem) NextItem

func (t *TextItem) NextItem() TrackItem

NextItem returns the next item of this TrackItem.

The next item is usually the item connected to the end of the item that is not the Origin

func (*TextItem) Origin

func (t *TextItem) Origin() Point

Origin are the two coordinates (x, y) of the origin point of this TrackItem.

func (*TextItem) Place

func (t *TextItem) Place() *Place

Place returns the TrackItem of type Place associated with this item (as defined by PlaceCode).

func (*TextItem) PreviousItem

func (t *TextItem) PreviousItem() TrackItem

PreviousItem returns the previous item of this TrackItem.

The previous item is usually the item connected to the Origin() of this item.

func (*TextItem) RealLength

func (t *TextItem) RealLength() float64

RealLength is the length in meters that this TrackItem has in real life track length

func (*TextItem) Simulation

func (t *TextItem) Simulation() *Simulation

Simulation returns the Simulation object that this TrackItem belongs to.

func (*TextItem) TrackCode

func (t *TextItem) TrackCode() string

TrackCode returns the track number of this LineItem, if it is part of a TypePlace and if it has one.

func (*TextItem) TrainPresent

func (t *TextItem) TrainPresent() bool

TrainPresent returns true if at least one train is present on this TrackItem

func (*TextItem) Type

func (ti *TextItem) Type() TrackItemType

Type returns the name of the type of this item

type Time

type Time struct {
	sync.RWMutex
	time.Time
}

Time type for the simulation (HH:MM:SS).

Valid Time objects start on 0000-01-02.

func ParseTime

func ParseTime(data string) Time

ParseTime returns a Time object from its string representation in format 15:04:05

func (Time) Add

func (h Time) Add(duration time.Duration) Time

Add returns the time h + duration .

func (Time) After

func (h Time) After(u Time) bool

After reports whether the time instant h is after u.

func (Time) Before

func (h Time) Before(u Time) bool

Before reports whether the time instant h is before u.

func (Time) ID

func (h Time) ID() string

ID method exists only to comply to the SimObject interface so that Time objects can be serialized in event notifications.

func (Time) MarshalJSON

func (h Time) MarshalJSON() ([]byte, error)

MarshalJSON for the Time type

func (Time) Sub

func (h Time) Sub(u Time) time.Duration

Sub returns the duration t-u. If the result exceeds the maximum (or minimum) value that can be stored in a Duration, the maximum (or minimum) duration will be returned. To compute t-d for a duration d, use t.Add(-d).

func (*Time) UnmarshalJSON

func (h *Time) UnmarshalJSON(data []byte) error

UnmarshalJSON for the Time type

type TrackItem

type TrackItem interface {
	// routeID returns the unique routeID of this TrackItem, which is the index of this
	// item in the Simulation's TrackItems map.
	ID() string

	// Type returns the name of the type of this item
	Type() TrackItemType

	// Name returns the human readable name of this item
	Name() string

	// NextItem returns the next item of this TrackItem.
	//
	// The next item is usually the item connected to the end of the item that is not the Origin
	NextItem() TrackItem

	// PreviousItem returns the previous item of this TrackItem.
	//
	// The previous item is usually the item connected to the Origin() of this item.
	PreviousItem() TrackItem

	// MaxSpeed is the maximum allowed speed on this TrackItem in meters per second.
	MaxSpeed() float64

	// RealLength is the length in meters that this TrackItem has in real life track length
	RealLength() float64

	// Origin are the two coordinates (x, y) of the origin point of this TrackItem.
	Origin() Point

	// End are the two coordinates (xf, yf) of the end point of this TrackItem.
	End() Point

	// ConflictItem returns the conflicting item of this TrackItem. The conflicting
	// item is another item of the scenery on which a route must not be set if
	// one is already active on this TrackItem (and vice-versa). This is
	// particularly the case when two TrackItems cross over with no points.
	ConflictItem() TrackItem

	// Place returns the TrackItem of type Place associated with this item
	// (as defined by PlaceCode).
	Place() *Place

	// TrackCode returns the code (usually a number) of the track line
	TrackCode() string

	// FollowingItem returns the following TrackItem linked to this one,
	// knowing we come from precedingItem(). Returned is either NextItem or
	// PreviousItem, depending which way we come from.
	//
	// The second argument will return a ItemsNotLinkedError if the given
	// precedingItem is not linked to this item.
	FollowingItem(TrackItem, PointDirection) (TrackItem, error)

	// IsConnected returns true if this TrackItem is connected to the given
	// TrackItem, false otherwise
	IsConnected(TrackItem) bool

	// CustomProperty returns the custom property with the given key
	CustomProperty(string) CustomProperty

	// ActiveRoute returns a pointer to the route currently active on this item
	ActiveRoute() *Route

	// ActiveRoutePreviousItem returns the previous item in the active route direction
	ActiveRoutePreviousItem() TrackItem

	// TrainPresent returns true if at least one train is present on this TrackItem
	TrainPresent() bool

	// IsOnPosition returns true if this track item is the track item of the given position.
	// When applicable, also checks if the item is in the same direction as the position.
	IsOnPosition(Position) bool

	// DistanceToTrainEnd returns the distance to the closest end (either train head or
	// train tail) of the closest train when on pos. If no train is on this item, the
	// distance will be 0, and the second argument will be false.
	DistanceToTrainEnd(Position) (float64, bool)

	// Equals returns true if this track item and the given one are the same
	// (i.e. they have the same routeID)
	Equals(TrackItem) bool

	// Simulation returns the Simulation object that this TrackItem belongs to.
	Simulation() *Simulation
	// contains filtered or unexported methods
}

A TrackItem is a piece of scenery and is "the base interface" for others such as SignalItem, EndItem, PointsItem.

Every item has defined coordinates in the scenery layout and is connected to other TrackItems's so that trains can travel from one to another.

The coordinates are expressed in pixels, the X-axis is from left to right and the Y-axis is from top to bottom.

Every TrackItem has an Origin() Point defined by its X and Y values.

type TrackItemType

type TrackItemType string

A TrackItemType holds the type of a track item

const (
	TypeTrack         TrackItemType = "TrackItem"
	TypeLine          TrackItemType = "LineItem"
	TypeInvisibleLink TrackItemType = "InvisibleLinkItem"
	TypeEnd           TrackItemType = "EndItem"
	TypeSignal        TrackItemType = "SignalItem"
	TypePoints        TrackItemType = "PointsItem"
	TypePlace         TrackItemType = "Place"
	TypePlatform      TrackItemType = "PlatformItem"
	TypeText          TrackItemType = "TextItem"
)

Available track item types.

type Train

type Train struct {
	AppearTime     Time           `json:"appearTime"`
	InitialDelay   DelayGenerator `json:"initialDelay"`
	InitialSpeed   float64        `json:"initialSpeed"`
	NextPlaceIndex int            `json:"nextPlaceIndex"`
	ServiceCode    string         `json:"serviceCode"`
	Speed          float64        `json:"speed"`
	Status         TrainStatus    `json:"status"`
	StoppedTime    int            `json:"stoppedTime"`
	TrainTypeCode  string         `json:"trainTypeCode"`
	TrainHead      Position       `json:"trainHead"`
	// contains filtered or unexported fields
}

Train is a stock of `TrainType` running on a track at a certain speed and to which is assigned a `Service`.

func (*Train) ApplicableAction

func (t *Train) ApplicableAction() SignalAction

ApplicableAction returns the current signal action that this train is following

func (*Train) AssignService

func (t *Train) AssignService(srv string) error

AssignService assigns the given service to the train, replacing the current one

func (*Train) ID

func (t *Train) ID() string

ID returns the unique internal identifier of this Train

func (*Train) IsActive

func (t *Train) IsActive() bool

IsActive returns true if this train is in the area and its service is not finished.

func (*Train) IsShunting

func (t *Train) IsShunting() bool

IsShunting returns true if this train is currently shunting.

func (*Train) LastSeenSignal

func (t *Train) LastSeenSignal() *SignalItem

LastSeenSignal returns the last signal seen by the driver. It may still be in front of the train head.

func (Train) MarshalJSON

func (t Train) MarshalJSON() ([]byte, error)

MarshalJSON method for the train type

func (*Train) NextSignalPosition

func (t *Train) NextSignalPosition() Position

NextSignalPosition returns the position of the next signal in front of this train

Returns a null position if there is no signal ahead.

func (*Train) ProceedWithCaution

func (t *Train) ProceedWithCaution() error

ProceedWithCaution tells the train driver to proceed through the closed signal at WarningSpeed until the next signal.

func (*Train) ResetService

func (t *Train) ResetService() error

ResetService restarts the service for the current train, as if nothing had happened.

func (*Train) Reverse

func (t *Train) Reverse() error

Reverse the train direction

func (*Train) Service

func (t *Train) Service() *Service

Service returns a pointer to the Service assigned to this Train, or nil if no Service is assigned.

func (*Train) TrainTail

func (t *Train) TrainTail() Position

TrainTail returns the position of the train's tail

func (*Train) TrainType

func (t *Train) TrainType() *TrainType

TrainType returns a pointer to the TrainType that this Train is running.

type TrainNotPresentBeforeNextSignal added in v0.7.3

type TrainNotPresentBeforeNextSignal struct{}

TrainNotPresentBeforeNextSignal is true if there is no train ahead of this signal and before the next signal on the line. Signal aspects ending with ! can be added in the list to discard the given signal and look up to the next one.

func (TrainNotPresentBeforeNextSignal) Code added in v0.7.3

Code of the ConditionType, uniquely defines this ConditionType

func (TrainNotPresentBeforeNextSignal) SetupTriggers added in v0.7.3

func (tnpbns TrainNotPresentBeforeNextSignal) SetupTriggers(item *SignalItem, params []string)

SetupTriggers installs needed triggers for the given SignalItem, with the given Condition.

func (TrainNotPresentBeforeNextSignal) Solve added in v0.7.3

func (tnpbns TrainNotPresentBeforeNextSignal) Solve(item *SignalItem, values []string, params []string) bool

Solve returns if the condition is met for the given SignalItem and parameters

type TrainNotPresentOnItems

type TrainNotPresentOnItems struct{}

TrainNotPresentOnItems is true if there is no train on the track items defined by params.

func (TrainNotPresentOnItems) Code

func (tnpoi TrainNotPresentOnItems) Code() string

Code of the ConditionType, uniquely defines this ConditionType

func (TrainNotPresentOnItems) SetupTriggers

func (tnpoi TrainNotPresentOnItems) SetupTriggers(item *SignalItem, params []string)

SetupTriggers installs needed triggers for the given SignalItem, with the given Condition.

func (TrainNotPresentOnItems) Solve

func (tnpoi TrainNotPresentOnItems) Solve(item *SignalItem, values []string, params []string) bool

Solve returns if the condition is met for the given SignalItem and parameters

type TrainNotPresentOnNextRoute

type TrainNotPresentOnNextRoute struct{}

TrainNotPresentOnNextRoute is true if there is no train ahead of this signal and before the end of the next active route. If no route is set, the condition is always false.

func (TrainNotPresentOnNextRoute) Code

func (tnpnr TrainNotPresentOnNextRoute) Code() string

Code of the ConditionType, uniquely defines this ConditionType

func (TrainNotPresentOnNextRoute) SetupTriggers

func (tnpnr TrainNotPresentOnNextRoute) SetupTriggers(item *SignalItem, params []string)

SetupTriggers installs needed triggers for the given SignalItem, with the given Condition.

func (TrainNotPresentOnNextRoute) Solve

func (tnpnr TrainNotPresentOnNextRoute) Solve(item *SignalItem, values []string, params []string) bool

Solve returns if the condition is met for the given SignalItem and parameters

type TrainPresentOnItems

type TrainPresentOnItems struct{}

TrainPresentOnItems is true if there a train on all the track items defined by custom property.

func (TrainPresentOnItems) Code

func (tpoi TrainPresentOnItems) Code() string

Code of the ConditionType, uniquely defines this ConditionType

func (TrainPresentOnItems) SetupTriggers

func (tpoi TrainPresentOnItems) SetupTriggers(item *SignalItem, params []string)

SetupTriggers installs needed triggers for the given SignalItem, with the given Condition.

func (TrainPresentOnItems) Solve

func (tpoi TrainPresentOnItems) Solve(item *SignalItem, values []string, params []string) bool

Solve returns if the condition is met for the given SignalItem and parameters

type TrainStatus

type TrainStatus uint8

The TrainStatus describe the current state of a train

const (
	// Inactive means not yet entered on the scene
	Inactive TrainStatus = 0

	// Running with a positive speed
	Running TrainStatus = 10

	// Stopped at a station
	Stopped TrainStatus = 20

	// Waiting means an unscheduled stop, e.g. at a red signal
	Waiting TrainStatus = 30

	// Out means the train exited the area
	Out TrainStatus = 40

	// EndOfService means the train has finished its service and no new service assigned
	EndOfService TrainStatus = 50
)

type TrainType

type TrainType struct {
	Description  string   `json:"description"`
	EmergBraking float64  `json:"emergBraking"`
	Length       float64  `json:"length"`
	MaxSpeed     float64  `json:"maxSpeed"`
	StdAccel     float64  `json:"stdAccel"`
	StdBraking   float64  `json:"stdBraking"`
	ElementsStr  []string `json:"elements"`
	// contains filtered or unexported fields
}

TrainType defines a rolling stock type.

func (*TrainType) Elements

func (tt *TrainType) Elements() []*TrainType

Elements() returns the train types this TrainType is composed of.

func (*TrainType) ID

func (tt *TrainType) ID() string

ID returns the unique identifier of this train type

func (*TrainType) MarshalJSON

func (tt *TrainType) MarshalJSON() ([]byte, error)

MarshalJSON for the TrainType type

type TrainsManager

type TrainsManager interface {
	// Speed computes and returns the speed of the given train after timeElapsed
	Speed(*Train, time.Duration) float64
	// Name of this manager used for UI messages
	Name() string
}

A TrainsManager defines a driver behaviour which impacts the speed of trains.

Jump to

Keyboard shortcuts

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