Mercurial > hg > openttd
changeset 14762:c3f866bf71f6 draft
(svn r19350) -Codechange: StationRect::BeforeAddRect() returns a CommandCost.
author | alberth <alberth@openttd.org> |
---|---|
date | Sat, 06 Mar 2010 13:23:33 +0000 |
parents | e11f49e15469 |
children | f46adc9839d3 |
files | src/base_station_base.h src/station.cpp src/station_cmd.cpp src/station_gui.cpp src/waypoint_cmd.cpp |
diffstat | 5 files changed, 21 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/src/base_station_base.h +++ b/src/base_station_base.h @@ -41,7 +41,7 @@ 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);
--- a/src/station.cpp +++ b/src/station.cpp @@ -400,16 +400,15 @@ 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(); } /**
--- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -1159,7 +1159,9 @@ } /* 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 @@ 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 @@ 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 @@ 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 {
--- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -1293,7 +1293,7 @@ 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; }
--- a/src/waypoint_cmd.cpp +++ b/src/waypoint_cmd.cpp @@ -273,7 +273,9 @@ 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);