Mercurial > hg > openttd
changeset 15722:3d1ca3435ebb draft
(svn r20389) [NoAI] -Add: AIOrder::IsVoidOrder to find void "(Invalid Order)" orders.
[NoAI] -Change: AIOrder::GetOrderFlags returns AIOrder::AIOF_INVALID for void orders.
author | rubidium <rubidium@openttd.org> |
---|---|
date | Fri, 06 Aug 2010 19:04:21 +0000 |
parents | 75a90c79d66d |
children | e4e81e86026e |
files | src/ai/api/ai_changelog.hpp src/ai/api/ai_order.cpp src/ai/api/ai_order.hpp src/ai/api/ai_order.hpp.sq |
diffstat | 4 files changed, 26 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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 *
--- a/src/ai/api/ai_order.cpp +++ b/src/ai/api/ai_order.cpp @@ -99,6 +99,15 @@ 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 @@ 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();
--- a/src/ai/api/ai_order.hpp +++ b/src/ai/api/ai_order.hpp @@ -173,6 +173,18 @@ 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 @@ * @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
--- a/src/ai/api/ai_order.hpp.sq +++ b/src/ai/api/ai_order.hpp.sq @@ -94,6 +94,7 @@ 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");