Documentation ¶
Overview ¶
package simulation contains core logic of ts2
Index ¶
- Constants
- Variables
- func InitializeLogger(parentLogger log.Logger)
- func RegisterLineItemManager(lim LineItemManager)
- func RegisterPointsItemManager(pim PointsItemManager)
- func RegisterRoutesManager(rm RoutesManager)
- func RegisterSignalItemManager(sim SignalItemManager)
- func RegisterTrainsManager(tm TrainsManager)
- type ActionTarget
- type BoolObject
- type Color
- type Condition
- type ConditionType
- type CustomProperty
- type DelayGenerator
- type EndItem
- func (t *EndItem) ActiveRoute() *Route
- func (t *EndItem) ActiveRoutePreviousItem() TrackItem
- func (t *EndItem) ConflictItem() TrackItem
- func (t *EndItem) CustomProperty(key string) CustomProperty
- func (t *EndItem) DistanceToTrainEnd(pos Position) (float64, bool)
- func (t *EndItem) End() Point
- func (t *EndItem) Equals(ti TrackItem) bool
- func (t *EndItem) FollowingItem(precedingItem TrackItem, dir PointDirection) (TrackItem, error)
- func (t *EndItem) ID() string
- func (t *EndItem) IsConnected(oti TrackItem) bool
- func (t *EndItem) IsOnPosition(pos Position) bool
- func (ei *EndItem) MarshalJSON() ([]byte, error)
- func (t *EndItem) MaxSpeed() float64
- func (t *EndItem) Name() string
- func (t *EndItem) NextItem() TrackItem
- func (t *EndItem) Origin() Point
- func (t *EndItem) Place() *Place
- func (t *EndItem) PreviousItem() TrackItem
- func (ei *EndItem) RealLength() float64
- func (t *EndItem) Simulation() *Simulation
- func (t *EndItem) TrackCode() string
- func (t *EndItem) TrainPresent() bool
- func (ei *EndItem) Type() TrackItemType
- type Event
- type EventName
- type IntObject
- type InvisibleLinkItem
- func (t *InvisibleLinkItem) ActiveRoute() *Route
- func (t *InvisibleLinkItem) ActiveRoutePreviousItem() TrackItem
- func (t *InvisibleLinkItem) ConflictItem() TrackItem
- func (t *InvisibleLinkItem) CustomProperty(key string) CustomProperty
- func (t *InvisibleLinkItem) DistanceToTrainEnd(pos Position) (float64, bool)
- func (t *InvisibleLinkItem) Equals(ti TrackItem) bool
- func (t *InvisibleLinkItem) FollowingItem(precedingItem TrackItem, dir PointDirection) (TrackItem, error)
- func (t *InvisibleLinkItem) ID() string
- func (t *InvisibleLinkItem) IsConnected(oti TrackItem) bool
- func (t *InvisibleLinkItem) IsOnPosition(pos Position) bool
- func (t *InvisibleLinkItem) MaxSpeed() float64
- func (t *InvisibleLinkItem) Name() string
- func (t *InvisibleLinkItem) NextItem() TrackItem
- func (t *InvisibleLinkItem) Origin() Point
- func (t *InvisibleLinkItem) Place() *Place
- func (t *InvisibleLinkItem) PreviousItem() TrackItem
- func (t *InvisibleLinkItem) RealLength() float64
- func (t *InvisibleLinkItem) Simulation() *Simulation
- func (t *InvisibleLinkItem) TrackCode() string
- func (t *InvisibleLinkItem) TrainPresent() bool
- func (ili *InvisibleLinkItem) Type() TrackItemType
- type ItemInconsistentLinkError
- type ItemNotLinkedAtError
- type ItemsNotLinkedError
- type LineItem
- func (t *LineItem) ActiveRoute() *Route
- func (t *LineItem) ActiveRoutePreviousItem() TrackItem
- func (t *LineItem) ConflictItem() TrackItem
- func (t *LineItem) CustomProperty(key string) CustomProperty
- func (t *LineItem) DistanceToTrainEnd(pos Position) (float64, bool)
- func (li *LineItem) End() Point
- func (t *LineItem) Equals(ti TrackItem) bool
- func (t *LineItem) FollowingItem(precedingItem TrackItem, dir PointDirection) (TrackItem, error)
- func (t *LineItem) ID() string
- func (t *LineItem) IsConnected(oti TrackItem) bool
- func (t *LineItem) IsOnPosition(pos Position) bool
- func (li *LineItem) MarshalJSON() ([]byte, error)
- func (t *LineItem) MaxSpeed() float64
- func (t *LineItem) Name() string
- func (t *LineItem) NextItem() TrackItem
- func (t *LineItem) Origin() Point
- func (t *LineItem) Place() *Place
- func (t *LineItem) PreviousItem() TrackItem
- func (t *LineItem) RealLength() float64
- func (t *LineItem) Simulation() *Simulation
- func (t *LineItem) TrackCode() string
- func (t *LineItem) TrainPresent() bool
- func (li *LineItem) Type() TrackItemType
- type LineItemManager
- type Message
- type MessageLogger
- type MessageType
- type NextActiveRoute
- type NextSignalAspects
- type Options
- type Place
- func (t *Place) ActiveRoute() *Route
- func (t *Place) ActiveRoutePreviousItem() TrackItem
- func (t *Place) ConflictItem() TrackItem
- func (t *Place) CustomProperty(key string) CustomProperty
- func (t *Place) DistanceToTrainEnd(pos Position) (float64, bool)
- func (t *Place) End() Point
- func (t *Place) Equals(ti TrackItem) bool
- func (t *Place) FollowingItem(precedingItem TrackItem, dir PointDirection) (TrackItem, error)
- func (t *Place) ID() string
- func (t *Place) IsConnected(oti TrackItem) bool
- func (t *Place) IsOnPosition(pos Position) bool
- func (t *Place) MarshalJSON() ([]byte, error)
- func (t *Place) MaxSpeed() float64
- func (t *Place) Name() string
- func (t *Place) NextItem() TrackItem
- func (t *Place) Origin() Point
- func (t *Place) Place() *Place
- func (t *Place) PreviousItem() TrackItem
- func (t *Place) RealLength() float64
- func (t *Place) Simulation() *Simulation
- func (t *Place) TrackCode() string
- func (t *Place) TrainPresent() bool
- func (pl *Place) Type() TrackItemType
- type PlatformItem
- func (t *PlatformItem) ActiveRoute() *Route
- func (t *PlatformItem) ActiveRoutePreviousItem() TrackItem
- func (t *PlatformItem) ConflictItem() TrackItem
- func (t *PlatformItem) CustomProperty(key string) CustomProperty
- func (t *PlatformItem) DistanceToTrainEnd(pos Position) (float64, bool)
- func (t *PlatformItem) Equals(ti TrackItem) bool
- func (t *PlatformItem) FollowingItem(precedingItem TrackItem, dir PointDirection) (TrackItem, error)
- func (t *PlatformItem) ID() string
- func (t *PlatformItem) IsConnected(oti TrackItem) bool
- func (t *PlatformItem) IsOnPosition(pos Position) bool
- func (t *PlatformItem) MaxSpeed() float64
- func (t *PlatformItem) Name() string
- func (t *PlatformItem) NextItem() TrackItem
- func (t *PlatformItem) Origin() Point
- func (t *PlatformItem) Place() *Place
- func (t *PlatformItem) PreviousItem() TrackItem
- func (t *PlatformItem) RealLength() float64
- func (t *PlatformItem) Simulation() *Simulation
- func (t *PlatformItem) TrackCode() string
- func (t *PlatformItem) TrainPresent() bool
- func (pfi *PlatformItem) Type() TrackItemType
- type Point
- type PointDirection
- type PointsItem
- func (t *PointsItem) ActiveRoute() *Route
- func (t *PointsItem) ActiveRoutePreviousItem() TrackItem
- func (pi *PointsItem) Center() Point
- func (pi *PointsItem) CommonEnd() Point
- func (t *PointsItem) ConflictItem() TrackItem
- func (t *PointsItem) CustomProperty(key string) CustomProperty
- func (t *PointsItem) DistanceToTrainEnd(pos Position) (float64, bool)
- func (pi *PointsItem) End() Point
- func (t *PointsItem) Equals(ti TrackItem) bool
- func (pi *PointsItem) FollowingItem(precedingItem TrackItem, dir PointDirection) (TrackItem, error)
- func (t *PointsItem) ID() string
- func (pi *PointsItem) IsConnected(oti TrackItem) bool
- func (t *PointsItem) IsOnPosition(pos Position) bool
- func (pi *PointsItem) MarshalJSON() ([]byte, error)
- func (t *PointsItem) MaxSpeed() float64
- func (t *PointsItem) Name() string
- func (t *PointsItem) NextItem() TrackItem
- func (pi *PointsItem) NormalEnd() Point
- func (pi *PointsItem) Origin() Point
- func (pi *PointsItem) PairedItem() *PointsItem
- func (t *PointsItem) Place() *Place
- func (t *PointsItem) PreviousItem() TrackItem
- func (t *PointsItem) RealLength() float64
- func (pi *PointsItem) Reverse() Point
- func (pi *PointsItem) ReverseEnd() Point
- func (pi *PointsItem) ReverseItem() TrackItem
- func (pi *PointsItem) Reversed() bool
- func (t *PointsItem) Simulation() *Simulation
- func (t *PointsItem) TrackCode() string
- func (t *PointsItem) TrainPresent() bool
- func (pi *PointsItem) Type() TrackItemType
- type PointsItemManager
- type Position
- func (pos Position) Add(length float64) Position
- func (pos Position) Equals(pos2 Position) bool
- func (pos Position) IsNull() bool
- func (pos Position) IsOut() bool
- func (pos Position) IsValid() bool
- func (pos Position) Next(dir PointDirection) Position
- func (pos Position) Previous() Position
- func (pos Position) PreviousItem() TrackItem
- func (pos Position) Reversed() Position
- func (pos Position) String() string
- func (pos Position) Sub(orig Position) (float64, error)
- func (pos Position) TrackItem() TrackItem
- type PreviousActiveRoute
- type Route
- func (r *Route) Activate(persistent bool) error
- func (r *Route) BeginSignal() *SignalItem
- func (r *Route) Deactivate() error
- func (r *Route) EndSignal() *SignalItem
- func (r *Route) Equals(other *Route) bool
- func (r *Route) ID() string
- func (r *Route) IsActive() bool
- func (r *Route) MarshalJSON() ([]byte, error)
- func (r *Route) State() RouteState
- func (r *Route) UnmarshalJSON(data []byte) error
- type RouteExitSignalAspects
- type RouteSet
- type RouteSetAcross
- type RouteState
- type RoutesManager
- type Service
- type ServiceAction
- type ServiceLine
- type SignalAction
- type SignalAspect
- type SignalItem
- func (si *SignalItem) ActiveAspect() *SignalAspect
- func (t *SignalItem) ActiveRoute() *Route
- func (t *SignalItem) ActiveRoutePreviousItem() TrackItem
- func (si *SignalItem) BerthOrigin() Point
- func (t *SignalItem) ConflictItem() TrackItem
- func (t *SignalItem) CustomProperty(key string) CustomProperty
- func (t *SignalItem) DistanceToTrainEnd(pos Position) (float64, bool)
- func (t *SignalItem) End() Point
- func (t *SignalItem) Equals(ti TrackItem) bool
- func (t *SignalItem) FollowingItem(precedingItem TrackItem, dir PointDirection) (TrackItem, error)
- func (t *SignalItem) ID() string
- func (t *SignalItem) IsConnected(oti TrackItem) bool
- func (si *SignalItem) IsOnPosition(pos Position) bool
- func (si *SignalItem) MarshalJSON() ([]byte, error)
- func (t *SignalItem) MaxSpeed() float64
- func (t *SignalItem) Name() string
- func (t *SignalItem) NextItem() TrackItem
- func (t *SignalItem) Origin() Point
- func (t *SignalItem) Place() *Place
- func (si *SignalItem) Position() Position
- func (t *SignalItem) PreviousItem() TrackItem
- func (t *SignalItem) RealLength() float64
- func (si *SignalItem) Reversed() bool
- func (si *SignalItem) SignalType() *SignalType
- func (t *SignalItem) Simulation() *Simulation
- func (t *SignalItem) TrackCode() string
- func (t *SignalItem) TrainPresent() bool
- func (si *SignalItem) Type() TrackItemType
- type SignalItemManager
- type SignalLibrary
- type SignalState
- type SignalType
- type SimObject
- type Simulation
- type TextItem
- func (t *TextItem) ActiveRoute() *Route
- func (t *TextItem) ActiveRoutePreviousItem() TrackItem
- func (t *TextItem) ConflictItem() TrackItem
- func (t *TextItem) CustomProperty(key string) CustomProperty
- func (t *TextItem) DistanceToTrainEnd(pos Position) (float64, bool)
- func (t *TextItem) End() Point
- func (t *TextItem) Equals(ti TrackItem) bool
- func (t *TextItem) FollowingItem(precedingItem TrackItem, dir PointDirection) (TrackItem, error)
- func (t *TextItem) ID() string
- func (t *TextItem) IsConnected(oti TrackItem) bool
- func (t *TextItem) IsOnPosition(pos Position) bool
- func (t *TextItem) MarshalJSON() ([]byte, error)
- func (t *TextItem) MaxSpeed() float64
- func (t *TextItem) Name() string
- func (t *TextItem) NextItem() TrackItem
- func (t *TextItem) Origin() Point
- func (t *TextItem) Place() *Place
- func (t *TextItem) PreviousItem() TrackItem
- func (t *TextItem) RealLength() float64
- func (t *TextItem) Simulation() *Simulation
- func (t *TextItem) TrackCode() string
- func (t *TextItem) TrainPresent() bool
- func (ti *TextItem) Type() TrackItemType
- type Time
- type TrackItem
- type TrackItemType
- type Train
- func (t *Train) ApplicableAction() SignalAction
- func (t *Train) AssignService(srv string) error
- func (t *Train) ID() string
- func (t *Train) IsActive() bool
- func (t *Train) IsShunting() bool
- func (t *Train) LastSeenSignal() *SignalItem
- func (t Train) MarshalJSON() ([]byte, error)
- func (t *Train) NextSignalPosition() Position
- func (t *Train) ProceedWithCaution() error
- func (t *Train) ResetService() error
- func (t *Train) Reverse() error
- func (t *Train) Service() *Service
- func (t *Train) TrainTail() Position
- func (t *Train) TrainType() *TrainType
- type TrainNotPresentBeforeNextSignal
- type TrainNotPresentOnItems
- type TrainNotPresentOnNextRoute
- type TrainPresentOnItems
- type TrainStatus
- type TrainType
- type TrainsManager
Constants ¶
const NoMorePlace = 9999
NoMorePlace is a large float used to represent a non existent service line index
const Version = "0.7"
Version of the software, mostly used for file format
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 ¶
var (
Logger log.Logger
)
Functions ¶
func InitializeLogger ¶
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 ¶
FromHex() parses a "css/html" hex color-string, either in the 3 "#f0c" or 6 "#ff1034" digits form.
func (*Color) MarshalJSON ¶
MarshalJSON for the Color Type
func (*Color) UnmarshalJSON ¶
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.
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 ¶
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 ¶
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 ¶
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 ¶
IsConnected returns true if this TrackItem is connected to the given TrackItem, false otherwise
func (*EndItem) IsOnPosition ¶
IsOnPosition returns true if this track item is the track item of the given position.
func (*EndItem) MarshalJSON ¶
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 ¶
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 ¶
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
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 ¶
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 ¶
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 ¶
IsConnected returns true if this TrackItem is connected to the given TrackItem, false otherwise
func (*InvisibleLinkItem) IsOnPosition ¶
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 ¶
func (i ItemInconsistentLinkError) Error() string
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 ¶
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) Equals ¶
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 ¶
IsConnected returns true if this TrackItem is connected to the given TrackItem, false otherwise
func (*LineItem) IsOnPosition ¶
IsOnPosition returns true if this track item is the track item of the given position.
func (*LineItem) MarshalJSON ¶
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.
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 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
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 ¶
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 ¶
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 ¶
IsConnected returns true if this TrackItem is connected to the given TrackItem, false otherwise
func (*Place) IsOnPosition ¶
IsOnPosition returns true if this track item is the track item of the given position.
func (*Place) MarshalJSON ¶
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 ¶
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 ¶
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 ¶
IsConnected returns true if this TrackItem is connected to the given TrackItem, false otherwise
func (*PlatformItem) IsOnPosition ¶
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 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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
Add returns the Position that is length ahead of this position. If length is negative, find the position backwards.
func (Position) IsValid ¶
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 ¶
Previous is the last Position on the previous TrackItem with regard to this Position
func (Position) PreviousItem ¶
PreviousItem of this Position
func (Position) Reversed ¶
Reversed returns the position that is at the same position but in the opposite direction.
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 ¶
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 ¶
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 ¶
Equals returns true if this Route is the same as other, that is they have the same routeID.
func (*Route) MarshalJSON ¶
MarshalJSON for the Route type
func (*Route) State ¶
func (r *Route) State() RouteState
State returns the current state of this route
func (*Route) UnmarshalJSON ¶
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) SetupTriggers ¶
func (rs RouteSet) SetupTriggers(item *SignalItem, params []string)
SetupTriggers installs needed triggers for the given SignalItem, with the given Condition.
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) MarshalJSON ¶
MarshalJSON for the Service type
func (*Service) PlannedTrainType ¶
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 ¶
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 ¶
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 ¶
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 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 ¶
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 ¶
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 ¶
IsConnected returns true if this TrackItem is connected to the given TrackItem, false otherwise
func (*TextItem) IsOnPosition ¶
IsOnPosition returns true if this track item is the track item of the given position.
func (*TextItem) MarshalJSON ¶
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 ¶
Time type for the simulation (HH:MM:SS).
Valid Time objects start on 0000-01-02.
func (Time) ID ¶
ID method exists only to comply to the SimObject interface so that Time objects can be serialized in event notifications.
func (Time) Sub ¶
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 ¶
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 ¶
AssignService assigns the given service to the train, replacing the current one
func (*Train) IsActive ¶
IsActive returns true if this train is in the area and its service is not finished.
func (*Train) IsShunting ¶
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 ¶
MarshalJSON method for the train type
func (*Train) NextSignalPosition ¶
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 ¶
ProceedWithCaution tells the train driver to proceed through the closed signal at WarningSpeed until the next signal.
func (*Train) ResetService ¶
ResetService restarts the service for the current train, as if nothing had happened.
func (*Train) Service ¶
Service returns a pointer to the Service assigned to this Train, or nil if no Service is assigned.
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
func (tnpbns TrainNotPresentBeforeNextSignal) Code() string
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) MarshalJSON ¶
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.