summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/order_cmd.cpp17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp
index 4b5962411..b8bc5dd64 100644
--- a/src/order_cmd.cpp
+++ b/src/order_cmd.cpp
@@ -298,6 +298,18 @@ static TileIndex GetOrderLocation(const Order& o)
}
}
+static uint GetOrderDistance(const Order *prev, const Order *cur, const Vehicle *v, int conditional_depth = 0)
+{
+ if (cur->IsType(OT_CONDITIONAL)) {
+ if (conditional_depth > v->num_orders) return 0;
+
+ conditional_depth++;
+ return max(GetOrderDistance(prev, &v->orders[cur->GetConditionSkipToOrder()], v, conditional_depth),
+ GetOrderDistance(prev, (prev + 1 == &v->orders[v->num_orders]) ? v->orders : (prev + 1), v, conditional_depth));
+ }
+
+ return DistanceManhattan(GetOrderLocation(*prev), GetOrderLocation(*cur));
+}
/** Add an order to the orderlist of a vehicle.
* @param tile unused
@@ -468,10 +480,7 @@ CommandCost CmdInsertOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
if (++n == sel_ord && prev != NULL) break;
}
if (prev != NULL) {
- uint dist = DistanceManhattan(
- GetOrderLocation(*prev),
- GetOrderLocation(new_order)
- );
+ uint dist = GetOrderDistance(prev, &new_order, v);
if (dist >= 130) {
return_cmd_error(STR_0210_TOO_FAR_FROM_PREVIOUS_DESTINATIO);
}