OpenTTD
road.cpp File Reference

Generic road related functions. More...

#include "stdafx.h"
#include "rail_map.h"
#include "road_map.h"
#include "water_map.h"
#include "genworld.h"
#include "company_func.h"
#include "company_base.h"
#include "engine_base.h"
#include "date_func.h"
#include "landscape.h"
#include "road.h"
#include "road_func.h"
#include "roadveh.h"
#include "safeguards.h"

Go to the source code of this file.

Functions

static bool IsPossibleCrossing (const TileIndex tile, Axis ax)
 Return if the tile is a valid tile for a crossing. More...
 
RoadBits CleanUpRoadBits (const TileIndex tile, RoadBits org_rb)
 Clean up unnecessary RoadBits of a planned tile. More...
 
bool HasRoadTypeAvail (const CompanyID company, RoadType roadtype)
 Finds out, whether given company has a given RoadType available for construction. More...
 
static RoadTypes GetMaskForRoadTramType (RoadTramType rtt)
 
bool HasAnyRoadTypesAvail (CompanyID company, RoadTramType rtt)
 Test if any buildable RoadType is available for a company. More...
 
bool ValParamRoadType (RoadType roadtype)
 Validate functions for rail building. More...
 
RoadTypes AddDateIntroducedRoadTypes (RoadTypes current, Date date)
 Add the road types that are to be introduced at the given date. More...
 
RoadTypes GetCompanyRoadTypes (CompanyID company, bool introduces)
 Get the road types the given company can build. More...
 
RoadTypes GetRoadTypes (bool introduces)
 Get list of road types, regardless of company availability. More...
 
RoadType GetRoadTypeByLabel (RoadTypeLabel label, bool allow_alternate_labels)
 Get the road type for a given label. More...
 
RoadTypes ExistingRoadTypes (CompanyID c)
 Returns the available RoadSubTypes for the provided RoadType If the given company is valid then will be returned a list of the available sub types at the current date, while passing a deity company will make all the sub types available. More...
 
bool CanBuildRoadTypeInfrastructure (RoadType roadtype, CompanyID company)
 Check whether we can build infrastructure for the given RoadType. More...
 

Detailed Description

Generic road related functions.

Definition in file road.cpp.

Function Documentation

◆ AddDateIntroducedRoadTypes()

RoadTypes AddDateIntroducedRoadTypes ( RoadTypes  current,
Date  date 
)

Add the road types that are to be introduced at the given date.

Parameters
rtRoadtype
currentThe currently available roadtypes.
dateThe date for the introduction comparisons.
Returns
The road types that should be available when date introduced road types are taken into account as well.

Definition at line 155 of file road.cpp.

References AddDateIntroducedRoadTypes(), GetRoadTypeInfo(), RoadTypeInfo::introduces_roadtypes, RoadTypeInfo::introduction_date, RoadTypeInfo::introduction_required_roadtypes, IsInsideMM(), RoadTypeInfo::label, MAX_DAY, ROADTYPE_BEGIN, and ROADTYPE_END.

Referenced by AddDateIntroducedRoadTypes(), EnginesDailyLoop(), ExistingRoadTypes(), and HasRoadCatenaryDrawn().

◆ CanBuildRoadTypeInfrastructure()

bool CanBuildRoadTypeInfrastructure ( RoadType  roadtype,
CompanyID  company 
)

Check whether we can build infrastructure for the given RoadType.

This to disable building stations etc. when you are not allowed/able to have the RoadType yet.

Parameters
roadtypethe roadtype to check this for
companythe company id to check this for
any_dateto check only existing vehicles or if it is possible to build them in the future
Returns
true if there is any reason why you may build the infrastructure for the given roadtype

Definition at line 307 of file road.cpp.

◆ CleanUpRoadBits()

RoadBits CleanUpRoadBits ( const TileIndex  tile,
RoadBits  org_rb 
)

Clean up unnecessary RoadBits of a planned tile.

Parameters
tilecurrent tile
org_rbplanned RoadBits
Returns
optimised RoadBits

Definition at line 47 of file road.cpp.

References DIAGDIR_BEGIN, DIAGDIR_END, DiagDirToRoadBits(), GetAnyRoadBits(), GetTileType(), IsNormalRoadTile(), IsValidTile(), MirrorRoadBits(), MP_CLEAR, MP_ROAD, MP_STATION, MP_TREES, MP_TUNNELBRIDGE, ROAD_NONE, and TileAddByDiagDir().

◆ ExistingRoadTypes()

RoadTypes ExistingRoadTypes ( CompanyID  c)

Returns the available RoadSubTypes for the provided RoadType If the given company is valid then will be returned a list of the available sub types at the current date, while passing a deity company will make all the sub types available.

Parameters
rtthe RoadType to filter
cthe company ID to check the roadtype against
any_datewhether to return only currently introduced roadtypes or also future ones
Returns
the existing RoadSubTypes

Definition at line 272 of file road.cpp.

References _settings_game, AddDateIntroducedRoadTypes(), Company::avail_roadtypes, GameSettings::game_creation, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::GetIfValid(), GetRoadTypeInfo(), HasBit(), RoadTypeInfo::introduces_roadtypes, Engine::IterateType(), GameCreationSettings::landscape, MAX_DAY, OWNER_END, ROADTYPES_NONE, and VEH_ROAD.

◆ GetCompanyRoadTypes()

RoadTypes GetCompanyRoadTypes ( CompanyID  company,
bool  introduces 
)

Get the road types the given company can build.

Parameters
companythe company to get the road types for.
introducesIf true, include road types introduced by other road types
Returns
the road types.

Definition at line 188 of file road.cpp.

References _date, _settings_game, EngineInfo::climates, DAYS_IN_YEAR, GameSettings::game_creation, HasBit(), Engine::IterateType(), GameCreationSettings::landscape, ROADTYPES_NONE, and VEH_ROAD.

Referenced by HasRoadCatenaryDrawn(), and StartupEngines().

◆ GetRoadTypeByLabel()

RoadType GetRoadTypeByLabel ( RoadTypeLabel  label,
bool  allow_alternate_labels 
)

Get the road type for a given label.

Parameters
labelthe roadtype label.
allow_alternate_labelsSearch in the alternate label lists as well.
Returns
the roadtype.

Definition at line 243 of file road.cpp.

References RoadTypeInfo::alternate_labels, GetRoadTypeInfo(), INVALID_ROADTYPE, RoadTypeInfo::label, ROADTYPE_BEGIN, and ROADTYPE_END.

◆ GetRoadTypes()

RoadTypes GetRoadTypes ( bool  introduces)

Get list of road types, regardless of company availability.

Parameters
introducesIf true, include road types introduced by other road types
Returns
the road types.

Definition at line 216 of file road.cpp.

References _settings_game, EngineInfo::climates, GameSettings::game_creation, HasBit(), Engine::IterateType(), GameCreationSettings::landscape, ROADTYPES_NONE, and VEH_ROAD.

Referenced by HasRoadCatenaryDrawn(), and ScenarioEditorToolbarWindow::OnPaint().

◆ HasAnyRoadTypesAvail()

bool HasAnyRoadTypesAvail ( CompanyID  company,
RoadTramType  rtt 
)

Test if any buildable RoadType is available for a company.

Parameters
companythe company in question
Returns
true if company has any RoadTypes available

Definition at line 132 of file road.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::Get().

◆ HasRoadTypeAvail()

bool HasRoadTypeAvail ( const CompanyID  company,
RoadType  roadtype 
)

Finds out, whether given company has a given RoadType available for construction.

Parameters
companyID of company
roadtypetRoadType to test
Returns
true if company has the requested RoadType available

Definition at line 111 of file road.cpp.

References OWNER_DEITY, and OWNER_TOWN.

Referenced by HasRoadCatenaryDrawn(), and ValParamRoadType().

◆ IsPossibleCrossing()

static bool IsPossibleCrossing ( const TileIndex  tile,
Axis  ax 
)
static

Return if the tile is a valid tile for a crossing.

Parameters
tilethe current tile
axthe axis of the road over the rail
Returns
true if it is a valid tile

Definition at line 33 of file road.cpp.

References AXIS_X, GetFoundationSlope(), GetRailTileType(), GetTrackBits(), IsTileType(), MP_RAILWAY, RAIL_TILE_NORMAL, SLOPE_FLAT, TRACK_BIT_X, and TRACK_BIT_Y.

◆ ValParamRoadType()

bool ValParamRoadType ( RoadType  roadtype)

Validate functions for rail building.

Parameters
roadtyperoad type to check.
Returns
true if the current company may build the road.

Definition at line 142 of file road.cpp.

References _current_company, HasRoadTypeAvail(), and INVALID_ROADTYPE.

Referenced by CmdBuildBridge(), CmdBuildLongRoad(), CmdBuildRoadDepot(), CmdBuildRoadStop(), CmdBuildTunnel(), CmdConvertRoad(), CmdRemoveLongRoad(), HasRoadCatenaryDrawn(), and ShowBuildRoadToolbar().