summaryrefslogtreecommitdiff
path: root/src/script/api
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2013-12-08 15:13:06 +0000
committerfrosch <frosch@openttd.org>2013-12-08 15:13:06 +0000
commit2e79fd9c4015a1777f52431b524f02aa1ce82a15 (patch)
tree7a2d1ef113f9d9cdee09d038506f09ef51d808c7 /src/script/api
parentf317d0146ed1ded3a32facc5ea9fac247f9a92d4 (diff)
downloadopenttd-2e79fd9c4015a1777f52431b524f02aa1ce82a15.tar.xz
(svn r26148) -Fix [FS#5824] (r25735): Script API failed for vehicles with only implicit orders.
Diffstat (limited to 'src/script/api')
-rw-r--r--src/script/api/script_order.cpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/script/api/script_order.cpp b/src/script/api/script_order.cpp
index 3087caa65..3098b452f 100644
--- a/src/script/api/script_order.cpp
+++ b/src/script/api/script_order.cpp
@@ -66,7 +66,7 @@ static const Order *ResolveOrder(VehicleID vehicle_id, ScriptOrder::OrderPositio
order_position = ScriptOrder::ResolveOrderPosition(vehicle_id, order_position);
if (order_position == ScriptOrder::ORDER_INVALID) return NULL;
}
- const Order *order = v->orders.list->GetFirstOrder();
+ const Order *order = v->GetFirstOrder();
while (order->GetType() == OT_IMPLICIT) order = order->next;
while (order_position > 0) {
order_position = (ScriptOrder::OrderPosition)(order_position - 1);
@@ -165,18 +165,22 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
{
if (!ScriptVehicle::IsValidVehicle(vehicle_id)) return ORDER_INVALID;
+ int num_manual_orders = ::Vehicle::Get(vehicle_id)->GetNumManualOrders();
+ if (num_manual_orders == 0) return ORDER_INVALID;
+
if (order_position == ORDER_CURRENT) {
int cur_order_pos = ::Vehicle::Get(vehicle_id)->cur_real_order_index;
- const Order *order = ::Vehicle::Get(vehicle_id)->GetOrder(0);
- if (order == NULL) return ORDER_INVALID;
+ const Order *order = ::Vehicle::Get(vehicle_id)->GetFirstOrder();
int num_implicit_orders = 0;
for (int i = 0; i < cur_order_pos; i++) {
if (order->GetType() == OT_IMPLICIT) num_implicit_orders++;
order = order->next;
}
- return (ScriptOrder::OrderPosition)(cur_order_pos - num_implicit_orders);
+ int real_order_pos = cur_order_pos - num_implicit_orders;
+ assert(real_order_pos < num_manual_orders);
+ return (ScriptOrder::OrderPosition)real_order_pos;
}
- return (order_position >= 0 && order_position < ::Vehicle::Get(vehicle_id)->GetNumManualOrders()) ? order_position : ORDER_INVALID;
+ return (order_position >= 0 && order_position < num_manual_orders) ? order_position : ORDER_INVALID;
}