@ -651,6 +651,7 @@ CommandCost CmdBuildSingleRail(TileIndex tile, DoCommandFlag flags, uint32 p1, u
if ( flags & DC_EXEC ) {
SubtractRailTunnelBridgeInfrastructure ( tile , other_end ) ;
SetCustomBridgeHeadTrackBits ( tile , future ) ;
SetTunnelBridgeGroundBits ( tile , IsRailCustomBridgeHead ( tile ) ? 2 : 0 ) ;
if ( secondary_piece ) {
SetSecondaryRailType ( tile , railtype ) ;
}
@ -939,6 +940,7 @@ CommandCost CmdRemoveSingleRail(TileIndex tile, DoCommandFlag flags, uint32 p1,
}
SetCustomBridgeHeadTrackBits ( tile , future ) ;
SetTunnelBridgeGroundBits ( tile , IsRailCustomBridgeHead ( tile ) ? 2 : 0 ) ;
AddRailTunnelBridgeInfrastructure ( tile , other_end ) ;
DirtyCompanyInfrastructureWindows ( _current_company ) ;
}
@ -2628,7 +2630,7 @@ static void DrawTrackFence_SW(const TileInfo *ti, SpriteID base_image, uint num_
* @ param ti Tile drawing information .
* @ param rti Rail type information .
*/
static void DrawTrackDetails ( const TileInfo * ti , const RailtypeInfo * rti )
void DrawTrackDetails ( const TileInfo * ti , const RailtypeInfo * rti , const RailGroundType rgt )
{
/* Base sprite for track fences.
* Note : Halftile slopes only have fences on the upper part . */
@ -2641,7 +2643,7 @@ static void DrawTrackDetails(const TileInfo *ti, const RailtypeInfo *rti)
assert ( num_sprites > 0 ) ;
switch ( GetRailGroundType( ti - > tile ) ) {
switch ( rgt ) {
case RAIL_GROUND_FENCE_NW : DrawTrackFence_NW ( ti , base_image , num_sprites ) ; break ;
case RAIL_GROUND_FENCE_SE : DrawTrackFence_SE ( ti , base_image , num_sprites ) ; break ;
case RAIL_GROUND_FENCE_SENW : DrawTrackFence_NW ( ti , base_image , num_sprites ) ;
@ -2698,7 +2700,7 @@ static inline void DrawTrackSprite(SpriteID sprite, PaletteID pal, const TileInf
static RailGroundType GetRailOrBridgeGroundType ( TileInfo * ti ) {
if ( IsTileType ( ti - > tile , MP_TUNNELBRIDGE ) ) {
return HasTunnelBridgeSnowOrDesert ( ti - > tile ) ? RAIL_GROUND_ICE_DESERT : RAIL_GROUND_GRASS ;
return GetTunnelBridgeGroundType ( ti - > tile ) ;
} else {
return GetRailGroundType ( ti - > tile ) ;
}
@ -3115,7 +3117,7 @@ static void DrawTile_Track(TileInfo *ti, DrawTileProcParams params)
DrawTrackBits ( ti , rails ) ;
if ( HasBit ( _display_opt , DO_FULL_DETAIL ) ) DrawTrackDetails ( ti , rti );
if ( HasBit ( _display_opt , DO_FULL_DETAIL ) ) DrawTrackDetails ( ti , rti , GetRailGroundType ( ti - > tile ) );
if ( HasRailCatenaryDrawn ( GetRailType ( ti - > tile ) , GetTileSecondaryRailTypeIfValid ( ti - > tile ) ) ) DrawRailCatenary ( ti ) ;
@ -3271,6 +3273,44 @@ static Foundation GetFoundation_Track(TileIndex tile, Slope tileh)
return IsPlainRail ( tile ) ? GetRailFoundation ( tileh , GetTrackBits ( tile ) ) : FlatteningFoundation ( tileh ) ;
}
RailGroundType RailTrackToFence ( TileIndex tile , TrackBits rail )
{
Owner owner = GetTileOwner ( tile ) ;
byte fences = 0 ;
for ( DiagDirection d = DIAGDIR_BEGIN ; d < DIAGDIR_END ; d + + ) {
static const TrackBits dir_to_trackbits [ DIAGDIR_END ] = { TRACK_BIT_3WAY_NE , TRACK_BIT_3WAY_SE , TRACK_BIT_3WAY_SW , TRACK_BIT_3WAY_NW } ;
/* Track bit on this edge => no fence. */
if ( ( rail & dir_to_trackbits [ d ] ) ! = TRACK_BIT_NONE ) continue ;
TileIndex tile2 = tile + TileOffsByDiagDir ( d ) ;
/* Show fences if it's a house, industry, object, road, tunnelbridge or not owned by us. */
if ( ! IsValidTile ( tile2 ) | | IsTileType ( tile2 , MP_HOUSE ) | | IsTileType ( tile2 , MP_INDUSTRY ) | |
IsTileType ( tile2 , MP_ROAD ) | | ( IsTileType ( tile2 , MP_OBJECT ) & & ! IsObjectType ( tile2 , OBJECT_OWNED_LAND ) ) | | IsTileType ( tile2 , MP_TUNNELBRIDGE ) | | ! IsTileOwner ( tile2 , owner ) ) {
fences | = 1 < < d ;
}
}
RailGroundType new_ground ;
switch ( fences ) {
case 0 : new_ground = RAIL_GROUND_GRASS ; break ;
case ( 1 < < DIAGDIR_NE ) : new_ground = RAIL_GROUND_FENCE_NE ; break ;
case ( 1 < < DIAGDIR_SE ) : new_ground = RAIL_GROUND_FENCE_SE ; break ;
case ( 1 < < DIAGDIR_SW ) : new_ground = RAIL_GROUND_FENCE_SW ; break ;
case ( 1 < < DIAGDIR_NW ) : new_ground = RAIL_GROUND_FENCE_NW ; break ;
case ( 1 < < DIAGDIR_NE ) | ( 1 < < DIAGDIR_SW ) : new_ground = RAIL_GROUND_FENCE_NESW ; break ;
case ( 1 < < DIAGDIR_SE ) | ( 1 < < DIAGDIR_NW ) : new_ground = RAIL_GROUND_FENCE_SENW ; break ;
case ( 1 < < DIAGDIR_NE ) | ( 1 < < DIAGDIR_SE ) : new_ground = RAIL_GROUND_FENCE_VERT1 ; break ;
case ( 1 < < DIAGDIR_NE ) | ( 1 < < DIAGDIR_NW ) : new_ground = RAIL_GROUND_FENCE_HORIZ2 ; break ;
case ( 1 < < DIAGDIR_SE ) | ( 1 < < DIAGDIR_SW ) : new_ground = RAIL_GROUND_FENCE_HORIZ1 ; break ;
case ( 1 < < DIAGDIR_SW ) | ( 1 < < DIAGDIR_NW ) : new_ground = RAIL_GROUND_FENCE_VERT2 ; break ;
default : NOT_REACHED ( ) ;
}
return new_ground ;
}
static void TileLoop_Track ( TileIndex tile )
{
RailGroundType old_ground = GetRailGroundType ( tile ) ;
@ -3352,39 +3392,7 @@ static void TileLoop_Track(TileIndex tile)
if ( IsPlainRail ( tile ) & & old_ground ! = RAIL_GROUND_BARREN ) { // wait until bottom is green
/* determine direction of fence */
TrackBits rail = GetTrackBits ( tile ) ;
Owner owner = GetTileOwner ( tile ) ;
byte fences = 0 ;
for ( DiagDirection d = DIAGDIR_BEGIN ; d < DIAGDIR_END ; d + + ) {
static const TrackBits dir_to_trackbits [ DIAGDIR_END ] = { TRACK_BIT_3WAY_NE , TRACK_BIT_3WAY_SE , TRACK_BIT_3WAY_SW , TRACK_BIT_3WAY_NW } ;
/* Track bit on this edge => no fence. */
if ( ( rail & dir_to_trackbits [ d ] ) ! = TRACK_BIT_NONE ) continue ;
TileIndex tile2 = tile + TileOffsByDiagDir ( d ) ;
/* Show fences if it's a house, industry, object, road, tunnelbridge or not owned by us. */
if ( ! IsValidTile ( tile2 ) | | IsTileType ( tile2 , MP_HOUSE ) | | IsTileType ( tile2 , MP_INDUSTRY ) | |
IsTileType ( tile2 , MP_ROAD ) | | ( IsTileType ( tile2 , MP_OBJECT ) & & ! IsObjectType ( tile2 , OBJECT_OWNED_LAND ) ) | | IsTileType ( tile2 , MP_TUNNELBRIDGE ) | | ! IsTileOwner ( tile2 , owner ) ) {
fences | = 1 < < d ;
}
}
switch ( fences ) {
case 0 : break ;
case ( 1 < < DIAGDIR_NE ) : new_ground = RAIL_GROUND_FENCE_NE ; break ;
case ( 1 < < DIAGDIR_SE ) : new_ground = RAIL_GROUND_FENCE_SE ; break ;
case ( 1 < < DIAGDIR_SW ) : new_ground = RAIL_GROUND_FENCE_SW ; break ;
case ( 1 < < DIAGDIR_NW ) : new_ground = RAIL_GROUND_FENCE_NW ; break ;
case ( 1 < < DIAGDIR_NE ) | ( 1 < < DIAGDIR_SW ) : new_ground = RAIL_GROUND_FENCE_NESW ; break ;
case ( 1 < < DIAGDIR_SE ) | ( 1 < < DIAGDIR_NW ) : new_ground = RAIL_GROUND_FENCE_SENW ; break ;
case ( 1 < < DIAGDIR_NE ) | ( 1 < < DIAGDIR_SE ) : new_ground = RAIL_GROUND_FENCE_VERT1 ; break ;
case ( 1 < < DIAGDIR_NE ) | ( 1 < < DIAGDIR_NW ) : new_ground = RAIL_GROUND_FENCE_HORIZ2 ; break ;
case ( 1 < < DIAGDIR_SE ) | ( 1 < < DIAGDIR_SW ) : new_ground = RAIL_GROUND_FENCE_HORIZ1 ; break ;
case ( 1 < < DIAGDIR_SW ) | ( 1 < < DIAGDIR_NW ) : new_ground = RAIL_GROUND_FENCE_VERT2 ; break ;
default : NOT_REACHED ( ) ;
}
new_ground = RailTrackToFence ( tile , rail ) ;
}
set_ground :