Changeset - r14752:ebcf936bf2ae
[Not reviewed]
master
0 5 0
alberth - 15 years ago 2010-03-06 13:23:33
alberth@openttd.org
(svn r19350) -Codechange: StationRect::BeforeAddRect() returns a CommandCost.
5 files changed with 21 insertions and 12 deletions:
0 comments (0 inline, 0 general)
src/base_station_base.h
Show inline comments
 
@@ -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);
 

	
src/station.cpp
Show inline comments
 
@@ -400,16 +400,15 @@ CommandCost StationRect::BeforeAddTile(T
 
	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();
 
}
 

	
 
/**
src/station_cmd.cpp
Show inline comments
 
@@ -1159,7 +1159,9 @@ CommandCost CmdBuildRailStation(TileInde
 
		}
 

	
 
		/* 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 t
 
			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 ti
 
			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,
 
			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 {
src/station_gui.cpp
Show inline comments
 
@@ -1293,7 +1293,7 @@ static bool AddNearbyStation(TileIndex t
 
	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;
 
	}
 

	
src/waypoint_cmd.cpp
Show inline comments
 
@@ -273,7 +273,9 @@ CommandCost CmdBuildRailWaypoint(TileInd
 
			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);
0 comments (0 inline, 0 general)