diff options
author | alberth <alberth@openttd.org> | 2010-02-27 14:17:33 +0000 |
---|---|---|
committer | alberth <alberth@openttd.org> | 2010-02-27 14:17:33 +0000 |
commit | b8f811c7ffb2eae25c4c7ba4998dc6ab36f38382 (patch) | |
tree | a5318ed289458a515c28c768a04f6df7f62b52d9 /src | |
parent | fee81aedcb36ea7d34596d692d5a613379bfc0e6 (diff) | |
download | openttd-b8f811c7ffb2eae25c4c7ba4998dc6ab36f38382.tar.xz |
(svn r19275) -Codechange: CanExpandRailStation() returns a CommandCost.
Diffstat (limited to 'src')
-rw-r--r-- | src/station_cmd.cpp | 27 | ||||
-rw-r--r-- | src/waypoint_cmd.cpp | 7 |
2 files changed, 17 insertions, 17 deletions
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index f40bf4927..914685ad4 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -891,9 +891,9 @@ static CommandCost CheckFlatLandRoadStop(TileArea tile_area, DoCommandFlag flags * @param st the station to expand * @param new_ta the current (and if all is fine new) tile area of the rail part of the station * @param axis the axis of the newly build rail - * @return true if we are allowed to extend + * @return Succeeded or failed command. */ -bool CanExpandRailStation(const BaseStation *st, TileArea &new_ta, Axis axis) +CommandCost CanExpandRailStation(const BaseStation *st, TileArea &new_ta, Axis axis) { TileArea cur_ta = st->train_station; @@ -909,15 +909,13 @@ bool CanExpandRailStation(const BaseStation *st, TileArea &new_ta, Axis axis) * the uniform-stations code wouldn't handle it well */ TILE_LOOP(t, cur_ta.w, cur_ta.h, cur_ta.tile) { if (!st->TileBelongsToRailStation(t)) { // there may be adjoined station - _error_message = STR_ERROR_NONUNIFORM_STATIONS_DISALLOWED; - return false; + return_cmd_error(STR_ERROR_NONUNIFORM_STATIONS_DISALLOWED); } } /* check so the orientation is the same */ if (GetRailStationAxis(cur_ta.tile) != axis) { - _error_message = STR_ERROR_NONUNIFORM_STATIONS_DISALLOWED; - return false; + return_cmd_error(STR_ERROR_NONUNIFORM_STATIONS_DISALLOWED); } /* check if the new station adjoins the old station in either direction */ @@ -936,17 +934,15 @@ bool CanExpandRailStation(const BaseStation *st, TileArea &new_ta, Axis axis) new_ta.tile = cur_ta.tile; new_ta.w += cur_ta.w; } else { - _error_message = STR_ERROR_NONUNIFORM_STATIONS_DISALLOWED; - return false; + return_cmd_error(STR_ERROR_NONUNIFORM_STATIONS_DISALLOWED); } } /* make sure the final size is not too big. */ if (new_ta.w > _settings_game.station.station_spread || new_ta.h > _settings_game.station.station_spread) { - _error_message = STR_ERROR_STATION_TOO_SPREAD_OUT; - return false; + return_cmd_error(STR_ERROR_STATION_TOO_SPREAD_OUT); } - return true; + return CommandCost(); } static inline byte *CreateSingle(byte *layout, int n) @@ -1150,10 +1146,11 @@ CommandCost CmdBuildRailStation(TileIndex tile_org, DoCommandFlag flags, uint32 if (st->train_station.tile != INVALID_TILE) { /* check if we want to expanding an already existing station? */ - if (!_settings_game.station.join_stations) - return_cmd_error(STR_ERROR_TOO_CLOSE_TO_ANOTHER_RAILROAD); - if (!CanExpandRailStation(st, new_location, axis)) - return CMD_ERROR; + if (!_settings_game.station.join_stations) return_cmd_error(STR_ERROR_TOO_CLOSE_TO_ANOTHER_RAILROAD); + + CommandCost ret = CanExpandRailStation(st, new_location, axis); + ret.SetGlobalErrorMessage(); + if (ret.Failed()) return ret; } /* XXX can't we pack this in the "else" part of the if above? */ diff --git a/src/waypoint_cmd.cpp b/src/waypoint_cmd.cpp index 348ac5d12..413d7be66 100644 --- a/src/waypoint_cmd.cpp +++ b/src/waypoint_cmd.cpp @@ -194,7 +194,7 @@ static CommandCost IsValidTileForWaypoint(TileIndex tile, Axis axis, StationID * extern void GetStationLayout(byte *layout, int numtracks, int plat_len, const StationSpec *statspec); extern CommandCost FindJoiningWaypoint(StationID existing_station, StationID station_to_join, bool adjacent, TileArea ta, Waypoint **wp); -extern bool CanExpandRailStation(const BaseStation *st, TileArea &new_ta, Axis axis); +extern CommandCost CanExpandRailStation(const BaseStation *st, TileArea &new_ta, Axis axis); /** Convert existing rail to waypoint. Eg build a waypoint station over * piece of rail @@ -265,7 +265,10 @@ CommandCost CmdBuildRailWaypoint(TileIndex start_tile, DoCommandFlag flags, uint if (wp->owner != _current_company) return_cmd_error(STR_ERROR_TOO_CLOSE_TO_ANOTHER_WAYPOINT); /* check if we want to expand an already existing waypoint? */ - if (wp->train_station.tile != INVALID_TILE && !CanExpandRailStation(wp, new_location, axis)) return CMD_ERROR; + if (wp->train_station.tile != INVALID_TILE) { + CommandCost ret = CanExpandRailStation(wp, new_location, axis); + if (ret.Failed()) return ret; + } if (!wp->rect.BeforeAddRect(start_tile, width, height, StationRect::ADD_TEST)) return CMD_ERROR; } else { |