Prioritize Enemies PATCH


Mod fixing issue with no creating biters nests in heavy forest. Now trees dont overwrite enemy bases.

Content
2 years ago
1.1
442
Enemies

g Code Optimisation

2 years ago
(updated 2 years ago)

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
2 years ago

Hey.
It's really nice you improved this mod.
Your code has been put to 0.2.2 release.

2 years ago
(updated 2 years ago)

You're welcome mate!
Keep in mind that keeping the two redundant blocks (and relative functions) will only set spawners and worms at "b[enemy]...".
Trees being set at "z[tree]..." are below both worms and spawners anyways, as vanilla order is "a[tree]..." & "b[enemy]...", you could basically just pick the last four rows to be good to go

2 years ago

ok, thanks ;)

New response