OpenTTD GameScript API  20240424-master-g9121770582
Public Types | Static Public Member Functions
GSBridge Class Reference

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

Inheritance diagram for GSBridge:

Public Types

enum  ErrorMessages {
  ERR_BRIDGE_BASE,
  ERR_BRIDGE_TYPE_UNAVAILABLE,
  ERR_BRIDGE_CANNOT_END_IN_WATER,
  ERR_BRIDGE_HEADS_NOT_ON_SAME_HEIGHT
}
 All bridge related error messages. More...
 

Static Public Member Functions

static bool IsValidBridge (BridgeID bridge_id)
 Checks whether the given bridge type is valid. More...
 
static bool IsBridgeTile (TileIndex tile)
 Checks whether the given tile is actually a bridge start or end tile. More...
 
static BridgeID GetBridgeID (TileIndex tile)
 Get the BridgeID of a bridge at a given tile. More...
 
static std::optional< std::string > GetName (BridgeID bridge_id, GSVehicle::VehicleType vehicle_type)
 Get the name of a bridge. More...
 
static SQInteger GetMaxSpeed (BridgeID bridge_id)
 Get the maximum speed of a bridge. More...
 
static Money GetPrice (BridgeID bridge_id, SQInteger length)
 Get the new cost of a bridge, excluding the road and/or rail. More...
 
static SQInteger GetMaxLength (BridgeID bridge_id)
 Get the maximum length of a bridge. More...
 
static SQInteger GetMinLength (BridgeID bridge_id)
 Get the minimum length of a bridge. More...
 
static bool BuildBridge (GSVehicle::VehicleType vehicle_type, BridgeID bridge_id, TileIndex start, TileIndex end)
 Build a bridge from one tile to the other. More...
 
static bool RemoveBridge (TileIndex tile)
 Removes a bridge, by executing it on either the start or end tile. More...
 
static TileIndex GetOtherBridgeEnd (TileIndex tile)
 Get the tile that is on the other end of a bridge starting at tile. More...
 

Detailed Description

Class that handles all bridge related functions.

Member Enumeration Documentation

◆ ErrorMessages

All bridge related error messages.

Enumerator
ERR_BRIDGE_BASE 

Base for bridge related errors.

ERR_BRIDGE_TYPE_UNAVAILABLE 

The bridge you want to build is not available yet, or it is not available for the requested length.

ERR_BRIDGE_CANNOT_END_IN_WATER 

One (or more) of the bridge head(s) ends in water.

ERR_BRIDGE_HEADS_NOT_ON_SAME_HEIGHT 

The bride heads need to be on the same height.

Member Function Documentation

◆ BuildBridge()

static bool GSBridge::BuildBridge ( GSVehicle::VehicleType  vehicle_type,
BridgeID  bridge_id,
TileIndex  start,
TileIndex  end 
)
static

Build a bridge from one tile to the other.

As an extra for road, this functions builds two half-pieces of road on each end of the bridge, making it easier for you to connect it to your network.

Parameters
vehicle_typeThe vehicle-type of bridge to build.
bridge_idThe bridge-type to build.
startWhere to start the bridge.
endWhere to end the bridge.
Precondition
GSMap::IsValidTile(start).
GSMap::IsValidTile(end).
'start' and 'end' are in a straight line, i.e. GSMap::GetTileX(start) == GSMap::GetTileX(end) or GSMap::GetTileY(start) == GSMap::GetTileY(end).
vehicle_type == GSVehicle::VT_WATER || (vehicle_type == GSVehicle::VT_ROAD && GSRoad::IsRoadTypeAvailable(GSRoad::GetCurrentRoadType())) || (vehicle_type == GSVehicle::VT_RAIL && GSRail::IsRailTypeAvailable(GSRail::GetCurrentRailType())).
GSCompanyMode::IsValid() || vehicle_type == GSVehicle::VT_ROAD.
Exceptions
GSError::ERR_ALREADY_BUILT
GSError::ERR_AREA_NOT_CLEAR
GSError::ERR_LAND_SLOPED_WRONG
GSError::ERR_VEHICLE_IN_THE_WAY
GSBridge::ERR_BRIDGE_TYPE_UNAVAILABLE
GSBridge::ERR_BRIDGE_CANNOT_END_IN_WATER
GSBridge::ERR_BRIDGE_HEADS_NOT_ON_SAME_HEIGHT
Returns
Whether the bridge has been/can be build or not.
Note
Building a bridge as deity (GSCompanyMode::IsDeity()) results in a bridge owned by towns.
No matter if the road pieces were build or not, if building the bridge succeeded, this function returns true.

◆ GetBridgeID()

static BridgeID GSBridge::GetBridgeID ( TileIndex  tile)
static

Get the BridgeID of a bridge at a given tile.

Parameters
tileThe tile to get the BridgeID from.
Precondition
IsBridgeTile(tile).
Returns
The BridgeID from the bridge at tile 'tile'.

◆ GetMaxLength()

static SQInteger GSBridge::GetMaxLength ( BridgeID  bridge_id)
static

Get the maximum length of a bridge.

Parameters
bridge_idThe bridge to get the maximum length of.
Precondition
IsValidBridge(bridge_id).
Returns
The maximum length the bridge has.

◆ GetMaxSpeed()

static SQInteger GSBridge::GetMaxSpeed ( BridgeID  bridge_id)
static

Get the maximum speed of a bridge.

Parameters
bridge_idThe bridge to get the maximum speed of.
Precondition
IsValidBridge(bridge_id).
Returns
The maximum speed the bridge 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.

◆ GetMinLength()

static SQInteger GSBridge::GetMinLength ( BridgeID  bridge_id)
static

Get the minimum length of a bridge.

Parameters
bridge_idThe bridge to get the minimum length of.
Precondition
IsValidBridge(bridge_id).
Returns
The minimum length the bridge has.

◆ GetName()

static std::optional<std::string> GSBridge::GetName ( BridgeID  bridge_id,
GSVehicle::VehicleType  vehicle_type 
)
static

Get the name of a bridge.

Parameters
bridge_idThe bridge to get the name of.
vehicle_typeThe vehicle-type of bridge to get the name of.
Precondition
IsValidBridge(bridge_id).
vehicle_type == GSVehicle::VT_ROAD || vehicle_type == GSVehicle::VT_RAIL || vehicle_type == GSVehicle::VT_WATER
Returns
The name the bridge has.

◆ GetOtherBridgeEnd()

static TileIndex GSBridge::GetOtherBridgeEnd ( TileIndex  tile)
static

Get the tile that is on the other end of a bridge starting at tile.

Parameters
tileThe tile that is an end of a bridge.
Precondition
GSMap::IsValidTile(tile).
IsBridgeTile(tile).
Returns
The TileIndex that is the other end of the bridge.

◆ GetPrice()

static Money GSBridge::GetPrice ( BridgeID  bridge_id,
SQInteger  length 
)
static

Get the new cost of a bridge, excluding the road and/or rail.

Parameters
bridge_idThe bridge to get the new cost of.
lengthThe length of the bridge. The value will be clamped to 0 .. MAX(int32_t).
Precondition
IsValidBridge(bridge_id).
Returns
The new cost the bridge has.

◆ IsBridgeTile()

static bool GSBridge::IsBridgeTile ( TileIndex  tile)
static

Checks whether the given tile is actually a bridge start or end tile.

Parameters
tileThe tile to check.
Precondition
GSMap::IsValidTile(tile).
Returns
True if and only if the tile is the beginning or end of a bridge.

◆ IsValidBridge()

static bool GSBridge::IsValidBridge ( BridgeID  bridge_id)
static

Checks whether the given bridge type is valid.

Parameters
bridge_idThe bridge to check.
Returns
True if and only if the bridge type is valid.

◆ RemoveBridge()

static bool GSBridge::RemoveBridge ( TileIndex  tile)
static

Removes a bridge, by executing it on either the start or end tile.

Parameters
tileAn end or start tile of the bridge.
Precondition
GSMap::IsValidTile(tile).
GSCompanyMode::IsValid().
Exceptions
GSError::ERR_OWNED_BY_ANOTHER_COMPANY
Returns
Whether the bridge has been/can be removed or not.