diff --git a/src/roadveh.h b/src/roadveh.h index faaadab355..a76d19f5fe 100644 --- a/src/roadveh.h +++ b/src/roadveh.h @@ -42,6 +42,7 @@ enum RoadVehicleStates { /* Bit numbers */ RVS_USING_SECOND_BAY = 1, ///< Only used while in a road stop + RVS_ENTERED_STOP = 2, ///< Only set when a vehicle has entered the stop RVS_DRIVE_SIDE = 4, ///< Only used when retrieving move data RVS_IN_ROAD_STOP = 5, ///< The vehicle is in a road stop RVS_IN_DT_ROAD_STOP = 6, ///< The vehicle is in a drive-through road stop diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp index c1ad847dca..3889e2fa98 100644 --- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -933,13 +933,6 @@ struct RoadDriveEntry { #include "table/roadveh_movement.h" -static const byte _road_veh_data_1[] = { - 20, 20, 16, 16, 0, 0, 0, 0, - 19, 19, 15, 15, 0, 0, 0, 0, - 16, 16, 12, 12, 0, 0, 0, 0, - 15, 15, 11, 11 -}; - static bool RoadVehLeaveDepot(RoadVehicle *v, bool first) { /* Don't leave if not all the wagons are in the depot. */ @@ -1382,7 +1375,7 @@ again: * (the station test and stop type test ensure that other vehicles, using the road stop as * a through route, do not stop) */ if (v->IsRoadVehFront() && ((IsInsideMM(v->state, RVSB_IN_ROAD_STOP, RVSB_IN_ROAD_STOP_END) && - _road_veh_data_1[v->state - RVSB_IN_ROAD_STOP + (_settings_game.vehicle.road_side << RVS_DRIVE_SIDE)] == v->frame) || + _road_stop_stop_frame[v->state - RVSB_IN_ROAD_STOP + (_settings_game.vehicle.road_side << RVS_DRIVE_SIDE)] == v->frame) || (IsInsideMM(v->state, RVSB_IN_DT_ROAD_STOP, RVSB_IN_DT_ROAD_STOP_END) && v->current_order.ShouldStopAtStation(v, GetStationIndex(v->tile)) && v->owner == GetTileOwner(v->tile) && @@ -1395,7 +1388,7 @@ again: /* Vehicle is at the stop position (at a bay) in a road stop. * Note, if vehicle is loading/unloading it has already been handled, * so if we get here the vehicle has just arrived or is just ready to leave. */ - if (!v->current_order.IsType(OT_LEAVESTATION)) { + if (!HasBit(v->state, RVS_ENTERED_STOP)) { /* Vehicle has arrived at a bay in a road stop */ if (IsDriveThroughStopTile(v->tile)) { @@ -1412,6 +1405,7 @@ again: } rs->SetEntranceBusy(false); + SetBit(v->state, RVS_ENTERED_STOP); v->last_station_visited = st->index; @@ -1427,7 +1421,7 @@ again: v->cur_speed = 0; return false; } - v->current_order.Free(); + if (v->current_order.IsType(OT_LEAVESTATION)) v->current_order.Free(); } if (IsStandardRoadStopTile(v->tile)) rs->SetEntranceBusy(true); diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index 7ed394d202..1b5b437aad 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -2377,6 +2377,19 @@ bool AfterLoadGame() } } + if (CheckSavegameVersion(153)) { + RoadVehicle *rv; + FOR_ALL_ROADVEHICLES(rv) { + bool loading = rv->current_order.IsType(OT_LOADING) || rv->current_order.IsType(OT_LEAVESTATION); + if (HasBit(rv->state, RVS_IN_ROAD_STOP)) { + extern const byte _road_stop_stop_frame[]; + SB(rv->state, RVS_ENTERED_STOP, 1, loading || rv->frame > _road_stop_stop_frame[rv->state - RVSB_IN_ROAD_STOP + (_settings_game.vehicle.road_side << RVS_DRIVE_SIDE)]); + } else if (HasBit(rv->state, RVS_IN_DT_ROAD_STOP)) { + SB(rv->state, RVS_ENTERED_STOP, 1, loading || rv->frame > RVC_DRIVE_THROUGH_STOP_FRAME); + } + } + } + /* Road stops is 'only' updating some caches */ AfterLoadRoadStops(); AfterLoadLabelMaps(); diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp index ba7819a55b..c84d69bfc9 100644 --- a/src/saveload/saveload.cpp +++ b/src/saveload/saveload.cpp @@ -215,8 +215,9 @@ * 150 20857 * 151 20918 * 152 21171 + * 153 21263 */ -extern const uint16 SAVEGAME_VERSION = 152; ///< Current savegame version of OpenTTD. +extern const uint16 SAVEGAME_VERSION = 153; ///< Current savegame version of OpenTTD. SavegameType _savegame_type; ///< type of savegame we are loading diff --git a/src/table/roadveh_movement.h b/src/table/roadveh_movement.h index e47970f24c..5b202b2b59 100644 --- a/src/table/roadveh_movement.h +++ b/src/table/roadveh_movement.h @@ -1055,34 +1055,43 @@ static const RoadDriveEntry * const _road_road_drive_data[] = { _rv_station_left_nw_far, _rv_station_left_sw_near, _rv_station_left_nw_near, - NULL, - NULL, - NULL, - NULL, + _rv_station_left_sw_far, + _rv_station_left_nw_far, + _rv_station_left_sw_near, + _rv_station_left_nw_near, + _rv_station_left_ne_far, + _rv_station_left_se_far, + _rv_station_left_ne_near, + _rv_station_left_se_near, _rv_station_left_ne_far, _rv_station_left_se_far, _rv_station_left_ne_near, _rv_station_left_se_near, - NULL, - NULL, - NULL, - NULL, _rv_station_right_sw_far, _rv_station_right_nw_far, _rv_station_right_sw_near, _rv_station_right_nw_near, - NULL, - NULL, - NULL, - NULL, + _rv_station_right_sw_far, + _rv_station_right_nw_far, + _rv_station_right_sw_near, + _rv_station_right_nw_near, _rv_station_right_ne_far, _rv_station_right_se_far, _rv_station_right_ne_near, _rv_station_right_se_near, - NULL, - NULL, - NULL, - NULL, + _rv_station_right_ne_far, + _rv_station_right_se_far, + _rv_station_right_ne_near, + _rv_station_right_se_near, +}; + +/** Table of road stop stop frames, when to stop at a road stop. */ +extern const byte _road_stop_stop_frame[] = { + /* Duplicated left and right because of "entered stop" bit */ + 20, 20, 16, 16, 20, 20, 16, 16, + 19, 19, 15, 15, 19, 19, 15, 15, + 16, 16, 12, 12, 16, 16, 12, 12, + 15, 15, 11, 11, 15, 15, 11, 11 }; static const RoadDriveEntry _roadveh_tram_turn_ne_0[] = {