OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

Data Structures | Typedefs | Enumerations | Functions | Variables
road_gui.cpp File Reference

GUI for building roads. More...

`#include "stdafx.h"`
`#include "gui.h"`
`#include "window_gui.h"`
`#include "station_gui.h"`
`#include "terraform_gui.h"`
`#include "viewport_func.h"`
`#include "command_func.h"`
`#include "road_cmd.h"`
`#include "station_func.h"`
`#include "window_func.h"`
`#include "vehicle_func.h"`
`#include "sound_func.h"`
`#include "company_func.h"`
`#include "tunnelbridge.h"`
`#include "tunnelbridge_map.h"`
`#include "tilehighlight_func.h"`
`#include "company_base.h"`
`#include "hotkeys.h"`
`#include "road_gui.h"`
`#include "zoom_func.h"`
`#include "widgets/road_widget.h"`
`#include "table/strings.h"`
`#include "safeguards.h"`

Go to the source code of this file.

## Data Structures
struct | RoadTypeInfo
| Structure holding information per roadtype for several functions. More...
struct | BuildRoadToolbarWindow
| Road toolbar window handler. More...
struct | BuildRoadDepotWindow
struct | BuildRoadStationWindow

## Typedefs
typedef void | OnButtonClick (Window *w)

## Enumerations
enum | RoadFlags { RF_NONE = 0x00, RF_START_HALFROAD_Y = 0x01, RF_END_HALFROAD_Y = 0x02, RF_DIR_Y = 0x04, RF_DIR_X = RF_NONE, RF_START_HALFROAD_X = 0x08, RF_END_HALFROAD_X = 0x10 }
| Define the values of the RoadFlags. More...

## Functions
static void | ShowRVStationPicker (Window *parent, RoadStopType rs)
static void | ShowRoadDepotPicker (Window *parent)
void | CcPlaySound1D (const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
static void | PlaceRoad_Bridge (TileIndex tile, Window *w)
| Callback to start placing a bridge.
void | CcBuildRoadTunnel (const CommandCost &result, TileIndex start_tile, uint32 p1, uint32 p2)
| Callback executed after a build road tunnel command has been called.
void | ConnectRoadToStructure (TileIndex tile, DiagDirection direction)
| If required, connects a new structure to an existing road or tram by building the missing roadbit.
void | CcRoadDepot (const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
void | CcRoadStop (const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
| Command callback for building road stops.
static void | PlaceRoadStop (TileIndex start_tile, TileIndex end_tile, uint32 p2, uint32 cmd)
| Place a new road stop.
static void | PlaceRoad_BusStation (TileIndex tile)
| Callback for placing a bus station.
static void | PlaceRoad_TruckStation (TileIndex tile)
| Callback for placing a truck station.
static void | ToggleRoadButton_Remove (Window *w)
| Toggles state of the Remove button of Build road toolbar.
static bool | RoadToolbar_CtrlChanged (Window *w)
| Updates the Remove button because of Ctrl state change.
static EventState | RoadToolbarGlobalHotkeys (int hotkey)
| Handler for global hotkeys of the BuildRoadToolbarWindow.
Window * | ShowBuildRoadToolbar (RoadType roadtype)
| Open the build road toolbar window.
Window * | ShowBuildRoadScenToolbar ()
| Show the road building toolbar in the scenario editor.
void | InitializeRoadGui ()

## Variables
static bool | _remove_button_clicked
static bool | _one_way_button_clicked
static RoadFlags | _place_road_flag
static RoadType | _cur_roadtype
static DiagDirection | _road_depot_orientation
static DiagDirection | _road_station_picker_orientation
static const RoadTypeInfo | _road_type_infos []
| What errors/cursors must be shown for several types of roads.
static Hotkey | roadtoolbar_hotkeys []
static const NWidgetPart | _nested_build_road_widgets []
static WindowDesc | _build_road_desc (WDP_ALIGN_TOOLBAR,"toolbar_road", 0, 0, WC_BUILD_TOOLBAR, WC_NONE, WDF_CONSTRUCTION, _nested_build_road_widgets, lengthof(_nested_build_road_widgets),&BuildRoadToolbarWindow::hotkeys)
static const NWidgetPart | _nested_build_tramway_widgets []
static WindowDesc | _build_tramway_desc (WDP_ALIGN_TOOLBAR,"toolbar_tramway", 0, 0, WC_BUILD_TOOLBAR, WC_NONE, WDF_CONSTRUCTION, _nested_build_tramway_widgets, lengthof(_nested_build_tramway_widgets),&BuildRoadToolbarWindow::hotkeys)
static const NWidgetPart | _nested_build_road_scen_widgets []
static WindowDesc | _build_road_scen_desc (WDP_AUTO,"toolbar_road_scen", 0, 0, WC_SCEN_BUILD_TOOLBAR, WC_NONE, WDF_CONSTRUCTION, _nested_build_road_scen_widgets, lengthof(_nested_build_road_scen_widgets),&BuildRoadToolbarWindow::hotkeys)
static const NWidgetPart | _nested_build_road_depot_widgets []
static WindowDesc | _build_road_depot_desc (WDP_AUTO, NULL, 0, 0, WC_BUILD_DEPOT, WC_BUILD_TOOLBAR, WDF_CONSTRUCTION, _nested_build_road_depot_widgets, lengthof(_nested_build_road_depot_widgets))
static const NWidgetPart | _nested_rv_station_picker_widgets []
| Widget definition of the build road station window.
static WindowDesc | _rv_station_picker_desc (WDP_AUTO, NULL, 0, 0, WC_BUS_STATION, WC_BUILD_TOOLBAR, WDF_CONSTRUCTION, _nested_rv_station_picker_widgets, lengthof(_nested_rv_station_picker_widgets))

## Detailed Description

GUI for building roads.

Definition in file road_gui.cpp.

## Enumeration Type Documentation

enum RoadFlags

Define the values of the RoadFlags.

See Also
  CmdBuildLongRoad

Definition at line 49 of file road_gui.cpp.

## Function Documentation

void CcBuildRoadTunnel | ( | const CommandCost & | result,
|  | TileIndex | start_tile,
|  | uint32 | p1,
|  | uint32 | p2
| ) |  |

Callback executed after a build road tunnel command has been called.

Parameters

  result | Whether the build succeeded.
  start_tile | Starting tile of the tunnel.
  p1 | bit 0-3 railtype or roadtypes bit 8-9 transport type
  p2 | unused

Definition at line 96 of file road_gui.cpp.

References _build_tunnel_endtile, _settings_client, SoundSettings::confirm, ConnectRoadToStructure(), GetOtherTunnelBridgeEnd(), GetTunnelBridgeDirection(), ClientSettings::gui, GUISettings::persistent_buildingtools, ReverseDiagDir(), SetRedErrorSquare(), SND_1F_SPLAT_OTHER, ClientSettings::sound, and CommandCost::Succeeded().

Referenced by BuildRoadToolbarWindow::OnPlaceObject().

void CcRoadStop | ( | const CommandCost & | result,
|  | TileIndex | tile,
|  | uint32 | p1,
|  | uint32 | p2
| ) |  |

Command callback for building road stops.

Parameters

  result | Result of the build road stop command.
  tile | Start tile.
  p1 | bit 0..7: Width of the road stop. bit 8..15: Length of the road stop.
  p2 | bit 0: 0 For bus stops, 1 for truck stops. bit 1: 0 For normal stops, 1 for drive-through. bit 2..3: The roadtypes. bit 5: Allow stations directly adjacent to other stations. bit 6..7: Entrance direction (DiagDirection). bit 16..31: Station ID to join (NEW_STATION if build new one).

See Also
  CmdBuildRoadStop

Definition at line 199 of file road_gui.cpp.

References _settings_client, SoundSettings::confirm, ConnectRoadToStructure(), CommandCost::Failed(), GB(), ClientSettings::gui, HasBit(), GUISettings::persistent_buildingtools, ReverseDiagDir(), SND_1F_SPLAT_OTHER, ClientSettings::sound, and TILE_AREA_LOOP.

Referenced by PlaceRoadStop().

void ConnectRoadToStructure | ( | TileIndex | tile,
|  | DiagDirection | direction
| ) |  |

If required, connects a new structure to an existing road or tram by building the missing roadbit.

Parameters

  tile | Tile containing the structure to connect.
  direction | Direction to check.

Definition at line 164 of file road_gui.cpp.

References CMD_BUILD_ROAD, DiagDirToRoadBits(), DoCommandP(), GetRoadBits(), IsNormalRoadTile(), ReverseDiagDir(), ROAD_NONE, and TileOffsByDiagDir().

Referenced by CcBuildBridge(), CcBuildRoadTunnel(), and CcRoadStop().

static void PlaceRoad_Bridge | ( | TileIndex | tile,
|  | Window * | w
| ) |  |
| static

Callback to start placing a bridge.

Parameters

  tile | Start tile of the bridge.

Definition at line 76 of file road_gui.cpp.

References DDSP_BUILD_BRIDGE, GetOtherTunnelBridgeEnd(), IsBridgeTile(), Window::OnPlaceMouseUp(), VPM_X_OR_Y, and VpStartPlaceSizing().

Referenced by BuildRoadToolbarWindow::OnPlaceObject().

static void PlaceRoad_BusStation | ( | TileIndex | tile | ) |
| static

Callback for placing a bus station.

Parameters

  tile | Position to place the station.

Definition at line 244 of file road_gui.cpp.

References _remove_button_clicked, _settings_game, AXIS_X, DDSP_BUILD_BUSSTOP, DDSP_REMOVE_BUSSTOP, DIAGDIR_END, DiagDirToAxis(), GameSettings::station, StationSettings::station_spread, VPM_X_AND_Y, VPM_X_AND_Y_LIMITED, VPM_X_LIMITED, VPM_Y_LIMITED, and VpStartPlaceSizing().

Referenced by BuildRoadToolbarWindow::OnPlaceObject().

static void PlaceRoad_TruckStation | ( | TileIndex | tile | ) |
| static

Callback for placing a truck station.

Parameters

  tile | Position to place the station.

Definition at line 262 of file road_gui.cpp.

References _remove_button_clicked, _settings_game, AXIS_X, DDSP_BUILD_TRUCKSTOP, DDSP_REMOVE_TRUCKSTOP, DIAGDIR_END, DiagDirToAxis(), GameSettings::station, StationSettings::station_spread, VPM_X_AND_Y, VPM_X_AND_Y_LIMITED, VPM_X_LIMITED, VPM_Y_LIMITED, and VpStartPlaceSizing().

Referenced by BuildRoadToolbarWindow::OnPlaceObject().

static void PlaceRoadStop | ( | TileIndex | start_tile,
|  | TileIndex | end_tile,
|  | uint32 | p2,
|  | uint32 | cmd
| ) |  |
| static

Place a new road stop.

Parameters

  start_tile | First tile of the area.
  end_tile | Last tile of the area.
  p2 | bit 0: 0 For bus stops, 1 for truck stops. bit 2..3: The roadtypes. bit 5: Allow stations directly adjacent to other stations.
  cmd | Command to use.

See Also
  CcRoadStop()

Definition at line 224 of file road_gui.cpp.

References CcRoadStop(), DIAGDIR_END, OrthogonalTileArea::h, SB(), SetBit(), ShowSelectStationIfNeeded(), OrthogonalTileArea::tile, and OrthogonalTileArea::w.

Referenced by BuildRoadToolbarWindow::OnPlaceMouseUp().

static bool RoadToolbar_CtrlChanged | ( | Window * | w | ) |
| static

Updates the Remove button because of Ctrl state change.

Parameters

  w | window the button belongs to

Returns
  true iff the remove button was changed

Definition at line 295 of file road_gui.cpp.

References Window::IsWidgetDisabled(), Window::IsWidgetLowered(), ToggleRoadButton_Remove(), WID_ROT_AUTOROAD, WID_ROT_REMOVE, and WID_ROT_ROAD_X.

Referenced by BuildRoadToolbarWindow::OnClick(), and BuildRoadToolbarWindow::OnCTRLStateChange().

static EventState RoadToolbarGlobalHotkeys | ( | int | hotkey | ) |
| static

Handler for global hotkeys of the BuildRoadToolbarWindow.

Parameters

  hotkey | Hotkey

Returns
  ES_HANDLED if hotkey was accepted.

Definition at line 678 of file road_gui.cpp.

References ES_NOT_HANDLED, Window::OnHotkey(), ShowBuildRoadScenToolbar(), and ShowBuildRoadToolbar().

Window* ShowBuildRoadScenToolbar | ( |  | ) |
| read

Show the road building toolbar in the scenario editor.

Returns
  The just opened toolbar, or `NULL` if the toolbar was already open.

Definition at line 853 of file road_gui.cpp.

References ROADTYPE_ROAD, and TRANSPORT_ROAD.

Referenced by RoadToolbarGlobalHotkeys().

Window* ShowBuildRoadToolbar | ( | RoadType | roadtype | ) |
| read

Open the build road toolbar window.

If the terraform toolbar is linked to the toolbar, that window is also opened.

Returns
  newly opened road toolbar, or NULL if the toolbar could not be opened.

Definition at line 805 of file road_gui.cpp.

References _local_company, DeleteWindowByClass(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), ROADTYPE_ROAD, TRANSPORT_ROAD, and WC_BUILD_TOOLBAR.

Referenced by MenuClickBuildRoad(), MainToolbarWindow::OnHotkey(), and RoadToolbarGlobalHotkeys().

static void ToggleRoadButton_Remove | ( | Window * | w | ) |
| static

Toggles state of the Remove button of Build road toolbar.

Parameters

  w | window the button belongs to

Definition at line 282 of file road_gui.cpp.

References _remove_button_clicked, Window::IsWidgetLowered(), Window::SetWidgetDirty(), Window::ToggleWidgetLoweredState(), and WID_ROT_REMOVE.

Referenced by BuildRoadToolbarWindow::OnClick(), and RoadToolbar_CtrlChanged().

## Variable Documentation

const NWidgetPart _nested_build_road_depot_widgets[]
| static

Initial value:
{
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, WID_BROD_CAPTION), SetDataTip(STR_BUILD_DEPOT_ROAD_ORIENTATION_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
EndContainer(),
NWidget(WWT_PANEL, COLOUR_DARK_GREEN),
NWidget(NWID_SPACER), SetMinimalSize(0, 3),
NWidget(NWID_HORIZONTAL_LTR),
NWidget(NWID_SPACER), SetMinimalSize(3, 0), SetFill(1, 0),
NWidget(NWID_VERTICAL),
NWidget(WWT_PANEL, COLOUR_GREY, WID_BROD_DEPOT_NW), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP),
EndContainer(),
NWidget(NWID_SPACER), SetMinimalSize(0, 2),
NWidget(WWT_PANEL, COLOUR_GREY, WID_BROD_DEPOT_SW), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP),
EndContainer(),
EndContainer(),
NWidget(NWID_SPACER), SetMinimalSize(2, 0),
NWidget(NWID_VERTICAL),
NWidget(WWT_PANEL, COLOUR_GREY, WID_BROD_DEPOT_NE), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP),
EndContainer(),
NWidget(NWID_SPACER), SetMinimalSize(0, 2),
NWidget(WWT_PANEL, COLOUR_GREY, WID_BROD_DEPOT_SE), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP),
EndContainer(),
EndContainer(),
NWidget(NWID_SPACER), SetMinimalSize(3, 0), SetFill(1, 0),
EndContainer(),
NWidget(NWID_SPACER), SetMinimalSize(0, 3),
EndContainer(),
}

Definition at line 908 of file road_gui.cpp.

const NWidgetPart _nested_build_road_scen_widgets[]
| static

Initial value:
{
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_ROAD_TOOLBAR_ROAD_CONSTRUCTION_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
EndContainer(),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ROAD_X),
SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_X_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION),
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ROAD_Y),
SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_Y_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION),
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_AUTOROAD),
SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_AUTOROAD, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_AUTOROAD),
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_DEMOLISH),
SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
NWidget(WWT_PANEL, COLOUR_DARK_GREEN, -1), SetMinimalSize(0, 22), SetFill(1, 1), EndContainer(),
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ONE_WAY),
SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_ONE_WAY, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_ONE_WAY_ROAD),
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUILD_BRIDGE),
SetFill(0, 1), SetMinimalSize(43, 22), SetDataTip(SPR_IMG_BRIDGE, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_BRIDGE),
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUILD_TUNNEL),
SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_TUNNEL, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_TUNNEL),
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_REMOVE),
SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_REMOVE, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR_ROAD),
EndContainer(),
}

Definition at line 814 of file road_gui.cpp.

const RoadTypeInfo _road_type_infos[]
| static

Initial value:
{
{
STR_ERROR_CAN_T_BUILD_ROAD_HERE,
STR_ERROR_CAN_T_REMOVE_ROAD_FROM,
STR_ERROR_CAN_T_BUILD_ROAD_DEPOT,
{ STR_ERROR_CAN_T_BUILD_BUS_STATION, STR_ERROR_CAN_T_BUILD_TRUCK_STATION },
{ STR_ERROR_CAN_T_REMOVE_BUS_STATION, STR_ERROR_CAN_T_REMOVE_TRUCK_STATION },
{ STR_STATION_BUILD_BUS_ORIENTATION, STR_STATION_BUILD_TRUCK_ORIENTATION },
{ STR_STATION_BUILD_BUS_ORIENTATION_TOOLTIP, STR_STATION_BUILD_TRUCK_ORIENTATION_TOOLTIP },
SPR_CURSOR_ROAD_NESW,
SPR_CURSOR_ROAD_NWSE,
SPR_CURSOR_AUTOROAD,
},
{
STR_ERROR_CAN_T_BUILD_TRAMWAY_HERE,
STR_ERROR_CAN_T_REMOVE_TRAMWAY_FROM,
STR_ERROR_CAN_T_BUILD_TRAM_DEPOT,
{ STR_ERROR_CAN_T_BUILD_PASSENGER_TRAM_STATION, STR_ERROR_CAN_T_BUILD_CARGO_TRAM_STATION },
{ STR_ERROR_CAN_T_REMOVE_PASSENGER_TRAM_STATION, STR_ERROR_CAN_T_REMOVE_CARGO_TRAM_STATION },
{ STR_STATION_BUILD_PASSENGER_TRAM_ORIENTATION, STR_STATION_BUILD_CARGO_TRAM_ORIENTATION },
{ STR_STATION_BUILD_PASSENGER_TRAM_ORIENTATION_TOOLTIP, STR_STATION_BUILD_CARGO_TRAM_ORIENTATION_TOOLTIP },
SPR_CURSOR_TRAMWAY_NESW,
SPR_CURSOR_TRAMWAY_NWSE,
SPR_CURSOR_AUTOTRAM,
},
}

What errors/cursors must be shown for several types of roads.

Definition at line 130 of file road_gui.cpp.

Hotkey roadtoolbar_hotkeys[]
| static

Initial value:
{
Hotkey('1', "build_x", WID_ROT_ROAD_X),
Hotkey('2', "build_y", WID_ROT_ROAD_Y),
Hotkey('3', "autoroad", WID_ROT_AUTOROAD),
Hotkey('4', "demolish", WID_ROT_DEMOLISH),
Hotkey('5', "depot", WID_ROT_DEPOT),
Hotkey('6', "bus_station", WID_ROT_BUS_STATION),
Hotkey('7', "truck_station", WID_ROT_TRUCK_STATION),
Hotkey('8', "oneway", WID_ROT_ONE_WAY),
Hotkey('B', "bridge", WID_ROT_BUILD_BRIDGE),
Hotkey('T', "tunnel", WID_ROT_BUILD_TUNNEL),
Hotkey('R', "remove", WID_ROT_REMOVE),
HOTKEY_LIST_END
}

Definition at line 700 of file road_gui.cpp.