Log inGet started
Package

brain.module

README.md

turretsKit.brain

A turret's mind, built on Watchful Minds' state machine (aiKit.fsm) and shaped like aiKit's own turret preset: it sweeps its arc, locks on to what it can engage, keeps aiming at the last spot for a moment when the target is lost, then sweeps again.

The machine runs only on the peer in charge of the turret. The turretsKit.Turret component creates it with new and supplies the verbs it calls on the runtime r: r:scan(dt), r:aimAt(c, dt), r:engage(c, dt), r:sweep(dt), r:stopFiring() and r:passiveTick(dt).

States

StateMachineWhat it does
sweepactiveNothing to engage: swings back and forth across the arc. Goes to track on a target.
trackactiveTurns onto the target (its lead point) and fires when lined up. Goes to hold when it is lost.
holdactiveStops firing and keeps aiming where the target was for HOLD_TIME (or r.holdTime); back to track if re-acquired, else sweep.
idlepassiveSupport beacons and walls: no aiming, runs r:passiveTick(dt).

Fields

  • SWEEP, SWEEP_SPEED: sweep width (degrees) and speed, read from aiKit's turret preset (sweep / sweepSpeed), falling back to 80 and 35.
  • HOLD_TIME: 1.0 second.
  • ACTIVE: the turretsKit.turret machine definition (sweep / track / hold).
  • PASSIVE: the turretsKit.passive machine definition (idle).

Functions

  • new(r: any, passive: boolean): any: creates a machine for runtime r (passive for support and wall roles), stores it in r.machine and returns it.