summaryrefslogtreecommitdiff
path: root/src/ai
diff options
context:
space:
mode:
Diffstat (limited to 'src/ai')
-rw-r--r--src/ai/api/ai_changelog.hpp2
-rw-r--r--src/ai/api/ai_order.cpp11
-rw-r--r--src/ai/api/ai_order.hpp14
-rw-r--r--src/ai/api/ai_order.hpp.sq1
4 files changed, 26 insertions, 2 deletions
diff --git a/src/ai/api/ai_changelog.hpp b/src/ai/api/ai_changelog.hpp
index 03ba5dca4..b767778d9 100644
--- a/src/ai/api/ai_changelog.hpp
+++ b/src/ai/api/ai_changelog.hpp
@@ -24,6 +24,7 @@
* \li AIIndustry::GetIndustryID
* \li AIIndustryType::INDUSTRYTYPE_TOWN
* \li AIIndustryType::INDUSTRYTYPE_UNKNOWN
+ * \li AIOrder::IsVoidOrder
*
* API removals:
* \li HasNext for all lists.
@@ -34,6 +35,7 @@
* \li AIEngine::GetPower can be used for road vehicles.
* \li AIEngine::GetWeight can be used for road vehicles.
* \li AIEngine::GetMaxTractiveEffort can be used for road vehicles.
+ * \li AIOrder::GetOrderFlags returns AIOrder::AIOF_INVALID for void orders as well.
*
* \b 1.0.3
*
diff --git a/src/ai/api/ai_order.cpp b/src/ai/api/ai_order.cpp
index bf55cc504..370cff4f6 100644
--- a/src/ai/api/ai_order.cpp
+++ b/src/ai/api/ai_order.cpp
@@ -99,6 +99,15 @@ static const Order *ResolveOrder(VehicleID vehicle_id, AIOrder::OrderPosition or
return order->GetType() == OT_CONDITIONAL;
}
+/* static */ bool AIOrder::IsVoidOrder(VehicleID vehicle_id, OrderPosition order_position)
+{
+ if (order_position == ORDER_CURRENT) return false;
+ if (!IsValidVehicleOrder(vehicle_id, order_position)) return false;
+
+ const Order *order = Vehicle::Get(vehicle_id)->GetOrder(order_position);
+ return order->GetType() == OT_DUMMY;
+}
+
/* static */ bool AIOrder::IsCurrentOrderPartOfOrderList(VehicleID vehicle_id)
{
if (AIVehicle::IsValidVehicle(vehicle_id)) return false;
@@ -224,7 +233,7 @@ static const Order *ResolveOrder(VehicleID vehicle_id, AIOrder::OrderPosition or
if (!IsValidVehicleOrder(vehicle_id, order_position)) return AIOF_INVALID;
const Order *order = ::ResolveOrder(vehicle_id, order_position);
- if (order == NULL || order->GetType() == OT_CONDITIONAL) return AIOF_INVALID;
+ if (order == NULL || order->GetType() == OT_CONDITIONAL || order->GetType() == OT_DUMMY) return AIOF_INVALID;
AIOrderFlags order_flags = AIOF_NONE;
order_flags |= (AIOrderFlags)order->GetNonStopType();
diff --git a/src/ai/api/ai_order.hpp b/src/ai/api/ai_order.hpp
index 4bdd3f560..8f142f3a6 100644
--- a/src/ai/api/ai_order.hpp
+++ b/src/ai/api/ai_order.hpp
@@ -173,6 +173,18 @@ public:
static bool IsConditionalOrder(VehicleID vehicle_id, OrderPosition order_position);
/**
+ * Checks whether the given order is a void order.
+ * A void order is an order that used to be a goto station, depot or waypoint order but
+ * its destination got removed. In OpenTTD these orders as shown as "(Invalid Order)"
+ * in the order list of a vehicle.
+ * @param vehicle_id The vehicle to check.
+ * @param order_position The order index to check.
+ * @pre order_position != ORDER_CURRENT && IsValidVehicleOrder(vehicle_id, order_position).
+ * @return True if and only if the order is a void order.
+ */
+ static bool IsVoidOrder(VehicleID vehicle_id, OrderPosition order_position);
+
+ /**
* Checks whether the current order is part of the orderlist.
* @param vehicle_id The vehicle to check.
* @pre AIVehicle::IsValidVehicle(vehicle_id).
@@ -240,7 +252,7 @@ public:
* @param vehicle_id The vehicle to get the destination for.
* @param order_position The order to get the destination for.
* @pre IsValidVehicleOrder(vehicle_id, order_position).
- * @pre order_position == ORDER_CURRENT || !IsConditionalOrder(vehicle_id, order_position).
+ * @pre order_position == ORDER_CURRENT || (!IsConditionalOrder(vehicle_id, order_position) && !IsVoidOrder(vehicle_id, order_position)).
* @note Giving ORDER_CURRENT as order_position will give the order that is
* currently being executed by the vehicle. This is not necessarily the
* current order as given by ResolveOrderPosition (the current index in the
diff --git a/src/ai/api/ai_order.hpp.sq b/src/ai/api/ai_order.hpp.sq
index d79964e00..dff9d889f 100644
--- a/src/ai/api/ai_order.hpp.sq
+++ b/src/ai/api/ai_order.hpp.sq
@@ -94,6 +94,7 @@ void SQAIOrder_Register(Squirrel *engine)
SQAIOrder.DefSQStaticMethod(engine, &AIOrder::IsGotoDepotOrder, "IsGotoDepotOrder", 3, ".ii");
SQAIOrder.DefSQStaticMethod(engine, &AIOrder::IsGotoWaypointOrder, "IsGotoWaypointOrder", 3, ".ii");
SQAIOrder.DefSQStaticMethod(engine, &AIOrder::IsConditionalOrder, "IsConditionalOrder", 3, ".ii");
+ SQAIOrder.DefSQStaticMethod(engine, &AIOrder::IsVoidOrder, "IsVoidOrder", 3, ".ii");
SQAIOrder.DefSQStaticMethod(engine, &AIOrder::IsCurrentOrderPartOfOrderList, "IsCurrentOrderPartOfOrderList", 2, ".i");
SQAIOrder.DefSQStaticMethod(engine, &AIOrder::ResolveOrderPosition, "ResolveOrderPosition", 3, ".ii");
SQAIOrder.DefSQStaticMethod(engine, &AIOrder::AreOrderFlagsValid, "AreOrderFlagsValid", 3, ".ii");