Hello mate, here's some improvements to the code, should be ok to raise it to final fixes and just skip the redundant parts
-- Returns true if autoplace force = "enemy"
local function is_enemy(enemy)
if enemy.autoplace.force == "enemy" then return true end
end
-- Returns true if turret name contains the word "-worm-"
local function is_worm(turret)
if string.find(turret.name, "-worm-", 1, true) then return true end
end
for _, spawner in pairs(data.raw["unit-spawner"]) do
if spawner.autoplace and is_enemy(spawner) then
spawner.autoplace.order = "b[enemy]-a[spawner]" -- [This is redundant as trees are already marked to Z (see below)]
end
end
for _, turret in pairs(data.raw.turret) do
if turret.autoplace and is_worm(turret) and is_enemy(turret) then
turret.autoplace.order = "b[enemy]-b[worm]" -- [This is redundant as trees are already marked to Z (see below)]
end
end
for _, tree in pairs(data.raw.tree) do
if tree.autoplace then
tree.autoplace.order = "z[tree]-b[forest]" -- [same order as "Alien Biomes"]
end
end