mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r3813) Simplify strange control flow
This commit is contained in:
parent
abca252ff5
commit
293bf531be
30
water_cmd.c
30
water_cmd.c
|
@ -210,7 +210,7 @@ int32 CmdBuildLock(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
*/
|
*/
|
||||||
int32 CmdBuildCanal(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
int32 CmdBuildCanal(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
{
|
{
|
||||||
int32 ret, cost;
|
int32 cost;
|
||||||
int size_x, size_y;
|
int size_x, size_y;
|
||||||
int sx, sy;
|
int sx, sy;
|
||||||
|
|
||||||
|
@ -234,7 +234,6 @@ int32 CmdBuildCanal(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
|
|
||||||
cost = 0;
|
cost = 0;
|
||||||
BEGIN_TILE_LOOP(tile, size_x, size_y, TileXY(sx, sy)) {
|
BEGIN_TILE_LOOP(tile, size_x, size_y, TileXY(sx, sy)) {
|
||||||
ret = 0;
|
|
||||||
if (GetTileSlope(tile, NULL) != 0) return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
|
if (GetTileSlope(tile, NULL) != 0) return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
|
||||||
|
|
||||||
// can't make water of water!
|
// can't make water of water!
|
||||||
|
@ -246,28 +245,29 @@ int32 CmdBuildCanal(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
if (_m[tile].m5 & 0x20) // transport route under bridge
|
if (_m[tile].m5 & 0x20) // transport route under bridge
|
||||||
return_cmd_error(STR_5800_OBJECT_IN_THE_WAY);
|
return_cmd_error(STR_5800_OBJECT_IN_THE_WAY);
|
||||||
|
|
||||||
if (_m[tile].m5 & 0x18) // already water under bridge
|
if (_m[tile].m5 & 0x18) { // already water under bridge
|
||||||
return_cmd_error(STR_1007_ALREADY_BUILT);
|
return_cmd_error(STR_1007_ALREADY_BUILT);
|
||||||
/* no bridge? then try to clear it. */
|
}
|
||||||
} else
|
|
||||||
ret = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
|
||||||
|
|
||||||
if (CmdFailed(ret)) return CMD_ERROR;
|
if (flags & DC_EXEC) {
|
||||||
cost += ret;
|
|
||||||
|
|
||||||
/* execute modifications */
|
|
||||||
if (flags & DC_EXEC) {
|
|
||||||
if (IsTileType(tile, MP_TUNNELBRIDGE)) {
|
|
||||||
// change owner to OWNER_WATER and set land under bridge bit to water
|
// change owner to OWNER_WATER and set land under bridge bit to water
|
||||||
ModifyTile(tile, MP_MAP5 | MP_MAPOWNER, OWNER_WATER, _m[tile].m5 | 0x08);
|
ModifyTile(tile, MP_MAP5 | MP_MAPOWNER, OWNER_WATER, _m[tile].m5 | 0x08);
|
||||||
} else {
|
}
|
||||||
|
} else {
|
||||||
|
/* no bridge, try to clear it. */
|
||||||
|
int32 ret = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
|
||||||
|
|
||||||
|
if (CmdFailed(ret)) return CMD_ERROR;
|
||||||
|
cost += ret;
|
||||||
|
|
||||||
|
if (flags & DC_EXEC) {
|
||||||
MakeWater(tile);
|
MakeWater(tile);
|
||||||
MarkTileDirtyByTile(tile);
|
MarkTileDirtyByTile(tile);
|
||||||
}
|
}
|
||||||
// mark the tiles around dirty too
|
|
||||||
MarkTilesAroundDirty(tile);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (flags & DC_EXEC) MarkTilesAroundDirty(tile);
|
||||||
|
|
||||||
cost += _price.clear_water;
|
cost += _price.clear_water;
|
||||||
}
|
}
|
||||||
} END_TILE_LOOP(tile, size_x, size_y, 0);
|
} END_TILE_LOOP(tile, size_x, size_y, 0);
|
||||||
|
|
Loading…
Reference in New Issue