The train manager manages all the train in the game. LuaTrainManager allows to perform some direct queries to the train manager.
There is always exactly one train manager instance in a game, it can be obtained from LuaGameScript::train_manager. This object is always valid and is equal to any other instance of LuaTrainManager from this game.
booleanunknownfalseIs this object valid? This Lua object holds a reference to an object within the game engine. It is possible that the game-engine object is removed whilst a mod still holds the corresponding Lua object. If that happens, the object becomes invalid, i.e. this attribute will be false. Mods are advised to check for object validity if any change to the game state might have occurred between the creation of the Lua object and its access.
stringunknownfalseThe class name of this object. Available even when valid is false. For LuaStruct objects it may also be suffixed with a dotted path to a member of the struct.
LuaTrainManager.get_train_by_id(train_id: uint32) -> LuaTrain?
trainManager.get_train_by_id(train_id)
takes_table: falsetable_optional: falseSearches for a train with given ID.
train_id: uint32 — Train ID to searchLuaTrain? — Train if foundLuaTrainManager.get_trains(filter: TrainFilter) -> Array<LuaTrain>
trainManager.get_trains(filter)
takes_table: falsetable_optional: falseGets all trains that pass given filter
filter: TrainFilter — Filters the train must pass in order to be returned hereArray<LuaTrain>LuaTrainManager.get_train_stops(filter: TrainStopFilter) -> Array<LuaEntity>
trainManager.get_train_stops(filter)
takes_table: falsetable_optional: falseGets all train stops that pass given filter
filter: TrainStopFilter — Filters the train stop must pass in order to be returned hereArray<LuaEntity>LuaTrainManager.request_train_path{ type?: TrainPathRequestType, train?: LuaTrain, goals: Array<TrainPathFinderGoal>, return_path?: boolean, starts?: Array<RailEndStart>, search_direction?: "respect-movement-direction" | "any-direction-with-locomotives", in_chain_signal_section?: boolean, steps_limit?: uint32, shortest_path?: boolean } -> TrainPathFinderOneGoalResult | TrainPathAllGoalsResult
trainManager.request_train_path{ goals=goals }
takes_table: truetable_optional: falseDirect access to train pathfinder. Allows to search rail paths or querying which stops are accessible
type?: TrainPathRequestType — Request type. Determines the return type of the method. Defaults to "path".train?: LuaTrain — Mandatory if starts is not provided, optional otherwise. Selects a context for the pathfinder to decide which train to exclude from penalties and which signals are considered possible to reacquire. If starts is not provided, then it is also used to collect front and back ends for the searchgoals: Array<TrainPathFinderGoal>return_path?: boolean — Only relevant if request type is "path". Returning a full path is expensive due to multiple LuaEntity created. In order for path to be returned, true must be provided here. Defaults to false in which case a path will not be provided.starts?: Array<RailEndStart> — Manually provided starting positions.search_direction?: "respect-movement-direction" | "any-direction-with-locomotives" — Only relevant if starts was not provided in which case 2 starts (front and back) are deduced from the train. Selects which train ends should be considered as starts. Defaults to "any-direction-with-locomotives".in_chain_signal_section?: boolean — Defaults to false. If set to true, pathfinder will not return a path that cannot have its start immediately reserved. A path that cannot have its start immediately reserved could cause a train to stop inside of an intersection.steps_limit?: uint32 — Maximum amount of steps pathfinder is allowed to perform.shortest_path?: boolean — Defaults to false. If set to true, only length of rails is added to penalties causing search to look for shortest path (not smallest penalty)TrainPathFinderOneGoalResult | TrainPathAllGoalsResult — The type of the returned value depends on type.