Changeset - r19437:273b94619371
[Not reviewed]
master
0 1 0
frosch - 12 years ago 2012-06-23 15:27:15
frosch@openttd.org
(svn r24354) -Fix: When airport construction was denied due to noise, the error message named the wrong town.
1 file changed with 4 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/station_cmd.cpp
Show inline comments
 
@@ -2120,115 +2120,118 @@ void UpdateAirportsNoise()
 
 * - p1 = (bit  0- 7) - airport type, @see airport.h
 
 * - p1 = (bit  8-15) - airport layout
 
 * @param p2 various bitstuffed elements
 
 * - p2 = (bit     0) - allow airports directly adjacent to other airports.
 
 * - p2 = (bit 16-31) - station ID to join (NEW_STATION if build new one)
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdBuildAirport(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	StationID station_to_join = GB(p2, 16, 16);
 
	bool reuse = (station_to_join != NEW_STATION);
 
	if (!reuse) station_to_join = INVALID_STATION;
 
	bool distant_join = (station_to_join != INVALID_STATION);
 
	byte airport_type = GB(p1, 0, 8);
 
	byte layout = GB(p1, 8, 8);
 

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

	
 
	if (airport_type >= NUM_AIRPORTS) return CMD_ERROR;
 

	
 
	CommandCost ret = CheckIfAuthorityAllowsNewStation(tile, flags);
 
	if (ret.Failed()) return ret;
 

	
 
	/* Check if a valid, buildable airport was chosen for construction */
 
	const AirportSpec *as = AirportSpec::Get(airport_type);
 
	if (!as->IsAvailable() || layout >= as->num_table) return CMD_ERROR;
 

	
 
	Direction rotation = as->rotation[layout];
 
	Town *t = ClosestTownFromTile(tile, UINT_MAX);
 
	int w = as->size_x;
 
	int h = as->size_y;
 
	if (rotation == DIR_E || rotation == DIR_W) Swap(w, h);
 

	
 
	if (w > _settings_game.station.station_spread || h > _settings_game.station.station_spread) {
 
		return_cmd_error(STR_ERROR_STATION_TOO_SPREAD_OUT);
 
	}
 

	
 
	CommandCost cost = CheckFlatLand(TileArea(tile, w, h), flags);
 
	if (cost.Failed()) return cost;
 

	
 
	/* The noise level is the noise from the airport and reduce it to account for the distance to the town center. */
 
	AirportTileTableIterator iter(as->table[layout], tile);
 
	Town *nearest = AirportGetNearestTown(as, iter);
 
	uint newnoise_level = GetAirportNoiseLevelForTown(as, iter, nearest->xy);
 

	
 
	/* Check if local auth would allow a new airport */
 
	StringID authority_refuse_message = STR_NULL;
 
	Town *authority_refuse_town = NULL;
 

	
 
	if (_settings_game.economy.station_noise_level) {
 
		/* do not allow to build a new airport if this raise the town noise over the maximum allowed by town */
 
		if ((nearest->noise_reached + newnoise_level) > nearest->MaxTownNoise()) {
 
			authority_refuse_message = STR_ERROR_LOCAL_AUTHORITY_REFUSES_NOISE;
 
			authority_refuse_town = nearest;
 
		}
 
	} else {
 
		uint num = 0;
 
		const Station *st;
 
		FOR_ALL_STATIONS(st) {
 
			if (st->town == t && (st->facilities & FACIL_AIRPORT) && st->airport.type != AT_OILRIG) num++;
 
		}
 
		if (num >= 2) {
 
			authority_refuse_message = STR_ERROR_LOCAL_AUTHORITY_REFUSES_AIRPORT;
 
			authority_refuse_town = t;
 
		}
 
	}
 

	
 
	if (authority_refuse_message != STR_NULL) {
 
		SetDParam(0, t->index);
 
		SetDParam(0, authority_refuse_town->index);
 
		return_cmd_error(authority_refuse_message);
 
	}
 

	
 
	Station *st = NULL;
 
	ret = FindJoiningStation(INVALID_STATION, station_to_join, HasBit(p2, 0), TileArea(tile, w, h), &st);
 
	if (ret.Failed()) return ret;
 

	
 
	/* Distant join */
 
	if (st == NULL && distant_join) st = Station::GetIfValid(station_to_join);
 

	
 
	/* Find a deleted station close to us */
 
	if (st == NULL && reuse) st = GetClosestDeletedStation(tile);
 

	
 
	if (st != NULL) {
 
		if (st->owner != _current_company) {
 
			return_cmd_error(STR_ERROR_TOO_CLOSE_TO_ANOTHER_STATION);
 
		}
 

	
 
		CommandCost ret = st->rect.BeforeAddRect(tile, w, h, StationRect::ADD_TEST);
 
		if (ret.Failed()) return ret;
 

	
 
		if (st->airport.tile != INVALID_TILE) {
 
			return_cmd_error(STR_ERROR_TOO_CLOSE_TO_ANOTHER_AIRPORT);
 
		}
 
	} else {
 
		/* allocate and initialize new station */
 
		if (!Station::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_STATIONS_LOADING);
 

	
 
		if (flags & DC_EXEC) {
 
			st = new Station(tile);
 

	
 
			st->town = t;
 
			st->string_id = GenerateStationName(st, tile, !(GetAirport(airport_type)->flags & AirportFTAClass::AIRPLANES) ? STATIONNAMING_HELIPORT : STATIONNAMING_AIRPORT);
 

	
 
			if (Company::IsValidID(_current_company)) {
 
				SetBit(st->town->have_ratings, _current_company);
 
			}
 
		}
 
	}
 

	
 
	for (AirportTileTableIterator iter(as->table[layout], tile); iter != INVALID_TILE; ++iter) {
 
		cost.AddCost(_price[PR_BUILD_STATION_AIRPORT]);
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		/* Always add the noise, so there will be no need to recalculate when option toggles */
 
		nearest->noise_reached += newnoise_level;
 

	
0 comments (0 inline, 0 general)