--- a/src/ai/api/ai_order.cpp Sun Apr 06 14:12:19 2008 +0000
+++ b/src/ai/api/ai_order.cpp Sun Apr 06 23:07:42 2008 +0000
@@ -68,10 +68,10 @@
Order *order = ::GetVehicle(vehicle_id)->orders;
for (uint i = 0; i < order_id; i++) order = order->next;
- switch (order->type) {
- case OT_GOTO_DEPOT: return ::GetDepot(order->dest)->xy;
- case OT_GOTO_STATION: return ::GetStation(order->dest)->xy;
- case OT_GOTO_WAYPOINT: return ::GetWaypoint(order->dest)->xy;
+ switch (order->GetType()) {
+ case OT_GOTO_DEPOT: return ::GetDepot(order->GetDestination())->xy;
+ case OT_GOTO_STATION: return ::GetStation(order->GetDestination())->xy;
+ case OT_GOTO_WAYPOINT: return ::GetWaypoint(order->GetDestination())->xy;
default: return INVALID_TILE;
}
}
@@ -83,7 +83,23 @@
Order *order = ::GetVehicle(vehicle_id)->orders;
for (uint i = 0; i < order_id; i++) order = order->next;
- return (AIOrder::AIOrderFlags)order->flags;
+ AIOrderFlags order_flags= AIOF_NONE;
+ if (order->GetNonStopType() != OFB_NO_NON_STOP) order_flags |= AIOF_NON_STOP;
+ switch (order->GetType()) {
+ case OT_GOTO_DEPOT:
+ if (order->GetDepotOrderType() & OFB_SERVICE_IF_NEEDED) order_flags |= AIOF_SERVICE_IF_NEEDED;
+ break;
+
+ case OT_GOTO_STATION:
+ if (order->GetLoadType() & OFB_FULL_LOAD) order_flags |= AIOF_FULL_LOAD;
+ if (order->GetUnloadType() & OFB_UNLOAD) order_flags |= AIOF_UNLOAD;
+ if (order->GetUnloadType() & OFB_TRANSFER) order_flags |= AIOF_TRANSFER;
+ break;
+
+ default: break;
+ }
+
+ return order_flags;
}
/* static */ bool AIOrder::AppendOrder(VehicleID vehicle_id, TileIndex destination, AIOrderFlags order_flags)
@@ -99,16 +115,29 @@
!AreOrderFlagsValid(destination, order_flags)) return false;
Order order;
- order.type = ::GetOrderTypeByTile(destination);
- order.flags = order_flags;
- switch (order.type) {
- case OT_GOTO_DEPOT: order.dest = ::GetDepotByTile(destination)->index; break;
- case OT_GOTO_STATION: order.dest = ::GetStationIndex(destination); break;
- case OT_GOTO_WAYPOINT: order.dest = ::GetWaypointIndex(destination); break;
- default: NOT_REACHED(); return false;
+ switch (::GetOrderTypeByTile(destination)) {
+ case OT_GOTO_DEPOT:
+ order.MakeGoToDepot(::GetDepotByTile(destination)->index, true);
+ if (order_flags & AIOF_SERVICE_IF_NEEDED) order.SetDepotOrderType(OFB_SERVICE_IF_NEEDED);
+ break;
+
+ case OT_GOTO_STATION:
+ order.MakeGoToStation(::GetStationIndex(destination));
+ if (order_flags & AIOF_FULL_LOAD) order.SetLoadType(OFB_FULL_LOAD);
+ order.SetUnloadType(((order_flags & AIOF_TRANSFER) ? OFB_TRANSFER : 0) | ((order_flags & AIOF_UNLOAD) ? OFB_UNLOAD : 0));
+ break;
+
+ case OT_GOTO_WAYPOINT:
+ order.MakeGoToWaypoint(::GetWaypointIndex(destination));
+ break;
+
+ default:
+ return false;
}
- return AIObject::DoCommand(0, vehicle_id | (order_id << 16), PackOrder(&order), CMD_INSERT_ORDER);
+ if (order_flags & AIOF_NON_STOP) order.SetNonStopType(OFB_NON_STOP);
+
+ return AIObject::DoCommand(0, vehicle_id | (order_id << 16), order.Pack(), CMD_INSERT_ORDER);
}
/* static */ bool AIOrder::RemoveOrder(VehicleID vehicle_id, uint32 order_id)