Remove conditional order refs when removing tracerestrict slot

See #40
This commit is contained in:
Jonathan G Rennison
2018-04-22 14:46:15 +01:00
parent 78588d8ce5
commit 97fd250d21

View File

@@ -1575,6 +1575,7 @@ void TraceRestrictGetVehicleSlots(VehicleID id, std::vector<TraceRestrictSlotID>
/** /**
* This is called when a slot is about to be deleted * This is called when a slot is about to be deleted
* Scan program pool and change any references to it to the invalid group ID, to avoid dangling references * Scan program pool and change any references to it to the invalid group ID, to avoid dangling references
* Scan order list and change any references to it to the invalid group ID, to avoid dangling slot condition references
*/ */
void TraceRestrictRemoveSlotID(TraceRestrictSlotID index) void TraceRestrictRemoveSlotID(TraceRestrictSlotID index)
{ {
@@ -1593,8 +1594,21 @@ void TraceRestrictRemoveSlotID(TraceRestrictSlotID index)
} }
} }
bool changed_order = false;
Order *o;
FOR_ALL_ORDERS(o) {
if (o->IsType(OT_CONDITIONAL) && o->GetConditionVariable() == OCV_SLOT_OCCUPANCY && o->GetXData() == index) {
o->GetXDataRef() = INVALID_TRACE_RESTRICT_SLOT_ID;
changed_order = true;
}
}
// update windows // update windows
InvalidateWindowClassesData(WC_TRACE_RESTRICT); InvalidateWindowClassesData(WC_TRACE_RESTRICT);
if (changed_order) {
InvalidateWindowClassesData(WC_VEHICLE_ORDERS);
InvalidateWindowClassesData(WC_VEHICLE_TIMETABLE);
}
} }
static bool IsUniqueSlotName(const char *name) static bool IsUniqueSlotName(const char *name)