(svn r13585) [NoAI] -Add: possibility to get information/perform order changes based on the current order of a vehicle.
--- a/src/ai/api/ai_order.cpp Thu Jun 19 16:33:24 2008 +0000
+++ b/src/ai/api/ai_order.cpp Thu Jun 19 18:09:29 2008 +0000
@@ -41,11 +41,20 @@
return OT_END;
}
-/* static */ bool AIOrder::IsValidVehicleOrder(VehicleID vehicle_id, uint32 order_id)
+/* static */ bool AIOrder::IsValidVehicleOrder(VehicleID vehicle_id, OrderPosition order_position)
{
- return AIVehicle::IsValidVehicle(vehicle_id) && order_id < ::GetVehicle(vehicle_id)->num_orders;
+ return AIVehicle::IsValidVehicle(vehicle_id) && (order_position < ::GetVehicle(vehicle_id)->num_orders || order_position == CURRENT_ORDER);
}
+/* static */ AIOrder::OrderPosition AIOrder::ResolveOrderPosition(VehicleID vehicle_id, OrderPosition order_position)
+{
+ if (!AIVehicle::IsValidVehicle(vehicle_id)) return INVALID_ORDER;
+
+ if (order_position == CURRENT_ORDER) return (AIOrder::OrderPosition)::GetVehicle(vehicle_id)->cur_order_index;
+ return (order_position < ::GetVehicle(vehicle_id)->num_orders) ? order_position : INVALID_ORDER;
+}
+
+
/* static */ bool AIOrder::AreOrderFlagsValid(TileIndex destination, AIOrderFlags order_flags)
{
switch (::GetOrderTypeByTile(destination)) {
@@ -70,12 +79,17 @@
return AIVehicle::IsValidVehicle(vehicle_id) ? ::GetVehicle(vehicle_id)->num_orders : -1;
}
-/* static */ TileIndex AIOrder::GetOrderDestination(VehicleID vehicle_id, uint32 order_id)
+/* static */ TileIndex AIOrder::GetOrderDestination(VehicleID vehicle_id, OrderPosition order_position)
{
- if (!IsValidVehicleOrder(vehicle_id, order_id)) return INVALID_TILE;
+ if (!IsValidVehicleOrder(vehicle_id, order_position)) return INVALID_TILE;
- Order *order = ::GetVehicle(vehicle_id)->orders;
- for (uint i = 0; i < order_id; i++) order = order->next;
+ const Order *order;
+ if (order_position == CURRENT_ORDER) {
+ order = &::GetVehicle(vehicle_id)->current_order;
+ } else {
+ order = ::GetVehicle(vehicle_id)->orders;
+ for (int i = 0; i < order_position; i++) order = order->next;
+ }
switch (order->GetType()) {
case OT_GOTO_DEPOT: return ::GetDepot(order->GetDestination())->xy;
@@ -85,12 +99,17 @@
}
}
-/* static */ AIOrder::AIOrderFlags AIOrder::GetOrderFlags(VehicleID vehicle_id, uint32 order_id)
+/* static */ AIOrder::AIOrderFlags AIOrder::GetOrderFlags(VehicleID vehicle_id, OrderPosition order_position)
{
- if (!IsValidVehicleOrder(vehicle_id, order_id)) return AIOF_INVALID;
+ if (!IsValidVehicleOrder(vehicle_id, order_position)) return AIOF_INVALID;
- Order *order = ::GetVehicle(vehicle_id)->orders;
- for (uint i = 0; i < order_id; i++) order = order->next;
+ const Order *order;
+ if (order_position == CURRENT_ORDER) {
+ order = &::GetVehicle(vehicle_id)->current_order;
+ } else {
+ order = ::GetVehicle(vehicle_id)->orders;
+ for (int i = 0; i < order_position; i++) order = order->next;
+ }
AIOrderFlags order_flags = AIOF_NONE;
order_flags |= (AIOrderFlags)order->GetNonStopType();
@@ -113,14 +132,16 @@
/* static */ bool AIOrder::AppendOrder(VehicleID vehicle_id, TileIndex destination, AIOrderFlags order_flags)
{
EnforcePrecondition(false, AIVehicle::IsValidVehicle(vehicle_id));
- return InsertOrder(vehicle_id, ::GetVehicle(vehicle_id)->num_orders, destination, order_flags);
+ return InsertOrder(vehicle_id, (AIOrder::OrderPosition)::GetVehicle(vehicle_id)->num_orders, destination, order_flags);
}
-/* static */ bool AIOrder::InsertOrder(VehicleID vehicle_id, uint32 order_id, TileIndex destination, AIOrder::AIOrderFlags order_flags)
+/* static */ bool AIOrder::InsertOrder(VehicleID vehicle_id, OrderPosition order_position, TileIndex destination, AIOrder::AIOrderFlags order_flags)
{
/* IsValidVehicleOrder is not good enough because it does not allow appending. */
+ if (order_position == CURRENT_ORDER) order_position = AIOrder::ResolveOrderPosition(vehicle_id, order_position);
+
EnforcePrecondition(false, AIVehicle::IsValidVehicle(vehicle_id));
- EnforcePrecondition(false, order_id <= ::GetVehicle(vehicle_id)->num_orders);
+ EnforcePrecondition(false, order_position <= ::GetVehicle(vehicle_id)->num_orders);
EnforcePrecondition(false, AreOrderFlagsValid(destination, order_flags));
Order order;
@@ -145,46 +166,50 @@
order.SetNonStopType((OrderNonStopFlags)GB(order_flags, 0, 2));
- return AIObject::DoCommand(0, vehicle_id | (order_id << 16), order.Pack(), CMD_INSERT_ORDER);
-}
-
-/* static */ bool AIOrder::RemoveOrder(VehicleID vehicle_id, uint32 order_id)
-{
- EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_id));
-
- return AIObject::DoCommand(0, vehicle_id, order_id, CMD_DELETE_ORDER);
+ return AIObject::DoCommand(0, vehicle_id | (order_position << 16), order.Pack(), CMD_INSERT_ORDER);
}
-/* static */ bool AIOrder::ChangeOrder(VehicleID vehicle_id, uint32 order_id, AIOrder::AIOrderFlags order_flags)
+/* static */ bool AIOrder::RemoveOrder(VehicleID vehicle_id, OrderPosition order_position)
{
- EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_id));
- EnforcePrecondition(false, AreOrderFlagsValid(GetOrderDestination(vehicle_id, order_id), order_flags));
+ order_position = AIOrder::ResolveOrderPosition(vehicle_id, order_position);
+
+ EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position));
+
+ return AIObject::DoCommand(0, vehicle_id, order_position, CMD_DELETE_ORDER);
+}
+
+/* static */ bool AIOrder::ChangeOrder(VehicleID vehicle_id, OrderPosition order_position, AIOrder::AIOrderFlags order_flags)
+{
+ order_position = AIOrder::ResolveOrderPosition(vehicle_id, order_position);
+
+ EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position));
+ EnforcePrecondition(false, AreOrderFlagsValid(GetOrderDestination(vehicle_id, order_position), order_flags));
Order *order = ::GetVehicle(vehicle_id)->orders;
- for (uint i = 0; i < order_id; i++) order = order->next;
+ for (int i = 0; i < order_position; i++) order = order->next;
- AIOrderFlags current = GetOrderFlags(vehicle_id, order_id);
+ AIOrderFlags current = GetOrderFlags(vehicle_id, order_position);
if ((current & AIOF_NON_STOP_FLAGS) != (order_flags & AIOF_NON_STOP_FLAGS)) {
- bool res = AIObject::DoCommand(0, vehicle_id | (order_id << 16), (order_flags & AIOF_NON_STOP_FLAGS) << 4 | MOF_NON_STOP, CMD_MODIFY_ORDER);
+ bool res = AIObject::DoCommand(0, vehicle_id | (order_position << 16), (order_flags & AIOF_NON_STOP_FLAGS) << 4 | MOF_NON_STOP, CMD_MODIFY_ORDER);
if (!res) return false;
}
switch (order->GetType()) {
case OT_GOTO_DEPOT:
if ((current & AIOF_SERVICE_IF_NEEDED) != (order_flags & AIOF_SERVICE_IF_NEEDED)) {
- bool res = AIObject::DoCommand(0, vehicle_id | (order_id << 16), MOF_DEPOT_ACTION, CMD_MODIFY_ORDER);
+ bool res = AIObject::DoCommand(0, vehicle_id | (order_position << 16), MOF_DEPOT_ACTION, CMD_MODIFY_ORDER);
if (!res) return false;
}
break;
case OT_GOTO_STATION:
if ((current & AIOF_UNLOAD_FLAGS) != (order_flags & AIOF_UNLOAD_FLAGS)) {
- bool res = AIObject::DoCommand(0, vehicle_id | (order_id << 16), (order_flags & AIOF_UNLOAD_FLAGS) << 2 | MOF_UNLOAD, CMD_MODIFY_ORDER);
+ bool res = AIObject::DoCommand(0, vehicle_id | (order_position << 16), (order_flags & AIOF_UNLOAD_FLAGS) << 2 | MOF_UNLOAD, CMD_MODIFY_ORDER);
if (!res) return false;
}
if ((current & AIOF_LOAD_FLAGS) != (order_flags & AIOF_LOAD_FLAGS)) {
- bool res = AIObject::DoCommand(0, vehicle_id | (order_id << 16), (order_flags & AIOF_LOAD_FLAGS) >> 1 | MOF_LOAD, CMD_MODIFY_ORDER);
+ bool res = AIObject::DoCommand(0, vehicle_id | (order_position << 16), (order_flags & AIOF_LOAD_FLAGS) >> 1 | MOF_LOAD, CMD_MODIFY_ORDER);
if (!res) return false;
}
break;
@@ -192,17 +217,20 @@
default: break;
}
- assert(GetOrderFlags(vehicle_id, order_id) == order_flags);
+ assert(GetOrderFlags(vehicle_id, order_position) == order_flags);
return true;
}
-/* static */ bool AIOrder::MoveOrder(VehicleID vehicle_id, uint32 order_id_move, uint32 order_id_target)
+/* static */ bool AIOrder::MoveOrder(VehicleID vehicle_id, OrderPosition order_position_move, OrderPosition order_position_target)
{
- EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_id_move));
- EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_id_target));
+ order_position_move = AIOrder::ResolveOrderPosition(vehicle_id, order_position_move);
+ order_position_target = AIOrder::ResolveOrderPosition(vehicle_id, order_position_target);
- return AIObject::DoCommand(0, vehicle_id, order_id_move | (order_id_target << 16), CMD_MOVE_ORDER);
+ EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position_move));
+ EnforcePrecondition(false, IsValidVehicleOrder(vehicle_id, order_position_target));
+
+ return AIObject::DoCommand(0, vehicle_id, order_position_move | (order_position_target << 16), CMD_MOVE_ORDER);
}
/* static */ bool AIOrder::CopyOrders(VehicleID vehicle_id, VehicleID main_vehicle_id)
--- a/src/ai/api/ai_order.hpp Thu Jun 19 16:33:24 2008 +0000
+++ b/src/ai/api/ai_order.hpp Thu Jun 19 18:09:29 2008 +0000
@@ -69,14 +69,32 @@
AIOF_INVALID = 0xFFFF,
};
+ /** Different constants related to the OrderPosition */
+ enum OrderPosition {
+ CURRENT_ORDER = 0xFF, //!< Constant that gets resolved to the current order.
+ INVALID_ORDER = -1, //!< An invalid order.
+ };
+
/**
* Checks whether the given order id is valid for the given vehicle.
* @param vehicle_id The vehicle to check the order index for.
- * @param order_id The order index to check.
+ * @param order_position The order index to check.
* @pre AIVehicle::IsValidVehicle(vehicle_id).
- * @return True if and only if the order_id is valid for the given vehicle.
+ * @return True if and only if the order_position is valid for the given vehicle.
*/
- static bool IsValidVehicleOrder(VehicleID vehicle_id, uint32 order_id);
+ static bool IsValidVehicleOrder(VehicleID vehicle_id, OrderPosition order_position);
+
+ /**
+ * Resolves the given order index to the correct index for the given vehicle.
+ * If the order index was CURRENT_ORDER it will be resolved to the index of
+ * the current order (as shown in the order list). If the order with the
+ * given index does not exist it will return INVALID_ORDER.
+ * @param vehicle_id The vehicle to check the order index for.
+ * @param order_position The order index to resolve.
+ * @pre AIVehicle::IsValidVehicle(vehicle_id).
+ * @return The resolved order index.
+ */
+ static OrderPosition ResolveOrderPosition(VehicleID vehicle_id, OrderPosition order_position);
/**
* Checks whether the given order flags are valid for the given destination.
@@ -98,20 +116,30 @@
/**
* Gets the destination of the given order for the given vehicle.
* @param vehicle_id The vehicle to get the destination for.
- * @param order_id The order to get the destination for.
- * @pre IsValidVehicleOrder(vehicle_id, order_id).
+ * @param order_position The order to get the destination for.
+ * @pre IsValidVehicleOrder(vehicle_id, order_position).
+ * @note Giving CURRENT_ORDER 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
+ * order list) as manual or autoservicing depot orders do not show up
+ * in the orderlist, but they can be the current order of a vehicle.
* @return The destination tile of the order.
*/
- static TileIndex GetOrderDestination(VehicleID vehicle_id, uint32 order_id);
+ static TileIndex GetOrderDestination(VehicleID vehicle_id, OrderPosition order_position);
/**
* Gets the AIOrderFlags of the given order for the given vehicle.
* @param vehicle_id The vehicle to get the destination for.
- * @param order_id The order to get the destination for.
- * @pre IsValidVehicleOrder(vehicle_id, order_id).
+ * @param order_position The order to get the destination for.
+ * @pre IsValidVehicleOrder(vehicle_id, order_position).
+ * @note Giving CURRENT_ORDER 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
+ * order list) as manual or autoservicing depot orders do not show up
+ * in the orderlist, but they can be the current order of a vehicle.
* @return The AIOrderFlags of the order.
*/
- static AIOrderFlags GetOrderFlags(VehicleID vehicle_id, uint32 order_id);
+ static AIOrderFlags GetOrderFlags(VehicleID vehicle_id, OrderPosition order_position);
/**
* Appends an order to the end of the vehicle's order list.
@@ -128,49 +156,49 @@
static bool AppendOrder(VehicleID vehicle_id, TileIndex destination, AIOrderFlags order_flags);
/**
- * Inserts an order before the given order_id into the vehicle's order list.
+ * Inserts an order before the given order_position into the vehicle's order list.
* @param vehicle_id The vehicle to add the order to.
- * @param order_id The order to place the new order before.
+ * @param order_position The order to place the new order before.
* @param destination The destination of the order.
* @param order_flags The flags given to the order.
- * @pre IsValidVehicleOrder(vehicle_id, order_id).
+ * @pre IsValidVehicleOrder(vehicle_id, order_position).
* @pre AreOrderFlagsValid(destination, order_flags).
* @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY
* @exception AIOrder::ERR_ORDER_NO_MORE_SPACE
* @exception AIOrder::ERR_ORDER_TOO_FAR_AWAY_FROM_PREVIOUS_DESTINATION
* @return True if and only if the order was inserted.
*/
- static bool InsertOrder(VehicleID vehicle_id, uint32 order_id, TileIndex destination, AIOrderFlags order_flags);
+ static bool InsertOrder(VehicleID vehicle_id, OrderPosition order_position, TileIndex destination, AIOrderFlags order_flags);
/**
* Removes an order from the vehicle's order list.
* @param vehicle_id The vehicle to remove the order from.
- * @param order_id The order to remove from the order list.
- * @pre AIVehicle::IsValidVehicleOrder(vehicle_id, order_id).
+ * @param order_position The order to remove from the order list.
+ * @pre AIVehicle::IsValidVehicleOrder(vehicle_id, order_position).
* @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY
* @return True if and only if the order was removed.
*/
- static bool RemoveOrder(VehicleID vehicle_id, uint32 order_id);
+ static bool RemoveOrder(VehicleID vehicle_id, OrderPosition order_position);
/**
* Changes the order flags of the given order.
* @param vehicle_id The vehicle to change the order of.
- * @param order_id The order to change.
+ * @param order_position The order to change.
* @param order_flags The new flags given to the order.
- * @pre IsValidVehicleOrder(vehicle_id, order_id).
- * @pre AreOrderFlagsValid(GetOrderDestination(vehicle_id, order_id), order_flags).
+ * @pre IsValidVehicleOrder(vehicle_id, order_position).
+ * @pre AreOrderFlagsValid(GetOrderDestination(vehicle_id, order_position), order_flags).
* @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY
* @return True if and only if the order was changed.
*/
- static bool ChangeOrder(VehicleID vehicle_id, uint32 order_id, AIOrderFlags order_flags);
+ static bool ChangeOrder(VehicleID vehicle_id, OrderPosition order_position, AIOrderFlags order_flags);
/**
* Move an order inside the orderlist
* @param vehicle_id The vehicle to move the orders.
- * @param order_id_move The order to move.
- * @param order_id_target The target order
- * @pre IsValidVehicleOrder(vehicle_id, order_id_move).
- * @pre IsValidVehicleOrder(vehicle_id, order_id_target).
+ * @param order_position_move The order to move.
+ * @param order_position_target The target order
+ * @pre IsValidVehicleOrder(vehicle_id, order_position_move).
+ * @pre IsValidVehicleOrder(vehicle_id, order_position_target).
* @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY
* @return True if and only if the order was moved.
* @note If the order is moved to a lower place (e.g. from 7 to 2)
@@ -178,7 +206,7 @@
* to a higher place (e.g. from 7 to 9) the target will be moved
* downwards (e.g. 8).
*/
- static bool MoveOrder(VehicleID vehicle_id, uint32 order_id_move, uint32 order_id_target);
+ static bool MoveOrder(VehicleID vehicle_id, OrderPosition order_position_move, OrderPosition order_position_target);
/**
* Copies the orders from another vehicle. The orders of the main vehicle
--- a/src/ai/api/ai_order.hpp.sq Thu Jun 19 16:33:24 2008 +0000
+++ b/src/ai/api/ai_order.hpp.sq Thu Jun 19 18:09:29 2008 +0000
@@ -9,6 +9,8 @@
template <> int Return<AIOrder::ErrorMessages>(HSQUIRRELVM vm, AIOrder::ErrorMessages res) { sq_pushinteger(vm, (int32)res); return 1; }
template <> AIOrder::AIOrderFlags GetParam(ForceType<AIOrder::AIOrderFlags>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (AIOrder::AIOrderFlags)tmp; }
template <> int Return<AIOrder::AIOrderFlags>(HSQUIRRELVM vm, AIOrder::AIOrderFlags res) { sq_pushinteger(vm, (int32)res); return 1; }
+ template <> AIOrder::OrderPosition GetParam(ForceType<AIOrder::OrderPosition>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (AIOrder::OrderPosition)tmp; }
+ template <> int Return<AIOrder::OrderPosition>(HSQUIRRELVM vm, AIOrder::OrderPosition res) { sq_pushinteger(vm, (int32)res); return 1; }
/* Allow AIOrder to be used as Squirrel parameter */
template <> AIOrder *GetParam(ForceType<AIOrder *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AIOrder *)instance; }
@@ -40,6 +42,8 @@
SQAIOrder.DefSQConst(engine, AIOrder::AIOF_UNLOAD_FLAGS, "AIOF_UNLOAD_FLAGS");
SQAIOrder.DefSQConst(engine, AIOrder::AIOF_LOAD_FLAGS, "AIOF_LOAD_FLAGS");
SQAIOrder.DefSQConst(engine, AIOrder::AIOF_INVALID, "AIOF_INVALID");
+ SQAIOrder.DefSQConst(engine, AIOrder::CURRENT_ORDER, "CURRENT_ORDER");
+ SQAIOrder.DefSQConst(engine, AIOrder::INVALID_ORDER, "INVALID_ORDER");
AIError::RegisterErrorMap(STR_8831_NO_MORE_SPACE_FOR_ORDERS, AIOrder::ERR_ORDER_TOO_MANY);
AIError::RegisterErrorMap(STR_0210_TOO_FAR_FROM_PREVIOUS_DESTINATIO, AIOrder::ERR_ORDER_TOO_FAR_AWAY_FROM_PREVIOUS_DESTINATION);
@@ -47,20 +51,21 @@
AIError::RegisterErrorMapString(AIOrder::ERR_ORDER_TOO_MANY, "ERR_ORDER_TOO_MANY");
AIError::RegisterErrorMapString(AIOrder::ERR_ORDER_TOO_FAR_AWAY_FROM_PREVIOUS_DESTINATION, "ERR_ORDER_TOO_FAR_AWAY_FROM_PREVIOUS_DESTINATION");
- SQAIOrder.DefSQStaticMethod(engine, &AIOrder::GetClassName, "GetClassName", 1, "x");
- SQAIOrder.DefSQStaticMethod(engine, &AIOrder::IsValidVehicleOrder, "IsValidVehicleOrder", 3, "xii");
- SQAIOrder.DefSQStaticMethod(engine, &AIOrder::AreOrderFlagsValid, "AreOrderFlagsValid", 3, "xii");
- SQAIOrder.DefSQStaticMethod(engine, &AIOrder::GetOrderCount, "GetOrderCount", 2, "xi");
- SQAIOrder.DefSQStaticMethod(engine, &AIOrder::GetOrderDestination, "GetOrderDestination", 3, "xii");
- SQAIOrder.DefSQStaticMethod(engine, &AIOrder::GetOrderFlags, "GetOrderFlags", 3, "xii");
- SQAIOrder.DefSQStaticMethod(engine, &AIOrder::AppendOrder, "AppendOrder", 4, "xiii");
- SQAIOrder.DefSQStaticMethod(engine, &AIOrder::InsertOrder, "InsertOrder", 5, "xiiii");
- SQAIOrder.DefSQStaticMethod(engine, &AIOrder::RemoveOrder, "RemoveOrder", 3, "xii");
- SQAIOrder.DefSQStaticMethod(engine, &AIOrder::ChangeOrder, "ChangeOrder", 4, "xiii");
- SQAIOrder.DefSQStaticMethod(engine, &AIOrder::MoveOrder, "MoveOrder", 4, "xiii");
- SQAIOrder.DefSQStaticMethod(engine, &AIOrder::CopyOrders, "CopyOrders", 3, "xii");
- SQAIOrder.DefSQStaticMethod(engine, &AIOrder::ShareOrders, "ShareOrders", 3, "xii");
- SQAIOrder.DefSQStaticMethod(engine, &AIOrder::UnshareOrders, "UnshareOrders", 2, "xi");
+ SQAIOrder.DefSQStaticMethod(engine, &AIOrder::GetClassName, "GetClassName", 1, "x");
+ SQAIOrder.DefSQStaticMethod(engine, &AIOrder::IsValidVehicleOrder, "IsValidVehicleOrder", 3, "xii");
+ SQAIOrder.DefSQStaticMethod(engine, &AIOrder::ResolveOrderPosition, "ResolveOrderPosition", 3, "xii");
+ SQAIOrder.DefSQStaticMethod(engine, &AIOrder::AreOrderFlagsValid, "AreOrderFlagsValid", 3, "xii");
+ SQAIOrder.DefSQStaticMethod(engine, &AIOrder::GetOrderCount, "GetOrderCount", 2, "xi");
+ SQAIOrder.DefSQStaticMethod(engine, &AIOrder::GetOrderDestination, "GetOrderDestination", 3, "xii");
+ SQAIOrder.DefSQStaticMethod(engine, &AIOrder::GetOrderFlags, "GetOrderFlags", 3, "xii");
+ SQAIOrder.DefSQStaticMethod(engine, &AIOrder::AppendOrder, "AppendOrder", 4, "xiii");
+ SQAIOrder.DefSQStaticMethod(engine, &AIOrder::InsertOrder, "InsertOrder", 5, "xiiii");
+ SQAIOrder.DefSQStaticMethod(engine, &AIOrder::RemoveOrder, "RemoveOrder", 3, "xii");
+ SQAIOrder.DefSQStaticMethod(engine, &AIOrder::ChangeOrder, "ChangeOrder", 4, "xiii");
+ SQAIOrder.DefSQStaticMethod(engine, &AIOrder::MoveOrder, "MoveOrder", 4, "xiii");
+ SQAIOrder.DefSQStaticMethod(engine, &AIOrder::CopyOrders, "CopyOrders", 3, "xii");
+ SQAIOrder.DefSQStaticMethod(engine, &AIOrder::ShareOrders, "ShareOrders", 3, "xii");
+ SQAIOrder.DefSQStaticMethod(engine, &AIOrder::UnshareOrders, "UnshareOrders", 2, "xi");
SQAIOrder.PostRegister(engine);
}
--- a/src/ai/api/ai_vehicle.cpp Thu Jun 19 16:33:24 2008 +0000
+++ b/src/ai/api/ai_vehicle.cpp Thu Jun 19 18:09:29 2008 +0000
@@ -115,11 +115,13 @@
}
}
-/* static */ bool AIVehicle::SkipToVehicleOrder(VehicleID vehicle_id, uint32 order_id)
+/* static */ bool AIVehicle::SkipToVehicleOrder(VehicleID vehicle_id, AIOrder::OrderPosition order_position)
{
- EnforcePrecondition(false, AIOrder::IsValidVehicleOrder(vehicle_id, order_id));
+ order_position = AIOrder::ResolveOrderPosition(vehicle_id, order_position);
- return AIObject::DoCommand(0, vehicle_id, order_id, CMD_SKIP_TO_ORDER);
+ EnforcePrecondition(false, AIOrder::IsValidVehicleOrder(vehicle_id, order_position));
+
+ return AIObject::DoCommand(0, vehicle_id, order_position, CMD_SKIP_TO_ORDER);
}
/* static */ bool AIVehicle::SetName(VehicleID vehicle_id, const char *name)
--- a/src/ai/api/ai_vehicle.hpp Thu Jun 19 16:33:24 2008 +0000
+++ b/src/ai/api/ai_vehicle.hpp Thu Jun 19 18:09:29 2008 +0000
@@ -8,6 +8,7 @@
#include "ai_object.hpp"
#include "ai_error.hpp"
#include "ai_road.hpp"
+#include "ai_order.hpp"
/**
* Class that handles all vehicle related functions.
@@ -327,11 +328,11 @@
/**
* Skips the current order of the given vehicle.
* @param vehicle_id The vehicle to skip the order for.
- * @param order_id The selected order to which we want to skip.
- * @pre IsValidVehicleOrder(vehicle_id, order_id).
+ * @param order_position The selected order to which we want to skip.
+ * @pre IsValidVehicleOrder(vehicle_id, order_position).
* @return True if and only if the order has been skipped.
*/
- static bool SkipToVehicleOrder(VehicleID vehicle_id, uint32 order_id);
+ static bool SkipToVehicleOrder(VehicleID vehicle_id, AIOrder::OrderPosition order_position);
/**
* Get the maximum amount of a specific cargo the given vehicle can transport.