summaryrefslogtreecommitdiff
path: root/water_cmd.c
diff options
context:
space:
mode:
authorDarkvater <darkvater@openttd.org>2005-04-02 23:05:09 +0000
committerDarkvater <darkvater@openttd.org>2005-04-02 23:05:09 +0000
commitf35b59adedd9c2e3008fd57f4f73f0ebee08cbae (patch)
treea3c43533eb0b67e41d490acab241a6fb4eb30cf6 /water_cmd.c
parent3bfda758dbdca55ff9d0b628743caed5a61255a7 (diff)
downloadopenttd-f35b59adedd9c2e3008fd57f4f73f0ebee08cbae.tar.xz
(svn r2136) - Fix: [ 1174313 ] terrain hotkeys nonfunctional in scenario editor (D,Q,W,E,R,T,Y,U fltr)
- Fix: 'L' no longer opens ingame terraform bar in scenario editor bar, but the land generator one - Feature: [ 1095110 ] Create Lake and draggable Create Desert tools (initial implementation GoneWacko), also added sticky buttons to land generator and town generator - CodeChange: moved around some of the draggable tools, demystifying them - CodeChange: change CmdBuildCanal to allow for XANDY dragging not only X or Y (only scenario editor) - CodeChange: add some more enums to sprites. - TODO: merge most of the ingame and scenario editor land terraform code. This can only be done after OnClickButton function is changed so it also includes the backreference to the widget being clicked, postponed to after 0.4.0
Diffstat (limited to 'water_cmd.c')
-rw-r--r--water_cmd.c40
1 files changed, 17 insertions, 23 deletions
diff --git a/water_cmd.c b/water_cmd.c
index 64278cc0e..6a55e131e 100644
--- a/water_cmd.c
+++ b/water_cmd.c
@@ -179,33 +179,32 @@ int32 CmdBuildLock(int x, int y, uint32 flags, uint32 p1, uint32 p2)
int32 CmdBuildCanal(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{
- uint tile = TILE_FROM_XY(x,y);
- int32 ret;
- uint th;
- uint endtile = (uint)p1;
- int delta;
- int32 cost;
+ int32 ret, cost;
+ int size_x, size_y;
+ int sx = TileX((TileIndex)p1);
+ int sy = TileY((TileIndex)p1);
+ x >>= 4; y >>= 4;
+
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
- // move in which direction?
- delta = (TileX(tile) == TileX(endtile)) ? TILE_XY(0,1) : TILE_XY(1,0);
- if (endtile < tile) delta = -delta;
+ if (x < sx) intswap(x, sx);
+ if (y < sy) intswap(y, sy);
+ size_x = (x - sx) + 1;
+ size_y = (y - sy) + 1;
cost = 0;
- for(;;) {
+ BEGIN_TILE_LOOP(tile, size_x, size_y, TILE_XY(sx, sy)) {
ret = 0;
- th = GetTileSlope(tile, NULL);
- if(th!=0)
+ if (GetTileSlope(tile, NULL) != 0)
return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
// can't make water of water!
if (IsTileType(tile, MP_WATER)) {
_error_message = STR_1007_ALREADY_BUILT;
} else {
-
/* is middle piece of a bridge? */
if (IsTileType(tile, MP_TUNNELBRIDGE) && _map5[tile] & 0x40) { /* build under bridge */
- if(_map5[tile] & 0x20) { // transport route under bridge
+ if (_map5[tile] & 0x20) { // transport route under bridge
_error_message = STR_5800_OBJECT_IN_THE_WAY;
ret = CMD_ERROR;
}
@@ -213,11 +212,10 @@ int32 CmdBuildCanal(int x, int y, uint32 flags, uint32 p1, uint32 p2)
_error_message = STR_1007_ALREADY_BUILT;
ret = CMD_ERROR;
}
-
/* no bridge? then try to clear it. */
- } else {
+ } else
ret = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
- }
+
if (ret == CMD_ERROR) return ret;
cost += ret;
@@ -235,13 +233,9 @@ int32 CmdBuildCanal(int x, int y, uint32 flags, uint32 p1, uint32 p2)
cost += _price.clear_water;
}
- if (tile == endtile)
- break;
- tile += delta;
- }
- if (cost == 0) return CMD_ERROR;
+ } END_TILE_LOOP(tile, size_x, size_y, 0);
- return cost;
+ return (cost == 0) ? CMD_ERROR : cost;
}
static int32 ClearTile_Water(uint tile, byte flags) {