summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoralberth <alberth@openttd.org>2010-03-06 13:23:33 +0000
committeralberth <alberth@openttd.org>2010-03-06 13:23:33 +0000
commit6a3dbaf99a91aa223b2541c172f0ded06c55baf2 (patch)
tree49acf1aa8af1af505e37797a833d9c969d345d2a /src
parentef5764f98a665f554d168c10ac4f5b147d7e0dc3 (diff)
downloadopenttd-6a3dbaf99a91aa223b2541c172f0ded06c55baf2.tar.xz
(svn r19350) -Codechange: StationRect::BeforeAddRect() returns a CommandCost.
Diffstat (limited to 'src')
-rw-r--r--src/base_station_base.h2
-rw-r--r--src/station.cpp7
-rw-r--r--src/station_cmd.cpp18
-rw-r--r--src/station_gui.cpp2
-rw-r--r--src/waypoint_cmd.cpp4
5 files changed, 21 insertions, 12 deletions
diff --git a/src/base_station_base.h b/src/base_station_base.h
index d6d97cc83..e652c3264 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 9ef44a280..416403048 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 17d110401..70f8690ef 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 6efb569f2..e731931dd 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 7be4a6ce4..04db4fc93 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);