(svn r19561) -Feature: Give more detailed error message when trying to build a too long bridge.

pull/155/head
alberth 14 years ago
parent 141761a333
commit 581c110bfe

@ -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();

@ -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;

@ -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...

@ -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 */

Loading…
Cancel
Save