OpenTTD
|
Commands related to road tiles. More...
#include "stdafx.h"
#include "cmd_helper.h"
#include "road.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_debug.h"
#include "newgrf_railtype.h"
#include "newgrf_roadtype.h"
#include "date_func.h"
#include "genworld.h"
#include "company_gui.h"
#include "road_func.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. More... | |
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. More... | |
void | UpdateCompanyRoadInfrastructure (RoadType rt, Owner o, int count) |
Update road infrastructure counts for a company. 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, RoadTramType rtt, 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, RoadTramType rtt, 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 uint | GetRoadSpriteOffset (Slope slope, RoadBits bits) |
Get the sprite offset within a spritegroup. More... | |
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 | DrawRoadTypeCatenary (const TileInfo *ti, RoadType rt, RoadBits rb) |
Draws the catenary for the RoadType of the given tile. More... | |
void | DrawRoadCatenary (const TileInfo *ti) |
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... | |
void | DrawRoadOverlays (const TileInfo *ti, PaletteID pal, const RoadTypeInfo *road_rti, const RoadTypeInfo *tram_rti, uint road_offset, uint tram_offset) |
Draw road underlay and overlay sprites. More... | |
static SpriteID | GetRoadGroundSprite (const TileInfo *ti, Roadside roadside, const RoadTypeInfo *rti, uint offset, PaletteID *pal) |
Get ground sprite to draw for a road tile. 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) |
static Vehicle * | UpdateRoadVehPowerProc (Vehicle *v, void *data) |
Update power of road vehicle under which is the roadtype being converted. | |
static bool | CanConvertRoadType (Owner owner, RoadTramType rtt) |
Checks the tile and returns whether the current player is allowed to convert the roadtype to another roadtype. More... | |
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 applyable. More... | |
CommandCost | CmdConvertRoad (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
Convert one road subtype to another. More... | |
Variables | |
RoadTypeInfo | _roadtypes [ROADTYPE_END] |
std::vector< RoadType > | _sorted_roadtypes |
RoadTypes | _roadtypes_hidden_mask |
RoadTypes | _roadtypes_type |
Bitmap of road/tram types. More... | |
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... | |
Commands related to road tiles.
Definition in file road_cmd.cpp.
|
static |
Checks whether a road or tram connection can be found when building a new road or tram.
tile | Tile at which the road being built will end. |
rt | Roadtype of the road being built. |
dir | Direction that the road is following. |
Definition at line 953 of file road_cmd.cpp.
References IsValidTile(), MayHaveRoad(), and TileOffsByDiagDir().
Referenced by CmdBuildLongRoad().
|
static |
Checks the tile and returns whether the current player is allowed to convert the roadtype to another roadtype.
owner | the tile owner. |
rtt | Road/tram type. |
Definition at line 2277 of file road_cmd.cpp.
References OWNER_NONE, and OWNER_TOWN.
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?
tile | the tile to remove the road from |
remove | the roadbits that are going to be removed |
owner | the actual owner of the roadbits of the tile |
rt | the road type to remove the bits from |
flags | command flags |
town_check | Shall the town rating checked/affected |
Definition at line 266 of file road_cmd.cpp.
|
static |
Calculate the costs for roads on slopes Aside modify the RoadBits to fit on the slopes.
tileh | The current slope |
pieces | The RoadBits we want to add |
existing | The existent RoadBits of the current type |
other | The other existent RoadBits |
Definition at line 547 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().
CommandCost CmdBuildLongRoad | ( | TileIndex | start_tile, |
DoCommandFlag | flags, | ||
uint32 | p1, | ||
uint32 | p2, | ||
const char * | text | ||
) |
Build a long piece of road.
start_tile | start tile of drag (the building cost will appear over this tile) |
flags | operation to perform |
p1 | end tile of drag |
p2 | various bitstuffed elements
|
text | unused |
Definition at line 984 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(), MapSize(), MP_TUNNELBRIDGE, ReverseDiagDir(), TileOffsByDiagDir(), TileX(), TileY(), and ValParamRoadType().
CommandCost CmdBuildRoad | ( | TileIndex | tile, |
DoCommandFlag | flags, | ||
uint32 | p1, | ||
uint32 | p2, | ||
const char * | text | ||
) |
Build a piece of road.
tile | tile where to build road |
flags | operation to perform |
p1 | bit 0..3 road pieces to build (RoadBits) bit 4..9 road type bit 11..12 disallowed directions to toggle |
p2 | the town that is building the road (0 if not applicable) |
text | unused |
Definition at line 613 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.
CommandCost CmdBuildRoadDepot | ( | TileIndex | tile, |
DoCommandFlag | flags, | ||
uint32 | p1, | ||
uint32 | p2, | ||
const char * | text | ||
) |
Build a road depot.
tile | tile where to build the depot |
flags | operation to perform |
p1 | bit 0..1 entrance direction (DiagDirection) bit 2..7 road type |
p2 | unused |
text | unused |
Definition at line 1165 of file road_cmd.cpp.
References _settings_game, CommandCost::AddCost(), ConstructionSettings::build_on_slopes, CanBuildDepotByTileh(), CMD_ERROR, GameSettings::construction, EXPENSES_CONSTRUCTION, GetTileSlope(), return_cmd_error, SLOPE_FLAT, and ValParamRoadType().
CommandCost CmdConvertRoad | ( | TileIndex | tile, |
DoCommandFlag | flags, | ||
uint32 | p1, | ||
uint32 | p2, | ||
const char * | text | ||
) |
Convert one road subtype to another.
Not meant to convert from road to tram.
tile | end tile of road conversion drag |
flags | operation to perform |
p1 | start tile of drag |
p2 | various bitstuffed elements:
|
text | unused |
Definition at line 2327 of file road_cmd.cpp.
References CMD_ERROR, MapSize(), and ValParamRoadType().
CommandCost CmdRemoveLongRoad | ( | TileIndex | start_tile, |
DoCommandFlag | flags, | ||
uint32 | p1, | ||
uint32 | p2, | ||
const char * | text | ||
) |
Remove a long piece of road.
start_tile | start tile of drag |
flags | operation to perform |
p1 | end tile of drag |
p2 | various bitstuffed elements
|
text | unused |
Definition at line 1089 of file road_cmd.cpp.
References AXIS_X, AXIS_Y, AxisToRoadBits(), CMD_ERROR, EXPENSES_CONSTRUCTION, GetAvailableMoneyForCommand(), HasBit(), IsInsideMM(), MapSize(), ROAD_NE, ROAD_NW, ROAD_SE, ROAD_SW, TileX(), TileY(), and ValParamRoadType().
Compare roadtypes based on their sorting order.
first | The roadtype to compare to. |
second | The roadtype to compare. |
Definition at line 107 of file road_cmd.cpp.
|
static |
Convert the ownership of the RoadType of the tile if applyable.
tile | the tile of which convert ownership |
num_pieces | the count of the roadbits to assign to the new owner |
owner | the current owner of the RoadType |
from_type | the old road type |
to_type | the new road type |
Definition at line 2290 of file road_cmd.cpp.
References _current_company, MAX_COMPANIES, OWNER_NONE, and SetRoadOwner().
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.
tile | The tile the road is on |
roadside | What sort of road this is |
Definition at line 1363 of file road_cmd.cpp.
References _settings_game, GameSettings::game_creation, IsOnSnow(), and GameCreationSettings::landscape.
Referenced by GetRoadGroundSprite().
|
static |
Draw ground sprite and road pieces.
ti | TileInfo |
Definition at line 1576 of file road_cmd.cpp.
References GetRoadBits(), and TileInfo::tile.
Referenced by DrawTile_Road().
void DrawRoadCatenary | ( | const TileInfo * | ti | ) |
Draws the catenary for the given tile.
ti | information about the tile (slopes, height etc) |
Definition at line 1433 of file road_cmd.cpp.
References GetRoadBits(), IsNormalRoad(), IsTileType(), MP_ROAD, ROAD_NONE, and TileInfo::tile.
void DrawRoadDepotSprite | ( | int | x, |
int | y, | ||
DiagDirection | dir, | ||
RoadType | rt | ||
) |
Draw the road depot sprite.
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 1780 of file road_cmd.cpp.
Referenced by BuildRoadDepotWindow::DrawWidget().
Draws details on/around the road.
img | the sprite to draw |
ti | the tile to draw on |
dx | the offset from the top of the BB of the tile |
dy | the offset from the top of the BB of the tile |
h | the height of the sprite to draw |
Definition at line 1478 of file road_cmd.cpp.
void DrawRoadOverlays | ( | const TileInfo * | ti, |
PaletteID | pal, | ||
const RoadTypeInfo * | road_rti, | ||
const RoadTypeInfo * | tram_rti, | ||
uint | road_offset, | ||
uint | tram_offset | ||
) |
Draw road underlay and overlay sprites.
ti | TileInfo |
road_rti | Road road type information |
tram_rti | Tram road type information |
road_offset | Road sprite offset (based on road bits) |
tram_offset | Tram sprite offset (based on road bits) |
Definition at line 1495 of file road_cmd.cpp.
References DrawGroundSprite(), GetCustomRoadSprite(), ROTSG_GROUND, and TileInfo::tile.
Referenced by HasRoadCatenaryDrawn().
Draws the catenary for the RoadType of the given tile.
ti | information about the tile (slopes, height etc) |
rt | road type to draw catenary for |
rb | the roadbits for the tram |
Definition at line 1376 of file road_cmd.cpp.
References IsBridgeAbove(), IsTransparencySet(), TileInfo::tile, and TO_CATENARY.
|
static |
Get the foundationtype of a RoadBits Slope combination.
tileh | The Slope part |
bits | The RoadBits part |
Definition at line 1298 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().
|
static |
Get ground sprite to draw for a road tile.
ti | TileInof | |
roadside | Road side type | |
rti | Road type info | |
offset | Road sprite offset | |
[out] | pal | Palette to draw. |
Definition at line 1539 of file road_cmd.cpp.
References DrawRoadAsSnowDesert(), and TileInfo::tile.
Get the sprite offset within a spritegroup.
slope | Slope |
bits | Roadbits |
Definition at line 1333 of file road_cmd.cpp.
References SLOPE_FLAT, SLOPE_NE, SLOPE_NW, SLOPE_SE, and SLOPE_SW.
|
static |
Delete a piece of road.
tile | tile where to remove road from |
flags | operation to perform |
pieces | roadbits to remove |
rt | roadtype to remove |
crossing_check | should we check if there is a tram track when we are removing road from crossing? |
town_check | should we check if the town allows removal? |
Definition at line 330 of file road_cmd.cpp.
bool RoadVehiclesAreBuilt | ( | ) |
Verify whether a road vehicle is available.
true
if at least one road vehicle is available, false
if not Definition at line 183 of file road_cmd.cpp.
References SpecializedVehicle< RoadVehicle, Type >::Iterate().
Referenced by CheckRoadSide().
Update road infrastructure counts for a company.
rt | Road type to update count of. |
o | Owner of road piece. |
count | Number of road pieces to adjust. |
Definition at line 194 of file road_cmd.cpp.
References DirtyCompanyInfrastructureWindows(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::GetIfValid(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Company::infrastructure, INVALID_ROADTYPE, and CompanyInfrastructure::road.
Referenced by HasRoadCatenaryDrawn().
void UpdateNearestTownForRoadTiles | ( | bool | invalidate | ) |
Updates cached nearest town for all road tiles.
invalidate | are we just invalidating cached data? |
Definition at line 1823 of file road_cmd.cpp.
Referenced by Town::PostDestructor().
|
static |
Invalid RoadBits on slopes.
Definition at line 206 of file road_cmd.cpp.
Referenced by CheckRoadSlope(), and GetRoadFoundation().
const byte _road_sloped_sprites[14] |
Definition at line 1320 of file road_cmd.cpp.
|
static |
Definition at line 2054 of file road_cmd.cpp.
|
static |
Definition at line 1982 of file road_cmd.cpp.
RoadTypes _roadtypes_type |
Bitmap of road/tram types.
Bit if set if a roadtype is tram.
Definition at line 57 of file road_cmd.cpp.
Referenced by ScenarioEditorToolbarWindow::OnPaint().
|
static |
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 2135 of file road_cmd.cpp.
const TileTypeProcs _tile_type_road_procs |
Tile callback functions for road tiles.
|
static |
Definition at line 1864 of file road_cmd.cpp.
|
static |
Definition at line 1872 of file road_cmd.cpp.