Public Types | Static Public Member Functions

ScriptBridge Class Reference

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

#include <script_bridge.hpp>

Inheritance diagram for ScriptBridge:
ScriptObject SimpleCountedObject

Public Types

enum  ErrorMessages { ERR_BRIDGE_BASE = ScriptError::ERR_CAT_BRIDGE << ScriptError::ERR_CAT_BIT_SIZE, 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.
static bool IsBridgeTile (TileIndex tile)
 Checks whether the given tile is actually a bridge start or end tile.
static BridgeID GetBridgeID (TileIndex tile)
 Get the BridgeID of a bridge at a given tile.
static char * GetName (BridgeID bridge_id)
 Get the name of a bridge.
static int32 GetMaxSpeed (BridgeID bridge_id)
 Get the maximum speed of a bridge.
static Money GetPrice (BridgeID bridge_id, uint length)
 Get the new cost of a bridge, excluding the road and/or rail.
static int32 GetMaxLength (BridgeID bridge_id)
 Get the maximum length of a bridge.
static int32 GetMinLength (BridgeID bridge_id)
 Get the minimum length of a bridge.
static bool _BuildBridgeRoad1 ()
 Internal function to help BuildBridge in case of road.
static bool _BuildBridgeRoad2 ()
 Internal function to help BuildBridge in case of road.
static bool BuildBridge (ScriptVehicle::VehicleType vehicle_type, BridgeID bridge_id, TileIndex start, TileIndex end)
 Build a bridge from one tile to the other.
static bool RemoveBridge (TileIndex tile)
 Removes a bridge, by executing it on either the start or end tile.
static TileIndex GetOtherBridgeEnd (TileIndex tile)
 Get the tile that is on the other end of a bridge starting at tile.

Detailed Description

Class that handles all bridge related functions.

ai game

Definition at line 21 of file script_bridge.hpp.


Member Enumeration Documentation

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.

Definition at line 26 of file script_bridge.hpp.


Member Function Documentation

bool ScriptBridge::_BuildBridgeRoad1 (  )  [static]
bool ScriptBridge::_BuildBridgeRoad2 (  )  [static]
bool ScriptBridge::BuildBridge ( ScriptVehicle::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_type The vehicle-type of bridge to build.
bridge_id The bridge-type to build.
start Where to start the bridge.
end Where to end the bridge.
Precondition:
ScriptMap::IsValidTile(start).
ScriptMap::IsValidTile(end).
'start' and 'end' are in a straight line, i.e. ScriptMap::GetTileX(start) == ScriptMap::GetTileX(end) or ScriptMap::GetTileY(start) == ScriptMap::GetTileY(end).
vehicle_type == ScriptVehicle::VT_ROAD || vehicle_type == ScriptVehicle::VT_WATER || (vehicle_type == ScriptVehicle::VT_RAIL && ScriptRail::IsRailTypeAvailable(ScriptRail::GetCurrentRailType())).
Outside CompanyMode: vehicle_type == ScriptVehicle::VT_ROAD.
Exceptions:
ScriptError::ERR_ALREADY_BUILT 
ScriptError::ERR_AREA_NOT_CLEAR 
ScriptError::ERR_LAND_SLOPED_WRONG 
ScriptError::ERR_VEHICLE_IN_THE_WAY 
ScriptBridge::ERR_BRIDGE_TYPE_UNAVAILABLE 
ScriptBridge::ERR_BRIDGE_CANNOT_END_IN_WATER 
ScriptBridge::ERR_BRIDGE_HEADS_NOT_ON_SAME_HEIGHT 
Returns:
Whether the bridge has been/can be build or not.
Note:
Building a bridge (without CompanyMode) 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.

Definition at line 70 of file script_bridge.cpp.

References _DoCommandReturnBuildBridge1(), CMD_BUILD_BRIDGE, ScriptObject::DoCommand(), EnforcePrecondition, ScriptObject::GetCompany(), ScriptRail::GetCurrentRailType(), ScriptObject::GetRoadType(), ScriptRail::IsRailTypeAvailable(), IsValidTile(), OWNER_DEITY, RoadTypeToRoadTypes(), ScriptObject::SetCallbackVariable(), TileX(), TileY(), TRANSPORT_RAIL, TRANSPORT_ROAD, TRANSPORT_WATER, ScriptVehicle::VT_RAIL, ScriptVehicle::VT_ROAD, and ScriptVehicle::VT_WATER.

BridgeID ScriptBridge::GetBridgeID ( TileIndex  tile  )  [static]

Get the BridgeID of a bridge at a given tile.

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

Definition at line 32 of file script_bridge.cpp.

References GetBridgeType(), and IsBridgeTile().

int32 ScriptBridge::GetMaxLength ( BridgeID  bridge_id  )  [static]

Get the maximum length of a bridge.

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

Definition at line 161 of file script_bridge.cpp.

References _settings_game, GameSettings::construction, GetBridgeSpec(), IsValidBridge(), ConstructionSettings::max_bridge_length, and min().

Referenced by ScriptBridgeList_Length::ScriptBridgeList_Length().

int32 ScriptBridge::GetMaxSpeed ( BridgeID  bridge_id  )  [static]

Get the maximum speed of a bridge.

Parameters:
bridge_id The 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.

Definition at line 147 of file script_bridge.cpp.

References GetBridgeSpec(), IsValidBridge(), and BridgeSpec::speed.

int32 ScriptBridge::GetMinLength ( BridgeID  bridge_id  )  [static]

Get the minimum length of a bridge.

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

Definition at line 168 of file script_bridge.cpp.

References GetBridgeSpec(), IsValidBridge(), and BridgeSpec::min_length.

Referenced by ScriptBridgeList_Length::ScriptBridgeList_Length().

char * ScriptBridge::GetName ( BridgeID  bridge_id  )  [static]

Get the name of a bridge.

Parameters:
bridge_id The bridge to get the name of.
Precondition:
IsValidBridge(bridge_id).
Returns:
The name the bridge has.

Definition at line 136 of file script_bridge.cpp.

References GetBridgeSpec(), and IsValidBridge().

TileIndex ScriptBridge::GetOtherBridgeEnd ( TileIndex  tile  )  [static]

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

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

Definition at line 175 of file script_bridge.cpp.

References INVALID_TILE, IsBridgeTile(), and IsValidTile().

Money ScriptBridge::GetPrice ( BridgeID  bridge_id,
uint  length 
) [static]

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

Parameters:
bridge_id The bridge to get the new cost of.
length The length of the bridge.
Precondition:
IsValidBridge(bridge_id).
Returns:
The new cost the bridge has.

Definition at line 154 of file script_bridge.cpp.

References CalcBridgeLenCostFactor(), GetBridgeSpec(), and IsValidBridge().

bool ScriptBridge::IsBridgeTile ( TileIndex  tile  )  [static]

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

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

Definition at line 26 of file script_bridge.cpp.

References IsValidTile().

Referenced by GetBridgeID(), GetOtherBridgeEnd(), and RemoveBridge().

bool ScriptBridge::IsValidBridge ( BridgeID  bridge_id  )  [static]

Checks whether the given bridge type is valid.

Parameters:
bridge_id The bridge to check.
Returns:
True if and only if the bridge type is valid.

Definition at line 21 of file script_bridge.cpp.

References _cur_year, GetBridgeSpec(), and MAX_BRIDGES.

Referenced by GetMaxLength(), GetMaxSpeed(), GetMinLength(), GetName(), GetPrice(), and ScriptBridgeList_Length::ScriptBridgeList_Length().

bool ScriptBridge::RemoveBridge ( TileIndex  tile  )  [static]

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

Parameters:
tile An end or start tile of the bridge.
Precondition:
ScriptMap::IsValidTile(tile).
Valid ScriptCompanyMode active in scope.
Exceptions:
ScriptError::ERR_OWNED_BY_ANOTHER_COMPANY 
Returns:
Whether the bridge has been/can be removed or not.

Definition at line 129 of file script_bridge.cpp.

References CMD_LANDSCAPE_CLEAR, ScriptObject::DoCommand(), EnforcePrecondition, ScriptObject::GetCompany(), IsBridgeTile(), and OWNER_DEITY.


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