1
0
Fork 0

Add: Add road depot platforms.

pull/8480/head
J0anJosep 2021-05-15 16:32:01 +02:00
parent a64aa22b67
commit ec5f239a9a
3 changed files with 101 additions and 5 deletions

View File

@ -183,6 +183,39 @@ uint GetRailDepotPlatformLength(TileIndex tile)
return len - 1; return len - 1;
} }
/**
* Get the length of a road depot platform.
* @pre IsDepotTypeTile(tile, TRANSPORT_ROAD)
* @param tile Tile to check
* @param rtt Whether to check for road or tram type.
* @return The length of the platform in tile length.
*/
uint GetRoadDepotPlatformLength(TileIndex tile, RoadTramType rtt)
{
assert(IsExtendedRoadDepotTile(tile));
DiagDirection dir = GetRoadDepotDirection(tile);
TileIndexDiff delta = TileOffsByDiagDir(dir);
TileIndex t = tile;
uint len = 0;
do {
len++;
if ((GetRoadBits(t, rtt) & DiagDirToRoadBits(dir)) == ROAD_NONE) break;
t -= delta;
} while (IsCompatibleRoadDepotTile(t, tile, rtt));
t = tile;
dir = ReverseDiagDir(dir);
do {
len++;
if ((GetRoadBits(t, rtt) & DiagDirToRoadBits(dir)) == ROAD_NONE) break;
t += delta;
} while (IsCompatibleRoadDepotTile(t, tile, rtt));
return len - 1;
}
/** /**
* Get the length of a rail depot platform in a given direction. * Get the length of a rail depot platform in a given direction.
@ -206,12 +239,37 @@ uint GetRailDepotPlatformLength(TileIndex tile, DiagDirection dir)
return length; return length;
} }
/**
* Get the length of a road depot platform in a given direction.
* @pre IsRoadDepotTile(tile)
* @param tile Tile to check
* @param dir Direction to check
* @param rtt Whether to check for road or tram type.
* @return The length of the platform in tile length in the given direction.
*/
uint GetRoadDepotPlatformLength(TileIndex tile, DiagDirection dir, RoadTramType rtt)
{
TileIndex start_tile = tile;
uint length = 0;
assert(IsExtendedRoadDepotTile(tile));
assert(dir < DIAGDIR_END);
do {
length++;
if ((GetRoadBits(tile, rtt) & DiagDirToRoadBits(dir)) == ROAD_NONE) break;
tile += TileOffsByDiagDir(dir);
} while (IsCompatibleRoadDepotTile(tile, start_tile, rtt));
return length;
}
/** /**
* Get the length of a platform. * Get the length of a platform.
* @param tile Tile to check * @param tile Tile to check
* @param rtt Whether to check for road or tram type (only for road transport).
* @return The length of the platform in tile length. * @return The length of the platform in tile length.
*/ */
uint GetPlatformLength(TileIndex tile) uint GetPlatformLength(TileIndex tile, RoadTramType rtt)
{ {
switch (GetPlatformType(tile)) { switch (GetPlatformType(tile)) {
case PT_RAIL_STATION: case PT_RAIL_STATION:
@ -220,6 +278,8 @@ uint GetPlatformLength(TileIndex tile)
return 1; return 1;
case PT_RAIL_DEPOT: case PT_RAIL_DEPOT:
return GetRailDepotPlatformLength(tile); return GetRailDepotPlatformLength(tile);
case PT_ROAD_DEPOT:
return GetRoadDepotPlatformLength(tile, rtt);
default: NOT_REACHED(); default: NOT_REACHED();
} }
} }
@ -229,9 +289,10 @@ uint GetPlatformLength(TileIndex tile)
* @pre IsRailDepotTile(tile) * @pre IsRailDepotTile(tile)
* @param tile Tile to check * @param tile Tile to check
* @param dir Direction to check * @param dir Direction to check
* @param rtt Whether to check for road or tram type (only for road transport).
* @return The length of the platform in tile length in the given direction. * @return The length of the platform in tile length in the given direction.
*/ */
uint GetPlatformLength(TileIndex tile, DiagDirection dir) uint GetPlatformLength(TileIndex tile, DiagDirection dir, RoadTramType rtt)
{ {
switch (GetPlatformType(tile)) { switch (GetPlatformType(tile)) {
case PT_RAIL_STATION: case PT_RAIL_STATION:
@ -240,6 +301,8 @@ uint GetPlatformLength(TileIndex tile, DiagDirection dir)
return 1; return 1;
case PT_RAIL_DEPOT: case PT_RAIL_DEPOT:
return GetRailDepotPlatformLength(tile, dir); return GetRailDepotPlatformLength(tile, dir);
case PT_ROAD_DEPOT:
return GetRoadDepotPlatformLength(tile, dir, rtt);
default: NOT_REACHED(); default: NOT_REACHED();
} }
} }

View File

@ -13,6 +13,7 @@
#include "station_map.h" #include "station_map.h"
#include "depot_map.h" #include "depot_map.h"
#include "platform_type.h" #include "platform_type.h"
#include "road_map.h"
/** /**
* Check if a tile is a valid continuation to a railstation tile. * Check if a tile is a valid continuation to a railstation tile.
@ -57,6 +58,31 @@ static inline bool IsCompatibleTrainDepotTile(TileIndex test_tile, TileIndex dep
GetDepotIndex(test_tile) == GetDepotIndex(depot_tile); GetDepotIndex(test_tile) == GetDepotIndex(depot_tile);
} }
/**
* Check if a tile is a valid continuation to an extended road depot tile.
* The tile \a test_tile is a valid continuation to \a depot_tile, if all of the following are true:
* \li \a test_tile is an extended depot tile
* \li \a test_tile and \a depot_tile have the same road type and appropriate road bits
* \li the tracks on \a test_tile and \a depot_tile are in the same direction
* \li both tiles belong to the same depot
* @param test_tile Tile to test
* @param depot_tile Depot tile to compare with
* @param rtt Whether road or tram type.
* @pre IsExtendedRoadDepotTile(depot_tile)
* @return true if the two tiles are compatible
*/
static inline bool IsCompatibleRoadDepotTile(TileIndex test_tile, TileIndex depot_tile, RoadTramType rtt)
{
assert(IsExtendedRoadDepotTile(depot_tile));
if (!IsExtendedRoadDepotTile(test_tile)) return false;
if (GetDepotIndex(test_tile) != GetDepotIndex(depot_tile)) return false;
if (GetRoadType(depot_tile, rtt) != GetRoadType(test_tile, rtt)) return false;
DiagDirection dir = DiagdirBetweenTiles(test_tile, depot_tile);
assert(dir != INVALID_DIAGDIR);
return (GetRoadBits(test_tile, rtt) & DiagDirToRoadBits(dir)) != ROAD_NONE;
}
/** /**
* Returns the type of platform of a given tile. * Returns the type of platform of a given tile.
* @param tile Tile to check * @param tile Tile to check
@ -72,6 +98,9 @@ static inline PlatformType GetPlatformType(TileIndex tile)
case MP_RAILWAY: case MP_RAILWAY:
if (IsExtendedRailDepotTile(tile)) return PT_RAIL_DEPOT; if (IsExtendedRailDepotTile(tile)) return PT_RAIL_DEPOT;
break; break;
case MP_ROAD:
if (IsExtendedRoadDepotTile(tile)) return PT_ROAD_DEPOT;
break;
default: break; default: break;
} }
@ -110,9 +139,10 @@ static inline bool HasPlatformReservation(TileIndex tile)
* platform type and (depending on the platform type) its railtype or other specs. * platform type and (depending on the platform type) its railtype or other specs.
* @param test_tile the tile to check * @param test_tile the tile to check
* @param orig_tile the tile with the platform type we are interested in * @param orig_tile the tile with the platform type we are interested in
* @param rtt Whether to check road or tram types (only for road transport);
* @return whether the two tiles are compatible tiles for defining a platform * @return whether the two tiles are compatible tiles for defining a platform
*/ */
static inline bool IsCompatiblePlatformTile(TileIndex test_tile, TileIndex orig_tile) static inline bool IsCompatiblePlatformTile(TileIndex test_tile, TileIndex orig_tile, RoadTramType rtt = RTT_ROAD)
{ {
switch (GetPlatformType(orig_tile)) { switch (GetPlatformType(orig_tile)) {
case PT_RAIL_STATION: case PT_RAIL_STATION:
@ -121,6 +151,8 @@ static inline bool IsCompatiblePlatformTile(TileIndex test_tile, TileIndex orig_
return test_tile == orig_tile; return test_tile == orig_tile;
case PT_RAIL_DEPOT: case PT_RAIL_DEPOT:
return IsCompatibleTrainDepotTile(test_tile, orig_tile); return IsCompatibleTrainDepotTile(test_tile, orig_tile);
case PT_ROAD_DEPOT:
return IsCompatibleRoadDepotTile(test_tile, orig_tile, rtt);
default: NOT_REACHED(); default: NOT_REACHED();
} }
} }
@ -128,8 +160,8 @@ static inline bool IsCompatiblePlatformTile(TileIndex test_tile, TileIndex orig_
void SetPlatformReservation(TileIndex start, DiagDirection dir, bool b); void SetPlatformReservation(TileIndex start, DiagDirection dir, bool b);
void SetPlatformReservation(TileIndex start, bool b); void SetPlatformReservation(TileIndex start, bool b);
uint GetPlatformLength(TileIndex tile); uint GetPlatformLength(TileIndex tile, RoadTramType rtt = RTT_ROAD);
uint GetPlatformLength(TileIndex tile, DiagDirection dir); uint GetPlatformLength(TileIndex tile, DiagDirection dir, RoadTramType rtt = RTT_ROAD);
TileIndex GetPlatformExtremeTile(TileIndex tile, DiagDirection dir); TileIndex GetPlatformExtremeTile(TileIndex tile, DiagDirection dir);
TileArea GetPlatformTileArea(TileIndex tile); TileArea GetPlatformTileArea(TileIndex tile);

View File

@ -16,6 +16,7 @@ enum PlatformType {
PT_RAIL_STATION, PT_RAIL_STATION,
PT_RAIL_WAYPOINT, PT_RAIL_WAYPOINT,
PT_RAIL_DEPOT, PT_RAIL_DEPOT,
PT_ROAD_DEPOT,
PT_END, PT_END,
INVALID_PLATFORM_TYPE = PT_END, INVALID_PLATFORM_TYPE = PT_END,
}; };