Coordinate-based biter generation

Place to get help with not working mods / modding interface.
Post Reply
aljo
Burner Inserter
Burner Inserter
Posts: 18
Joined: Sat Nov 10, 2018 7:54 am
Contact:

Coordinate-based biter generation

Post by aljo »

I'm entirely new to Factorio modding, and frankly I probably won't even post this mod as it's just something I want to try out locally, but I'm trying to disable biter generation below y = 0. TL;DR, I have no idea what I'm doing. I suspect it's the autoplace specification that I have to modify (https://wiki.factorio.com/Types/AutoplaceSpecification), for spawners and units (https://wiki.factorio.com/Prototype/Entity#autoplace), but honestly I feel a little out of my league for what I expect is a simple thing. Ideally, the normal biter generation specification would be otherwise unchanged, it would just "skip" anything below y = 0.

Any help would be appreciated.

Bilka
Factorio Staff
Factorio Staff
Posts: 3128
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: Coordinate-based biter generation

Post by Bilka »

You can use the following code in the data stage. (Place it in data*.lua).

Code: Select all

local noise = require("noise")

for k,v in pairs(data.raw["unit-spawner"]) do -- spawners
  if v.autoplace and v.autoplace.probability_expression then
    v.autoplace.probability_expression = noise.less_or_equal(0, noise.var("y")) * v.autoplace.probability_expression
  end
end

for k,v in pairs(data.raw["turret"]) do -- worms
  if v.autoplace and v.autoplace.probability_expression then
    v.autoplace.probability_expression = noise.less_or_equal(0, noise.var("y")) * v.autoplace.probability_expression
  end
end
Note that in Factorio, negative Y is up, so this means biters only spawn on the south half of the map. If you wanted it the other way around (only on the north half), just turn around the comparison: "v.autoplace.probability_expression = noise.less_than(noise.var("y"), 0) * v.autoplace.probability_expression".

You can find more info about noise expression (which make the magic happen in the above code/most of map gen) on this wiki page: https://wiki.factorio.com/Types/NoiseExpression
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.

aljo
Burner Inserter
Burner Inserter
Posts: 18
Joined: Sat Nov 10, 2018 7:54 am
Contact:

Re: Coordinate-based biter generation

Post by aljo »

Oh, this is perfect. Thank you so much. Also, yes, I did intend for it to be flipped so that south has no biters. Thanks for that tip :)

Fwiw, my goal is to have a ribbon world with biters in the north, but freedom to expand in the south, plus Natural Evolution Enemies and Rampant so that I can have the intensity of those two mods but in a very specific, easy-to-focus-on defense section. Effectively a mixture of the casual gameplay that I love above Factorio plus a reasonable dash of military logistics and excitement.

Seriously though, this is just perfect. 10/10 on that response time too, wow.

Post Reply

Return to “Modding help”