How to control what bases/worms are placed on base expansion?

Place to get help with not working mods / modding interface.
Quorken
Burner Inserter
Burner Inserter
Posts: 16
Joined: Mon Aug 18, 2025 3:53 pm
Contact:

How to control what bases/worms are placed on base expansion?

Post by Quorken »

Is there any way to control/influence exactly what nests or worms are placed when enemies expand, without writing your own placement logic in control.lua? I know you can set the evolution % requirement (build_base_evolution_requirement), but can you set specific weights for particular nests, or otherwise influence which nests generate?

Like, how does the game choose whether it places a biter or spitter nest when expanding? Or a worm instead? Is it a 50/50 chance of worm or nest? And then an equal chance of each valid nest/worm prototype?

I know you can control what nests spawn at worldgen through the autoplace stuff - my concern is base expansions after worldgen.

I'm asking because I'm writing a mod that adds a "wrecking-ball biter"; this would be a rare, fairly strong biter with a custom AI, that can "charge" at targets, destroying pretty much everything in its path like a Demolisher. It essentially acts like a force multiplier, as it punches holes clean through your walls, allowing other biters through - hopefully encouraging more interesting defense designs than "monolithic wall with turrets every other tile." For example, you might want partitions, breaking your wall up into cells, so if one cell is breached, the others will stay intact. Cliffs might also be far more valuable, as they are something this biter couldn't wreck.

I know how to implement the AI & effects - that's not a problem. However, spawning it is something I'm not so sure about. Ideally, I'd leverage the built in spawning infrastructure, by adding a special nest that only spawns this new biter, and which generates (both on generation and on expansion) pretty rarely. But I'm not sure I can control this nest's rarity/frequency.

I could set its evolution requirement to 1.0 (something unattainable), and then I could do some control.lua stuff to precisely control its placement, like occasionally replacing biter bases in on_biter_base_built - but it'd be nice to be able to just set a weight value or something.

if there isn't really a way to have more fine-grained control over what nests spawn - without writing your own, custom control.lua logic that determines exactly what nests spawn where - I can submit a Modding Interface request. Probably would request that you could at least set weights for each nest (default of 1) and worm prototype.

Edit:
Ideally, you could define something like an expansion_placement_expression(x, y, evolution_factor), which takes those arguments - x, y, and evolution_factor - and returns which base should be spawned (or a list of possible bases). So you could have something like "desert biters only spawn in desert regions", and this would enforce that, by checking the moisture and elevation at that location. But, this isn't a formal modding interface request.

Edit 2:
Or an "on_about_to_build_base" event, which would provide which biter is about to be used to create a nest/worm; if you destroy the biter yourself, you could either prevent that base from being built, or "consume" it to create a nest w/ your own logic - without having to write your own base expansion logic from scratch.
Bilka
Factorio Staff
Factorio Staff
Posts: 3597
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: How to control what bases/worms are placed on base expansion?

Post by Bilka »

Right now it's picked randomly (meaning with a random number generator) from all the entities with the correct autoplace control and large enough evolution factor. If you want something else I would suggest to make a modding interface request. Looks like the current position should indeed be available in BuildBaseBehavior::selectEntityToBuild to potentially make a more complicated condition.

Something that should already work is to make the collision mask of the spawners collide with the tiles in the areas where you do not want them, since the collision is checked before placement.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
Quorken
Burner Inserter
Burner Inserter
Posts: 16
Joined: Mon Aug 18, 2025 3:53 pm
Contact:

Re: How to control what bases/worms are placed on base expansion?

Post by Quorken »

Okay, I'll make an interface request.

W/ the collision mask - is it used to cull the list of valid spawners before it even attempts to place one (e.g. filter(spawnerPrototypes, doesntCollide)), or does it pick one to attempt to place, then check? W/ the second option, I'm wondering if it would then reroll the nest to place, fail to place one at all, or something else.
Bilka
Factorio Staff
Factorio Staff
Posts: 3597
Joined: Sat Aug 13, 2016 9:20 am
Contact:

Re: How to control what bases/worms are placed on base expansion?

Post by Bilka »

Quorken wrote: Wed Sep 10, 2025 6:01 am
W/ the collision mask - is it used to cull the list of valid spawners before it even attempts to place one (e.g. filter(spawnerPrototypes, doesntCollide)), or does it pick one to attempt to place, then check? W/ the second option, I'm wondering if it would then reroll the nest to place, fail to place one at all, or something else.
It doesn't consider the collision mask when picking (selectEntityToBuild), only when building later. If the entity can't be built within a certain radius, it will not build anything and set BuildBaseState::Failed, which eventually trickles down to max_failed_behavior_count so the group will get destroyed if it happens too much. But before that happens it will wander and then run other behaviours as normal.
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
Post Reply

Return to “Modding help”