(svn r18718) -Codechange: make a wrapper macro for looping TileAreas

This commit is contained in:
rubidium 2010-01-04 18:30:10 +00:00
parent 87466a4ed0
commit 3e131e2fec
9 changed files with 23 additions and 13 deletions

View File

@ -162,7 +162,7 @@
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;
}
@ -184,7 +184,7 @@
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;
}

View File

@ -86,7 +86,7 @@ AITileList_IndustryAccepting::AITileList_IndustryAccepting(IndustryID industry_i
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;
@ -123,7 +123,7 @@ AITileList_IndustryProducing::AITileList_IndustryProducing(IndustryID industry_i
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;

View File

@ -144,7 +144,7 @@ Industry::~Industry()
* 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' */

View File

@ -347,6 +347,16 @@ uint DistanceFromEdge(TileIndex); ///< shortest distance from any edge of the ma
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
*

View File

@ -396,7 +396,7 @@ bool StartStopIndustryTileAnimation(const Industry *ind, IndustryAnimationTrigge
{
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());
@ -441,7 +441,7 @@ void TriggerIndustryTile(TileIndex tile, IndustryTileTrigger trigger)
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);
}

View File

@ -837,7 +837,7 @@ void DeallocateSpecFromStation(BaseStation *st, byte specindex)
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;
}
@ -1076,7 +1076,7 @@ void StationAnimationTrigger(const BaseStation *st, TileIndex tile, StatAnimTrig
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)) {

View File

@ -1223,7 +1223,7 @@ CommandCost RemoveFromRailBaseStation(TileArea ta, SmallVector<T *, 4> &affected
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;
@ -1388,7 +1388,7 @@ CommandCost RemoveRailStation(T *st, DoCommandFlag flags)
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;

View File

@ -1211,7 +1211,7 @@ static const T *FindStationsNearby(TileArea ta, bool distant_join)
_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);
}

View File

@ -761,7 +761,7 @@ static void FloodVehicles(TileIndex tile)
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);
}