diff --git a/src/tbtr_template_vehicle_func.cpp b/src/tbtr_template_vehicle_func.cpp index d2a68b301f..86d84bb155 100644 --- a/src/tbtr_template_vehicle_func.cpp +++ b/src/tbtr_template_vehicle_func.cpp @@ -346,18 +346,21 @@ int NumTrainsNeedTemplateReplacement(GroupID g_id, const TemplateVehicle *tv) return count; } // refit each vehicle in t as is in tv, assume t and tv contain the same types of vehicles -void CmdRefitTrainFromTemplate(Train *t, TemplateVehicle *tv, DoCommandFlag flags) +CommandCost CmdRefitTrainFromTemplate(Train *t, TemplateVehicle *tv, DoCommandFlag flags) { + CommandCost cost(t->GetExpenseType(false)); + while (t && tv) { // refit t as tv uint32 cb = GetCmdRefitVeh(t); - DoCommand(t->tile, t->index, tv->cargo_type | tv->cargo_subtype << 8 | (1 << 16) | (1 << 31), flags, cb); + cost.AddCost(DoCommand(t->tile, t->index, tv->cargo_type | tv->cargo_subtype << 8 | (1 << 16) | (1 << 31), flags, cb)); // next t = t->GetNextUnit(); tv = tv->GetNextUnit(); } + return cost; } /** using cmdtemplatereplacevehicle as test-function (i.e. with flag DC_NONE) is not a good idea as that function relies on diff --git a/src/tbtr_template_vehicle_func.h b/src/tbtr_template_vehicle_func.h index 58365d187b..72f9e385a8 100644 --- a/src/tbtr_template_vehicle_func.h +++ b/src/tbtr_template_vehicle_func.h @@ -46,7 +46,7 @@ int NumTrainsNeedTemplateReplacement(GroupID, const TemplateVehicle*); CommandCost TestBuyAllTemplateVehiclesInChain(TemplateVehicle *tv, TileIndex tile); -void CmdRefitTrainFromTemplate(Train *t, TemplateVehicle *tv, DoCommandFlag); +CommandCost CmdRefitTrainFromTemplate(Train *t, TemplateVehicle *tv, DoCommandFlag); void BreakUpRemainders(Train *t); bool TemplateVehicleContainsEngineOfRailtype(const TemplateVehicle*, RailType); diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index c28b27fd4d..194fba4e37 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -5659,7 +5659,7 @@ CommandCost CmdTemplateReplaceVehicle(TileIndex tile, DoCommandFlag flags, uint3 // refit, only if the template option is set so if (use_refit && (need_refit || need_replacement)) { - CmdRefitTrainFromTemplate(new_chain, tv, flags); + buy.AddCost(CmdRefitTrainFromTemplate(new_chain, tv, flags)); } if (new_chain && remainder_chain) {