Reference
TrainObservation
Copied trains, services, lines and stops available in callbacks.
Usage context
| Module | Package | SDK source |
|---|---|---|
| Kotlin/Native | nimby | kotlin/src/nimby/TrainObservation.kt |
Public API for SDK 0.9.0-alpha.2. Each entry provides the Kotlin signature and its contract: what the value means, conditions of use and effects to understand. Choose imports from the module shown above.
import nimby.GameInstant
import nimby.TrainState
import nimby.TrainAlert
import nimby.Station
import nimby.Line
import nimby.TrainPosition
import nimby.TrainAssignment
import nimby.TrainServiceTimes
import nimby.TrainService
import nimby.Train
import nimby.TrainSnapshot
import nimby.Stop
import nimby.LinePlanChoose a read and interpret its results
In a mod, use ToolContext.trains(query). In a JVM application, use game.trains.snapshot(query = query); selecting a train also requests its line plan. One query batches all trains: do not create a snapshot per train. Clock reads and targeted single-train reads are separate.
| TrainQuery option | Default | Requested data |
|---|---|---|
| includeService | true | Observed state, service and assignment. |
| includeLocations | true | Positions and required location references. |
| includeCharacteristics | false | Configured and current material profiles. |
| includeTimetables | false | Available timetable information; implies includeService. |
| includeTags | false | Declared tags and inheritance references; implies includeLines. |
| includePassengers | false | Observed occupants, distinct from capacity. |
| includeLines | false | Line catalog, including lines with no assigned train. |
| includeComposition | false | Ordered vehicles of configured and current compositions and referenced models. |
| Value | Unit and contract |
|---|---|
| Train.speedMps / Train.speedKmh | Current speed. Native: an unavailable measurement remains null. JVM: also check speedDefaulted before treating a fallback value as a measurement. |
| maximumSpeedMps / maximumSpeedKmh | Material maximum speed, in m/s or km/h; distinct from current speed and the track speed limit. |
| lengthM / emptyMassKg / maximumAccelerationMps2 | Metres, kilograms, metres per second squared. |
| powerW / tractiveForceN | Watts and newtons. |
| passengers / passengerCapacity / carCount | Occupants, capacity and vehicle count: three distinct quantities. |
| configured / current / composition | Independent profiles, without filling missing values from one another. Null composition: unknown or unrequested; empty list: observed empty composition. |
| predictedArrivalDelayUs / predictedArrivalDelaySeconds | Signed estimate in microseconds or seconds; negative for predicted early arrival. Neither deadline age nor priority. |
| arrivalOffsetSeconds / departureOffsetSeconds | Validated offsets in seconds from the line-plan origin. Do not convert them into a train’s absolute date. |
| arrivalTimeUs / departureTimeUs / dispatchRetryTimeUs | Microseconds from the simulation origin, not 1970. Use calendar helpers; dates remain null when the origin is unknown. |
| capturedAtMillis / ageMillis | Computer UTC time / monotonic age when copying; distinct from the game calendar. |
Typed identifiers are opaque. TimetableShiftId is unique only together with its TimetableId. LineType distinguishes only Depot and Other; no passenger/freight category is inferred. An unavailable timetable name remains null. Tags are labels without automatic priority; incomplete or cyclic inheritance remains unknown. VehicleModel.nameEnglish retains the English catalog name.
TrainVehicle describes a vehicle within a composition. The nimby.Vehicle type used in driving calculations is a different contract. Do not mix identically named classes from nimby and fr.nimby.sdk.
GameInstant
data class GameInstant(val utcSeconds: Long, val microsecond: Int = 0)UTC instant in the game calendar, at microsecond precision. Years 1 through 9999; microsecond ranges from 0 to 999999. Conversions do not read the game.
GameInstant.utcSeconds
val utcSeconds: LongUTC seconds since 1970 in the game calendar; may be negative.
GameInstant.microsecond
val microsecond: Int = 0Fraction of the second between 0 and 999999.
GameInstant.dateTime
fun dateTime(): GameDateTimeConverts seconds into game UTC date/time; the microsecond fraction is not part of the returned GameDateTime.
TrainState
enum class TrainState {
Unknown,
Driving,
StationStop,
TimedStop,
Depot,
DispatchWait,
SignalWait,
Mothballed,
NotPresent,
Other
}Observed service state. null means unavailable; Unknown and Other are observed results, not missing data.
TrainState.Unknown
UnknownThe game reports an undetermined state.
TrainState.Driving
DrivingReported driving state; does not prove strictly positive speed.
TrainState.StationStop
StationStopReported station stop.
TrainState.TimedStop
TimedStopReported timed stop.
TrainState.Depot
DepotReported depot state.
TrainState.DispatchWait
DispatchWaitReported dispatch wait.
TrainState.SignalWait
SignalWaitReported signal wait; this field alone does not describe the signal rule.
TrainState.Mothballed
MothballedTrain mothballed according to the reported state.
TrainState.NotPresent
NotPresentTrain reported as not present; distinct from an object missing from the snapshot.
TrainState.Other
OtherObserved state not represented by another known enum value.
TrainAlert
enum class TrainAlert {
None,
LineClosed,
NoPath,
InvalidOrders,
Collision,
SignalWait,
ScheduleClosed,
DispatchTracksOccupied,
NoServices,
ServicesAlreadyAssigned,
Other
}Observed train alert. null means unavailable; None means no reported alert. An alert is not a priority.
TrainAlert.None
NoneNo reported alert.
TrainAlert.LineClosed
LineClosedReported closed line.
TrainAlert.NoPath
NoPathReported missing path.
TrainAlert.InvalidOrders
InvalidOrdersReported invalid orders.
TrainAlert.Collision
CollisionCollision reported by the game.
TrainAlert.SignalWait
SignalWaitSignal-wait alert.
TrainAlert.ScheduleClosed
ScheduleClosedReported closed schedule.
TrainAlert.DispatchTracksOccupied
DispatchTracksOccupiedDispatch tracks occupied according to the game.
TrainAlert.NoServices
NoServicesNo services available according to the game.
TrainAlert.ServicesAlreadyAssigned
ServicesAlreadyAssignedServices already assigned according to the game.
TrainAlert.Other
OtherOther observed alert code, not represented by known values.
Station
data class Station(val id: Long, val name: String?)Station joined into a train or line-plan observation. A missing name does not prove the station does not exist.
Station.id
val id: LongOpaque value to compare and pass unchanged; do not decode it or reuse it in another game.
Station.name
val name: String?Observed name; null when unavailable.
Station.stationId
val stationId: StationIdThe same identity as a StationId.
Line
data class Line(val id: Long, val name: String?, val isDepot: Boolean?, val parentLineId: LineId? = null,
val parentInformationAvailable: Boolean = false, val declaredTags: List<Tag>? = null)Line observed in a service or catalogue. Parent and tag information is available only when requested and validated.
Line.id
val id: LongOpaque value to compare and pass unchanged; do not decode it or reuse it in another game.
Line.name
val name: String?Observed line name; null when unavailable.
Line.isDepot
val isDepot: Boolean?true: depot; false: another observed type; null: unknown classification.
Line.parentLineId
val parentLineId: LineId? = nullParent identity; interpret null together with parentInformationAvailable.
Line.lineId
val lineId: LineIdThe same identity as a LineId.
Line.type
val type: LineType?Classification derived from isDepot: Depot, Other or null.
TrainPosition
data class TrainPosition(val trackId: Long, val fraction: Double, val direction: Int?, val station: Station?)Copied train position on a track. The fraction describes longitudinal position, not a distance in metres or a reservation.
TrainPosition.trackId
val trackId: LongOpaque value to compare and pass unchanged; do not decode it or reuse it in another game.
TrainPosition.fraction
val fraction: DoublePosition between 0 and 1 relative to the track origin.
TrainPosition.direction
val direction: Int?+1 from A to B, -1 from B to A; null when unknown.
TrainPosition.station
val station: Station?Station joined to the position track; null when no usable join exists.
TrainPosition.track
val track: TrackIdTrack identity as a TrackId.
TrainAssignment
data class TrainAssignment(val scheduleId: Long?, val shiftId: Long?, val orderIndex: Int?)Observed train assignment to a timetable, shift and order. Does not announce a calculated next passing time.
TrainAssignment.scheduleId
val scheduleId: Long?Opaque assigned timetable identity; null when unavailable.
TrainAssignment.shiftId
val shiftId: Long?Shift key within scheduleId; do not compare it alone across timetables.
TrainAssignment.orderIndex
val orderIndex: Int?Observed zero-based order index; null when unavailable.
TrainAssignment.timetable
val timetable: Timetable?Timetable built from scheduleId, with identity only; null if scheduleId is missing.
TrainAssignment.shift
val shift: TimetableShiftId?Composite identity available only when timetable and shift key are known.
TrainServiceTimes
data class TrainServiceTimes(
val gameEpochSeconds: Long?, val gameTimeUs: Long?,
val arrivalTimeUs: Long?, val departureTimeUs: Long?, val dispatchRetryTimeUs: Long?,
val arrivalRemainingSeconds: Double?, val departureRemainingSeconds: Double?, val dispatchRetryRemainingSeconds: Double?,
)Observed active deadlines and remaining times. A duration can be available without a calendar origin. Conversions preserve null; no future date is extrapolated.
TrainServiceTimes.gameEpochSeconds
val gameEpochSeconds: Long?UTC simulation-calendar origin in seconds since 1970; null when unknown.
TrainServiceTimes.gameTimeUs
val gameTimeUs: Long?Observed counter in microseconds from the simulation origin; not a Unix date.
TrainServiceTimes.arrivalTimeUs
val arrivalTimeUs: Long?Optional active arrival deadline in microseconds from the simulation origin.
TrainServiceTimes.departureTimeUs
val departureTimeUs: Long?Optional active departure deadline in microseconds from the simulation origin.
TrainServiceTimes.dispatchRetryTimeUs
val dispatchRetryTimeUs: Long?Dispatch-retry deadline in microseconds from the simulation origin.
TrainServiceTimes.arrivalRemainingSeconds
val arrivalRemainingSeconds: Double?Seconds remaining to the arrival deadline; may be negative. Not predicted commercial delay.
TrainServiceTimes.departureRemainingSeconds
val departureRemainingSeconds: Double?Seconds remaining to the departure deadline, clamped to zero; null when unknown.
TrainServiceTimes.dispatchRetryRemainingSeconds
val dispatchRetryRemainingSeconds: Double?Seconds remaining before a dispatch retry, clamped to zero; null when unknown.
TrainServiceTimes.observedAt
val observedAt: GameInstant?Observed counter converted to the game UTC calendar; null if origin/counter is missing or conversion is out of range.
TrainServiceTimes.arrival
val arrival: GameInstant?UTC date of the active arrival deadline. null if conversion is impossible; not necessarily the commercial timetable.
TrainServiceTimes.departure
val departure: GameInstant?UTC date of the active departure deadline. null if conversion is impossible; not necessarily the commercial timetable.
TrainServiceTimes.dispatchRetry
val dispatchRetry: GameInstant?UTC dispatch-retry date; not a commercial departure time. null when not convertible.
TrainService
data class TrainService(
val state: TrainState?, val alert: TrainAlert?, val hidden: Boolean?, val onNetwork: Boolean?,
val locationTrackId: Long?, val locationStation: TrainStation?, val line: TrainLine?,
val stopTrackId: Long?, val stopStation: TrainStation?, val stopIndex: Int?, val times: TrainServiceTimes,
)Observed train service, with independently optional state, locations and deadlines. Position station, service location and target stop are not interchangeable.
TrainService.state
val state: TrainState?Service state; null means unavailable, unlike TrainState.Unknown.
TrainService.alert
val alert: TrainAlert?Optional observed alert; None is an observation without an alert.
TrainService.onNetwork
val onNetwork: Boolean?Reported network presence; null when unknown. Does not prove movement permission.
TrainService.locationTrackId
val locationTrackId: Long?Track of the observed service location; may differ from the position track.
TrainService.locationStation
val locationStation: TrainStation?Station of the observed service location; a missing join does not prove no station exists.
TrainService.line
val line: TrainLine?Service line; null when unavailable.
TrainService.stopTrackId
val stopTrackId: Long?Track of the currently targeted stop; null when unknown.
TrainService.stopStation
val stopStation: TrainStation?Station of the target stop, when resolved.
TrainService.stopIndex
val stopIndex: Int?Zero-based current stop index in the line; null when unknown.
TrainService.times
val times: TrainServiceTimesService deadlines; each value retains its own availability.
Train
data class Train(
val id: Long, val name: String, val position: TrainPosition?, val speedMps: Double?,
val speedDefaulted: Boolean, val passengers: Int?, val assignment: TrainAssignment?, val service: TrainService?,
val declaredTags: List<Tag>? = null, val predictedArrivalDelayUs: Long? = null,
val configured: TrainCharacteristics? = null, val current: TrainCharacteristics? = null,
)Copied train record. TrainQuery groups determine optional data; unknown values remain null, without implicit reads.
Train.id
val id: LongOpaque value to compare and pass unchanged; do not decode it or reuse it in another game.
Train.name
val name: StringTrain name in this observation; does not replace its identity.
Train.position
val position: TrainPosition?Copied position when observable; null when absent or unavailable.
Train.speedMps
val speedMps: Double?Measured speed in metres per second; null when unknown or replaced with a fallback.
Train.speedDefaulted
val speedDefaulted: BooleanIndicates a fallback game speed. Measured speed remains unknown in this case; it does not prove a stop.
Train.passengers
val passengers: Int?Observed occupants, only when requested; null does not mean zero.
Train.assignment
val assignment: TrainAssignment?Observed assignment; null when unavailable or unrequested.
Train.service
val service: TrainService?Observed service, possibly partial: a location read can supply presence and places without service state. Callback options may also have accumulated. null indicates that no usable part was supplied.
Train.predictedArrivalDelayUs
val predictedArrivalDelayUs: Long? = nullGame-estimated arrival delay in signed microseconds; negative means predicted early arrival. null when unknown. Neither a deadline’s age nor a priority.
Train.configured
val configured: TrainCharacteristics? = nullExplicitly requested configured/purchased train profile. Independent of current material: its values do not replace missing current values.
Train.current
val current: TrainCharacteristics? = nullCharacteristics of the current composition, when observable and requested. Do not substitute the configured profile.
Train.trainId
val trainId: TrainIdThe same identity as a TrainId.
Train.speedKmh
val speedKmh: Double?Measured speed converted to km/h; null remains null.
Train.predictedArrivalDelaySeconds
val predictedArrivalDelaySeconds: Double?The same arrival estimate converted from microseconds to seconds; preserves its sign and null.
TrainSnapshot
class TrainSnapshotTrain copy obtained from ToolContext.trains. Retainable after the callback; lookups read only this copy. Data is validated separately without freezing a simulation tick.
TrainSnapshot.worldId
val worldId: StringObserved world identity; retain it with its generation to identify the scope of the data.
TrainSnapshot.generation
val generation: LongObserved game generation. Invalidate derived data when it changes, even when reloading the same save.
TrainSnapshot.capturedAtMillis
val capturedAtMillis: LongComputer UTC timestamp in milliseconds since 1970. It does not measure simulation time.
TrainSnapshot.ageMillis
val ageMillis: LongMonotonic snapshot age when copied, in milliseconds; does not update afterwards.
TrainSnapshot.clock
val clock: ToolClock?Observed simulation clock; null when unavailable.
TrainSnapshot.trains
val trains: List<TrainObservation>Trains copied according to the query; optional fields reflect requested groups.
TrainSnapshot.vehicleModels
val vehicleModels: List<VehicleModel>? = nullModels referenced by requested compositions; null when unrequested or unavailable.
TrainSnapshot.get
operator fun get(id: Long): TrainObservation?Indexed lookup in copied trains; null if the identity is absent. No new observation.
TrainSnapshot.get
operator fun get(id: TrainId): Train?The same local lookup with a typed identity; null when absent from this snapshot.
TrainSnapshot.lines
val lines: List<Line>?Requested line catalogue, including lines without assigned trains; null when unknown or unrequested.
TrainSnapshot.line
fun line(id: LineId): Line?Line from the copied catalogue; null when absent, unavailable or unrequested.
TrainSnapshot.tag
fun tag(id: TagId): Tag?Tag from the copied catalogue; null when absent, unavailable or unrequested.
Stop
data class Stop(val index: Int, val trackId: Long, val station: Station?,
val arrivalOffsetSeconds: Int?, val departureOffsetSeconds: Int?)Stop or waypoint in a line plan. May be outside a station; offsets remain relative to the plan.
Stop.index
val index: IntZero-based stop index in the line plan.
Stop.trackId
val trackId: LongOpaque value to compare and pass unchanged; do not decode it or reuse it in another game.
Stop.station
val station: Station?Joined station, when available; a waypoint can be outside stations.
Stop.arrivalOffsetSeconds
val arrivalOffsetSeconds: Int?Arrival offset in seconds from the plan origin; null when unknown. Not an absolute train date.
Stop.departureOffsetSeconds
val departureOffsetSeconds: Int?Departure offset in seconds from the plan origin; null when unknown.
Stop.track
val track: TrackIdTyped identity of the stop track.
Stop.plannedDwellSeconds
val plannedDwellSeconds: Long?departureOffsetSeconds minus arrivalOffsetSeconds, in seconds; null if either offset is missing.
LinePlan
data class LinePlan(val trainId: Long, val line: Line, val stops: List<Stop>,
val worldId: String, val generation: Long, val capturedAtMillis: Long)Complete plan of the line associated with the train in this snapshot, obtained from ToolContext.linePlan. May contain stops outside the train’s partial run.
LinePlan.trainId
val trainId: LongOpaque value to compare and pass unchanged; do not decode it or reuse it in another game.
LinePlan.line
val line: LineObserved line associated with the train.
LinePlan.stops
val stops: List<Stop>Stops in the full plan, in order; do not convert them directly into the train’s next passing times.
LinePlan.worldId
val worldId: StringObserved world identity; retain it with its generation to identify the scope of the data.
LinePlan.generation
val generation: LongObserved game generation. Invalidate derived data when it changes, even when reloading the same save.
LinePlan.capturedAtMillis
val capturedAtMillis: LongComputer UTC timestamp in milliseconds since 1970. It does not measure simulation time.
LinePlan.train
val train: TrainIdTyped identity of the train used to request this plan.