summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2010-12-12 17:22:17 +0000
committerrubidium <rubidium@openttd.org>2010-12-12 17:22:17 +0000
commit67e6ad2a4b9f40c4e86fa57c12d74d417931c78a (patch)
tree9cec75287e8bc7d64c3242c4b1c73e82136debf0
parenta1d923700feba2edf35b2df22b64d56258c7fb5d (diff)
downloadopenttd-67e6ad2a4b9f40c4e86fa57c12d74d417931c78a.tar.xz
(svn r21482) -Codechange: make landscape clearing make use of TILE_AREA_LOOP as well
-rw-r--r--src/landscape.cpp56
1 files changed, 24 insertions, 32 deletions
diff --git a/src/landscape.cpp b/src/landscape.cpp
index a0ffb0cfd..dec03a09a 100644
--- a/src/landscape.cpp
+++ b/src/landscape.cpp
@@ -650,46 +650,38 @@ CommandCost CmdClearArea(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
{
if (p1 >= MapSize()) return CMD_ERROR;
- /* make sure sx,sy are smaller than ex,ey */
- int ex = TileX(tile);
- int ey = TileY(tile);
- int sx = TileX(p1);
- int sy = TileY(p1);
- if (ex < sx) Swap(ex, sx);
- if (ey < sy) Swap(ey, sy);
-
Money money = GetAvailableMoneyForCommand();
CommandCost cost(EXPENSES_CONSTRUCTION);
CommandCost last_error = CMD_ERROR;
bool had_success = false;
- for (int x = sx; x <= ex; ++x) {
- for (int y = sy; y <= ey; ++y) {
- CommandCost ret = DoCommand(TileXY(x, y), 0, 0, flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR);
- if (ret.Failed()) {
- last_error = ret;
- continue;
- }
+ TileArea ta(tile, p1);
+ TILE_AREA_LOOP(t, ta) {
+ CommandCost ret = DoCommand(t, 0, 0, flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR);
+ if (ret.Failed()) {
+ last_error = ret;
+ continue;
+ }
- had_success = true;
- if (flags & DC_EXEC) {
- money -= ret.GetCost();
- if (ret.GetCost() > 0 && money < 0) {
- _additional_cash_required = ret.GetCost();
- return cost;
- }
- DoCommand(TileXY(x, y), 0, 0, flags, CMD_LANDSCAPE_CLEAR);
-
- /* draw explosion animation... */
- if ((x == sx || x == ex) && (y == sy || y == ey)) {
- /* big explosion in each corner, or small explosion for single tiles */
- CreateEffectVehicleAbove(x * TILE_SIZE + TILE_SIZE / 2, y * TILE_SIZE + TILE_SIZE / 2, 2,
- sy == ey && sx == ex ? EV_EXPLOSION_SMALL : EV_EXPLOSION_LARGE
- );
- }
+ had_success = true;
+ if (flags & DC_EXEC) {
+ money -= ret.GetCost();
+ if (ret.GetCost() > 0 && money < 0) {
+ _additional_cash_required = ret.GetCost();
+ return cost;
+ }
+ DoCommand(t, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
+
+ /* draw explosion animation... */
+ TileIndex off = t - ta.tile;
+ if ((TileX(off) == 0 || TileX(off) == ta.w - 1U) && (TileY(off) == 0 || TileY(off) == ta.h - 1U)) {
+ /* big explosion in each corner, or small explosion for single tiles */
+ CreateEffectVehicleAbove(TileX(t) * TILE_SIZE + TILE_SIZE / 2, TileY(t) * TILE_SIZE + TILE_SIZE / 2, 2,
+ ta.w == 1 && ta.h == 1 ? EV_EXPLOSION_SMALL : EV_EXPLOSION_LARGE
+ );
}
- cost.AddCost(ret);
}
+ cost.AddCost(ret);
}
return had_success ? cost : last_error;