Changeset - r11229:0d2d21cc618d
[Not reviewed]
master
0 7 0
frosch - 16 years ago 2009-02-25 21:29:50
frosch@openttd.org
(svn r15583) -Fix: Do not use TILE_MASK when you do not want to wrap around them map.
7 files changed with 41 insertions and 61 deletions:
0 comments (0 inline, 0 general)
src/disaster_cmd.cpp
Show inline comments
 
@@ -682,10 +682,12 @@ static void DisasterTick_Big_Ufo_Destroy
 
				EV_EXPLOSION_SMALL);
 
		}
 

	
 
		BEGIN_TILE_LOOP(tile, 6, 6, v->tile - TileDiffXY(3, 3))
 
			tile = TILE_MASK(tile);
 
			DisasterClearSquare(tile);
 
		END_TILE_LOOP(tile, 6, 6, v->tile - TileDiffXY(3, 3))
 
		for (int dy = -3; dy < 3; dy++) {
 
			for (int dx = -3; dx < 3; dx++) {
 
				TileIndex tile = TileAddWrap(v->tile, dx, dy);
 
				if (tile != INVALID_TILE) DisasterClearSquare(tile);
 
			}
 
		}
 
	}
 
}
 

	
src/industry_cmd.cpp
Show inline comments
 
@@ -928,7 +928,7 @@ static void PlantFarmField(TileIndex til
 
	/* check the amount of bad tiles */
 
	count = 0;
 
	BEGIN_TILE_LOOP(cur_tile, size_x, size_y, tile)
 
		cur_tile = TILE_MASK(cur_tile);
 
		TILE_ASSERT(cur_tile);
 
		count += IsBadFarmFieldTile(cur_tile);
 
	END_TILE_LOOP(cur_tile, size_x, size_y, tile)
 
	if (count * 2 >= size_x * size_y) return;
 
@@ -940,7 +940,7 @@ static void PlantFarmField(TileIndex til
 

	
 
	/* make field */
 
	BEGIN_TILE_LOOP(cur_tile, size_x, size_y, tile)
 
		cur_tile = TILE_MASK(cur_tile);
 
		TILE_ASSERT(cur_tile);
 
		if (!IsBadFarmFieldTile2(cur_tile)) {
 
			MakeField(cur_tile, field_type, industry);
 
			SetClearCounter(cur_tile, counter);
src/landscape.cpp
Show inline comments
 
@@ -830,8 +830,8 @@ static void CreateDesertOrRainForest()
 

	
 
		for (data = _make_desert_or_rainforest_data;
 
				data != endof(_make_desert_or_rainforest_data); ++data) {
 
			TileIndex t = TILE_MASK(tile + ToTileIndexDiff(*data));
 
			if (TileHeight(t) >= 4 || IsTileType(t, MP_WATER)) break;
 
			TileIndex t = AddTileIndexDiffCWrap(tile, *data);
 
			if (t != INVALID_TILE && (TileHeight(t) >= 4 || IsTileType(t, MP_WATER))) break;
 
		}
 
		if (data == endof(_make_desert_or_rainforest_data))
 
			SetTropicZone(tile, TROPICZONE_DESERT);
 
@@ -848,8 +848,8 @@ static void CreateDesertOrRainForest()
 

	
 
		for (data = _make_desert_or_rainforest_data;
 
				data != endof(_make_desert_or_rainforest_data); ++data) {
 
			TileIndex t = TILE_MASK(tile + ToTileIndexDiff(*data));
 
			if (IsTileType(t, MP_CLEAR) && IsClearGround(t, CLEAR_DESERT)) break;
 
			TileIndex t = AddTileIndexDiffCWrap(tile, *data);
 
			if (t != INVALID_TILE && IsTileType(t, MP_CLEAR) && IsClearGround(t, CLEAR_DESERT)) break;
 
		}
 
		if (data == endof(_make_desert_or_rainforest_data))
 
			SetTropicZone(tile, TROPICZONE_RAINFOREST);
src/newgrf_commons.cpp
Show inline comments
 
@@ -292,7 +292,7 @@ TileIndex GetNearbyTile(byte parameter, 
 
	/* Swap width and height depending on axis for railway stations */
 
	if (IsRailwayStationTile(tile) && GetRailStationAxis(tile) == AXIS_Y) Swap(x, y);
 

	
 
	/* Make sure we never roam outside of the map */
 
	/* Make sure we never roam outside of the map, better wrap in that case */
 
	return TILE_MASK(tile + TileDiffXY(x, y));
 
}
 

	
src/station_cmd.cpp
Show inline comments
 
@@ -124,7 +124,8 @@ static int CountMapSquareAround(TileInde
 

	
 
	for (int dx = -3; dx <= 3; dx++) {
 
		for (int dy = -3; dy <= 3; dy++) {
 
			if (cmp(TILE_MASK(tile + TileDiffXY(dx, dy)))) num++;
 
			TileIndex t = TileAddWrap(tile, dx, dy);
 
			if (t != INVALID_TILE && cmp(t)) num++;
 
		}
 
	}
 

	
 
@@ -2956,52 +2957,27 @@ void FindStationsAroundTiles(TileIndex t
 
{
 
	/* area to search = producer plus station catchment radius */
 
	int max_rad = (_settings_game.station.modified_catchment ? MAX_CATCHMENT : CA_UNMODIFIED);
 
	int w = w_prod + 2 * max_rad;
 
	int h = h_prod + 2 * max_rad;
 

	
 
	BEGIN_TILE_LOOP(cur_tile, w, h, tile - TileDiffXY(max_rad, max_rad))
 
		cur_tile = TILE_MASK(cur_tile);
 
		if (!IsTileType(cur_tile, MP_STATION)) continue;
 

	
 
		Station *st = GetStationByTile(cur_tile);
 

	
 
		if (st->IsBuoy()) continue; // bouys don't accept cargo
 

	
 

	
 
		if (_settings_game.station.modified_catchment) {
 
			/* min and max coordinates of the producer relative */
 
			const int x_min_prod = max_rad + 1;
 
			const int x_max_prod = max_rad + w_prod;
 
			const int y_min_prod = max_rad + 1;
 
			const int y_max_prod = max_rad + h_prod;
 

	
 
			int rad = st->GetCatchmentRadius();
 

	
 
			int x_dist = min(w_cur - x_min_prod, x_max_prod - w_cur);
 
			if (w_cur < x_min_prod) {
 
				x_dist = x_min_prod - w_cur;
 
			} else if (w_cur > x_max_prod) {
 
				x_dist = w_cur - x_max_prod;
 

	
 
	for (int dy = -max_rad; dy < h_prod + max_rad; dy++) {
 
		for (int dx = -max_rad; dx < w_prod + max_rad; dx++) {
 
			TileIndex cur_tile = TileAddWrap(tile, dx, dy);
 
			if (cur_tile == INVALID_TILE || !IsTileType(cur_tile, MP_STATION)) continue;
 

	
 
			Station *st = GetStationByTile(cur_tile);
 

	
 
			if (st->IsBuoy()) continue; // bouys don't accept cargo
 

	
 
			if (_settings_game.station.modified_catchment) {
 
				int rad = st->GetCatchmentRadius();
 
				if (dx < -rad || dx >= rad + w_prod || dy < -rad || dy >= rad + h_prod) continue;
 
			}
 

	
 
			if (x_dist > rad) continue;
 

	
 
			int y_dist = min(h_cur - y_min_prod, y_max_prod - h_cur);
 
			if (h_cur < y_min_prod) {
 
				y_dist = y_min_prod - h_cur;
 
			} else if (h_cur > y_max_prod) {
 
				y_dist = h_cur - y_max_prod;
 
			}
 

	
 
			if (y_dist > rad) continue;
 
			/* Insert the station in the set. This will fail if it has
 
			 * already been added.
 
			 */
 
			stations->Include(st);
 
		}
 

	
 
		/* Insert the station in the set. This will fail if it has
 
		 * already been added.
 
		 */
 
		stations->Include(st);
 

	
 
	END_TILE_LOOP(cur_tile, w, h, tile - TileDiffXY(max_rad, max_rad))
 
	}
 
}
 

	
 
uint MoveGoodsToStation(TileIndex tile, int w, int h, CargoID type, uint amount)
src/tree_cmd.cpp
Show inline comments
 
@@ -174,9 +174,9 @@ static void DoPlaceMoreTrees(TileIndex t
 
		int x = GB(r, 0, 5) - 16;
 
		int y = GB(r, 8, 5) - 16;
 
		uint dist = abs(x) + abs(y);
 
		TileIndex cur_tile = TILE_MASK(tile + TileDiffXY(x, y));
 
		TileIndex cur_tile = TileAddWrap(tile, x, y);
 

	
 
		if (dist <= 13 && CanPlantTreesOnTile(cur_tile, true)) {
 
		if (cur_tile != INVALID_TILE && dist <= 13 && CanPlantTreesOnTile(cur_tile, true)) {
 
			PlaceTree(cur_tile, r);
 
		}
 
	}
 
@@ -212,7 +212,8 @@ static void PlaceTreeAtSameHeight(TileIn
 
		uint32 r = Random();
 
		int x = GB(r, 0, 5) - 16;
 
		int y = GB(r, 8, 5) - 16;
 
		TileIndex cur_tile = TILE_MASK(tile + TileDiffXY(x, y));
 
		TileIndex cur_tile = TileAddWrap(tile, x, y);
 
		if (cur_tile == INVALID_TILE) continue;
 

	
 
		/* Keep in range of the existing tree */
 
		if (abs(x) + abs(y) > 16) continue;
 
@@ -735,7 +736,7 @@ void OnTick_Trees()
 

	
 
	/* place a tree at a random spot */
 
	r = Random();
 
	tile = TILE_MASK(r);
 
	tile = RandomTileSeed(r);
 
	if (CanPlantTreesOnTile(tile, false) && (tree = GetRandomTreeType(tile, GB(r, 24, 8))) != TREE_INVALID) {
 
		PlantTreesOnTile(tile, tree, 0, 0);
 
	}
src/unmovable_cmd.cpp
Show inline comments
 
@@ -452,10 +452,11 @@ void GenerateUnmovables()
 
				MakeLighthouse(tile);
 
				IncreaseGeneratingWorldProgress(GWP_UNMOVABLE);
 
				lighthouses_to_build--;
 
				assert(tile == TILE_MASK(tile));
 
				TILE_ASSERT(tile);
 
				break;
 
			}
 
			tile = TILE_MASK(tile + TileOffsByDiagDir(dir));
 
			tile = AddTileIndexDiffCWrap(tile, TileIndexDiffCByDiagDir(dir));
 
			if (tile == INVALID_TILE) break;
 
		}
 
	}
 
}
0 comments (0 inline, 0 general)