summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2008-06-30 14:49:50 +0000
committerrubidium <rubidium@openttd.org>2008-06-30 14:49:50 +0000
commit7ed892411a29ae3cabd7834add886cf7628b914b (patch)
treeaee8470aa970534b6831cc181b7899ea4ace5d5f /src
parent6a216ee4f6b2ca9508ee96b48357a75746bff53d (diff)
downloadopenttd-7ed892411a29ae3cabd7834add886cf7628b914b.tar.xz
(svn r13662) -Fix [FS#2113]: crash when adding conditional orders to ships.
Diffstat (limited to 'src')
-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);
}