1
0
Fork 0

(svn r19350) -Codechange: StationRect::BeforeAddRect() returns a CommandCost.

release/1.1
alberth 2010-03-06 13:23:33 +00:00
parent ef5764f98a
commit 6a3dbaf99a
5 changed files with 21 additions and 12 deletions

View File

@ -41,7 +41,7 @@ struct StationRect : public Rect {
bool PtInExtendedRect(int x, int y, int distance = 0) const; bool PtInExtendedRect(int x, int y, int distance = 0) const;
bool IsEmpty() const; bool IsEmpty() const;
CommandCost BeforeAddTile(TileIndex tile, StationRectMode mode); 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 AfterRemoveTile(BaseStation *st, TileIndex tile);
bool AfterRemoveRect(BaseStation *st, TileIndex tile, int w, int h); bool AfterRemoveRect(BaseStation *st, TileIndex tile, int w, int h);

View File

@ -400,16 +400,15 @@ CommandCost StationRect::BeforeAddTile(TileIndex tile, StationRectMode mode)
return CommandCost(); 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)) { 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. */ /* Important when the old rect is completely inside the new rect, resp. the old one was empty. */
CommandCost ret = this->BeforeAddTile(tile, mode); CommandCost ret = this->BeforeAddTile(tile, mode);
if (ret.Succeeded()) ret = this->BeforeAddTile(TILE_ADDXY(tile, w - 1, h - 1), mode); if (ret.Succeeded()) ret = this->BeforeAddTile(TILE_ADDXY(tile, w - 1, h - 1), mode);
if (ret.Succeeded()) return true; return ret;
ret.SetGlobalErrorMessage();
} }
return false; return CommandCost();
} }
/** /**

View File

@ -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? */ /* 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 { } else {
/* allocate and initialize new station */ /* allocate and initialize new station */
if (!Station::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_STATIONS_LOADING); 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); 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 { } else {
/* allocate and initialize new station */ /* allocate and initialize new station */
if (!Station::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_STATIONS_LOADING); 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); 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) { if (st->airport.tile != INVALID_TILE) {
return_cmd_error(STR_ERROR_TOO_CLOSE_TO_ANOTHER_AIRPORT); 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); 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]), 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); if (st->dock_tile != INVALID_TILE) return_cmd_error(STR_ERROR_TOO_CLOSE_TO_ANOTHER_DOCK);
} else { } else {

View File

@ -1293,7 +1293,7 @@ static bool AddNearbyStation(TileIndex tile, void *user_data)
T *st = T::Get(sid); T *st = T::Get(sid);
if (st->owner != _local_company || _stations_nearby_list.Contains(sid)) return false; 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; *_stations_nearby_list.Append() = sid;
} }

View File

@ -273,7 +273,9 @@ CommandCost CmdBuildRailWaypoint(TileIndex start_tile, DoCommandFlag flags, uint
if (ret.Failed()) return ret; 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 { } else {
/* allocate and initialize new waypoint */ /* allocate and initialize new waypoint */
if (!Waypoint::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_STATIONS_LOADING); if (!Waypoint::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_STATIONS_LOADING);