From 90a35d2e5b3728a8cd7fe1717d6c940b525cca9e Mon Sep 17 00:00:00 2001 From: rubidium Date: Fri, 6 Aug 2010 19:04:21 +0000 Subject: [PATCH] (svn r20389) [NoAI] -Add: AIOrder::IsVoidOrder to find void "(Invalid Order)" orders. [NoAI] -Change: AIOrder::GetOrderFlags returns AIOrder::AIOF_INVALID for void orders. --- src/ai/api/ai_changelog.hpp | 2 ++ src/ai/api/ai_order.cpp | 11 ++++++++++- src/ai/api/ai_order.hpp | 14 +++++++++++++- src/ai/api/ai_order.hpp.sq | 1 + 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/ai/api/ai_changelog.hpp b/src/ai/api/ai_changelog.hpp index 03ba5dca47..b767778d9e 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 bf55cc504c..370cff4f6c 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 4bdd3f5607..8f142f3a65 100644 --- a/src/ai/api/ai_order.hpp +++ b/src/ai/api/ai_order.hpp @@ -172,6 +172,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. @@ -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 d79964e00c..dff9d889fe 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");