Changeset - r25451:917146b539af
[Not reviewed]
src/industry_cmd.cpp
Show inline comments
 
@@ -146,13 +146,13 @@ Industry::~Industry()
 
	 * This means that we do not have to clear tiles either.
 
	 * Also we must not decrement industry counts in that case. */
 
	if (this->location.w == 0) return;
 

	
 
	const bool has_neutral_station = this->neutral_station != nullptr;
 

	
 
	TILE_AREA_LOOP(tile_cur, this->location) {
 
	for (TileIndex tile_cur : this->location) {
 
		if (IsTileType(tile_cur, MP_INDUSTRY)) {
 
			if (GetIndustryIndex(tile_cur) == this->index) {
 
				DeleteNewGRFInspectWindow(GSF_INDUSTRYTILES, tile_cur);
 

	
 
				/* MakeWaterKeepingClass() can also handle 'land' */
 
				MakeWaterKeepingClass(tile_cur, OWNER_NONE);
 
@@ -161,22 +161,22 @@ Industry::~Industry()
 
			DeleteOilRig(tile_cur);
 
		}
 
	}
 

	
 
	if (has_neutral_station) {
 
		/* Remove possible docking tiles */
 
		TILE_AREA_LOOP(tile_cur, this->location) {
 
		for (TileIndex tile_cur : this->location) {
 
			ClearDockingTilesCheckingNeighbours(tile_cur);
 
		}
 
	}
 

	
 
	if (GetIndustrySpec(this->type)->behaviour & INDUSTRYBEH_PLANT_FIELDS) {
 
		TileArea ta = TileArea(this->location.tile, 0, 0).Expand(21);
 

	
 
		/* Remove the farmland and convert it to regular tiles over time. */
 
		TILE_AREA_LOOP(tile_cur, ta) {
 
		for (TileIndex tile_cur : ta) {
 
			if (IsTileType(tile_cur, MP_CLEAR) && IsClearGround(tile_cur, CLEAR_FIELDS) &&
 
					GetIndustryIndexOfField(tile_cur) == this->index) {
 
				SetIndustryIndexOfField(tile_cur, INVALID_INDUSTRY);
 
			}
 
		}
 
	}
 
@@ -1038,25 +1038,25 @@ static void PlantFarmField(TileIndex til
 
	ta.ClampToMap();
 

	
 
	if (ta.w == 0 || ta.h == 0) return;
 

	
 
	/* check the amount of bad tiles */
 
	int count = 0;
 
	TILE_AREA_LOOP(cur_tile, ta) {
 
	for (TileIndex cur_tile : ta) {
 
		assert(cur_tile < MapSize());
 
		count += IsSuitableForFarmField(cur_tile, false);
 
	}
 
	if (count * 2 < ta.w * ta.h) return;
 

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

	
 
	/* make field */
 
	TILE_AREA_LOOP(cur_tile, ta) {
 
	for (TileIndex cur_tile : ta) {
 
		assert(cur_tile < MapSize());
 
		if (IsSuitableForFarmField(cur_tile, true)) {
 
			MakeField(cur_tile, field_type, industry);
 
			SetClearCounter(cur_tile, counter);
 
			MarkTileDirtyByTile(cur_tile);
 
		}
 
@@ -1112,13 +1112,13 @@ static bool SearchLumberMillTrees(TileIn
 
 * Perform a circular search around the Lumber Mill in order to find trees to cut
 
 * @param i industry
 
 */
 
static void ChopLumberMillTrees(Industry *i)
 
{
 
	/* We only want to cut trees if all tiles are completed. */
 
	TILE_AREA_LOOP(tile_cur, i->location) {
 
	for (TileIndex tile_cur : i->location) {
 
		if (i->TileBelongsToIndustry(tile_cur)) {
 
			if (!IsIndustryCompleted(tile_cur)) return;
 
		}
 
	}
 

	
 
	TileIndex tile = i->location.tile;
 
@@ -1529,13 +1529,13 @@ static CommandCost CheckIfIndustryIsAllo
 
static bool CheckCanTerraformSurroundingTiles(TileIndex tile, uint height, int internal)
 
{
 
	/* Check if we don't leave the map */
 
	if (TileX(tile) == 0 || TileY(tile) == 0 || GetTileType(tile) == MP_VOID) return false;
 

	
 
	TileArea ta(tile - TileDiffXY(1, 1), 2, 2);
 
	TILE_AREA_LOOP(tile_walk, ta) {
 
	for (TileIndex tile_walk : ta) {
 
		uint 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 */
 
		if (internal != 0 && Delta(curh, height) > 1) return false;
 
@@ -1584,13 +1584,13 @@ static bool CheckIfCanLevelIndustryPlatf
 
	if (TileX(ta.tile) + ta.w >= MapMaxX() || TileY(ta.tile) + ta.h >= MapMaxY()) return false;
 

	
 
	/* _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. */
 
	Backup<CompanyID> cur_company(_current_company, OWNER_TOWN, FILE_LINE);
 

	
 
	TILE_AREA_LOOP(tile_walk, ta) {
 
	for (TileIndex tile_walk : ta) {
 
		uint 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)) {
 
				cur_company.Restore();
 
@@ -1604,13 +1604,13 @@ static bool CheckIfCanLevelIndustryPlatf
 
			}
 
		}
 
	}
 

	
 
	if (flags & DC_EXEC) {
 
		/* Terraform the land under the industry */
 
		TILE_AREA_LOOP(tile_walk, ta) {
 
		for (TileIndex tile_walk : ta) {
 
			uint 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);
 
@@ -1636,13 +1636,13 @@ static CommandCost CheckIfFarEnoughFromC
 

	
 
	/* On a large map with many industries, it may be faster to check an area. */
 
	static const int dmax = 14;
 
	if (Industry::GetNumItems() > (size_t) (dmax * dmax * 2)) {
 
		const Industry* i = nullptr;
 
		TileArea tile_area = TileArea(tile, 1, 1).Expand(dmax);
 
		TILE_AREA_LOOP(atile, tile_area) {
 
		for (TileIndex atile : tile_area) {
 
			if (GetTileType(atile) == MP_INDUSTRY) {
 
				const Industry *i2 = Industry::GetByTile(atile);
 
				if (i == i2) continue;
 
				i = i2;
 
				if (DistanceMax(tile, i->location.tile) > (uint)dmax) continue;
 
				if (i->type == indspec->conflicting[0] ||
src/newgrf_airporttiles.cpp
Show inline comments
 
@@ -304,11 +304,11 @@ void AirportTileAnimationTrigger(Station
 
}
 

	
 
void AirportAnimationTrigger(Station *st, AirpAnimationTrigger trigger, CargoID cargo_type)
 
{
 
	if (st->airport.tile == INVALID_TILE) return;
 

	
 
	TILE_AREA_LOOP(tile, st->airport) {
 
	for (TileIndex tile : st->airport) {
 
		if (st->TileBelongsToAirport(tile)) AirportTileAnimationTrigger(st, tile, trigger, cargo_type);
 
	}
 
}
 

	
src/newgrf_industrytiles.cpp
Show inline comments
 
@@ -284,13 +284,13 @@ bool StartStopIndustryTileAnimation(Tile
 
}
 

	
 
bool StartStopIndustryTileAnimation(const Industry *ind, IndustryAnimationTrigger iat)
 
{
 
	bool ret = true;
 
	uint32 random = Random();
 
	TILE_AREA_LOOP(tile, ind->location) {
 
	for (TileIndex tile : ind->location) {
 
		if (ind->TileBelongsToIndustry(tile)) {
 
			if (StartStopIndustryTileAnimation(tile, iat, random)) {
 
				SB(random, 0, 16, Random());
 
			} else {
 
				ret = false;
 
			}
 
@@ -369,13 +369,13 @@ void TriggerIndustryTile(TileIndex tile,
 
 * @param ind Industry to trigger.
 
 * @param trigger Trigger to trigger.
 
 */
 
void TriggerIndustry(Industry *ind, IndustryTileTrigger trigger)
 
{
 
	uint32 reseed_industry = 0;
 
	TILE_AREA_LOOP(tile, ind->location) {
 
	for (TileIndex tile : ind->location) {
 
		if (ind->TileBelongsToIndustry(tile)) {
 
			DoTriggerIndustryTile(tile, trigger, ind, reseed_industry);
 
		}
 
	}
 
	DoReseedIndustry(ind, reseed_industry);
 
}
src/newgrf_object.cpp
Show inline comments
 
@@ -551,10 +551,10 @@ void TriggerObjectTileAnimation(Object *
 
 * @param spec    The spec associated with the object.
 
 */
 
void TriggerObjectAnimation(Object *o, ObjectAnimationTrigger trigger, const ObjectSpec *spec)
 
{
 
	if (!HasBit(spec->animation.triggers, trigger)) return;
 

	
 
	TILE_AREA_LOOP(tile, o->location) {
 
	for (TileIndex tile : o->location) {
 
		TriggerObjectTileAnimation(o, tile, trigger, spec);
 
	}
 
}
src/newgrf_station.cpp
Show inline comments
 
@@ -734,13 +734,13 @@ void DeallocateSpecFromStation(BaseStati
 
{
 
	/* specindex of 0 (default) is never freeable */
 
	if (specindex == 0) return;
 

	
 
	ETileArea area = ETileArea(st, INVALID_TILE, TA_WHOLE);
 
	/* Check all tiles over the station to check if the specindex is still in use */
 
	TILE_AREA_LOOP(tile, area) {
 
	for (TileIndex tile : area) {
 
		if (st->TileBelongsToRailStation(tile) && GetCustomStationSpecIndex(tile) == specindex) {
 
			return;
 
		}
 
	}
 

	
 
	/* This specindex is no longer in use, so deallocate it */
 
@@ -936,13 +936,13 @@ void TriggerStationAnimation(BaseStation
 
	if (!HasBit(st->cached_anim_triggers, trigger)) return;
 

	
 
	uint16 random_bits = Random();
 
	ETileArea area = ETileArea(st, tile, tas[trigger]);
 

	
 
	/* Check all tiles over the station to check if the specindex is still in use */
 
	TILE_AREA_LOOP(tile, area) {
 
	for (TileIndex tile : area) {
 
		if (st->TileBelongsToRailStation(tile)) {
 
			const StationSpec *ss = GetStationSpec(tile);
 
			if (ss != nullptr && HasBit(ss->animation.triggers, trigger)) {
 
				CargoID cargo;
 
				if (cargo_type == CT_INVALID) {
 
					cargo = CT_INVALID;
 
@@ -992,13 +992,13 @@ void TriggerStationRandomisation(Station
 

	
 
	/* Store triggers now for var 5F */
 
	SetBit(st->waiting_triggers, trigger);
 
	uint32 used_triggers = 0;
 

	
 
	/* Check all tiles over the station to check if the specindex is still in use */
 
	TILE_AREA_LOOP(tile, area) {
 
	for (TileIndex tile : area) {
 
		if (st->TileBelongsToRailStation(tile)) {
 
			const StationSpec *ss = GetStationSpec(tile);
 
			if (ss == nullptr) continue;
 

	
 
			/* Cargo taken "will only be triggered if all of those
 
			 * cargo types have no more cargo waiting." */
src/object_cmd.cpp
Show inline comments
 
@@ -111,13 +111,13 @@ void BuildObject(ObjectType type, TileIn
 
			o->colour = GB(res, 0, 8);
 
		}
 
	}
 

	
 
	assert(o->town != nullptr);
 

	
 
	TILE_AREA_LOOP(t, ta) {
 
	for (TileIndex t : ta) {
 
		WaterClass wc = (IsWaterTile(t) ? GetWaterClass(t) : WATER_CLASS_INVALID);
 
		/* Update company infrastructure counts for objects build on canals owned by nobody. */
 
		if (wc == WATER_CLASS_CANAL && owner != OWNER_NONE && (IsTileOwner(tile, OWNER_NONE) || IsTileOwner(tile, OWNER_WATER))) {
 
			Company::Get(owner)->infrastructure.water++;
 
			DirtyCompanyInfrastructureWindows(owner);
 
		}
 
@@ -133,13 +133,13 @@ void BuildObject(ObjectType type, TileIn
 
 * Increase the animation stage of a whole structure.
 
 * @param tile The tile of the structure.
 
 */
 
static void IncreaseAnimationStage(TileIndex tile)
 
{
 
	TileArea ta = Object::GetByTile(tile)->location;
 
	TILE_AREA_LOOP(t, ta) {
 
	for (TileIndex t : ta) {
 
		SetAnimationFrame(t, GetAnimationFrame(t) + 1);
 
		MarkTileDirtyByTile(t);
 
	}
 
}
 

	
 
/** We encode the company HQ size in the animation stage. */
 
@@ -227,13 +227,13 @@ CommandCost CmdBuildObject(TileIndex til
 
	} else {
 
		/* Check the surface to build on. At this time we can't actually execute the
 
		 * the CLEAR_TILE commands since the newgrf callback later on can check
 
		 * some information about the tiles. */
 
		bool allow_water = (spec->flags & (OBJECT_FLAG_BUILT_ON_WATER | OBJECT_FLAG_NOT_ON_LAND)) != 0;
 
		bool allow_ground = (spec->flags & OBJECT_FLAG_NOT_ON_LAND) == 0;
 
		TILE_AREA_LOOP(t, ta) {
 
		for (TileIndex t : ta) {
 
			if (HasTileWaterGround(t)) {
 
				if (!allow_water) return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER);
 
				if (!IsWaterTile(t)) {
 
					/* Normal water tiles don't have to be cleared. For all other tile types clear
 
					 * the tile but leave the water. */
 
					cost.AddCost(DoCommand(t, 0, 0, flags & ~DC_NO_WATER & ~DC_EXEC, CMD_LANDSCAPE_CLEAR));
 
@@ -260,13 +260,13 @@ CommandCost CmdBuildObject(TileIndex til
 
		}
 

	
 
		/* So, now the surface is checked... check the slope of said surface. */
 
		int allowed_z;
 
		if (GetTileSlope(tile, &allowed_z) != SLOPE_FLAT) allowed_z++;
 

	
 
		TILE_AREA_LOOP(t, ta) {
 
		for (TileIndex t : ta) {
 
			uint16 callback = CALLBACK_FAILED;
 
			if (HasBit(spec->callback_mask, CBM_OBJ_SLOPE_CHECK)) {
 
				TileIndex diff = t - tile;
 
				callback = GetObjectCallback(CBID_OBJECT_LAND_SLOPE_CHECK, GetTileSlope(t), TileY(diff) << 4 | TileX(diff), spec, nullptr, t, view);
 
			}
 

	
 
@@ -280,13 +280,13 @@ CommandCost CmdBuildObject(TileIndex til
 
			}
 
		}
 

	
 
		if (flags & DC_EXEC) {
 
			/* This is basically a copy of the loop above with the exception that we now
 
			 * execute the commands and don't check for errors, since that's already done. */
 
			TILE_AREA_LOOP(t, ta) {
 
			for (TileIndex t : ta) {
 
				if (HasTileWaterGround(t)) {
 
					if (!IsWaterTile(t)) {
 
						DoCommand(t, 0, 0, (flags & ~DC_NO_WATER) | DC_NO_MODIFY_TOWN_RATING, CMD_LANDSCAPE_CLEAR);
 
					}
 
				} else {
 
					DoCommand(t, 0, 0, flags | DC_NO_MODIFY_TOWN_RATING, CMD_LANDSCAPE_CLEAR);
 
@@ -294,13 +294,13 @@ CommandCost CmdBuildObject(TileIndex til
 
			}
 
		}
 
	}
 
	if (cost.Failed()) return cost;
 

	
 
	/* Finally do a check for bridges. */
 
	TILE_AREA_LOOP(t, ta) {
 
	for (TileIndex t : ta) {
 
		if (IsBridgeAbove(t) && (
 
				!(spec->flags & OBJECT_FLAG_ALLOW_UNDER_BRIDGE) ||
 
				(GetTileMaxZ(t) + spec->height >= GetBridgeHeight(GetSouthernBridgeEnd(t))))) {
 
			return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
 
		}
 
	}
 
@@ -435,13 +435,13 @@ static Foundation GetFoundation_Object(T
 
 * Perform the actual removal of the object from the map.
 
 * @param o The object to really clear.
 
 */
 
static void ReallyClearObjectTile(Object *o)
 
{
 
	Object::DecTypeCount(o->type);
 
	TILE_AREA_LOOP(tile_cur, o->location) {
 
	for (TileIndex tile_cur : o->location) {
 
		DeleteNewGRFInspectWindow(GSF_OBJECTS, tile_cur);
 

	
 
		MakeWaterKeepingClass(tile_cur, GetTileOwner(tile_cur));
 
	}
 
	delete o;
 
}
src/openttd.cpp
Show inline comments
 
@@ -1262,21 +1262,21 @@ static void CheckCaches()
 
			assert(memcmp(&st->goods[c].cargo, buff, sizeof(StationCargoList)) == 0);
 
		}
 

	
 
		/* Check docking tiles */
 
		TileArea ta;
 
		std::map<TileIndex, bool> docking_tiles;
 
		TILE_AREA_LOOP(tile, st->docking_station) {
 
		for (TileIndex tile : st->docking_station) {
 
			ta.Add(tile);
 
			docking_tiles[tile] = IsDockingTile(tile);
 
		}
 
		UpdateStationDockingTiles(st);
 
		if (ta.tile != st->docking_station.tile || ta.w != st->docking_station.w || ta.h != st->docking_station.h) {
 
			DEBUG(desync, 2, "station docking mismatch: station %i, company %i", st->index, (int)st->owner);
 
		}
 
		TILE_AREA_LOOP(tile, ta) {
 
		for (TileIndex tile : ta) {
 
			if (docking_tiles[tile] != IsDockingTile(tile)) {
 
				DEBUG(desync, 2, "docking tile mismatch: tile %i", (int)tile);
 
			}
 
		}
 

	
 
		/* Check industries_near */
src/road_gui.cpp
Show inline comments
 
@@ -160,13 +160,13 @@ void CcRoadStop(const CommandCost &resul
 
	if (result.Failed()) return;
 

	
 
	DiagDirection dir = (DiagDirection)GB(p2, 3, 2);
 
	if (_settings_client.sound.confirm) SndPlayTileFx(SND_1F_CONSTRUCTION_OTHER, tile);
 
	if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
 
	TileArea roadstop_area(tile, GB(p1, 0, 8), GB(p1, 8, 8));
 
	TILE_AREA_LOOP(cur_tile, roadstop_area) {
 
	for (TileIndex cur_tile : roadstop_area) {
 
		ConnectRoadToStructure(cur_tile, dir);
 
		/* For a drive-through road stop build connecting road for other entrance. */
 
		if (HasBit(p2, 1)) ConnectRoadToStructure(cur_tile, ReverseDiagDir(dir));
 
	}
 
}
 

	
src/saveload/station_sl.cpp
Show inline comments
 
@@ -83,13 +83,13 @@ void MoveBuoysToWaypoints()
 
		wp->owner      = train ? GetTileOwner(xy) : OWNER_NONE;
 

	
 
		if (IsInsideBS(string_id, STR_SV_STNAME_BUOY, 9)) wp->town_cn = string_id - STR_SV_STNAME_BUOY;
 

	
 
		if (train) {
 
			/* When we make a rail waypoint of the station, convert the map as well. */
 
			TILE_AREA_LOOP(t, train_st) {
 
			for (TileIndex t : train_st) {
 
				if (!IsTileType(t, MP_STATION) || GetStationIndex(t) != index) continue;
 

	
 
				SB(_me[t].m6, 3, 3, STATION_WAYPOINT);
 
				wp->rect.BeforeAddTile(t, StationRect::ADD_FORCE);
 
			}
 

	
src/script/api/script_industry.cpp
Show inline comments
 
@@ -183,13 +183,13 @@
 
/* static */ TileIndex ScriptIndustry::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);
 
	TILE_AREA_LOOP(tile_cur, ind->location) {
 
	for (TileIndex tile_cur : ind->location) {
 
		if (IsTileType(tile_cur, MP_STATION) && IsOilRig(tile_cur)) {
 
			return tile_cur;
 
		}
 
	}
 

	
 
	return INVALID_TILE;
 
@@ -205,13 +205,13 @@
 
/* static */ TileIndex ScriptIndustry::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);
 
	TILE_AREA_LOOP(tile_cur, ind->location) {
 
	for (TileIndex tile_cur : ind->location) {
 
		if (IsTileType(tile_cur, MP_STATION) && IsOilRig(tile_cur)) {
 
			return tile_cur;
 
		}
 
	}
 

	
 
	return INVALID_TILE;
src/script/api/script_order.cpp
Show inline comments
 
@@ -253,35 +253,35 @@ static int ScriptOrderPositionToRealOrde
 
			return st->airport.GetHangarTile(0);
 
		}
 

	
 
		case OT_GOTO_STATION: {
 
			const Station *st = ::Station::Get(order->GetDestination());
 
			if (st->train_station.tile != INVALID_TILE) {
 
				TILE_AREA_LOOP(t, st->train_station) {
 
				for (TileIndex t : st->train_station) {
 
					if (st->TileBelongsToRailStation(t)) return t;
 
				}
 
			} else if (st->ship_station.tile != INVALID_TILE) {
 
				TILE_AREA_LOOP(t, st->ship_station) {
 
				for (TileIndex t : st->ship_station) {
 
					if (IsTileType(t, MP_STATION) && (IsDock(t) || IsOilRig(t)) && GetStationIndex(t) == st->index) return t;
 
				}
 
			} else if (st->bus_stops != nullptr) {
 
				return st->bus_stops->xy;
 
			} else if (st->truck_stops != nullptr) {
 
				return st->truck_stops->xy;
 
			} else if (st->airport.tile != INVALID_TILE) {
 
				TILE_AREA_LOOP(tile, st->airport) {
 
				for (TileIndex tile : st->airport) {
 
					if (st->TileBelongsToAirport(tile) && !::IsHangar(tile)) return tile;
 
				}
 
			}
 
			return INVALID_TILE;
 
		}
 

	
 
		case OT_GOTO_WAYPOINT: {
 
			const Waypoint *wp = ::Waypoint::Get(order->GetDestination());
 
			if (wp->train_station.tile != INVALID_TILE) {
 
				TILE_AREA_LOOP(t, wp->train_station) {
 
				for (TileIndex t : wp->train_station) {
 
					if (wp->TileBelongsToRailStation(t)) return t;
 
				}
 
			}
 
			/* If the waypoint has no rail waypoint tiles, it must have a buoy */
 
			return wp->xy;
 
		}
src/script/api/script_tilelist.cpp
Show inline comments
 
@@ -18,13 +18,13 @@
 
void ScriptTileList::AddRectangle(TileIndex t1, TileIndex t2)
 
{
 
	if (!::IsValidTile(t1)) return;
 
	if (!::IsValidTile(t2)) return;
 

	
 
	TileArea ta(t1, t2);
 
	TILE_AREA_LOOP(t, ta) this->AddItem(t);
 
	for (TileIndex t : ta) this->AddItem(t);
 
}
 

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

	
 
@@ -34,13 +34,13 @@ void ScriptTileList::AddTile(TileIndex t
 
void ScriptTileList::RemoveRectangle(TileIndex t1, TileIndex t2)
 
{
 
	if (!::IsValidTile(t1)) return;
 
	if (!::IsValidTile(t2)) return;
 

	
 
	TileArea ta(t1, t2);
 
	TILE_AREA_LOOP(t, ta) this->RemoveItem(t);
 
	for (TileIndex t : ta) this->RemoveItem(t);
 
}
 

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

	
 
@@ -52,13 +52,13 @@ void ScriptTileList::RemoveTile(TileInde
 
 * @param i Industry in question
 
 * @param radius Catchment radius to test
 
 * @param bta BitmapTileArea to fill
 
 */
 
static void FillIndustryCatchment(const Industry *i, int radius, BitmapTileArea &bta)
 
{
 
	TILE_AREA_LOOP(cur_tile, i->location) {
 
	for (TileIndex cur_tile : i->location) {
 
		if (!::IsTileType(cur_tile, MP_INDUSTRY) || ::GetIndustryIndex(cur_tile) != i->index) continue;
 

	
 
		int tx = TileX(cur_tile);
 
		int ty = TileY(cur_tile);
 
		for (int y = -radius; y <= radius; y++) {
 
			if (ty + y < 0 || ty + y > (int)MapMaxY()) continue;
 
@@ -153,13 +153,13 @@ ScriptTileList_StationType::ScriptTileLi
 
	if ((station_type & ScriptStation::STATION_TRUCK_STOP) != 0) station_type_value |= (1 << ::STATION_TRUCK);
 
	if ((station_type & ScriptStation::STATION_BUS_STOP) != 0)   station_type_value |= (1 << ::STATION_BUS);
 
	if ((station_type & ScriptStation::STATION_AIRPORT) != 0)    station_type_value |= (1 << ::STATION_AIRPORT) | (1 << ::STATION_OILRIG);
 
	if ((station_type & ScriptStation::STATION_DOCK) != 0)       station_type_value |= (1 << ::STATION_DOCK)    | (1 << ::STATION_OILRIG);
 

	
 
	TileArea ta(::TileXY(rect->left, rect->top), rect->right - rect->left + 1, rect->bottom - rect->top + 1);
 
	TILE_AREA_LOOP(cur_tile, ta) {
 
	for (TileIndex cur_tile : ta) {
 
		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);
 
	}
 
}
src/smallmap_gui.cpp
Show inline comments
 
@@ -747,13 +747,13 @@ void SmallMapWindow::SetZoomLevel(ZoomLe
 
inline uint32 SmallMapWindow::GetTileColours(const TileArea &ta) const
 
{
 
	int importance = 0;
 
	TileIndex tile = INVALID_TILE; // Position of the most important tile.
 
	TileType et = MP_VOID;         // Effective tile type at that position.
 

	
 
	TILE_AREA_LOOP(ti, ta) {
 
	for (TileIndex ti : ta) {
 
		TileType ttype = GetTileType(ti);
 

	
 
		switch (ttype) {
 
			case MP_TUNNELBRIDGE: {
 
				TransportType tt = GetTunnelBridgeTransportType(ti);
 

	
src/station.cpp
Show inline comments
 
@@ -413,13 +413,13 @@ void Station::RecomputeCatchment()
 
		return;
 
	}
 

	
 
	if (!_settings_game.station.serve_neutral_industries && this->industry != nullptr) {
 
		/* Station is associated with an industry, so we only need to deliver to that industry. */
 
		this->catchment_tiles.Initialize(this->industry->location);
 
		TILE_AREA_LOOP(tile, this->industry->location) {
 
		for (TileIndex tile : this->industry->location) {
 
			if (IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == this->industry->index) {
 
				this->catchment_tiles.SetTile(tile);
 
			}
 
		}
 
		/* The industry's stations_near may have been computed before its neutral station was built so clear and re-add here. */
 
		for (Station *st : this->industry->stations_near) {
 
@@ -432,21 +432,21 @@ void Station::RecomputeCatchment()
 
	}
 

	
 
	this->catchment_tiles.Initialize(GetCatchmentRect());
 

	
 
	/* Loop finding all station tiles */
 
	TileArea ta(TileXY(this->rect.left, this->rect.top), TileXY(this->rect.right, this->rect.bottom));
 
	TILE_AREA_LOOP(tile, ta) {
 
	for (TileIndex tile : ta) {
 
		if (!IsTileType(tile, MP_STATION) || GetStationIndex(tile) != this->index) continue;
 

	
 
		uint r = GetTileCatchmentRadius(tile, this);
 
		if (r == CA_NONE) continue;
 

	
 
		/* This tile sub-loop doesn't need to test any tiles, they are simply added to the catchment set. */
 
		TileArea ta2 = TileArea(tile, 1, 1).Expand(r);
 
		TILE_AREA_LOOP(tile2, ta2) this->catchment_tiles.SetTile(tile2);
 
		for (TileIndex tile2 : ta2) this->catchment_tiles.SetTile(tile2);
 
	}
 

	
 
	/* Search catchment tiles for towns and industries */
 
	BitmapTileIterator it(this->catchment_tiles);
 
	for (TileIndex tile = it; tile != INVALID_TILE; tile = ++it) {
 
		if (IsTileType(tile, MP_HOUSE)) {
 
@@ -564,13 +564,13 @@ CommandCost StationRect::BeforeAddRect(T
 
 * @param bottom_a Maximal tile Y edge of the rectangle (inclusive)
 
 * @return \c true if a station tile with the given \a st_id exists in the rectangle, \c false otherwise
 
 */
 
/* static */ bool StationRect::ScanForStationTiles(StationID st_id, int left_a, int top_a, int right_a, int bottom_a)
 
{
 
	TileArea ta(TileXY(left_a, top_a), TileXY(right_a, bottom_a));
 
	TILE_AREA_LOOP(tile, ta) {
 
	for (TileIndex tile : ta) {
 
		if (IsTileType(tile, MP_STATION) && GetStationIndex(tile) == st_id) return true;
 
	}
 

	
 
	return false;
 
}
 

	
src/station_base.h
Show inline comments
 
@@ -572,25 +572,25 @@ void ForAllStationsAroundTiles(const Til
 
	std::set<StationID> seen_stations;
 

	
 
	/* Scan an area around the building covering the maximum possible station
 
	 * to find the possible nearby stations. */
 
	uint max_c = _settings_game.station.modified_catchment ? MAX_CATCHMENT : CA_UNMODIFIED;
 
	TileArea ta_ext = TileArea(ta).Expand(max_c);
 
	TILE_AREA_LOOP(tile, ta_ext) {
 
	for (TileIndex tile : ta_ext) {
 
		if (IsTileType(tile, MP_STATION)) seen_stations.insert(GetStationIndex(tile));
 
	}
 

	
 
	for (StationID stationid : seen_stations) {
 
		Station *st = Station::GetIfValid(stationid);
 
		if (st == nullptr) continue; /* Waypoint */
 

	
 
		/* Check if station is attached to an industry */
 
		if (!_settings_game.station.serve_neutral_industries && st->industry != nullptr) continue;
 

	
 
		/* Test if the tile is within the station's catchment */
 
		TILE_AREA_LOOP(tile, ta) {
 
		for (TileIndex tile : ta) {
 
			if (st->TileIsInCatchment(tile)) {
 
				if (func(st, tile)) break;
 
			}
 
		}
 
	}
 
}
src/station_cmd.cpp
Show inline comments
 
@@ -102,13 +102,13 @@ bool IsHangar(TileIndex t)
 
template <class T>
 
CommandCost GetStationAround(TileArea ta, StationID closest_station, CompanyID company, T **st)
 
{
 
	ta.Expand(1);
 

	
 
	/* check around to see if there are any stations there owned by the company */
 
	TILE_AREA_LOOP(tile_cur, ta) {
 
	for (TileIndex tile_cur : ta) {
 
		if (IsTileType(tile_cur, MP_STATION)) {
 
			StationID t = GetStationIndex(tile_cur);
 
			if (!T::IsValidID(t) || Station::Get(t)->owner != company) continue;
 
			if (closest_station == INVALID_STATION) {
 
				closest_station = t;
 
			} else if (closest_station != t) {
 
@@ -508,13 +508,13 @@ CargoArray GetProductionAroundTiles(Tile
 
	CargoArray produced;
 
	std::set<IndustryID> industries;
 
	TileArea ta = TileArea(tile, w, h).Expand(rad);
 

	
 
	/* Loop over all tiles to get the produced cargo of
 
	 * everything except industries */
 
	TILE_AREA_LOOP(tile, ta) {
 
	for (TileIndex tile : ta) {
 
		if (IsTileType(tile, MP_INDUSTRY)) industries.insert(GetIndustryIndex(tile));
 
		AddProducedCargo(tile, produced);
 
	}
 

	
 
	/* Loop over the seen industries. They produce cargo for
 
	 * anything that is within 'rad' of any one of their tiles.
 
@@ -546,13 +546,13 @@ CargoArray GetAcceptanceAroundTiles(Tile
 
{
 
	CargoArray acceptance;
 
	if (always_accepted != nullptr) *always_accepted = 0;
 

	
 
	TileArea ta = TileArea(tile, w, h).Expand(rad);
 

	
 
	TILE_AREA_LOOP(tile, ta) {
 
	for (TileIndex tile : ta) {
 
		/* Ignore industry if it has a neutral station. */
 
		if (!_settings_game.station.serve_neutral_industries && IsTileType(tile, MP_INDUSTRY) && Industry::GetByTile(tile)->neutral_station != nullptr) continue;
 

	
 
		AddAcceptedCargo(tile, acceptance, always_accepted);
 
	}
 

	
 
@@ -869,13 +869,13 @@ static CommandCost CheckFlatLandRailStat
 
	int allowed_z = -1;
 
	uint invalid_dirs = 5 << axis;
 

	
 
	const StationSpec *statspec = StationClass::Get(spec_class)->GetSpec(spec_index);
 
	bool slope_cb = statspec != nullptr && HasBit(statspec->callback_mask, CBM_STATION_SLOPE_CHECK);
 

	
 
	TILE_AREA_LOOP(tile_cur, tile_area) {
 
	for (TileIndex tile_cur : tile_area) {
 
		CommandCost ret = CheckBuildableTile(tile_cur, invalid_dirs, allowed_z, false);
 
		if (ret.Failed()) return ret;
 
		cost.AddCost(ret);
 

	
 
		if (slope_cb) {
 
			/* Do slope check if requested. */
 
@@ -951,13 +951,13 @@ static CommandCost CheckFlatLandRailStat
 
 */
 
static CommandCost CheckFlatLandRoadStop(TileArea tile_area, DoCommandFlag flags, uint invalid_dirs, bool is_drive_through, bool is_truck_stop, Axis axis, StationID *station, RoadType rt)
 
{
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 
	int allowed_z = -1;
 

	
 
	TILE_AREA_LOOP(cur_tile, tile_area) {
 
	for (TileIndex cur_tile : tile_area) {
 
		CommandCost ret = CheckBuildableTile(cur_tile, invalid_dirs, allowed_z, !is_drive_through);
 
		if (ret.Failed()) return ret;
 
		cost.AddCost(ret);
 

	
 
		/* If station is set, then we have special handling to allow building on top of already existing stations.
 
		 * Station points to INVALID_STATION if we can build on any station.
 
@@ -1432,13 +1432,13 @@ CommandCost CmdBuildRailStation(TileInde
 
		if (axis == AXIS_X) {
 
			update_reservation_area = TileArea(tile_org, 1, numtracks_orig);
 
		} else {
 
			update_reservation_area = TileArea(tile_org, numtracks_orig, 1);
 
		}
 

	
 
		TILE_AREA_LOOP(tile, update_reservation_area) {
 
		for (TileIndex tile : update_reservation_area) {
 
			/* Don't even try to make eye candy parts reserved. */
 
			if (IsStationTileBlocked(tile)) continue;
 

	
 
			DiagDirection dir = AxisToDiagDir(axis);
 
			TileIndexDiff tile_offset = TileOffsByDiagDir(dir);
 
			TileIndex platform_begin = tile;
 
@@ -1560,13 +1560,13 @@ CommandCost RemoveFromRailBaseStation(Ti
 
	/* Accumulator for the errors seen during clearing. If no errors happen,
 
	 * and the quantity is 0 there is no station. Otherwise it will be one
 
	 * of the other error that got accumulated. */
 
	CommandCost error;
 

	
 
	/* Do the action for every tile into the area */
 
	TILE_AREA_LOOP(tile, ta) {
 
	for (TileIndex tile : ta) {
 
		/* Make sure the specified tile is a rail station */
 
		if (!HasStationTileRail(tile)) continue;
 

	
 
		/* If there is a vehicle on ground, do not allow to remove (flood) the tile */
 
		CommandCost ret = EnsureNoVehicleOnGround(tile);
 
		error.AddCost(ret);
 
@@ -1726,13 +1726,13 @@ CommandCost RemoveRailStation(T *st, DoC
 
	TileArea ta = st->train_station;
 

	
 
	assert(ta.w != 0 && ta.h != 0);
 

	
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 
	/* clear all areas of the station */
 
	TILE_AREA_LOOP(tile, ta) {
 
	for (TileIndex tile : ta) {
 
		/* only remove tiles that are actually train station tiles */
 
		if (st->TileBelongsToRailStation(tile)) {
 
			std::vector<T*> affected_stations; // dummy
 
			CommandCost ret = RemoveFromRailBaseStation(TileArea(tile, 1, 1), affected_stations, flags, removal_cost, false);
 
			if (ret.Failed()) return ret;
 
			cost.AddCost(ret);
 
@@ -1891,13 +1891,13 @@ CommandCost CmdBuildRoadStop(TileIndex t
 

	
 
	ret = BuildStationPart(&st, flags, reuse, roadstop_area, STATIONNAMING_ROAD);
 
	if (ret.Failed()) return ret;
 

	
 
	if (flags & DC_EXEC) {
 
		/* Check every tile in the area. */
 
		TILE_AREA_LOOP(cur_tile, roadstop_area) {
 
		for (TileIndex cur_tile : roadstop_area) {
 
			/* Get existing road types and owners before any tile clearing */
 
			RoadType road_rt = MayHaveRoad(cur_tile) ? GetRoadType(cur_tile, RTT_ROAD) : INVALID_ROADTYPE;
 
			RoadType tram_rt = MayHaveRoad(cur_tile) ? GetRoadType(cur_tile, RTT_TRAM) : INVALID_ROADTYPE;
 
			Owner road_owner = road_rt != INVALID_ROADTYPE ? GetRoadOwner(cur_tile, RTT_ROAD) : _current_company;
 
			Owner tram_owner = tram_rt != INVALID_ROADTYPE ? GetRoadOwner(cur_tile, RTT_TRAM) : _current_company;
 

	
 
@@ -2098,13 +2098,13 @@ CommandCost CmdRemoveRoadStop(TileIndex 
 
	TileArea roadstop_area(tile, width, height);
 

	
 
	CommandCost cost(EXPENSES_CONSTRUCTION);
 
	CommandCost last_error(STR_ERROR_THERE_IS_NO_STATION);
 
	bool had_success = false;
 

	
 
	TILE_AREA_LOOP(cur_tile, roadstop_area) {
 
	for (TileIndex cur_tile : roadstop_area) {
 
		/* Make sure the specified tile is a road stop of the correct type */
 
		if (!IsTileType(cur_tile, MP_STATION) || !IsRoadStop(cur_tile) || (uint32)GetRoadStopType(cur_tile) != GB(p2, 0, 1)) continue;
 

	
 
		/* Save information on to-be-restored roads before the stop is removed. */
 
		RoadBits road_bits = ROAD_NONE;
 
		RoadType road_type[] = { INVALID_ROADTYPE, INVALID_ROADTYPE };
 
@@ -2406,13 +2406,13 @@ static CommandCost RemoveAirport(TileInd
 
		AirportTileIterator it(st);
 
		uint dist;
 
		Town *nearest = AirportGetNearestTown(as, it, dist);
 
		nearest->noise_reached -= GetAirportNoiseLevelForDistance(as, dist);
 
	}
 

	
 
	TILE_AREA_LOOP(tile_cur, st->airport) {
 
	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]);
 
@@ -4117,13 +4117,13 @@ void UpdateStationDockingTiles(Station *
 
	int x1 = std::max<int>(x - 1, 0);
 

	
 
	int y2 = std::min<int>(y + area->h + 1, MapSizeY());
 
	int y1 = std::max<int>(y - 1, 0);
 

	
 
	TileArea ta(TileXY(x1, y1), TileXY(x2 - 1, y2 - 1));
 
	TILE_AREA_LOOP(tile, ta) {
 
	for (TileIndex tile : ta) {
 
		if (IsValidTile(tile) && IsPossibleDockingTile(tile)) CheckForDockingTile(tile);
 
	}
 
}
 

	
 
void BuildOilRig(TileIndex tile)
 
{
src/station_gui.cpp
Show inline comments
 
@@ -100,13 +100,13 @@ static void FindStationsAroundSelection(
 
	int max_c = 1;
 
	TileArea ta(TileXY(std::max<int>(0, x - max_c), std::max<int>(0, y - max_c)), TileXY(std::min<int>(MapMaxX(), x + location.w + max_c), std::min<int>(MapMaxY(), y + location.h + max_c)));
 

	
 
	Station *adjacent = nullptr;
 

	
 
	/* Direct loop instead of ForAllStationsAroundTiles as we are not interested in catchment area */
 
	TILE_AREA_LOOP(tile, ta) {
 
	for (TileIndex tile : ta) {
 
		if (IsTileType(tile, MP_STATION) && GetTileOwner(tile) == _local_company) {
 
			Station *st = Station::GetByTile(tile);
 
			if (st == nullptr) continue;
 
			if (adjacent != nullptr && st != adjacent) {
 
				/* Multiple nearby, distant join is required. */
 
				adjacent = nullptr;
 
@@ -2211,13 +2211,13 @@ static const T *FindStationsNearby(TileA
 
	TileArea ctx = ta;
 

	
 
	_stations_nearby_list.clear();
 
	_deleted_stations_nearby.clear();
 

	
 
	/* Check the inside, to return, if we sit on another station */
 
	TILE_AREA_LOOP(t, ta) {
 
	for (TileIndex t : ta) {
 
		if (t < MapSize() && IsTileType(t, MP_STATION) && T::IsValidID(GetStationIndex(t))) return T::GetByTile(t);
 
	}
 

	
 
	/* Look for deleted stations */
 
	for (const BaseStation *st : BaseStation::Iterate()) {
 
		if (T::IsExpected(st) && !st->IsInUse() && st->owner == _local_company) {
src/subsidy.cpp
Show inline comments
 
@@ -326,13 +326,13 @@ bool FindSubsidyTownCargoRoute()
 
	const Town *src_town = Town::GetRandom();
 
	if (src_town->cache.population < SUBSIDY_CARGO_MIN_POPULATION) return false;
 

	
 
	/* Calculate the produced cargo of houses around town center. */
 
	CargoArray town_cargo_produced;
 
	TileArea ta = TileArea(src_town->xy, 1, 1).Expand(SUBSIDY_TOWN_CARGO_RADIUS);
 
	TILE_AREA_LOOP(tile, ta) {
 
	for (TileIndex tile : ta) {
 
		if (IsTileType(tile, MP_HOUSE)) {
 
			AddProducedCargo(tile, town_cargo_produced);
 
		}
 
	}
 

	
 
	/* Passenger subsidies are not handled here. */
 
@@ -437,13 +437,13 @@ bool FindSubsidyCargoDestination(CargoID
 
			/* Select a random town. */
 
			const Town *dst_town = Town::GetRandom();
 

	
 
			/* Calculate cargo acceptance of houses around town center. */
 
			CargoArray town_cargo_accepted;
 
			TileArea ta = TileArea(dst_town->xy, 1, 1).Expand(SUBSIDY_TOWN_CARGO_RADIUS);
 
			TILE_AREA_LOOP(tile, ta) {
 
			for (TileIndex tile : ta) {
 
				if (IsTileType(tile, MP_HOUSE)) {
 
					AddAcceptedCargo(tile, town_cargo_accepted, nullptr);
 
				}
 
			}
 

	
 
			/* Check if the town can accept this cargo. */
src/terraform_gui.cpp
Show inline comments
 
@@ -54,13 +54,13 @@ static void GenerateDesertArea(TileIndex
 
{
 
	if (_game_mode != GM_EDITOR) return;
 

	
 
	_generating_world = true;
 

	
 
	TileArea ta(start, end);
 
	TILE_AREA_LOOP(tile, ta) {
 
	for (TileIndex tile : ta) {
 
		SetTropicZone(tile, (_ctrl_pressed) ? TROPICZONE_NORMAL : TROPICZONE_DESERT);
 
		DoCommandP(tile, 0, 0, CMD_LANDSCAPE_CLEAR);
 
		MarkTileDirtyByTile(tile);
 
	}
 
	_generating_world = false;
 
	InvalidateWindowClassesData(WC_TOWN_VIEW, 0);
 
@@ -71,13 +71,13 @@ static void GenerateRockyArea(TileIndex 
 
{
 
	if (_game_mode != GM_EDITOR) return;
 

	
 
	bool success = false;
 
	TileArea ta(start, end);
 

	
 
	TILE_AREA_LOOP(tile, ta) {
 
	for (TileIndex tile : ta) {
 
		switch (GetTileType(tile)) {
 
			case MP_TREES:
 
				if (GetTreeGround(tile) == TREE_GROUND_SHORE) continue;
 
				FALLTHROUGH;
 

	
 
			case MP_CLEAR:
 
@@ -405,24 +405,24 @@ static void CommonRaiseLowerBigLand(Tile
 
		if (_settings_client.sound.confirm) SndPlayTileFx(SND_1F_CONSTRUCTION_OTHER, tile);
 

	
 
		uint h;
 
		if (mode != 0) {
 
			/* Raise land */
 
			h = MAX_TILE_HEIGHT;
 
			TILE_AREA_LOOP(tile2, ta) {
 
			for (TileIndex tile2 : ta) {
 
				h = std::min(h, TileHeight(tile2));
 
			}
 
		} else {
 
			/* Lower land */
 
			h = 0;
 
			TILE_AREA_LOOP(tile2, ta) {
 
			for (TileIndex tile2 : ta) {
 
				h = std::max(h, TileHeight(tile2));
 
			}
 
		}
 

	
 
		TILE_AREA_LOOP(tile2, ta) {
 
		for (TileIndex tile2 : ta) {
 
			if (TileHeight(tile2) == h) {
 
				DoCommandP(tile2, SLOPE_N, (uint32)mode, CMD_TERRAFORM_LAND);
 
			}
 
		}
 
	}
 
}
src/tilearea.cpp
Show inline comments
 
@@ -144,12 +144,30 @@ void OrthogonalTileArea::ClampToMap()
 
	assert(this->tile < MapSize());
 
	this->w = std::min<int>(this->w, MapSizeX() - TileX(this->tile));
 
	this->h = std::min<int>(this->h, MapSizeY() - TileY(this->tile));
 
}
 

	
 
/**
 
 * Returns an iterator to the beginning of the tile area.
 
 * @return The OrthogonalTileIterator.
 
 */
 
OrthogonalTileIterator OrthogonalTileArea::begin() const
 
{
 
	return OrthogonalTileIterator(*this);
 
}
 

	
 
/**
 
 * Returns an iterator to the end of the tile area.
 
 * @return The OrthogonalTileIterator.
 
 */
 
OrthogonalTileIterator OrthogonalTileArea::end() const
 
{
 
	return OrthogonalTileIterator(OrthogonalTileArea());
 
}
 

	
 
/**
 
 * Create a diagonal tile area from two corners.
 
 * @param start First corner of the area.
 
 * @param end Second corner of the area.
 
 */
 
DiagonalTileArea::DiagonalTileArea(TileIndex start, TileIndex end) : tile(start)
 
{
src/tilearea_type.h
Show inline comments
 
@@ -9,12 +9,14 @@
 

	
 
#ifndef TILEAREA_TYPE_H
 
#define TILEAREA_TYPE_H
 

	
 
#include "map_func.h"
 

	
 
class OrthogonalTileIterator;
 

	
 
/** Represents the covered area of e.g. a rail station */
 
struct OrthogonalTileArea {
 
	TileIndex tile; ///< The base tile of the area
 
	uint16 w;       ///< The width of the area
 
	uint16 h;       ///< The height of the area
 

	
 
@@ -55,12 +57,16 @@ struct OrthogonalTileArea {
 
	 * @return The tile at the center, or just north of it.
 
	 */
 
	TileIndex GetCenterTile() const
 
	{
 
		return TILE_ADDXY(this->tile, this->w / 2, this->h / 2);
 
	}
 

	
 
	OrthogonalTileIterator begin() const;
 

	
 
	OrthogonalTileIterator end() const;
 
};
 

	
 
/** Represents a diagonal tile area. */
 
struct DiagonalTileArea {
 

	
 
	TileIndex tile; ///< Base tile of the area
 
@@ -121,12 +127,21 @@ public:
 
	inline operator TileIndex () const
 
	{
 
		return this->tile;
 
	}
 

	
 
	/**
 
	 * Get the tile we are currently at.
 
	 * @return The tile we are at, or INVALID_TILE when we're done.
 
	 */
 
	inline TileIndex operator *() const
 
	{
 
		return this->tile;
 
	}
 

	
 
	/**
 
	 * Move ourselves to the next tile in the rectangle on the map.
 
	 */
 
	virtual TileIterator& operator ++() = 0;
 

	
 
	/**
 
	 * Allocate a new iterator that is a copy of this one.
 
@@ -220,15 +235,7 @@ public:
 
	virtual TileIterator *Clone() const
 
	{
 
		return new DiagonalTileIterator(*this);
 
	}
 
};
 

	
 
/**
 
 * A loop which iterates over the tiles of a TileArea.
 
 * @param var The name of the variable which contains the current tile.
 
 *            This variable will be allocated in this \c for of this loop.
 
 * @param ta  The tile area to search over.
 
 */
 
#define TILE_AREA_LOOP(var, ta) for (OrthogonalTileIterator var(ta); var != INVALID_TILE; ++var)
 

	
 
#endif /* TILEAREA_TYPE_H */
src/tree_cmd.cpp
Show inline comments
 
@@ -389,13 +389,13 @@ CommandCost CmdPlantTree(TileIndex tile,
 
	if (tree_to_plant != TREE_INVALID && !IsInsideBS(tree_to_plant, _tree_base_by_landscape[_settings_game.game_creation.landscape], _tree_count_by_landscape[_settings_game.game_creation.landscape])) return CMD_ERROR;
 

	
 
	Company *c = (_game_mode != GM_EDITOR) ? Company::GetIfValid(_current_company) : nullptr;
 
	int limit = (c == nullptr ? INT32_MAX : GB(c->tree_limit, 16, 16));
 

	
 
	TileArea ta(tile, p2);
 
	TILE_AREA_LOOP(tile, ta) {
 
	for (TileIndex tile : ta) {
 
		switch (GetTileType(tile)) {
 
			case MP_TREES:
 
				/* no more space for trees? */
 
				if (GetTreeCount(tile) == 4) {
 
					msg = STR_ERROR_TREE_ALREADY_HERE;
 
					continue;
src/water_cmd.cpp
Show inline comments
 
@@ -1041,13 +1041,13 @@ static Vehicle *FloodVehicleProc(Vehicle
 
static void FloodVehicles(TileIndex tile)
 
{
 
	int z = 0;
 

	
 
	if (IsAirportTile(tile)) {
 
		const Station *st = Station::GetByTile(tile);
 
		TILE_AREA_LOOP(tile, st->airport) {
 
		for (TileIndex tile : st->airport) {
 
			if (st->TileBelongsToAirport(tile)) FindVehicleOnPos(tile, &z, &FloodVehicleProc);
 
		}
 

	
 
		/* No vehicle could be flooded on this airport anymore */
 
		return;
 
	}
0 comments (0 inline, 0 general)