TBTR: Fix CmdDeleteVirtualTrain deleting non-head vehicles

Deleting a non-head virtual vehicle left a dangling next pointer on
the previous vehicle. Delete the head instead.
Check for non-virtual vehicles
This commit is contained in:
Jonathan G Rennison
2020-10-09 00:39:42 +01:00
parent 0d4a023c1d
commit 65cdb35898

View File

@@ -1109,7 +1109,12 @@ CommandCost CmdDeleteVirtualTrain(TileIndex tile, DoCommandFlag flags, uint32 p1
return CMD_ERROR;
}
vehicle = vehicle->First();
Train* train = Train::From(vehicle);
if (!train->IsVirtual()) {
return CMD_ERROR;
}
bool should_execute = (flags & DC_EXEC) != 0;