Mercurial > hg > openttd
changeset 8598:ef2c93a9589d draft
(svn r12179) -Codechange: use GetCrossingRailTrack() and GetCrossingRailAxis() to improve code readability
author | smatz <smatz@openttd.org> |
---|---|
date | Mon, 18 Feb 2008 18:35:36 +0000 |
parents | 4874986a37aa |
children | 8d23ba9f619f |
files | src/openttd.cpp src/rail_cmd.cpp src/road_cmd.cpp src/road_map.h src/train_cmd.cpp |
diffstat | 5 files changed, 16 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -2393,7 +2393,7 @@ if (!GetPlayer(o)->is_active) { /* remove leftover rail piece from crossing (from very old savegames) */ _current_player = o; - DoCommand(t, 0, AxisToTrack(OtherAxis(GetCrossingRoadAxis(t))), DC_EXEC | DC_BANKRUPT, CMD_REMOVE_SINGLE_RAIL); + DoCommand(t, 0, GetCrossingRailTrack(t), DC_EXEC | DC_BANKRUPT, CMD_REMOVE_SINGLE_RAIL); } } }
--- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -1313,7 +1313,7 @@ default: // MP_STATION, MP_ROAD if (flags & DC_EXEC) { - Track track = (tt == MP_STATION) ? GetRailStationTrack(tile) : AxisToTrack(OtherAxis(GetCrossingRoadAxis(tile))); + Track track = ((tt == MP_STATION) ? GetRailStationTrack(tile) : GetCrossingRailTrack(tile)); YapfNotifyTrackLayoutChange(tile, track); }
--- a/src/road_cmd.cpp +++ b/src/road_cmd.cpp @@ -1448,7 +1448,7 @@ if (IsLevelCrossing(tile)) { if (GetTileOwner(tile) == old_player) { if (new_player == PLAYER_SPECTATOR) { - DoCommand(tile, 0, AxisToTrack(OtherAxis(GetCrossingRoadAxis(tile))), DC_EXEC | DC_BANKRUPT, CMD_REMOVE_SINGLE_RAIL); + DoCommand(tile, 0, GetCrossingRailTrack(tile), DC_EXEC | DC_BANKRUPT, CMD_REMOVE_SINGLE_RAIL); } else { SetTileOwner(tile, new_player); }
--- a/src/road_map.h +++ b/src/road_map.h @@ -206,14 +206,25 @@ return (Axis)GB(_m[t].m4, 6, 1); } +static inline Axis GetCrossingRailAxis(TileIndex t) +{ + assert(IsLevelCrossing(t)); + return OtherAxis((Axis)GetCrossingRoadAxis(t)); +} + static inline RoadBits GetCrossingRoadBits(TileIndex tile) { return GetCrossingRoadAxis(tile) == AXIS_X ? ROAD_X : ROAD_Y; } +static inline Track GetCrossingRailTrack(TileIndex tile) +{ + return AxisToTrack(GetCrossingRailAxis(tile)); +} + static inline TrackBits GetCrossingRailBits(TileIndex tile) { - return AxisToTrackBits(OtherAxis(GetCrossingRoadAxis(tile))); + return AxisToTrackBits(GetCrossingRailAxis(tile)); } static inline bool IsCrossingBarred(TileIndex t)
--- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -1667,7 +1667,7 @@ { assert(IsLevelCrossingTile(tile)); - DiagDirection dir = AxisToDiagDir(OtherAxis(GetCrossingRoadAxis(tile))); + DiagDirection dir = AxisToDiagDir(GetCrossingRailAxis(tile)); TileIndex tile_from = tile + TileOffsByDiagDir(dir); Vehicle *v = (Vehicle *)VehicleFromPos(tile_from, &tile, &TrainApproachingCrossingEnum);