From 12d252d9bd7ffee83c4be5162cd506bda1070020 Mon Sep 17 00:00:00 2001 From: tron Date: Sun, 12 Mar 2006 16:13:16 +0000 Subject: [PATCH] (svn r3831) Add and use GetRailDepotDirection() --- ai/default/default.c | 6 ++++-- depot.h | 3 ++- rail_cmd.c | 4 ++-- rail_map.h | 6 ++++++ train_cmd.c | 8 ++++---- vehicle.c | 2 +- 6 files changed, 19 insertions(+), 10 deletions(-) diff --git a/ai/default/default.c b/ai/default/default.c index 41580720c5..7ba7fb1375 100644 --- a/ai/default/default.c +++ b/ai/default/default.c @@ -4,6 +4,7 @@ #include "../../openttd.h" #include "../../functions.h" #include "../../map.h" +#include "../../rail_map.h" #include "../../road_map.h" #include "../../tile.h" #include "../../player.h" @@ -3625,8 +3626,9 @@ pos_3: } else { static const byte _depot_bits[] = {0x19,0x16,0x25,0x2A}; - m5 &= 3; - if (GetRailTrackStatus(tile + TileOffsByDir(m5)) & _depot_bits[m5]) + DiagDirection dir = GetRailDepotDirection(tile); + + if (GetRailTrackStatus(tile + TileOffsByDir(dir)) & _depot_bits[dir]) return; DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); diff --git a/depot.h b/depot.h index a3efdf233b..1cc87e3166 100644 --- a/depot.h +++ b/depot.h @@ -8,6 +8,7 @@ #include "direction.h" #include "pool.h" +#include "rail_map.h" #include "road_map.h" #include "tile.h" #include "variables.h" @@ -103,7 +104,7 @@ static inline DiagDirection GetDepotDirection(TileIndex tile, TransportType type switch (type) { - case TRANSPORT_RAIL: return (DiagDirection)GB(_m[tile].m5, 0, 2); + case TRANSPORT_RAIL: return GetRailDepotDirection(tile); case TRANSPORT_ROAD: return GetRoadDepotDirection(tile); case TRANSPORT_WATER: /* Water is stubborn, it stores the directions in a different order. */ diff --git a/rail_cmd.c b/rail_cmd.c index 8dc36a59dc..034a8ad10e 100644 --- a/rail_cmd.c +++ b/rail_cmd.c @@ -1027,7 +1027,7 @@ static int32 RemoveTrainDepot(TileIndex tile, uint32 flags) return CMD_ERROR; if (flags & DC_EXEC) { - Track track = TrackdirToTrack(DiagdirToDiagTrackdir(GetDepotDirection(tile, TRANSPORT_RAIL))); + Track track = TrackdirToTrack(DiagdirToDiagTrackdir(GetRailDepotDirection(tile))); DoDeleteDepot(tile); SetSignalsOnBothDir(tile, track); @@ -2085,7 +2085,7 @@ static uint32 VehicleEnter_Track(Vehicle *v, TileIndex tile, int x, int y) if (v->type != VEH_Train || !IsTileDepotType(tile, TRANSPORT_RAIL)) return 0; /* depot direction */ - dir = GetDepotDirection(tile, TRANSPORT_RAIL); + dir = GetRailDepotDirection(tile); /* calculate the point where the following wagon should be activated */ /* this depends on the length of the current vehicle */ diff --git a/rail_map.h b/rail_map.h index 9affa22478..ee407a3847 100644 --- a/rail_map.h +++ b/rail_map.h @@ -8,6 +8,12 @@ #include "waypoint.h" +static inline DiagDirection GetRailDepotDirection(TileIndex t) +{ + return (DiagDirection)GB(_m[t].m5, 0, 2); +} + + static inline TrackBits GetRailWaypointBits(TileIndex t) { return _m[t].m5 & RAIL_WAYPOINT_TRACK_MASK ? TRACK_BIT_Y : TRACK_BIT_X; diff --git a/train_cmd.c b/train_cmd.c index bc2f28c57f..c174937d8b 100644 --- a/train_cmd.c +++ b/train_cmd.c @@ -540,7 +540,7 @@ static int32 CmdBuildRailWagon(EngineID engine, TileIndex tile, uint32 flags) v->engine_type = engine; - dir = GB(_m[tile].m5, 0, 2); + dir = GetRailDepotDirection(tile); v->direction = DiagDirToDir(dir); v->tile = tile; @@ -699,7 +699,7 @@ int32 CmdBuildRailVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2) v->unitnumber = unit_num; - dir = GB(_m[tile].m5, 0, 2); + dir = GetRailDepotDirection(tile); v->direction = DiagDirToDir(dir); v->tile = tile; @@ -3167,7 +3167,7 @@ static bool TrainCheckIfLineEnds(Vehicle *v) if (x + 4 > 15 && (!CheckCompatibleRail(v, tile) || (IsTileDepotType(tile, TRANSPORT_RAIL) && - GetDepotDirection(tile, TRANSPORT_RAIL) == dir))) { + GetRailDepotDirection(tile) == dir))) { v->cur_speed = 0; ReverseTrainDirection(v); return false; @@ -3287,7 +3287,7 @@ static const byte _depot_track_ind[4] = {0,1,0,1}; void TrainEnterDepot(Vehicle *v, TileIndex tile) { - SetSignalsOnBothDir(tile, _depot_track_ind[GB(_m[tile].m5, 0, 2)]); + SetSignalsOnBothDir(tile, _depot_track_ind[GetRailDepotDirection(tile)]); if (!IsFrontEngine(v)) v = GetFirstVehicleInChain(v); diff --git a/vehicle.c b/vehicle.c index 1e34c78d1f..d737350f23 100644 --- a/vehicle.c +++ b/vehicle.c @@ -1960,7 +1960,7 @@ Trackdir GetVehicleTrackdir(const Vehicle* v) switch (v->type) { case VEH_Train: if (v->u.rail.track == 0x80) /* We'll assume the train is facing outwards */ - return DiagdirToDiagTrackdir(GetDepotDirection(v->tile, TRANSPORT_RAIL)); /* Train in depot */ + return DiagdirToDiagTrackdir(GetRailDepotDirection(v->tile)); /* Train in depot */ if (v->u.rail.track == 0x40) /* train in tunnel, so just use his direction and assume a diagonal track */ return DiagdirToDiagTrackdir(DirToDiagDir(v->direction));