diff --git a/src/vehicle.cpp b/src/vehicle.cpp index c8fefff234..748ad84b7d 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -691,7 +691,7 @@ void ResetVehicleColourMap() * List of vehicles that should check for autoreplace this tick. * Mapping of vehicle -> leave depot immediately after autoreplace. */ -using AutoreplaceMap = std::map; +using AutoreplaceMap = std::map; static AutoreplaceMap _vehicles_to_autoreplace; void InitializeVehicles() @@ -921,7 +921,7 @@ Vehicle::~Vehicle() void VehicleEnteredDepotThisTick(Vehicle *v) { /* Vehicle should stop in the depot if it was in 'stopping' state */ - _vehicles_to_autoreplace[v] = !(v->vehstatus & VS_STOPPED); + _vehicles_to_autoreplace[v->index] = !(v->vehstatus & VS_STOPPED); /* We ALWAYS set the stopped state. Even when the vehicle does not plan on * stopping in the depot, so we stop it to ensure that it will not reserve @@ -1069,7 +1069,7 @@ void CallVehicleTicks() Backup cur_company(_current_company); for (auto &it : _vehicles_to_autoreplace) { - Vehicle *v = it.first; + Vehicle *v = Vehicle::Get(it.first); /* Autoreplace needs the current company set as the vehicle owner */ cur_company.Change(v->owner); @@ -1625,7 +1625,7 @@ void VehicleEnterDepot(Vehicle *v) cur_company.Restore(); if (cost.Failed()) { - _vehicles_to_autoreplace[v] = false; + _vehicles_to_autoreplace[v->index] = false; if (v->owner == _local_company) { /* Notify the user that we stopped the vehicle */ SetDParam(0, v->index); @@ -1647,7 +1647,7 @@ void VehicleEnterDepot(Vehicle *v) } if (v->current_order.GetDepotActionType() & ODATFB_HALT) { /* Vehicles are always stopped on entering depots. Do not restart this one. */ - _vehicles_to_autoreplace[v] = false; + _vehicles_to_autoreplace[v->index] = false; /* Invalidate last_loading_station. As the link from the station * before the stop to the station after the stop can't be predicted * we shouldn't construct it when the vehicle visits the next stop. */