From ef8eb66a2bb238c683dd358fca76d40250e13fb3 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Wed, 17 Apr 2024 18:54:50 +0100 Subject: [PATCH] Fix c38df2d58: Use VehicleID instead of pointer in map of vehicles to replace. (#12512) This affects the sort order, VehicleID is deterministic, Vehicle * is not. --- src/vehicle.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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. */