OpenTTD Game API
Public Types | Static Public Member Functions
GSTunnel Class Reference

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

Inheritance diagram for GSTunnel:

Public Types

enum  ErrorMessages {
  ERR_TUNNEL_BASE,
  ERR_TUNNEL_CANNOT_BUILD_ON_WATER,
  ERR_TUNNEL_START_SITE_UNSUITABLE,
  ERR_TUNNEL_ANOTHER_TUNNEL_IN_THE_WAY,
  ERR_TUNNEL_END_SITE_UNSUITABLE
}
 All tunnel related errors. More...
 

Static Public Member Functions

static bool IsTunnelTile (TileIndex tile)
 Check whether the tile is an entrance to a tunnel. More...
 
static TileIndex GetOtherTunnelEnd (TileIndex tile)
 Get the tile that exits on the other end of a (would be) tunnel starting at tile. More...
 
static bool BuildTunnel (GSVehicle::VehicleType vehicle_type, TileIndex start)
 Builds a tunnel starting at start. More...
 
static bool RemoveTunnel (TileIndex tile)
 Remove the tunnel whose entrance is located at tile. More...
 

Detailed Description

Class that handles all tunnel related functions.

Member Enumeration Documentation

◆ ErrorMessages

All tunnel related errors.

Enumerator
ERR_TUNNEL_BASE 

Base for bridge related errors.

ERR_TUNNEL_CANNOT_BUILD_ON_WATER 

Can't build tunnels on water.

ERR_TUNNEL_START_SITE_UNSUITABLE 

The start tile must slope either North, South, West or East.

ERR_TUNNEL_ANOTHER_TUNNEL_IN_THE_WAY 

Another tunnel is in the way.

ERR_TUNNEL_END_SITE_UNSUITABLE 

Unable to excavate land at the end to create the tunnel's exit.

Member Function Documentation

◆ BuildTunnel()

static bool GSTunnel::BuildTunnel ( GSVehicle::VehicleType  vehicle_type,
TileIndex  start 
)
static

Builds a tunnel starting at start.

The direction of the tunnel depends on the slope of the start tile. Tunnels can be created for either rails or roads; use the appropriate GSVehicle::VehicleType. As an extra for road, this functions builds two half-pieces of road on each end of the tunnel, making it easier for you to connect it to your network.

Parameters
startWhere to start the tunnel.
vehicle_typeThe vehicle-type of tunnel to build.
Precondition
GSMap::IsValidTile(start).
(vehicle_type == GSVehicle::VT_ROAD && GSRoad::IsRoadTypeAvailable(GSRoad::GetCurrentRoadType())) || (vehicle_type == GSVehicle::VT_RAIL && GSRail::IsRailTypeAvailable(GSRail::GetCurrentRailType())).
Outside CompanyMode: vehicle_type == GSVehicle::VT_ROAD.
Exceptions
GSError::ERR_AREA_NOT_CLEAR
GSTunnel::ERR_TUNNEL_CANNOT_BUILD_ON_WATER
GSTunnel::ERR_TUNNEL_START_SITE_UNSUITABLE
GSTunnel::ERR_TUNNEL_ANOTHER_TUNNEL_IN_THE_WAY
GSTunnel::ERR_TUNNEL_END_SITE_UNSUITABLE
Returns
Whether the tunnel has been/can be build or not.
Note
The slope of a tile can be determined by GSTile::GetSlope(TileIndex).
No matter if the road pieces were build or not, if building the tunnel succeeded, this function returns true.
Building a bridge (without CompanyMode) results in a bridge owned by towns.

◆ GetOtherTunnelEnd()

static TileIndex GSTunnel::GetOtherTunnelEnd ( TileIndex  tile)
static

Get the tile that exits on the other end of a (would be) tunnel starting at tile.

If there is no 'simple' inclined slope at the start tile, this function will return GSMap::TILE_INVALID.

Parameters
tileThe tile that is an entrance to a tunnel or the tile where you may want to build a tunnel.
Precondition
GSMap::IsValidTile(tile).
Returns
The TileIndex that is the other end of the (would be) tunnel, or GSMap::TILE_INVALID if no other end was found (can't build tunnel).
Note
Even if this function returns a valid tile, that is no guarantee that building a tunnel will succeed. Use BuildTunnel in GSTestMode to check whether a tunnel can actually be build.

◆ IsTunnelTile()

static bool GSTunnel::IsTunnelTile ( TileIndex  tile)
static

Check whether the tile is an entrance to a tunnel.

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

◆ RemoveTunnel()

static bool GSTunnel::RemoveTunnel ( TileIndex  tile)
static

Remove the tunnel whose entrance is located at tile.

Parameters
tileThe tile that is an entrance to a tunnel.
Precondition
GSMap::IsValidTile(tile) && IsTunnelTile(tile).
Valid GSCompanyMode active in scope.
Exceptions
GSError::ERR_OWNED_BY_ANOTHER_COMPANY
Returns
Whether the tunnel has been/can be removed or not.