Mercurial > hg > openttd
changeset 4206:b69fd95a26b4 draft
(svn r5690) Factor common code to reduce code duplication
author | tron <tron@openttd.org> |
---|---|
date | Tue, 01 Aug 2006 06:08:11 +0000 |
parents | ee201da48779 |
children | a30eea1e2898 |
files | newgrf_station.c |
diffstat | 1 files changed, 21 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/newgrf_station.c +++ b/newgrf_station.c @@ -678,42 +678,37 @@ return true; } + +static const StationSpec* GetStationSpec(TileIndex t) +{ + const Station* st; + uint specindex; + + if (!IsCustomStationSpecIndex(t)) return NULL; + + st = GetStationByTile(t); + specindex = GetCustomStationSpecIndex(t); + return specindex < st->num_specs ? st->speclist[specindex].spec : NULL; +} + + /* 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 Station *st; - const StationSpec *statspec; - uint specindex; - - if (!IsCustomStationSpecIndex(tile)) return false; + const StationSpec* statspec = GetStationSpec(tile); - st = GetStationByTile(tile); - specindex = GetCustomStationSpecIndex(tile); - if (specindex >= st->num_specs) return false; - - statspec = st->speclist[specindex].spec; - if (statspec == NULL) return false; - - return HASBIT(statspec->blocked, GetStationGfx(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; + const StationSpec* statspec = GetStationSpec(tile); - st = GetStationByTile(tile); - specindex = GetCustomStationSpecIndex(tile); - if (specindex >= st->num_specs) return true; - - statspec = st->speclist[specindex].spec; - if (statspec == NULL) return true; - - return HASBIT(statspec->pylons, GetStationGfx(tile)) || !HASBIT(statspec->wires, GetStationGfx(tile)); + return + statspec == NULL || + HASBIT(statspec->pylons, GetStationGfx(tile)) || + !HASBIT(statspec->wires, GetStationGfx(tile)); }