OpenTTD
Data Structures | Functions | Variables
road_cmd.cpp File Reference

Commands related to road tiles. More...

#include "stdafx.h"
#include "cmd_helper.h"
#include "road_internal.h"
#include "viewport_func.h"
#include "command_func.h"
#include "pathfinder/yapf/yapf_cache.h"
#include "depot_base.h"
#include "newgrf.h"
#include "autoslope.h"
#include "tunnelbridge_map.h"
#include "strings_func.h"
#include "vehicle_func.h"
#include "sound_func.h"
#include "tunnelbridge.h"
#include "cheat_type.h"
#include "effectvehicle_func.h"
#include "effectvehicle_base.h"
#include "elrail_func.h"
#include "roadveh.h"
#include "town.h"
#include "company_base.h"
#include "core/random_func.hpp"
#include "newgrf_railtype.h"
#include "date_func.h"
#include "genworld.h"
#include "company_gui.h"
#include "table/strings.h"
#include "safeguards.h"
#include "table/road_land.h"

Go to the source code of this file.

Data Structures

struct  DrawRoadTileStruct
 

Functions

bool RoadVehiclesAreBuilt ()
 Verify whether a road vehicle is available. More...
 
static Foundation GetRoadFoundation (Slope tileh, RoadBits bits)
 Get the foundationtype of a RoadBits Slope combination. More...
 
CommandCost CheckAllowRemoveRoad (TileIndex tile, RoadBits remove, Owner owner, RoadType rt, DoCommandFlag flags, bool town_check)
 Is it allowed to remove the given road bits from the given tile? More...
 
static CommandCost RemoveRoad (TileIndex tile, DoCommandFlag flags, RoadBits pieces, RoadType rt, bool crossing_check, bool town_check=true)
 Delete a piece of road. More...
 
static CommandCost CheckRoadSlope (Slope tileh, RoadBits *pieces, RoadBits existing, RoadBits other)
 Calculate the costs for roads on slopes Aside modify the RoadBits to fit on the slopes. More...
 
CommandCost CmdBuildRoad (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 Build a piece of road. More...
 
static bool CanConnectToRoad (TileIndex tile, RoadType rt, DiagDirection dir)
 Checks whether a road or tram connection can be found when building a new road or tram. More...
 
CommandCost CmdBuildLongRoad (TileIndex start_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 Build a long piece of road. More...
 
CommandCost CmdRemoveLongRoad (TileIndex start_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 Remove a long piece of road. More...
 
CommandCost CmdBuildRoadDepot (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 Build a road depot. More...
 
static CommandCost RemoveRoadDepot (TileIndex tile, DoCommandFlag flags)
 
static CommandCost ClearTile_Road (TileIndex tile, DoCommandFlag flags)
 
static bool DrawRoadAsSnowDesert (TileIndex tile, Roadside roadside)
 Should the road be drawn as a unpaved snow/desert road? By default, roads are always drawn as unpaved if they are on desert or above the snow line, but NewGRFs can override this for desert. More...
 
void DrawRoadCatenary (const TileInfo *ti, RoadBits tram)
 Draws the catenary for the given tile. More...
 
static void DrawRoadDetail (SpriteID img, const TileInfo *ti, int dx, int dy, int h)
 Draws details on/around the road. More...
 
static void DrawRoadBits (TileInfo *ti)
 Draw ground sprite and road pieces. More...
 
static void DrawTile_Road (TileInfo *ti)
 Tile callback function for rendering a road tile to the screen.
 
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...
 
static int GetSlopePixelZ_Road (TileIndex tile, uint x, uint y)
 
static Foundation GetFoundation_Road (TileIndex tile, Slope tileh)
 
static void TileLoop_Road (TileIndex tile)
 
static bool ClickTile_Road (TileIndex tile)
 
static TrackStatus GetTileTrackStatus_Road (TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
 
static void GetTileDesc_Road (TileIndex tile, TileDesc *td)
 
static VehicleEnterTileStatus VehicleEnter_Road (Vehicle *v, TileIndex tile, int x, int y)
 
static void ChangeTileOwner_Road (TileIndex tile, Owner old_owner, Owner new_owner)
 
static CommandCost TerraformTile_Road (TileIndex tile, DoCommandFlag flags, int z_new, Slope tileh_new)
 

Variables

static const RoadBits _invalid_tileh_slopes_road [2][15]
 Invalid RoadBits on slopes. More...
 
const byte _road_sloped_sprites [14]
 
static const Roadside _town_road_types [][2]
 
static const Roadside _town_road_types_2 [][2]
 
static const TrackBits _road_trackbits [16]
 
static const StringID _road_tile_strings []
 
static const byte _roadveh_enter_depot_dir [4]
 Given the direction the road depot is pointing, this is the direction the vehicle should be travelling in in order to enter the depot. More...
 
const TileTypeProcs _tile_type_road_procs
 Tile callback functions for road tiles. More...
 

Detailed Description

Commands related to road tiles.

Definition in file road_cmd.cpp.

Function Documentation

◆ CanConnectToRoad()

static bool CanConnectToRoad ( TileIndex  tile,
RoadType  rt,
DiagDirection  dir 
)
static

Checks whether a road or tram connection can be found when building a new road or tram.

Parameters
tileTile at which the road being built will end.
rtRoadtype of the road being built.
dirDirection that the road is following.
Returns
True if the next tile at dir direction is suitable for being connected directly by a second roadbit at the end of the road being built.

Definition at line 810 of file road_cmd.cpp.

References DiagDirToRoadBits(), GetAnyRoadBits(), ReverseDiagDir(), and TileOffsByDiagDir().

Referenced by CmdBuildLongRoad().

◆ CheckAllowRemoveRoad()

CommandCost CheckAllowRemoveRoad ( TileIndex  tile,
RoadBits  remove,
Owner  owner,
RoadType  rt,
DoCommandFlag  flags,
bool  town_check 
)

Is it allowed to remove the given road bits from the given tile?

Parameters
tilethe tile to remove the road from
removethe roadbits that are going to be removed
ownerthe actual owner of the roadbits of the tile
rtthe road type to remove the bits from
flagscommand flags
town_checkShall the town rating checked/affected
Returns
A succeeded command when it is allowed to remove the road bits, a failed command otherwise.

Definition at line 116 of file road_cmd.cpp.

Referenced by CanRemoveRoadWithStop(), and RemoveRoad().

◆ CheckRoadSlope()

static CommandCost CheckRoadSlope ( Slope  tileh,
RoadBits pieces,
RoadBits  existing,
RoadBits  other 
)
static

Calculate the costs for roads on slopes Aside modify the RoadBits to fit on the slopes.

Note
The RoadBits are modified too!
Parameters
tilehThe current slope
piecesThe RoadBits we want to add
existingThe existent RoadBits of the current type
otherThe other existent RoadBits
Returns
The costs for these RoadBits on this slope

Definition at line 418 of file road_cmd.cpp.

References _invalid_tileh_slopes_road, _settings_game, ConstructionSettings::build_on_slopes, CLRBITS, CMD_ERROR, GameSettings::construction, EXPENSES_CONSTRUCTION, GetHighestSlopeCorner(), IsSteepSlope(), ROAD_NONE, SLOPE_FLAT, and SlopeWithOneCornerRaised().

◆ CmdBuildLongRoad()

CommandCost CmdBuildLongRoad ( TileIndex  start_tile,
DoCommandFlag  flags,
uint32  p1,
uint32  p2,
const char *  text 
)

Build a long piece of road.

Parameters
start_tilestart tile of drag (the building cost will appear over this tile)
flagsoperation to perform
p1end tile of drag
p2various bitstuffed elements
  • p2 = (bit 0) - start tile starts in the 2nd half of tile (p2 & 1). Only used if bit 6 is set or if we are building a single tile
  • p2 = (bit 1) - end tile starts in the 2nd half of tile (p2 & 2). Only used if bit 6 is set or if we are building a single tile
  • p2 = (bit 2) - direction: 0 = along x-axis, 1 = along y-axis (p2 & 4)
  • p2 = (bit 3 + 4) - road type
  • p2 = (bit 5) - set road direction
  • p2 = (bit 6) - defines two different behaviors for this command:
    • 0 = 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
    • 1 = Fail if an obstacle is found. Always take into account bit 0 and 1. This behavior is used for scripts
textunused
Returns
the cost of this operation or an error

Definition at line 833 of file road_cmd.cpp.

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

◆ CmdBuildRoad()

CommandCost CmdBuildRoad ( TileIndex  tile,
DoCommandFlag  flags,
uint32  p1,
uint32  p2,
const char *  text 
)

Build a piece of road.

Parameters
tiletile where to build road
flagsoperation to perform
p1bit 0..3 road pieces to build (RoadBits) bit 4..5 road type bit 6..7 disallowed directions to toggle
p2the town that is building the road (0 if not applicable)
textunused
Returns
the cost of this operation or an error

Definition at line 484 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 ( TileIndex  tile,
DoCommandFlag  flags,
uint32  p1,
uint32  p2,
const char *  text 
)

◆ CmdRemoveLongRoad()

CommandCost CmdRemoveLongRoad ( TileIndex  start_tile,
DoCommandFlag  flags,
uint32  p1,
uint32  p2,
const char *  text 
)

Remove a long piece of road.

Parameters
start_tilestart tile of drag
flagsoperation to perform
p1end tile of drag
p2various bitstuffed elements
  • p2 = (bit 0) - start tile starts in the 2nd half of tile (p2 & 1)
  • p2 = (bit 1) - end tile starts in the 2nd half of tile (p2 & 2)
  • p2 = (bit 2) - direction: 0 = along x-axis, 1 = along y-axis (p2 & 4)
  • p2 = (bit 3 + 4) - road type
textunused
Returns
the cost of this operation or an error

Definition at line 938 of file road_cmd.cpp.

References AXIS_X, AXIS_Y, AxisToRoadBits(), CMD_ERROR, DC_EXEC, EXPENSES_CONSTRUCTION, GetAvailableMoneyForCommand(), CommandCost::GetCost(), HasBit(), IsInsideMM(), IsValidRoadType(), MapSize(), RemoveRoad(), ROAD_NE, ROAD_NW, ROAD_SE, ROAD_SW, CommandCost::Succeeded(), TileX(), and TileY().

◆ DrawRoadAsSnowDesert()

static bool DrawRoadAsSnowDesert ( TileIndex  tile,
Roadside  roadside 
)
static

Should the road be drawn as a unpaved snow/desert road? By default, roads are always drawn as unpaved if they are on desert or above the snow line, but NewGRFs can override this for desert.

Parameters
tileThe tile the road is on
roadsideWhat sort of road this is
Returns
True if snow/desert road sprites should be used.

Definition at line 1182 of file road_cmd.cpp.

References _settings_game, GameSettings::game_creation, IsOnSnow(), and GameCreationSettings::landscape.

◆ DrawRoadBits()

static void DrawRoadBits ( TileInfo ti)
static

Draw ground sprite and road pieces.

Parameters
tiTileInfo

Definition at line 1242 of file road_cmd.cpp.

References GetRoadBits(), ROADTYPE_ROAD, ROADTYPE_TRAM, and TileInfo::tile.

Referenced by DrawTile_Road().

◆ DrawRoadCatenary()

void DrawRoadCatenary ( const TileInfo ti,
RoadBits  tram 
)

Draws the catenary for the given tile.

Parameters
tiinformation about the tile (slopes, height etc)
tramthe roadbits for the tram

Definition at line 1194 of file road_cmd.cpp.

References IsBridgeAbove(), IsInvisibilitySet(), IsTransparencySet(), TileInfo::tile, and TO_CATENARY.

◆ DrawRoadDepotSprite()

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

Draw the road depot sprite.

Parameters
xThe x offset to draw at.
yThe y offset to draw at.
dirThe direction the depot must be facing.
rtThe road type of the depot to draw.

Definition at line 1425 of file road_cmd.cpp.

Referenced by BuildRoadDepotWindow::DrawWidget().

◆ DrawRoadDetail()

static void DrawRoadDetail ( SpriteID  img,
const TileInfo ti,
int  dx,
int  dy,
int  h 
)
static

Draws details on/around the road.

Parameters
imgthe sprite to draw
tithe tile to draw on
dxthe offset from the top of the BB of the tile
dythe offset from the top of the BB of the tile
hthe height of the sprite to draw

Definition at line 1229 of file road_cmd.cpp.

◆ GetRoadFoundation()

static Foundation GetRoadFoundation ( Slope  tileh,
RoadBits  bits 
)
static

Get the foundationtype of a RoadBits Slope combination.

Parameters
tilehThe Slope part
bitsThe RoadBits part
Returns
The resulting Foundation

Definition at line 1144 of file road_cmd.cpp.

References _invalid_tileh_slopes_road, FOUNDATION_INCLINED_X, FOUNDATION_INCLINED_Y, FOUNDATION_LEVELED, FOUNDATION_NONE, GetHighestSlopeCorner(), IsSlopeWithOneCornerRaised(), IsSteepSlope(), ROAD_NONE, ROAD_X, SLOPE_FLAT, and SlopeWithOneCornerRaised().

◆ RemoveRoad()

static CommandCost RemoveRoad ( TileIndex  tile,
DoCommandFlag  flags,
RoadBits  pieces,
RoadType  rt,
bool  crossing_check,
bool  town_check = true 
)
static

Delete a piece of road.

Parameters
tiletile where to remove road from
flagsoperation to perform
piecesroadbits to remove
rtroadtype to remove
crossing_checkshould we check if there is a tram track when we are removing road from crossing?
town_checkshould we check if the town allows removal?

Definition at line 180 of file road_cmd.cpp.

References CommandCost::AddCost(), AxisToRoadBits(), CheckAllowRemoveRoad(), CMD_ERROR, CMD_LANDSCAPE_CLEAR, DiagDirToAxis(), DoCommand(), EnsureNoVehicleOnGround(), EXPENSES_CONSTRUCTION, CommandCost::Failed(), GetOtherTunnelBridgeEnd(), GetRoadOwner(), GetRoadTypes(), GetTileType(), GetTunnelBridgeDirection(), GetTunnelBridgeLength(), GetTunnelBridgeTransportType(), HasBit(), IsDriveThroughStopTile(), IsTileType(), MP_ROAD, MP_STATION, MP_TUNNELBRIDGE, return_cmd_error, ROAD_NONE, ROADTYPE_TRAM, RoadTypeToRoadTypes(), TRANSPORT_ROAD, and TunnelBridgeIsFree().

Referenced by CmdRemoveLongRoad().

◆ RoadVehiclesAreBuilt()

bool RoadVehiclesAreBuilt ( )

Verify whether a road vehicle is available.

Returns
true if at least one road vehicle is available, false if not

Definition at line 47 of file road_cmd.cpp.

Referenced by CheckRoadSide().

◆ UpdateNearestTownForRoadTiles()

void UpdateNearestTownForRoadTiles ( bool  invalidate)

Updates cached nearest town for all road tiles.

Parameters
invalidateare we just invalidating cached data?
Precondition
invalidate == true implies _generating_world == true

Definition at line 1439 of file road_cmd.cpp.

Referenced by Town::PostDestructor().

Variable Documentation

◆ _invalid_tileh_slopes_road

const RoadBits _invalid_tileh_slopes_road[2][15]
static

Invalid RoadBits on slopes.

Definition at line 56 of file road_cmd.cpp.

Referenced by CheckRoadSlope(), and GetRoadFoundation().

◆ _road_sloped_sprites

const byte _road_sloped_sprites[14]
Initial value:
= {
0, 0, 2, 0,
0, 1, 0, 0,
3, 0, 0, 0,
0, 0
}

Definition at line 1166 of file road_cmd.cpp.

◆ _road_tile_strings

const StringID _road_tile_strings[]
static
Initial value:
= {
STR_LAI_ROAD_DESCRIPTION_ROAD,
STR_LAI_ROAD_DESCRIPTION_ROAD,
STR_LAI_ROAD_DESCRIPTION_ROAD,
STR_LAI_ROAD_DESCRIPTION_ROAD_WITH_STREETLIGHTS,
STR_LAI_ROAD_DESCRIPTION_ROAD,
STR_LAI_ROAD_DESCRIPTION_TREE_LINED_ROAD,
STR_LAI_ROAD_DESCRIPTION_ROAD,
STR_LAI_ROAD_DESCRIPTION_ROAD,
}

Definition at line 1661 of file road_cmd.cpp.

◆ _road_trackbits

const TrackBits _road_trackbits[16]
static
Initial value:
= {
TRACK_BIT_LEFT | TRACK_BIT_LOWER | TRACK_BIT_Y,
TRACK_BIT_LEFT | TRACK_BIT_UPPER | TRACK_BIT_X,
TRACK_BIT_RIGHT | TRACK_BIT_UPPER | TRACK_BIT_Y,
TRACK_BIT_RIGHT | TRACK_BIT_LOWER | TRACK_BIT_X,
}
Right track.
Definition: track_type.h:48
All possible tracks.
Definition: track_type.h:56
X-axis track.
Definition: track_type.h:43
Lower track.
Definition: track_type.h:46
Upper track.
Definition: track_type.h:45
Left track.
Definition: track_type.h:47
No track.
Definition: track_type.h:42
Y-axis track.
Definition: track_type.h:44

Definition at line 1590 of file road_cmd.cpp.

◆ _roadveh_enter_depot_dir

const byte _roadveh_enter_depot_dir[4]
static
Initial value:
= {
}
Y-axis and direction to north-west.
Definition: track_type.h:85
X-axis and direction to south-west.
Definition: track_type.h:84
Y-axis and direction to south-east.
Definition: track_type.h:77
X-axis and direction to north-east.
Definition: track_type.h:76

Given the direction the road depot is pointing, this is the direction the vehicle should be travelling in in order to enter the depot.

Definition at line 1734 of file road_cmd.cpp.

◆ _tile_type_road_procs

const TileTypeProcs _tile_type_road_procs
Initial value:
= {
GetSlopePixelZ_Road,
ClearTile_Road,
NULL,
GetTileDesc_Road,
GetTileTrackStatus_Road,
ClickTile_Road,
NULL,
TileLoop_Road,
ChangeTileOwner_Road,
NULL,
VehicleEnter_Road,
GetFoundation_Road,
TerraformTile_Road,
}
static void DrawTile_Road(TileInfo *ti)
Tile callback function for rendering a road tile to the screen.
Definition: road_cmd.cpp:1326

Tile callback functions for road tiles.

◆ _town_road_types

const Roadside _town_road_types[][2]
static
Initial value:
= {
{ ROADSIDE_PAVED, ROADSIDE_PAVED },
{ ROADSIDE_STREET_LIGHTS, ROADSIDE_PAVED }
}
Road with paved sidewalks.
Definition: road_map.h:450
Road on grass.
Definition: road_map.h:449
Road with trees on paved sidewalks.
Definition: road_map.h:452
Road with street lights on paved sidewalks.
Definition: road_map.h:451

Definition at line 1480 of file road_cmd.cpp.

◆ _town_road_types_2

const Roadside _town_road_types_2[][2]
static
Initial value:
= {
{ ROADSIDE_STREET_LIGHTS, ROADSIDE_PAVED },
{ ROADSIDE_STREET_LIGHTS, ROADSIDE_PAVED },
{ ROADSIDE_STREET_LIGHTS, ROADSIDE_PAVED }
}
Road with paved sidewalks.
Definition: road_map.h:450
Road on grass.
Definition: road_map.h:449
Road with street lights on paved sidewalks.
Definition: road_map.h:451

Definition at line 1488 of file road_cmd.cpp.