diff --git a/depot.h b/depot.h index c52c3292aa..7cf25a1b1e 100644 --- a/depot.h +++ b/depot.h @@ -107,4 +107,6 @@ Depot *GetDepotByTile(TileIndex tile); void InitializeDepots(void); Depot *AllocateDepot(void); +void DeleteDepotHighlightOfVehicle(const Vehicle *v); + #endif /* DEPOT_H */ diff --git a/depot_gui.c b/depot_gui.c index da879bb420..c0ee00ddcf 100644 --- a/depot_gui.c +++ b/depot_gui.c @@ -1033,3 +1033,21 @@ void ShowDepotWindow(TileIndex tile, byte type) ResizeDepotButtons(w); } } + +/** Removes the highlight of a vehicle in a depot window + * @param *v Vehicle to remove all highlights from + */ +void DeleteDepotHighlightOfVehicle(const Vehicle *v) +{ + Window* const *wz; + + FOR_ALL_WINDOWS(wz) { + const Window *w = *wz; + if (w->window_class != WC_VEHICLE_DEPOT) continue; + if (w->window_number != v->tile) continue; + if (WP(w, depot_d).sel == v->index) { + WP(w, depot_d).sel = INVALID_VEHICLE; + ResetObjectToPlace(); + } + } +} diff --git a/vehicle.c b/vehicle.c index 9c657483cf..0cf909efbf 100644 --- a/vehicle.c +++ b/vehicle.c @@ -566,6 +566,8 @@ void DestroyVehicle(Vehicle *v) InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); } + DeleteDepotHighlightOfVehicle(v); + UpdateVehiclePosHash(v, INVALID_COORD, 0); v->next_hash = INVALID_VEHICLE; if (v->orders != NULL) DeleteVehicleOrders(v);