Mercurial > hg > openttd
changeset 15022:d6237ac69342 draft
(svn r19637) -Codechange: Pass complete TransportType to CmdBuildTunnel.
author | frosch <frosch@openttd.org> |
---|---|
date | Wed, 14 Apr 2010 20:28:37 +0000 |
parents | 69d2f575deb7 |
children | 4f90865323a4 |
files | src/ai/api/ai_tunnel.cpp src/rail_gui.cpp src/road_gui.cpp src/tunnelbridge_cmd.cpp |
diffstat | 4 files changed, 27 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ai/api/ai_tunnel.cpp +++ b/src/ai/api/ai_tunnel.cpp @@ -77,10 +77,10 @@ uint type = 0; if (vehicle_type == AIVehicle::VT_ROAD) { - type |= (TRANSPORT_ROAD << 9); + type |= (TRANSPORT_ROAD << 8); type |= ::RoadTypeToRoadTypes((::RoadType)AIObject::GetRoadType()); } else { - type |= (TRANSPORT_RAIL << 9); + type |= (TRANSPORT_RAIL << 8); type |= AIRail::GetCurrentRailType(); }
--- a/src/rail_gui.cpp +++ b/src/rail_gui.cpp @@ -277,7 +277,7 @@ static void PlaceRail_Tunnel(TileIndex tile) { - DoCommandP(tile, _cur_railtype, 0, CMD_BUILD_TUNNEL | CMD_MSG(STR_ERROR_CAN_T_BUILD_TUNNEL_HERE), CcBuildRailTunnel); + DoCommandP(tile, _cur_railtype | (TRANSPORT_RAIL << 8), 0, CMD_BUILD_TUNNEL | CMD_MSG(STR_ERROR_CAN_T_BUILD_TUNNEL_HERE), CcBuildRailTunnel); } static void PlaceRail_ConvertRail(TileIndex tile) @@ -821,7 +821,7 @@ virtual void OnPlacePresize(Point pt, TileIndex tile) { - DoCommand(tile, _cur_railtype, 0, DC_AUTO, CMD_BUILD_TUNNEL); + DoCommand(tile, _cur_railtype | (TRANSPORT_RAIL << 8), 0, DC_AUTO, CMD_BUILD_TUNNEL); VpSetPresizeRange(tile, _build_tunnel_endtile == 0 ? tile : _build_tunnel_endtile); }
--- a/src/road_gui.cpp +++ b/src/road_gui.cpp @@ -182,7 +182,7 @@ static void PlaceRoad_Tunnel(TileIndex tile) { - DoCommandP(tile, 0x200 | RoadTypeToRoadTypes(_cur_roadtype), 0, CMD_BUILD_TUNNEL | CMD_MSG(STR_ERROR_CAN_T_BUILD_TUNNEL_HERE), CcBuildRoadTunnel); + DoCommandP(tile, RoadTypeToRoadTypes(_cur_roadtype) | (TRANSPORT_ROAD << 8), 0, CMD_BUILD_TUNNEL | CMD_MSG(STR_ERROR_CAN_T_BUILD_TUNNEL_HERE), CcBuildRoadTunnel); } static void BuildRoadOutsideStation(TileIndex tile, DiagDirection direction) @@ -688,7 +688,7 @@ virtual void OnPlacePresize(Point pt, TileIndex tile) { - DoCommand(tile, 0x200 | RoadTypeToRoadTypes(_cur_roadtype), 0, DC_AUTO, CMD_BUILD_TUNNEL); + DoCommand(tile, RoadTypeToRoadTypes(_cur_roadtype) | (TRANSPORT_ROAD << 8), 0, DC_AUTO, CMD_BUILD_TUNNEL); VpSetPresizeRange(tile, _build_tunnel_endtile == 0 ? tile : _build_tunnel_endtile); }
--- a/src/tunnelbridge_cmd.cpp +++ b/src/tunnelbridge_cmd.cpp @@ -482,21 +482,31 @@ /** Build Tunnel. * @param start_tile start tile of tunnel * @param flags type of operation - * @param p1 railtype or roadtypes. bit 9 set means road tunnel + * @param p1 bit 0-3 railtype or roadtypes + * bit 8-9 transport type * @param p2 unused * @param text unused * @return the cost of this operation or an error */ CommandCost CmdBuildTunnel(TileIndex start_tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) { - TransportType transport_type = (TransportType)GB(p1, 9, 1); + TransportType transport_type = (TransportType)GB(p1, 8, 2); + RailType railtype = INVALID_RAILTYPE; + RoadTypes rts = ROADTYPES_NONE; _build_tunnel_endtile = 0; - if (transport_type == TRANSPORT_RAIL) { - if (!ValParamRailtype((RailType)p1)) return CMD_ERROR; - } else { - const RoadTypes rts = (RoadTypes)GB(p1, 0, 2); - if (!HasExactlyOneBit(rts) || !HasRoadTypesAvail(_current_company, rts)) return CMD_ERROR; + switch (transport_type) { + case TRANSPORT_RAIL: + railtype = (RailType)GB(p1, 0, 4); + if (!ValParamRailtype(railtype)) return CMD_ERROR; + break; + + case TRANSPORT_ROAD: + rts = (RoadTypes)GB(p1, 0, 2); + if (!HasExactlyOneBit(rts) || !HasRoadTypesAvail(_current_company, rts)) return CMD_ERROR; + break; + + default: return CMD_ERROR; } uint start_z; @@ -584,13 +594,13 @@ if (flags & DC_EXEC) { if (transport_type == TRANSPORT_RAIL) { - MakeRailTunnel(start_tile, _current_company, direction, (RailType)GB(p1, 0, 4)); - MakeRailTunnel(end_tile, _current_company, ReverseDiagDir(direction), (RailType)GB(p1, 0, 4)); + MakeRailTunnel(start_tile, _current_company, direction, railtype); + MakeRailTunnel(end_tile, _current_company, ReverseDiagDir(direction), railtype); AddSideToSignalBuffer(start_tile, INVALID_DIAGDIR, _current_company); YapfNotifyTrackLayoutChange(start_tile, DiagDirToDiagTrack(direction)); } else { - MakeRoadTunnel(start_tile, _current_company, direction, (RoadTypes)GB(p1, 0, 2)); - MakeRoadTunnel(end_tile, _current_company, ReverseDiagDir(direction), (RoadTypes)GB(p1, 0, 2)); + MakeRoadTunnel(start_tile, _current_company, direction, rts); + MakeRoadTunnel(end_tile, _current_company, ReverseDiagDir(direction), rts); } }