Log inGet started
Package

targeting.module

README.md

turretsKit.targeting

Which enemy a turret picks, as pure functions. A candidate is { id, pos = { x, y, z }, progress (0..1 along its path), health } (target sources may add more). eligible keeps the candidates the turret can engage (inside range and minimum range, inside its turn limits); pick orders what is left by the targeting mode and returns the best.

Called by the turretsKit.Turret component's scan on the peer in charge; turretsKit.api re-exports define as defineTargeting and lists modes through modes().

Modes

ModePicks
firstthe enemy furthest along the path (highest progress)
lastthe enemy least far along the path
nearestthe closest enemy to the turret
strongestthe enemy with the most health left
weakestthe enemy with the least health left

Ties fall back to progress (furthest first), then to the entity id, so every peer running the same numbers picks the same enemy.

Fields

  • MODES: the mode names, in order (grows when define adds one).
  • LABELS: one human-readable line per mode.

Functions

  • define(name: string, betterFn: (any, any) -> boolean, label: string?): adds or replaces a mode; betterFn(a, b) returns true when a should be picked over b. Candidates carry id, pos, dist, progress, health.
  • has(name: string): boolean: whether a mode is known.
  • inArc(ctx: any, pos: { number }): (boolean, string?): whether a turret described by ctx = { origin, homeYaw (rad), range, minRange, yawMin, yawMax, pitchMin, pitchMax (deg), indirect, aimHeight } can engage a point; when not, the reason: "range", "tooClose", "yaw" or "pitch" (pitch is not checked for indirect turrets).
  • eligible(cands: { any }, ctx: any): { any }: candidates it can engage, each given its dist from the turret.
  • order(cands: { any }, mode: string): { any }: sorts best-first in place (unknown modes count as first) and returns the list.
  • pick(cands: { any }, mode: string, ctx: any, accept: ((any) -> boolean)?): any: the best candidate, or nil. accept can veto one (e.g. line of sight); up to six are tried.