Static Public Member Functions

ScriptEngine Class Reference

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

#include <script_engine.hpp>

Inheritance diagram for ScriptEngine:
ScriptObject SimpleCountedObject

Static Public Member Functions

static bool IsValidEngine (EngineID engine_id)
 Checks whether the given engine type is valid.
static bool IsBuildable (EngineID engine_id)
 Checks whether the given engine type is buildable by you.
static char * GetName (EngineID engine_id)
 Get the name of an engine.
static CargoID GetCargoType (EngineID engine_id)
 Get the cargo-type of an engine.
static bool CanRefitCargo (EngineID engine_id, CargoID cargo_id)
 Check if the cargo of an engine can be refitted to your requested.
static bool CanPullCargo (EngineID engine_id, CargoID cargo_id)
 Check if the engine can pull a wagon with the given cargo.
static int32 GetCapacity (EngineID engine_id)
 Get the capacity of an engine.
static int32 GetReliability (EngineID engine_id)
 Get the reliability of an engine.
static int32 GetMaxSpeed (EngineID engine_id)
 Get the maximum speed of an engine.
static Money GetPrice (EngineID engine_id)
 Get the new cost of an engine.
static int32 GetMaxAge (EngineID engine_id)
 Get the maximum age of a brand new engine.
static Money GetRunningCost (EngineID engine_id)
 Get the running cost of an engine.
static int32 GetPower (EngineID engine_id)
 Get the power of an engine.
static int32 GetWeight (EngineID engine_id)
 Get the weight of an engine.
static int32 GetMaxTractiveEffort (EngineID engine_id)
 Get the maximum tractive effort of an engine.
static int32 GetDesignDate (EngineID engine_id)
 Get the date this engine was designed.
static ScriptVehicle::VehicleType GetVehicleType (EngineID engine_id)
 Get the type of an engine.
static bool IsWagon (EngineID engine_id)
 Check if an engine is a wagon.
static bool CanRunOnRail (EngineID engine_id, ScriptRail::RailType track_rail_type)
 Check if a train vehicle can run on a RailType.
static bool HasPowerOnRail (EngineID engine_id, ScriptRail::RailType track_rail_type)
 Check if a train engine has power on a RailType.
static ScriptRoad::RoadType GetRoadType (EngineID engine_id)
 Get the RoadType of the engine.
static ScriptRail::RailType GetRailType (EngineID engine_id)
 Get the RailType of the engine.
static bool IsArticulated (EngineID engine_id)
 Check if the engine is articulated.
static ScriptAirport::PlaneType GetPlaneType (EngineID engine_id)
 Get the PlaneType of the engine.

Detailed Description

Class that handles all engine related functions.

ai

Definition at line 23 of file script_engine.hpp.


Member Function Documentation

bool ScriptEngine::CanPullCargo ( EngineID  engine_id,
CargoID  cargo_id 
) [static]

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

Parameters:
engine_id The engine to check.
cargo_id The cargo to check.
Precondition:
IsValidEngine(engine_id).
GetVehicleType(engine_id) == ScriptVehicle::VT_RAIL.
ScriptCargo::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.

Definition at line 74 of file script_engine.cpp.

References ScriptCargo::CC_PASSENGERS, GetVehicleType(), ScriptCargo::HasCargoClass(), ScriptCargo::IsValidCargo(), IsValidEngine(), and ScriptVehicle::VT_RAIL.

bool ScriptEngine::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_id The engine to check for refitting.
cargo_id The cargo to check for refitting.
Precondition:
IsValidEngine(engine_id).
ScriptCargo::IsValidCargo(cargo_id).
Returns:
True if the engine can carry this cargo, either via refit, or by default.

Definition at line 66 of file script_engine.cpp.

References GetUnionOfArticulatedRefitMasks(), HasBit(), ScriptCargo::IsValidCargo(), and IsValidEngine().

bool ScriptEngine::CanRunOnRail ( EngineID  engine_id,
ScriptRail::RailType  track_rail_type 
) [static]

Check if a train vehicle can run on a RailType.

Parameters:
engine_id The engine to check.
track_rail_type The type you want to check.
Precondition:
IsValidEngine(engine_id).
GetVehicleType(engine_id) == ScriptVehicle::VT_RAIL.
ScriptRail::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.

Definition at line 202 of file script_engine.cpp.

References GetVehicleType(), IsCompatibleRail(), ScriptRail::IsRailTypeAvailable(), IsValidEngine(), and ScriptVehicle::VT_RAIL.

int32 ScriptEngine::GetCapacity ( EngineID  engine_id  )  [static]

Get the capacity of an engine.

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

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

Definition at line 84 of file script_engine.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), GetCapacityOfArticulatedParts(), Engine::GetDisplayDefaultCapacity(), IsValidEngine(), Engine::type, VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, and VEH_TRAIN.

CargoID ScriptEngine::GetCargoType ( EngineID  engine_id  )  [static]

Get the cargo-type of an engine.

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

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

Definition at line 48 of file script_engine.cpp.

References GetCapacityOfArticulatedParts(), and IsValidEngine().

int32 ScriptEngine::GetDesignDate ( EngineID  engine_id  )  [static]

Get the date this engine was designed.

Parameters:
engine_id The engine to get the design date of.
Precondition:
IsValidEngine(engine_id).
Returns:
The date this engine was designed.

Definition at line 174 of file script_engine.cpp.

References IsValidEngine().

int32 ScriptEngine::GetMaxAge ( EngineID  engine_id  )  [static]

Get the maximum age of a brand new engine.

Parameters:
engine_id The engine to get the maximum age of.
Precondition:
IsValidEngine(engine_id).
Returns:
The maximum age of a new engine in days.
Note:
Age is in days; divide by 366 to get per year.

Definition at line 133 of file script_engine.cpp.

References GetVehicleType(), IsValidEngine(), IsWagon(), and ScriptVehicle::VT_RAIL.

int32 ScriptEngine::GetMaxSpeed ( EngineID  engine_id  )  [static]

Get the maximum speed of an engine.

Parameters:
engine_id The engine to get the maximum speed of.
Precondition:
IsValidEngine(engine_id).
GetVehicleType(engine_id) != ScriptVehicle::VT_TRAIN || !IsWagon(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.

Definition at line 116 of file script_engine.cpp.

References _settings_game, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), Engine::GetDisplayMaxSpeed(), IsValidEngine(), VehicleSettings::plane_speed, Engine::type, VEH_AIRCRAFT, and GameSettings::vehicle.

int32 ScriptEngine::GetMaxTractiveEffort ( EngineID  engine_id  )  [static]

Get the maximum tractive effort of an engine.

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

Definition at line 165 of file script_engine.cpp.

References GetVehicleType(), IsValidEngine(), IsWagon(), ScriptVehicle::VT_RAIL, and ScriptVehicle::VT_ROAD.

char * ScriptEngine::GetName ( EngineID  engine_id  )  [static]

Get the name of an engine.

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

Definition at line 36 of file script_engine.cpp.

References IsValidEngine(), and SetDParam().

ScriptAirport::PlaneType ScriptEngine::GetPlaneType ( EngineID  engine_id  )  [static]

Get the PlaneType of the engine.

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

Definition at line 244 of file script_engine.cpp.

References GetVehicleType(), IsValidEngine(), and ScriptVehicle::VT_AIR.

int32 ScriptEngine::GetPower ( EngineID  engine_id  )  [static]

Get the power of an engine.

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

Definition at line 148 of file script_engine.cpp.

References GetVehicleType(), IsValidEngine(), IsWagon(), ScriptVehicle::VT_RAIL, and ScriptVehicle::VT_ROAD.

Money ScriptEngine::GetPrice ( EngineID  engine_id  )  [static]

Get the new cost of an engine.

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

Definition at line 126 of file script_engine.cpp.

References IsValidEngine().

ScriptRail::RailType ScriptEngine::GetRailType ( EngineID  engine_id  )  [static]

Get the RailType of the engine.

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

Definition at line 228 of file script_engine.cpp.

References GetVehicleType(), IsValidEngine(), and ScriptVehicle::VT_RAIL.

int32 ScriptEngine::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_id The engine to get the reliability of.
Precondition:
IsValidEngine(engine_id).
GetVehicleType(engine_id) != ScriptVehicle::VT_TRAIN || !IsWagon(engine_id).
Returns:
The reliability the engine has.

Definition at line 108 of file script_engine.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), GetVehicleType(), IsValidEngine(), IsWagon(), ToPercent16(), and ScriptVehicle::VT_RAIL.

ScriptRoad::RoadType ScriptEngine::GetRoadType ( EngineID  engine_id  )  [static]

Get the RoadType of the engine.

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

Definition at line 220 of file script_engine.cpp.

References EF_ROAD_TRAM, GetVehicleType(), HasBit(), IsValidEngine(), ScriptRoad::ROADTYPE_TRAM, and ScriptVehicle::VT_ROAD.

Money ScriptEngine::GetRunningCost ( EngineID  engine_id  )  [static]

Get the running cost of an engine.

Parameters:
engine_id The engine to get the running cost of.
Precondition:
IsValidEngine(engine_id).
Returns:
The running cost of a vehicle per year.
Note:
Cost is per year; divide by 365 to get per day.

Definition at line 141 of file script_engine.cpp.

References IsValidEngine().

ScriptVehicle::VehicleType ScriptEngine::GetVehicleType ( EngineID  engine_id  )  [static]

Get the type of an engine.

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

Definition at line 181 of file script_engine.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), IsValidEngine(), VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, and VEH_TRAIN.

Referenced by CanPullCargo(), CanRunOnRail(), GetMaxAge(), GetMaxTractiveEffort(), GetPlaneType(), GetPower(), GetRailType(), GetReliability(), GetRoadType(), GetWeight(), HasPowerOnRail(), IsArticulated(), and IsWagon().

int32 ScriptEngine::GetWeight ( EngineID  engine_id  )  [static]

Get the weight of an engine.

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

Definition at line 157 of file script_engine.cpp.

References GetVehicleType(), IsValidEngine(), ScriptVehicle::VT_RAIL, and ScriptVehicle::VT_ROAD.

bool ScriptEngine::HasPowerOnRail ( EngineID  engine_id,
ScriptRail::RailType  track_rail_type 
) [static]

Check if a train engine has power on a RailType.

Parameters:
engine_id The engine to check.
track_rail_type Another RailType.
Precondition:
IsValidEngine(engine_id).
GetVehicleType(engine_id) == ScriptVehicle::VT_RAIL.
ScriptRail::IsRailTypeAvailable(track_rail_type).
Returns:
Whether an engine of type 'engine_id' has power on 'track_rail_type'.

Definition at line 211 of file script_engine.cpp.

References GetVehicleType(), ScriptRail::IsRailTypeAvailable(), IsValidEngine(), and ScriptVehicle::VT_RAIL.

bool ScriptEngine::IsArticulated ( EngineID  engine_id  )  [static]

Check if the engine is articulated.

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

Definition at line 236 of file script_engine.cpp.

References CountArticulatedParts(), GetVehicleType(), IsValidEngine(), ScriptVehicle::VT_RAIL, and ScriptVehicle::VT_ROAD.

bool ScriptEngine::IsBuildable ( EngineID  engine_id  )  [static]

Checks whether the given engine type is buildable by you.

Parameters:
engine_id The engine to check.
Returns:
True if and only if the engine type is buildable.

Definition at line 30 of file script_engine.cpp.

References _current_company, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::GetIfValid(), IsEngineBuildable(), and Engine::type.

Referenced by ScriptVehicle::BuildVehicle(), and ScriptGroup::SetAutoReplace().

bool ScriptEngine::IsValidEngine ( EngineID  engine_id  )  [static]
bool ScriptEngine::IsWagon ( EngineID  engine_id  )  [static]

Check if an engine is a wagon.

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

Definition at line 194 of file script_engine.cpp.

References GetVehicleType(), IsValidEngine(), and ScriptVehicle::VT_RAIL.

Referenced by GetMaxAge(), GetMaxTractiveEffort(), GetPower(), and GetReliability().


The documentation for this class was generated from the following files: