From 1f8533ebe096a566d518cd1b160a8022a53a792c Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Wed, 7 Feb 2024 08:51:03 +0000 Subject: [PATCH] Fix #12024: Autoreplace failed news message for trains must go to lead engine. (#12025) --- src/autoreplace_cmd.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/autoreplace_cmd.cpp b/src/autoreplace_cmd.cpp index 5d6b6eeaaf..e481b9d439 100644 --- a/src/autoreplace_cmd.cpp +++ b/src/autoreplace_cmd.cpp @@ -333,7 +333,8 @@ static CommandCost BuildReplacementVehicle(Vehicle *old_veh, Vehicle **new_vehic if (!IsValidCargoID(refit_cargo)) { if (!IsLocalCompany()) return CommandCost(); - SetDParam(0, old_veh->index); + VehicleID old_veh_id = (old_veh->type == VEH_TRAIN) ? Train::From(old_veh)->First()->index : old_veh->index; + SetDParam(0, old_veh_id); int order_id = GetIncompatibleRefitOrderIdForAutoreplace(old_veh, e); if (order_id != -1) { @@ -346,7 +347,7 @@ static CommandCost BuildReplacementVehicle(Vehicle *old_veh, Vehicle **new_vehic SetDParam(2, CargoSpec::Get(old_veh->cargo_type)->name); } - AddVehicleAdviceNewsItem(STR_NEWS_VEHICLE_AUTORENEW_FAILED, old_veh->index); + AddVehicleAdviceNewsItem(STR_NEWS_VEHICLE_AUTORENEW_FAILED, old_veh_id); return CommandCost(); }