Issue
The train facing up in this layout is behind the train stop after it is cloned two times via LuaSurface::clone_brush resulting in "no path" after it is switched back to automatic mode. This is because each clone slightly moves the train upwards.How to reproduce
Use this savegame and this script in the editor's "Run Lua" tool on the area with concrete underneath:Code: Select all
local surface = game.player.surface
local sx, sy = unpack(area.left_top)
local ex, ey = unpack(area.right_bottom)
local dx = ex - sx + 10
local loco = unpack(surface.find_entities_filtered { area = area, name = "locomotive" })
if loco then
game.print(serpent.line(loco.position))
loco.train.manual_mode = false
end
for i=1,2 do
local clone_positions = {}
for _, tile in pairs(surface.find_tiles_filtered {
area = { {sx, sy,}, {ex, ey}},
name = "refined-concrete",
}) do
if tile.name == "refined-concrete" then
table.insert(clone_positions, tile.position)
end
end
game.player.surface.clone_brush {
source_offset = { x = 0, y = 0 },
source_positions = clone_positions,
destination_surface = surface,
destination_offset = { x = dx, y = 0},
clone_tiles = true,
clone_entities = true,
expand_map = true,
}
local dest = { { sx + dx, sy}, { ex + dx, ey }}
local loco = unpack(surface.find_entities_filtered { area = dest, name = "locomotive" })
if loco then
game.print(serpent.line(loco.position))
loco.train.manual_mode = false
end
-- clone a 2nd time
sx = sx + dx
ex = ex + dx
end
Notes
- Only clone_brush() does this. clone_area() clones the trains perfectly
- The train facing down is also affected but also moves up, so it stays in front of the train stop
- Cloning trains stopped on a completely straight track is fine
- This is not an academic issue, Space Exploration clones spaceships (entities on spaceship floor-tiles) via clone_brush() at least two times - from planet-surface to travel-surface and from travel-surface to destination planet-surface - and a ship might make waystops before finally releasing trains on-board (so 2*n clones)
- It is deseriable to have that bend before the stop because spaceships have a tile-limit, which requires to design them as compact as possible
Thoughts
The position error accumulates with each clone so it would be best if clone_brush() made at least sure that the leading locomotive stays in place (but what is "leading" with double-ended trains?). It might be easier to be more lenient when switching a train from manual to automatic and checking if it is already at the currently scheduled train stop.EDIT: The locomotive that should stay put is decidable from the waiting state of the train. It's the one next to the stop the train is waiting at. As long as the caller of clone_brush() restores automatic mode after cloning this should propagate correctly.