OpenTTD GameScript API  20241118-master-gb8f3d0dd68
Static Public Member Functions
GSEngine Class Reference

Class that handles all engine related functions. More...

Inheritance diagram for GSEngine:

Static Public Member Functions

static bool IsValidEngine (EngineID engine_id)
 Checks whether the given engine type is valid. More...
 
static bool IsBuildable (EngineID engine_id)
 Checks whether the given engine type is buildable for a company. More...
 
static string GetName (EngineID engine_id)
 Get the name of an engine. More...
 
static CargoID GetCargoType (EngineID engine_id)
 Get the cargo-type of an engine. More...
 
static bool CanRefitCargo (EngineID engine_id, CargoID cargo_id)
 Check if the cargo of an engine can be refitted to your requested. More...
 
static bool CanPullCargo (EngineID engine_id, CargoID cargo_id)
 Check if the engine can pull a wagon with the given cargo. More...
 
static int GetCapacity (EngineID engine_id)
 Get the capacity of an engine. More...
 
static int GetReliability (EngineID engine_id)
 Get the reliability of an engine. More...
 
static int GetMaxSpeed (EngineID engine_id)
 Get the maximum speed of an engine. More...
 
static Money GetPrice (EngineID engine_id)
 Get the new cost of an engine. More...
 
static int GetMaxAge (EngineID engine_id)
 Get the maximum age of a brand new engine. More...
 
static Money GetRunningCost (EngineID engine_id)
 Get the running cost of an engine. More...
 
static int GetPower (EngineID engine_id)
 Get the power of an engine. More...
 
static int GetWeight (EngineID engine_id)
 Get the weight of an engine. More...
 
static int GetMaxTractiveEffort (EngineID engine_id)
 Get the maximum tractive effort of an engine. More...
 
static GSDate::Date GetDesignDate (EngineID engine_id)
 Get the calendar-date this engine was designed. More...
 
static GSVehicle::VehicleType GetVehicleType (EngineID engine_id)
 Get the type of an engine. More...
 
static bool IsWagon (EngineID engine_id)
 Check if an engine is a wagon. More...
 
static bool CanRunOnRail (EngineID engine_id, GSRail::RailType track_rail_type)
 Check if a train vehicle can run on a RailType. More...
 
static bool HasPowerOnRail (EngineID engine_id, GSRail::RailType track_rail_type)
 Check if a train engine has power on a RailType. More...
 
static bool CanRunOnRoad (EngineID engine_id, GSRoad::RoadType road_type)
 Check if a road vehicle can run on a RoadType. More...
 
static bool HasPowerOnRoad (EngineID engine_id, GSRoad::RoadType road_type)
 Check if a road vehicle has power on a RoadType. More...
 
static GSRoad::RoadType GetRoadType (EngineID engine_id)
 Get the RoadType of the engine. More...
 
static GSRail::RailType GetRailType (EngineID engine_id)
 Get the RailType of the engine. More...
 
static bool IsArticulated (EngineID engine_id)
 Check if the engine is articulated. More...
 
static GSAirport::PlaneType GetPlaneType (EngineID engine_id)
 Get the PlaneType of the engine. More...
 
static int GetMaximumOrderDistance (EngineID engine_id)
 Get the maximum allowed distance between two orders for an engine. More...
 
static bool EnableForCompany (EngineID engine_id, GSCompany::CompanyID company_id)
 Allows a company to use an engine before its intro date or after retirement. More...
 
static bool DisableForCompany (EngineID engine_id, GSCompany::CompanyID company_id)
 Forbids a company to use an engine before its natural retirement. More...
 

Detailed Description

Class that handles all engine related functions.

Member Function Documentation

◆ CanPullCargo()

static bool GSEngine::CanPullCargo ( EngineID  engine_id,
CargoID  cargo_id 
)
static

Check if the engine can pull a wagon with the given cargo.

Parameters
engine_idThe engine to check.
cargo_idThe cargo to check.
Precondition
IsValidEngine(engine_id).
GetVehicleType(engine_id) == GSVehicle::VT_RAIL.
GSCargo::IsValidCargo(cargo_id).
Returns
True if the engine can pull wagons carrying this cargo.
Note
This function is not exhaustive; a true here does not mean that the vehicle can pull the wagons, a false does mean it can't.

◆ CanRefitCargo()

static bool GSEngine::CanRefitCargo ( EngineID  engine_id,
CargoID  cargo_id 
)
static

Check if the cargo of an engine can be refitted to your requested.

If the engine already allows this cargo, the function also returns true. In case of articulated vehicles the function decides whether at least one part can carry the cargo.

Parameters
engine_idThe engine to check for refitting.
cargo_idThe cargo to check for refitting.
Precondition
IsValidEngine(engine_id).
GSCargo::IsValidCargo(cargo_id).
Returns
True if the engine can carry this cargo, either via refit, or by default.

◆ CanRunOnRail()

static bool GSEngine::CanRunOnRail ( EngineID  engine_id,
GSRail::RailType  track_rail_type 
)
static

Check if a train vehicle can run on a RailType.

Parameters
engine_idThe engine to check.
track_rail_typeThe type you want to check.
Precondition
IsValidEngine(engine_id).
GetVehicleType(engine_id) == GSVehicle::VT_RAIL.
GSRail::IsRailTypeAvailable(track_rail_type).
Returns
Whether an engine of type 'engine_id' can run on 'track_rail_type'.
Note
Even if a train can run on a RailType that doesn't mean that it'll be able to power the train. Use HasPowerOnRail for that.

◆ CanRunOnRoad()

static bool GSEngine::CanRunOnRoad ( EngineID  engine_id,
GSRoad::RoadType  road_type 
)
static

Check if a road vehicle can run on a RoadType.

Parameters
engine_idThe engine to check.
road_typeAnother RoadType.
Precondition
IsValidEngine(engine_id).
GetVehicleType(engine_id) == GSVehicle::VT_ROAD.
GSRoad::IsRoadTypeAvailable(road_type).
Returns
Whether an engine of type 'engine_id' can run on 'road_type'.

◆ DisableForCompany()

static bool GSEngine::DisableForCompany ( EngineID  engine_id,
GSCompany::CompanyID  company_id 
)
static

Forbids a company to use an engine before its natural retirement.

Parameters
engine_idThe engine to disable.
company_idThe company to forbid using the engine.
Precondition
IsValidEngine(engine_id).
GSCompany.ResolveCompanyID(company_id) != GSCompany::COMPANY_INVALID.
Returns
True if the action succeeded.

◆ EnableForCompany()

static bool GSEngine::EnableForCompany ( EngineID  engine_id,
GSCompany::CompanyID  company_id 
)
static

Allows a company to use an engine before its intro date or after retirement.

Parameters
engine_idThe engine to enable.
company_idThe company to allow using the engine.
Precondition
IsValidEngine(engine_id).
GSCompany.ResolveCompanyID(company_id) != GSCompany::COMPANY_INVALID.
Returns
True if the action succeeded.

◆ GetCapacity()

static int GSEngine::GetCapacity ( EngineID  engine_id)
static

Get the capacity of an engine.

In case it can transport multiple cargoes, it returns the first/main.

Parameters
engine_idThe engine to get the capacity of.
Precondition
IsValidEngine(engine_id).
Returns
The capacity of the engine.

◆ GetCargoType()

static CargoID GSEngine::GetCargoType ( EngineID  engine_id)
static

Get the cargo-type of an engine.

In case it can transport multiple cargoes, it returns the first/main.

Parameters
engine_idThe engine to get the cargo-type of.
Precondition
IsValidEngine(engine_id).
Returns
The cargo-type of the engine.

◆ GetDesignDate()

static GSDate::Date GSEngine::GetDesignDate ( EngineID  engine_id)
static

Get the calendar-date this engine was designed.

Parameters
engine_idThe engine to get the design date of.
Precondition
IsValidEngine(engine_id).
Returns
The calendar-date this engine was designed.
See also
GSCalendarTime

◆ GetMaxAge()

static int GSEngine::GetMaxAge ( EngineID  engine_id)
static

Get the maximum age of a brand new engine.

Parameters
engine_idThe engine to get the maximum age of.
Precondition
IsValidEngine(engine_id).
Returns
The maximum age of a new engine in calendar-days.
See also
GSCalendarTime

◆ GetMaximumOrderDistance()

static int GSEngine::GetMaximumOrderDistance ( EngineID  engine_id)
static

Get the maximum allowed distance between two orders for an engine.

The distance returned is a vehicle-type specific distance independent from other map distances, you may use the result of this function to compare it with the result of GSOrder::GetOrderDistance.

Parameters
engine_idThe engine to get the max distance for.
Precondition
IsValidEngine(engine_id).
Returns
The maximum distance between two orders for the engine or 0 if the distance is unlimited.
Note
The unit of the order distances is unspecified and should not be compared with map distances
See also
GSOrder::GetOrderDistance

◆ GetMaxSpeed()

static int GSEngine::GetMaxSpeed ( EngineID  engine_id)
static

Get the maximum speed of an engine.

Parameters
engine_idThe engine to get the maximum speed of.
Precondition
IsValidEngine(engine_id).
Returns
The maximum speed the engine has.
Note
The speed is in OpenTTD's internal speed unit. This is mph / 1.6, which is roughly km/h. To get km/h multiply this number by 1.00584.

◆ GetMaxTractiveEffort()

static int GSEngine::GetMaxTractiveEffort ( EngineID  engine_id)
static

Get the maximum tractive effort of an engine.

Parameters
engine_idThe engine to get the maximum tractive effort of.
Precondition
IsValidEngine(engine_id).
(GetVehicleType(engine_id) == GSVehicle::VT_RAIL || GetVehicleType(engine_id) == GSVehicle::VT_ROAD) && !IsWagon(engine_id).
Returns
The maximum tractive effort of the engine in kN.

◆ GetName()

static string GSEngine::GetName ( EngineID  engine_id)
static

Get the name of an engine.

Parameters
engine_idThe engine to get the name of.
Precondition
IsValidEngine(engine_id).
Returns
The name the engine has.

◆ GetPlaneType()

static GSAirport::PlaneType GSEngine::GetPlaneType ( EngineID  engine_id)
static

Get the PlaneType of the engine.

Parameters
engine_idThe engine to get the PlaneType of.
Precondition
IsValidEngine(engine_id).
GetVehicleType(engine_id) == GSVehicle::VT_AIR.
Returns
The PlaneType the engine has.

◆ GetPower()

static int GSEngine::GetPower ( EngineID  engine_id)
static

Get the power of an engine.

Parameters
engine_idThe engine to get the power of.
Precondition
IsValidEngine(engine_id).
(GetVehicleType(engine_id) == GSVehicle::VT_RAIL || GetVehicleType(engine_id) == GSVehicle::VT_ROAD) && !IsWagon(engine_id).
Returns
The power of the engine in hp.

◆ GetPrice()

static Money GSEngine::GetPrice ( EngineID  engine_id)
static

Get the new cost of an engine.

Parameters
engine_idThe engine to get the new cost of.
Precondition
IsValidEngine(engine_id).
Returns
The new cost the engine has.

◆ GetRailType()

static GSRail::RailType GSEngine::GetRailType ( EngineID  engine_id)
static

Get the RailType of the engine.

Parameters
engine_idThe engine to get the RailType of.
Precondition
IsValidEngine(engine_id).
GetVehicleType(engine_id) == GSVehicle::VT_RAIL.
Returns
The RailType the engine has.

◆ GetReliability()

static int GSEngine::GetReliability ( EngineID  engine_id)
static

Get the reliability of an engine.

The value is between 0 and 100, where 100 means 100% reliability (never breaks down) and 0 means 0% reliability (you most likely don't want to buy it).

Parameters
engine_idThe engine to get the reliability of.
Precondition
IsValidEngine(engine_id).
GetVehicleType(engine_id) != GSVehicle::VT_TRAIN || !IsWagon(engine_id).
Returns
The reliability the engine has.

◆ GetRoadType()

static GSRoad::RoadType GSEngine::GetRoadType ( EngineID  engine_id)
static

Get the RoadType of the engine.

Parameters
engine_idThe engine to get the RoadType of.
Precondition
IsValidEngine(engine_id).
GetVehicleType(engine_id) == GSVehicle::VT_ROAD.
Returns
The RoadType the engine has.

◆ GetRunningCost()

static Money GSEngine::GetRunningCost ( EngineID  engine_id)
static

Get the running cost of an engine.

Parameters
engine_idThe engine to get the running cost of.
Precondition
IsValidEngine(engine_id).
Returns
The running cost of a vehicle per economy-year.
See also
GSEconomyTime

◆ GetVehicleType()

static GSVehicle::VehicleType GSEngine::GetVehicleType ( EngineID  engine_id)
static

Get the type of an engine.

Parameters
engine_idThe engine to get the type of.
Precondition
IsValidEngine(engine_id).
Returns
The type the engine has.

◆ GetWeight()

static int GSEngine::GetWeight ( EngineID  engine_id)
static

Get the weight of an engine.

Parameters
engine_idThe engine to get the weight of.
Precondition
IsValidEngine(engine_id).
(GetVehicleType(engine_id) == GSVehicle::VT_RAIL || GetVehicleType(engine_id) == GSVehicle::VT_ROAD).
Returns
The weight of the engine in metric tons.

◆ HasPowerOnRail()

static bool GSEngine::HasPowerOnRail ( EngineID  engine_id,
GSRail::RailType  track_rail_type 
)
static

Check if a train engine has power on a RailType.

Parameters
engine_idThe engine to check.
track_rail_typeAnother RailType.
Precondition
IsValidEngine(engine_id).
GetVehicleType(engine_id) == GSVehicle::VT_RAIL.
GSRail::IsRailTypeAvailable(track_rail_type).
Returns
Whether an engine of type 'engine_id' has power on 'track_rail_type'.

◆ HasPowerOnRoad()

static bool GSEngine::HasPowerOnRoad ( EngineID  engine_id,
GSRoad::RoadType  road_type 
)
static

Check if a road vehicle has power on a RoadType.

Parameters
engine_idThe engine to check.
road_typeAnother RoadType.
Precondition
IsValidEngine(engine_id).
GetVehicleType(engine_id) == GSVehicle::VT_ROAD.
GSRoad::IsRoadTypeAvailable(road_type).
Returns
Whether an engine of type 'engine_id' has power on 'road_type'.

◆ IsArticulated()

static bool GSEngine::IsArticulated ( EngineID  engine_id)
static

Check if the engine is articulated.

Parameters
engine_idThe engine to check.
Precondition
IsValidEngine(engine_id).
GetVehicleType(engine_id) == GSVehicle::VT_ROAD || GetVehicleType(engine_id) == GSVehicle::VT_RAIL.
Returns
True if the engine is articulated.

◆ IsBuildable()

static bool GSEngine::IsBuildable ( EngineID  engine_id)
static

Checks whether the given engine type is buildable for a company.

Outside GSCompanyMode scope (GSCompanyMode::IsDeity) the function checks whether the engine is currently buildable by all companies (no exclusive preview).

Parameters
engine_idThe engine to check.
Returns
True if and only if the engine type is buildable.

◆ IsValidEngine()

static bool GSEngine::IsValidEngine ( EngineID  engine_id)
static

Checks whether the given engine type is valid.

An engine is valid for a company if it has at least one vehicle of this engine or it's currently buildable. Outside GSCompanyMode scope (GSCompanyMode::IsDeity) the function reports all engines valid, which were or will be available at some point.

Parameters
engine_idThe engine to check.
Returns
True if and only if the engine type is valid.

◆ IsWagon()

static bool GSEngine::IsWagon ( EngineID  engine_id)
static

Check if an engine is a wagon.

Parameters
engine_idThe engine to check.
Precondition
IsValidEngine(engine_id).
GetVehicleType(engine_id) == GSVehicle::VT_RAIL.
Returns
Whether or not the engine is a wagon.