From fa8f227a9746ca3bbc6455a430e8d41307b78326 Mon Sep 17 00:00:00 2001 From: alberth Date: Sun, 4 Apr 2010 14:22:55 +0000 Subject: (svn r19561) -Feature: Give more detailed error message when trying to build a too long bridge. --- src/bridge.h | 2 +- src/bridge_gui.cpp | 4 ++-- src/lang/english.txt | 1 + src/tunnelbridge_cmd.cpp | 20 ++++++++++++-------- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/bridge.h b/src/bridge.h index ba4a07a6e..052313e24 100644 --- a/src/bridge.h +++ b/src/bridge.h @@ -67,7 +67,7 @@ static inline const BridgeSpec *GetBridgeSpec(BridgeType i) void DrawBridgeMiddle(const TileInfo *ti); -bool CheckBridgeAvailability(BridgeType bridge_type, uint bridge_len, DoCommandFlag flags = DC_NONE); +CommandCost CheckBridgeAvailability(BridgeType bridge_type, uint bridge_len, DoCommandFlag flags = DC_NONE); int CalcBridgeLenCostFactor(int x); void ResetBridges(); diff --git a/src/bridge_gui.cpp b/src/bridge_gui.cpp index 9e8632c1f..acdb95b5a 100644 --- a/src/bridge_gui.cpp +++ b/src/bridge_gui.cpp @@ -375,7 +375,7 @@ void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transpo case TRANSPORT_RAIL: last_bridge_type = _last_railbridge_type; break; default: break; // water ways and air routes don't have bridge types } - if (_ctrl_pressed && CheckBridgeAvailability(last_bridge_type, bridge_len)) { + if (_ctrl_pressed && CheckBridgeAvailability(last_bridge_type, bridge_len).Succeeded()) { DoCommandP(end, start, type | last_bridge_type, CMD_BUILD_BRIDGE | CMD_MSG(STR_ERROR_CAN_T_BUILD_BRIDGE_HERE), CcBuildBridge); return; } @@ -396,7 +396,7 @@ void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transpo /* loop for all bridgetypes */ for (BridgeType brd_type = 0; brd_type != MAX_BRIDGES; brd_type++) { - if (CheckBridgeAvailability(brd_type, bridge_len)) { + if (CheckBridgeAvailability(brd_type, bridge_len).Succeeded()) { /* bridge is accepted, add to list */ BuildBridgeData *item = bl->Append(); item->index = brd_type; diff --git a/src/lang/english.txt b/src/lang/english.txt index e0074f4ca..db4366379 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -3539,6 +3539,7 @@ STR_ERROR_BRIDGEHEADS_NOT_SAME_HEIGHT :{WHITE}Bridge h STR_ERROR_BRIDGE_TOO_LOW_FOR_TERRAIN :{WHITE}Bridge is too low for the terrain STR_ERROR_START_AND_END_MUST_BE_IN :{WHITE}Start and end must be in line STR_ERROR_ENDS_OF_BRIDGE_MUST_BOTH :{WHITE}... ends of bridge must both be on land +STR_ERROR_BRIDGE_TOO_LONG :{WHITE}... bridge too long # Tunnel related errors STR_ERROR_CAN_T_BUILD_TUNNEL_HERE :{WHITE}Can't build tunnel here... diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp index 6cf02644c..522879f17 100644 --- a/src/tunnelbridge_cmd.cpp +++ b/src/tunnelbridge_cmd.cpp @@ -166,23 +166,26 @@ static CommandCost CheckBridgeSlopeSouth(Axis axis, Slope *tileh, uint *z) /** Is a bridge of the specified type and length available? * @param bridge_type Wanted type of bridge. * @param bridge_len Wanted length of the bridge. - * @return The requested bridge is available. + * @return A succeeded (the requested bridge is available) or failed (it cannot be built) command. */ -bool CheckBridgeAvailability(BridgeType bridge_type, uint bridge_len, DoCommandFlag flags) +CommandCost CheckBridgeAvailability(BridgeType bridge_type, uint bridge_len, DoCommandFlag flags) { if (flags & DC_QUERY_COST) { - return bridge_len <= (_settings_game.construction.longbridges ? 100U : 16U); + if (bridge_len <= (_settings_game.construction.longbridges ? 100U : 16U)) return CommandCost(); + return_cmd_error(STR_ERROR_BRIDGE_TOO_LONG); } - if (bridge_type >= MAX_BRIDGES) return false; + if (bridge_type >= MAX_BRIDGES) return CMD_ERROR; const BridgeSpec *b = GetBridgeSpec(bridge_type); - if (b->avail_year > _cur_year) return false; + if (b->avail_year > _cur_year) return CMD_ERROR; uint max = b->max_length; if (max >= 16 && _settings_game.construction.longbridges) max = 100; - return b->min_length <= bridge_len && bridge_len <= max; + if (b->min_length > bridge_len) return CMD_ERROR; + if (bridge_len <= max) return CommandCost(); + return_cmd_error(STR_ERROR_BRIDGE_TOO_LONG); } /** Build a Bridge @@ -248,9 +251,10 @@ CommandCost CmdBuildBridge(TileIndex end_tile, DoCommandFlag flags, uint32 p1, u uint bridge_len = GetTunnelBridgeLength(tile_start, tile_end); if (transport_type != TRANSPORT_WATER) { /* set and test bridge length, availability */ - if (!CheckBridgeAvailability(bridge_type, bridge_len, flags)) return CMD_ERROR; + CommandCost ret = CheckBridgeAvailability(bridge_type, bridge_len, flags); + if (ret.Failed()) return ret; } else { - if (bridge_len > (_settings_game.construction.longbridges ? 100U : 16U)) return CMD_ERROR; + if (bridge_len > (_settings_game.construction.longbridges ? 100U : 16U)) return_cmd_error(STR_ERROR_BRIDGE_TOO_LONG); } /* retrieve landscape height and ensure it's on land */ -- cgit v1.2.3-54-g00ecf