(svn r9479) [NoAI] -Fix: AIOrder::ChangeOrder didn't work as expected, or rather CMD_MODIFY_ORDER didn't.
--- a/src/ai/api/ai_order.cpp Mon Mar 26 12:41:42 2007 +0000
+++ b/src/ai/api/ai_order.cpp Mon Mar 26 12:58:47 2007 +0000
@@ -50,7 +50,7 @@
{
switch (::GetOrderTypeByTile(destination)) {
case OT_GOTO_DEPOT: return (order_flags & ~(AIOF_NON_STOP | AIOF_SERVICE_IF_NEEDED)) == 0;
- case OT_GOTO_STATION: return (order_flags & ~(AIOF_NON_STOP | AIOF_TRANSFER | AIOF_UNLOAD | AIOF_FULL_LOAD)) == 0;
+ case OT_GOTO_STATION: return (order_flags & ~(AIOF_NON_STOP | AIOF_TRANSFER | AIOF_UNLOAD | AIOF_FULL_LOAD)) == 0 && ((order_flags & AIOF_UNLOAD) == 0 || (order_flags & AIOF_FULL_LOAD) == 0);
case OT_GOTO_WAYPOINT: return (order_flags & ~(AIOF_NON_STOP)) == 0;
default: return false;
}
@@ -123,7 +123,16 @@
if (!IsValidVehicleOrder(vehicle_id, order_id) ||
!this->AreOrderFlagsValid(GetOrderDestination(vehicle_id, order_id), order_flags)) return false;
- return this->DoCommand(0, vehicle_id | (order_id << 16), order_flags, CMD_MODIFY_ORDER);
+ for (;;) {
+ /* Loop as long as there is a difference between the requested and
+ * the current orders of the vehicle. */
+ AIOrderFlags current = this->GetOrderFlags(vehicle_id, order_id);
+ AIOrderFlags diff = current ^ order_flags;
+ if (diff == 0) return true;
+
+ bool res = this->DoCommand(0, vehicle_id | (order_id << 16), FIND_FIRST_BIT(diff), CMD_MODIFY_ORDER);
+ if (!res) return false;
+ }
}
bool AIOrder::CopyOrders(VehicleID vehicle_id, VehicleID main_vehicle_id)
--- a/src/ai/api/ai_order.hpp Mon Mar 26 12:41:42 2007 +0000
+++ b/src/ai/api/ai_order.hpp Mon Mar 26 12:58:47 2007 +0000
@@ -26,9 +26,9 @@
/** Transfer instead of deliver the goods; only for stations. */
AIOF_TRANSFER = 1 << 0,
- /** Always unload the vehicle; only for stations. */
+ /** Always unload the vehicle; only for stations. Cannot be set when AIOF_FULL_LOAD is set. */
AIOF_UNLOAD = 1 << 1,
- /** Wait till the the vehicle is fully loaded; only for stations. */
+ /** Wait till the the vehicle is fully loaded; only for stations. Cannot be set when AIOF_UNLOAD is set. */
AIOF_FULL_LOAD = 1 << 2,
/** Service the vehicle when needed, otherwise skip this order; only for depots. */