summaryrefslogtreecommitdiff
path: root/newgrf_station.c
diff options
context:
space:
mode:
authortron <tron@openttd.org>2006-08-01 06:08:11 +0000
committertron <tron@openttd.org>2006-08-01 06:08:11 +0000
commit2ee4ebfa39a45a8fe4a0b405da0cc24f9721900c (patch)
treec3f3e4544675d57d3041c295c9cb6ec04e80fdab /newgrf_station.c
parent31e0bae89a9ff2eb49b7b43136210f9516e3d724 (diff)
downloadopenttd-2ee4ebfa39a45a8fe4a0b405da0cc24f9721900c.tar.xz
(svn r5690) Factor common code to reduce code duplication
Diffstat (limited to 'newgrf_station.c')
-rw-r--r--newgrf_station.c45
1 files changed, 20 insertions, 25 deletions
diff --git a/newgrf_station.c b/newgrf_station.c
index 14b1d083b..b3f76648c 100644
--- a/newgrf_station.c
+++ b/newgrf_station.c
@@ -678,42 +678,37 @@ bool DrawStationTile(int x, int y, RailType railtype, Axis axis, StationClassID
return true;
}
-/* Check if a rail station tile is traversable.
- * XXX This could be cached (during build) in the map array to save on all the dereferencing */
-bool IsStationTileBlocked(TileIndex tile)
+
+static const StationSpec* GetStationSpec(TileIndex t)
{
- const Station *st;
- const StationSpec *statspec;
+ const Station* st;
uint specindex;
- if (!IsCustomStationSpecIndex(tile)) return false;
+ if (!IsCustomStationSpecIndex(t)) return NULL;
- st = GetStationByTile(tile);
- specindex = GetCustomStationSpecIndex(tile);
- if (specindex >= st->num_specs) return false;
+ st = GetStationByTile(t);
+ specindex = GetCustomStationSpecIndex(t);
+ return specindex < st->num_specs ? st->speclist[specindex].spec : NULL;
+}
- statspec = st->speclist[specindex].spec;
- if (statspec == NULL) return false;
- return HASBIT(statspec->blocked, GetStationGfx(tile));
+/* Check if a rail station tile is traversable.
+ * XXX This could be cached (during build) in the map array to save on all the dereferencing */
+bool IsStationTileBlocked(TileIndex tile)
+{
+ const StationSpec* statspec = GetStationSpec(tile);
+
+ return statspec != NULL && HASBIT(statspec->blocked, GetStationGfx(tile));
}
/* Check if a rail station tile is electrifiable.
* XXX This could be cached (during build) in the map array to save on all the dereferencing */
bool IsStationTileElectrifiable(TileIndex tile)
{
- const Station *st;
- const StationSpec *statspec;
- uint specindex;
-
- if (!IsCustomStationSpecIndex(tile)) return true;
-
- st = GetStationByTile(tile);
- specindex = GetCustomStationSpecIndex(tile);
- if (specindex >= st->num_specs) return true;
-
- statspec = st->speclist[specindex].spec;
- if (statspec == NULL) return true;
+ const StationSpec* statspec = GetStationSpec(tile);
- return HASBIT(statspec->pylons, GetStationGfx(tile)) || !HASBIT(statspec->wires, GetStationGfx(tile));
+ return
+ statspec == NULL ||
+ HASBIT(statspec->pylons, GetStationGfx(tile)) ||
+ !HASBIT(statspec->wires, GetStationGfx(tile));
}