Fix deleting an in-use template vehicle, only updating the first group.

pull/8/head
Jonathan G Rennison 8 years ago
parent 31136bac50
commit b7aac40da8

@ -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);

@ -199,7 +199,6 @@ struct TemplateReplacement : TemplateReplacementPool::PoolItem<&_template_replac
};
TemplateReplacement* GetTemplateReplacementByGroupID(GroupID);
TemplateReplacement* GetTemplateReplacementByTemplateID(TemplateID);
bool IssueTemplateReplacement(GroupID, TemplateID);
short deleteIllegalTemplateReplacements(GroupID);

@ -4280,6 +4280,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);

@ -1183,10 +1183,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;

Loading…
Cancel
Save