Skip to main content

LuaTrain

Struct LuaTrain 

Source
pub struct LuaTrain;
Expand description

A train. Trains are a sequence of connected rolling stocks – locomotives and wagons.

Implementations§

Source§

impl LuaTrain

Source

pub fn back_end(&self) -> LuaRailEnd

Back end of the train: Rail and direction on that rail where the train will go when moving backward

Source

pub fn back_stock(&self) -> LuaEntity

The back stock of this train, if any. The back of the train is at the opposite end of the front.

Source

pub fn cargo_wagons(&self) -> Vec<LuaEntity>

The cargo carriages the train contains.

Source

pub fn carriages(&self) -> Vec<LuaEntity>

The rolling stocks this train is composed of, with the numbering starting at the front of the train.

Source

pub fn fluid_wagons(&self) -> Vec<LuaEntity>

The fluid carriages the train contains.

Source

pub fn front_end(&self) -> LuaRailEnd

Front end of the train: Rail and direction on that rail where the train will go when moving forward

Source

pub fn front_stock(&self) -> LuaEntity

The front stock of this train, if any. The front of the train is in the direction that a majority of locomotives are pointing in. If it’s a tie, the North and West directions take precedence.

Source

pub fn group(&self) -> &str

The group this train belongs to.

Setting the group will apply the schedule of the group to this train.

Source

pub fn has_path(&self) -> bool

If this train has a path.

Source

pub fn id(&self) -> u32

The unique train ID.

Source

pub fn kill_count(&self) -> u32

The total number of kills by this train.

Source

pub fn killed_players(&self) -> LuaAny

The players killed by this train.

The keys are the player indices, the values are how often this train killed that player.

Source

pub fn locomotives(&self) -> LuaTrainLocomotives

Locomotives of the train.

Source

pub fn manual_mode(&self) -> bool

When true, the train is explicitly controlled by the player or script. When false, the train moves autonomously according to its schedule.

Source

pub fn max_backward_speed(&self) -> f64

Current max speed when moving backwards, depends on locomotive prototype and fuel.

Source

pub fn max_forward_speed(&self) -> f64

Current max speed when moving forward, depends on locomotive prototype and fuel.

Source

pub fn object_name(&self) -> &str

The 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.

Source

pub fn passengers(&self) -> Vec<LuaPlayer>

The player passengers on the train

This does not index using player index. See LuaPlayer::index on each player instance for the player index.

Source

pub fn path(&self) -> LuaRailPath

The path this train is using, if any.

Source

pub fn path_end_rail(&self) -> LuaEntity

The destination rail this train is currently pathing to, if any.

Source

pub fn path_end_stop(&self) -> LuaEntity

The destination train stop this train is currently pathing to, if any.

Source

pub fn riding_state(&self) -> RidingState

The riding state of this train.

Source

pub fn schedule(&self) -> TrainSchedule

This train’s current schedule, if any. Set to nil to clear.

The schedule can’t be changed by modifying the returned table. Instead, changes must be made by assigning a new table to this attribute.

This is a simplified schedule that does not include train groups and interrupts. See LuaTrain::get_schedule for full access to the train schedule, including interrupts and train groups.

Source

pub fn signal(&self) -> LuaEntity

The signal this train is arriving or waiting at, if any.

Source

pub fn speed(&self) -> f64

Current speed.

Changing the speed of the train is potentially an unsafe operation because train uses the speed for its internal calculations of break distances, etc.

Source

pub fn state(&self) -> &str

This train’s current state.

Source

pub fn station(&self) -> LuaEntity

The train stop this train is stopped at, if any.

Source

pub fn valid(&self) -> bool

Is 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.

Source

pub fn weight(&self) -> f64

The weight of this train.

Source

pub fn clear_fluids_inside(&self)

Clears all fluids in this train.

Source

pub fn clear_items_inside(&self)

Clear all items in this train.

Source

pub fn get_contents(&self) -> Vec<ItemWithQualityCount>

Get a mapping of the train’s inventory.

Source

pub fn get_fluid_contents(&self) -> HashMap<String, LuaAny>

Gets a mapping of the train’s fluid inventory.

Source

pub fn get_fluid_count(&self, fluid: Option<&str>) -> f64

Get the amount of a particular fluid stored in the train.

Source

pub fn get_item_count(&self, item: Option<ItemFilter>) -> u32

Get the amount of a particular item stored in the train.

Source

pub fn get_rail_end(&self, direction: &str) -> LuaRailEnd

Gets a LuaRailEnd object pointing away from the train at specified end of the train

Source

pub fn get_rails(&self) -> Vec<LuaEntity>

Gets all rails under the train.

Source

pub fn get_schedule(&self) -> LuaSchedule

This allows full access to the train schedule, including modifying the schedule records, the train group and the interrupts.

Source

pub fn go_to_station(&self, index: u32)

Go to the station specified by the index in the train’s schedule.

Source

pub fn insert(&self, stack: LuaAny)

Insert a stack into the train.

Source

pub fn insert_fluid(&self, fluid: Fluid) -> f64

Inserts the given fluid into the first available location in this train.

Source

pub fn recalculate_path(&self, force: Option<bool>) -> bool

Checks if the path is invalid and tries to re-path if it isn’t.

Source

pub fn remove_fluid(&self, fluid: Fluid) -> f64

Remove some fluid from the train.

Source

pub fn remove_item(&self, stack: LuaAny) -> u32

Remove some items from the train.

Trait Implementations§

Source§

impl Clone for LuaTrain

Source§

fn clone(&self) -> LuaTrain

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for LuaTrain

Source§

impl Debug for LuaTrain

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for LuaTrain

Source§

fn default() -> LuaTrain

Returns the “default value” for a type. Read more
Source§

impl Eq for LuaTrain

Source§

impl From<LuaTrain> for LuaAny

Source§

fn from(_: LuaTrain) -> Self

Converts to this type from the input type.
Source§

impl LuaObject for LuaTrain

Source§

impl PartialEq for LuaTrain

Source§

fn eq(&self, other: &LuaTrain) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for LuaTrain

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.