Merge branch 'master' into jgrpp
# Conflicts: # src/depot_type.h # src/lang/german.txt # src/order_gui.cpp # src/pathfinder/yapf/yapf_rail.cpp # src/script/api/script_window.hpp.in # src/settings_table.cpp # src/train_cmd.cpp
This commit is contained in:
@@ -3723,13 +3723,16 @@ static const byte _initial_tile_subcoord[6][4][3] = {
|
||||
* @param[out] path_found Whether a path has been found or not.
|
||||
* @param do_track_reservation Path reservation is requested
|
||||
* @param[out] dest State and destination of the requested path
|
||||
* @param[out] final_dest Final tile of the best path found
|
||||
* @return The best track the train should follow
|
||||
*/
|
||||
static Track DoTrainPathfind(const Train *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool &path_found, bool do_track_reservation, PBSTileInfo *dest)
|
||||
static Track DoTrainPathfind(const Train *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool &path_found, bool do_track_reservation, PBSTileInfo *dest, TileIndex *final_dest)
|
||||
{
|
||||
if (final_dest != nullptr) *final_dest = INVALID_TILE;
|
||||
|
||||
switch (_settings_game.pf.pathfinder_for_trains) {
|
||||
case VPF_NPF: return NPFTrainChooseTrack(v, path_found, do_track_reservation, dest);
|
||||
case VPF_YAPF: return YapfTrainChooseTrack(v, tile, enterdir, tracks, path_found, do_track_reservation, dest);
|
||||
case VPF_YAPF: return YapfTrainChooseTrack(v, tile, enterdir, tracks, path_found, do_track_reservation, dest, final_dest);
|
||||
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
@@ -3868,6 +3871,7 @@ private:
|
||||
VehicleOrderID old_tt_index;
|
||||
bool suppress_implicit_orders;
|
||||
bool clear_saved_order_ptr;
|
||||
bool restored;
|
||||
|
||||
public:
|
||||
VehicleOrderSaver(Train *_v) :
|
||||
@@ -3878,7 +3882,8 @@ public:
|
||||
old_index(_v->cur_real_order_index),
|
||||
old_impl_index(_v->cur_implicit_order_index),
|
||||
old_tt_index(_v->cur_timetable_order_index),
|
||||
suppress_implicit_orders(HasBit(_v->gv_flags, GVF_SUPPRESS_IMPLICIT_ORDERS))
|
||||
suppress_implicit_orders(HasBit(_v->gv_flags, GVF_SUPPRESS_IMPLICIT_ORDERS)),
|
||||
restored(false)
|
||||
{
|
||||
if (_choose_train_track_saved_current_order == nullptr) {
|
||||
_choose_train_track_saved_current_order = &(this->old_order);
|
||||
@@ -3888,7 +3893,10 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
~VehicleOrderSaver()
|
||||
/**
|
||||
* Restore the saved order to the vehicle.
|
||||
*/
|
||||
void Restore()
|
||||
{
|
||||
this->v->current_order = std::move(this->old_order);
|
||||
this->v->dest_tile = this->old_dest_tile;
|
||||
@@ -3898,6 +3906,15 @@ public:
|
||||
this->v->cur_timetable_order_index = this->old_tt_index;
|
||||
SB(this->v->gv_flags, GVF_SUPPRESS_IMPLICIT_ORDERS, 1, suppress_implicit_orders ? 1: 0);
|
||||
if (this->clear_saved_order_ptr) _choose_train_track_saved_current_order = nullptr;
|
||||
this->restored = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore the saved order to the vehicle, if Restore() has not already been called.
|
||||
*/
|
||||
~VehicleOrderSaver()
|
||||
{
|
||||
if (!this->restored) this->Restore();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -4230,6 +4247,7 @@ static Track ChooseTrainTrack(Train *v, TileIndex tile, DiagDirection enterdir,
|
||||
Track best_track = INVALID_TRACK;
|
||||
bool do_track_reservation = _settings_game.pf.reserve_paths || (flags & CTTF_FORCE_RES);
|
||||
Trackdir changed_signal = INVALID_TRACKDIR;
|
||||
TileIndex final_dest = INVALID_TILE;
|
||||
|
||||
dbg_assert((tracks & ~TRACK_BIT_MASK) == 0);
|
||||
|
||||
@@ -4343,7 +4361,7 @@ static Track ChooseTrainTrack(Train *v, TileIndex tile, DiagDirection enterdir,
|
||||
bool path_found = true;
|
||||
TileIndex new_tile = res_dest.tile;
|
||||
|
||||
Track next_track = DoTrainPathfind(v, new_tile, dest_enterdir, tracks, path_found, do_track_reservation, &res_dest);
|
||||
Track next_track = DoTrainPathfind(v, new_tile, dest_enterdir, tracks, path_found, do_track_reservation, &res_dest, &final_dest);
|
||||
DEBUG_UPDATESTATECHECKSUM("ChooseTrainTrack: v: %u, path_found: %d, next_track: %d", v->index, path_found, next_track);
|
||||
UpdateStateChecksum((((uint64) v->index) << 32) | (path_found << 16) | next_track);
|
||||
if (new_tile == tile) best_track = next_track;
|
||||
@@ -4410,7 +4428,7 @@ static Track ChooseTrainTrack(Train *v, TileIndex tile, DiagDirection enterdir,
|
||||
if (orders.SwitchToNextOrder(true)) {
|
||||
PBSTileInfo cur_dest;
|
||||
bool path_found;
|
||||
DoTrainPathfind(v, next_tile, exitdir, reachable, path_found, true, &cur_dest);
|
||||
DoTrainPathfind(v, next_tile, exitdir, reachable, path_found, true, &cur_dest, nullptr);
|
||||
if (cur_dest.tile != INVALID_TILE) {
|
||||
res_dest = cur_dest;
|
||||
if (res_dest.okay) {
|
||||
@@ -4454,6 +4472,15 @@ static Track ChooseTrainTrack(Train *v, TileIndex tile, DiagDirection enterdir,
|
||||
if (changed_signal != INVALID_TRACKDIR) MarkSingleSignalDirty(tile, changed_signal);
|
||||
if (p_got_reservation != nullptr) *p_got_reservation = got_reservation;
|
||||
|
||||
orders.Restore();
|
||||
if (v->current_order.IsType(OT_GOTO_DEPOT) &&
|
||||
(v->current_order.GetDepotActionType() & ODATFB_NEAREST_DEPOT) &&
|
||||
final_dest != INVALID_TILE && IsRailDepotTile(final_dest)) {
|
||||
v->current_order.SetDestination(GetDepotIndex(final_dest));
|
||||
v->dest_tile = final_dest;
|
||||
SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP);
|
||||
}
|
||||
|
||||
return best_track;
|
||||
}
|
||||
|
||||
@@ -6675,7 +6702,7 @@ static void CheckIfTrainNeedsService(Train *v)
|
||||
}
|
||||
|
||||
SetBit(v->gv_flags, GVF_SUPPRESS_IMPLICIT_ORDERS);
|
||||
v->current_order.MakeGoToDepot(depot, ODTFB_SERVICE);
|
||||
v->current_order.MakeGoToDepot(depot, ODTFB_SERVICE, ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS, ODATFB_NEAREST_DEPOT);
|
||||
v->dest_tile = tfdd.tile;
|
||||
SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, WID_VV_START_STOP);
|
||||
|
||||
|
Reference in New Issue
Block a user