OpenTTD Source 20241224-master-gf74b0cf984
road_cmd.cpp File Reference

Commands related to road tiles. More...

#include "stdafx.h"
#include "road.h"
#include "road_internal.h"
#include "viewport_func.h"
#include "command_func.h"
#include "company_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 "train.h"
#include "town.h"
#include "company_base.h"
#include "core/random_func.hpp"
#include "core/container_func.hpp"
#include "newgrf_debug.h"
#include "newgrf_railtype.h"
#include "newgrf_roadtype.h"
#include "timer/timer_game_calendar.h"
#include "genworld.h"
#include "company_gui.h"
#include "road_func.h"
#include "road_cmd.h"
#include "landscape_cmd.h"
#include "rail_cmd.h"
#include "table/strings.h"
#include "table/roadtypes.h"
#include "safeguards.h"
#include "table/road_land.h"

Go to the source code of this file.

Data Structures

struct  DrawRoadTileStruct
 

Typedefs

typedef std::vector< RoadVehicle * > RoadVehicleList
 Helper type for lists/vectors of road vehicles.
 

Functions

void ResetRoadTypes ()
 Reset all road type information to its default values.
 
void ResolveRoadTypeGUISprites (RoadTypeInfo *rti)
 
static bool CompareRoadTypes (const RoadType &first, const RoadType &second)
 Compare roadtypes based on their sorting order.
 
void InitRoadTypes ()
 Resolve sprites of custom road types.
 
RoadType AllocateRoadType (RoadTypeLabel label, RoadTramType rtt)
 Allocate a new road type label.
 
bool RoadVehiclesAreBuilt ()
 Verify whether a road vehicle is available.
 
void UpdateCompanyRoadInfrastructure (RoadType rt, Owner o, int count)
 Update road infrastructure counts for a company.
 
static Foundation GetRoadFoundation (Slope tileh, RoadBits bits)
 Get the foundationtype of a RoadBits Slope combination.
 
CommandCost CheckAllowRemoveRoad (TileIndex tile, RoadBits remove, Owner owner, RoadTramType rtt, DoCommandFlag flags, bool town_check)
 Is it allowed to remove the given road bits from the given tile?
 
static CommandCost RemoveRoad (TileIndex tile, DoCommandFlag flags, RoadBits pieces, RoadTramType rtt, bool town_check)
 Delete a piece of road.
 
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.
 
CommandCost CmdBuildRoad (DoCommandFlag flags, TileIndex tile, RoadBits pieces, RoadType rt, DisallowedRoadDirections toggle_drd, TownID town_id)
 Build a piece of road.
 
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.
 
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.
 
std::tuple< CommandCost, MoneyCmdRemoveLongRoad (DoCommandFlag flags, TileIndex end_tile, TileIndex start_tile, RoadType rt, Axis axis, bool start_half, bool end_half)
 Remove a long piece of road.
 
CommandCost CmdBuildRoadDepot (DoCommandFlag flags, TileIndex tile, RoadType rt, DiagDirection dir)
 Build a road depot.
 
static CommandCost RemoveRoadDepot (TileIndex tile, DoCommandFlag flags)
 
static CommandCost ClearTile_Road (TileIndex tile, DoCommandFlag flags)
 
static uint GetRoadSpriteOffset (Slope slope, RoadBits bits)
 Get the sprite offset within a spritegroup.
 
static bool DrawRoadAsSnowDesert (bool snow_or_desert, 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.
 
void DrawRoadTypeCatenary (const TileInfo *ti, RoadType rt, RoadBits rb)
 Draws the catenary for the RoadType of the given tile.
 
void DrawRoadCatenary (const TileInfo *ti)
 Draws the catenary for the given tile.
 
static void DrawRoadDetail (SpriteID img, const TileInfo *ti, int dx, int dy, int h, bool transparent)
 Draws details on/around the road.
 
void DrawRoadOverlays (const TileInfo *ti, PaletteID pal, const RoadTypeInfo *road_rti, const RoadTypeInfo *tram_rti, uint road_offset, uint tram_offset, bool draw_underlay)
 Draw road underlay and overlay sprites.
 
static SpriteID GetRoadGroundSprite (const TileInfo *ti, Roadside roadside, const RoadTypeInfo *rti, uint offset, bool snow_or_desert, PaletteID *pal)
 Get ground sprite to draw for a road tile.
 
void DrawRoadGroundSprites (const TileInfo *ti, RoadBits road, RoadBits tram, const RoadTypeInfo *road_rti, const RoadTypeInfo *tram_rti, Roadside roadside, bool snow_or_desert)
 Draw road ground sprites.
 
static void DrawRoadBits (TileInfo *ti)
 Draw ground sprite and road pieces.
 
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.
 
void UpdateNearestTownForRoadTiles (bool invalidate)
 Updates cached nearest town for all road tiles.
 
static int GetSlopePixelZ_Road (TileIndex tile, uint x, uint y, bool)
 
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, int)
 
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)
 
static VehicleUpdateRoadVehPowerProc (Vehicle *v, void *data)
 Update power of road vehicle under which is the roadtype being converted.
 
static bool CanConvertUnownedRoadType (Owner owner, RoadTramType rtt)
 Checks the tile and returns whether the current player is allowed to convert the roadtype to another roadtype without taking ownership.
 
static void ConvertRoadTypeOwner (TileIndex tile, uint num_pieces, Owner owner, RoadType from_type, RoadType to_type)
 Convert the ownership of the RoadType of the tile if applicable.
 
CommandCost CmdConvertRoad (DoCommandFlag flags, TileIndex tile, TileIndex area_start, RoadType to_type)
 Convert one road subtype to another.
 

Variables

RoadTypeInfo _roadtypes [ROADTYPE_END]
 
std::vector< RoadType_sorted_roadtypes
 
RoadTypes _roadtypes_hidden_mask
 
RoadTypes _roadtypes_type
 Bitmap of road/tram types.
 
static const RoadBits _invalid_tileh_slopes_road [2][15]
 Invalid RoadBits on slopes.
 
const uint8_t _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 uint8_t _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.
 
const TileTypeProcs _tile_type_road_procs
 Tile callback functions for road tiles.
 

Detailed Description

Commands related to road tiles.

Definition in file road_cmd.cpp.

Typedef Documentation

◆ RoadVehicleList

typedef std::vector<RoadVehicle *> RoadVehicleList

Helper type for lists/vectors of road vehicles.

Definition at line 52 of file road_cmd.cpp.

Function Documentation

◆ AllocateRoadType()

◆ 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 950 of file road_cmd.cpp.

References DiagDirToRoadBits(), GetAnyRoadBits(), HasPowerOnRoad(), INVALID_ROADTYPE, IsValidTile(), MayHaveRoad(), ReverseDiagDir(), and TileOffsByDiagDir().

Referenced by CmdBuildLongRoad().

◆ CanConvertUnownedRoadType()

static bool CanConvertUnownedRoadType ( Owner  owner,
RoadTramType  rtt 
)
static

Checks the tile and returns whether the current player is allowed to convert the roadtype to another roadtype without taking ownership.

Parameters
ownerthe tile owner.
rttRoad/tram type.
Returns
whether the road is convertible

Definition at line 2394 of file road_cmd.cpp.

References OWNER_NONE, and OWNER_TOWN.

Referenced by CmdConvertRoad().

◆ ChangeTileOwner_Road()

static void ChangeTileOwner_Road ( TileIndex  tile,
Owner  old_owner,
Owner  new_owner 
)
static

Definition at line 2284 of file road_cmd.cpp.

◆ CheckAllowRemoveRoad()

CommandCost CheckAllowRemoveRoad ( TileIndex  tile,
RoadBits  remove,
Owner  owner,
RoadTramType  rtt,
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 262 of file road_cmd.cpp.

References _cheats, _current_company, _settings_game, ChangeTownRating(), CheckforTownRating(), CheckOwnership(), ClosestTownFromTile(), GameSettings::construction, ConstructionSettings::extra_dynamite, CommandCost::Failed(), GetAnyRoadBits(), 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(), KillFirstBit(), Cheats::magic_bulldozer, OWNER_NONE, OWNER_TOWN, OWNER_WATER, RATING_ROAD_DOWN_STEP_EDGE, RATING_ROAD_DOWN_STEP_INNER, RATING_ROAD_MINIMUM, ROAD_NE, ROAD_NONE, ROAD_NW, ROAD_REMOVE, ROAD_SE, ROAD_SW, SetDParam(), TileAddXY(), and Cheat::value.

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 545 of file road_cmd.cpp.

References _invalid_tileh_slopes_road, _settings_game, ConstructionSettings::build_on_slopes, CLRBITS, CMD_ERROR, GameSettings::construction, EXPENSES_CONSTRUCTION, FOUNDATION_NONE, GetHighestSlopeCorner(), GetRoadFoundation(), HasExactlyOneBit(), IsSlopeWithOneCornerRaised(), IsSteepSlope(), IsStraightRoad(), MirrorRoadBits(), ROAD_NONE, SLOPE_FLAT, and SlopeWithOneCornerRaised().

Referenced by CmdBuildRoad().

◆ ClearTile_Road()

static CommandCost ClearTile_Road ( TileIndex  tile,
DoCommandFlag  flags 
)
static

Definition at line 1234 of file road_cmd.cpp.

◆ ClickTile_Road()

static bool ClickTile_Road ( TileIndex  tile)
static

Definition at line 2080 of file road_cmd.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
flagsoperation to perform
end_tileend tile of drag
start_tilestart tile of drag
rtroad type
axisdirection
drdset road direction
start_halfstart 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_halfend 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_aidefines 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 979 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(), MP_TUNNELBRIDGE, ReverseDiagDir(), Map::Size(), 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
flagsoperation to perform
tiletile where to build road
piecesroad pieces to build (RoadBits)
rtroad type
toggle_drddisallowed directions to toggle
town_idthe town that is building the road (0 if not applicable)
Returns
the cost of this operation or an error

Definition at line 610 of file road_cmd.cpp.

References _current_company, _settings_game, CommandCost::AddCost(), AXIS_X, AXIS_Y, AxisToRoadBits(), AxisToTrack(), ConstructionSettings::build_on_slopes, Town::cache, CalcClosestTownFromTile(), CheckOwnership(), CheckRoadSlope(), CheckTileOwnership(), CMD_ERROR, ComplementRoadBits(), GameSettings::construction, CountBits(), ConstructionSettings::crossing_with_competitor, DC_EXEC, DiagDirToRoadBits(), DirtyCompanyInfrastructureWindows(), DistanceSquare(), DRD_NONE, EnsureNoVehicleOnGround(), EXPENSES_CONSTRUCTION, CommandCost::Failed(), GetAnyRoadBits(), CommandCost::GetCost(), GetCrossingRoadAxis(), GetCrossingRoadBits(), GetDisallowedRoadDirections(), GetDriveThroughStopAxis(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::GetIfValid(), GetOtherTunnelBridgeEnd(), GetRailReservationTrackBits(), GetRailTileType(), GetRailType(), GetRoadBits(), GetRoadFoundation(), GetRoadOwner(), GetRoadTileType(), GetTileOwner(), GetTileSlope(), GetTileType(), GetTrackBits(), GetTunnelBridgeDirection(), GetTunnelBridgeLength(), GetTunnelBridgeTransportType(), HasBit(), HasExactlyOneBit(), HasPowerOnRoad(), HasRoadWorks(), HasTileRoadType(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Company::infrastructure, INVALID_ROADTYPE, IsBridge(), IsDriveThroughStopTile(), IsNormalRoad(), IsNormalRoadTile(), IsSteepSlope(), IsStraightRoad(), IsTileType(), IsValidDisallowedRoadDirections(), 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(), IsValidRoadBits(), LEVELCROSSING_TRACKBIT_FACTOR, MakeRoadCrossing(), MakeRoadNormal(), MarkBridgeDirty(), MarkDirtyAdjacentLevelCrossingTiles(), MarkTileDirtyByTile(), MirrorRoadBits(), MP_RAILWAY, MP_ROAD, MP_STATION, MP_TUNNELBRIDGE, OtherAxis(), OWNER_DEITY, OWNER_NONE, OWNER_TOWN, CompanyInfrastructure::rail, RAIL_TILE_NORMAL, RailNoLevelCrossings(), ROAD_NONE, ROAD_TILE_CROSSING, ROAD_TILE_DEPOT, ROAD_TILE_NORMAL, ROAD_X, ROAD_Y, RoadBuildCost(), RoadNoLevelCrossing(), SetCrossingReservation(), SetDisallowedRoadDirections(), SetRoadBits(), SetRoadOwner(), SetRoadType(), SetTownIndex(), TownCache::squared_town_zone_radius, TRACK_BIT_X, TRACK_BIT_Y, TRANSPORT_ROAD, TUNNELBRIDGE_TRACKBIT_FACTOR, TunnelBridgeIsFree(), UpdateCompanyRoadInfrastructure(), UpdateLevelCrossing(), VALID_LEVEL_CROSSING_SLOPES, ValParamRoadType(), Town::xy, and YapfNotifyTrackLayoutChange().

◆ CmdBuildRoadDepot()

◆ CmdConvertRoad()

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

◆ 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
flagsoperation to perform
end_tileend tile of drag
start_tilestart tile of drag
rtroad type
axisdirection
start_halfstart tile starts in the 2nd half of tile
end_halfend tile starts in the 2nd half of tile (p2 & 2)
Returns
the cost of this operation or an error

Definition at line 1075 of file road_cmd.cpp.

References CommandCost::AddCost(), AXIS_X, AXIS_Y, AxisToRoadBits(), CMD_ERROR, DC_EXEC, EXPENSES_CONSTRUCTION, GetAvailableMoneyForCommand(), CommandCost::GetCost(), CommandCost::GetErrorMessage(), IsValidAxis(), RemoveRoad(), ROAD_NE, ROAD_NW, ROAD_SE, ROAD_SW, Map::Size(), CommandCost::Succeeded(), TileOffsByAxis(), TileX(), TileY(), and ValParamRoadType().

◆ CompareRoadTypes()

static bool CompareRoadTypes ( const RoadType first,
const RoadType second 
)
static

Compare roadtypes based on their sorting order.

Parameters
firstThe roadtype to compare to.
secondThe roadtype to compare.
Returns
True iff the first should be sorted before the second.

Definition at line 103 of file road_cmd.cpp.

References GetRoadTypeInfo(), and RoadTypeInfo::sorting_order.

Referenced by InitRoadTypes().

◆ ConvertRoadTypeOwner()

static void ConvertRoadTypeOwner ( TileIndex  tile,
uint  num_pieces,
Owner  owner,
RoadType  from_type,
RoadType  to_type 
)
static

Convert the ownership of the RoadType of the tile if applicable.

Parameters
tilethe tile of which convert ownership
num_piecesthe count of the roadbits to assign to the new owner
ownerthe current owner of the RoadType
from_typethe old road type
to_typethe new road type

Definition at line 2407 of file road_cmd.cpp.

References _current_company, DirtyCompanyInfrastructureWindows(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Company::infrastructure, MAX_COMPANIES, OWNER_NONE, CompanyInfrastructure::road, SetRoadOwner(), and UpdateCompanyRoadInfrastructure().

Referenced by CmdConvertRoad().

◆ DrawRoadAsSnowDesert()

static bool DrawRoadAsSnowDesert ( bool  snow_or_desert,
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
snow_or_desertIs snowy or desert tile
roadsideWhat sort of road this is
Returns
True if snow/desert road sprites should be used.

Definition at line 1366 of file road_cmd.cpp.

References _settings_game, GameSettings::game_creation, HasGrfMiscBit(), GameCreationSettings::landscape, ROADSIDE_BARREN, ROADSIDE_GRASS, and ROADSIDE_GRASS_ROAD_WORKS.

Referenced by DrawTile_Road(), and GetRoadGroundSprite().

◆ DrawRoadBits()

◆ DrawRoadCatenary()

void DrawRoadCatenary ( const TileInfo ti)

◆ 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 1875 of file road_cmd.cpp.

References _loaded_newgrf_features, _local_company, DiagDirToRoadBits(), DrawRailTileSeqInGUI(), DrawSprite(), RoadTypeInfo::flags, GetCustomRoadSprite(), GetRoadSpriteOffset(), GetRoadTypeInfo(), DrawTileSprites::ground, HasBit(), INVALID_TILE, ROTF_CATENARY, ROTSG_DEPOT, ROTSG_OVERLAY, SLOPE_FLAT, PalSpriteID::sprite, GRFLoadedFeatures::tram, and TRAMWAY_REPLACE_DEPOT_WITH_TRACK.

Referenced by BuildRoadDepotWindow::DrawWidget().

◆ DrawRoadDetail()

static void DrawRoadDetail ( SpriteID  img,
const TileInfo ti,
int  dx,
int  dy,
int  h,
bool  transparent 
)
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
transparentwhether the sprite should be transparent (used for roadside trees)

Definition at line 1497 of file road_cmd.cpp.

References AddSortableSpriteToDraw(), GetSlopePixelZ(), SLOPE_FLAT, TileInfo::tileh, TileInfo::x, TileInfo::y, and TileInfo::z.

Referenced by DrawRoadBits().

◆ DrawRoadGroundSprites()

void DrawRoadGroundSprites ( const TileInfo ti,
RoadBits  road,
RoadBits  tram,
const RoadTypeInfo road_rti,
const RoadTypeInfo tram_rti,
Roadside  roadside,
bool  snow_or_desert 
)

Draw road ground sprites.

Parameters
tiTileInfo
roadRoad bits
tramTram bits
road_rtiRoad road type information
tram_rtiTram road type information
roadsideRoadside type
snow_or_desertWhether to draw snow/desert ground sprites

Definition at line 1605 of file road_cmd.cpp.

References DrawGroundSprite(), DrawRoadOverlays(), GetRoadGroundSprite(), GetRoadSpriteOffset(), ROAD_NONE, and TileInfo::tileh.

Referenced by DrawRoadBits().

◆ DrawRoadOverlays()

void DrawRoadOverlays ( const TileInfo ti,
PaletteID  pal,
const RoadTypeInfo road_rti,
const RoadTypeInfo tram_rti,
uint  road_offset,
uint  tram_offset,
bool  draw_underlay 
)

Draw road underlay and overlay sprites.

Parameters
tiTileInfo
road_rtiRoad road type information
tram_rtiTram road type information
road_offsetRoad sprite offset (based on road bits)
tram_offsetTram sprite offset (based on road bits)
draw_underlayWhether to draw underlays

Definition at line 1515 of file road_cmd.cpp.

References DrawGroundSprite(), GetCustomRoadSprite(), ROTSG_GROUND, ROTSG_OVERLAY, and TileInfo::tile.

Referenced by DrawRoadGroundSprites(), DrawTile_Road(), and DrawTile_TunnelBridge().

◆ DrawRoadTypeCatenary()

void DrawRoadTypeCatenary ( const TileInfo ti,
RoadType  rt,
RoadBits  rb 
)

◆ DrawTile_Road()

◆ GetFoundation_Road()

static Foundation GetFoundation_Road ( TileIndex  tile,
Slope  tileh 
)
static

Definition at line 1949 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 1301 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().

Referenced by CheckRoadSlope(), CmdBuildRoad(), DrawRoadBits(), and RemoveRoad().

◆ GetRoadGroundSprite()

static SpriteID GetRoadGroundSprite ( const TileInfo ti,
Roadside  roadside,
const RoadTypeInfo rti,
uint  offset,
bool  snow_or_desert,
PaletteID pal 
)
static

Get ground sprite to draw for a road tile.

Parameters
tiTileInof
roadsideRoad side type
rtiRoad type info
offsetRoad sprite offset
snow_or_desertWhether to get snow/desert ground sprite
[out]palPalette to draw.

Definition at line 1562 of file road_cmd.cpp.

References DrawRoadAsSnowDesert(), PALETTE_TO_BARE_LAND, ROADSIDE_BARREN, ROADSIDE_GRASS, ROADSIDE_GRASS_ROAD_WORKS, SlopeToSpriteOffset(), and TileInfo::tileh.

Referenced by DrawRoadGroundSprites().

◆ GetRoadSpriteOffset()

static uint GetRoadSpriteOffset ( Slope  slope,
RoadBits  bits 
)
static

Get the sprite offset within a spritegroup.

Parameters
slopeSlope
bitsRoadbits
Returns
Offset for the sprite within the spritegroup.

Definition at line 1336 of file road_cmd.cpp.

References SLOPE_FLAT, SLOPE_NE, SLOPE_NW, SLOPE_SE, and SLOPE_SW.

Referenced by DrawRoadDepotSprite(), DrawRoadGroundSprites(), DrawRoadTypeCatenary(), and DrawTile_Road().

◆ GetSlopePixelZ_Road()

static int GetSlopePixelZ_Road ( TileIndex  tile,
uint  x,
uint  y,
bool   
)
static

Definition at line 1934 of file road_cmd.cpp.

◆ GetTileDesc_Road()

static void GetTileDesc_Road ( TileIndex  tile,
TileDesc td 
)
static

Definition at line 2183 of file road_cmd.cpp.

◆ GetTileTrackStatus_Road()

static TrackStatus GetTileTrackStatus_Road ( TileIndex  tile,
TransportType  mode,
uint  sub_mode,
DiagDirection  side 
)
static

Definition at line 2108 of file road_cmd.cpp.

◆ InitRoadTypes()

void InitRoadTypes ( )

Resolve sprites of custom road types.

Definition at line 114 of file road_cmd.cpp.

References CompareRoadTypes(), RoadTypeInfo::flags, HasBit(), ROADTYPE_BEGIN, ROADTYPE_END, ROTF_HIDDEN, and SetBit().

Referenced by AfterLoadGRFs().

◆ RemoveRoad()

static CommandCost RemoveRoad ( TileIndex  tile,
DoCommandFlag  flags,
RoadBits  pieces,
RoadTramType  rtt,
bool  town_check 
)
static

Delete a piece of road.

Parameters
tiletile where to remove road from
flagsoperation to perform
piecesroadbits to remove
rtroadtype to remove
town_checkshould we check if the town allows removal?

Definition at line 325 of file road_cmd.cpp.

References _current_company, _invalid_tileh_slopes_road, _settings_game, CommandCost::AddCost(), AxisToRoadBits(), ConstructionSettings::build_on_slopes, CalcClosestTownFromTile(), CheckAllowRemoveRoad(), CMD_ERROR, ComplementRoadBits(), GameSettings::construction, CountBits(), DC_EXEC, DiagDirToAxis(), DirtyCompanyInfrastructureWindows(), DRD_NONE, EnsureNoVehicleOnGround(), EXPENSES_CONSTRUCTION, CommandCost::Failed(), FOUNDATION_NONE, GetCrossingRailBits(), GetCrossingRailTrack(), GetCrossingRoadAxis(), GetCrossingRoadBits(), GetHighestSlopeCorner(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::GetIfValid(), GetOtherTunnelBridgeEnd(), GetRailType(), GetRoadBits(), GetRoadFoundation(), GetRoadOwner(), GetRoadTileType(), GetTileOwner(), GetTileSlope(), GetTileType(), GetTunnelBridgeDirection(), GetTunnelBridgeLength(), GetTunnelBridgeTransportType(), HasCrossingReservation(), HasRoadWorks(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Company::infrastructure, INVALID_ROADTYPE, IsBridge(), IsDriveThroughStopTile(), IsRoadOwner(), IsSteepSlope(), IsStraightRoad(), IsTileOwner(), IsTileType(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::Iterate(), LEVELCROSSING_TRACKBIT_FACTOR, MarkBridgeDirty(), MarkTileDirtyByTile(), MayHaveRoad(), MirrorRoadBits(), MP_ROAD, MP_STATION, MP_TUNNELBRIDGE, OWNER_TOWN, OWNER_WATER, CompanyInfrastructure::rail, ROAD_NONE, ROAD_TILE_CROSSING, ROAD_TILE_DEPOT, ROAD_TILE_NORMAL, RoadClearCost(), SetDisallowedRoadDirections(), SetRoadBits(), SetRoadType(), SetTileOwner(), SetTownIndex(), SetTrackReservation(), SLOPE_ELEVATED, SLOPE_FLAT, SlopeWithOneCornerRaised(), TileVirtXY(), TRANSPORT_ROAD, TUNNELBRIDGE_TRACKBIT_FACTOR, TunnelBridgeIsFree(), UpdateAdjacentLevelCrossingTilesOnLevelCrossingRemoval(), UpdateCompanyRoadInfrastructure(), and YapfNotifyTrackLayoutChange().

Referenced by CmdRemoveLongRoad().

◆ RemoveRoadDepot()

static CommandCost RemoveRoadDepot ( TileIndex  tile,
DoCommandFlag  flags 
)
static

Definition at line 1207 of file road_cmd.cpp.

◆ ResetRoadTypes()

void ResetRoadTypes ( )

Reset all road type information to its default values.

Definition at line 67 of file road_cmd.cpp.

References _original_roadtypes, _roadtypes_type, lengthof, ROADTYPES_NONE, and ROADTYPES_TRAM.

Referenced by ResetNewGRFData().

◆ ResolveRoadTypeGUISprites()

void ResolveRoadTypeGUISprites ( RoadTypeInfo rti)

Definition at line 78 of file road_cmd.cpp.

◆ 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 179 of file road_cmd.cpp.

References SpecializedVehicle< T, Type >::Iterate().

Referenced by CheckRoadSide().

◆ TerraformTile_Road()

static CommandCost TerraformTile_Road ( TileIndex  tile,
DoCommandFlag  flags,
int  z_new,
Slope  tileh_new 
)
static

Definition at line 2338 of file road_cmd.cpp.

◆ TileLoop_Road()

static void TileLoop_Road ( TileIndex  tile)
static

Definition at line 1979 of file road_cmd.cpp.

◆ UpdateCompanyRoadInfrastructure()

◆ 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 1918 of file road_cmd.cpp.

References _generating_world, CalcClosestTownFromTile(), HasTownOwnedRoad(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, IsRoadDepot(), IsTileType(), Map::Iterate(), MP_ROAD, and SetTownIndex().

Referenced by AfterLoadGame(), CmdFoundTown(), FoundTownWindow::OnClick(), and Town::PostDestructor().

◆ UpdateRoadVehPowerProc()

static Vehicle * UpdateRoadVehPowerProc ( Vehicle v,
void *  data 
)
static

Update power of road vehicle under which is the roadtype being converted.

Definition at line 2378 of file road_cmd.cpp.

References SpecializedVehicle< T, Type >::From(), include(), BaseVehicle::type, and VEH_ROAD.

Referenced by CmdConvertRoad().

◆ VehicleEnter_Road()

static VehicleEnterTileStatus VehicleEnter_Road ( Vehicle v,
TileIndex  tile,
int  ,
int   
)
static

Definition at line 2257 of file road_cmd.cpp.

Variable Documentation

◆ _invalid_tileh_slopes_road

const RoadBits _invalid_tileh_slopes_road[2][15]
static

Invalid RoadBits on slopes.


Definition at line 202 of file road_cmd.cpp.

Referenced by CheckRoadSlope(), GetRoadFoundation(), and RemoveRoad().

◆ _road_sloped_sprites

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

Definition at line 1323 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 2172 of file road_cmd.cpp.

◆ _road_trackbits

const TrackBits _road_trackbits[16]
static
Initial value:
= {
}
@ TRACK_BIT_UPPER
Upper track.
Definition track_type.h:39
@ TRACK_BIT_LEFT
Left track.
Definition track_type.h:41
@ TRACK_BIT_Y
Y-axis track.
Definition track_type.h:38
@ TRACK_BIT_NONE
No track.
Definition track_type.h:36
@ TRACK_BIT_X
X-axis track.
Definition track_type.h:37
@ TRACK_BIT_LOWER
Lower track.
Definition track_type.h:40
@ TRACK_BIT_ALL
All possible tracks.
Definition track_type.h:50
@ TRACK_BIT_RIGHT
Right track.
Definition track_type.h:42

Definition at line 2089 of file road_cmd.cpp.

◆ _roadtypes

Definition at line 54 of file road_cmd.cpp.

◆ _roadtypes_hidden_mask

RoadTypes _roadtypes_hidden_mask

Definition at line 56 of file road_cmd.cpp.

◆ _roadtypes_type

RoadTypes _roadtypes_type

Bitmap of road/tram types.

Bit if set if a roadtype is tram.

Definition at line 62 of file road_cmd.cpp.

Referenced by AllocateRoadType(), ScenarioEditorToolbarWindow::OnPaint(), ResetRoadTypes(), and BuildRoadToolbarWindow::RoadTramToolbarGlobalHotkeys().

◆ _roadveh_enter_depot_dir

const uint8_t _roadveh_enter_depot_dir[4]
static
Initial value:
= {
}
@ TRACKDIR_X_NE
X-axis and direction to north-east.
Definition track_type.h:69
@ TRACKDIR_Y_SE
Y-axis and direction to south-east.
Definition track_type.h:70
@ TRACKDIR_X_SW
X-axis and direction to south-west.
Definition track_type.h:77
@ TRACKDIR_Y_NW
Y-axis and direction to north-west.
Definition track_type.h:78

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 2253 of file road_cmd.cpp.

◆ _sorted_roadtypes

std::vector<RoadType> _sorted_roadtypes

Definition at line 55 of file road_cmd.cpp.

◆ _tile_type_road_procs

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

Tile callback functions for road tiles.

Definition at line 50 of file landscape.cpp.

◆ _town_road_types

const Roadside _town_road_types[][2]
static
Initial value:
= {
}
@ ROADSIDE_PAVED
Road with paved sidewalks.
Definition road_map.h:480
@ ROADSIDE_STREET_LIGHTS
Road with street lights on paved sidewalks.
Definition road_map.h:481
@ ROADSIDE_GRASS
Road on grass.
Definition road_map.h:479
@ ROADSIDE_TREES
Road with trees on paved sidewalks.
Definition road_map.h:483

Definition at line 1958 of file road_cmd.cpp.

◆ _town_road_types_2

const Roadside _town_road_types_2[][2]
static