OpenTTD Source: src/road_cmd.h File Reference

OpenTTD Source 13.2.1

Functions | Variables
road_cmd.h File Reference
`#include "direction_type.h"`
`#include "road_type.h"`
`#include "command_type.h"`

Go to the source code of this file.

## Functions
void | DrawRoadDepotSprite (int x, int y, DiagDirection dir, RoadType rt)
| Draw the road depot sprite. More...
void | UpdateNearestTownForRoadTiles (bool invalidate)
| Updates cached nearest town for all road tiles. More...
CommandCost | CmdBuildLongRoad (DoCommandFlag flags, TileIndex end_tile, TileIndex start_tile, RoadType rt, Axis axis, DisallowedRoadDirections drd, bool start_half, bool end_half, bool is_ai)
| Build a long piece of road. More...
std::tuple< CommandCost, Money > | CmdRemoveLongRoad (DoCommandFlag flags, TileIndex end_tile, TileIndex start_tile, RoadType rt, Axis axis, bool start_half, bool end_half)
| Remove a long piece of road. More...
CommandCost | CmdBuildRoad (DoCommandFlag flags, TileIndex tile, RoadBits pieces, RoadType rt, DisallowedRoadDirections toggle_drd, TownID town_id)
| Build a piece of road. More...
CommandCost | CmdBuildRoadDepot (DoCommandFlag flags, TileIndex tile, RoadType rt, DiagDirection dir)
| Build a road depot. More...
CommandCost | CmdConvertRoad (DoCommandFlag flags, TileIndex tile, TileIndex area_start, RoadType to_type)
| Convert one road subtype to another. More...
| DEF_CMD_TRAIT (CMD_REMOVE_LONG_ROAD, CmdRemoveLongRoad, CMD_AUTO|CMD_NO_TEST, CMDT_LANDSCAPE_CONSTRUCTION) CommandCallback CcPlaySound_CONSTRUCTION_OTHER
void | CcRoadDepot (Commands cmd, const CommandCost &result, TileIndex tile, RoadType rt, DiagDirection dir)
void | CcRoadStop (Commands cmd, const CommandCost &result, TileIndex tile, uint8 width, uint8 length, RoadStopType, bool is_drive_through, DiagDirection dir, RoadType, StationID, bool)
| Command callback for building road stops. More...

## Variables
CommandCallback | CcBuildRoadTunnel

## Detailed Description

Road related functions.

Definition in file road_cmd.h.

## Function Documentation

## ◆ CcRoadStop()

void CcRoadStop | ( | Commands | cmd,
|  | const CommandCost & | result,
|  | TileIndex | tile,
|  | uint8 | width,
|  | uint8 | length,
|  | RoadStopType | ,
|  | bool | is_drive_through,
|  | DiagDirection | dir,
|  | RoadType | ,
|  | StationID | ,
|  | bool |
| ) |  |

Command callback for building road stops.

Parameters

  cmd | Unused.
  result | Result of the build road stop command.
  tile | Start tile.
  width | Width of the road stop.
  length | Length of the road stop.
  is_drive_through | False for normal stops, true for drive-through.
  dir | Entrance direction (DiagDirection) for normal stops. Converted to the axis for drive-through stops.

See also
  CmdBuildRoadStop

Definition at line 140 of file road_gui.cpp.

## ◆ CmdBuildLongRoad()

CommandCost CmdBuildLongRoad | ( | DoCommandFlag | flags,
|  | TileIndex | end_tile,
|  | TileIndex | start_tile,
|  | RoadType | rt,
|  | Axis | axis,
|  | DisallowedRoadDirections | drd,
|  | bool | start_half,
|  | bool | end_half,
|  | bool | is_ai
| ) |  |

Build a long piece of road.

Parameters

  flags | operation to perform
  end_tile | end tile of drag
  start_tile | start tile of drag
  rt | road type
  axis | direction
  drd | set road direction
  start_half | start tile starts in the 2nd half of tile (p2 & 1). Only used if `is_ai` is set or if we are building a single tile
  end_half | end tile starts in the 2nd half of tile (p2 & 2). Only used if `is_ai` is set or if we are building a single tile
  is_ai | defines two different behaviors for this command: false = Build up to an obstacle. Do not build the first and last roadbits unless they can be connected to something, or if we are building a single tile true = Fail if an obstacle is found. Always take into account start_half and end_half. This behavior is used for scripts

Returns
  the cost of this operation or an error

Definition at line 981 of file road_cmd.cpp.

References CommandCost::AddCost(), AXIS_X, AXIS_Y, AxisToDiagDir(), AxisToRoadBits(), CanConnectToRoad(), CMD_ERROR, DiagDirToRoadBits(), DRD_BOTH, DRD_NORTHBOUND, DRD_SOUTHBOUND, EXPENSES_CONSTRUCTION, CommandCost::Failed(), CommandCost::GetErrorMessage(), GetTunnelBridgeDirection(), IsBridge(), IsTileType(), IsValidAxis(), IsValidDisallowedRoadDirections(), MapSize(), MP_TUNNELBRIDGE, ReverseDiagDir(), TileOffsByDiagDir(), TileX(), TileY(), and ValParamRoadType().

## ◆ CmdBuildRoad()

CommandCost CmdBuildRoad | ( | DoCommandFlag | flags,
|  | TileIndex | tile,
|  | RoadBits | pieces,
|  | RoadType | rt,
|  | DisallowedRoadDirections | toggle_drd,
|  | TownID | town_id
| ) |  |

Build a piece of road.

Parameters

  flags | operation to perform
  tile | tile where to build road
  pieces | road pieces to build (RoadBits)
  rt | road type
  toggle_drd | disallowed directions to toggle
  town_id | the town that is building the road (0 if not applicable)

Returns
  the cost of this operation or an error

Definition at line 617 of file road_cmd.cpp.

References _current_company, CalcClosestTownFromTile(), CMD_ERROR, EXPENSES_CONSTRUCTION, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_town_pool >::IsValidID(), OWNER_DEITY, OWNER_TOWN, and ROAD_NONE.

## ◆ CmdBuildRoadDepot()

CommandCost CmdBuildRoadDepot | ( | DoCommandFlag | flags,
|  | TileIndex | tile,
|  | RoadType | rt,
|  | DiagDirection | dir
| ) |  |

Build a road depot.

Parameters

  tile | tile where to build the depot
  flags | operation to perform
  rt | road type
  dir | entrance direction

Returns
  the cost of this operation or an error

Todo:
  When checking for the tile slope, distinguish between "Flat land required" and "land sloped in wrong direction"

Definition at line 1151 of file road_cmd.cpp.

References _settings_game, CommandCost::AddCost(), ConstructionSettings::build_on_slopes, CanBuildDepotByTileh(), CMD_ERROR, GameSettings::construction, EXPENSES_CONSTRUCTION, GetTileSlope(), IsValidDiagDirection(), return_cmd_error, SLOPE_FLAT, and ValParamRoadType().

## ◆ CmdConvertRoad()

CommandCost CmdConvertRoad | ( | DoCommandFlag | flags,
|  | TileIndex | tile,
|  | TileIndex | area_start,
|  | RoadType | to_type
| ) |  |

Convert one road subtype to another.

Not meant to convert from road to tram.

Parameters

  flags | operation to perform
  tile | end tile of road conversion drag
  area_start | start tile of drag
  to_type | new roadtype to convert to.

Returns
  the cost of this operation or an error

Definition at line 2392 of file road_cmd.cpp.

References CMD_ERROR, MapSize(), and ValParamRoadType().

## ◆ CmdRemoveLongRoad()

std::tuple<CommandCost, Money> CmdRemoveLongRoad | ( | DoCommandFlag | flags,
|  | TileIndex | end_tile,
|  | TileIndex | start_tile,
|  | RoadType | rt,
|  | Axis | axis,
|  | bool | start_half,
|  | bool | end_half
| ) |  |

Remove a long piece of road.

Parameters

  flags | operation to perform
  end_tile | end tile of drag
  start_tile | start tile of drag
  rt | road type
  axis | direction
  start_half | start tile starts in the 2nd half of tile
  end_half | end tile starts in the 2nd half of tile (p2 & 2)

Returns
  the cost of this operation or an error

Definition at line 1077 of file road_cmd.cpp.

References AXIS_X, AXIS_Y, AxisToRoadBits(), CMD_ERROR, EXPENSES_CONSTRUCTION, GetAvailableMoneyForCommand(), IsValidAxis(), MapSize(), ROAD_NE, ROAD_NW, ROAD_SE, ROAD_SW, TileX(), TileY(), and ValParamRoadType().

## ◆ DrawRoadDepotSprite()

void DrawRoadDepotSprite | ( | int | x,
|  | int | y,
|  | DiagDirection | dir,
|  | RoadType | rt
| ) |  |

Draw the road depot sprite.

Parameters

  x | The x offset to draw at.
  y | The y offset to draw at.
  dir | The direction the depot must be facing.
  rt | The road type of the depot to draw.

Definition at line 1830 of file road_cmd.cpp.

## ◆ UpdateNearestTownForRoadTiles()

void UpdateNearestTownForRoadTiles | ( | bool | invalidate | ) |

Updates cached nearest town for all road tiles.

Parameters

  invalidate | are we just invalidating cached data?

Precondition
  invalidate == true implies _generating_world == true

Definition at line 1873 of file road_cmd.cpp.

References _generating_world, HasTownOwnedRoad(), IsRoadDepot(), IsTileType(), MapSize(), and MP_ROAD.