OpenTTD Source
20240917-master-g9ab0a47812
|
Go to the documentation of this file.
171 return (tracks & mask) !=
TRACK_BIT_NONE ? tracks & mask : tracks;
181 return wires == 0 ? SPR_WIRE_BASE : wires;
191 return pylons == 0 ? SPR_PYLON_BASE : pylons;
238 static const uint HALF_TILE_HEIGHT =
TILE_HEIGHT / 2;
239 return (z + HALF_TILE_HEIGHT / 2) / HALF_TILE_HEIGHT * HALF_TILE_HEIGHT;
252 static const int _tunnel_wire_BB[4][4] = {
264 const int *BB_data = _tunnel_wire_BB[dir];
266 wire_base + sss->image_offset, PAL_NONE, ti->
x + sss->x_offset, ti->
y + sss->y_offset,
267 BB_data[2] - sss->x_offset, BB_data[3] - sss->y_offset,
BB_Z_SEPARATOR - sss->z_offset + 1,
270 BB_data[0] - sss->x_offset, BB_data[1] - sss->y_offset,
BB_Z_SEPARATOR - sss->z_offset
291 Corner halftile_corner = CORNER_INVALID;
298 uint8_t PCPstatus = 0;
299 uint8_t OverridePCP = 0;
320 static const uint edge_corners[] = {
321 1 << CORNER_N | 1 << CORNER_E,
322 1 << CORNER_S | 1 << CORNER_E,
323 1 << CORNER_S | 1 << CORNER_W,
324 1 << CORNER_N | 1 << CORNER_W,
326 SpriteID pylon_base = (halftile_corner != CORNER_INVALID &&
HasBit(edge_corners[i], halftile_corner)) ? pylon_halftile : pylon_normal;
334 wireconfig[TS_NEIGHBOUR] =
MaskWireBits(neighbour, trackconfig[TS_NEIGHBOUR]);
346 PPPpreferred[i] = 0xFF;
351 for (uint k = 0; k < NUM_TRACKS_AT_PCP; k++) {
353 if (TrackSourceTile[i][k] == TS_NEIGHBOUR &&
362 if (
HasBit(wireconfig[TrackSourceTile[i][k]], TracksAtPCP[i][k])) {
365 PCPpos = (TrackSourceTile[i][k] == TS_HOME) ? i :
ReverseDiagDir(i);
370 if (
HasBit(trackconfig[TrackSourceTile[i][k]], TracksAtPCP[i][k])) {
376 if (!
HasBit(PCPstatus, i)) {
403 if (tileh[TS_HOME] == tileh[TS_NEIGHBOUR] || (isflat[TS_HOME] && isflat[TS_NEIGHBOUR])) {
404 for (uint k = 0; k < NUM_IGNORE_GROUPS; k++) {
413 if ((PPPallowed[i] & PPPpreferred[i]) != 0) PPPallowed[i] &= PPPpreferred[i];
425 if (PPPallowed[i] != 0 &&
HasBit(PCPstatus, i) && !
HasBit(OverridePCP, i) &&
428 uint8_t temp = PPPorder[i][
GetTLG(ti->
tile)][k];
430 if (
HasBit(PPPallowed[i], temp)) {
431 uint x = ti->
x + x_pcp_offsets[i] + x_ppp_offsets[temp];
432 uint y = ti->
y + y_pcp_offsets[i] + y_ppp_offsets[temp];
465 Track halftile_track;
466 switch (halftile_corner) {
467 case CORNER_W: halftile_track =
TRACK_LEFT;
break;
468 case CORNER_S: halftile_track =
TRACK_LOWER;
break;
469 case CORNER_E: halftile_track =
TRACK_RIGHT;
break;
470 case CORNER_N: halftile_track =
TRACK_UPPER;
break;
476 SpriteID wire_base = (t == halftile_track) ? wire_halftile : wire_normal;
481 int tileh_selector = !(tileh[TS_HOME] % 3) * tileh[TS_HOME] / 3;
483 assert(PCPconfig != 0);
485 sss = &RailCatenarySpriteData[Wires[tileh_selector][t][PCPconfig]];
494 sss->x_size, sss->y_size, sss->z_size, (
GetSlopePixelZ(ti->
x + sss->x_offset, ti->
y + sss->y_offset,
true) + 4) / 8 * 8 + sss->z_offset,
521 if ((length % 2) && num == length) {
524 sss = &RailCatenarySpriteData[WIRE_X_FLAT_BOTH + offset];
527 sss = &RailCatenarySpriteData[WIRE_X_FLAT_SW + (num % 2) + offset];
535 sss->x_size, sss->y_size, sss->z_size, height + sss->z_offset,
547 uint x = ti->
x + x_pcp_offsets[PCPpos] + x_ppp_offsets[PPPpos];
548 uint y = ti->
y + y_pcp_offsets[PCPpos] + y_ppp_offsets[PPPpos];
549 AddSortableSpriteToDraw(pylon_base + pylon_sprites[PPPpos], PAL_NONE, x, y, 1, 1,
BB_HEIGHT_UNDER_BRIDGE, height,
IsTransparencySet(
TO_CATENARY), -1, -1);
557 uint x = ti->
x + x_pcp_offsets[PCPpos] + x_ppp_offsets[PPPpos];
558 uint y = ti->
y + y_pcp_offsets[PCPpos] + y_ppp_offsets[PPPpos];
559 AddSortableSpriteToDraw(pylon_base + pylon_sprites[PPPpos], PAL_NONE, x, y, 1, 1,
BB_HEIGHT_UNDER_BRIDGE, height,
IsTransparencySet(
TO_CATENARY), -1, -1);
579 wire_base + sss->image_offset, PAL_NONE, ti->
x + sss->x_offset, ti->
y + sss->y_offset,
580 sss->x_size, sss->y_size, sss->z_size,
600 bool disable = (new_value != 0);
631 if (t->IsFrontEngine()) {
@ INVALID_RAILTYPE
Flag for invalid railtype.
TrackBits DiagdirReachesTracks(DiagDirection diagdir)
Returns all tracks that can be reached when entering a tile from a given (diagonal) direction.
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
@ TCX_UPPER_HALFTILE
Querying information about the upper part of a tile with halftile foundation.
@ DIAGDIR_NE
Northeast, upper right on your monitor.
Direction ReverseDir(Direction d)
Return the reverse of a direction.
static TLG GetTLG(TileIndex t)
Get the tile location group of a tile.
static Pool::IterateWrapperFiltered< Engine, EngineTypeFilter > IterateType(VehicleType vt, size_t from=0)
Returns an iterable ensemble of all valid engines of the given type.
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
void SettingsDisableElrail(int32_t new_value)
_settings_game.disable_elrail callback
TileIndex GetOtherBridgeEnd(TileIndex tile)
Starting at one bridge end finds the other bridge end.
int GetTileMaxZ(TileIndex t)
Get top height of the tile inside the map.
Foundation GetBridgeFoundation(Slope tileh, Axis axis)
Get the foundation for a bridge.
static constexpr bool IsHalftileSlope(Slope s)
Checks for non-continuous slope on halftile foundations.
static const uint BB_Z_SEPARATOR
Separates the bridge/tunnel from the things under/above it.
uint GetTunnelBridgeLength(TileIndex begin, TileIndex end)
Calculates the length of a tunnel or a bridge (without end tiles)
bool IsTunnelTile(Tile t)
Is this a tunnel (entrance)?
@ TRACK_BIT_X
X-axis track.
const RailTypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
Tile information, used while rendering the tile.
@ DIR_BEGIN
Used to iterate.
@ RAILTYPE_RAIL
Standard non-electric rails.
@ RAILTYPE_ELECTRIC
Electric rails.
Slope GetTileSlope(TileIndex tile)
Return the slope of a given tile inside the map.
@ RTSG_PYLONS
Catenary pylons.
@ RAIL_TILE_SIGNALS
Normal rail tile with signals.
TrackBits GetCrossingRailBits(Tile tile)
Get the rail track bits of a level crossing.
bool IsTransparencySet(TransparencyOption to)
Check if the transparency option bit is set and if we aren't in the game menu (there's never transpar...
RailType
Enumeration for all possible railtypes.
@ TRACK_BIT_HORZ
Upper and lower track.
@ DIR_END
Used to iterate.
Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
@ VEH_TRAIN
Train vehicle type.
int GetBridgeHeight(TileIndex t)
Get the height ('z') of a bridge.
static void DrawRailCatenaryRailway(const TileInfo *ti)
Draws wires and, if required, pylons on a given tile.
This struct contains all the info that is needed to draw and construct tracks.
RailCatenarySprite
Refers to a certain element of the catenary.
static const uint BB_HEIGHT_UNDER_BRIDGE
Some values for constructing bounding boxes (BB).
static constexpr bool IsSteepSlope(Slope s)
Checks if a slope is steep.
bool IsRailStationTile(Tile t)
Is this tile a station tile and a rail station?
@ TRACK_BIT_VERT
Left and right track.
static const uint TILE_SIZE
Tile size in world coordinates.
@ VRF_EL_ENGINE_ALLOWED_NORMAL_RAIL
Electric train engine is allowed to run on normal rail. */.
DiagDirection
Enumeration for diagonal directions.
bool IsLevelCrossing(Tile t)
Return whether a tile is a level crossing.
void DrawRailCatenaryOnBridge(const TileInfo *ti)
Draws wires on a tunnel tile.
bool HasRailCatenary(RailType rt)
Test if a rail type has catenary.
int y
Y position of the tile in unit coordinates.
static constexpr Corner GetHalftileSlopeCorner(Slope s)
Returns the leveled halftile of a halftile slope.
@ TRACKDIR_BIT_Y_NW
Track y-axis, direction north-west.
RailType GetRailType(Tile t)
Gets the rail type of the given tile.
int GetSlopePixelZ(int x, int y, bool ground_vehicle)
Return world Z coordinate of a given point of a tile.
@ MP_ROAD
A tile with road (or tram tracks)
Axis GetRailStationAxis(Tile t)
Get the rail direction of a rail station.
Foundation
Enumeration for Foundations.
static TrackBits GetRailTrackBitsUniversal(TileIndex t, uint8_t *override)
Finds which Electrified Rail Bits are present on a given tile.
@ TRACK_BIT_MASK
Bitmask for the first 6 bits.
TrackBits TrackToTrackBits(Track track)
Maps a Track to the corresponding TrackBits value.
static const uint8_t AllowedPPPonPCP[DIAGDIR_END]
Which PPPs are possible at all on a given PCP.
bool TracksOverlap(TrackBits bits)
Checks if the given tracks overlap, ie form a crossing.
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
TrackBits DiagDirToDiagTrackBits(DiagDirection diagdir)
Maps a (4-way) direction to the diagonal track bits incidating with that diagdir.
Slope tileh
Slope of the tile.
static debug_inline TileType GetTileType(Tile tile)
Get the tiletype of a given tile.
@ TRACK_BIT_NONE
No track.
DiagDirection GetRailDepotDirection(Tile t)
Returns the direction the depot is facing to.
static const uint8_t DisallowedPPPofTrackAtPCP[TRACK_END][DIAGDIR_END]
Which pylons can definitely NOT be built.
static debug_inline bool IsRailDepot(Tile t)
Is this rail tile a rail depot?
Information about a rail vehicle.
Track GetRailStationTrack(Tile t)
Get the rail track of a rail station tile.
Iterable ensemble of each set bit in a value.
TrackBits
Allow incrementing of Track variables.
@ DIAGDIR_BEGIN
Used for iterations.
bool IsTunnel(Tile t)
Is this a tunnel (entrance)?
@ TRACKDIR_BIT_NONE
No track build.
DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
Corner
Enumeration of tile corners.
TileIndex GetNorthernBridgeEnd(TileIndex t)
Finds the northern end of a bridge starting at a middle tile.
bool HasStationTileRail(Tile t)
Has this station tile a rail? In other words, is this station tile a rail station or rail waypoint?
TrackdirBits DiagdirReachesTrackdirs(DiagDirection diagdir)
Returns all trackdirs that can be reached when entering a tile from a given (diagonal) direction.
uint ApplyFoundationToSlope(Foundation f, Slope &s)
Applies a foundation to a slope.
static void AdjustTileh(TileIndex tile, Slope *tileh)
Corrects the tileh for certain tile types.
bool IsBridgeTile(Tile t)
checks if there is a bridge on this tile
TrackBits TrackdirBitsToTrackBits(TrackdirBits bits)
Discards all directional information from a TrackdirBits value.
TileContext
Context for tile accesses.
bool CanStationTileHavePylons(Tile t)
Can tile t have catenary pylons?
'Train' is either a loco or a wagon.
@ TCX_NORMAL
Nothing special.
@ MP_TUNNELBRIDGE
Tunnel entry/exit and bridge heads.
@ FOUNDATION_NONE
The tile has no foundation, the slope remains unchanged.
TileIndex GetSouthernBridgeEnd(TileIndex t)
Finds the southern end of a bridge starting at a middle tile.
@ TRACK_BIT_CROSS
X-Y-axis cross.
static debug_inline RailTileType GetRailTileType(Tile t)
Returns the RailTileType (normal with or without signals, waypoint or depot).
static const uint8_t IgnoredPCP[NUM_IGNORE_GROUPS][TLG_END][DIAGDIR_END]
In case we have a straight line, we place pylon only every two tiles, so there are certain tiles whic...
TrackBits TrackStatusToTrackBits(TrackStatus ts)
Returns the present-track-information of a TrackStatus.
static const uint8_t OwnedPPPonPCP[DIAGDIR_END]
Which of the PPPs are inside the tile.
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
static debug_inline bool IsPlainRailTile(Tile t)
Checks whether the tile is a rail tile or rail tile with signals.
void AddSortableSpriteToDraw(SpriteID image, PaletteID pal, int x, int y, int w, int h, int dz, int z, bool transparent, int bb_offset_x, int bb_offset_y, int bb_offset_z, const SubSprite *sub)
Draw a (transparent) sprite at given coordinates with a given bounding box.
TrackBits GetTrackBits(Tile tile)
Gets the track bits of the given tile.
TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
static TrackBits MaskWireBits(TileIndex t, TrackBits tracks)
Masks out track bits when neighbouring tiles are unelectrified.
@ TRACKDIR_BIT_X_NE
Track x-axis, direction north-east.
static SpriteID GetPylonBase(TileIndex tile, TileContext context=TCX_NORMAL)
Get the base pylon sprite to use.
@ RTSG_WIRES
Catenary wires.
Track
These are used to specify a single track.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
RailTypes GetCompanyRailTypes(CompanyID company, bool introduces)
Get the rail types the given company can build.
@ SLOPE_STEEP
indicates the slope is steep
Slope
Enumeration for the slope-type.
Axis
Allow incrementing of DiagDirDiff variables.
@ TRANSPORT_RAIL
Transport by train.
Foundation GetRailFoundation(Slope tileh, TrackBits bits)
Checks if a track combination is valid on a specific slope and returns the needed foundation.
@ TCX_ON_BRIDGE
Querying information about stuff on the bridge (via some bridgehead).
constexpr bool HasAtMostOneBit(T value)
Test whether value has at most 1 bit set.
bool HasStationRail(Tile t)
Has this station tile a rail? In other words, is this station tile a rail station or rail waypoint?
static int GetPCPElevation(TileIndex tile, DiagDirection PCPpos)
Returns the Z position of a Pylon Control Point.
@ TRACK_LEFT
Track in the left corner of the tile (west)
RailType GetTileRailType(Tile tile)
Return the rail type of tile, or INVALID_RAILTYPE if this is no rail tile.
@ MP_STATION
A tile of a station.
@ RAIL_TILE_NORMAL
Normal rail tile without signals.
static SpriteID GetWireBase(TileIndex tile, TileContext context=TCX_NORMAL)
Get the base wire sprite to use.
TransportType GetTunnelBridgeTransportType(Tile t)
Tunnel: Get the transport type of the tunnel (road or rail) Bridge: Get the transport type of the bri...
@ DIAGDIR_END
Used for iterations.
@ TRACK_UPPER
Track in the upper corner of the tile (north)
Direction
Defines the 8 directions on the map.
RailType railtype
Railtype, mangled if elrail is disabled.
bool IsBridgeAbove(Tile t)
checks if a bridge is set above the ground of this tile
@ TRACK_BIT_Y
Y-axis track.
@ TRACK_LOWER
Track in the lower corner of the tile (south)
static Pool::IterateWrapper< Train > Iterate(size_t from=0)
Returns an iterable ensemble of all valid vehicles of type T.
RailType intended_railtype
Intended railtype, regardless of elrail being enabled or disabled.
void DrawRailCatenaryOnTunnel(const TileInfo *ti)
Draws wires on a tunnel tile.
Slope InclinedSlope(DiagDirection dir)
Returns the slope that is inclined in a specific direction.
@ TRACKDIR_BIT_Y_SE
Track y-axis, direction south-east.
int GetTileMaxPixelZ(TileIndex tile)
Get top height of the tile.
static const uint TILE_HEIGHT
Height of a height level in world coordinate AND in pixels in #ZOOM_BASE.
void DrawRailCatenary(const TileInfo *ti)
Draws overhead wires and pylons for electric railways.
static const DiagDirection PCPpositions[TRACK_END][2]
Maps a track bit onto two PCP positions.
int x
X position of the tile in unit coordinates.
TileIndex tile
Tile index.
@ CCF_TRACK
Valid changes while vehicle is driving, and possibly changing tracks.
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
TrackdirBits
Allow incrementing of Trackdir variables.
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
@ TRACK_Y
Track along the y-axis (north-west to south-east)
int GetBridgePixelHeight(TileIndex tile)
Get the height ('z') of a bridge in pixels.
Axis GetBridgeAxis(Tile t)
Get the axis of the bridge that goes over the tile.
static const uint8_t PreferredPPPofTrackAtPCP[TRACK_END][DIAGDIR_END]
Preferred points of each trackbit.
constexpr T ClrBit(T &x, const uint8_t y)
Clears a bit in a variable.
@ INVALID_TRACK
Flag for an invalid track.
int GetTilePixelZ(TileIndex tile)
Get bottom height of the tile.
TileIndex TileAddByDiagDir(TileIndex tile, DiagDirection dir)
Adds a DiagDir to a tile.
@ TRACK_X
Track along the x-axis (north-east to south-west)
bool CanStationTileHaveWires(Tile t)
Can tile t have catenary wires?
SpriteID GetCustomRailSprite(const RailTypeInfo *rti, TileIndex tile, RailTypeSpriteGroup rtsg, TileContext context, uint *num_results)
Get the sprite to draw for the given tile.
@ TRACKDIR_BIT_X_SW
Track x-axis, direction south-west.
@ RAILTYPES_RAIL
Non-electrified rails.
DiagDirection GetTunnelBridgeDirection(Tile t)
Get the direction pointing to the other end.
void ReinitGuiAfterToggleElrail(bool disable)
Re-initialize rail-build toolbar after toggling support for electric trains.
@ TRACK_RIGHT
Track in the right corner of the tile (east)
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.