|
@@ -704,25 +704,25 @@ TileIndex Order::GetLocation(const Vehic
|
|
|
* @param conditional_depth Internal param for resolving conditional orders.
|
|
|
* @return Maximum distance between the two orders.
|
|
|
*/
|
|
|
uint GetOrderDistance(const Order *prev, const Order *cur, const Vehicle *v, int conditional_depth)
|
|
|
{
|
|
|
if (cur->IsType(OT_CONDITIONAL)) {
|
|
|
if (conditional_depth > v->GetNumOrders()) return 0;
|
|
|
|
|
|
conditional_depth++;
|
|
|
|
|
|
int dist1 = GetOrderDistance(prev, v->GetOrder(cur->GetConditionSkipToOrder()), v, conditional_depth);
|
|
|
int dist2 = GetOrderDistance(prev, cur->next == nullptr ? v->orders.list->GetFirstOrder() : cur->next, v, conditional_depth);
|
|
|
return max(dist1, dist2);
|
|
|
return std::max(dist1, dist2);
|
|
|
}
|
|
|
|
|
|
TileIndex prev_tile = prev->GetLocation(v, true);
|
|
|
TileIndex cur_tile = cur->GetLocation(v, true);
|
|
|
if (prev_tile == INVALID_TILE || cur_tile == INVALID_TILE) return 0;
|
|
|
return v->type == VEH_AIRCRAFT ? DistanceSquare(prev_tile, cur_tile) : DistanceManhattan(prev_tile, cur_tile);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Add an order to the orderlist of a vehicle.
|
|
|
* @param tile unused
|
|
|
* @param flags operation to perform
|
|
@@ -1084,25 +1084,25 @@ void DeleteOrder(Vehicle *v, VehicleOrde
|
|
|
}
|
|
|
|
|
|
/* Update any possible open window of the vehicle */
|
|
|
InvalidateVehicleOrder(u, sel_ord | (INVALID_VEH_ORDER_ID << 8));
|
|
|
}
|
|
|
|
|
|
/* As we delete an order, the order to skip to will be 'wrong'. */
|
|
|
VehicleOrderID cur_order_id = 0;
|
|
|
for (Order *order : v->Orders()) {
|
|
|
if (order->IsType(OT_CONDITIONAL)) {
|
|
|
VehicleOrderID order_id = order->GetConditionSkipToOrder();
|
|
|
if (order_id >= sel_ord) {
|
|
|
order_id = max(order_id - 1, 0);
|
|
|
order_id = std::max(order_id - 1, 0);
|
|
|
}
|
|
|
if (order_id == cur_order_id) {
|
|
|
order_id = (order_id + 1) % v->GetNumOrders();
|
|
|
}
|
|
|
order->SetConditionSkipToOrder(order_id);
|
|
|
}
|
|
|
cur_order_id++;
|
|
|
}
|
|
|
|
|
|
InvalidateWindowClassesData(GetWindowClassForVehicleType(v->type), 0);
|
|
|
}
|
|
|
|
|
@@ -1976,25 +1976,25 @@ VehicleOrderID ProcessConditionalOrder(c
|
|
|
bool skip_order = false;
|
|
|
OrderConditionComparator occ = order->GetConditionComparator();
|
|
|
uint16 value = order->GetConditionValue();
|
|
|
|
|
|
switch (order->GetConditionVariable()) {
|
|
|
case OCV_LOAD_PERCENTAGE: skip_order = OrderConditionCompare(occ, CalcPercentVehicleFilled(v, nullptr), value); break;
|
|
|
case OCV_RELIABILITY: skip_order = OrderConditionCompare(occ, ToPercent16(v->reliability), value); break;
|
|
|
case OCV_MAX_RELIABILITY: skip_order = OrderConditionCompare(occ, ToPercent16(v->GetEngine()->reliability), value); break;
|
|
|
case OCV_MAX_SPEED: skip_order = OrderConditionCompare(occ, v->GetDisplayMaxSpeed() * 10 / 16, value); break;
|
|
|
case OCV_AGE: skip_order = OrderConditionCompare(occ, v->age / DAYS_IN_LEAP_YEAR, value); break;
|
|
|
case OCV_REQUIRES_SERVICE: skip_order = OrderConditionCompare(occ, v->NeedsServicing(), value); break;
|
|
|
case OCV_UNCONDITIONALLY: skip_order = true; break;
|
|
|
case OCV_REMAINING_LIFETIME: skip_order = OrderConditionCompare(occ, max(v->max_age - v->age + DAYS_IN_LEAP_YEAR - 1, 0) / DAYS_IN_LEAP_YEAR, value); break;
|
|
|
case OCV_REMAINING_LIFETIME: skip_order = OrderConditionCompare(occ, std::max(v->max_age - v->age + DAYS_IN_LEAP_YEAR - 1, 0) / DAYS_IN_LEAP_YEAR, value); break;
|
|
|
default: NOT_REACHED();
|
|
|
}
|
|
|
|
|
|
return skip_order ? order->GetConditionSkipToOrder() : (VehicleOrderID)INVALID_VEH_ORDER_ID;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Update the vehicle's destination tile from an order.
|
|
|
* @param order the order the vehicle currently has
|
|
|
* @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 pbs_look_ahead Whether we are forecasting orders for pbs reservations in advance. If true, the order indices must not be modified.
|