From 6880cf24a0432ac495d5e8a941c1e9bd95500068 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Tue, 30 May 2023 23:31:09 +0100 Subject: [PATCH] Fix crash in template replacement failure news if autorenew succeeds --- src/autoreplace_cmd.cpp | 1 + src/vehicle.cpp | 3 +++ 2 files changed, 4 insertions(+) diff --git a/src/autoreplace_cmd.cpp b/src/autoreplace_cmd.cpp index 36e2556b5f..00b665d84e 100644 --- a/src/autoreplace_cmd.cpp +++ b/src/autoreplace_cmd.cpp @@ -810,6 +810,7 @@ CommandCost CmdAutoreplaceVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1 } if (cost.Succeeded() && nothing_to_do) cost = CommandCost(STR_ERROR_AUTOREPLACE_NOTHING_TO_DO); + cost.SetResultData(v->index); return cost; } diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 22401a740b..08228bcc01 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -1647,6 +1647,9 @@ void CallVehicleTicks() const Company *c = Company::Get(_current_company); SubtractMoneyFromCompany(CommandCost(EXPENSES_NEW_VEHICLES, (Money)c->settings.engine_renew_money)); CommandCost res2 = DoCommand(0, t_new, 1, DC_EXEC, CMD_AUTOREPLACE_VEHICLE); + if (res2.HasResultData()) { + t = Train::Get(res2.GetResultData()); + } SubtractMoneyFromCompany(CommandCost(EXPENSES_NEW_VEHICLES, -(Money)c->settings.engine_renew_money)); if (res2.Succeeded() || res.GetCost() == 0) res.AddCost(res2); }