Changeset - r14160:24d7cfd54d1c
[Not reviewed]
master
0 9 0
rubidium - 14 years ago 2010-01-04 18:30:10
rubidium@openttd.org
(svn r18718) -Codechange: make a wrapper macro for looping TileAreas
9 files changed with 23 insertions and 13 deletions:
0 comments (0 inline, 0 general)
src/ai/api/ai_industry.cpp
Show inline comments
 
@@ -159,13 +159,13 @@
 
/* 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);
 
	TILE_LOOP(tile_cur, ind->location.w, ind->location.h, ind->location.tile) {
 
	TILE_AREA_LOOP(tile_cur, ind->location) {
 
		if (IsTileType(tile_cur, MP_STATION) && IsOilRig(tile_cur)) {
 
			return tile_cur;
 
		}
 
	}
 

	
 
	return INVALID_TILE;
 
@@ -181,13 +181,13 @@
 
/* 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);
 
	TILE_LOOP(tile_cur, ind->location.w, ind->location.h, ind->location.tile) {
 
	TILE_AREA_LOOP(tile_cur, ind->location) {
 
		if (IsTileType(tile_cur, MP_STATION) && IsOilRig(tile_cur)) {
 
			return tile_cur;
 
		}
 
	}
 

	
 
	return INVALID_TILE;
src/ai/api/ai_tilelist.cpp
Show inline comments
 
@@ -83,13 +83,13 @@ AITileList_IndustryAccepting::AITileList
 
		}
 
		if (!cargo_accepts) return;
 
	}
 

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

	
 
	TILE_LOOP(cur_tile, i->location.w + radius * 2, i->location.h+ radius * 2, i->location.tile - ::TileDiffXY(radius, radius)) {
 
	TILE_LOOP(cur_tile, i->location.w + radius * 2, i->location.h + radius * 2, i->location.tile - ::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). */
 
@@ -120,13 +120,13 @@ AITileList_IndustryProducing::AITileList
 
		}
 
		if (!cargo_produces) return;
 
	}
 

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

	
 
	TILE_LOOP(cur_tile, i->location.w + radius * 2, i->location.h+ radius * 2, i->location.tile - ::TileDiffXY(radius, radius)) {
 
	TILE_LOOP(cur_tile, i->location.w + radius * 2, i->location.h + radius * 2, i->location.tile - ::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). */
src/industry_cmd.cpp
Show inline comments
 
@@ -141,13 +141,13 @@ 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->location.w == 0) return;
 

	
 
	TILE_LOOP(tile_cur, this->location.w, this->location.h, this->location.tile) {
 
	TILE_AREA_LOOP(tile_cur, this->location) {
 
		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
src/map_func.h
Show inline comments
 
@@ -345,12 +345,22 @@ uint DistanceFromEdge(TileIndex); ///< s
 
 */
 
#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++)
 

	
 
/**
 
 * A loop which iterates over the tiles of a TileArea
 
 *
 
 * 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 ta  The tile area to search over
 
 */
 
#define TILE_AREA_LOOP(var, ta) TILE_LOOP(var, ta.w, ta.h, ta.tile)
 

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

	
 
bool StartStopIndustryTileAnimation(const Industry *ind, IndustryAnimationTrigger iat)
 
{
 
	bool ret = true;
 
	uint32 random = Random();
 
	TILE_LOOP(tile, ind->location.w, ind->location.h, ind->location.tile) {
 
	TILE_AREA_LOOP(tile, ind->location) {
 
		if (IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == ind->index) {
 
			if (StartStopIndustryTileAnimation(tile, iat, random)) {
 
				SB(random, 0, 16, Random());
 
			} else {
 
				ret = false;
 
			}
 
@@ -438,12 +438,12 @@ void TriggerIndustryTile(TileIndex tile,
 
{
 
	DoTriggerIndustryTile(tile, trigger, Industry::GetByTile(tile));
 
}
 

	
 
void TriggerIndustry(Industry *ind, IndustryTileTrigger trigger)
 
{
 
	TILE_LOOP(tile, ind->location.w, ind->location.h, ind->location.tile) {
 
	TILE_AREA_LOOP(tile, ind->location) {
 
		if (IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == ind->index) {
 
			DoTriggerIndustryTile(tile, trigger, ind);
 
		}
 
	}
 
}
src/newgrf_station.cpp
Show inline comments
 
@@ -834,13 +834,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_LOOP(tile, area.w, area.h, area.tile) {
 
	TILE_AREA_LOOP(tile, area) {
 
		if (st->TileBelongsToRailStation(tile) && GetCustomStationSpecIndex(tile) == specindex) {
 
			return;
 
		}
 
	}
 

	
 
	/* This specindex is no longer in use, so deallocate it */
 
@@ -1073,13 +1073,13 @@ void StationAnimationTrigger(const BaseS
 
	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_LOOP(tile, area.w, area.h, area.tile) {
 
	TILE_AREA_LOOP(tile, area) {
 
		if (st->TileBelongsToRailStation(tile)) {
 
			const StationSpec *ss = GetStationSpec(tile);
 
			if (ss != NULL && HasBit(ss->anim_triggers, trigger)) {
 
				CargoID cargo;
 
				if (cargo_type == CT_INVALID) {
 
					cargo = CT_INVALID;
src/station_cmd.cpp
Show inline comments
 
@@ -1220,13 +1220,13 @@ CommandCost RemoveFromRailBaseStation(Ti
 
{
 
	/* Count of the number of tiles removed */
 
	int quantity = 0;
 
	CommandCost total_cost(EXPENSES_CONSTRUCTION);
 

	
 
	/* Do the action for every tile into the area */
 
	TILE_LOOP(tile, ta.w, ta.h, ta.tile) {
 
	TILE_AREA_LOOP(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 */
 
		if (!EnsureNoVehicleOnGround(tile)) continue;
 

	
 
@@ -1385,13 +1385,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_LOOP(tile, ta.w, ta.h, ta.tile) {
 
	TILE_AREA_LOOP(tile, ta) {
 
		/* for nonuniform stations, only remove tiles that are actually train station tiles */
 
		if (!st->TileBelongsToRailStation(tile)) continue;
 

	
 
		if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
 

	
 
		cost.AddCost(_price[PR_CLEAR_STATION_RAIL]);
src/station_gui.cpp
Show inline comments
 
@@ -1208,13 +1208,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_LOOP(t, ta.w, ta.h, ta.tile) {
 
	TILE_AREA_LOOP(t, ta) {
 
		if (t < MapSize() && IsTileType(t, MP_STATION) && T::IsValidID(GetStationIndex(t))) return T::GetByTile(t);
 
	}
 

	
 
	/* Look for deleted stations */
 
	const BaseStation *st;
 
	FOR_ALL_BASE_STATIONS(st) {
src/water_cmd.cpp
Show inline comments
 
@@ -758,13 +758,13 @@ 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);
 

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

	
 
		return;
0 comments (0 inline, 0 general)