road_cmd.cpp File Reference

Commands related to road tiles. More...

#include "stdafx.h"
#include "cmd_helper.h"
#include "road_internal.h"
#include "landscape.h"
#include "viewport_func.h"
#include "command_func.h"
#include "pathfinder/yapf/yapf_cache.h"
#include "depot_base.h"
#include "newgrf.h"
#include "variables.h"
#include "autoslope.h"
#include "tunnelbridge_map.h"
#include "window_func.h"
#include "strings_func.h"
#include "vehicle_func.h"
#include "sound_func.h"
#include "tunnelbridge.h"
#include "cheat_type.h"
#include "functions.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 "table/strings.h"
#include "table/road_land.h"

Go to the source code of this file.

Data Structures

struct  DrawRoadTileStruct

Defines

#define M(x)   (1 << (x))

Functions

bool RoadVehiclesAreBuilt ()
 Verify whether a road vehicle is available.
static Foundation GetRoadFoundation (Slope tileh, RoadBits bits)
 Get the foundationtype of a RoadBits Slope combination.
bool 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?
static CommandCost RemoveRoad (TileIndex tile, DoCommandFlag flags, RoadBits pieces, RoadType rt, bool crossing_check, bool town_check=true)
 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 (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 Build a piece of road.
CommandCost CmdBuildLongRoad (TileIndex start_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 Build a long piece of road.
CommandCost CmdRemoveLongRoad (TileIndex start_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 Remove a long piece of road.
CommandCost CmdBuildRoadDepot (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 Build a road depot.
static CommandCost RemoveRoadDepot (TileIndex tile, DoCommandFlag flags)
static CommandCost ClearTile_Road (TileIndex tile, DoCommandFlag flags)
static bool AlwaysDrawUnpavedRoads (TileIndex tile, Roadside roadside)
 Whether to draw unpaved roads regardless of the town zone.
void DrawTramCatenary (const TileInfo *ti, RoadBits tram)
 Draws the catenary for the given tile.
static void DrawRoadDetail (SpriteID img, const TileInfo *ti, int dx, int dy, int h)
 Draws details on/around the road.
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)
void UpdateNearestTownForRoadTiles (bool invalidate)
 Updates cached nearest town for all road tiles.
static uint GetSlopeZ_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, uint z_new, Slope tileh_new)

Variables

static const uint32 VALID_LEVEL_CROSSING_SLOPES = (M(SLOPE_SEN) | M(SLOPE_ENW) | M(SLOPE_NWS) | M(SLOPE_NS) | M(SLOPE_WSE) | M(SLOPE_EW) | M(SLOPE_FLAT))
static const RoadBits _invalid_tileh_slopes_road [2][15]
const byte _road_sloped_sprites [14]
static const Roadside _town_road_types [][2]
static const Roadside _town_road_types_2 [][2]
static const byte _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.
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.


Function Documentation

static bool AlwaysDrawUnpavedRoads ( TileIndex  tile,
Roadside  roadside 
) [static]

Whether to draw unpaved roads regardless of the town zone.

By default, OpenTTD always draws roads as unpaved if they are on a desert tile or above the snowline. Newgrf files, however, can set a bit that allows paved roads to be built on desert tiles as they would be on grassy tiles.

Parameters:
tile The tile the road is on
roadside What sort of road this is
Returns:
True if the road should be drawn unpaved regardless of the roadside.

Definition at line 1032 of file road_cmd.cpp.

References _settings_game, GameSettings::game_creation, and GameCreationSettings::landscape.

Referenced by DrawRoadBits(), and DrawTile_Road().

bool 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:
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
Returns:
true when it is allowed to remove the road bits

Definition at line 120 of file road_cmd.cpp.

References _settings_game, ChangeTownRating(), CheckOwnership(), GameSettings::construction, ConstructionSettings::extra_dynamite, GetAnyRoadBits(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, 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_SE, ROAD_SW, ROADTYPE_ROAD, SetDParam(), TILE_ADDXY, and Cheat::value.

Referenced by CanRemoveRoadWithStop(), and RemoveRoad().

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:
tileh The current slope
pieces The RoadBits we want to add
existing The existent RoadBits of the current type
other The other existent RoadBits
Returns:
The costs for these RoadBits on this slope

Definition at line 368 of file road_cmd.cpp.

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

Referenced by CmdBuildRoad().

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

Build a long piece of road.

Parameters:
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

  • 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
  • p2 = (bit 5) - set road direction
  • p2 = (bit 6) - 0 = build up to an obstacle, 1 = fail if an obstacle is found (used for AIs).
text unused
Returns:
the cost of this operation or an error

Definition at line 717 of file road_cmd.cpp.

References CommandCost::AddCost(), AXIS_X, AXIS_Y, AxisToDiagDir(), AxisToRoadBits(), CMD_BUILD_ROAD, CMD_ERROR, DiagDirToRoadBits(), DoCommand(), DRD_BOTH, DRD_NONE, DRD_NORTHBOUND, DRD_SOUTHBOUND, EXPENSES_CONSTRUCTION, CommandCost::Failed(), GetTunnelBridgeDirection(), HasBit(), INVALID_STRING_ID, IsBridge(), IsTileType(), IsValidRoadType(), 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.

Parameters:
tile tile where to build road
flags operation to perform
p1 bit 0..3 road pieces to build (RoadBits) bit 4..5 road type bit 6..7 disallowed directions to toggle
p2 the town that is building the road (0 if not applicable)
text unused
Returns:
the cost of this operation or an error

Definition at line 443 of file road_cmd.cpp.

References _settings_game, CommandCost::AddCost(), AXIS_X, AXIS_Y, AxisToRoadBits(), AxisToTrack(), ConstructionSettings::build_on_slopes, CheckOwnership(), CheckRoadSlope(), CMD_ERROR, CMD_LANDSCAPE_CLEAR, ComplementRoadBits(), GameSettings::construction, CountBits(), DC_EXEC, DiagDirToAxis(), DiagDirToRoadBits(), DoCommand(), DRD_NONE, EXPENSES_CONSTRUCTION, CommandCost::Failed(), GetAnyRoadBits(), CommandCost::GetCost(), GetDisallowedRoadDirections(), GetOtherRoadBits(), GetOtherTunnelBridgeEnd(), GetRailReservationTrackBits(), GetRailTileType(), GetRailType(), GetRoadFoundation(), GetRoadStopDir(), GetTileOwner(), GetTileSlope(), GetTileType(), GetTrackBits(), GetTunnelBridgeDirection(), GetTunnelBridgeLength(), GetTunnelBridgeTransportType(), HasBit(), HasVehicleOnTunnelBridge(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index, IsBridge(), IsDriveThroughStopTile(), IsSteepSlope(), IsStraightRoad(), IsTileType(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_town_pool >::IsValidID(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), IsValidRoadType(), MarkTileDirtyByTile(), MirrorRoadBits(), MP_RAILWAY, MP_ROAD, MP_STATION, MP_TUNNELBRIDGE, CommandCost::MultiplyCost(), OtherAxis(), OWNER_NONE, OWNER_TOWN, RAIL_TILE_NORMAL, RailNoLevelCrossings(), return_cmd_error, ROAD_NONE, ROAD_X, ROAD_Y, ROADTYPE_END, ROADTYPE_ROAD, ROADTYPE_TRAM, ROADTYPES_ROAD, RoadTypeToRoadTypes(), SetCrossingReservation(), SetDisallowedRoadDirections(), SetTownIndex(), TileOffsByDiagDir(), TRACK_BIT_X, TRACK_BIT_Y, TRANSPORT_ROAD, UpdateLevelCrossing(), ValParamRoadType(), and YapfNotifyTrackLayoutChange().

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

Build a road depot.

Parameters:
tile tile where to build the depot
flags operation to perform
p1 bit 0..1 entrance direction (DiagDirection) bit 2..3 road type
p2 unused
text unused
Returns:
the cost of this operation or an error
Todo:
When checking for the tile slope, distingush between "Flat land required" and "land sloped in wrong direction"

Definition at line 878 of file road_cmd.cpp.

References _settings_game, CommandCost::AddCost(), ConstructionSettings::build_on_slopes, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_depot_pool >::CanAllocateItem(), CanBuildDepotByTileh(), CMD_ERROR, CMD_LANDSCAPE_CLEAR, GameSettings::construction, DC_EXEC, DoCommand(), CommandCost::Failed(), GetTileSlope(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index, IsBridgeAbove(), IsSteepSlope(), IsValidRoadType(), MarkTileDirtyByTile(), MayHaveBridgeAbove(), return_cmd_error, SLOPE_FLAT, and ValParamRoadType().

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

Remove a long piece of road.

Parameters:
start_tile start tile of drag
flags operation to perform
p1 end tile of drag
p2 various 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
text unused
Returns:
the cost of this operation or an error

Definition at line 810 of file road_cmd.cpp.

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

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

Draws details on/around the road.

Parameters:
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 1079 of file road_cmd.cpp.

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

Referenced by DrawRoadBits().

void DrawTramCatenary ( const TileInfo ti,
RoadBits  tram 
)

Draws the catenary for the given tile.

Draw the catenary for tram road bits.

Parameters:
ti information about the tile (slopes, height etc)
tram the roadbits for the tram

Definition at line 1044 of file road_cmd.cpp.

References AddSortableSpriteToDraw(), BB_HEIGHT_UNDER_BRIDGE, GetBridgeHeight(), GetNorthernBridgeEnd(), GetTileMaxZ(), IsBridgeAbove(), IsInvisibilitySet(), IsTransparencySet(), MayHaveBridgeAbove(), SLOPE_FLAT, TileInfo::tile, TILE_HEIGHT, TileInfo::tileh, TO_CATENARY, TileInfo::x, TileInfo::y, and TileInfo::z.

Referenced by DrawRoadBits(), and DrawTile_Road().

static Foundation GetRoadFoundation ( Slope  tileh,
RoadBits  bits 
) [static]

Get the foundationtype of a RoadBits Slope combination.

Parameters:
tileh The Slope part
bits The RoadBits part
Returns:
The resulting Foundation

Definition at line 996 of file road_cmd.cpp.

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

Referenced by CheckRoadSlope(), CmdBuildRoad(), DrawRoadBits(), and 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:
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 179 of file road_cmd.cpp.

References _settings_game, CommandCost::AddCost(), ConstructionSettings::build_on_slopes, CheckAllowRemoveRoad(), CMD_ERROR, CMD_LANDSCAPE_CLEAR, ComplementRoadBits(), ComplementRoadTypes(), GameSettings::construction, CountBits(), DC_EXEC, DoCommand(), DRD_NONE, EXPENSES_CONSTRUCTION, FOUNDATION_NONE, GetOtherRoadBits(), GetOtherTunnelBridgeEnd(), GetRailType(), GetRoadFoundation(), GetTileOwner(), GetTileSlope(), GetTileType(), GetTunnelBridgeDirection(), GetTunnelBridgeLength(), GetTunnelBridgeTransportType(), HasBit(), HasCrossingReservation(), HasVehicleOnTunnelBridge(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index, IsBridge(), IsDriveThroughStopTile(), IsSteepSlope(), IsStraightRoad(), IsTileType(), MarkTileDirtyByTile(), MirrorRoadBits(), MP_ROAD, MP_STATION, MP_TUNNELBRIDGE, OWNER_TOWN, OWNER_WATER, return_cmd_error, ROAD_NONE, ROADTYPE_ROAD, ROADTYPE_TRAM, ROADTYPES_NONE, RoadTypeToRoadTypes(), SetDisallowedRoadDirections(), SetTileOwner(), SetTownIndex(), SetTrackReservation(), SLOPE_ELEVATED, SLOPE_FLAT, TileOffsByDiagDir(), TRANSPORT_ROAD, and YapfNotifyTrackLayoutChange().

Referenced by CmdRemoveLongRoad().

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

Referenced by CheckRoadSide(), and GameOptionsWindow::OnClick().

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

References HasTownOwnedRoad(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index, IsTileType(), MapSize(), MP_ROAD, and SetTownIndex().

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


Variable Documentation

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

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

const byte _road_trackbits[16] [static]
Initial value:
 {
  0x0, 0x0, 0x0, 0x10, 0x0, 0x2, 0x8, 0x1A, 0x0, 0x4, 0x1, 0x15, 0x20, 0x26, 0x29, 0x3F,
}

Definition at line 1432 of file road_cmd.cpp.

const byte _roadveh_enter_depot_dir[4] [static]
Initial value:

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

Initial value:
 {
  DrawTile_Road,           
  GetSlopeZ_Road,          
  ClearTile_Road,          
  NULL,                    
  GetTileDesc_Road,        
  GetTileTrackStatus_Road, 
  ClickTile_Road,          
  NULL,                    
  TileLoop_Road,           
  ChangeTileOwner_Road,    
  NULL,                    
  VehicleEnter_Road,       
  GetFoundation_Road,      
  TerraformTile_Road,      
}

Tile callback functions for road tiles.

const Roadside _town_road_types[][2] [static]
Initial value:
 {
  { ROADSIDE_GRASS,         ROADSIDE_GRASS },
  { ROADSIDE_PAVED,         ROADSIDE_PAVED },
  { ROADSIDE_PAVED,         ROADSIDE_PAVED },
  { ROADSIDE_TREES,         ROADSIDE_TREES },
  { ROADSIDE_STREET_LIGHTS, ROADSIDE_PAVED }
}

Definition at line 1322 of file road_cmd.cpp.

const Roadside _town_road_types_2[][2] [static]
Initial value:
 {
  { ROADSIDE_GRASS,         ROADSIDE_GRASS },
  { ROADSIDE_PAVED,         ROADSIDE_PAVED },
  { ROADSIDE_STREET_LIGHTS, ROADSIDE_PAVED },
  { ROADSIDE_STREET_LIGHTS, ROADSIDE_PAVED },
  { ROADSIDE_STREET_LIGHTS, ROADSIDE_PAVED }
}

Definition at line 1330 of file road_cmd.cpp.


Generated on Sat Nov 20 20:59:19 2010 for OpenTTD by  doxygen 1.6.1