diff --git a/src/tbtr_template_vehicle.cpp b/src/tbtr_template_vehicle.cpp index 1a87266f0d..001d36f8ad 100644 --- a/src/tbtr_template_vehicle.cpp +++ b/src/tbtr_template_vehicle.cpp @@ -149,17 +149,6 @@ TemplateReplacement* GetTemplateReplacementByGroupID(GroupID gid) return NULL; } -TemplateReplacement* GetTemplateReplacementByTemplateID(TemplateID tid) -{ - TemplateReplacement *tr; - FOR_ALL_TEMPLATE_REPLACEMENTS(tr) { - if (tr->Template() == tid) { - return tr; - } - } - return NULL; -} - bool IssueTemplateReplacement(GroupID gid, TemplateID tid) { TemplateReplacement *tr = GetTemplateReplacementByGroupID(gid); diff --git a/src/tbtr_template_vehicle.h b/src/tbtr_template_vehicle.h index e4331a1f5a..82a655a676 100644 --- a/src/tbtr_template_vehicle.h +++ b/src/tbtr_template_vehicle.h @@ -199,7 +199,6 @@ struct TemplateReplacement : TemplateReplacementPool::PoolItem<&_template_replac }; TemplateReplacement* GetTemplateReplacementByGroupID(GroupID); -TemplateReplacement* GetTemplateReplacementByTemplateID(TemplateID); bool IssueTemplateReplacement(GroupID, TemplateID); short deleteIllegalTemplateReplacements(GroupID); diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 946a28c555..61f0b7335e 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -4864,6 +4864,9 @@ CommandCost CmdTemplateReplaceVehicle(TileIndex tile, DoCommandFlag flags, uint3 Train *remainder_chain = NULL; Train *tmp_chain = NULL; TemplateVehicle *tv = GetTemplateVehicleByGroupID(incoming->group_id); + if (tv == NULL) { + return CMD_ERROR; + } EngineID eid = tv->engine_type; CommandCost buy(EXPENSES_NEW_VEHICLES); diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp index 558b5a47a2..e20770dc52 100644 --- a/src/vehicle_cmd.cpp +++ b/src/vehicle_cmd.cpp @@ -1224,10 +1224,12 @@ CommandCost CmdDeleteTemplateVehicle(TileIndex tile, DoCommandFlag flags, uint32 bool should_execute = (flags & DC_EXEC) != 0; if (should_execute) { - // Remove a corresponding template replacement if existing - TemplateReplacement *tr = GetTemplateReplacementByTemplateID(del->index); - if (tr != NULL) { - delete tr; + // Remove corresponding template replacements if existing + TemplateReplacement *tr; + FOR_ALL_TEMPLATE_REPLACEMENTS(tr) { + if (tr->Template() == del->index) { + delete tr; + } } delete del;