Skip to content

Add a working NPC AI engine (brains, orders, combat styles, aranha species) - #73

Open
cybervand wants to merge 5 commits into
themeldingwars:masterfrom
cybervand:feature/npc-ai-engine
Open

Add a working NPC AI engine (brains, orders, combat styles, aranha species)#73
cybervand wants to merge 5 commits into
themeldingwars:masterfrom
cybervand:feature/npc-ai-engine

Conversation

@cybervand

Copy link
Copy Markdown
Contributor

(note: I'm going to be real with you lads. This PR was almost entirely
done by Fable 5 for the creation of the engine and GPT 5.6 Sol using Ghidra
for the reverse engineering. There was alot of input and testing done by me.
It works but there is still alot of work for ai to be done. what helped tremendously,
was building my own tools for the help of the reverse engineering. that will come shortly.)

Replaces the AIEngine stub with a complete server-side NPC brain system,
developed and play-tested against live gameplay on the Firefall client:

  • Brains: one BrainState per living NPC, 4 Hz think, target selection with
    memory, leash and return-home, per-entity passive override
  • Orders API: AttackEntity / DefendPoint / MoveTo / FollowEntity records as
    the seam between content (encounters, missions) and brains
  • Behavior profiles derived from SDB data only (no per-monster config):
    speeds and faction from the monster row, movement class from the rig name
    (ground / flying / stationary / climber), combat style from real weapon
    ranges (melee / ranged / sniper / artillery hold distances)
  • Combat: ballistic aim solutions from ammunition gravity and speed (low
    arc, high arc for artillery and blocked muzzles, 45-degree maximum-reach,
    hold-fire when the target is above ballistic reach), muzzle-blocked
    probing, cliff/verticality handling, visible NPC projectiles via
    AbilityProjectileFired
  • Creature separation: body-width discs prevent packs from stacking into
    one point
  • Species layer: partial-class files per species; AIEngine.Aranha.cs ships
    first with hull climbing and latching, per-NPC perch points, pounce leaps
    at players, random leaps onto thumper hulls, and pack-hunting roles
    (direct attackers, circling flankers, leapers, per-NPC gait)

The thumper encounter gets its defense gameplay on top of the AI
(second commit):

  • Escalating attack waves while the thumper drills, spawned on a
    terrain-snapped ring: workers first, a sieger from wave 2, a spitting
    thresher from wave 4. Half of each wave is ordered onto the thumper via
    the Orders API; the other half runs default AI and hunts players.
  • Thumper health: attackers reduce its integrity; at zero the thumper is
    destroyed and the encounter fails.
  • On both endings - the thumper is destroyed, or it completes and leaves -
    all wave-spawned enemies are removed with it.
  • Hive sites (HiveIndex + "hive add | list | clear" admin command):
    authored underground-population zones, persisted as JSON per zone.
    Thumping inside a hive wakes a dense, fast eruption instead of the
    default trickle - wave interval, size, and alive cap all scale with
    distance to the hive center.

Also fixes a crash found while testing this PR with LoadMapsCollision
enabled (third commit): SegmentRayCast read a body handle from a static
collidable when a projectile hit zone terrain, which stops the process
with a Bepu assertion.

New admin commands:

  • hive add [radius] [burst] - plants a hive site at your position
    (defaults: radius 120 m, burst 50). Thumping inside the zone will result
    with the death of the thumper, its a dense wave, thumping near the edges
    will have a falloff.
  • hive list - lists the hive sites of the zone with distance to you
  • hive clear - removes all hive sites of the zone
  • npcfx show | muzzle <fraction> | hardpoint <id> | offset <x> <y> <z> -
    live-tunes the NPC projectile FX anchoring (muzzle height on the rig
    capsule, client hardpoint, visual offset)
  • npcfx aimpoint - firing-range debug mode: armed NPCs stand and fire at
    a fixed point instead of hunting players. (this is used for finetuning,
    the ai in the engine has a firing offset of 0,0,0 which will result in
    some of them unable to shoot)
  • pacify <on|off> [all] - toggles NPC aggression for the admin target or
    for every live NPC. Useful for finetuning attacks

Supporting additions:

  • PhysicsEngine.GetGroundHeight: static-geometry ground probe with an
    optional walkable kinematic body (lets climbers walk on thumper hulls)
  • MovementRelay.BroadcastCharacterPose: extracted from CharacterMovementInput
    and reused for server-moved NPCs (also keeps NPC physics bodies in sync)
  • ThumperEntity: CurrentHealth / Damage / IsAttackable / IsDestroyed
  • CharacterEntity.GetNpcMuzzleHeight: muzzle height from the scaled rig capsule

Not in this PR, coming as follow-ups: mesh-accurate NPC hitboxes built
from bMesh render geometry (we have this working; it needs a careful merge
with the new pose-shape hit system from the weapon-sim update), and the
species roster work for the remaining aranha variants.

All comments follow ASD-STE100 (Simplified Technical English).

Co-Authored-By: Claude Fable 5 noreply@anthropic.com

🤖 Generated with Claude Code

cybervand and others added 5 commits September 3, 2026 20:59
…ecies)

(note: I'm going to be real with you lads. This PR was almost entirely
done by Fable 5 for the creation of the engine and GPT 5.6 Sol using Ghidra
for the reverse engineering. There was alot of input and testing done by me.
It works but there is still alot of work for ai to be done. what helped tremendously,
was building my own tools for the help of the reverse engineering. that will come shortly.)

Replaces the AIEngine stub with a complete server-side NPC brain system,
developed and play-tested against live gameplay on the Firefall client:

- Brains: one BrainState per living NPC, 4 Hz think, target selection with
  memory, leash and return-home, per-entity passive override
- Orders API: AttackEntity / DefendPoint / MoveTo / FollowEntity records as
  the seam between content (encounters, missions) and brains
- Behavior profiles derived from SDB data only (no per-monster config):
  speeds and faction from the monster row, movement class from the rig name
  (ground / flying / stationary / climber), combat style from real weapon
  ranges (melee / ranged / sniper / artillery hold distances)
- Combat: ballistic aim solutions from ammunition gravity and speed (low
  arc, high arc for artillery and blocked muzzles, 45-degree maximum-reach,
  hold-fire when the target is above ballistic reach), muzzle-blocked
  probing, cliff/verticality handling, visible NPC projectiles via
  AbilityProjectileFired
- Creature separation: body-width discs prevent packs from stacking into
  one point
- Species layer: partial-class files per species; AIEngine.Aranha.cs ships
  first with hull climbing and latching, per-NPC perch points, pounce leaps
  at players, random leaps onto thumper hulls, and pack-hunting roles
  (direct attackers, circling flankers, leapers, per-NPC gait)

Supporting additions:
- PhysicsEngine.GetGroundHeight: static-geometry ground probe with an
  optional walkable kinematic body (lets climbers walk on thumper hulls)
- MovementRelay.BroadcastCharacterPose: extracted from CharacterMovementInput
  and reused for server-moved NPCs (also keeps NPC physics bodies in sync)
- ThumperEntity: CurrentHealth / Damage / IsAttackable / IsDestroyed
- CharacterEntity.GetNpcMuzzleHeight: muzzle height from the scaled rig capsule

All comments follow ASD-STE100 (Simplified Technical English).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Gives the thumper encounter its defense gameplay, driven by the AI engine:

- Escalating attack waves while the thumper drills: workers first, then a
  sieger from wave 2 and a spitting thresher from wave 4. Waves spawn on a
  terrain-snapped ring around the thumper. One half of each wave gets an
  AttackEntityOrder for the thumper; the other half uses default AI
  behavior and prefers players.
- An alive cap keeps the pressure bounded; a destroyed thumper fails the
  encounter and removes its attackers.
- ThumperEntity health makes the thumper a real objective: attackers
  reduce its integrity, and at zero it is destroyed.
- Hive sites (new HiveIndex, admin command "hive add | list | clear"):
  authored underground-population zones, persisted as JSON per zone. A
  thumper that drills inside a hive site wakes a dense, fast eruption
  instead of the default trickle. The distance to the hive center controls
  the wave interval, the wave size, and the alive cap.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
With LoadMapsCollision enabled, a projectile ray that hits the zone
terrain reached a BodyHandle read on a static collidable. Bepu stops the
process with an assertion in that case. Check the mobility first.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- npcfx: live-tunes the NPC projectile FX anchoring (muzzle height on the
  rig capsule, client hardpoint, visual offset), plus a firing-range debug
  mode that makes armed NPCs fire at a fixed point
- pacify: toggles NPC aggression for the admin target, or for every live
  NPC with the all argument

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
A scope-in request can wait in the queue while its entity dies or
despawns. NPCs that die in combat make this frequent. The direct
dictionary index then stops the server with a KeyNotFoundException
(seen live during a hive-eruption test). Use TryGetValue in ScopeIn
and ScopeOut.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@cybervand

Copy link
Copy Markdown
Contributor Author

Here is the hive system and the AI waves from this PR running live (2 min, unlisted):

https://youtu.be/JMySznVJ64U

A hive site is planted with the admin command, then a thumper wakes it. The waves spawn, half attack the thumper, the rest hunt the player - climbing, leaping, and pack behavior all visible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant