Changeset - r14683:3efbea14e64e
[Not reviewed]
master
0 2 0
alberth - 15 years ago 2010-02-27 14:17:33
alberth@openttd.org
(svn r19275) -Codechange: CanExpandRailStation() returns a CommandCost.
2 files changed with 17 insertions and 17 deletions:
0 comments (0 inline, 0 general)
src/station_cmd.cpp
Show inline comments
 
@@ -891,9 +891,9 @@ static CommandCost CheckFlatLandRoadStop
 
 * @param st the station to expand
 
 * @param new_ta the current (and if all is fine new) tile area of the rail part of the station
 
 * @param axis the axis of the newly build rail
 
 * @return true if we are allowed to extend
 
 * @return Succeeded or failed command.
 
 */
 
bool CanExpandRailStation(const BaseStation *st, TileArea &new_ta, Axis axis)
 
CommandCost CanExpandRailStation(const BaseStation *st, TileArea &new_ta, Axis axis)
 
{
 
	TileArea cur_ta = st->train_station;
 

	
 
@@ -909,15 +909,13 @@ bool CanExpandRailStation(const BaseStat
 
		 * the uniform-stations code wouldn't handle it well */
 
		TILE_LOOP(t, cur_ta.w, cur_ta.h, cur_ta.tile) {
 
			if (!st->TileBelongsToRailStation(t)) { // there may be adjoined station
 
				_error_message = STR_ERROR_NONUNIFORM_STATIONS_DISALLOWED;
 
				return false;
 
				return_cmd_error(STR_ERROR_NONUNIFORM_STATIONS_DISALLOWED);
 
			}
 
		}
 

	
 
		/* check so the orientation is the same */
 
		if (GetRailStationAxis(cur_ta.tile) != axis) {
 
			_error_message = STR_ERROR_NONUNIFORM_STATIONS_DISALLOWED;
 
			return false;
 
			return_cmd_error(STR_ERROR_NONUNIFORM_STATIONS_DISALLOWED);
 
		}
 

	
 
		/* check if the new station adjoins the old station in either direction */
 
@@ -936,17 +934,15 @@ bool CanExpandRailStation(const BaseStat
 
			new_ta.tile = cur_ta.tile;
 
			new_ta.w += cur_ta.w;
 
		} else {
 
			_error_message = STR_ERROR_NONUNIFORM_STATIONS_DISALLOWED;
 
			return false;
 
			return_cmd_error(STR_ERROR_NONUNIFORM_STATIONS_DISALLOWED);
 
		}
 
	}
 
	/* make sure the final size is not too big. */
 
	if (new_ta.w > _settings_game.station.station_spread || new_ta.h > _settings_game.station.station_spread) {
 
		_error_message = STR_ERROR_STATION_TOO_SPREAD_OUT;
 
		return false;
 
		return_cmd_error(STR_ERROR_STATION_TOO_SPREAD_OUT);
 
	}
 

	
 
	return true;
 
	return CommandCost();
 
}
 

	
 
static inline byte *CreateSingle(byte *layout, int n)
 
@@ -1150,10 +1146,11 @@ CommandCost CmdBuildRailStation(TileInde
 

	
 
		if (st->train_station.tile != INVALID_TILE) {
 
			/* check if we want to expanding an already existing station? */
 
			if (!_settings_game.station.join_stations)
 
				return_cmd_error(STR_ERROR_TOO_CLOSE_TO_ANOTHER_RAILROAD);
 
			if (!CanExpandRailStation(st, new_location, axis))
 
				return CMD_ERROR;
 
			if (!_settings_game.station.join_stations) return_cmd_error(STR_ERROR_TOO_CLOSE_TO_ANOTHER_RAILROAD);
 

	
 
			CommandCost ret = CanExpandRailStation(st, new_location, axis);
 
			ret.SetGlobalErrorMessage();
 
			if (ret.Failed()) return ret;
 
		}
 

	
 
		/* XXX can't we pack this in the "else" part of the if above? */
src/waypoint_cmd.cpp
Show inline comments
 
@@ -194,7 +194,7 @@ static CommandCost IsValidTileForWaypoin
 

	
 
extern void GetStationLayout(byte *layout, int numtracks, int plat_len, const StationSpec *statspec);
 
extern CommandCost FindJoiningWaypoint(StationID existing_station, StationID station_to_join, bool adjacent, TileArea ta, Waypoint **wp);
 
extern bool CanExpandRailStation(const BaseStation *st, TileArea &new_ta, Axis axis);
 
extern CommandCost CanExpandRailStation(const BaseStation *st, TileArea &new_ta, Axis axis);
 

	
 
/** Convert existing rail to waypoint. Eg build a waypoint station over
 
 * piece of rail
 
@@ -265,7 +265,10 @@ CommandCost CmdBuildRailWaypoint(TileInd
 
		if (wp->owner != _current_company) return_cmd_error(STR_ERROR_TOO_CLOSE_TO_ANOTHER_WAYPOINT);
 

	
 
		/* check if we want to expand an already existing waypoint? */
 
		if (wp->train_station.tile != INVALID_TILE && !CanExpandRailStation(wp, new_location, axis)) return CMD_ERROR;
 
		if (wp->train_station.tile != INVALID_TILE) {
 
			CommandCost ret = CanExpandRailStation(wp, new_location, axis);
 
			if (ret.Failed()) return ret;
 
		}
 

	
 
		if (!wp->rect.BeforeAddRect(start_tile, width, height, StationRect::ADD_TEST)) return CMD_ERROR;
 
	} else {
0 comments (0 inline, 0 general)