summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2010-12-12 18:18:50 +0000
committerrubidium <rubidium@openttd.org>2010-12-12 18:18:50 +0000
commit1123d4790fc2098951b68faa77a72d6b13a39203 (patch)
tree56fff4f2c0916873b63435e38bddebff29efeffd /src
parent02451d8af609ba32f9bf0c61bb1726f7add2f62e (diff)
downloadopenttd-1123d4790fc2098951b68faa77a72d6b13a39203.tar.xz
(svn r21485) -Codechange: use CircularTileSearch to find whether there's a transmitter nearby
Diffstat (limited to 'src')
-rw-r--r--src/object_cmd.cpp22
1 files changed, 10 insertions, 12 deletions
diff --git a/src/object_cmd.cpp b/src/object_cmd.cpp
index f5e3e0cf4..499790579 100644
--- a/src/object_cmd.cpp
+++ b/src/object_cmd.cpp
@@ -563,18 +563,15 @@ static void AnimateTile_Object(TileIndex tile)
AnimateNewObjectTile(tile);
}
-/* checks, if a radio tower is within a 9x9 tile square around tile */
-static bool IsRadioTowerNearby(TileIndex tile)
+/**
+ * Helper function for \c CircularTileSearch.
+ * @param tile The tile to check.
+ * @param user Ignored.
+ * @return True iff the tile has a radio tower.
+ */
+static bool HasTransmitter(TileIndex tile, void *user)
{
- 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);
-
- TILE_LOOP(tile, w, h, tile_s) {
- if (IsTransmitterTile(tile)) return true;
- }
-
- return false;
+ return IsTransmitterTile(tile);
}
void GenerateObjects()
@@ -608,7 +605,8 @@ void GenerateObjects()
uint h;
if (IsTileType(tile, MP_CLEAR) && GetTileSlope(tile, &h) == SLOPE_FLAT && h >= TILE_HEIGHT * 4 && !IsBridgeAbove(tile)) {
- if (IsRadioTowerNearby(tile)) continue;
+ TileIndex t = tile;
+ if (CircularTileSearch(&t, 9, HasTransmitter, NULL)) continue;
BuildObject(OBJECT_TRANSMITTER, tile);
IncreaseGeneratingWorldProgress(GWP_OBJECT);