diff --git a/src/bridge.h b/src/bridge.h --- a/src/bridge.h +++ b/src/bridge.h @@ -28,6 +28,11 @@ extern const Bridge orig_bridge[MAX_BRID 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 --- 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 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -3136,7 +3136,10 @@ static void TrainController(Vehicle *v, /* 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 --- 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;