Changeset - r14442:71e906ee7140
[Not reviewed]
master
0 1 0
terkhen - 15 years ago 2010-02-04 21:09:29
terkhen@openttd.org
(svn r19010) -Codechange: Remove a now unneeded check at CmdBuildRailStation.
1 file changed with 6 insertions and 13 deletions:
0 comments (0 inline, 0 general)
src/station_cmd.cpp
Show inline comments
 
@@ -985,57 +985,56 @@ CommandCost CmdBuildRailStation(TileInde
 
	if (plat_len == 0 || numtracks == 0) return CMD_ERROR;
 

	
 
	int w_org, h_org;
 
	if (axis == AXIS_X) {
 
		w_org = plat_len;
 
		h_org = numtracks;
 
	} else {
 
		h_org = plat_len;
 
		w_org = numtracks;
 
	}
 

	
 
	bool reuse = (station_to_join != NEW_STATION);
 
	if (!reuse) station_to_join = INVALID_STATION;
 
	bool distant_join = (station_to_join != INVALID_STATION);
 

	
 
	if (distant_join && (!_settings_game.station.distant_join_stations || !Station::IsValidID(station_to_join))) return CMD_ERROR;
 

	
 
	if (h_org > _settings_game.station.station_spread || w_org > _settings_game.station.station_spread) return CMD_ERROR;
 

	
 
	/* these values are those that will be stored in train_tile and station_platforms */
 
	TileArea new_location(tile_org, w_org, h_org);
 

	
 
	/* Make sure the area below consists of clear tiles. (OR tiles belonging to a certain rail station) */
 
	StationID est = INVALID_STATION;
 
	/* If DC_EXEC is in flag, do not want to pass it to CheckFlatLandBelow, because of a nice bug
 
	 * for detail info, see:
 
	 * https://sourceforge.net/tracker/index.php?func=detail&aid=1029064&group_id=103924&atid=636365 */
 
	CommandCost ret = CheckFlatLandBelow(tile_org, w_org, h_org, flags & ~DC_EXEC, 5 << axis, _settings_game.station.nonuniform_stations ? &est : NULL, true, rt);
 
	if (ret.Failed()) return ret;
 
	CommandCost cost(EXPENSES_CONSTRUCTION, ret.GetCost() + (numtracks * _price[PR_BUILD_STATION_RAIL] + _price[PR_BUILD_STATION_RAIL_LENGTH]) * plat_len);
 
	/* Clear the land below the station. */
 
	CommandCost cost = CheckFlatLandBelow(tile_org, w_org, h_org, flags, 5 << axis, _settings_game.station.nonuniform_stations ? &est : NULL, true, rt);
 
	if (cost.Failed()) return cost;
 
	/* Add construction expenses. */
 
	cost.AddCost((numtracks * _price[PR_BUILD_STATION_RAIL] + _price[PR_BUILD_STATION_RAIL_LENGTH]) * plat_len);
 

	
 
	Station *st = NULL;
 
	ret = FindJoiningStation(est, station_to_join, adjacent, new_location, &st);
 
	CommandCost ret = FindJoiningStation(est, station_to_join, adjacent, new_location, &st);
 
	if (ret.Failed()) return ret;
 

	
 
	/* See if there is a deleted station close to us. */
 
	if (st == NULL && reuse) st = GetClosestDeletedStation(tile_org);
 

	
 
	if (st != NULL) {
 
		/* Reuse an existing station. */
 
		if (st->owner != _current_company)
 
			return_cmd_error(STR_ERROR_TOO_CLOSE_TO_ANOTHER_STATION);
 

	
 
		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;
 
		}
 

	
 
		/* 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;
 
	} else {
 
		/* allocate and initialize new station */
 
		if (!Station::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_STATIONS_LOADING);
 

	
 
@@ -1055,54 +1054,48 @@ CommandCost CmdBuildRailStation(TileInde
 
	const StationSpec *statspec = GetCustomStationSpec(spec_class, spec_index);
 
	int specindex = AllocateSpecToStation(statspec, st, (flags & DC_EXEC) != 0);
 
	if (specindex == -1) return_cmd_error(STR_ERROR_TOO_MANY_STATION_SPECS);
 

	
 
	if (statspec != NULL) {
 
		/* Perform NewStation checks */
 

	
 
		/* Check if the station size is permitted */
 
		if (HasBit(statspec->disallowed_platforms, numtracks - 1) || HasBit(statspec->disallowed_lengths, plat_len - 1)) {
 
			return CMD_ERROR;
 
		}
 

	
 
		/* Check if the station is buildable */
 
		if (HasBit(statspec->callback_mask, CBM_STATION_AVAIL) && GB(GetStationCallback(CBID_STATION_AVAILABILITY, 0, 0, statspec, NULL, INVALID_TILE), 0, 8) == 0) {
 
			return CMD_ERROR;
 
		}
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		TileIndexDiff tile_delta;
 
		byte *layout_ptr;
 
		byte numtracks_orig;
 
		Track track;
 

	
 
		/* Now really clear the land below the station
 
		 * It should never return CMD_ERROR.. but you never know ;)
 
		 * (a bit strange function name for it, but it really does clear the land, when DC_EXEC is in flags) */
 
		ret = CheckFlatLandBelow(tile_org, w_org, h_org, flags, 5 << axis, _settings_game.station.nonuniform_stations ? &est : NULL, true, rt);
 
		if (ret.Failed()) return ret;
 

	
 
		st->train_station = new_location;
 
		st->AddFacility(FACIL_TRAIN, new_location.tile);
 

	
 
		st->rect.BeforeAddRect(tile_org, w_org, h_org, StationRect::ADD_TRY);
 

	
 
		if (statspec != NULL) {
 
			/* Include this station spec's animation trigger bitmask
 
			 * in the station's cached copy. */
 
			st->cached_anim_triggers |= statspec->anim_triggers;
 
		}
 

	
 
		tile_delta = (axis == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
 
		track = AxisToTrack(axis);
 

	
 
		layout_ptr = AllocaM(byte, numtracks * plat_len);
 
		GetStationLayout(layout_ptr, numtracks, plat_len, statspec);
 

	
 
		numtracks_orig = numtracks;
 

	
 
		SmallVector<Train*, 4> affected_vehicles;
 
		do {
 
			TileIndex tile = tile_org;
 
			int w = plat_len;
 
			do {
0 comments (0 inline, 0 general)