Index: src/order.h =================================================================== --- src/order.h (revision 8787) +++ src/order.h (working copy) @@ -199,6 +199,7 @@ bool IsOrderListShared(const Vehicle *v); void AssignOrder(Order *order, Order data); bool CheckForValidOrders(const Vehicle* v); +TileIndex GetOrderDestinationTile(const Order *o); Order UnpackOldOrder(uint16 packed); Index: src/order_cmd.cpp =================================================================== --- src/order_cmd.cpp (revision 8787) +++ src/order_cmd.cpp (working copy) @@ -346,15 +346,18 @@ /* For ships, make sure that the station is not too far away from the * previous destination, for human players with new pathfinding disabled */ if (v->type == VEH_Ship && IsHumanPlayer(v->owner) && - sel_ord != 0 && GetVehicleOrder(v, sel_ord - 1)->type == OT_GOTO_STATION - && !_patches.new_pathfinding_all) { + sel_ord != 0 && !_patches.new_pathfinding_all) { - int dist = DistanceManhattan( - GetStation(GetVehicleOrder(v, sel_ord - 1)->dest)->xy, - GetStation(new_order.dest)->xy // XXX type != OT_GOTO_STATION? - ); - if (dist >= 130) - return_cmd_error(STR_0210_TOO_FAR_FROM_PREVIOUS_DESTINATIO); + TileIndex t1 = GetOrderDestinationTile(GetVehicleOrder(v, sel_ord - 1)); + TileIndex t2 = GetOrderDestinationTile(&new_order); + + //t1 & t2 should not be invalid, but just in-case the types of orders are changed + //don't crash just assume that the user knows what they are doing. If the ship can't + //find its destination the user should get an alert. + if (t1 != INVALID_TILE && t2 != INVALID_TILE) { + if (DistanceManhattan(t1, t2) >= 130) + return_cmd_error(STR_0210_TOO_FAR_FROM_PREVIOUS_DESTINATIO); + } } if (flags & DC_EXEC) { @@ -1178,6 +1181,27 @@ return false; } +/** + * + * Gets the TileIndex for an order's destination. + * + * Only supports orders of type OT_GOTO_* + * + * @return TileIndex of the destination, or INVALID_TILE if order type was unrecognised. + */ +TileIndex GetOrderDestinationTile(const Order *o) { + switch(o->type) { + case OT_GOTO_STATION: + return GetStation(o->dest)->xy; + case OT_GOTO_DEPOT: + return GetDepot(o->dest)->xy; + case OT_GOTO_WAYPOINT: + return GetWaypoint(o->dest)->xy; + default: + return INVALID_TILE; + } +} + void InitializeOrders(void) { CleanPool(&_Order_pool);