Fix order removal due to shared-infra company deletion.
Order totals were not updated correctly, implicit orders not handled properly, etc. Create generic function for vehicle order filtering. Use for station deletion and infra sharing company deletion.
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
#include "gui.h"
|
||||
#include "pathfinder/yapf/yapf_cache.h"
|
||||
#include "company_base.h"
|
||||
#include "order_cmd.h"
|
||||
|
||||
#include "table/strings.h"
|
||||
|
||||
@@ -138,6 +139,7 @@ static bool OrderDestinationIsAllowed(const Order *order, const Vehicle *v, Owne
|
||||
{
|
||||
Owner dest_owner;
|
||||
switch (order->GetType()) {
|
||||
case OT_IMPLICIT:
|
||||
case OT_GOTO_STATION:
|
||||
case OT_GOTO_WAYPOINT: dest_owner = BaseStation::Get(order->GetDestination())->owner; break;
|
||||
case OT_GOTO_DEPOT: dest_owner = (v->type == VEH_AIRCRAFT) ? Station::Get(order->GetDestination())->owner : GetTileOwner(Depot::Get(order->GetDestination())->xy); break;
|
||||
@@ -294,19 +296,10 @@ void HandleSharingCompanyDeletion(Owner owner)
|
||||
/* order list */
|
||||
if (v->FirstShared() != v) continue;
|
||||
|
||||
Order *o;
|
||||
int id = -1;
|
||||
FOR_VEHICLE_ORDERS(v, o) {
|
||||
id++;
|
||||
if (OrderDestinationIsAllowed(o, v, owner)) continue;
|
||||
|
||||
o->MakeDummy();
|
||||
for (const Vehicle *w = v; w != NULL; w = w->NextShared()) {
|
||||
/* In GUI, simulate by removing the order and adding it back */
|
||||
InvalidateVehicleOrder(w, id | (INVALID_VEH_ORDER_ID << 8));
|
||||
InvalidateVehicleOrder(w, (id << 8) | INVALID_VEH_ORDER_ID);
|
||||
}
|
||||
}
|
||||
RemoveVehicleOrdersIf(v, [&](const Order *o) {
|
||||
if (o->GetType() == OT_GOTO_DEPOT && (o->GetDepotActionType() & ODATFB_NEAREST_DEPOT) != 0) return false;
|
||||
return !OrderDestinationIsAllowed(o, v, owner);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user