Changeset - r12519:e52fcaadf579
[Not reviewed]
master
0 13 0
rubidium - 15 years ago 2009-07-26 21:50:30
rubidium@openttd.org
(svn r16966) -Codechange: BEGIN_TILE_LOOP and END_TILE_LOOP reworked into TILE_LOOP, which means no more duplication of parameters between BEGIN_TILE_LOOP and END_TILE_LOOP
13 files changed with 71 insertions and 87 deletions:
0 comments (0 inline, 0 general)
src/ai/api/ai_industry.cpp
Show inline comments
 
@@ -139,17 +139,17 @@
 
/* static */ TileIndex AIIndustry::GetHeliportLocation(IndustryID industry_id)
 
{
 
	if (!IsValidIndustry(industry_id)) return INVALID_TILE;
 
	if (!HasHeliport(industry_id)) return INVALID_TILE;
 

	
 
	const Industry *ind = ::Industry::Get(industry_id);
 
	BEGIN_TILE_LOOP(tile_cur, ind->width, ind->height, ind->xy);
 
	TILE_LOOP(tile_cur, ind->width, ind->height, ind->xy) {
 
		if (IsTileType(tile_cur, MP_STATION) && IsOilRig(tile_cur)) {
 
			return tile_cur;
 
		}
 
	END_TILE_LOOP(tile_cur, ind->width, ind->height, ind->xy);
 
	}
 

	
 
	return INVALID_TILE;
 
}
 

	
 
/* static */ bool AIIndustry::HasDock(IndustryID industry_id)
 
{
 
@@ -161,17 +161,17 @@
 
/* static */ TileIndex AIIndustry::GetDockLocation(IndustryID industry_id)
 
{
 
	if (!IsValidIndustry(industry_id)) return INVALID_TILE;
 
	if (!HasDock(industry_id)) return INVALID_TILE;
 

	
 
	const Industry *ind = ::Industry::Get(industry_id);
 
	BEGIN_TILE_LOOP(tile_cur, ind->width, ind->height, ind->xy);
 
	TILE_LOOP(tile_cur, ind->width, ind->height, ind->xy) {
 
		if (IsTileType(tile_cur, MP_STATION) && IsOilRig(tile_cur)) {
 
			return tile_cur;
 
		}
 
	END_TILE_LOOP(tile_cur, ind->width, ind->height, ind->xy);
 
	}
 

	
 
	return INVALID_TILE;
 
}
 

	
 
/* static */ IndustryType AIIndustry::GetIndustryType(IndustryID industry_id)
 
{
src/ai/api/ai_order.cpp
Show inline comments
 
@@ -189,15 +189,15 @@ static const Order *ResolveOrder(Vehicle
 
			} else if (st->bus_stops != NULL) {
 
				return st->bus_stops->xy;
 
			} else if (st->truck_stops != NULL) {
 
				return st->truck_stops->xy;
 
			} else if (st->airport_tile != INVALID_TILE) {
 
				const AirportFTAClass *fta = st->Airport();
 
				BEGIN_TILE_LOOP(tile, fta->size_x, fta->size_y, st->airport_tile) {
 
				TILE_LOOP(tile, fta->size_x, fta->size_y, st->airport_tile) {
 
					if (!::IsHangar(tile)) return tile;
 
				} END_TILE_LOOP(tile, fta->size_x, fta->size_y, st->airport_tile)
 
				}
 
			}
 
			return INVALID_TILE;
 
		}
 
		case OT_GOTO_WAYPOINT: return ::Waypoint::Get(order->GetDestination())->xy;
 
		default:               return INVALID_TILE;
 
	}
src/ai/api/ai_tilelist.cpp
Show inline comments
 
@@ -31,15 +31,13 @@ void AITileList::AddRectangle(TileIndex 
 

	
 
	this->FixRectangleSpan(t1, t2);
 

	
 
	uint w = TileX(t2) - TileX(t1) + 1;
 
	uint h = TileY(t2) - TileY(t1) + 1;
 

	
 
	BEGIN_TILE_LOOP(t, w, h, t1) {
 
		this->AddItem(t);
 
	} END_TILE_LOOP(t, w, h, t1)
 
	TILE_LOOP(t, w, h, t1) this->AddItem(t);
 
}
 

	
 
void AITileList::AddTile(TileIndex tile)
 
{
 
	if (!::IsValidTile(tile)) return;
 

	
 
@@ -53,15 +51,13 @@ void AITileList::RemoveRectangle(TileInd
 

	
 
	this->FixRectangleSpan(t1, t2);
 

	
 
	uint w = TileX(t2) - TileX(t1) + 1;
 
	uint h = TileY(t2) - TileY(t1) + 1;
 

	
 
	BEGIN_TILE_LOOP(t, w, h, t1) {
 
		this->RemoveItem(t);
 
	} END_TILE_LOOP(t, w, h, t1)
 
	TILE_LOOP(t, w, h, t1) this->RemoveItem(t);
 
}
 

	
 
void AITileList::RemoveTile(TileIndex tile)
 
{
 
	if (!::IsValidTile(tile)) return;
 

	
 
@@ -82,13 +78,13 @@ AITileList_IndustryAccepting::AITileList
 
		}
 
		if (!cargo_accepts) return;
 
	}
 

	
 
	if (!_settings_game.station.modified_catchment) radius = CA_UNMODIFIED;
 

	
 
	BEGIN_TILE_LOOP(cur_tile, i->width + radius * 2, i->height + radius * 2, i->xy - ::TileDiffXY(radius, radius)) {
 
	TILE_LOOP(cur_tile, i->width + radius * 2, i->height + radius * 2, i->xy - ::TileDiffXY(radius, radius)) {
 
		if (!::IsValidTile(cur_tile)) continue;
 
		/* Exclude all tiles that belong to this industry */
 
		if (::IsTileType(cur_tile, MP_INDUSTRY) && ::GetIndustryIndex(cur_tile) == industry_id) continue;
 

	
 
		/* Only add the tile if it accepts the cargo (sometimes just 1 tile of an
 
		 *  industry triggers the acceptance). */
 
@@ -99,13 +95,13 @@ AITileList_IndustryAccepting::AITileList
 
				if (i->accepts_cargo[j] != CT_INVALID && acceptance[i->accepts_cargo[j]] != 0) cargo_accepts = true;
 
			}
 
			if (!cargo_accepts) continue;
 
		}
 

	
 
		this->AddTile(cur_tile);
 
	} END_TILE_LOOP(cur_tile, i->width + radius * 2, i->height + radius * 2, i->xy - ::TileDiffXY(radius, radius))
 
	}
 
}
 

	
 
AITileList_IndustryProducing::AITileList_IndustryProducing(IndustryID industry_id, int radius)
 
{
 
	if (!AIIndustry::IsValidIndustry(industry_id) || radius <= 0) return;
 

	
 
@@ -119,13 +115,13 @@ AITileList_IndustryProducing::AITileList
 
		}
 
		if (!cargo_produces) return;
 
	}
 

	
 
	if (!_settings_game.station.modified_catchment) radius = CA_UNMODIFIED;
 

	
 
	BEGIN_TILE_LOOP(cur_tile, i->width + radius * 2, i->height + radius * 2, i->xy - ::TileDiffXY(radius, radius)) {
 
	TILE_LOOP(cur_tile, i->width + radius * 2, i->height + radius * 2, i->xy - ::TileDiffXY(radius, radius)) {
 
		if (!::IsValidTile(cur_tile)) continue;
 
		/* Exclude all tiles that belong to this industry */
 
		if (::IsTileType(cur_tile, MP_INDUSTRY) && ::GetIndustryIndex(cur_tile) == industry_id) continue;
 

	
 
		/* Only add the tile if it produces the cargo (a bug in OpenTTD makes this
 
		 *  inconsitance). */
 
@@ -136,13 +132,13 @@ AITileList_IndustryProducing::AITileList
 
				if (i->produced_cargo[j] != CT_INVALID && produced[i->produced_cargo[j]] != 0) cargo_produces = true;
 
			}
 
			if (!cargo_produces) continue;
 
		}
 

	
 
		this->AddTile(cur_tile);
 
	} END_TILE_LOOP(cur_tile, i->width + radius * 2, i->height + radius * 2, i->xy - ::TileDiffXY(radius, radius))
 
	}
 
}
 

	
 
AITileList_StationType::AITileList_StationType(StationID station_id, AIStation::StationType station_type)
 
{
 
	if (!AIStation::IsValidStation(station_id)) return;
 

	
 
@@ -154,13 +150,13 @@ AITileList_StationType::AITileList_Stati
 
	if ((station_type & AIStation::STATION_TRAIN) != 0)      station_type_value |= (1 << ::STATION_RAIL);
 
	if ((station_type & AIStation::STATION_TRUCK_STOP) != 0) station_type_value |= (1 << ::STATION_TRUCK);
 
	if ((station_type & AIStation::STATION_BUS_STOP) != 0)   station_type_value |= (1 << ::STATION_BUS);
 
	if ((station_type & AIStation::STATION_AIRPORT) != 0)    station_type_value |= (1 << ::STATION_AIRPORT) | (1 << ::STATION_OILRIG);
 
	if ((station_type & AIStation::STATION_DOCK) != 0)       station_type_value |= (1 << ::STATION_DOCK)    | (1 << ::STATION_OILRIG);
 

	
 
	BEGIN_TILE_LOOP(cur_tile, rect->right - rect->left + 1, rect->bottom - rect->top + 1, ::TileXY(rect->left, rect->top)) {
 
	TILE_LOOP(cur_tile, rect->right - rect->left + 1, rect->bottom - rect->top + 1, ::TileXY(rect->left, rect->top)) {
 
		if (!::IsTileType(cur_tile, MP_STATION)) continue;
 
		if (::GetStationIndex(cur_tile) != station_id) continue;
 
		if (!HasBit(station_type_value, ::GetStationType(cur_tile))) continue;
 
		this->AddTile(cur_tile);
 
	} END_TILE_LOOP(cur_tile, rect->right - rect->left + 1, rect->bottom - rect->top + 1, ::TileXY(rect->left, rect->top))
 
}
 
}
src/industry_cmd.cpp
Show inline comments
 
@@ -133,36 +133,36 @@ Industry::~Industry()
 
	if (CleaningPool()) return;
 

	
 
	/* Industry can also be destroyed when not fully initialized.
 
	 * This means that we do not have to clear tiles either. */
 
	if (this->width == 0) return;
 

	
 
	BEGIN_TILE_LOOP(tile_cur, this->width, this->height, this->xy);
 
	TILE_LOOP(tile_cur, this->width, this->height, this->xy) {
 
		if (IsTileType(tile_cur, MP_INDUSTRY)) {
 
			if (GetIndustryIndex(tile_cur) == this->index) {
 
				/* MakeWaterKeepingClass() can also handle 'land' */
 
				MakeWaterKeepingClass(tile_cur, OWNER_NONE);
 

	
 
				/* MakeWaterKeepingClass() doesn't remove animation if the tiles
 
				 * become watery, but be on the safe side an always remote it. */
 
				DeleteAnimatedTile(tile_cur);
 
			}
 
		} else if (IsTileType(tile_cur, MP_STATION) && IsOilRig(tile_cur)) {
 
			DeleteOilRig(tile_cur);
 
		}
 
	END_TILE_LOOP(tile_cur, this->width, this->height, this->xy);
 
	}
 

	
 
	if (GetIndustrySpec(this->type)->behaviour & INDUSTRYBEH_PLANT_FIELDS) {
 
		/* Remove the farmland and convert it to regular tiles over time. */
 
		BEGIN_TILE_LOOP(tile_cur, 42, 42, this->xy - TileDiffXY(21, 21)) {
 
		TILE_LOOP(tile_cur, 42, 42, this->xy - TileDiffXY(21, 21)) {
 
			tile_cur = TILE_MASK(tile_cur);
 
			if (IsTileType(tile_cur, MP_CLEAR) && IsClearGround(tile_cur, CLEAR_FIELDS) &&
 
					GetIndustryIndexOfField(tile_cur) == this->index) {
 
				SetIndustryIndexOfField(tile_cur, INVALID_INDUSTRY);
 
			}
 
		} END_TILE_LOOP(tile_cur, 42, 42, this->xy - TileDiff(21, 21))
 
		}
 
	}
 

	
 
	/* don't let any disaster vehicle target invalid industry */
 
	ReleaseDisastersTargetingIndustry(this->index);
 

	
 
	DecIndustryTypeCount(this->type);
 
@@ -954,32 +954,32 @@ static void PlantFarmField(TileIndex til
 
	tile -= TileDiffXY(size_x / 2, size_y / 2);
 

	
 
	if (TileX(tile) + size_x >= MapSizeX() || TileY(tile) + size_y >= MapSizeY()) return;
 

	
 
	/* check the amount of bad tiles */
 
	count = 0;
 
	BEGIN_TILE_LOOP(cur_tile, size_x, size_y, tile)
 
	TILE_LOOP(cur_tile, size_x, size_y, tile) {
 
		assert(cur_tile < MapSize());
 
		count += IsBadFarmFieldTile(cur_tile);
 
	END_TILE_LOOP(cur_tile, size_x, size_y, tile)
 
	}
 
	if (count * 2 >= size_x * size_y) return;
 

	
 
	/* determine type of field */
 
	r = Random();
 
	counter = GB(r, 5, 3);
 
	field_type = GB(r, 8, 8) * 9 >> 8;
 

	
 
	/* make field */
 
	BEGIN_TILE_LOOP(cur_tile, size_x, size_y, tile)
 
	TILE_LOOP(cur_tile, size_x, size_y, tile) {
 
		assert(cur_tile < MapSize());
 
		if (!IsBadFarmFieldTile2(cur_tile)) {
 
			MakeField(cur_tile, field_type, industry);
 
			SetClearCounter(cur_tile, counter);
 
			MarkTileDirtyByTile(cur_tile);
 
		}
 
	END_TILE_LOOP(cur_tile, size_x, size_y, tile)
 
	}
 

	
 
	type = 3;
 
	if (_settings_game.game_creation.landscape != LT_ARCTIC && _settings_game.game_creation.landscape != LT_TROPIC) {
 
		type = _plantfarmfield_type[Random() & 0xF];
 
	}
 

	
 
@@ -1337,13 +1337,13 @@ static bool CheckCanTerraformSurrounding
 
	size_y = 2;
 

	
 
	/* Check if we don't leave the map */
 
	if (TileX(tile) == 0 || TileY(tile) == 0 || GetTileType(tile) == MP_VOID) return false;
 

	
 
	tile += TileDiffXY(-1, -1);
 
	BEGIN_TILE_LOOP(tile_walk, size_x, size_y, tile) {
 
	TILE_LOOP(tile_walk, size_x, size_y, tile) {
 
		curh = TileHeight(tile_walk);
 
		/* Is the tile clear? */
 
		if ((GetTileType(tile_walk) != MP_CLEAR) && (GetTileType(tile_walk) != MP_TREES))
 
			return false;
 

	
 
		/* Don't allow too big of a change if this is the sub-tile check */
 
@@ -1353,13 +1353,13 @@ static bool CheckCanTerraformSurrounding
 
		 *  has to be correct too (in level, or almost in level)
 
		 *  else you get a chain-reaction of terraforming. */
 
		if (internal == 0 && curh != height) {
 
			if (TileX(tile_walk) == 0 || TileY(tile_walk) == 0 || !CheckCanTerraformSurroundingTiles(tile_walk + TileDiffXY(-1, -1), height, internal + 1))
 
				return false;
 
		}
 
	} END_TILE_LOOP(tile_walk, size_x, size_y, tile);
 
	}
 

	
 
	return true;
 
}
 

	
 
/**
 
 * This function tries to flatten out the land below an industry, without
 
@@ -1396,13 +1396,13 @@ static bool CheckIfCanLevelIndustryPlatf
 

	
 
	/* _current_company is OWNER_NONE for randomly generated industries and in editor, or the company who funded or prospected the industry.
 
	 * Perform terraforming as OWNER_TOWN to disable autoslope and town ratings. */
 
	CompanyID old_company = _current_company;
 
	_current_company = OWNER_TOWN;
 

	
 
	BEGIN_TILE_LOOP(tile_walk, size_x, size_y, cur_tile) {
 
	TILE_LOOP(tile_walk, size_x, size_y, cur_tile) {
 
		curh = TileHeight(tile_walk);
 
		if (curh != h) {
 
			/* This tile needs terraforming. Check if we can do that without
 
			 *  damaging the surroundings too much. */
 
			if (!CheckCanTerraformSurroundingTiles(tile_walk, h, 0)) {
 
				_current_company = old_company;
 
@@ -1412,26 +1412,26 @@ static bool CheckIfCanLevelIndustryPlatf
 
			 *  What is missing, is if the difference in height is more than 1.. */
 
			if (CmdFailed(DoCommand(tile_walk, SLOPE_N, (curh > h) ? 0 : 1, flags & ~DC_EXEC, CMD_TERRAFORM_LAND))) {
 
				_current_company = old_company;
 
				return false;
 
			}
 
		}
 
	} END_TILE_LOOP(tile_walk, size_x, size_y, cur_tile)
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		/* Terraform the land under the industry */
 
		BEGIN_TILE_LOOP(tile_walk, size_x, size_y, cur_tile) {
 
		TILE_LOOP(tile_walk, size_x, size_y, cur_tile) {
 
			curh = TileHeight(tile_walk);
 
			while (curh != h) {
 
				/* We give the terraforming for free here, because we can't calculate
 
				 *  exact cost in the test-round, and as we all know, that will cause
 
				 *  a nice assert if they don't match ;) */
 
				DoCommand(tile_walk, SLOPE_N, (curh > h) ? 0 : 1, flags, CMD_TERRAFORM_LAND);
 
				curh += (curh > h) ? -1 : 1;
 
			}
 
		} END_TILE_LOOP(tile_walk, size_x, size_y, cur_tile)
 
		}
 
	}
 

	
 
	_current_company = old_company;
 
	return true;
 
}
 

	
src/map_func.h
Show inline comments
 
@@ -324,37 +324,25 @@ uint DistanceManhattan(TileIndex, TileIn
 
uint DistanceSquare(TileIndex, TileIndex); ///< euclidian- or L2-Norm squared
 
uint DistanceMax(TileIndex, TileIndex); ///< also known as L-Infinity-Norm
 
uint DistanceMaxPlusManhattan(TileIndex, TileIndex); ///< Max + Manhattan
 
uint DistanceFromEdge(TileIndex); ///< shortest distance from any edge of the map
 

	
 
/**
 
 * Starts a loop which iterates to a square of tiles
 
 * A loop which iterates to a square of tiles
 
 *
 
 * This macro starts 2 nested loops which iterates over a square of tiles.
 
 *
 
 * @param var The name of the variable which contains the current tile
 
 * @param w The width (x-width) of the square
 
 * @param h The heigth (y-width) of the square
 
 * @param tile The start tile of the square
 
 */
 
#define BEGIN_TILE_LOOP(var, w, h, tile)                      \
 
	{                                                        \
 
		int h_cur = h;                                         \
 
		uint var = tile;                                       \
 
		do {                                                   \
 
			int w_cur = w;                                       \
 
			do {
 
/**
 
 * Ends the square-loop used before
 
 *
 
 * @see BEGIN_TILE_LOOP
 
 */
 
#define END_TILE_LOOP(var, w, h, tile)                        \
 
			} while (++var, --w_cur != 0);                       \
 
		} while (var += TileDiffXY(0, 1) - (w), --h_cur != 0); \
 
	}
 
#define TILE_LOOP(var, w, h, tile)                                                      \
 
	for (uint var = tile, cur_h = (h); cur_h > 0; --cur_h, var += TileDiffXY(0, 1) - (w)) \
 
		for (uint cur_w = (w); cur_w > 0; --cur_w, var++)
 

	
 
/**
 
 * Convert a DiagDirection to a TileIndexDiff
 
 *
 
 * @param dir The DiagDirection
 
 * @return The resulting TileIndexDiff
 
 * @see TileIndexDiffCByDiagDir
src/newgrf_industrytiles.cpp
Show inline comments
 
@@ -386,21 +386,21 @@ bool StartStopIndustryTileAnimation(Tile
 
}
 

	
 
bool StartStopIndustryTileAnimation(const Industry *ind, IndustryAnimationTrigger iat)
 
{
 
	bool ret = true;
 
	uint32 random = Random();
 
	BEGIN_TILE_LOOP(tile, ind->width, ind->height, ind->xy)
 
	TILE_LOOP(tile, ind->width, ind->height, ind->xy) {
 
		if (IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == ind->index) {
 
			if (StartStopIndustryTileAnimation(tile, iat, random)) {
 
				SB(random, 0, 16, Random());
 
			} else {
 
				ret = false;
 
			}
 
		}
 
	END_TILE_LOOP(tile, ind->width, ind->height, ind->xy)
 
	}
 

	
 
	return ret;
 
}
 

	
 
static void DoTriggerIndustryTile(TileIndex tile, IndustryTileTrigger trigger, Industry *ind)
 
{
 
@@ -430,12 +430,12 @@ void TriggerIndustryTile(TileIndex tile,
 
{
 
	DoTriggerIndustryTile(tile, trigger, GetIndustryByTile(tile));
 
}
 

	
 
void TriggerIndustry(Industry *ind, IndustryTileTrigger trigger)
 
{
 
	BEGIN_TILE_LOOP(tile, ind->width, ind->height, ind->xy)
 
	TILE_LOOP(tile, ind->width, ind->height, ind->xy) {
 
		if (IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == ind->index) {
 
			DoTriggerIndustryTile(tile, trigger, ind);
 
		}
 
	END_TILE_LOOP(tile, ind->width, ind->height, ind->xy)
 
}
 
}
src/station.cpp
Show inline comments
 
@@ -412,15 +412,15 @@ bool StationRect::BeforeAddRect(TileInde
 
/* static */ bool StationRect::ScanForStationTiles(StationID st_id, int left_a, int top_a, int right_a, int bottom_a)
 
{
 
	TileIndex top_left = TileXY(left_a, top_a);
 
	int width = right_a - left_a + 1;
 
	int height = bottom_a - top_a + 1;
 

	
 
	BEGIN_TILE_LOOP(tile, width, height, top_left)
 
	TILE_LOOP(tile, width, height, top_left) {
 
		if (IsTileType(tile, MP_STATION) && GetStationIndex(tile) == st_id) return true;
 
	END_TILE_LOOP(tile, width, height, top_left);
 
	}
 

	
 
	return false;
 
}
 

	
 
bool StationRect::AfterRemoveTile(BaseStation *st, TileIndex tile)
 
{
src/station_cmd.cpp
Show inline comments
 
@@ -73,24 +73,24 @@ static uint GetNumRoadStopsInStation(con
 

	
 
#define CHECK_STATIONS_ERR ((Station*)-1)
 

	
 
static Station *GetStationAround(TileIndex tile, int w, int h, StationID closest_station)
 
{
 
	/* check around to see if there's any stations there */
 
	BEGIN_TILE_LOOP(tile_cur, w + 2, h + 2, tile - TileDiffXY(1, 1))
 
	TILE_LOOP(tile_cur, w + 2, h + 2, tile - TileDiffXY(1, 1)) {
 
		if (IsTileType(tile_cur, MP_STATION)) {
 
			StationID t = GetStationIndex(tile_cur);
 

	
 
			if (closest_station == INVALID_STATION) {
 
				if (Station::IsValidID(t)) closest_station = t;
 
			} else if (closest_station != t) {
 
				_error_message = STR_ERROR_ADJOINS_MORE_THAN_ONE_EXISTING;
 
				return CHECK_STATIONS_ERR;
 
			}
 
		}
 
	END_TILE_LOOP(tile_cur, w + 2, h + 2, tile - TileDiffXY(1, 1))
 
	}
 
	return (closest_station == INVALID_STATION) ? NULL : Station::Get(closest_station);
 
}
 

	
 
/**
 
 * Function to check whether the given tile matches some criterion.
 
 * @param tile the tile to check
 
@@ -646,13 +646,13 @@ static CommandCost ClearTile_Station(Til
 
 */
 
CommandCost CheckFlatLandBelow(TileIndex tile, uint w, uint h, DoCommandFlag flags, uint invalid_dirs, StationID *station, bool check_clear = true)
 
{
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 
	int allowed_z = -1;
 

	
 
	BEGIN_TILE_LOOP(tile_cur, w, h, tile) {
 
	TILE_LOOP(tile_cur, w, h, tile) {
 
		if (MayHaveBridgeAbove(tile_cur) && IsBridgeAbove(tile_cur)) {
 
			return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
 
		}
 

	
 
		if (!EnsureNoVehicleOnGround(tile_cur)) return CMD_ERROR;
 

	
 
@@ -706,13 +706,13 @@ CommandCost CheckFlatLandBelow(TileIndex
 
			}
 
		} else if (check_clear) {
 
			CommandCost ret = DoCommand(tile_cur, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
			if (CmdFailed(ret)) return ret;
 
			cost.AddCost(ret);
 
		}
 
	} END_TILE_LOOP(tile_cur, w, h, tile)
 
	}
 

	
 
	return cost;
 
}
 

	
 
/**
 
 * Check whether we can expand the rail part of the given station.
 
@@ -732,18 +732,18 @@ static bool CanExpandRailStation(const S
 
		new_ta.w = max(TileX(st->train_station.tile) + new_ta.w, TileX(cur_ta.tile) + cur_ta.w) - x;
 
		new_ta.h = max(TileY(st->train_station.tile) + new_ta.h, TileY(cur_ta.tile) + cur_ta.h) - y;
 
		new_ta.tile = TileXY(x, y);
 
	} else {
 
		/* do not allow modifying non-uniform stations,
 
		 * the uniform-stations code wouldn't handle it well */
 
		BEGIN_TILE_LOOP(t, st->train_station.w, st->train_station.h, st->train_station.tile)
 
		TILE_LOOP(t, st->train_station.w, st->train_station.h, st->train_station.tile) {
 
			if (!st->TileBelongsToRailStation(t)) { // there may be adjoined station
 
				_error_message = STR_NONUNIFORM_STATIONS_DISALLOWED;
 
				return false;
 
			}
 
		END_TILE_LOOP(t, st->train_station.w, st->train_station.h, st->train_station.tile)
 
		}
 

	
 
		/* check so the orientation is the same */
 
		if (GetRailStationAxis(st->train_station.tile) != axis) {
 
			_error_message = STR_NONUNIFORM_STATIONS_DISALLOWED;
 
			return false;
 
		}
 
@@ -1144,13 +1144,13 @@ CommandCost CmdRemoveFromRailroadStation
 
	int size_x = ex - sx + 1;
 
	int size_y = ey - sy + 1;
 

	
 
	SmallVector<Station *, 4> affected_stations;
 

	
 
	/* Do the action for every tile into the area */
 
	BEGIN_TILE_LOOP(tile2, size_x, size_y, tile) {
 
	TILE_LOOP(tile2, size_x, size_y, tile) {
 
		/* Make sure the specified tile is a railroad station */
 
		if (!IsRailStationTile(tile2)) {
 
			continue;
 
		}
 

	
 
		/* If there is a vehicle on ground, do not allow to remove (flood) the tile */
 
@@ -1205,13 +1205,13 @@ CommandCost CmdRemoveFromRailroadStation
 
				if (IsRailStationTile(v->tile)) SetRailStationPlatformReservation(v->tile, TrackdirToExitdir(v->GetVehicleTrackdir()), true);
 
				TryPathReserve(v, true, true);
 
				for (; v->Next() != NULL; v = v->Next()) ;
 
				if (IsRailStationTile(v->tile)) SetRailStationPlatformReservation(v->tile, TrackdirToExitdir(ReverseTrackdir(v->GetVehicleTrackdir())), true);
 
			}
 
		}
 
	} END_TILE_LOOP(tile2, size_x, size_y, tile)
 
	}
 

	
 
	for (Station **stp = affected_stations.Begin(); stp != affected_stations.End(); stp++) {
 
		Station *st = *stp;
 

	
 
		/* now we need to make the "spanned" area of the railway station smaller
 
		 * if we deleted something at the edges.
 
@@ -1834,16 +1834,16 @@ CommandCost CmdBuildAirport(TileIndex ti
 
		 */
 
		if (airport_upgrade) UpdateAirplanesOnNewStation(st);
 

	
 
		{
 
			const byte *b = _airport_sections[p1];
 

	
 
			BEGIN_TILE_LOOP(tile_cur, w, h, tile) {
 
			TILE_LOOP(tile_cur, w, h, tile) {
 
				MakeAirport(tile_cur, st->owner, st->index, *b);
 
				b++;
 
			} END_TILE_LOOP(tile_cur, w, h, tile)
 
			}
 
		}
 

	
 
		st->UpdateVirtCoord();
 
		UpdateStationAcceptance(st, false);
 
		st->RecomputeIndustriesNear();
 
		InvalidateWindowData(WC_SELECT_STATION, 0, 0);
 
@@ -1883,20 +1883,20 @@ static CommandCost RemoveAirport(TileInd
 
	const Aircraft *a;
 
	FOR_ALL_AIRCRAFT(a) {
 
		if (!a->IsNormalAircraft()) continue;
 
		if (a->targetairport == st->index && a->state != FLYING) return CMD_ERROR;
 
	}
 

	
 
	BEGIN_TILE_LOOP(tile_cur, w, h, tile) {
 
	TILE_LOOP(tile_cur, w, h, tile) {
 
		if (!EnsureNoVehicleOnGround(tile_cur)) return CMD_ERROR;
 

	
 
		if (flags & DC_EXEC) {
 
			DeleteAnimatedTile(tile_cur);
 
			DoClearSquare(tile_cur);
 
		}
 
	} END_TILE_LOOP(tile_cur, w, h, tile)
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		for (uint i = 0; i < afc->nof_depots; ++i) {
 
			DeleteWindowById(
 
				WC_VEHICLE_DEPOT, tile + ToTileIndexDiff(afc->airport_depots[i])
 
			);
src/station_gui.cpp
Show inline comments
 
@@ -1129,15 +1129,15 @@ static const Station *FindStationsNearby
 
	TileArea ctx = ta;
 

	
 
	_stations_nearby_list.Clear();
 
	_deleted_stations_nearby.Clear();
 

	
 
	/* Check the inside, to return, if we sit on another station */
 
	BEGIN_TILE_LOOP(t, ta.w, ta.h, ta.tile)
 
	TILE_LOOP(t, ta.w, ta.h, ta.tile) {
 
		if (t < MapSize() && IsTileType(t, MP_STATION) && Station::IsValidID(GetStationIndex(t))) return Station::GetByTile(t);
 
	END_TILE_LOOP(t, ta.w, ta.h, ta.tile)
 
	}
 

	
 
	/* Look for deleted stations */
 
	const BaseStation *st;
 
	FOR_ALL_BASE_STATIONS(st) {
 
		if (Station::IsExpected(st) && !st->IsInUse() && st->owner == _local_company) {
 
			/* Include only within station spread (yes, it is strictly less than) */
src/terraform_cmd.cpp
Show inline comments
 
@@ -382,13 +382,13 @@ CommandCost CmdLevelLand(TileIndex tile,
 
	int size_x = ex - sx + 1;
 
	int size_y = ey - sy + 1;
 

	
 
	Money money = GetAvailableMoneyForCommand();
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 

	
 
	BEGIN_TILE_LOOP(tile2, size_x, size_y, tile) {
 
	TILE_LOOP(tile2, size_x, size_y, tile) {
 
		uint curh = TileHeight(tile2);
 
		while (curh != h) {
 
			CommandCost ret = DoCommand(tile2, SLOPE_N, (curh > h) ? 0 : 1, flags & ~DC_EXEC, CMD_TERRAFORM_LAND);
 
			if (CmdFailed(ret)) break;
 

	
 
			if (flags & DC_EXEC) {
 
@@ -400,10 +400,10 @@ CommandCost CmdLevelLand(TileIndex tile,
 
				DoCommand(tile2, SLOPE_N, (curh > h) ? 0 : 1, flags, CMD_TERRAFORM_LAND);
 
			}
 

	
 
			cost.AddCost(ret);
 
			curh += (curh > h) ? -1 : 1;
 
		}
 
	} END_TILE_LOOP(tile2, size_x, size_y, tile)
 
	}
 

	
 
	return (cost.GetCost() == 0) ? CMD_ERROR : cost;
 
}
src/terraform_gui.cpp
Show inline comments
 
@@ -55,17 +55,17 @@ static void GenerateDesertArea(TileIndex
 
	if (ex < sx) Swap(ex, sx);
 
	if (ey < sy) Swap(ey, sy);
 
	size_x = (ex - sx) + 1;
 
	size_y = (ey - sy) + 1;
 

	
 
	_generating_world = true;
 
	BEGIN_TILE_LOOP(tile, size_x, size_y, TileXY(sx, sy)) {
 
	TILE_LOOP(tile, size_x, size_y, TileXY(sx, sy)) {
 
		SetTropicZone(tile, (_ctrl_pressed) ? TROPICZONE_NORMAL : TROPICZONE_DESERT);
 
		DoCommandP(tile, 0, 0, CMD_LANDSCAPE_CLEAR);
 
		MarkTileDirtyByTile(tile);
 
	} END_TILE_LOOP(tile, size_x, size_y, 0);
 
	}
 
	_generating_world = false;
 
}
 

	
 
/** Scenario editor command that generates rocky areas */
 
static void GenerateRockyArea(TileIndex end, TileIndex start)
 
{
 
@@ -80,26 +80,26 @@ static void GenerateRockyArea(TileIndex 
 

	
 
	if (ex < sx) Swap(ex, sx);
 
	if (ey < sy) Swap(ey, sy);
 
	size_x = (ex - sx) + 1;
 
	size_y = (ey - sy) + 1;
 

	
 
	BEGIN_TILE_LOOP(tile, size_x, size_y, TileXY(sx, sy)) {
 
	TILE_LOOP(tile, size_x, size_y, TileXY(sx, sy)) {
 
		switch (GetTileType(tile)) {
 
			case MP_TREES:
 
				if (GetTreeGround(tile) == TREE_GROUND_SHORE) continue;
 
			/* FALL THROUGH */
 
			case MP_CLEAR:
 
				MakeClear(tile, CLEAR_ROCKS, 3);
 
				break;
 

	
 
			default: continue;
 
		}
 
		MarkTileDirtyByTile(tile);
 
		success = true;
 
	} END_TILE_LOOP(tile, size_x, size_y, 0);
 
	}
 

	
 
	if (success) SndPlayTileFx(SND_1F_SPLAT, end);
 
}
 

	
 
/**
 
 * A central place to handle all X_AND_Y dragged GUI functions.
 
@@ -407,28 +407,28 @@ static void CommonRaiseLowerBigLand(Tile
 

	
 
		SndPlayTileFx(SND_1F_SPLAT, tile);
 

	
 
		if (mode != 0) {
 
			/* Raise land */
 
			h = 15; // XXX - max height
 
			BEGIN_TILE_LOOP(tile2, sizex, sizey, tile) {
 
			TILE_LOOP(tile2, sizex, sizey, tile) {
 
				h = min(h, TileHeight(tile2));
 
			} END_TILE_LOOP(tile2, sizex, sizey, tile)
 
			}
 
		} else {
 
			/* Lower land */
 
			h = 0;
 
			BEGIN_TILE_LOOP(tile2, sizex, sizey, tile) {
 
			TILE_LOOP(tile2, sizex, sizey, tile) {
 
				h = max(h, TileHeight(tile2));
 
			} END_TILE_LOOP(tile2, sizex, sizey, tile)
 
			}
 
		}
 

	
 
		BEGIN_TILE_LOOP(tile2, sizex, sizey, tile) {
 
		TILE_LOOP(tile2, sizex, sizey, tile) {
 
			if (TileHeight(tile2) == h) {
 
				DoCommandP(tile2, SLOPE_N, (uint32)mode, CMD_TERRAFORM_LAND);
 
			}
 
		} END_TILE_LOOP(tile2, sizex, sizey, tile)
 
		}
 
	}
 
}
 

	
 
static void PlaceProc_RaiseBigLand(TileIndex tile)
 
{
 
	CommonRaiseLowerBigLand(tile, 1);
src/unmovable_cmd.cpp
Show inline comments
 
@@ -367,15 +367,15 @@ static bool ClickTile_Unmovable(TileInde
 
static bool IsRadioTowerNearby(TileIndex tile)
 
{
 
	TileIndex tile_s = tile - TileDiffXY(min(TileX(tile), 4U), min(TileY(tile), 4U));
 
	uint w = min(TileX(tile), 4U) + 1 + min(MapMaxX() - TileX(tile), 4U);
 
	uint h = min(TileY(tile), 4U) + 1 + min(MapMaxY() - TileY(tile), 4U);
 

	
 
	BEGIN_TILE_LOOP(tile, w, h, tile_s)
 
	TILE_LOOP(tile, w, h, tile_s) {
 
		if (IsTransmitterTile(tile)) return true;
 
	END_TILE_LOOP(tile, w, h, tile_s)
 
	}
 

	
 
	return false;
 
}
 

	
 
void GenerateUnmovables()
 
{
src/water_cmd.cpp
Show inline comments
 
@@ -304,13 +304,13 @@ CommandCost CmdBuildCanal(TileIndex tile
 
	size_x = (x - sx) + 1;
 
	size_y = (y - sy) + 1;
 

	
 
	/* Outside the editor you can only drag canals, and not areas */
 
	if (_game_mode != GM_EDITOR && (sx != x && sy != y)) return CMD_ERROR;
 

	
 
	BEGIN_TILE_LOOP(tile, size_x, size_y, TileXY(sx, sy)) {
 
	TILE_LOOP(tile, size_x, size_y, TileXY(sx, sy)) {
 
		CommandCost ret;
 

	
 
		Slope slope = GetTileSlope(tile, NULL);
 
		if (slope != SLOPE_FLAT && (p2 != 2 || !IsInclinedSlope(slope))) {
 
			return_cmd_error(STR_ERROR_FLAT_LAND_REQUIRED);
 
		}
 
@@ -332,13 +332,13 @@ CommandCost CmdBuildCanal(TileIndex tile
 
			}
 
			MarkTileDirtyByTile(tile);
 
			MarkCanalsAndRiversAroundDirty(tile);
 
		}
 

	
 
		cost.AddCost(_price.clear_water);
 
	} END_TILE_LOOP(tile, size_x, size_y, 0);
 
	}
 

	
 
	if (cost.GetCost() == 0) {
 
		return_cmd_error(STR_ERROR_ALREADY_BUILT);
 
	} else {
 
		return cost;
 
	}
 
@@ -746,17 +746,17 @@ static void FloodVehicles(TileIndex tile
 
	}
 

	
 
	/* if non-uniform stations are disabled, flood some train in this train station (if there is any) */
 
	if (!_settings_game.station.nonuniform_stations && IsTileType(tile, MP_STATION) && GetStationType(tile) == STATION_RAIL) {
 
		const Station *st = Station::GetByTile(tile);
 

	
 
		BEGIN_TILE_LOOP(t, st->train_station.w, st->train_station.h, st->train_station.tile)
 
		TILE_LOOP(t, st->train_station.w, st->train_station.h, st->train_station.tile) {
 
			if (st->TileBelongsToRailStation(t)) {
 
				FindVehicleOnPos(tile, &z, &FloodVehicleProc);
 
			}
 
		END_TILE_LOOP(t, st->train_station.w, st->train_station.h, st->train_station.tile)
 
		}
 

	
 
		return;
 
	}
 

	
 
	if (!IsBridgeTile(tile)) {
 
		FindVehicleOnPos(tile, &z, &FloodVehicleProc);
0 comments (0 inline, 0 general)