From 5c91ec0587c386e07bb47cc0ccd73538c404e305 Mon Sep 17 00:00:00 2001 From: tron Date: Sat, 24 Feb 2007 18:44:30 +0000 Subject: (svn r8884) -Fix Replace SetSpeedLimitOnBridge() by something simpler --- src/bridge.h | 7 ++++++- src/roadveh_cmd.cpp | 4 +++- src/train_cmd.cpp | 5 ++++- src/tunnelbridge_cmd.cpp | 15 --------------- 4 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/bridge.h b/src/bridge.h index 0a493781d..bf622804d 100644 --- a/src/bridge.h +++ b/src/bridge.h @@ -28,6 +28,11 @@ extern const Bridge orig_bridge[MAX_BRIDGES]; extern Bridge _bridge[MAX_BRIDGES]; uint GetBridgeFoundation(Slope tileh, Axis axis); -uint SetSpeedLimitOnBridge(Vehicle *); + +static inline const Bridge *GetBridge(uint i) +{ + assert(i < lengthof(_bridge)); + return &_bridge[i]; +} #endif /* BRIDGE_H */ diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp index 1bb71eab2..37f43540a 100644 --- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -880,7 +880,9 @@ static bool RoadVehAccelerate(Vehicle *v) // Clamp spd = min(spd, v->max_speed); - if (v->u.road.state == RVSB_WORMHOLE) spd = min(spd, SetSpeedLimitOnBridge(v)); + if (v->u.road.state == RVSB_WORMHOLE && !(v->vehstatus & VS_HIDDEN)) { + spd = min(spd, GetBridge(GetBridgeType(v->tile))->speed * 2); + } //updates statusbar only if speed have changed to save CPU time if (spd != v->cur_speed) { diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 5f5193f0d..7bb0ad6fa 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -3136,7 +3136,10 @@ static void TrainController(Vehicle *v, bool update_image) /* In tunnel or on a bridge */ GetNewVehiclePos(v, &gp); - SetSpeedLimitOnBridge(v); + if (!(v->vehstatus & VS_HIDDEN)) { + v->cur_speed = + min(v->cur_speed, GetBridge(GetBridgeType(v->tile))->speed); + } if (!(IsTunnelTile(gp.new_tile) || IsBridgeTile(gp.new_tile)) || !HASBIT(VehicleEnterTile(v, gp.new_tile, gp.x, gp.y), VETS_ENTERED_WORMHOLE)) { v->x_pos = gp.x; diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp index 07c5fb47e..14dfcf154 100644 --- a/src/tunnelbridge_cmd.cpp +++ b/src/tunnelbridge_cmd.cpp @@ -1051,21 +1051,6 @@ void DrawBridgeMiddle(const TileInfo* ti) } -uint SetSpeedLimitOnBridge(Vehicle *v) -{ - uint bridge_speed; - if (v->vehstatus & VS_HIDDEN) return v->max_speed; /* in tunnel */ - - bridge_speed = _bridge[GetBridgeType(v->tile)].speed; - - if (v->type == VEH_Road) bridge_speed *= 2; /* XXX give vehicles proper speeds */ - - if (v->cur_speed > bridge_speed) v->cur_speed = bridge_speed; - return bridge_speed; -} - - - static uint GetSlopeZ_TunnelBridge(TileIndex tile, uint x, uint y) { uint z; -- cgit v1.2.3-70-g09d2