mirror of https://github.com/OpenTTD/OpenTTD
(svn r22589) -Fix [FS#4641]: PBS order forecasting modified the current order index in case of a goto-nearest-depot order and no depot could be found.
parent
52a3842fe3
commit
f71a96d584
|
@ -1808,8 +1808,9 @@ VehicleOrderID ProcessConditionalOrder(const Order *order, const Vehicle *v)
|
||||||
* @param order the order the vehicle currently has
|
* @param order the order the vehicle currently has
|
||||||
* @param v the vehicle to update
|
* @param v the vehicle to update
|
||||||
* @param conditional_depth the depth (amount of steps) to go with conditional orders. This to prevent infinite loops.
|
* @param conditional_depth the depth (amount of steps) to go with conditional orders. This to prevent infinite loops.
|
||||||
|
* @param pbs_look_ahead Whether we are forecasting orders for pbs reservations in advance. If true, the order indices must not be modified.
|
||||||
*/
|
*/
|
||||||
bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth)
|
bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth, bool pbs_look_ahead)
|
||||||
{
|
{
|
||||||
if (conditional_depth > v->GetNumOrders()) return false;
|
if (conditional_depth > v->GetNumOrders()) return false;
|
||||||
|
|
||||||
|
@ -1820,6 +1821,7 @@ bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth)
|
||||||
|
|
||||||
case OT_GOTO_DEPOT:
|
case OT_GOTO_DEPOT:
|
||||||
if ((order->GetDepotOrderType() & ODTFB_SERVICE) && !v->NeedsServicing()) {
|
if ((order->GetDepotOrderType() & ODTFB_SERVICE) && !v->NeedsServicing()) {
|
||||||
|
assert(!pbs_look_ahead);
|
||||||
UpdateVehicleTimetable(v, true);
|
UpdateVehicleTimetable(v, true);
|
||||||
v->IncrementRealOrderIndex();
|
v->IncrementRealOrderIndex();
|
||||||
break;
|
break;
|
||||||
|
@ -1832,6 +1834,9 @@ bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth)
|
||||||
bool reverse;
|
bool reverse;
|
||||||
|
|
||||||
if (v->FindClosestDepot(&location, &destination, &reverse)) {
|
if (v->FindClosestDepot(&location, &destination, &reverse)) {
|
||||||
|
/* PBS reservations cannot reverse */
|
||||||
|
if (pbs_look_ahead && reverse) return false;
|
||||||
|
|
||||||
v->dest_tile = location;
|
v->dest_tile = location;
|
||||||
v->current_order.MakeGoToDepot(destination, v->current_order.GetDepotOrderType(), v->current_order.GetNonStopType(), (OrderDepotActionFlags)(v->current_order.GetDepotActionType() & ~ODATFB_NEAREST_DEPOT), v->current_order.GetRefitCargo(), v->current_order.GetRefitSubtype());
|
v->current_order.MakeGoToDepot(destination, v->current_order.GetDepotOrderType(), v->current_order.GetNonStopType(), (OrderDepotActionFlags)(v->current_order.GetDepotActionType() & ~ODATFB_NEAREST_DEPOT), v->current_order.GetRefitCargo(), v->current_order.GetRefitSubtype());
|
||||||
|
|
||||||
|
@ -1849,6 +1854,9 @@ bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* If there is no depot, we cannot help PBS either. */
|
||||||
|
if (pbs_look_ahead) return false;
|
||||||
|
|
||||||
UpdateVehicleTimetable(v, true);
|
UpdateVehicleTimetable(v, true);
|
||||||
v->IncrementRealOrderIndex();
|
v->IncrementRealOrderIndex();
|
||||||
} else {
|
} else {
|
||||||
|
@ -1864,6 +1872,7 @@ bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case OT_CONDITIONAL: {
|
case OT_CONDITIONAL: {
|
||||||
|
assert(!pbs_look_ahead);
|
||||||
VehicleOrderID next_order = ProcessConditionalOrder(order, v);
|
VehicleOrderID next_order = ProcessConditionalOrder(order, v);
|
||||||
if (next_order != INVALID_VEH_ORDER_ID) {
|
if (next_order != INVALID_VEH_ORDER_ID) {
|
||||||
/* Jump to next_order. cur_implicit_order_index becomes exactly that order,
|
/* Jump to next_order. cur_implicit_order_index becomes exactly that order,
|
||||||
|
@ -1908,7 +1917,7 @@ bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth)
|
||||||
}
|
}
|
||||||
|
|
||||||
v->current_order = *order;
|
v->current_order = *order;
|
||||||
return UpdateOrderDest(v, order, conditional_depth + 1);
|
return UpdateOrderDest(v, order, conditional_depth + 1, pbs_look_ahead);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -22,7 +22,7 @@ void InvalidateVehicleOrder(const Vehicle *v, int data);
|
||||||
void CheckOrders(const Vehicle*);
|
void CheckOrders(const Vehicle*);
|
||||||
void DeleteVehicleOrders(Vehicle *v, bool keep_orderlist = false, bool reset_order_indices = true);
|
void DeleteVehicleOrders(Vehicle *v, bool keep_orderlist = false, bool reset_order_indices = true);
|
||||||
bool ProcessOrders(Vehicle *v);
|
bool ProcessOrders(Vehicle *v);
|
||||||
bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth = 0);
|
bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth = 0, bool pbs_look_ahead = false);
|
||||||
VehicleOrderID ProcessConditionalOrder(const Order *order, const Vehicle *v);
|
VehicleOrderID ProcessConditionalOrder(const Order *order, const Vehicle *v);
|
||||||
|
|
||||||
void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int y, bool selected, bool timetable, int left, int middle, int right);
|
void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int y, bool selected, bool timetable, int left, int middle, int right);
|
||||||
|
|
|
@ -2340,8 +2340,7 @@ public:
|
||||||
case OT_GOTO_STATION:
|
case OT_GOTO_STATION:
|
||||||
case OT_GOTO_WAYPOINT:
|
case OT_GOTO_WAYPOINT:
|
||||||
this->v->current_order = *order;
|
this->v->current_order = *order;
|
||||||
UpdateOrderDest(this->v, order);
|
return UpdateOrderDest(this->v, order, 0, true);
|
||||||
return true;
|
|
||||||
case OT_CONDITIONAL: {
|
case OT_CONDITIONAL: {
|
||||||
if (conditional_depth > this->v->GetNumOrders()) return false;
|
if (conditional_depth > this->v->GetNumOrders()) return false;
|
||||||
VehicleOrderID next = ProcessConditionalOrder(order, this->v);
|
VehicleOrderID next = ProcessConditionalOrder(order, this->v);
|
||||||
|
|
Loading…
Reference in New Issue