summaryrefslogtreecommitdiff
path: root/train_cmd.c
diff options
context:
space:
mode:
authortron <tron@openttd.org>2005-01-17 09:41:46 +0000
committertron <tron@openttd.org>2005-01-17 09:41:46 +0000
commitfb0c3c8061ef1320fee319756dc4a7e5f58090f1 (patch)
tree8dc229efa596b250b79a49c52e25faeaf55adc18 /train_cmd.c
parentd4beff7954f1f016ed517b6c54e6a25895f5481d (diff)
downloadopenttd-fb0c3c8061ef1320fee319756dc4a7e5f58090f1.tar.xz
(svn r1549) Clean up some functions:
uint tile -> TileIndex tile if () cascade -> switch ()
Diffstat (limited to 'train_cmd.c')
-rw-r--r--train_cmd.c51
1 files changed, 27 insertions, 24 deletions
diff --git a/train_cmd.c b/train_cmd.c
index e96bc5866..fccded322 100644
--- a/train_cmd.c
+++ b/train_cmd.c
@@ -1893,36 +1893,39 @@ static int GetDirectionToVehicle(Vehicle *v, int x, int y)
}
/* Check if the vehicle is compatible with the specified tile */
-static bool CheckCompatibleRail(Vehicle *v, uint tile)
+static bool CheckCompatibleRail(const Vehicle *v, TileIndex tile)
{
- if (IsTileType(tile, MP_RAILWAY) || IsTileType(tile, MP_STATION)) {
- // normal tracks, jump to owner check
- } else if (IsTileType(tile, MP_TUNNELBRIDGE)) {
- if ((_map5[tile] & 0xC0) == 0xC0) {// is bridge middle part?
- TileInfo ti;
- FindLandscapeHeightByTile(&ti, tile);
+ switch (TileType(tile)) {
+ case MP_RAILWAY:
+ case MP_STATION:
+ // normal tracks, jump to owner check
+ break;
- // correct Z position of a train going under a bridge on slopes
- if (CORRECT_Z(ti.tileh))
- ti.z += 8;
+ case MP_TUNNELBRIDGE:
+ if ((_map5[tile] & 0xC0) == 0xC0) { // is bridge middle part?
+ TileInfo ti;
+ FindLandscapeHeightByTile(&ti, tile);
- if(v->z_pos != ti.z) // train is going over bridge
- return true;
- }
- } else if (IsTileType(tile, MP_STREET)) { // train is going over a road-crossing
- // tracks over roads, do owner check of tracks (_map_owner[tile])
- if (_map_owner[tile] != v->owner || (v->subtype == 0 && (_map3_hi[tile] & 0xF) != v->u.rail.railtype))
- return false;
+ // correct Z position of a train going under a bridge on slopes
+ if (CORRECT_Z(ti.tileh)) ti.z += 8;
- return true;
- } else
- return true;
+ if (v->z_pos != ti.z) return true; // train is going over bridge
+ }
+ break;
- if (_map_owner[tile] != v->owner ||
- (v->subtype == 0 && (_map3_lo[tile] & 0xF) != v->u.rail.railtype))
- return false;
+ case MP_STREET:
+ // tracks over roads, do owner check of tracks (_map_owner[tile])
+ return
+ _map_owner[tile] == v->owner &&
+ (v->subtype != 0 || (_map3_hi[tile] & 0xF) == v->u.rail.railtype);
- return true;
+ default:
+ return true;
+ }
+
+ return
+ _map_owner[tile] == v->owner &&
+ (v->subtype != 0 || (_map3_lo[tile] & 0xF) == v->u.rail.railtype);
}
typedef struct {