From c840e5c0b5b269500d477b2675d29a97d43beae0 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Wed, 7 Feb 2024 02:34:53 +0000 Subject: [PATCH] Fix: Don't issue autoreplace failed news message for command test mode. --- src/autoreplace_cmd.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/autoreplace_cmd.cpp b/src/autoreplace_cmd.cpp index 5d6b6eeaaf..727bac4d95 100644 --- a/src/autoreplace_cmd.cpp +++ b/src/autoreplace_cmd.cpp @@ -315,9 +315,10 @@ static CommandCost GetNewEngineType(const Vehicle *v, const Company *c, bool alw * @param old_veh A single (articulated/multiheaded) vehicle that shall be replaced. * @param new_vehicle Returns the newly build and refitted vehicle * @param part_of_chain The vehicle is part of a train + * @param flags The calling command flags. * @return cost or error */ -static CommandCost BuildReplacementVehicle(Vehicle *old_veh, Vehicle **new_vehicle, bool part_of_chain) +static CommandCost BuildReplacementVehicle(Vehicle *old_veh, Vehicle **new_vehicle, bool part_of_chain, DoCommandFlag flags) { *new_vehicle = nullptr; @@ -331,7 +332,7 @@ static CommandCost BuildReplacementVehicle(Vehicle *old_veh, Vehicle **new_vehic /* Does it need to be refitted */ CargoID refit_cargo = GetNewCargoTypeForReplace(old_veh, e, part_of_chain); if (!IsValidCargoID(refit_cargo)) { - if (!IsLocalCompany()) return CommandCost(); + if (!IsLocalCompany() || (flags & DC_EXEC) == 0) return CommandCost(); SetDParam(0, old_veh->index); @@ -455,7 +456,7 @@ static CommandCost ReplaceFreeUnit(Vehicle **single_unit, DoCommandFlag flags, b /* Build and refit replacement vehicle */ Vehicle *new_v = nullptr; - cost.AddCost(BuildReplacementVehicle(old_v, &new_v, false)); + cost.AddCost(BuildReplacementVehicle(old_v, &new_v, false, flags)); /* Was a new vehicle constructed? */ if (cost.Succeeded() && new_v != nullptr) { @@ -531,7 +532,7 @@ static CommandCost ReplaceChain(Vehicle **chain, DoCommandFlag flags, bool wagon for (Train *w = Train::From(old_head); w != nullptr; w = w->GetNextUnit()) { ReplaceChainItem &replacement = replacements.emplace_back(w, nullptr, 0); - CommandCost ret = BuildReplacementVehicle(replacement.old_veh, &replacement.new_veh, true); + CommandCost ret = BuildReplacementVehicle(replacement.old_veh, &replacement.new_veh, true, flags); cost.AddCost(ret); if (cost.Failed()) break; @@ -688,7 +689,7 @@ static CommandCost ReplaceChain(Vehicle **chain, DoCommandFlag flags, bool wagon } else { /* Build and refit replacement vehicle */ Vehicle *new_head = nullptr; - cost.AddCost(BuildReplacementVehicle(old_head, &new_head, true)); + cost.AddCost(BuildReplacementVehicle(old_head, &new_head, true, flags)); /* Was a new vehicle constructed? */ if (cost.Succeeded() && new_head != nullptr) {