From 5cc56d6ad989c4a78cd174d84249ba16b3c51cfe Mon Sep 17 00:00:00 2001 From: keldorkatarn Date: Fri, 1 Apr 2016 21:27:19 +0200 Subject: [PATCH] Make 32 instead of 16 rail types possible. by using one free bit of m1 in the map array. (cherry picked from commit b44843800880cdc186f5183301ee0f42afbb5f84) Also set non-rail type M3 bits to 0 where applicable. Change savegame versioning to SLXI format. --- src/bridge_gui.cpp | 2 +- src/bridge_map.h | 8 +++++- src/command.cpp | 2 +- src/rail_cmd.cpp | 45 ++++++++++++++++---------------- src/rail_gui.cpp | 8 +++--- src/rail_map.h | 11 +++++--- src/rail_type.h | 4 +-- src/road_map.h | 6 ++++- src/saveload/afterload.cpp | 13 +++++++++ src/saveload/extended_ver_sl.cpp | 1 + src/saveload/extended_ver_sl.h | 1 + src/script/api/script_rail.cpp | 28 ++++++++++---------- src/station_cmd.cpp | 8 +++--- src/tunnel_map.h | 4 ++- src/tunnelbridge_cmd.cpp | 8 +++--- 15 files changed, 90 insertions(+), 59 deletions(-) diff --git a/src/bridge_gui.cpp b/src/bridge_gui.cpp index 797ead1f51..3b314087a8 100644 --- a/src/bridge_gui.cpp +++ b/src/bridge_gui.cpp @@ -55,7 +55,7 @@ typedef GUIList GUIBridgeList; ///< List of bridges, used in #B * @param p1 packed start tile coords (~ dx) * @param p2 various bitstuffed elements * - p2 = (bit 0- 7) - bridge type (hi bh) - * - p2 = (bit 8-11) - rail type or road types. + * - p2 = (bit 8-12) - rail type or road types. * - p2 = (bit 15-16) - transport type. */ void CcBuildBridge(const CommandCost &result, TileIndex end_tile, uint32 p1, uint32 p2) diff --git a/src/bridge_map.h b/src/bridge_map.h index 74c6974db2..99ff2440a0 100644 --- a/src/bridge_map.h +++ b/src/bridge_map.h @@ -131,7 +131,13 @@ static inline void MakeBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, D SetTileType(t, MP_TUNNELBRIDGE); SetTileOwner(t, o); _m[t].m2 = 0; - _m[t].m3 = rt; + if (tt == TRANSPORT_RAIL) { + SB(_m[t].m1, 7, 1, GB(rt, 4, 1)); + SB(_m[t].m3, 0, 4, GB(rt, 0, 4)); + SB(_m[t].m3, 4, 4, 0); + } else { + _m[t].m3 = rt; + } _m[t].m4 = 0; _m[t].m5 = 1 << 7 | tt << 2 | d; SB(_me[t].m6, 2, 4, bridgetype); diff --git a/src/command.cpp b/src/command.cpp index 1ec2b11a5e..1685c2b15b 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -265,7 +265,7 @@ static const Command _command_proc_table[] = { DEF_CMD(CmdBuildHouse, CMD_DEITY | CMD_NO_WATER | CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_BUILD_HOUSE DEF_CMD(CmdBuildTunnel, CMD_DEITY | CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_BUILD_TUNNEL DEF_CMD(CmdRemoveFromRailStation, 0, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_REMOVE_FROM_RAIL_STATION - DEF_CMD(CmdConvertRail, 0, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_CONVERT_RAILD + DEF_CMD(CmdConvertRail, 0, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_CONVERT_RAIL DEF_CMD(CmdBuildRailWaypoint, 0, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_BUILD_RAIL_WAYPOINT DEF_CMD(CmdRenameWaypoint, 0, CMDT_OTHER_MANAGEMENT ), // CMD_RENAME_WAYPOINT DEF_CMD(CmdRemoveFromRailWaypoint, 0, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_REMOVE_FROM_RAIL_WAYPOINT diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index 5545de8a06..c457b9d01c 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -438,7 +438,7 @@ static inline bool ValParamTrackOrientation(Track track) */ CommandCost CmdBuildSingleRail(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) { - RailType railtype = Extract(p1); + RailType railtype = Extract(p1); Track track = Extract(p2); CommandCost cost(EXPENSES_CONSTRUCTION); @@ -852,19 +852,20 @@ static CommandCost ValidateAutoDrag(Trackdir *trackdir, TileIndex start, TileInd * @param flags operation to perform * @param p1 end tile of drag * @param p2 various bitstuffed elements - * - p2 = (bit 0-3) - railroad type normal/maglev (0 = normal, 1 = mono, 2 = maglev), only used for building - * - p2 = (bit 4-6) - track-orientation, valid values: 0-5 (Track enum) - * - p2 = (bit 7) - 0 = build, 1 = remove tracks - * - p2 = (bit 8) - 0 = build up to an obstacle, 1 = fail if an obstacle is found (used for AIs). + * - p2 = (bit 0-4) - railroad type normal/maglev (0 = normal, 1 = mono, 2 = maglev), only used for building + * - p2 = (bit 5-7) - track-orientation, valid values: 0-5 (Track enum) + * - p2 = (bit 8) - 0 = build, 1 = remove tracks + * - p2 = (bit 9) - 0 = build up to an obstacle, 1 = fail if an obstacle is found (used for AIs). * @param text unused * @return the cost of this operation or an error */ static CommandCost CmdRailTrackHelper(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) { CommandCost total_cost(EXPENSES_CONSTRUCTION); - Track track = Extract(p2); - bool remove = HasBit(p2, 7); - RailType railtype = Extract(p2); + RailType railtype = Extract(p2); + Track track = Extract(p2); + bool remove = HasBit(p2, 8); + bool fail_if_obstacle = HasBit(p2, 9); if ((!remove && !ValParamRailtype(railtype)) || !ValParamTrackOrientation(track)) return CMD_ERROR; if (p1 >= MapSize()) return CMD_ERROR; @@ -882,7 +883,7 @@ static CommandCost CmdRailTrackHelper(TileIndex tile, DoCommandFlag flags, uint3 if (ret.Failed()) { last_error = ret; if (last_error.GetErrorMessage() != STR_ERROR_ALREADY_BUILT && !remove) { - if (HasBit(p2, 8)) return last_error; + if (fail_if_obstacle) return last_error; break; } @@ -912,16 +913,16 @@ static CommandCost CmdRailTrackHelper(TileIndex tile, DoCommandFlag flags, uint3 * @param flags operation to perform * @param p1 end tile of drag * @param p2 various bitstuffed elements - * - p2 = (bit 0-3) - railroad type normal/maglev (0 = normal, 1 = mono, 2 = maglev) - * - p2 = (bit 4-6) - track-orientation, valid values: 0-5 (Track enum) - * - p2 = (bit 7) - 0 = build, 1 = remove tracks + * - p2 = (bit 0-4) - railroad type normal/maglev (0 = normal, 1 = mono, 2 = maglev) + * - p2 = (bit 5-7) - track-orientation, valid values: 0-5 (Track enum) + * - p2 = (bit 8) - 0 = build, 1 = remove tracks * @param text unused * @return the cost of this operation or an error * @see CmdRailTrackHelper */ CommandCost CmdBuildRailroadTrack(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) { - return CmdRailTrackHelper(tile, flags, p1, ClrBit(p2, 7), text); + return CmdRailTrackHelper(tile, flags, p1, ClrBit(p2, 8), text); } /** @@ -931,16 +932,16 @@ CommandCost CmdBuildRailroadTrack(TileIndex tile, DoCommandFlag flags, uint32 p1 * @param flags operation to perform * @param p1 end tile of drag * @param p2 various bitstuffed elements - * - p2 = (bit 0-3) - railroad type normal/maglev (0 = normal, 1 = mono, 2 = maglev), only used for building - * - p2 = (bit 4-6) - track-orientation, valid values: 0-5 (Track enum) - * - p2 = (bit 7) - 0 = build, 1 = remove tracks + * - p2 = (bit 0-4) - railroad type normal/maglev (0 = normal, 1 = mono, 2 = maglev), only used for building + * - p2 = (bit 5-7) - track-orientation, valid values: 0-5 (Track enum) + * - p2 = (bit 8) - 0 = build, 1 = remove tracks * @param text unused * @return the cost of this operation or an error * @see CmdRailTrackHelper */ CommandCost CmdRemoveRailroadTrack(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) { - return CmdRailTrackHelper(tile, flags, p1, SetBit(p2, 7), text); + return CmdRailTrackHelper(tile, flags, p1, SetBit(p2, 8), text); } /** @@ -958,7 +959,7 @@ CommandCost CmdRemoveRailroadTrack(TileIndex tile, DoCommandFlag flags, uint32 p CommandCost CmdBuildTrainDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) { /* check railtype and valid direction for depot (0 through 3), 4 in total */ - RailType railtype = Extract(p1); + RailType railtype = Extract(p1); if (!ValParamRailtype(railtype)) return CMD_ERROR; Slope tileh = GetTileSlope(tile); @@ -1675,17 +1676,17 @@ static Vehicle *UpdateTrainPowerProc(Vehicle *v, void *data) * @param flags operation to perform * @param p1 start tile of drag * @param p2 various bitstuffed elements: - * - p2 = (bit 0- 3) new railtype to convert to. - * - p2 = (bit 4) build diagonally or not. + * - p2 = (bit 0 - 4) new railtype to convert to. + * - p2 = (bit 5) build diagonally or not. * @param text unused * @return the cost of this operation or an error */ CommandCost CmdConvertRail(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) { - RailType totype = Extract(p2); + RailType totype = Extract(p2); TileIndex area_start = p1; TileIndex area_end = tile; - bool diagonal = HasBit(p2, 4); + bool diagonal = HasBit(p2, 5); if (!ValParamRailtype(totype)) return CMD_ERROR; if (area_start >= MapSize()) return CMD_ERROR; diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp index 9f337ed276..4dfe2c7933 100644 --- a/src/rail_gui.cpp +++ b/src/rail_gui.cpp @@ -196,7 +196,7 @@ static void PlaceRail_Station(TileIndex tile) VpStartPlaceSizing(tile, VPM_X_AND_Y_LIMITED, DDSP_BUILD_STATION); VpSetPlaceSizingLimit(_settings_game.station.station_spread); } else { - uint32 p1 = _cur_railtype | _railstation.orientation << 4 | _settings_client.gui.station_numtracks << 8 | _settings_client.gui.station_platlength << 16 | _ctrl_pressed << 24; + uint32 p1 = _cur_railtype | _railstation.orientation << 5 | _settings_client.gui.station_numtracks << 8 | _settings_client.gui.station_platlength << 16 | _ctrl_pressed << 24; uint32 p2 = _railstation.station_class | _railstation.station_type << 8 | INVALID_STATION << 16; int w = _settings_client.gui.station_numtracks; @@ -373,7 +373,7 @@ static void BuildRailClick_Remove(Window *w) static void DoRailroadTrack(int mode) { - DoCommandP(TileVirtXY(_thd.selstart.x, _thd.selstart.y), TileVirtXY(_thd.selend.x, _thd.selend.y), _cur_railtype | (mode << 4), + DoCommandP(TileVirtXY(_thd.selstart.x, _thd.selstart.y), TileVirtXY(_thd.selend.x, _thd.selend.y), _cur_railtype | (mode << 5), _remove_button_clicked ? CMD_REMOVE_RAILROAD_TRACK | CMD_MSG(STR_ERROR_CAN_T_REMOVE_RAILROAD_TRACK) : CMD_BUILD_RAILROAD_TRACK | CMD_MSG(STR_ERROR_CAN_T_BUILD_RAILROAD_TRACK), @@ -732,7 +732,7 @@ struct BuildRailToolbarWindow : Window { break; case DDSP_CONVERT_RAIL: - DoCommandP(end_tile, start_tile, _cur_railtype | (_ctrl_pressed ? 0x10 : 0), CMD_CONVERT_RAIL | CMD_MSG(STR_ERROR_CAN_T_CONVERT_RAIL), CcPlaySound10); + DoCommandP(end_tile, start_tile, _cur_railtype | (_ctrl_pressed ? (1 << 5) : 0), CMD_CONVERT_RAIL | CMD_MSG(STR_ERROR_CAN_T_CONVERT_RAIL), CcPlaySound10); break; case DDSP_REMOVE_STATION: @@ -907,7 +907,7 @@ static void HandleStationPlacement(TileIndex start, TileIndex end) if (_railstation.orientation == AXIS_X) Swap(numtracks, platlength); - uint32 p1 = _cur_railtype | _railstation.orientation << 4 | numtracks << 8 | platlength << 16 | _ctrl_pressed << 24; + uint32 p1 = _cur_railtype | _railstation.orientation << 5 | numtracks << 8 | platlength << 16 | _ctrl_pressed << 24; uint32 p2 = _railstation.station_class | _railstation.station_type << 8 | INVALID_STATION << 16; CommandContainer cmdcont = { ta.tile, p1, p2, CMD_BUILD_RAIL_STATION | CMD_MSG(STR_ERROR_CAN_T_BUILD_RAILROAD_STATION), CcStation, 0, "" }; diff --git a/src/rail_map.h b/src/rail_map.h index ee6415037e..7c5e1af7f2 100644 --- a/src/rail_map.h +++ b/src/rail_map.h @@ -116,7 +116,7 @@ static inline bool IsRailDepotTile(TileIndex t) */ static inline RailType GetRailType(TileIndex t) { - return (RailType)GB(_m[t].m3, 0, 4); + return (RailType)((GB(_m[t].m1, 7, 1) << 4) | GB(_m[t].m3, 0, 4)); } /** @@ -126,7 +126,8 @@ static inline RailType GetRailType(TileIndex t) */ static inline void SetRailType(TileIndex t, RailType r) { - SB(_m[t].m3, 0, 4, r); + SB(_m[t].m1, 7, 1, GB(r, 4, 1)); + SB(_m[t].m3, 0, 4, GB(r, 0, 4)); } @@ -554,7 +555,8 @@ static inline void MakeRailNormal(TileIndex t, Owner o, TrackBits b, RailType r) SetTileType(t, MP_RAILWAY); SetTileOwner(t, o); _m[t].m2 = 0; - _m[t].m3 = r; + _m[t].m3 = 0; + SetRailType(t, r); _m[t].m4 = 0; _m[t].m5 = RAIL_TILE_NORMAL << 6 | b; SB(_me[t].m6, 2, 4, 0); @@ -567,7 +569,8 @@ static inline void MakeRailDepot(TileIndex t, Owner o, DepotID did, DiagDirectio SetTileType(t, MP_RAILWAY); SetTileOwner(t, o); _m[t].m2 = did; - _m[t].m3 = r; + _m[t].m3 = 0; + SetRailType(t, r); _m[t].m4 = 0; _m[t].m5 = RAIL_TILE_DEPOT << 6 | d; SB(_me[t].m6, 2, 4, 0); diff --git a/src/rail_type.h b/src/rail_type.h index ee589898b8..dba01b5b7b 100644 --- a/src/rail_type.h +++ b/src/rail_type.h @@ -32,7 +32,7 @@ enum RailType { RAILTYPE_ELECTRIC = 1, ///< Electric rails RAILTYPE_MONO = 2, ///< Monorail RAILTYPE_MAGLEV = 3, ///< Maglev - RAILTYPE_END = 16, ///< Used for iterations + RAILTYPE_END = 32, ///< Used for iterations INVALID_RAILTYPE = 0xFF, ///< Flag for invalid railtype DEF_RAILTYPE_FIRST = RAILTYPE_END, ///< Default railtype: first available @@ -43,7 +43,7 @@ enum RailType { /** Allow incrementing of Track variables */ DECLARE_POSTFIX_INCREMENT(RailType) /** Define basic enum properties */ -template <> struct EnumPropsT : MakeEnumPropsT {}; +template <> struct EnumPropsT : MakeEnumPropsT {}; typedef TinyEnumT RailTypeByte; /** diff --git a/src/road_map.h b/src/road_map.h index 693730294e..9849ad474a 100644 --- a/src/road_map.h +++ b/src/road_map.h @@ -579,7 +579,11 @@ static inline void MakeRoadCrossing(TileIndex t, Owner road, Owner tram, Owner r SetTileType(t, MP_ROAD); SetTileOwner(t, rail); _m[t].m2 = town; - _m[t].m3 = rat; + + SB(_m[t].m1, 7, 1, GB(rat, 4, 1)); + SB(_m[t].m3, 0, 4, GB(rat, 0, 4)); + SB(_m[t].m3, 4, 4, 0); + _m[t].m4 = 0; _m[t].m5 = ROAD_TILE_CROSSING << 6 | roaddir; SB(_me[t].m6, 2, 4, 0); diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index 107ab06249..6be8d0cbc7 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -3213,6 +3213,19 @@ bool AfterLoadGame() FOR_ALL_VEHICLES(v) v->profit_lifetime = 0; } + // Before this version we didn't store the 5th bit of the tracktype here. + // So set it to 0 just in case there was garbage in there. + if (SlXvIsFeatureMissing(XSLFI_MORE_RAIL_TYPES)) { + for (TileIndex t = 0; t < map_size; t++) { + if (_m[t].type == MP_RAILWAY || + _m[t].type == MP_ROAD || + _m[t].type == MP_STATION || + _m[t].type == MP_TUNNELBRIDGE) { + SB(_m[t].m1, 7, 1, 0); + } + } + } + /* Road stops is 'only' updating some caches */ AfterLoadRoadStops(); AfterLoadLabelMaps(); diff --git a/src/saveload/extended_ver_sl.cpp b/src/saveload/extended_ver_sl.cpp index e77fb1129a..76e5d36e74 100644 --- a/src/saveload/extended_ver_sl.cpp +++ b/src/saveload/extended_ver_sl.cpp @@ -69,6 +69,7 @@ const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = { { XSLFI_VEH_LIFETIME_PROFIT, XSCF_NULL, 1, 1, "veh_lifetime_profit", NULL, NULL, NULL }, { XSLFI_LINKGRAPH_DAY_SCALE, XSCF_NULL, 1, 1, "linkgraph_day_scale", NULL, NULL, NULL }, { XSLFI_TEMPLATE_REPLACEMENT, XSCF_NULL, 1, 1, "template_replacement", NULL, NULL, "TRPL,TMPL" }, + { XSLFI_MORE_RAIL_TYPES, XSCF_NULL, 1, 1, "more_rail_types", NULL, NULL, NULL }, { XSLFI_NULL, XSCF_NULL, 0, 0, NULL, NULL, NULL, NULL },// This is the end marker }; diff --git a/src/saveload/extended_ver_sl.h b/src/saveload/extended_ver_sl.h index 887ea20701..f977bcb3c7 100644 --- a/src/saveload/extended_ver_sl.h +++ b/src/saveload/extended_ver_sl.h @@ -43,6 +43,7 @@ enum SlXvFeatureIndex { XSLFI_VEH_LIFETIME_PROFIT, ///< Vehicle lifetime profit patch XSLFI_LINKGRAPH_DAY_SCALE, ///< Linkgraph job duration & interval may be in non-scaled days XSLFI_TEMPLATE_REPLACEMENT, ///< Template-based train replacement + XSLFI_MORE_RAIL_TYPES, ///< Increased number of rail types XSLFI_RIFF_HEADER_60_BIT, ///< Size field in RIFF chunk header is 60 bit XSLFI_HEIGHT_8_BIT, ///< Map tile height is 8 bit instead of 4 bit, but savegame version may be before this became true in trunk diff --git a/src/script/api/script_rail.cpp b/src/script/api/script_rail.cpp index af68a3edc8..5e4f2d5e92 100644 --- a/src/script/api/script_rail.cpp +++ b/src/script/api/script_rail.cpp @@ -157,7 +157,7 @@ EnforcePrecondition(false, station_id == ScriptStation::STATION_NEW || station_id == ScriptStation::STATION_JOIN_ADJACENT || ScriptStation::IsValidStation(station_id)); uint32 p1 = GetCurrentRailType() | (platform_length << 16) | (num_platforms << 8); - if (direction == RAILTRACK_NW_SE) p1 |= (1 << 4); + if (direction == RAILTRACK_NW_SE) p1 |= (1 << 5); if (station_id != ScriptStation::STATION_JOIN_ADJACENT) p1 |= (1 << 24); return ScriptObject::DoCommand(tile, p1, (ScriptStation::IsValidStation(station_id) ? station_id : INVALID_STATION) << 16, CMD_BUILD_RAIL_STATION); } @@ -176,7 +176,7 @@ EnforcePrecondition(false, goal_industry == ScriptIndustryType::INDUSTRYTYPE_UNKNOWN || goal_industry == ScriptIndustryType::INDUSTRYTYPE_TOWN || ScriptIndustryType::IsValidIndustryType(goal_industry)); uint32 p1 = GetCurrentRailType() | (platform_length << 16) | (num_platforms << 8); - if (direction == RAILTRACK_NW_SE) p1 |= 1 << 4; + if (direction == RAILTRACK_NW_SE) p1 |= 1 << 5; if (station_id != ScriptStation::STATION_JOIN_ADJACENT) p1 |= (1 << 24); const GRFFile *file; @@ -244,7 +244,7 @@ EnforcePrecondition(false, KillFirstBit((uint)rail_track) == 0); EnforcePrecondition(false, IsRailTypeAvailable(GetCurrentRailType())); - return ScriptObject::DoCommand(tile, tile, GetCurrentRailType() | (FindFirstTrack((::TrackBits)rail_track) << 4), CMD_BUILD_RAILROAD_TRACK); + return ScriptObject::DoCommand(tile, tile, GetCurrentRailType() | (FindFirstTrack((::TrackBits)rail_track) << 5), CMD_BUILD_RAILROAD_TRACK); } /* static */ bool ScriptRail::RemoveRailTrack(TileIndex tile, RailTrack rail_track) @@ -255,7 +255,7 @@ EnforcePrecondition(false, GetRailTracks(tile) & rail_track); EnforcePrecondition(false, KillFirstBit((uint)rail_track) == 0); - return ScriptObject::DoCommand(tile, tile, FindFirstTrack((::TrackBits)rail_track) << 4, CMD_REMOVE_RAILROAD_TRACK); + return ScriptObject::DoCommand(tile, tile, FindFirstTrack((::TrackBits)rail_track) << 5, CMD_REMOVE_RAILROAD_TRACK); } /* static */ bool ScriptRail::AreTilesConnected(TileIndex from, TileIndex tile, TileIndex to) @@ -288,16 +288,16 @@ static uint32 SimulateDrag(TileIndex from, TileIndex tile, TileIndex *to) int diag_offset = abs(abs((int)::TileX(*to) - (int)::TileX(tile)) - abs((int)::TileY(*to) - (int)::TileY(tile))); uint32 p2 = 0; if (::TileY(from) == ::TileY(*to)) { - p2 |= (TRACK_X << 4); + p2 |= (TRACK_X << 5); *to -= Clamp((int)::TileX(*to) - (int)::TileX(tile), -1, 1); } else if (::TileX(from) == ::TileX(*to)) { - p2 |= (TRACK_Y << 4); + p2 |= (TRACK_Y << 5); *to -= ::MapSizeX() * Clamp((int)::TileY(*to) - (int)::TileY(tile), -1, 1); } else if (::TileY(from) < ::TileY(tile)) { if (::TileX(*to) < ::TileX(tile)) { - p2 |= (TRACK_UPPER << 4); + p2 |= (TRACK_UPPER << 5); } else { - p2 |= (TRACK_LEFT << 4); + p2 |= (TRACK_LEFT << 5); } if (diag_offset != 0) { *to -= Clamp((int)::TileX(*to) - (int)::TileX(tile), -1, 1); @@ -306,9 +306,9 @@ static uint32 SimulateDrag(TileIndex from, TileIndex tile, TileIndex *to) } } else if (::TileY(from) > ::TileY(tile)) { if (::TileX(*to) < ::TileX(tile)) { - p2 |= (TRACK_RIGHT << 4); + p2 |= (TRACK_RIGHT << 5); } else { - p2 |= (TRACK_LOWER << 4); + p2 |= (TRACK_LOWER << 5); } if (diag_offset != 0) { *to -= Clamp((int)::TileX(*to) - (int)::TileX(tile), -1, 1); @@ -317,9 +317,9 @@ static uint32 SimulateDrag(TileIndex from, TileIndex tile, TileIndex *to) } } else if (::TileX(from) < ::TileX(tile)) { if (::TileY(*to) < ::TileY(tile)) { - p2 |= (TRACK_UPPER << 4); + p2 |= (TRACK_UPPER << 5); } else { - p2 |= (TRACK_RIGHT << 4); + p2 |= (TRACK_RIGHT << 5); } if (diag_offset == 0) { *to -= Clamp((int)::TileX(*to) - (int)::TileX(tile), -1, 1); @@ -328,9 +328,9 @@ static uint32 SimulateDrag(TileIndex from, TileIndex tile, TileIndex *to) } } else if (::TileX(from) > ::TileX(tile)) { if (::TileY(*to) < ::TileY(tile)) { - p2 |= (TRACK_LEFT << 4); + p2 |= (TRACK_LEFT << 5); } else { - p2 |= (TRACK_LOWER << 4); + p2 |= (TRACK_LOWER << 5); } if (diag_offset == 0) { *to -= Clamp((int)::TileX(*to) - (int)::TileX(tile), -1, 1); diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index affccab84d..3ae3571499 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -1190,8 +1190,8 @@ CommandCost FindJoiningWaypoint(StationID existing_waypoint, StationID waypoint_ * @param tile_org northern most position of station dragging/placement * @param flags operation to perform * @param p1 various bitstuffed elements - * - p1 = (bit 0- 3) - railtype - * - p1 = (bit 4) - orientation (Axis) + * - p1 = (bit 0- 4) - railtype + * - p1 = (bit 5) - orientation (Axis) * - p1 = (bit 8-15) - number of tracks * - p1 = (bit 16-23) - platform length * - p1 = (bit 24) - allow stations directly adjacent to other stations. @@ -1205,8 +1205,8 @@ CommandCost FindJoiningWaypoint(StationID existing_waypoint, StationID waypoint_ CommandCost CmdBuildRailStation(TileIndex tile_org, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) { /* Unpack parameters */ - RailType rt = Extract(p1); - Axis axis = Extract(p1); + RailType rt = Extract(p1); + Axis axis = Extract(p1); byte numtracks = GB(p1, 8, 8); byte plat_len = GB(p1, 16, 8); bool adjacent = HasBit(p1, 24); diff --git a/src/tunnel_map.h b/src/tunnel_map.h index e200a1275e..ec798587a4 100644 --- a/src/tunnel_map.h +++ b/src/tunnel_map.h @@ -75,7 +75,9 @@ static inline void MakeRailTunnel(TileIndex t, Owner o, DiagDirection d, RailTyp SetTileType(t, MP_TUNNELBRIDGE); SetTileOwner(t, o); _m[t].m2 = 0; - _m[t].m3 = r; + SB(_m[t].m1, 7, 1, GB(r, 4, 1)); + SB(_m[t].m3, 0, 4, GB(r, 0, 4)); + SB(_m[t].m3, 4, 4, 0); _m[t].m4 = 0; _m[t].m5 = TRANSPORT_RAIL << 2 | d; SB(_me[t].m6, 2, 4, 0); diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp index a2c671d814..0ba55b693e 100644 --- a/src/tunnelbridge_cmd.cpp +++ b/src/tunnelbridge_cmd.cpp @@ -248,7 +248,7 @@ CommandCost CheckBridgeAvailability(BridgeType bridge_type, uint bridge_len, DoC * @param p1 packed start tile coords (~ dx) * @param p2 various bitstuffed elements * - p2 = (bit 0- 7) - bridge type (hi bh) - * - p2 = (bit 8-11) - rail type or road types. + * - p2 = (bit 8-12) - rail type or road types. * - p2 = (bit 15-16) - transport type. * @param text unused * @return the cost of this operation or an error @@ -275,7 +275,7 @@ CommandCost CmdBuildBridge(TileIndex end_tile, DoCommandFlag flags, uint32 p1, u break; case TRANSPORT_RAIL: - railtype = Extract(p2); + railtype = Extract(p2); if (!ValParamRailtype(railtype)) return CMD_ERROR; break; @@ -590,7 +590,7 @@ CommandCost CmdBuildBridge(TileIndex end_tile, DoCommandFlag flags, uint32 p1, u * Build Tunnel. * @param start_tile start tile of tunnel * @param flags type of operation - * @param p1 bit 0-3 railtype or roadtypes + * @param p1 bit 0-4 railtype or roadtypes * bit 8-9 transport type * @param p2 unused * @param text unused @@ -607,7 +607,7 @@ CommandCost CmdBuildTunnel(TileIndex start_tile, DoCommandFlag flags, uint32 p1, _build_tunnel_endtile = 0; switch (transport_type) { case TRANSPORT_RAIL: - railtype = Extract(p1); + railtype = Extract(p1); if (!ValParamRailtype(railtype)) return CMD_ERROR; break;