From 2bb88255388bedae0d94c9c06751ee8f140a9194 Mon Sep 17 00:00:00 2001 From: rubidium Date: Sat, 2 Aug 2008 22:47:48 +0000 Subject: [PATCH] (svn r13928) -Add [YAPP]: Function for getting the path reservation state of any tile. (michi_cc) --- projects/openttd_vs80.vcproj | 8 +++++++ projects/openttd_vs90.vcproj | 8 +++++++ source.list | 2 ++ src/pbs.cpp | 43 ++++++++++++++++++++++++++++++++++++ src/pbs.h | 13 +++++++++++ 5 files changed, 74 insertions(+) create mode 100644 src/pbs.cpp create mode 100644 src/pbs.h diff --git a/projects/openttd_vs80.vcproj b/projects/openttd_vs80.vcproj index 2d4f9c02e1..b19198b2d1 100644 --- a/projects/openttd_vs80.vcproj +++ b/projects/openttd_vs80.vcproj @@ -663,6 +663,10 @@ RelativePath=".\..\src\pathfind.cpp" > + + @@ -1263,6 +1267,10 @@ RelativePath=".\..\src\pathfind.h" > + + diff --git a/projects/openttd_vs90.vcproj b/projects/openttd_vs90.vcproj index 4b33a7f358..3523d11dcd 100644 --- a/projects/openttd_vs90.vcproj +++ b/projects/openttd_vs90.vcproj @@ -660,6 +660,10 @@ RelativePath=".\..\src\pathfind.cpp" > + + @@ -1260,6 +1264,10 @@ RelativePath=".\..\src\pathfind.h" > + + diff --git a/source.list b/source.list index 8624afe241..a46e52a1eb 100644 --- a/source.list +++ b/source.list @@ -57,6 +57,7 @@ os_timer.cpp ottdres.rc #end pathfind.cpp +pbs.cpp players.cpp queue.cpp rail.cpp @@ -241,6 +242,7 @@ order_base.h order_func.h order_type.h pathfind.h +pbs.h player_base.h player_face.h player_func.h diff --git a/src/pbs.cpp b/src/pbs.cpp new file mode 100644 index 0000000000..c75eb8caf6 --- /dev/null +++ b/src/pbs.cpp @@ -0,0 +1,43 @@ +/* $Id$ */ + +/** @file pbs.cpp */ + +#include "stdafx.h" +#include "openttd.h" +#include "pbs.h" +#include "rail_map.h" +#include "road_map.h" +#include "station_map.h" +#include "tunnelbridge_map.h" + +/** + * Get the reserved trackbits for any tile, regardless of type. + * @param t the tile + * @return the reserved trackbits. TRACK_BIT_NONE on nothing reserved or + * a tile without rail. + */ +TrackBits GetReservedTrackbits(TileIndex t) +{ + switch (GetTileType(t)) { + case MP_RAILWAY: + if (IsRailWaypoint(t) || IsRailDepot(t)) return GetRailWaypointReservation(t); + if (IsPlainRailTile(t)) return GetTrackReservation(t); + break; + + case MP_ROAD: + if (IsLevelCrossing(t)) return GetRailCrossingReservation(t); + break; + + case MP_STATION: + if (IsRailwayStation(t)) return GetRailStationReservation(t); + break; + + case MP_TUNNELBRIDGE: + if (GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL) return GetRailTunnelBridgeReservation(t); + break; + + default: + break; + } + return TRACK_BIT_NONE; +} diff --git a/src/pbs.h b/src/pbs.h new file mode 100644 index 0000000000..51a9ba2017 --- /dev/null +++ b/src/pbs.h @@ -0,0 +1,13 @@ +/* $Id$ */ + +/** @file pbs.h PBS support routines */ + +#ifndef PBS_H +#define PBS_H + +#include "tile_type.h" +#include "track_type.h" + +TrackBits GetReservedTrackbits(TileIndex t); + +#endif /* PBS_H */