From ad2bcaeae530b58b2415ffb9c8733d31dd1cfb82 Mon Sep 17 00:00:00 2001 From: rubidium Date: Mon, 30 Jun 2008 14:49:50 +0000 Subject: (svn r13662) -Fix [FS#2113]: crash when adding conditional orders to ships. --- src/order_cmd.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src') 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); } -- cgit v1.2.3-70-g09d2