diff options
-rw-r--r-- | src/order_backup.cpp | 23 | ||||
-rw-r--r-- | src/order_backup.h | 1 | ||||
-rw-r--r-- | src/order_cmd.cpp | 3 |
3 files changed, 27 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; + } + } + } +} diff --git a/src/order_backup.h b/src/order_backup.h index 583d4a853..6679e55d2 100644 --- a/src/order_backup.h +++ b/src/order_backup.h @@ -67,6 +67,7 @@ public: static void ClearGroup(GroupID group); static void ClearVehicle(const Vehicle *v); + static void RemoveOrder(OrderType type, DestinationID destination); }; /** diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp index ad84b582c..7b7fc8f57 100644 --- a/src/order_cmd.cpp +++ b/src/order_cmd.cpp @@ -27,6 +27,7 @@ #include "station_base.h" #include "waypoint_base.h" #include "company_base.h" +#include "order_backup.h" #include "table/strings.h" @@ -1705,6 +1706,8 @@ restart: } } } + + OrderBackup::RemoveOrder(type, destination); } /** |