Bastion Works: Towers, Turrets and Targeting Kit
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
| Mode | Picks |
|---|---|
first | the enemy furthest along the path (highest progress) |
last | the enemy least far along the path |
nearest | the closest enemy to the turret |
strongest | the enemy with the most health left |
weakest | the 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 whendefineadds 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 whenashould be picked overb. Candidates carryid,pos,dist,progress,health.has(name: string): boolean: whether a mode is known.inArc(ctx: any, pos: { number }): (boolean, string?): whether a turret described byctx = { 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 forindirectturrets).eligible(cands: { any }, ctx: any): { any }: candidates it can engage, each given itsdistfrom the turret.order(cands: { any }, mode: string): { any }: sorts best-first in place (unknown modes count asfirst) and returns the list.pick(cands: { any }, mode: string, ctx: any, accept: ((any) -> boolean)?): any: the best candidate, ornil.acceptcan veto one (e.g. line of sight); up to six are tried.