mirror of https://github.com/OpenTTD/OpenTTD
Fix 0455627d16: Incorrect script order position mapping. (#14294)
parent
180ec6505b
commit
b42abfbefc
|
@ -89,17 +89,10 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
|
||||||
|
|
||||||
assert(ScriptOrder::IsValidVehicleOrder(vehicle_id, order_position));
|
assert(ScriptOrder::IsValidVehicleOrder(vehicle_id, order_position));
|
||||||
|
|
||||||
int pos = (int)order_position;
|
auto orders = v->Orders();
|
||||||
int res = (int)order_position;
|
auto real_orders = orders | std::views::filter([](const Order &order) { return !order.IsType(OT_IMPLICIT); });
|
||||||
for (const Order &order : v->Orders()) {
|
auto it = std::ranges::next(std::begin(real_orders), order_position, std::end(real_orders));
|
||||||
if (order.IsType(OT_IMPLICIT)) {
|
return static_cast<int>(std::distance(std::begin(orders), it.base()));
|
||||||
++res;
|
|
||||||
} else {
|
|
||||||
if (pos == 0) break;
|
|
||||||
--pos;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -111,18 +104,11 @@ static ScriptOrder::OrderPosition RealOrderPositionToScriptOrderPosition(Vehicle
|
||||||
{
|
{
|
||||||
const Vehicle *v = ::Vehicle::Get(vehicle_id);
|
const Vehicle *v = ::Vehicle::Get(vehicle_id);
|
||||||
|
|
||||||
int num_implicit_orders = 0;
|
auto orders = v->Orders();
|
||||||
int pos = order_position;
|
auto first = std::begin(orders);
|
||||||
for (const Order &order : v->Orders()) {
|
auto last = std::ranges::next(first, order_position, std::end(orders));
|
||||||
if (order.IsType(OT_IMPLICIT)) {
|
int num_implicit = static_cast<int>(std::count_if(first, last, [](const Order &order) { return order.IsType(OT_IMPLICIT); }));
|
||||||
++num_implicit_orders;
|
return static_cast<ScriptOrder::OrderPosition>(order_position - num_implicit);
|
||||||
} else {
|
|
||||||
if (pos == 0) break;
|
|
||||||
--pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
return static_cast<ScriptOrder::OrderPosition>(order_position - num_implicit_orders);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ bool ScriptOrder::IsGotoStationOrder(VehicleID vehicle_id, OrderPosition order_position)
|
/* static */ bool ScriptOrder::IsGotoStationOrder(VehicleID vehicle_id, OrderPosition order_position)
|
||||||
|
|
Loading…
Reference in New Issue