Smart Enemy AI Enhancement


Smarter biter AI with adaptive resistance, breach reinforcement, scheduled raids, wall regen, and overhaul-mod compatibility.

Overhaul
23 hours ago
2.0
522
Combat
Owner:
IamfindingNemo
Source:
N/A
Homepage:
N/A
License:
MIT
Created:
7 months ago
Latest Version:
8.5.6 (23 hours ago)
Factorio version:
2.0
Downloaded by:
522 users

Smart Enemy AI

Adds smarter behavior to Factorio 2.0's biters and worms. Biters path around your walls when there's a way around, retreat from fights they're losing, reinforce a successful breach, and grow resistant to damage types you over-rely on. Two defensive bonuses ride along: walls and gates regenerate after a damage-free pause, and spitter/worm acid streams stop arcing over walls.

Designed for megabases — the mod ships with a UPS-budget shedding ladder so it gracefully drops features under load instead of spiking your tick time. Compatible with overhaul mods that change biter prototypes; tested with Armored Biters, Pyanodons, Space Age, and Rampant.


Features

  • Path-around-walls AI — biter groups path around your walls when an alternate route exists. Paths whose detour ratio exceeds 2× or that require destroying obstacles fall back to direct attack instead of indefinite circling.
  • Squad retreat with hysteresis — squads flee toward the nearest spawner when health drops below 50% of their gathering-time baseline within 30 seconds of dispatch. A 10-second flee-lock prevents the command from flickering as members die.
  • Flanking — large attack groups (>30 members) split into 3 sub-squads for multi-prong approaches.
  • Target priority — biters reaching their target prioritize turrets, machinery, and power infrastructure over walls, with a final area-sweep to clean up secondary targets.
  • Breach reinforcement — enemy squads converge when a turret falls nearby.
  • Adaptive resistance — biters spawn with cumulative resistance to damage types you've recently used. Per-prototype damage ledger with exponential decay (~30-minute half-life) and a hard 30% cap.
  • Mega-raids — periodic raids dispatched from a single out-of-sight enemy spawner near the most-threatened chunk. Wave size scales with evolution (capped per difficulty preset). The unit picker reads the chosen spawner's own result_units curve at the current evolution, so modded enemies and tier-mixed nests are supported automatically. One raid in flight at a time.
  • Raid alerts — a yellow skull chart-tag and bold "Raid incoming" chat message fire when the wave is fully assembled at its source spawner; the wave then holds for 30 seconds before moving, giving you the same warning window every time regardless of raid size.
  • Wall and gate regeneration — walls and gates that have taken no damage for 10 seconds regenerate to full HP over the next 10 seconds. New damage during regen pauses and resets the timer.
  • Projectile blocking — spitter and worm acid streams convert to physical projectiles that collide with walls and gates. Player turret projectiles are unaffected.

Settings

  • Difficulty Preset — Easy, Normal, or Hard. Adjusts raid frequency, resistance cap, retreat threshold, pathfinding detour tolerance, wall regen speed, and breach-ping radius. Runtime setting — change anytime mid-game without restart.
  • Enemy Advanced AI (master) — when OFF, all offensive AI features are disabled. Use if you want only the defensive features (wall regen, projectile block) and prefer vanilla biter behavior.
  • Wall Block Projectile — converts spitter/worm streams to physical projectiles. Defensive.
  • Wall Regeneration — auto-regen for walls and gates. Defensive.
  • Biter Build Adaptive Resistance — enables the variant ledger and spawn-time variant swapping.

That's the entire user-facing settings panel — five entries. Tunings that aren't worth a setting (UPS budget, regen timing, raid intervals, etc.) live as constants and stay out of your way.


Compatibility

Modded enemies are auto-detected. Prototypes with subgroup == "enemies" are recognized automatically. Modded raid composition reads the spawner's result_units list at runtime — any mod that follows Factorio's standard biter-spawner pattern works without registration.

Vulnerability-aware variants. Overhaul mods that declare biters as vulnerable to specific damage types (negative resistance percent — e.g. Pyanodons' cold spitter at fire = -100%) are handled correctly. A fire-adapted cold spitter spawns fire-resistant rather than just slightly less-fire-vulnerable.

Tested-working overhauls (per playtester confirmation): Armored Biters, Pyanodons, Space Age + Space-Age-extras, Rampant.

Custom enemy forces. Mods that create non-default enemy forces can register them via:

remote.call("smart-enemy-ai", "register_enemy_force", "your-force-name")

Nauvis-only by design. AI, raid, and adaptive-resistance subsystems run on the Nauvis surface only — Vulcanus has no classic biters, Aquilo is empty, and Gleba pentapods would need multi-leg-safe variant swapping that this release does not scope. The defensive subsystems (wall regen, projectile blocking) work on every surface.


Performance

The mod measures its own per-tick cost over a rolling 60-tick window. When the average exceeds 2 ms/tick, features shed in priority order: flank + breach reinforcement → retreat → path-around → resistance recording. Recovers stepwise once load drops. Wall regen and projectile collision are never shed — they cost effectively nothing at runtime.

In practice, on a megabase this means biters keep their basic behavior and walls keep regenerating no matter how heavy the attack pressure gets.


Multiplayer

Deterministic and replay-safe. All randomness flows through a seeded LuaRandomGenerator stored in mod state. Save/load is CRC-clean.


Diagnostics

Several remote.call("smart-enemy-ai", ...) introspection functions are available for bug reports and triage. The most useful one to attach to an issue:

/c game.print(serpent.line(remote.call("smart-enemy-ai", "diag_dump")))

Returns a structured snapshot: version, schema, feature toggles, shed level, scheduler avg cost, squad/regen/resist counts, raid state, breach-ping counters, and recent path-outcome distribution. Full list in the README.


Roadmap

The 8.x line has been a polish cycle: preset-driven difficulty (8.1), in-game welcome (8.1), breach reinforcement (8.2/8.3), single-spawner raid pipeline + serialized warning window (8.4). Suggestions and bug reports welcome.