From 6a3dbaf99a91aa223b2541c172f0ded06c55baf2 Mon Sep 17 00:00:00 2001 From: alberth Date: Sat, 6 Mar 2010 13:23:33 +0000 Subject: [PATCH] (svn r19350) -Codechange: StationRect::BeforeAddRect() returns a CommandCost. --- src/base_station_base.h | 2 +- src/station.cpp | 7 +++---- src/station_cmd.cpp | 18 +++++++++++++----- src/station_gui.cpp | 2 +- src/waypoint_cmd.cpp | 4 +++- 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/base_station_base.h b/src/base_station_base.h index d6d97cc834..e652c3264b 100644 --- a/src/base_station_base.h +++ b/src/base_station_base.h @@ -41,7 +41,7 @@ struct StationRect : public Rect { bool PtInExtendedRect(int x, int y, int distance = 0) const; bool IsEmpty() const; CommandCost BeforeAddTile(TileIndex tile, StationRectMode mode); - bool BeforeAddRect(TileIndex tile, int w, int h, StationRectMode mode); + CommandCost BeforeAddRect(TileIndex tile, int w, int h, StationRectMode mode); bool AfterRemoveTile(BaseStation *st, TileIndex tile); bool AfterRemoveRect(BaseStation *st, TileIndex tile, int w, int h); diff --git a/src/station.cpp b/src/station.cpp index 9ef44a2803..416403048e 100644 --- a/src/station.cpp +++ b/src/station.cpp @@ -400,16 +400,15 @@ CommandCost StationRect::BeforeAddTile(TileIndex tile, StationRectMode mode) return CommandCost(); } -bool StationRect::BeforeAddRect(TileIndex tile, int w, int h, StationRectMode mode) +CommandCost StationRect::BeforeAddRect(TileIndex tile, int w, int h, StationRectMode mode) { if (mode == ADD_FORCE || (w <= _settings_game.station.station_spread && h <= _settings_game.station.station_spread)) { /* Important when the old rect is completely inside the new rect, resp. the old one was empty. */ CommandCost ret = this->BeforeAddTile(tile, mode); if (ret.Succeeded()) ret = this->BeforeAddTile(TILE_ADDXY(tile, w - 1, h - 1), mode); - if (ret.Succeeded()) return true; - ret.SetGlobalErrorMessage(); + return ret; } - return false; + return CommandCost(); } /** diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index 17d1104015..70f8690efc 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -1159,7 +1159,9 @@ CommandCost CmdBuildRailStation(TileIndex tile_org, DoCommandFlag flags, uint32 } /* XXX can't we pack this in the "else" part of the if above? */ - if (!st->rect.BeforeAddRect(tile_org, w_org, h_org, StationRect::ADD_TEST)) return CMD_ERROR; + CommandCost ret = st->rect.BeforeAddRect(tile_org, w_org, h_org, StationRect::ADD_TEST); + ret.SetGlobalErrorMessage(); + if (ret.Failed()) return ret; } else { /* allocate and initialize new station */ if (!Station::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_STATIONS_LOADING); @@ -1726,7 +1728,9 @@ CommandCost CmdBuildRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, uin return_cmd_error(STR_ERROR_TOO_CLOSE_TO_ANOTHER_STATION); } - if (!st->rect.BeforeAddRect(roadstop_area.tile, roadstop_area.w, roadstop_area.h, StationRect::ADD_TEST)) return CMD_ERROR; + CommandCost ret = st->rect.BeforeAddRect(roadstop_area.tile, roadstop_area.w, roadstop_area.h, StationRect::ADD_TEST); + ret.SetGlobalErrorMessage(); + if (ret.Failed()) return ret; } else { /* allocate and initialize new station */ if (!Station::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_STATIONS_LOADING); @@ -2137,7 +2141,9 @@ CommandCost CmdBuildAirport(TileIndex tile, DoCommandFlag flags, uint32 p1, uint return_cmd_error(STR_ERROR_TOO_CLOSE_TO_ANOTHER_STATION); } - if (!st->rect.BeforeAddRect(tile, w, h, StationRect::ADD_TEST)) return CMD_ERROR; + CommandCost ret = st->rect.BeforeAddRect(tile, w, h, StationRect::ADD_TEST); + ret.SetGlobalErrorMessage(); + if (ret.Failed()) return ret; if (st->airport.tile != INVALID_TILE) { return_cmd_error(STR_ERROR_TOO_CLOSE_TO_ANOTHER_AIRPORT); @@ -2385,9 +2391,11 @@ CommandCost CmdBuildDock(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 return_cmd_error(STR_ERROR_TOO_CLOSE_TO_ANOTHER_STATION); } - if (!st->rect.BeforeAddRect( + CommandCost ret = st->rect.BeforeAddRect( tile + ToTileIndexDiff(_dock_tileoffs_chkaround[direction]), - _dock_w_chk[direction], _dock_h_chk[direction], StationRect::ADD_TEST)) return CMD_ERROR; + _dock_w_chk[direction], _dock_h_chk[direction], StationRect::ADD_TEST); + ret.SetGlobalErrorMessage(); + if (ret.Failed()) return ret; if (st->dock_tile != INVALID_TILE) return_cmd_error(STR_ERROR_TOO_CLOSE_TO_ANOTHER_DOCK); } else { diff --git a/src/station_gui.cpp b/src/station_gui.cpp index 6efb569f2c..e731931ddd 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -1293,7 +1293,7 @@ static bool AddNearbyStation(TileIndex tile, void *user_data) T *st = T::Get(sid); if (st->owner != _local_company || _stations_nearby_list.Contains(sid)) return false; - if (st->rect.BeforeAddRect(ctx->tile, ctx->w, ctx->h, StationRect::ADD_TEST)) { + if (st->rect.BeforeAddRect(ctx->tile, ctx->w, ctx->h, StationRect::ADD_TEST).Succeeded()) { *_stations_nearby_list.Append() = sid; } diff --git a/src/waypoint_cmd.cpp b/src/waypoint_cmd.cpp index 7be4a6ce4b..04db4fc930 100644 --- a/src/waypoint_cmd.cpp +++ b/src/waypoint_cmd.cpp @@ -273,7 +273,9 @@ CommandCost CmdBuildRailWaypoint(TileIndex start_tile, DoCommandFlag flags, uint if (ret.Failed()) return ret; } - if (!wp->rect.BeforeAddRect(start_tile, width, height, StationRect::ADD_TEST)) return CMD_ERROR; + CommandCost ret = wp->rect.BeforeAddRect(start_tile, width, height, StationRect::ADD_TEST); + ret.SetGlobalErrorMessage(); + if (ret.Failed()) return ret; } else { /* allocate and initialize new waypoint */ if (!Waypoint::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_STATIONS_LOADING);