mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r21482) -Codechange: make landscape clearing make use of TILE_AREA_LOOP as well
This commit is contained in:
parent
a1d923700f
commit
67e6ad2a4b
|
@ -650,46 +650,38 @@ CommandCost CmdClearArea(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
|
||||||
{
|
{
|
||||||
if (p1 >= MapSize()) return CMD_ERROR;
|
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();
|
Money money = GetAvailableMoneyForCommand();
|
||||||
CommandCost cost(EXPENSES_CONSTRUCTION);
|
CommandCost cost(EXPENSES_CONSTRUCTION);
|
||||||
CommandCost last_error = CMD_ERROR;
|
CommandCost last_error = CMD_ERROR;
|
||||||
bool had_success = false;
|
bool had_success = false;
|
||||||
|
|
||||||
for (int x = sx; x <= ex; ++x) {
|
TileArea ta(tile, p1);
|
||||||
for (int y = sy; y <= ey; ++y) {
|
TILE_AREA_LOOP(t, ta) {
|
||||||
CommandCost ret = DoCommand(TileXY(x, y), 0, 0, flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR);
|
CommandCost ret = DoCommand(t, 0, 0, flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR);
|
||||||
if (ret.Failed()) {
|
if (ret.Failed()) {
|
||||||
last_error = ret;
|
last_error = ret;
|
||||||
continue;
|
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
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cost.AddCost(ret);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
return had_success ? cost : last_error;
|
return had_success ? cost : last_error;
|
||||||
|
|
Loading…
Reference in New Issue