Batch depot order removals when deleting companies
This commit is contained in:
@@ -578,6 +578,7 @@ void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Change ownership of tiles */
|
/* Change ownership of tiles */
|
||||||
|
StartRemoveOrderFromAllVehiclesBatch();
|
||||||
{
|
{
|
||||||
TileIndex tile = 0;
|
TileIndex tile = 0;
|
||||||
do {
|
do {
|
||||||
@@ -599,6 +600,7 @@ void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner)
|
|||||||
/* Update any signals in the buffer */
|
/* Update any signals in the buffer */
|
||||||
UpdateSignalsInBuffer();
|
UpdateSignalsInBuffer();
|
||||||
}
|
}
|
||||||
|
StopRemoveOrderFromAllVehiclesBatch();
|
||||||
|
|
||||||
/* Add airport infrastructure count of the old company to the new one. */
|
/* Add airport infrastructure count of the old company to the new one. */
|
||||||
if (new_owner != INVALID_OWNER) Company::Get(new_owner)->infrastructure.airport += Company::Get(old_owner)->infrastructure.airport;
|
if (new_owner != INVALID_OWNER) Company::Get(new_owner)->infrastructure.airport += Company::Get(old_owner)->infrastructure.airport;
|
||||||
|
@@ -2918,6 +2918,51 @@ void CheckOrders(const Vehicle *v)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool _remove_order_from_all_vehicles_batch = false;
|
||||||
|
std::vector<uint32_t> _remove_order_from_all_vehicles_depots;
|
||||||
|
|
||||||
|
static bool IsBatchRemoveOrderDepotRemoved(DestinationID destination)
|
||||||
|
{
|
||||||
|
if (destination / 32 >= _remove_order_from_all_vehicles_depots.size()) return false;
|
||||||
|
|
||||||
|
return HasBit(_remove_order_from_all_vehicles_depots[destination / 32], destination % 32);
|
||||||
|
}
|
||||||
|
|
||||||
|
void StartRemoveOrderFromAllVehiclesBatch()
|
||||||
|
{
|
||||||
|
assert(_remove_order_from_all_vehicles_batch == false);
|
||||||
|
_remove_order_from_all_vehicles_batch = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void StopRemoveOrderFromAllVehiclesBatch()
|
||||||
|
{
|
||||||
|
assert(_remove_order_from_all_vehicles_batch == true);
|
||||||
|
_remove_order_from_all_vehicles_batch = false;
|
||||||
|
|
||||||
|
/* Go through all vehicles */
|
||||||
|
for (Vehicle *v : Vehicle::IterateFrontOnly()) {
|
||||||
|
if (v->type == VEH_AIRCRAFT) continue;
|
||||||
|
|
||||||
|
Order *order = &v->current_order;
|
||||||
|
if (order->IsType(OT_GOTO_DEPOT) && IsBatchRemoveOrderDepotRemoved(order->GetDestination())) {
|
||||||
|
order->MakeDummy();
|
||||||
|
SetWindowDirty(WC_VEHICLE_VIEW, v->index);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* order list */
|
||||||
|
if (v->FirstShared() != v) continue;
|
||||||
|
|
||||||
|
RemoveVehicleOrdersIf(v, [&](const Order *o) {
|
||||||
|
OrderType ot = o->GetType();
|
||||||
|
if (ot != OT_GOTO_DEPOT) return false;
|
||||||
|
if ((o->GetDepotActionType() & ODATFB_NEAREST_DEPOT) != 0) return false;
|
||||||
|
return IsBatchRemoveOrderDepotRemoved(o->GetDestination());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
_remove_order_from_all_vehicles_depots.clear();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes an order from all vehicles. Triggers when, say, a station is removed.
|
* 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 type The type of the order (OT_GOTO_[STATION|DEPOT|WAYPOINT]).
|
||||||
@@ -2928,6 +2973,18 @@ void CheckOrders(const Vehicle *v)
|
|||||||
*/
|
*/
|
||||||
void RemoveOrderFromAllVehicles(OrderType type, DestinationID destination, bool hangar)
|
void RemoveOrderFromAllVehicles(OrderType type, DestinationID destination, bool hangar)
|
||||||
{
|
{
|
||||||
|
if (destination == ((type == OT_GOTO_DEPOT) ? (DestinationID)INVALID_DEPOT : (DestinationID)INVALID_STATION)) return;
|
||||||
|
|
||||||
|
OrderBackup::RemoveOrder(type, destination, hangar);
|
||||||
|
|
||||||
|
if (_remove_order_from_all_vehicles_batch && type == OT_GOTO_DEPOT && !hangar) {
|
||||||
|
std::vector<uint32_t> &ids = _remove_order_from_all_vehicles_depots;
|
||||||
|
uint32_t word_idx = destination / 32;
|
||||||
|
if (word_idx >= ids.size()) ids.resize(word_idx + 1);
|
||||||
|
SetBit(ids[word_idx], destination % 32);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* Aircraft have StationIDs for depot orders and never use DepotIDs
|
/* Aircraft have StationIDs for depot orders and never use DepotIDs
|
||||||
* This fact is handled specially below
|
* This fact is handled specially below
|
||||||
*/
|
*/
|
||||||
@@ -2962,8 +3019,6 @@ void RemoveOrderFromAllVehicles(OrderType type, DestinationID destination, bool
|
|||||||
return (ot == type && o->GetDestination() == destination);
|
return (ot == type && o->GetDestination() == destination);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
OrderBackup::RemoveOrder(type, destination, hangar);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -15,6 +15,8 @@
|
|||||||
#include "company_type.h"
|
#include "company_type.h"
|
||||||
|
|
||||||
/* Functions */
|
/* Functions */
|
||||||
|
void StartRemoveOrderFromAllVehiclesBatch();
|
||||||
|
void StopRemoveOrderFromAllVehiclesBatch();
|
||||||
void RemoveOrderFromAllVehicles(OrderType type, DestinationID destination, bool hangar = false);
|
void RemoveOrderFromAllVehicles(OrderType type, DestinationID destination, bool hangar = false);
|
||||||
void InvalidateVehicleOrder(const Vehicle *v, int data);
|
void InvalidateVehicleOrder(const Vehicle *v, int data);
|
||||||
void CheckOrders(const Vehicle*);
|
void CheckOrders(const Vehicle*);
|
||||||
|
Reference in New Issue
Block a user