mirror of https://github.com/OpenTTD/OpenTTD
(svn r20389) [NoAI] -Add: AIOrder::IsVoidOrder to find void "(Invalid Order)" orders.
[NoAI] -Change: AIOrder::GetOrderFlags returns AIOrder::AIOF_INVALID for void orders.release/1.1
parent
d54f2ba21f
commit
90a35d2e5b
|
@ -24,6 +24,7 @@
|
||||||
* \li AIIndustry::GetIndustryID
|
* \li AIIndustry::GetIndustryID
|
||||||
* \li AIIndustryType::INDUSTRYTYPE_TOWN
|
* \li AIIndustryType::INDUSTRYTYPE_TOWN
|
||||||
* \li AIIndustryType::INDUSTRYTYPE_UNKNOWN
|
* \li AIIndustryType::INDUSTRYTYPE_UNKNOWN
|
||||||
|
* \li AIOrder::IsVoidOrder
|
||||||
*
|
*
|
||||||
* API removals:
|
* API removals:
|
||||||
* \li HasNext for all lists.
|
* \li HasNext for all lists.
|
||||||
|
@ -34,6 +35,7 @@
|
||||||
* \li AIEngine::GetPower can be used for road vehicles.
|
* \li AIEngine::GetPower can be used for road vehicles.
|
||||||
* \li AIEngine::GetWeight 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 AIEngine::GetMaxTractiveEffort can be used for road vehicles.
|
||||||
|
* \li AIOrder::GetOrderFlags returns AIOrder::AIOF_INVALID for void orders as well.
|
||||||
*
|
*
|
||||||
* \b 1.0.3
|
* \b 1.0.3
|
||||||
*
|
*
|
||||||
|
|
|
@ -99,6 +99,15 @@ static const Order *ResolveOrder(VehicleID vehicle_id, AIOrder::OrderPosition or
|
||||||
return order->GetType() == OT_CONDITIONAL;
|
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)
|
/* static */ bool AIOrder::IsCurrentOrderPartOfOrderList(VehicleID vehicle_id)
|
||||||
{
|
{
|
||||||
if (AIVehicle::IsValidVehicle(vehicle_id)) return false;
|
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;
|
if (!IsValidVehicleOrder(vehicle_id, order_position)) return AIOF_INVALID;
|
||||||
|
|
||||||
const Order *order = ::ResolveOrder(vehicle_id, order_position);
|
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;
|
AIOrderFlags order_flags = AIOF_NONE;
|
||||||
order_flags |= (AIOrderFlags)order->GetNonStopType();
|
order_flags |= (AIOrderFlags)order->GetNonStopType();
|
||||||
|
|
|
@ -172,6 +172,18 @@ public:
|
||||||
*/
|
*/
|
||||||
static bool IsConditionalOrder(VehicleID vehicle_id, OrderPosition order_position);
|
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.
|
* Checks whether the current order is part of the orderlist.
|
||||||
* @param vehicle_id The vehicle to check.
|
* @param vehicle_id The vehicle to check.
|
||||||
|
@ -240,7 +252,7 @@ public:
|
||||||
* @param vehicle_id The vehicle to get the destination for.
|
* @param vehicle_id The vehicle to get the destination for.
|
||||||
* @param order_position The order to get the destination for.
|
* @param order_position The order to get the destination for.
|
||||||
* @pre IsValidVehicleOrder(vehicle_id, order_position).
|
* @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
|
* @note Giving ORDER_CURRENT as order_position will give the order that is
|
||||||
* currently being executed by the vehicle. This is not necessarily the
|
* currently being executed by the vehicle. This is not necessarily the
|
||||||
* current order as given by ResolveOrderPosition (the current index in the
|
* current order as given by ResolveOrderPosition (the current index in the
|
||||||
|
|
|
@ -94,6 +94,7 @@ void SQAIOrder_Register(Squirrel *engine)
|
||||||
SQAIOrder.DefSQStaticMethod(engine, &AIOrder::IsGotoDepotOrder, "IsGotoDepotOrder", 3, ".ii");
|
SQAIOrder.DefSQStaticMethod(engine, &AIOrder::IsGotoDepotOrder, "IsGotoDepotOrder", 3, ".ii");
|
||||||
SQAIOrder.DefSQStaticMethod(engine, &AIOrder::IsGotoWaypointOrder, "IsGotoWaypointOrder", 3, ".ii");
|
SQAIOrder.DefSQStaticMethod(engine, &AIOrder::IsGotoWaypointOrder, "IsGotoWaypointOrder", 3, ".ii");
|
||||||
SQAIOrder.DefSQStaticMethod(engine, &AIOrder::IsConditionalOrder, "IsConditionalOrder", 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::IsCurrentOrderPartOfOrderList, "IsCurrentOrderPartOfOrderList", 2, ".i");
|
||||||
SQAIOrder.DefSQStaticMethod(engine, &AIOrder::ResolveOrderPosition, "ResolveOrderPosition", 3, ".ii");
|
SQAIOrder.DefSQStaticMethod(engine, &AIOrder::ResolveOrderPosition, "ResolveOrderPosition", 3, ".ii");
|
||||||
SQAIOrder.DefSQStaticMethod(engine, &AIOrder::AreOrderFlagsValid, "AreOrderFlagsValid", 3, ".ii");
|
SQAIOrder.DefSQStaticMethod(engine, &AIOrder::AreOrderFlagsValid, "AreOrderFlagsValid", 3, ".ii");
|
||||||
|
|
Loading…
Reference in New Issue