Mercurial > hg > openttd
changeset 3065:a09d26e1abdf draft
(svn r3654) Turn another if-cascade into a switch
author | tron <tron@openttd.org> |
---|---|
date | Wed, 22 Feb 2006 21:35:45 +0000 |
parents | 9faaf26ffd1c |
children | 4088b1ebe8ff |
files | tunnelbridge_cmd.c |
diffstat | 1 files changed, 26 insertions(+), 28 deletions(-) [+] |
line wrap: on
line diff
--- a/tunnelbridge_cmd.c +++ b/tunnelbridge_cmd.c @@ -336,36 +336,34 @@ _error_message = STR_5009_LEVEL_LAND_OR_WATER_REQUIRED; if (ti.tileh != 0 && ti.z >= ti_start.z) return CMD_ERROR; - // Find ship below - if (ti.type == MP_WATER && !EnsureNoVehicle(ti.tile)) { - _error_message = STR_980E_SHIP_IN_THE_WAY; - return CMD_ERROR; - } + switch (ti.type){ + case MP_WATER: + if (!EnsureNoVehicle(ti.tile)) { + _error_message = STR_980E_SHIP_IN_THE_WAY; + return CMD_ERROR; + } + if (ti.map5 > 1) goto not_valid_below; + m5 = 0xC8; + break; - if (ti.type == MP_WATER) { - if (ti.map5 > 1) goto not_valid_below; - m5 = 0xC8; - } else if (ti.type == MP_RAILWAY) { - if (direction == 0) { - if (ti.map5 != 2) goto not_valid_below; - } else { - if (ti.map5 != 1) goto not_valid_below; - } - m5 = 0xE0; - } else if (ti.type == MP_STREET) { - if (direction == 0) { - if (ti.map5 != 5) goto not_valid_below; - } else { - if (ti.map5 != 10) goto not_valid_below; - } - m5 = 0xE8; - } else { + case MP_RAILWAY: + if (ti.map5 != (direction == 0 ? 2 : 1)) goto not_valid_below; + m5 = 0xE0; + break; + + case MP_STREET: + if (ti.map5 != (direction == 0 ? 5 : 10)) goto not_valid_below; + m5 = 0xE8; + break; + + default: not_valid_below:; - /* try and clear the middle landscape */ - ret = DoCommandByTile(ti.tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); - if (CmdFailed(ret)) return CMD_ERROR; - cost += ret; - m5 = 0xC0; + /* try and clear the middle landscape */ + ret = DoCommandByTile(ti.tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); + if (CmdFailed(ret)) return CMD_ERROR; + cost += ret; + m5 = 0xC0; + break; } /* do middle part of bridge */