summaryrefslogtreecommitdiff
path: root/src/order_backup.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2011-12-09 20:48:13 +0000
committerrubidium <rubidium@openttd.org>2011-12-09 20:48:13 +0000
commitd9b9ac6013eccff386da96a3ef8b97912b994584 (patch)
treec774d9555130bb5df36a3d2f4590138b7ab39a50 /src/order_backup.cpp
parent7af041d12da235df6f43c42f647dd4c219624bbe (diff)
downloadopenttd-d9b9ac6013eccff386da96a3ef8b97912b994584.tar.xz
(svn r23464) -Fix [FS#4876]: clear the backed up orders of a removed station as well, otherwise one could create orders to a station that was never in the original backupped orders. For example a road vehicle trying to go to a buoy.
Diffstat (limited to 'src/order_backup.cpp')
-rw-r--r--src/order_backup.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/order_backup.cpp b/src/order_backup.cpp
index 9cccb941f..36e6418a6 100644
--- a/src/order_backup.cpp
+++ b/src/order_backup.cpp
@@ -17,6 +17,7 @@
#include "order_backup.h"
#include "vehicle_base.h"
#include "window_func.h"
+#include "station_map.h"
OrderBackupPool _order_backup_pool("BackupOrder");
INSTANTIATE_POOL_METHODS(OrderBackup)
@@ -257,3 +258,25 @@ CommandCost CmdClearOrderBackup(TileIndex tile, DoCommandFlag flags, uint32 p1,
}
}
}
+
+/**
+ * Removes an order from all vehicles. Triggers when, say, a station is removed.
+ * @param type The type of the order (OT_GOTO_[STATION|DEPOT|WAYPOINT]).
+ * @param destination The destination. Can be a StationID, DepotID or WaypointID.
+ */
+/* static */ void OrderBackup::RemoveOrder(OrderType type, DestinationID destination)
+{
+ OrderBackup *ob;
+ FOR_ALL_ORDER_BACKUPS(ob) {
+ for (Order *order = ob->orders; order != NULL; order = order->next) {
+ OrderType ot = order->GetType();
+ if (ot == OT_GOTO_DEPOT && (order->GetDepotActionType() & ODATFB_NEAREST_DEPOT) != 0) continue;
+ if (ot == OT_IMPLICIT || (IsHangarTile(ob->tile) && ot == OT_GOTO_DEPOT)) ot = OT_GOTO_STATION;
+ if (ot == type && order->GetDestination() == destination) {
+ /* Remove the order backup! If a station/depot gets removed, we can't/shouldn't restore those broken orders. */
+ delete ob;
+ break;
+ }
+ }
+ }
+}