# HG changeset patch # User smatz # Date 1203351091 0 # Node ID 383a632de6662a848fddbdac9ec8408eb9cbe8e7 # Parent c1cddeb8511cf573dcbb986321aeead8f59b335f (svn r12177) -Codechange: use 'side' parameter in GetTileTrackStatus so there can be less checks in pathfinders for depots/stations/tunnels/bridges diff -r c1cddeb8511c -r 383a632de666 src/clear_cmd.cpp --- a/src/clear_cmd.cpp Mon Feb 18 14:59:30 2008 +0000 +++ b/src/clear_cmd.cpp Mon Feb 18 16:11:31 2008 +0000 @@ -315,7 +315,7 @@ /* not used */ } -static uint32 GetTileTrackStatus_Clear(TileIndex tile, TransportType mode, uint sub_mode) +static uint32 GetTileTrackStatus_Clear(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side) { return 0; } diff -r c1cddeb8511c -r 383a632de666 src/dummy_land.cpp --- a/src/dummy_land.cpp Mon Feb 18 14:59:30 2008 +0000 +++ b/src/dummy_land.cpp Mon Feb 18 16:11:31 2008 +0000 @@ -64,7 +64,7 @@ /* not used */ } -static uint32 GetTileTrackStatus_Dummy(TileIndex tile, TransportType mode, uint sub_mode) +static uint32 GetTileTrackStatus_Dummy(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side) { return 0; } diff -r c1cddeb8511c -r 383a632de666 src/industry_cmd.cpp --- a/src/industry_cmd.cpp Mon Feb 18 14:59:30 2008 +0000 +++ b/src/industry_cmd.cpp Mon Feb 18 16:11:31 2008 +0000 @@ -815,7 +815,7 @@ ShowIndustryViewWindow(GetIndustryIndex(tile)); } -static uint32 GetTileTrackStatus_Industry(TileIndex tile, TransportType mode, uint sub_mode) +static uint32 GetTileTrackStatus_Industry(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side) { return 0; } diff -r c1cddeb8511c -r 383a632de666 src/landscape.cpp --- a/src/landscape.cpp Mon Feb 18 14:59:30 2008 +0000 +++ b/src/landscape.cpp Mon Feb 18 16:11:31 2008 +0000 @@ -437,9 +437,18 @@ MarkTileDirtyByTile(tile); } -uint32 GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode) +/** Returns trackdirbits in lower two bytes and additional info about track status in upper two bytes + * If there is any trackbit at 'side', return all trackdirbits. + * For TRANSPORT_ROAD, return 0 if there is no roadbit (of given subtype) at given side. + * @param tile tile to get info about + * @param mode transport type + * @param sub_mode for TRANSPORT_ROAD, roadtypes to check + * @param side side we are entering from, INVALID_DIAGDIR to return all trackbits + * @return trackdirbits and other info depending on 'mode' + */ +uint32 GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side) { - return _tile_type_procs[GetTileType(tile)]->get_tile_track_status_proc(tile, mode, sub_mode); + return _tile_type_procs[GetTileType(tile)]->get_tile_track_status_proc(tile, mode, sub_mode, side); } void ChangeTileOwner(TileIndex tile, PlayerID old_player, PlayerID new_player) diff -r c1cddeb8511c -r 383a632de666 src/rail_cmd.cpp --- a/src/rail_cmd.cpp Mon Feb 18 14:59:30 2008 +0000 +++ b/src/rail_cmd.cpp Mon Feb 18 16:11:31 2008 +0000 @@ -2083,17 +2083,14 @@ } -static uint32 GetTileTrackStatus_Track(TileIndex tile, TransportType mode, uint sub_mode) +static uint32 GetTileTrackStatus_Track(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side) { if (mode != TRANSPORT_RAIL) return 0; switch (GetRailTileType(tile)) { default: NOT_REACHED(); - case RAIL_TILE_NORMAL: { - TrackBits rails = GetTrackBits(tile); - uint32 ret = rails * 0x101; - return (rails == TRACK_BIT_CROSS) ? ret | 0x40 : ret; - } + case RAIL_TILE_NORMAL: + return GetTrackBits(tile) * 0x101; case RAIL_TILE_SIGNALS: { uint32 ret = GetTrackBits(tile) * 0x101; @@ -2117,8 +2114,16 @@ return ret; } - case RAIL_TILE_DEPOT: return AxisToTrackBits(DiagDirToAxis(GetRailDepotDirection(tile))) * 0x101; - case RAIL_TILE_WAYPOINT: return GetRailWaypointBits(tile) * 0x101; + case RAIL_TILE_DEPOT: { + DiagDirection dir = GetRailDepotDirection(tile); + + if (side != INVALID_DIAGDIR && side != dir) return 0; + + return AxisToTrackBits(DiagDirToAxis(dir)) * 0x101; + } + + case RAIL_TILE_WAYPOINT: + return GetRailWaypointBits(tile) * 0x101; } } diff -r c1cddeb8511c -r 383a632de666 src/road_cmd.cpp --- a/src/road_cmd.cpp Mon Feb 18 14:59:30 2008 +0000 +++ b/src/road_cmd.cpp Mon Feb 18 16:11:31 2008 +0000 @@ -1314,7 +1314,7 @@ 0x0, 0x0, 0x0, 0x10, 0x0, 0x2, 0x8, 0x1A, 0x0, 0x4, 0x1, 0x15, 0x20, 0x26, 0x29, 0x3F, }; -static uint32 GetTileTrackStatus_Road(TileIndex tile, TransportType mode, uint sub_mode) +static uint32 GetTileTrackStatus_Road(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side) { switch (mode) { @@ -1326,22 +1326,35 @@ if ((GetRoadTypes(tile) & sub_mode) == 0) return 0; switch (GetRoadTileType(tile)) { case ROAD_TILE_NORMAL: { - RoadType rt = (RoadType)FindFirstBit(sub_mode); const uint drd_to_multiplier[DRD_END] = { 0x101, 0x100, 0x1, 0x0 }; + RoadType rt = (RoadType)FindFirstBit(sub_mode); + RoadBits bits = GetRoadBits(tile, rt); + + /* no roadbit at this side of tile, return 0 */ + if (side != INVALID_DIAGDIR && DiagDirToRoadBits(side) & bits == 0) return 0; + uint multiplier = drd_to_multiplier[rt == ROADTYPE_TRAM ? DRD_NONE : GetDisallowedRoadDirections(tile)]; - return HasRoadWorks(tile) ? 0 : _road_trackbits[GetRoadBits(tile, rt)] * multiplier; + return HasRoadWorks(tile) ? 0 : _road_trackbits[bits] * multiplier; } case ROAD_TILE_CROSSING: { - uint32 r = AxisToTrackBits(GetCrossingRoadAxis(tile)) * 0x101; + Axis axis = GetCrossingRoadAxis(tile); + if (side != INVALID_DIAGDIR && axis != DiagDirToAxis(side)) return 0; + + uint32 r = AxisToTrackBits(axis) * 0x101; if (IsCrossingBarred(tile)) r *= 0x10001; return r; } default: - case ROAD_TILE_DEPOT: - return AxisToTrackBits(DiagDirToAxis(GetRoadDepotDirection(tile))) * 0x101; + case ROAD_TILE_DEPOT: { + DiagDirection dir = GetRoadDepotDirection(tile); + + if (side != INVALID_DIAGDIR && side != dir) return 0; + + return AxisToTrackBits(DiagDirToAxis(dir)) * 0x101; + } } break; diff -r c1cddeb8511c -r 383a632de666 src/station_cmd.cpp --- a/src/station_cmd.cpp Mon Feb 18 14:59:30 2008 +0000 +++ b/src/station_cmd.cpp Mon Feb 18 16:11:31 2008 +0000 @@ -2280,7 +2280,7 @@ } -static uint32 GetTileTrackStatus_Station(TileIndex tile, TransportType mode, uint sub_mode) +static uint32 GetTileTrackStatus_Station(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side) { switch (mode) { case TRANSPORT_RAIL: @@ -2302,8 +2302,15 @@ break; case TRANSPORT_ROAD: - if ((GetRoadTypes(tile) & sub_mode) != 0 && IsRoadStopTile(tile)) { - return AxisToTrackBits(DiagDirToAxis(GetRoadStopDir(tile))) * 0x101; + if ((GetRoadTypes(tile) & sub_mode) != 0 && IsRoadStop(tile)) { + DiagDirection dir = GetRoadStopDir(tile); + Axis axis = DiagDirToAxis(dir); + + if (side != INVALID_DIAGDIR) { + if (axis != DiagDirToAxis(side) || (IsStandardRoadStopTile(tile) && dir != side)) return 0; + } + + return AxisToTrackBits(axis) * 0x101; } break; diff -r c1cddeb8511c -r 383a632de666 src/tile_cmd.h --- a/src/tile_cmd.h Mon Feb 18 14:59:30 2008 +0000 +++ b/src/tile_cmd.h Mon Feb 18 16:11:31 2008 +0000 @@ -13,6 +13,7 @@ #include "strings_type.h" #include "date_type.h" #include "player_type.h" +#include "direction_type.h" /** The returned bits of VehicleEnterTile. */ enum VehicleEnterTileStatus { @@ -81,7 +82,7 @@ * @param sub_mode used to differentiate between different kinds within the mode * @return the above mentions track status information */ -typedef uint32 GetTileTrackStatusProc(TileIndex tile, TransportType mode, uint sub_mode); +typedef uint32 GetTileTrackStatusProc(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side); typedef void GetProducedCargoProc(TileIndex tile, CargoID *b); typedef void ClickTileProc(TileIndex tile); typedef void AnimateTileProc(TileIndex tile); @@ -126,7 +127,7 @@ extern const TileTypeProcs * const _tile_type_procs[16]; -uint32 GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode); +uint32 GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side = INVALID_DIAGDIR); void GetAcceptedCargo(TileIndex tile, AcceptedCargo ac); void ChangeTileOwner(TileIndex tile, PlayerID old_player, PlayerID new_player); void AnimateTile(TileIndex tile); diff -r c1cddeb8511c -r 383a632de666 src/town_cmd.cpp --- a/src/town_cmd.cpp Mon Feb 18 14:59:30 2008 +0000 +++ b/src/town_cmd.cpp Mon Feb 18 16:11:31 2008 +0000 @@ -592,7 +592,7 @@ td->owner = OWNER_TOWN; } -static uint32 GetTileTrackStatus_Town(TileIndex tile, TransportType mode, uint sub_mode) +static uint32 GetTileTrackStatus_Town(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side) { /* not used */ return 0; diff -r c1cddeb8511c -r 383a632de666 src/tree_cmd.cpp --- a/src/tree_cmd.cpp Mon Feb 18 14:59:30 2008 +0000 +++ b/src/tree_cmd.cpp Mon Feb 18 16:11:31 2008 +0000 @@ -747,7 +747,7 @@ /* not used */ } -static uint32 GetTileTrackStatus_Trees(TileIndex tile, TransportType mode, uint sub_mode) +static uint32 GetTileTrackStatus_Trees(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side) { return 0; } diff -r c1cddeb8511c -r 383a632de666 src/tunnelbridge_cmd.cpp --- a/src/tunnelbridge_cmd.cpp Mon Feb 18 14:59:30 2008 +0000 +++ b/src/tunnelbridge_cmd.cpp Mon Feb 18 16:11:31 2008 +0000 @@ -1193,11 +1193,14 @@ } -static uint32 GetTileTrackStatus_TunnelBridge(TileIndex tile, TransportType mode, uint sub_mode) +static uint32 GetTileTrackStatus_TunnelBridge(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side) { TransportType transport_type = GetTunnelBridgeTransportType(tile); if (transport_type != mode || (transport_type == TRANSPORT_ROAD && (GetRoadTypes(tile) & sub_mode) == 0)) return 0; - return AxisToTrackBits(DiagDirToAxis(GetTunnelBridgeDirection(tile))) * 0x101; + + DiagDirection dir = GetTunnelBridgeDirection(tile); + if (side != INVALID_DIAGDIR && side != ReverseDiagDir(dir)) return 0; + return AxisToTrackBits(DiagDirToAxis(dir)) * 0x101; } static void ChangeTileOwner_TunnelBridge(TileIndex tile, PlayerID old_player, PlayerID new_player) diff -r c1cddeb8511c -r 383a632de666 src/unmovable_cmd.cpp --- a/src/unmovable_cmd.cpp Mon Feb 18 14:59:30 2008 +0000 +++ b/src/unmovable_cmd.cpp Mon Feb 18 16:11:31 2008 +0000 @@ -348,7 +348,7 @@ } -static uint32 GetTileTrackStatus_Unmovable(TileIndex tile, TransportType mode, uint sub_mode) +static uint32 GetTileTrackStatus_Unmovable(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side) { return 0; } diff -r c1cddeb8511c -r 383a632de666 src/water_cmd.cpp --- a/src/water_cmd.cpp Mon Feb 18 14:59:30 2008 +0000 +++ b/src/water_cmd.cpp Mon Feb 18 16:11:31 2008 +0000 @@ -1104,7 +1104,7 @@ } } -static uint32 GetTileTrackStatus_Water(TileIndex tile, TransportType mode, uint sub_mode) +static uint32 GetTileTrackStatus_Water(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side) { static const byte coast_tracks[] = {0, 32, 4, 0, 16, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0};