summaryrefslogtreecommitdiff
path: root/src/industry_cmd.cpp
diff options
context:
space:
mode:
authorPeterN <peter@fuzzle.org>2019-04-13 14:12:34 +0100
committerGitHub <noreply@github.com>2019-04-13 14:12:34 +0100
commitabe8cf4985da211ad70c6232a3c737f15574f5de (patch)
treeb391f3da8a64d9534f56f22d492bb6095b113343 /src/industry_cmd.cpp
parent801cbea9cce1e04e6921bb087add8206cffe1fe1 (diff)
downloadopenttd-abe8cf4985da211ad70c6232a3c737f15574f5de.tar.xz
Codechange: Replace duplicated code with TileArea::Expand() (#7467)
Diffstat (limited to 'src/industry_cmd.cpp')
-rw-r--r--src/industry_cmd.cpp9
1 files changed, 4 insertions, 5 deletions
diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp
index df9286308..9978145fa 100644
--- a/src/industry_cmd.cpp
+++ b/src/industry_cmd.cpp
@@ -156,8 +156,7 @@ Industry::~Industry()
}
if (GetIndustrySpec(this->type)->behaviour & INDUSTRYBEH_PLANT_FIELDS) {
- TileArea ta(this->location.tile - TileDiffXY(min(TileX(this->location.tile), 21), min(TileY(this->location.tile), 21)), 42, 42);
- ta.ClampToMap();
+ 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) {
@@ -1533,6 +1532,8 @@ static bool CheckIfCanLevelIndustryPlatform(TileIndex tile, DoCommandFlag flags,
/* Check that all tiles in area and surrounding are clear
* this determines that there are no obstructing items */
+ /* TileArea::Expand is not used here as we need to abort
+ * instead of clamping if the bounds cannot expanded. */
TileArea ta(tile + TileDiffXY(-_settings_game.construction.industry_platform, -_settings_game.construction.industry_platform),
max_x + 2 + 2 * _settings_game.construction.industry_platform, max_y + 2 + 2 * _settings_game.construction.industry_platform);
@@ -1593,9 +1594,7 @@ static CommandCost CheckIfFarEnoughFromConflictingIndustry(TileIndex tile, int t
/* 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 int tx = TileX(tile);
- const int ty = TileY(tile);
- TileArea tile_area = TileArea(TileXY(max(0, tx - dmax), max(0, ty - dmax)), TileXY(min(MapMaxX(), tx + dmax), min(MapMaxY(), ty + dmax)));
+ TileArea tile_area = TileArea(tile, 1, 1).Expand(dmax);
TILE_AREA_LOOP(atile, tile_area) {
if (GetTileType(atile) == MP_INDUSTRY) {
const Industry *i2 = Industry::GetByTile(atile);