Changeset - r25911:93ba9bfb32b9
[Not reviewed]
master
0 1 0
Joan Josep - 3 years ago 2021-08-18 12:33:32
juanjo.ng.83@gmail.com
Fix 659989af45: Set appropriate town window dirty when building/removing airports. (#9497)
1 file changed with 5 insertions and 5 deletions:
0 comments (0 inline, 0 general)
src/station_cmd.cpp
Show inline comments
 
@@ -2338,128 +2338,128 @@ CommandCost CmdBuildAirport(TileIndex ti
 

	
 
		st->rect.BeforeAddRect(tile, w, h, StationRect::ADD_TRY);
 

	
 
		for (AirportTileTableIterator iter(as->table[layout], tile); iter != INVALID_TILE; ++iter) {
 
			MakeAirport(iter, st->owner, st->index, iter.GetStationGfx(), WATER_CLASS_INVALID);
 
			SetStationTileRandomBits(iter, GB(Random(), 0, 4));
 
			st->airport.Add(iter);
 

	
 
			if (AirportTileSpec::Get(GetTranslatedAirportTileID(iter.GetStationGfx()))->animation.status != ANIM_STATUS_NO_ANIMATION) AddAnimatedTile(iter);
 
		}
 

	
 
		/* Only call the animation trigger after all tiles have been built */
 
		for (AirportTileTableIterator iter(as->table[layout], tile); iter != INVALID_TILE; ++iter) {
 
			AirportTileAnimationTrigger(st, iter, AAT_BUILT);
 
		}
 

	
 
		UpdateAirplanesOnNewStation(st);
 

	
 
		Company::Get(st->owner)->infrastructure.airport++;
 

	
 
		st->AfterStationTileSetChange(true, STATION_AIRPORT);
 
		InvalidateWindowData(WC_STATION_VIEW, st->index, -1);
 

	
 
		if (_settings_game.economy.station_noise_level) {
 
			SetWindowDirty(WC_TOWN_VIEW, st->town->index);
 
			SetWindowDirty(WC_TOWN_VIEW, nearest->index);
 
		}
 
	}
 

	
 
	return cost;
 
}
 

	
 
/**
 
 * Remove an airport
 
 * @param tile TileIndex been queried
 
 * @param flags operation to perform
 
 * @return cost or failure of operation
 
 */
 
static CommandCost RemoveAirport(TileIndex tile, DoCommandFlag flags)
 
{
 
	Station *st = Station::GetByTile(tile);
 

	
 
	if (_current_company != OWNER_WATER) {
 
		CommandCost ret = CheckOwnership(st->owner);
 
		if (ret.Failed()) return ret;
 
	}
 

	
 
	tile = st->airport.tile;
 

	
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 

	
 
	for (const Aircraft *a : Aircraft::Iterate()) {
 
		if (!a->IsNormalAircraft()) continue;
 
		if (a->targetairport == st->index && a->state != FLYING) {
 
			return_cmd_error(STR_ERROR_AIRCRAFT_IN_THE_WAY);
 
		}
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		for (uint i = 0; i < st->airport.GetNumHangars(); ++i) {
 
			TileIndex tile_cur = st->airport.GetHangarTile(i);
 
			OrderBackup::Reset(tile_cur, false);
 
			CloseWindowById(WC_VEHICLE_DEPOT, tile_cur);
 
		}
 

	
 
		const AirportSpec *as = st->airport.GetSpec();
 
		/* The noise level is the noise from the airport and reduce it to account for the distance to the town center.
 
		 * And as for construction, always remove it, even if the setting is not set, in order to avoid the
 
		 * need of recalculation */
 
		AirportTileIterator it(st);
 
		uint dist;
 
		Town *nearest = AirportGetNearestTown(as, it, dist);
 
		nearest->noise_reached -= GetAirportNoiseLevelForDistance(as, dist);
 

	
 
		if (_settings_game.economy.station_noise_level) {
 
			SetWindowDirty(WC_TOWN_VIEW, nearest->index);
 
		}
 
	}
 

	
 
	for (TileIndex tile_cur : st->airport) {
 
		if (!st->TileBelongsToAirport(tile_cur)) continue;
 

	
 
		CommandCost ret = EnsureNoVehicleOnGround(tile_cur);
 
		if (ret.Failed()) return ret;
 

	
 
		cost.AddCost(_price[PR_CLEAR_STATION_AIRPORT]);
 

	
 
		if (flags & DC_EXEC) {
 
			DeleteAnimatedTile(tile_cur);
 
			DoClearSquare(tile_cur);
 
			DeleteNewGRFInspectWindow(GSF_AIRPORTTILES, tile_cur);
 
		}
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		/* Clear the persistent storage. */
 
		delete st->airport.psa;
 

	
 
		st->rect.AfterRemoveRect(st, st->airport);
 

	
 
		st->airport.Clear();
 
		st->facilities &= ~FACIL_AIRPORT;
 

	
 
		InvalidateWindowData(WC_STATION_VIEW, st->index, -1);
 

	
 
		if (_settings_game.economy.station_noise_level) {
 
			SetWindowDirty(WC_TOWN_VIEW, st->town->index);
 
		}
 

	
 
		Company::Get(st->owner)->infrastructure.airport--;
 

	
 
		st->AfterStationTileSetChange(false, STATION_AIRPORT);
 

	
 
		DeleteNewGRFInspectWindow(GSF_AIRPORTS, st->index);
 
	}
 

	
 
	return cost;
 
}
 

	
 
/**
 
 * Open/close an airport to incoming aircraft.
 
 * @param tile Unused.
 
 * @param flags Operation to perform.
 
 * @param p1 Station ID of the airport.
 
 * @param p2 Unused.
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdOpenCloseAirport(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const std::string &text)
 
{
 
	if (!Station::IsValidID(p1)) return CMD_ERROR;
 
	Station *st = Station::Get(p1);
 

	
0 comments (0 inline, 0 general)