Reference
Mod
Observations, settings, decisions and signalling and driving contracts.
Usage context
| Module | Package | SDK source |
|---|---|---|
| Kotlin/Native | nimby | kotlin/src/nimby/Mod.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.Checkbox
import nimby.SignalType
import nimby.Occupancy
import nimby.SettingsStatus
import nimby.Observation
import nimby.Decision
import nimby.Signal
import nimby.Vehicle
import nimby.DrivingSettings
import nimby.Constraint
import nimby.DrivingInput
import nimby.DrivingPlan
import nimby.DrivingFlag
import nimby.DrivingRule
import nimby.SignallingMod
import nimby.maximumSignalNetworkSize
import nimby.prepareObservedNetwork
import nimby.evaluateNetworkUnits and unknown data
| Property / family | Unit or meaning |
|---|---|
| speedMps, reopenedSpeedMps | metres per second; km/h ÷ 3.6. |
| beginM, endM, headM, lengthM, marginM | metres. |
| …Mps2 | metres per second squared. |
| emptyMassKg, extraMassKg | kilograms. |
| tractiveEffortN / powerW | newtons / watts. |
| Observation.fresh | Freshness of received observations. |
| Occupancy.Unknown | No proof that a block is clear or occupied. |
| DrivingPlan.available | Availability of the mod's calculation, not native permission. |
Signal, Observation and DrivingSettings in nimby belong to the native mod. Types with the same names in fr.nimby.sdk belong to the JVM client: check your imports.
Checkbox
data class Checkbox(val name: String, val label: String, val description: String, val defaultValue: Boolean = false,
val onlyWhenEnabled: Boolean = false)Declares a persistent boolean setting belonging to a signal model. label and description accept tr; name remains a stable key. The checkbox affects behaviour only when rules read it.
Checkbox.name
val name: StringSaved key for each signal, scoped to its model; do not translate or rename it to change a label.
Checkbox.label
val label: StringText beside the checkbox; accepts tr to follow the game language.
Checkbox.description
val description: StringHelp shown below the checkbox, with wrapping. An empty string removes the help row; accepts tr.
Checkbox.defaultValue
val defaultValue: Boolean = falseValue used when no value is saved for this key; does not overwrite a saved choice.
Checkbox.onlyWhenEnabled
val onlyWhenEnabled: Boolean = falseShows the checkbox only while it is true. Useful for an acknowledgement warning; it disappears once unchecked.
SignalType
data class SignalType(
val id: String,
val title: String,
val textureSet: String,
val checkboxes: List<Checkbox> = emptyList(),
val observeApproach: Boolean = false,
val actions: List<SignalAction> = emptyList(),
val approachBlocks: Int = 1,
val construction: SignalConstruction? = null,
val numbers: List<NumberSetting> = emptyList()
)Public description of a constructible model: identity, catalogue, settings and actions. A mod accepts 1 to 16 types with distinct IDs and catalogues. Declare rules and images with signalModel.
SignalType.id
val id: StringStable model identifier used by Signal.type and saves. Unique within the mod; do not translate.
SignalType.title
val title: StringTitle shown in this model’s settings panel; accepts tr. The construction name is declared separately.
SignalType.textureSet
val textureSet: StringStable texture-catalogue identifier. Two models in the same mod cannot share this catalogue.
SignalType.checkboxes
val checkboxes: List<Checkbox> = emptyList()Boolean setting declarations for this type, with unique keys. Use checkbox in the builder to register options read by rules.
SignalType.observeApproach
val observeApproach: Boolean = falseRequests observation of a train oriented towards this signal. false avoids this request; true reserves no route and grants no movement permission.
SignalType.actions
val actions: List<SignalAction> = emptyList()Optional service buttons, up to 16 with distinct IDs. An action is absent if its provider or service is unavailable.
SignalType.approachBlocks
val approachBlocks: Int = 1Upstream approach-observation range, from 1 to 16 blocks. 1 means the block immediately behind the signal; used only when observeApproach=true.
SignalType.construction
val construction: SignalConstruction? = nullResources and settings used to generate the construction entry. null means no construction declaration is supplied here.
SignalType.numbers
val numbers: List<NumberSetting> = emptyList()Up to four persistent integer settings with distinct names. Declare them with number so the model also supplies their defaults.
Occupancy
enum class Occupancy {
Unknown,
Clear,
Occupied
}Physical occupancy of the observed block. Entry of the head occupies it; the rear must clear it. A known portion can prove occupancy but cannot prove the whole block clear.
Occupancy.Unknown
UnknownUndetermined occupancy: data cannot establish clear or occupied. Do not treat it as Clear.
Occupancy.Clear
ClearObserved block is physically clear. Also check fresh and routeKnown; this fact alone grants no driving permission.
Occupancy.Occupied
OccupiedPhysical presence observed in the block or its known downstream portion, even when the complete boundary remains unknown.
SettingsStatus
enum class SettingsStatus {
Unavailable,
Absent,
Present
}Describes settings-profile availability separately from its values. A declared default does not prove a valid read.
SettingsStatus.Absent
AbsentNo profile is present in the observation. SignalRuleContext applies declared defaults while preserving this readable status.
SettingsStatus.Present
PresentProfile is available. A new key may still use its default; Present does not mean every key was saved manually.
Observation
data class Observation(
val block: Occupancy = Occupancy.Unknown, val fresh: Boolean = false,
val routeKnown: Boolean = false, val forcedStop: Boolean = false,
val lampFailed: Boolean = false, val redFlashCondition: Boolean = false, val next: Int = 0,
val approachingTrain: Long? = null
)Copied values used by a rule or isolated test. Defaults represent an unknown, stale observation. Distinguish occupancy, route validity and approach observation.
Observation.block
val block: Occupancy = Occupancy.UnknownObserved physical occupancy; defaults to Unknown. A rule must handle unknown explicitly.
Observation.fresh
val fresh: Boolean = falseIndicates the observation is usable for this calculation. false cannot establish that a track is clear; this field supplies no age in milliseconds.
Observation.routeKnown
val routeKnown: Boolean = falseIndicates the observed route is known. Independent of block: partial occupancy may be known without a complete route.
Observation.forcedStop
val forcedStop: Boolean = falseBoolean stop-request input, including isolated scenarios. The mod chooses its priority in rules; this field is not itself a published driving rule.
Observation.lampFailed
val lampFailed: Boolean = falseLamp-failure input available to rules and tests. Does not imply automatic texture diagnosis or an SDK-selected aspect.
Observation.redFlashCondition
val redFlashCondition: Boolean = falseBoolean condition for the mod to interpret in an isolated calculation. Its name installs neither national signalling rules nor automatic animation.
Observation.next
val next: Int = 0Local next-aspect code in an isolated diagnostic. In a network, use the typed neighbour in rules; this number is not a signal ID.
Observation.approachingTrain
val approachingTrain: Long? = nullObserved approaching-train ID, or null. Use the context’s approachingTrain or trainApproaching to apply freshness checks.
Decision
data class Decision(val aspect: Int, val reason: Int)Opaque signal-calculation result. For independent models, use mod.indication(decision), then of(model); do not persist the codes or use them to index an enum.
Decision.aspect
val aspect: IntOpaque aspect code belonging to the mod declaration. Its raw value cannot be used to compare two models.
Decision.reason
val reason: IntOpaque reason code. Decode the mod’s indication to recover the model-specific enum.
Signal
data class Signal(
val id: Long = 0, val nextSignal: Long = 0, val settings: Map<String, Boolean> = emptyMap(),
val observation: Observation = Observation(), val settingsStatus: SettingsStatus = SettingsStatus.Present,
val type: String = ""
)Working signal value within the mod’s network. Identity, downstream link, settings and observation feed a pure rule. Defaults facilitate isolated tests, not invented in-game identities.
Signal.id
val id: Long = 0Signal ID in the game session. An evaluated network requires nonzero, unique IDs.
Signal.nextSignal
val nextSignal: Long = 0Downstream signal ID supplied by the network; zero or a missing link does not mean a clear neighbour.
Signal.settings
val settings: Map<String, Boolean> = emptyMap()Effective settings map for this signal. For an integer, use NumberSetting.read; modifying a copy persists nothing in the game.
Signal.observation
val observation: Observation = Observation()Physical and validity values for this evaluation; they do not refresh themselves.
Signal.settingsStatus
val settingsStatus: SettingsStatus = SettingsStatus.PresentProfile availability, separate from the content of settings. Rules can distinguish absence from unavailability.
Signal.type
val type: String = ""SignalType identifier supplied for this signal. An empty string selects the first type in calculation helpers; prefer an explicit type in multi-model tests.
Vehicle
data class Vehicle(
val maxSpeedMps: Double = 0.0, val maxAccelerationMps2: Double = 0.0,
val serviceBrakingMps2: Double = 0.0, val tractiveEffortN: Double = 0.0,
val powerW: Double = 0.0, val emptyMassKg: Double = 0.0,
val extraMassKg: Double = 0.0, val lengthM: Double = 0.0
)Characteristics used by a driving calculation, in SI units. Default zeroes do not prove valid measurements. This input type does not replace observed TrainMaterial data.
Vehicle.maxSpeedMps
val maxSpeedMps: Double = 0.0Rolling-stock maximum speed in metres per second; not the train’s current speed.
Vehicle.maxAccelerationMps2
val maxAccelerationMps2: Double = 0.0Maximum acceleration supplied to the calculation, in metres per second squared.
Vehicle.serviceBrakingMps2
val serviceBrakingMps2: Double = 0.0Service-braking deceleration capacity, expressed as a magnitude in m/s².
Vehicle.tractiveEffortN
val tractiveEffortN: Double = 0.0Tractive effort in newtons, separate from power and acceleration.
Vehicle.powerW
val powerW: Double = 0.0Power in watts; convert kilowatts by multiplying by 1000 before this calculation.
Vehicle.emptyMassKg
val emptyMassKg: Double = 0.0Empty mass in kilograms, excluding additional load.
Vehicle.extraMassKg
val extraMassKg: Double = 0.0Additional load in kilograms, to consider together with emptyMassKg.
Vehicle.lengthM
val lengthM: Double = 0.0Total length in metres, particularly useful for rear-clearance calculations.
DrivingSettings
data class DrivingSettings(val brakeUse: Double = 0.8, val responseSeconds: Double = 2.0, val marginM: Double = 10.0)Parameters supplied to the planning callback: braking share, response time and margin. The SDK passes them to the calculation; the callback must define and validate its policy.
DrivingSettings.brakeUse
val brakeUse: Double = 0.8Suggested service-braking fraction for the planner, dimensionless; defaults to 0.8.
DrivingSettings.responseSeconds
val responseSeconds: Double = 2.0Response time to incorporate into the calculation, in seconds; defaults to 2.
DrivingSettings.marginM
val marginM: Double = 10.0Suggested distance margin, in metres; defaults to 10.
Constraint
data class Constraint(val source: Long, val beginM: Double, val endM: Double, val speedMps: Double, val releaseByRear: Boolean = true)Speed restriction for a planning calculation. beginM and endM use the same longitudinal reference as DrivingInput.headM; this value does not publish a restriction into the game.
Constraint.source
val source: LongRestriction-source identifier, retained to explain which constraint limits the result.
Constraint.beginM
val beginM: DoubleStart of the constrained area, in metres in the calculation’s longitudinal reference.
Constraint.endM
val endM: DoubleEnd of the constrained area, in the same metre-based reference as beginM.
Constraint.speedMps
val speedMps: DoubleConstraint speed ceiling in m/s; zero represents a stop target.
Constraint.releaseByRear
val releaseByRear: Boolean = trueRequests that the planner retain the restriction until rear clearance; defaults to true.
DrivingInput
data class DrivingInput(
val headM: Double = 0.0, val speedMps: Double = 0.0, val lineSpeedMps: Double = 0.0,
val fresh: Boolean = false, val routeKnown: Boolean = false,
val onSight: Boolean = false, val visibleClearM: Double? = null
)Input situation for a driving calculation. Positions are longitudinal and speeds are in m/s; handle fresh and routeKnown before producing a usable plan.
DrivingInput.headM
val headM: Double = 0.0Longitudinal head position in metres, in the same reference as constraints.
DrivingInput.speedMps
val speedMps: Double = 0.0Current speed supplied to the calculation, in metres per second.
DrivingInput.lineSpeedMps
val lineSpeedMps: Double = 0.0Line-speed limit supplied to the calculation, in m/s, independent of the rolling-stock maximum.
DrivingInput.fresh
val fresh: Boolean = falseTemporal validity of input data; defaults to false. The callback must choose a fallback for stale data.
DrivingInput.routeKnown
val routeKnown: Boolean = falseIndicates whether the route needed for calculation is known; the default false cannot imply a clear track.
DrivingInput.onSight
val onSight: Boolean = falseIndicates an on-sight situation for calculation; grants no permission to pass a signal.
DrivingInput.visibleClearM
val visibleClearM: Double? = nullKnown physically clear distance in metres, or null when unavailable. null does not mean infinite distance.
DrivingPlan
data class DrivingPlan(
val available: Boolean = false, val speedCeilingMps: Double = 0.0,
val serviceDecelerationMps2: Double = 0.0, val accelerationMps2: Double = 0.0,
val brakingRequired: Boolean = false, val limitingSource: Long = 0
)Calculation or diagnostic result returned by plan. It does not directly command the train; in-game driving uses the DrivingRule values published for signals.
DrivingPlan.available
val available: Boolean = falsetrue only when the callback provides a usable result. Defaults to false: other zeroes are not a stop command.
DrivingPlan.speedCeilingMps
val speedCeilingMps: Double = 0.0Calculated speed ceiling in m/s, meaningful only when available=true.
DrivingPlan.serviceDecelerationMps2
val serviceDecelerationMps2: Double = 0.0Service deceleration selected by the calculation, in m/s².
DrivingPlan.accelerationMps2
val accelerationMps2: Double = 0.0Signed acceleration proposed by the calculation, in m/s²; negative for deceleration.
DrivingPlan.brakingRequired
val brakingRequired: Boolean = falseIndicates that the planner considers braking necessary; this diagnostic does not apply brakes.
DrivingPlan.limitingSource
val limitingSource: Long = 0Limiting constraint source selected by the planner; defaults to zero when none is supplied.
DrivingFlag
enum class DrivingFlag(val bit: Int) {
Clear(1),
HoldToClear(2),
Stop(4),
FollowTarget(8),
OnSight(16),
StopThenProceed(32),
CancelAtNextClear(64),
ApproachPassable(128)
}Policies composing a DrivingRule. Prefer AutomaticDriving helpers, which validate expected combinations and speeds.
DrivingFlag.bit
val bit: IntNumeric value associated with the flag. Mods use Set<DrivingFlag> and helpers; no manual mask is needed.
DrivingFlag.Clear
Clear(1)Marks Clear permission as a release point for policies that require it.
DrivingFlag.HoldToClear
HoldToClear(2)Retains a restriction until a Clear is actually passed and the rear then clears that point.
DrivingFlag.Stop
Stop(4)Requests a stop at the target point. Alone, this flag does not permit passing after stopping.
DrivingFlag.FollowTarget
FollowTarget(8)Allows following the numeric speed declared by an announcement target; does not interpret its colour.
DrivingFlag.OnSight
OnSight(16)Restricted-movement policy braking for physically clear space until the next signal.
DrivingFlag.StopThenProceed
StopThenProceed(32)Together with Stop and OnSight, requires a prior stop before explicitly permitted restricted entry.
DrivingFlag.CancelAtNextClear
CancelAtNextClear(64)Optional policy cancelling an announcement at the next Clear. The helper accepts it only with FollowTarget and a target two signals ahead.
DrivingFlag.ApproachPassable
ApproachPassable(128)Permits passing the current signal according to the remembered speed, without removing other restrictions.
DrivingRule
data class DrivingRule(
val speedMps: Double = -1.0, val reopenedSpeedMps: Double = 0.0,
val signalsAhead: Int = 0, val flags: Set<DrivingFlag> = emptySet()
)Declarative driving rule associated with an indication. Prefer AutomaticDriving to validate target, speeds and permissions. Constructing a value does not publish it.
DrivingRule.speedMps
val speedMps: Double = -1.0Target speed in m/s; zero for a stop. The default −1 means no numeric ceiling is supplied, notably for Clear.
DrivingRule.reopenedSpeedMps
val reopenedSpeedMps: Double = 0.0Replacement speed when a target reopens, or the post-entry ceiling for restricted movement; in m/s. The selected helper defines its role.
DrivingRule.signalsAhead
val signalsAhead: Int = 0Target position: 0 for this signal, 1 or 2 for a downstream signal. Helpers restrict values for each policy.
DrivingRule.flags
val flags: Set<DrivingFlag> = emptySet()Explicit set of passage, stop and release policies. An empty set grants no implicit permission.
SignallingMod
abstract class SignallingMod : GameModBase of a signalling mod. Use signalMod and signalModel to construct its implementation; calculation methods remain callable with copied values in tests.
SignallingMod.prepareNetwork
open fun prepareNetwork(signals: List<Signal>): List<Signal>Pure transformation of effective settings in the observed network. Preserve order, count, identities, links, types and observations; derived values are not saved. Returns its input list by default.
SignallingMod.textureSet
open val textureSet: String = ""Catalogue of a single-type declaration. For multiple models, use signalTypes and each SignalType’s catalogue.
SignallingMod.checkboxes
open val checkboxes: List<Checkbox>Settings of a single-type declaration. New models register their own checkboxes in signalModel.
SignallingMod.signalTypes
open val signalTypes: List<SignalType>Constructible types declared by the mod. They must have distinct identifiers and catalogues, validated before use.
SignallingMod.migrateSettings
open fun migrateSettings(type: String, saved: Map<String, Boolean>): Map<String, Boolean>Converts the keys actually saved for a type when loading its profile. The SDK fills defaults afterwards; do not invent values for absent keys here.
SignallingMod.maximumLineSpeed
open val maximumLineSpeed: Boolean = falseDriving option replacing the timetable cruising ceiling with the rolling-stock maximum. Track limits and braking targets still apply. Defaults to false; can also affect trains without this mod’s signal constraints.
SignallingMod.diagnosticFile
open val diagnosticFile: String = "nimby-kotlin-faults.jsonl"Filename for the mod’s fault diagnostics; defaults to nimby-kotlin-faults.jsonl. Does not replace action logs written with ToolContext.log.
SignallingMod.unknownDecision
abstract val unknownDecision: DecisionDefault declaration’s fallback when isolated calculation produces no indication. For a multi-model mod, request unknownDecision(type).
SignallingMod.invalidNetworkDecision
abstract val invalidNetworkDecision: DecisionDefault declaration’s fallback for a missing or cyclic link required by calculation. The overload with type selects the current model.
SignallingMod.modelLocalIndications
open val modelLocalIndications: Boolean = falseIndicates that indications retain model identity. Supplied by signalMod; authors read decisions through indication and of.
SignallingMod.unknownDecision
open fun unknownDecision(type: String): DecisionReturns the requested type’s observation fallback. Read this opaque result with indication to recover its enums.
SignallingMod.invalidNetworkDecision
open fun invalidNetworkDecision(type: String): DecisionReturns the requested model’s invalid-network fallback, notably when a downstream dependency cannot be resolved.
SignallingMod.indication
open fun indication(decision: Decision): SignalIndication?Decodes a decision produced by this mod’s independent models. null means an unrecognized code or an implementation without this reader; then use of(model).
SignallingMod.evaluate
abstract fun evaluate(settings: Map<String, Boolean>, observation: Observation): DecisionCalculates an isolated indication for the default type, without resolving a network. For multiple types, prefer the overload with type; this calculation publishes nothing in-game.
SignallingMod.evaluate
open fun evaluate(type: String, settings: Map<String, Boolean>, observation: Observation): DecisionCalculates the requested type from copied settings and observation. Uses its evaluate callback or isolated rule; does not replace evaluateNetwork for downstream dependencies.
SignallingMod.decide
abstract fun decide(signal: Signal, next: Decision?): Decision?Pure resolution step: next=null on the first call. Returning a decision concludes locally; returning null requests neighbour resolution. A second null uses the invalid-network fallback.
SignallingMod.fromLive
open fun fromLive(signal: Signal): SignalPrepares an observed value through the type’s prepareObservation callback. Defaults to identity; this transformation does not change the signal in the game.
SignallingMod.texture
abstract fun texture(decision: Decision, simulationMs: Long, halfPeriodMs: Long): StringSelects a declared image path from the indication, simulation time and half-period in milliseconds. For ordinary animation, prefer appearance with steady or blink.
SignallingMod.animation
open fun animation(decision: Decision): SignalAnimation?Returns the appearance description declared through appearance. null retains selection through texture; the description changes no driving rule.
SignallingMod.forcedDecision
open fun forcedDecision(aspect: Int): Decision?Requests a permitted test indication for the default type. The code is a local ordinal; null rejects forcing, notably without allowForcedAspect.
SignallingMod.forcedDecision
open fun forcedDecision(type: String, aspect: Int): Decision?Asks the selected model to permit a test aspect. The callback also selects the reason; null rejects it. Do not use a raw Decision.aspect code.
SignallingMod.drivingRule
abstract fun drivingRule(decision: Decision): DrivingRule?Reads the driving rule explicitly selected by the model for this decision. null means no rule is supplied; no speed is inferred from the image.
SignallingMod.isFault
abstract fun isFault(decision: Decision): BooleanClassifies the decision as a fault using the mod’s faults callback. This diagnostic classification does not automatically select an image or driving rule.
SignallingMod.isActive
open fun isActive(decision: Decision): BooleanIndicates whether the mod actively manages this indication according to activeWhen; defaults to true. Describes model activity, not physical occupancy.
SignallingMod.aspectName
open fun aspectName(aspect: Int): StringDiagnostic label for an aspect belonging to this mod. With independent models, use the encoded result value without inventing a global ordinal.
SignallingMod.reasonName
abstract fun reasonName(reason: Int): StringDiagnostic reason label selected by reasonNames. The reason explains the decision; it is not a movement permission.
SignallingMod.plan
open fun plan(vehicle: Vehicle, settings: DrivingSettings, input: DrivingInput, constraints: List<Constraint>): DrivingPlanRuns the drivingPlan callback on copied values. Without a callback, returns an unavailable DrivingPlan. The result is advisory and does not control the train.
maximumSignalNetworkSize
const val maximumSignalNetworkSize: Int = 4096Limit of 4096 signals per Kotlin resolver call. Larger lists are rejected; this is not a maximum-map-size promise.
prepareObservedNetwork
fun SignallingMod.prepareObservedNetwork(input: List<Signal>): List<Signal>Validates the list’s size, types and identities, then checks that prepareNetwork preserves links and observations. Preparation may derive effective settings. Missing or cyclic links are handled afterwards by evaluateNetwork.
evaluateNetwork
fun SignallingMod.evaluateNetwork(input: List<Signal>): List<Decision>Resolves decisions in input-list order after validated preparation. Local decisions finish immediately; missing or cyclic dependencies use invalidNetwork. A pure function suitable for tests.