@jgengine/core 0.8.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (303) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/dist/ai/flock.d.ts +36 -0
  3. package/dist/ai/flock.js +182 -0
  4. package/dist/ai/groupAssist.d.ts +19 -0
  5. package/dist/ai/groupAssist.js +59 -0
  6. package/dist/ai/laneSelect.d.ts +21 -0
  7. package/dist/ai/laneSelect.js +37 -0
  8. package/dist/ai/mobBrain.d.ts +68 -0
  9. package/dist/ai/mobBrain.js +115 -0
  10. package/dist/ai/spawnDirector.d.ts +13 -0
  11. package/dist/ai/spawnDirector.js +41 -17
  12. package/dist/ai/spawnPoint.d.ts +5 -0
  13. package/dist/ai/spawnPoint.js +5 -0
  14. package/dist/ai/threat.d.ts +2 -0
  15. package/dist/ai/threat.js +34 -0
  16. package/dist/audio/audioFalloff.d.ts +5 -2
  17. package/dist/audio/music.d.ts +53 -0
  18. package/dist/audio/music.js +34 -0
  19. package/dist/audio/synth.d.ts +60 -0
  20. package/dist/audio/synth.js +8 -0
  21. package/dist/authoring.d.ts +14 -0
  22. package/dist/authoring.js +14 -0
  23. package/dist/cartridge/runtime.d.ts +15 -0
  24. package/dist/cartridge/runtime.js +556 -0
  25. package/dist/cartridge/spec.d.ts +188 -0
  26. package/dist/cartridge/spec.js +19 -0
  27. package/dist/cartridge/validate.d.ts +2 -0
  28. package/dist/cartridge/validate.js +78 -0
  29. package/dist/combat/abilityKit.d.ts +17 -2
  30. package/dist/combat/abilityKit.js +62 -13
  31. package/dist/combat/castRunner.d.ts +40 -0
  32. package/dist/combat/castRunner.js +56 -0
  33. package/dist/combat/comboPoints.d.ts +14 -0
  34. package/dist/combat/comboPoints.js +52 -0
  35. package/dist/combat/defensiveWindow.d.ts +1 -1
  36. package/dist/combat/defensiveWindow.js +5 -3
  37. package/dist/combat/dotField.d.ts +43 -0
  38. package/dist/combat/dotField.js +48 -0
  39. package/dist/combat/projectiles.d.ts +33 -12
  40. package/dist/combat/projectiles.js +214 -129
  41. package/dist/combat/regenShield.d.ts +35 -0
  42. package/dist/combat/regenShield.js +45 -0
  43. package/dist/combat/resistance.d.ts +16 -4
  44. package/dist/combat/resistance.js +43 -7
  45. package/dist/combat/resourcePool.d.ts +20 -0
  46. package/dist/combat/resourcePool.js +55 -0
  47. package/dist/combat/shotOrigin.d.ts +52 -0
  48. package/dist/combat/shotOrigin.js +86 -0
  49. package/dist/combat/telegraph.d.ts +25 -0
  50. package/dist/combat/telegraph.js +47 -0
  51. package/dist/crafting/recipe.js +4 -1
  52. package/dist/devtools/devtools.d.ts +72 -24
  53. package/dist/devtools/devtools.js +449 -101
  54. package/dist/devtools/transformTunables.js +3 -3
  55. package/dist/devtools/tunableSchema.d.ts +140 -0
  56. package/dist/devtools/tunableSchema.js +476 -0
  57. package/dist/editor/commands.d.ts +65 -0
  58. package/dist/editor/commands.js +193 -0
  59. package/dist/editor/document.d.ts +40 -0
  60. package/dist/editor/document.js +153 -0
  61. package/dist/editor/index.d.ts +30 -0
  62. package/dist/editor/index.js +6 -0
  63. package/dist/editor/types.d.ts +69 -0
  64. package/dist/editor/types.js +29 -0
  65. package/dist/faction/factions.d.ts +33 -0
  66. package/dist/faction/factions.js +76 -0
  67. package/dist/faction/reputation.d.ts +32 -0
  68. package/dist/faction/reputation.js +82 -0
  69. package/dist/game/chat.d.ts +2 -0
  70. package/dist/game/chat.js +9 -1
  71. package/dist/game/chatFilter.d.ts +15 -0
  72. package/dist/game/chatFilter.js +55 -0
  73. package/dist/game/connectedPlayers.d.ts +28 -0
  74. package/dist/game/connectedPlayers.js +21 -0
  75. package/dist/game/controlGate.d.ts +4 -0
  76. package/dist/game/controlGate.js +7 -0
  77. package/dist/game/defineGame.d.ts +44 -1
  78. package/dist/game/defineGame.js +1 -0
  79. package/dist/game/events.d.ts +25 -0
  80. package/dist/game/gamePhase.d.ts +20 -0
  81. package/dist/game/gamePhase.js +21 -0
  82. package/dist/game/keyValueStore.d.ts +25 -0
  83. package/dist/game/keyValueStore.js +61 -0
  84. package/dist/game/levelSequence.d.ts +24 -2
  85. package/dist/game/levelSequence.js +51 -2
  86. package/dist/game/lootTable.d.ts +14 -1
  87. package/dist/game/lootTable.js +28 -7
  88. package/dist/game/modelAnimation.d.ts +8 -0
  89. package/dist/game/modelAnimation.js +18 -0
  90. package/dist/game/playableGame.d.ts +116 -4
  91. package/dist/game/playableGame.js +1 -1
  92. package/dist/game/quest.d.ts +7 -3
  93. package/dist/game/quest.js +17 -8
  94. package/dist/game/race.d.ts +39 -1
  95. package/dist/game/race.js +96 -11
  96. package/dist/game/recordBook.d.ts +27 -0
  97. package/dist/game/recordBook.js +86 -0
  98. package/dist/game/talents.d.ts +47 -0
  99. package/dist/game/talents.js +140 -0
  100. package/dist/index.d.ts +8 -0
  101. package/dist/index.js +8 -0
  102. package/dist/input/actionBindings.d.ts +2 -0
  103. package/dist/input/actionBindings.js +1 -0
  104. package/dist/input/axisInput.d.ts +33 -3
  105. package/dist/input/axisInput.js +60 -4
  106. package/dist/input/bindingOverrides.d.ts +25 -0
  107. package/dist/input/bindingOverrides.js +95 -0
  108. package/dist/input/pointerAxis.d.ts +30 -0
  109. package/dist/input/pointerAxis.js +31 -0
  110. package/dist/input/touchScheme.d.ts +6 -0
  111. package/dist/input/touchScheme.js +45 -7
  112. package/dist/interaction/contextMenu.d.ts +1 -0
  113. package/dist/interaction/contextMenu.js +1 -0
  114. package/dist/interaction/proximityPrompt.d.ts +3 -1
  115. package/dist/interaction/proximityPrompt.js +3 -3
  116. package/dist/meta/changelog.d.ts +1 -1
  117. package/dist/meta/changelog.js +44 -1
  118. package/dist/movement/dash.d.ts +3 -0
  119. package/dist/movement/dash.js +19 -5
  120. package/dist/movement/glideModel.d.ts +44 -0
  121. package/dist/movement/glideModel.js +54 -0
  122. package/dist/movement/grappleSwing.d.ts +34 -0
  123. package/dist/movement/grappleSwing.js +56 -0
  124. package/dist/movement/leaderTrail.d.ts +29 -0
  125. package/dist/movement/leaderTrail.js +67 -0
  126. package/dist/movement/movementModel.d.ts +4 -0
  127. package/dist/movement/movementModel.js +13 -0
  128. package/dist/movement/playerMovement.d.ts +41 -0
  129. package/dist/movement/playerMovement.js +181 -0
  130. package/dist/movement/steering.d.ts +27 -0
  131. package/dist/movement/steering.js +40 -0
  132. package/dist/multiplayer/feedWriteGate.d.ts +10 -0
  133. package/dist/multiplayer/feedWriteGate.js +12 -0
  134. package/dist/multiplayer/presenceModel.d.ts +14 -2
  135. package/dist/multiplayer/presenceModel.js +15 -3
  136. package/dist/nav/corridors.d.ts +30 -0
  137. package/dist/nav/corridors.js +69 -0
  138. package/dist/nav/navGrid.js +30 -4
  139. package/dist/nav/railGraph.d.ts +66 -0
  140. package/dist/nav/railGraph.js +129 -0
  141. package/dist/nav/timetable.d.ts +41 -0
  142. package/dist/nav/timetable.js +94 -0
  143. package/dist/physics/buoyancy.d.ts +6 -0
  144. package/dist/physics/buoyancy.js +14 -0
  145. package/dist/physics/flowTube.d.ts +32 -0
  146. package/dist/physics/flowTube.js +64 -0
  147. package/dist/physics/forceVolume.d.ts +27 -0
  148. package/dist/physics/forceVolume.js +38 -0
  149. package/dist/physics/kinematicVehicle.d.ts +52 -0
  150. package/dist/physics/kinematicVehicle.js +81 -0
  151. package/dist/physics/physicsWorld.d.ts +13 -6
  152. package/dist/physics/physicsWorld.js +169 -40
  153. package/dist/physics/ragdoll.js +1 -1
  154. package/dist/physics/vehicleBody.js +2 -1
  155. package/dist/random/rng.d.ts +2 -0
  156. package/dist/random/rng.js +2 -0
  157. package/dist/random/seedLink.d.ts +5 -0
  158. package/dist/random/seedLink.js +35 -0
  159. package/dist/render/postProcessing.d.ts +56 -0
  160. package/dist/render/postProcessing.js +1 -0
  161. package/dist/runtime/adapter.d.ts +19 -0
  162. package/dist/runtime/adapter.js +11 -5
  163. package/dist/runtime/cameraDirector.d.ts +6 -1
  164. package/dist/runtime/cameraDirector.js +6 -0
  165. package/dist/runtime/commandRunner.d.ts +2 -2
  166. package/dist/runtime/commandRunner.js +2 -2
  167. package/dist/runtime/gameContext.d.ts +72 -8
  168. package/dist/runtime/gameContext.js +374 -61
  169. package/dist/runtime/gameRuntime.d.ts +5 -1
  170. package/dist/runtime/gameRuntime.js +13 -12
  171. package/dist/runtime/hostPersistence.d.ts +9 -1
  172. package/dist/runtime/hostPersistence.js +23 -8
  173. package/dist/runtime/hostedGameRunner.d.ts +49 -0
  174. package/dist/runtime/hostedGameRunner.js +62 -0
  175. package/dist/runtime/hostedWorldSession.d.ts +65 -0
  176. package/dist/runtime/hostedWorldSession.js +57 -0
  177. package/dist/runtime/inputSnapshot.d.ts +18 -0
  178. package/dist/runtime/inputSnapshot.js +7 -0
  179. package/dist/runtime/motionIntents.d.ts +16 -6
  180. package/dist/runtime/motionIntents.js +31 -2
  181. package/dist/runtime/snapshot.d.ts +1 -0
  182. package/dist/runtime/snapshot.js +1 -1
  183. package/dist/runtime/visibility.d.ts +74 -0
  184. package/dist/runtime/visibility.js +127 -0
  185. package/dist/runtime/worldChannel.d.ts +58 -0
  186. package/dist/runtime/worldChannel.js +69 -0
  187. package/dist/runtime/worldMirror.d.ts +24 -0
  188. package/dist/runtime/worldMirror.js +31 -0
  189. package/dist/runtime/worldReplication.d.ts +46 -0
  190. package/dist/runtime/worldReplication.js +185 -0
  191. package/dist/runtime/worldSnapshot.d.ts +17 -0
  192. package/dist/runtime/worldSnapshot.js +15 -0
  193. package/dist/scene/assetCatalog.d.ts +1 -0
  194. package/dist/scene/colliders.d.ts +50 -0
  195. package/dist/scene/colliders.js +101 -0
  196. package/dist/scene/entityStats.d.ts +4 -0
  197. package/dist/scene/entityStats.js +21 -0
  198. package/dist/scene/entityStore.d.ts +51 -5
  199. package/dist/scene/entityStore.js +119 -12
  200. package/dist/scene/objectQuery.d.ts +13 -2
  201. package/dist/scene/objectQuery.js +34 -2
  202. package/dist/scene/objectStore.d.ts +2 -0
  203. package/dist/scene/objectStore.js +31 -12
  204. package/dist/scene/sceneRaycast.d.ts +80 -0
  205. package/dist/scene/sceneRaycast.js +284 -0
  206. package/dist/scene/spatial.d.ts +11 -16
  207. package/dist/scene/spatial.js +99 -38
  208. package/dist/sensor/recordingBuffer.d.ts +6 -0
  209. package/dist/sensor/recordingBuffer.js +7 -0
  210. package/dist/sensor/replayLoop.d.ts +39 -0
  211. package/dist/sensor/replayLoop.js +64 -0
  212. package/dist/sensor/visionCone.d.ts +31 -0
  213. package/dist/sensor/visionCone.js +72 -0
  214. package/dist/session/extraction.d.ts +2 -2
  215. package/dist/session/extraction.js +13 -2
  216. package/dist/settings/settingsModel.d.ts +97 -0
  217. package/dist/settings/settingsModel.js +100 -0
  218. package/dist/stats/statModifiers.d.ts +5 -2
  219. package/dist/stats/statModifiers.js +32 -14
  220. package/dist/store/observableKeyedStore.d.ts +4 -0
  221. package/dist/store/observableKeyedStore.js +17 -2
  222. package/dist/survival/decayMeter.d.ts +1 -1
  223. package/dist/survival/decayMeter.js +0 -1
  224. package/dist/tactics/fallingGrid.d.ts +2 -2
  225. package/dist/tactics/fallingGrid.js +2 -2
  226. package/dist/time/beatClock.d.ts +18 -0
  227. package/dist/time/beatClock.js +24 -0
  228. package/dist/time/idleProgress.d.ts +29 -0
  229. package/dist/time/idleProgress.js +31 -0
  230. package/dist/time/serverTick.d.ts +7 -1
  231. package/dist/time/serverTick.js +27 -4
  232. package/dist/time/stateSchedule.d.ts +57 -0
  233. package/dist/time/stateSchedule.js +121 -0
  234. package/dist/turn/commit.d.ts +2 -2
  235. package/dist/turn/commit.js +2 -2
  236. package/dist/ui/gameLayout.d.ts +125 -0
  237. package/dist/ui/gameLayout.js +129 -0
  238. package/dist/ui/hudLayout.d.ts +58 -0
  239. package/dist/ui/hudLayout.js +207 -0
  240. package/dist/ui/hudScale.d.ts +44 -0
  241. package/dist/ui/hudScale.js +55 -0
  242. package/dist/ui/orientation.d.ts +39 -0
  243. package/dist/ui/orientation.js +49 -0
  244. package/dist/ui/swingTimer.d.ts +42 -0
  245. package/dist/ui/swingTimer.js +38 -0
  246. package/dist/visibility/assetStreaming.d.ts +66 -0
  247. package/dist/visibility/assetStreaming.js +201 -0
  248. package/dist/visibility/bounds.d.ts +66 -0
  249. package/dist/visibility/bounds.js +113 -0
  250. package/dist/visibility/camera.d.ts +21 -0
  251. package/dist/visibility/camera.js +3 -0
  252. package/dist/visibility/config.d.ts +21 -0
  253. package/dist/visibility/config.js +1 -0
  254. package/dist/visibility/diagnostics.d.ts +26 -0
  255. package/dist/visibility/diagnostics.js +36 -0
  256. package/dist/visibility/distance.d.ts +11 -0
  257. package/dist/visibility/distance.js +30 -0
  258. package/dist/visibility/frustum.d.ts +47 -0
  259. package/dist/visibility/frustum.js +186 -0
  260. package/dist/visibility/occlusion.d.ts +36 -0
  261. package/dist/visibility/occlusion.js +45 -0
  262. package/dist/visibility/settings.d.ts +75 -0
  263. package/dist/visibility/settings.js +49 -0
  264. package/dist/visibility/simulationCulling.d.ts +34 -0
  265. package/dist/visibility/simulationCulling.js +36 -0
  266. package/dist/visibility/spatialIndex.d.ts +45 -0
  267. package/dist/visibility/spatialIndex.js +212 -0
  268. package/dist/visibility/visibilitySystem.d.ts +90 -0
  269. package/dist/visibility/visibilitySystem.js +257 -0
  270. package/dist/world/buildings.d.ts +6 -0
  271. package/dist/world/buildings.js +152 -0
  272. package/dist/world/carve.d.ts +7 -2
  273. package/dist/world/carve.js +17 -7
  274. package/dist/world/cellStates.d.ts +45 -0
  275. package/dist/world/cellStates.js +103 -0
  276. package/dist/world/environmentSummary.d.ts +21 -4
  277. package/dist/world/environmentSummary.js +22 -3
  278. package/dist/world/features.d.ts +185 -8
  279. package/dist/world/features.js +64 -6
  280. package/dist/world/gridInstances.d.ts +7 -8
  281. package/dist/world/gridInstances.js +145 -7
  282. package/dist/world/lod.d.ts +17 -0
  283. package/dist/world/lod.js +66 -0
  284. package/dist/world/mapLayers.d.ts +60 -0
  285. package/dist/world/mapLayers.js +44 -0
  286. package/dist/world/massing.d.ts +45 -0
  287. package/dist/world/massing.js +581 -0
  288. package/dist/world/minimap.d.ts +13 -1
  289. package/dist/world/minimap.js +21 -2
  290. package/dist/world/roads.d.ts +47 -0
  291. package/dist/world/roads.js +146 -0
  292. package/dist/world/streets.d.ts +80 -0
  293. package/dist/world/streets.js +144 -0
  294. package/dist/world/terrain.d.ts +69 -3
  295. package/dist/world/terrain.js +309 -16
  296. package/dist/world/water.d.ts +7 -0
  297. package/dist/world/water.js +19 -4
  298. package/dist/world/weather.d.ts +3 -18
  299. package/dist/world/weather.js +4 -17
  300. package/dist/world/windZones.d.ts +47 -0
  301. package/dist/world/windZones.js +59 -0
  302. package/llms.txt +3013 -1726
  303. package/package.json +12 -2
package/CHANGELOG.md CHANGED
@@ -11,6 +11,42 @@ Agents building on the published SDK can also read this programmatically:
11
11
  same data as typed values, so an updater can diff its installed version against
12
12
  the latest and surface the migration steps.
13
13
 
14
+ ## 0.10.0
15
+
16
+ ### Migrate
17
+
18
+ - **Nothing to change for existing games** — the shared mobile-composition system (viewport allocation, region collision, `--jg-*` viewport vars) is wired automatically by the shell for every game; `HudPanel`s inside a `HudCanvas` register themselves. Legacy `orientation: "landscape" | "portrait"` keeps its advisory dismissible-hint behavior unchanged.
19
+ - **Opt a driving/landscape game into the strict gate**: replace the advisory `orientation` with the contract form — `orientation: { mobile: "landscape-required" }` (rules: `any` · `portrait`/`landscape` advisory · `portrait-required`/`landscape-required` · `unsupported`). In portrait the engine now shows a polished `RotateDeviceScreen`, suppresses input, freezes the sim, and unmounts the HUD/controls until the device is landscape.
20
+ - **Declare HUD intent** where useful: `HudPanel` gains `priority` (`critical`/`secondary`/`tertiary`), `mobileBehavior` (`hidden` unmounts on phones, `transient` softens collision, …), `allowOverlapWith`, and `collisionGroup`. Optional — omitting them keeps prior behavior.
21
+ - **Mobile validation now also fails on overlap**: `bun run shoot <game> --device mobile|mobile-landscape|both` exits non-zero on forbidden inter-element collisions (not just viewport overflow), naming both regions.
22
+
23
+ ### Added
24
+
25
+ - Shared mobile layout composition — `@jgengine/core/ui/gameLayout` (pure geometry: `resolveLayoutMode`, `intersects`, `overlapArea`, `detectLayoutCollisions`, `computeGameplayRect`, `LayoutRegion`, `GameViewportLayout`) and `@jgengine/core/ui/orientation` (`resolveOrientationRequirement`, `orientationGateActive`, `MobileOrientationRule`). `@jgengine/react` adds `GameViewportProvider` (mounted by the shell), hooks (`useGameViewportLayout`, `useGameLayoutMode`, `useGameOrientation`, `useReservedControlZones`, `useLayoutCollisions`, `useRegisterLayoutRegion`), and a headless `RotateDeviceScreen`. The provider tracks `window.visualViewport`, publishes `--jg-viewport-*` / `--jg-visual-viewport-*` / `--jg-safe-*` CSS vars, resolves the explicit layout mode, and detects forbidden region overlaps (dev `data-jg-layout-collision` + console diagnostic).
26
+ - Mandatory orientation contract — `PlayableGame.orientation` accepts `{ mobile: <rule> }`; `landscape-required`/`portrait-required` render an engine-owned rotate gate that blocks gameplay (input suppressed, simulation frozen, HUD/controls unmounted), self-correcting when the device is turned. Reduced-motion and safe-area respected; `visualViewport`-sized for mobile Safari/PWA.
27
+ - Reserved touch-control zones — the touch dock registers its joystick / action-cluster / utility rectangles (runtime-measured) as `control` regions, so HUD placement and collision validation know exactly where controls sit.
28
+ - HUD placement metadata — `HudPanel` gains `priority`, `mobileBehavior`, `allowOverlapWith`, `collisionGroup`, and registers as a collision-tracked layout region.
29
+ - Mobile-landscape shoot device — `bun run shoot --device mobile-landscape` (844×390) plus collision-gate reads that fail mobile validation on forbidden overlaps.
30
+ - Canyon Chase migrated as the reference landscape-required game — declares `orientation: { mobile: "landscape-required" }`, composes its HUD through coordinated `HudPanel` regions (pursuit distance critical, border secondary, survey map hidden on mobile, radio transient) instead of independent fixed corners.
31
+
32
+ ### Changed
33
+
34
+ - First-person projectile tracers now originate from the weapon muzzle instead of the camera/eye centerline. Hit detection is unchanged (still crosshair-accurate) — only the drawn tracer's start point moved to the viewmodel muzzle, which tracks full aim yaw and pitch. Non-viewmodel games and enemy tracers are unaffected.
35
+
36
+ ## 0.9.0
37
+
38
+ ### Added
39
+
40
+ - Mobile HUD fit — design-resolution UI scaling now applies to every game by default: `HudCanvas` measures the live viewport and scales the whole HUD from `PlayableGame.hudFit.designSize` (default 1600×900, clamps `minScale`/`maxScale` 0.4–1) so desktop-authored layouts shrink to fit a phone instead of overflowing it; `hudFit.mobile` overrides tune the phone fit separately. Pure math lives in `@jgengine/core/ui/hudScale` (`hudScaleForViewport`, `resolveHudFit`, `rectOverflow`, `overflowingPanels`); the shell mounts `@jgengine/react`'s `HudViewportProvider` around `GameUI` so games need no wiring.
41
+ - Graphics → UI scale — a player-facing `graphics.uiScale` slider (0.5–1.5, default 1) multiplies the computed HUD scale on every platform; the same resolution system drives desktop preference and mobile shrink.
42
+ - HUD overflow gate — `HudCanvas` measures every `HudPanel` against the viewport at runtime and reports offenders on a `data-hud-overflow` attribute (plus a console warning); `bun run shoot <game> --device mobile|both` now exits non-zero naming the panels that escape the viewport.
43
+ - Automatic visibility & streaming defaults — an engine-level `VisibilitySystem` (exported from `@jgengine/core`) gives every scene renderer-agnostic culling and asset-streaming policy with no per-object wiring: distance culling, preload margins, hysteresis, delayed unloading, multi-camera awareness (including cameras excluded from streaming), and per-object overrides (always-visible, never-unload, disabled culling/streaming, custom render distance and preload margin).
44
+ - Self-hosted asset mirror — `DEFAULT_RELEASE_BASE` now points at this repo's rolling `packs` release instead of the upstream host; a catalog-driven `mirror-assets` workflow (weekly cron + manual dispatch) keeps the mirror in sync with the asset catalog.
45
+
46
+ ### Changed
47
+
48
+ - Mobile HUD fit is on by default — design-resolution HUD scaling now applies to every game with no config change (previously opt-in via `platforms: ["web", "mobile"]`). A desktop-only game keeps the legacy fixed 0.85 compact zoom by declaring `platforms: ["web"]` (without `"mobile"`).
49
+
14
50
  ## 0.8.0
15
51
 
16
52
  Transport-agnostic multiplayer (socket.io, WebRTC p2p, LAN/Fly adapters) plus grid/voxel
@@ -0,0 +1,36 @@
1
+ export type FlockVec3 = readonly [number, number, number];
2
+ export interface FlockAgent {
3
+ position: FlockVec3;
4
+ velocity: FlockVec3;
5
+ }
6
+ export interface FlockConfig {
7
+ maxSpeed: number;
8
+ /** How hard steering can change velocity (units/s²); default `maxSpeed * 2`. */
9
+ accel?: number;
10
+ separationRadius: number;
11
+ separationWeight?: number;
12
+ /** Neighbors inside this radius pull toward the local centroid and average heading. */
13
+ neighborRadius: number;
14
+ cohesionWeight?: number;
15
+ alignmentWeight?: number;
16
+ /** Pull toward the seek target; default `1`. */
17
+ seekWeight?: number;
18
+ /** Beyond this distance from the flock centroid an agent's cohesion is boosted so stragglers rejoin. */
19
+ stragglerRadius?: number;
20
+ /** Cohesion multiplier applied to stragglers; default `3`. */
21
+ stragglerBoost?: number;
22
+ }
23
+ /**
24
+ * Classic per-agent boid steering — seek + separation + cohesion + alignment with a straggler
25
+ * rescue radius — the many-agents-to-*each-other* primitive `ai/crowd`'s navmesh flow field
26
+ * (many-agents-to-POI) deliberately isn't. Pure: returns the desired acceleration for one agent;
27
+ * `stepFlock` is the convenience integrator. O(neighbors) per agent — pre-filter with a spatial
28
+ * grid past a few hundred agents.
29
+ */
30
+ export declare function flockSteer(agent: FlockAgent, neighbors: readonly FlockAgent[], config: FlockConfig, target?: FlockVec3): FlockVec3;
31
+ export interface FlockStepAgent {
32
+ position: FlockVec3;
33
+ velocity: FlockVec3;
34
+ }
35
+ /** Integrate one tick in place: steer every agent, clamp to `maxSpeed`, advance positions. */
36
+ export declare function stepFlock(agents: FlockStepAgent[], config: FlockConfig, dt: number, target?: FlockVec3): void;
@@ -0,0 +1,182 @@
1
+ /**
2
+ * Classic per-agent boid steering — seek + separation + cohesion + alignment with a straggler
3
+ * rescue radius — the many-agents-to-*each-other* primitive `ai/crowd`'s navmesh flow field
4
+ * (many-agents-to-POI) deliberately isn't. Pure: returns the desired acceleration for one agent;
5
+ * `stepFlock` is the convenience integrator. O(neighbors) per agent — pre-filter with a spatial
6
+ * grid past a few hundred agents.
7
+ */
8
+ export function flockSteer(agent, neighbors, config, target) {
9
+ const separationWeight = config.separationWeight ?? 1.5;
10
+ const cohesionWeight = config.cohesionWeight ?? 1;
11
+ const alignmentWeight = config.alignmentWeight ?? 1;
12
+ const seekWeight = config.seekWeight ?? 1;
13
+ const accel = config.accel ?? config.maxSpeed * 2;
14
+ let sepX = 0;
15
+ let sepY = 0;
16
+ let sepZ = 0;
17
+ let cohX = 0;
18
+ let cohY = 0;
19
+ let cohZ = 0;
20
+ let alignX = 0;
21
+ let alignY = 0;
22
+ let alignZ = 0;
23
+ let flockmates = 0;
24
+ for (const other of neighbors) {
25
+ if (other === agent)
26
+ continue;
27
+ const dx = other.position[0] - agent.position[0];
28
+ const dy = other.position[1] - agent.position[1];
29
+ const dz = other.position[2] - agent.position[2];
30
+ const distance = Math.hypot(dx, dy, dz);
31
+ if (distance > config.neighborRadius)
32
+ continue;
33
+ flockmates += 1;
34
+ cohX += other.position[0];
35
+ cohY += other.position[1];
36
+ cohZ += other.position[2];
37
+ alignX += other.velocity[0];
38
+ alignY += other.velocity[1];
39
+ alignZ += other.velocity[2];
40
+ if (distance < config.separationRadius && distance > 1e-9) {
41
+ const push = (config.separationRadius - distance) / config.separationRadius / distance;
42
+ sepX -= dx * push;
43
+ sepY -= dy * push;
44
+ sepZ -= dz * push;
45
+ }
46
+ }
47
+ let steerX = sepX * separationWeight;
48
+ let steerY = sepY * separationWeight;
49
+ let steerZ = sepZ * separationWeight;
50
+ if (flockmates > 0) {
51
+ const centroidX = cohX / flockmates;
52
+ const centroidY = cohY / flockmates;
53
+ const centroidZ = cohZ / flockmates;
54
+ const toCentroidX = centroidX - agent.position[0];
55
+ const toCentroidY = centroidY - agent.position[1];
56
+ const toCentroidZ = centroidZ - agent.position[2];
57
+ const centroidDistance = Math.hypot(toCentroidX, toCentroidY, toCentroidZ);
58
+ const straggling = config.stragglerRadius !== undefined && centroidDistance > config.stragglerRadius;
59
+ const cohesion = cohesionWeight * (straggling ? config.stragglerBoost ?? 3 : 1);
60
+ if (centroidDistance > 1e-9) {
61
+ steerX += (toCentroidX / centroidDistance) * cohesion;
62
+ steerY += (toCentroidY / centroidDistance) * cohesion;
63
+ steerZ += (toCentroidZ / centroidDistance) * cohesion;
64
+ }
65
+ const alignMagnitude = Math.hypot(alignX, alignY, alignZ);
66
+ if (alignMagnitude > 1e-9) {
67
+ steerX += (alignX / alignMagnitude) * alignmentWeight;
68
+ steerY += (alignY / alignMagnitude) * alignmentWeight;
69
+ steerZ += (alignZ / alignMagnitude) * alignmentWeight;
70
+ }
71
+ }
72
+ if (target !== undefined) {
73
+ const toTargetX = target[0] - agent.position[0];
74
+ const toTargetY = target[1] - agent.position[1];
75
+ const toTargetZ = target[2] - agent.position[2];
76
+ const targetDistance = Math.hypot(toTargetX, toTargetY, toTargetZ);
77
+ if (targetDistance > 1e-9) {
78
+ steerX += (toTargetX / targetDistance) * seekWeight;
79
+ steerY += (toTargetY / targetDistance) * seekWeight;
80
+ steerZ += (toTargetZ / targetDistance) * seekWeight;
81
+ }
82
+ }
83
+ const magnitude = Math.hypot(steerX, steerY, steerZ);
84
+ if (magnitude <= 1e-9)
85
+ return [0, 0, 0];
86
+ const scale = accel / magnitude;
87
+ return [steerX * scale, steerY * scale, steerZ * scale];
88
+ }
89
+ const CELL_KEY_STRIDE = 1_048_576;
90
+ const gridCells = new Map();
91
+ const freeBuckets = [];
92
+ const neighborScratch = [];
93
+ let steerScratch = new Float64Array(0);
94
+ function cellKey(cx, cz) {
95
+ return cx * CELL_KEY_STRIDE + cz;
96
+ }
97
+ function takeBucket() {
98
+ return freeBuckets.pop() ?? [];
99
+ }
100
+ function ensureSteerCapacity(agentCount) {
101
+ const needed = agentCount * 3;
102
+ if (steerScratch.length < needed) {
103
+ steerScratch = new Float64Array(needed);
104
+ }
105
+ }
106
+ function buildAgentGrid(agents, invCell) {
107
+ for (const bucket of gridCells.values()) {
108
+ bucket.length = 0;
109
+ freeBuckets.push(bucket);
110
+ }
111
+ gridCells.clear();
112
+ for (let i = 0; i < agents.length; i += 1) {
113
+ const position = agents[i].position;
114
+ const key = cellKey(Math.floor(position[0] * invCell), Math.floor(position[2] * invCell));
115
+ let bucket = gridCells.get(key);
116
+ if (bucket === undefined) {
117
+ bucket = takeBucket();
118
+ gridCells.set(key, bucket);
119
+ }
120
+ bucket.push(i);
121
+ }
122
+ }
123
+ function fillNeighbors(agents, agentIndex, invCell) {
124
+ const agent = agents[agentIndex];
125
+ const cx = Math.floor(agent.position[0] * invCell);
126
+ const cz = Math.floor(agent.position[2] * invCell);
127
+ let count = 0;
128
+ for (let dz = -1; dz <= 1; dz += 1) {
129
+ for (let dx = -1; dx <= 1; dx += 1) {
130
+ const bucket = gridCells.get(cellKey(cx + dx, cz + dz));
131
+ if (bucket === undefined)
132
+ continue;
133
+ for (let b = 0; b < bucket.length; b += 1) {
134
+ const otherIndex = bucket[b];
135
+ if (otherIndex === agentIndex)
136
+ continue;
137
+ neighborScratch[count] = agents[otherIndex];
138
+ count += 1;
139
+ }
140
+ }
141
+ }
142
+ neighborScratch.length = count;
143
+ return count;
144
+ }
145
+ /** Integrate one tick in place: steer every agent, clamp to `maxSpeed`, advance positions. */
146
+ export function stepFlock(agents, config, dt, target) {
147
+ const count = agents.length;
148
+ if (count === 0)
149
+ return;
150
+ const cellSize = config.neighborRadius > 1e-6 ? config.neighborRadius : 1;
151
+ const invCell = 1 / cellSize;
152
+ buildAgentGrid(agents, invCell);
153
+ ensureSteerCapacity(count);
154
+ for (let i = 0; i < count; i += 1) {
155
+ fillNeighbors(agents, i, invCell);
156
+ const steer = flockSteer(agents[i], neighborScratch, config, target);
157
+ const base = i * 3;
158
+ steerScratch[base] = steer[0];
159
+ steerScratch[base + 1] = steer[1];
160
+ steerScratch[base + 2] = steer[2];
161
+ }
162
+ for (let i = 0; i < count; i += 1) {
163
+ const agent = agents[i];
164
+ const base = i * 3;
165
+ let vx = agent.velocity[0] + steerScratch[base] * dt;
166
+ let vy = agent.velocity[1] + steerScratch[base + 1] * dt;
167
+ let vz = agent.velocity[2] + steerScratch[base + 2] * dt;
168
+ const speed = Math.hypot(vx, vy, vz);
169
+ if (speed > config.maxSpeed) {
170
+ const clamp = config.maxSpeed / speed;
171
+ vx *= clamp;
172
+ vy *= clamp;
173
+ vz *= clamp;
174
+ }
175
+ agent.velocity = [vx, vy, vz];
176
+ agent.position = [
177
+ agent.position[0] + vx * dt,
178
+ agent.position[1] + vy * dt,
179
+ agent.position[2] + vz * dt,
180
+ ];
181
+ }
182
+ }
@@ -0,0 +1,19 @@
1
+ import type { ThreatTable } from "./threat.js";
2
+ export interface AssistMember {
3
+ id: string;
4
+ groupId: string;
5
+ table: ThreatTable;
6
+ }
7
+ export interface AssistNetworkConfig {
8
+ radius?: number;
9
+ shareFraction?: number;
10
+ distanceBetween?: (a: string, b: string) => number;
11
+ }
12
+ export interface AssistNetwork {
13
+ register(member: AssistMember): void;
14
+ remove(memberId: string): void;
15
+ memberIds(groupId?: string): string[];
16
+ assistersOf(memberId: string): string[];
17
+ addThreat(memberId: string, sourceId: string, amount: number): string[];
18
+ }
19
+ export declare function createAssistNetwork(config?: AssistNetworkConfig): AssistNetwork;
@@ -0,0 +1,59 @@
1
+ export function createAssistNetwork(config = {}) {
2
+ const radius = config.radius;
3
+ const shareFraction = Math.max(0, config.shareFraction ?? 1);
4
+ const distanceBetween = config.distanceBetween;
5
+ const members = new Map();
6
+ const order = [];
7
+ function inRange(memberId, otherId) {
8
+ if (radius === undefined || !distanceBetween)
9
+ return true;
10
+ return distanceBetween(memberId, otherId) <= radius;
11
+ }
12
+ return {
13
+ register(member) {
14
+ if (!members.has(member.id))
15
+ order.push(member.id);
16
+ members.set(member.id, member);
17
+ },
18
+ remove(memberId) {
19
+ if (!members.delete(memberId))
20
+ return;
21
+ const index = order.indexOf(memberId);
22
+ if (index !== -1)
23
+ order.splice(index, 1);
24
+ },
25
+ memberIds(groupId) {
26
+ if (groupId === undefined)
27
+ return [...order];
28
+ return order.filter((id) => members.get(id).groupId === groupId);
29
+ },
30
+ assistersOf(memberId) {
31
+ const member = members.get(memberId);
32
+ if (!member)
33
+ return [];
34
+ return order.filter((id) => {
35
+ if (id === memberId)
36
+ return false;
37
+ const other = members.get(id);
38
+ return other.groupId === member.groupId && inRange(memberId, id);
39
+ });
40
+ },
41
+ addThreat(memberId, sourceId, amount) {
42
+ const member = members.get(memberId);
43
+ if (!member || amount <= 0)
44
+ return [];
45
+ member.table.add(sourceId, amount);
46
+ if (shareFraction <= 0)
47
+ return [];
48
+ const assisters = order.filter((id) => {
49
+ if (id === memberId)
50
+ return false;
51
+ const other = members.get(id);
52
+ return other.groupId === member.groupId && inRange(memberId, id);
53
+ });
54
+ for (const id of assisters)
55
+ members.get(id).table.add(sourceId, amount * shareFraction);
56
+ return assisters;
57
+ },
58
+ };
59
+ }
@@ -0,0 +1,21 @@
1
+ export interface LaneCandidate<TId extends string = string> {
2
+ id: TId;
3
+ cost: number;
4
+ }
5
+ export interface PickLaneOptions<TId extends string = string> {
6
+ /** The lane currently taken — kept unless a rival is decisively cheaper. */
7
+ current?: TId | null;
8
+ /** How much cheaper a rival must be to displace `current`: it wins only when `cost < currentCost / stickiness`. Default `1.2`. */
9
+ stickiness?: number;
10
+ /** Candidates within this cost of the best tie for the win; the tie is broken by `rng`. Default `0`. */
11
+ tieEpsilon?: number;
12
+ rng?: () => number;
13
+ }
14
+ /**
15
+ * Live cost-based selection over parallel corridors (#286.7) — the racing-line / lane-merge pick
16
+ * every AI driver hand-rolled. Evaluate each lane's cost this tick (crowding, hazards, distance)
17
+ * and let stickiness hysteresis stop the agent flip-flopping between near-equal lanes.
18
+ */
19
+ export declare function pickLane<TId extends string>(candidates: readonly LaneCandidate<TId>[], options?: PickLaneOptions<TId>): TId | null;
20
+ /** Sum a live cost function over a corridor's sample points — the standard way to build `LaneCandidate.cost`. */
21
+ export declare function corridorCost(points: readonly (readonly [number, number])[], costAt: (x: number, z: number) => number): number;
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Live cost-based selection over parallel corridors (#286.7) — the racing-line / lane-merge pick
3
+ * every AI driver hand-rolled. Evaluate each lane's cost this tick (crowding, hazards, distance)
4
+ * and let stickiness hysteresis stop the agent flip-flopping between near-equal lanes.
5
+ */
6
+ export function pickLane(candidates, options = {}) {
7
+ if (candidates.length === 0)
8
+ return null;
9
+ const stickiness = options.stickiness ?? 1.2;
10
+ const tieEpsilon = options.tieEpsilon ?? 0;
11
+ const rng = options.rng ?? Math.random;
12
+ let best = candidates[0];
13
+ for (const candidate of candidates) {
14
+ if (candidate.cost < best.cost)
15
+ best = candidate;
16
+ }
17
+ if (tieEpsilon > 0) {
18
+ const tied = candidates.filter((candidate) => candidate.cost <= best.cost + tieEpsilon);
19
+ if (tied.length > 1)
20
+ best = tied[Math.min(tied.length - 1, Math.floor(rng() * tied.length))];
21
+ }
22
+ const current = options.current ?? null;
23
+ if (current !== null && current !== best.id) {
24
+ const currentCandidate = candidates.find((candidate) => candidate.id === current);
25
+ if (currentCandidate !== undefined && best.cost >= currentCandidate.cost / stickiness) {
26
+ return current;
27
+ }
28
+ }
29
+ return best.id;
30
+ }
31
+ /** Sum a live cost function over a corridor's sample points — the standard way to build `LaneCandidate.cost`. */
32
+ export function corridorCost(points, costAt) {
33
+ let total = 0;
34
+ for (const [x, z] of points)
35
+ total += costAt(x, z);
36
+ return total;
37
+ }
@@ -0,0 +1,68 @@
1
+ import { type ThreatTable, type ThreatTableConfig } from "./threat.js";
2
+ export type MobBrainMode = "idle" | "wander" | "chase" | "engage" | "evade";
3
+ export type MobVec3 = readonly [number, number, number];
4
+ export interface MobWanderConfig {
5
+ /** Radius around home the wander points are drawn from. */
6
+ radius: number;
7
+ /** Seconds between wander-point picks; default `4`. */
8
+ intervalSeconds?: number;
9
+ /** Movement speed multiplier while wandering; default `0.35`. */
10
+ speedScale?: number;
11
+ /** Distance at which a wander point counts as reached; default `0.6`. */
12
+ arriveRadius?: number;
13
+ }
14
+ export interface MobBrainConfig {
15
+ /** Distance at which an unaggroed candidate pulls threat and becomes the target. */
16
+ aggroRadius: number;
17
+ /** Distance inside which the step reports `inAttackRange` and stops chasing. */
18
+ attackRange: number;
19
+ /** Distance from home beyond which the mob drops all threat and evades back. */
20
+ leashDistance: number;
21
+ /** Idle wandering around home; omit or `false` to stand still. */
22
+ wander?: MobWanderConfig | false;
23
+ /** Movement speed multiplier while evading home; default `1.4`. */
24
+ evadeSpeedScale?: number;
25
+ /** Target-switch stickiness passed to the threat table's `highest`; default `1.15`. */
26
+ stickiness?: number;
27
+ /** Distance to home at which an evade completes; default `1.2`. */
28
+ homeArriveRadius?: number;
29
+ threat?: ThreatTableConfig;
30
+ }
31
+ export interface MobBrainDeps {
32
+ home: MobVec3;
33
+ /** The mob's current position; `null` pauses the brain (despawned). */
34
+ position(): MobVec3 | null;
35
+ /** A target's current position; `null` drops it from the threat table (despawned, dead). */
36
+ targetPosition(targetId: string): MobVec3 | null;
37
+ /** Potential aggro targets near the mob — the brain distance-filters against `aggroRadius`. */
38
+ candidates(): readonly string[];
39
+ rng?: () => number;
40
+ }
41
+ export interface MobBrainStep {
42
+ mode: MobBrainMode;
43
+ targetId: string | null;
44
+ /** Where to step this tick — feed to `moveToward`; `null` holds position. */
45
+ moveTo: MobVec3 | null;
46
+ /** Multiplier on the mob's base move speed for this step. */
47
+ speedScale: number;
48
+ /** The target is inside `attackRange` — the swing/cast window. */
49
+ inAttackRange: boolean;
50
+ /** Fires on the single step an evade run reaches home — the reset/full-heal hook. */
51
+ arrivedHome: boolean;
52
+ }
53
+ /**
54
+ * The wander → aggro → chase → engage → leash-evade loop every MMO-shaped game hand-rolls,
55
+ * composed over `ai/threat`. The brain decides intent; the game executes it (`moveToward`,
56
+ * ground-snap, facing, swings) and routes damage into `addThreat`. Pack aggro is game-side:
57
+ * call `addThreat` on nearby packmates' brains when one aggros.
58
+ */
59
+ export interface MobBrain {
60
+ readonly threat: ThreatTable;
61
+ mode(): MobBrainMode;
62
+ /** Route damage/heal aggro here — sugar over `threat.add`; ignored while the mob is evading. */
63
+ addThreat(sourceId: string, amount: number): void;
64
+ tick(dt: number): MobBrainStep;
65
+ /** Back to idle at full rest (respawn) — clears threat, evade, and wander state. */
66
+ reset(): void;
67
+ }
68
+ export declare function createMobBrain(config: MobBrainConfig, deps: MobBrainDeps): MobBrain;
@@ -0,0 +1,115 @@
1
+ import { createThreatTable } from "./threat.js";
2
+ const HOLD = {
3
+ targetId: null,
4
+ moveTo: null,
5
+ speedScale: 1,
6
+ inAttackRange: false,
7
+ arrivedHome: false,
8
+ };
9
+ function distance(a, b) {
10
+ return Math.hypot(a[0] - b[0], a[1] - b[1], a[2] - b[2]);
11
+ }
12
+ export function createMobBrain(config, deps) {
13
+ const threat = createThreatTable(config.threat);
14
+ const stickiness = config.stickiness ?? 1.15;
15
+ const evadeSpeedScale = config.evadeSpeedScale ?? 1.4;
16
+ const homeArriveRadius = config.homeArriveRadius ?? 1.2;
17
+ const wander = config.wander === false || config.wander === undefined ? null : config.wander;
18
+ const wanderInterval = wander?.intervalSeconds ?? 4;
19
+ const wanderArrive = wander?.arriveRadius ?? 0.6;
20
+ const rng = deps.rng ?? Math.random;
21
+ let currentMode = "idle";
22
+ let currentTarget = null;
23
+ let evading = false;
24
+ let wanderClock = 0;
25
+ let wanderTo = null;
26
+ function step(mode, patch = {}) {
27
+ currentMode = mode;
28
+ return { mode, ...HOLD, ...patch };
29
+ }
30
+ function acquireByProximity(position) {
31
+ let nearest = null;
32
+ let nearestDistance = config.aggroRadius;
33
+ for (const candidateId of deps.candidates()) {
34
+ const candidatePosition = deps.targetPosition(candidateId);
35
+ if (candidatePosition === null)
36
+ continue;
37
+ const candidateDistance = distance(position, candidatePosition);
38
+ if (candidateDistance <= nearestDistance) {
39
+ nearest = candidateId;
40
+ nearestDistance = candidateDistance;
41
+ }
42
+ }
43
+ if (nearest !== null)
44
+ threat.add(nearest, 1);
45
+ }
46
+ return {
47
+ threat,
48
+ mode: () => currentMode,
49
+ addThreat(sourceId, amount) {
50
+ if (evading)
51
+ return;
52
+ threat.add(sourceId, amount);
53
+ },
54
+ tick(dt) {
55
+ const position = deps.position();
56
+ if (position === null)
57
+ return step(currentMode);
58
+ if (evading) {
59
+ if (distance(position, deps.home) <= homeArriveRadius) {
60
+ evading = false;
61
+ wanderClock = 0;
62
+ wanderTo = null;
63
+ return step("idle", { arrivedHome: true });
64
+ }
65
+ return step("evade", { moveTo: deps.home, speedScale: evadeSpeedScale });
66
+ }
67
+ threat.decay(dt);
68
+ if (threat.size() === 0)
69
+ acquireByProximity(position);
70
+ let targetId = threat.highest({ current: currentTarget, stickiness });
71
+ if (targetId !== null && deps.targetPosition(targetId) === null) {
72
+ threat.remove(targetId);
73
+ targetId = threat.highest({ stickiness });
74
+ }
75
+ currentTarget = targetId;
76
+ if (targetId !== null) {
77
+ if (distance(position, deps.home) > config.leashDistance) {
78
+ threat.clear();
79
+ currentTarget = null;
80
+ evading = true;
81
+ return step("evade", { moveTo: deps.home, speedScale: evadeSpeedScale });
82
+ }
83
+ const targetPosition = deps.targetPosition(targetId);
84
+ if (targetPosition === null)
85
+ return step(currentMode);
86
+ if (distance(position, targetPosition) <= config.attackRange) {
87
+ return step("engage", { targetId, inAttackRange: true });
88
+ }
89
+ return step("chase", { targetId, moveTo: targetPosition });
90
+ }
91
+ if (wander === null)
92
+ return step("idle");
93
+ wanderClock += dt;
94
+ if (wanderTo !== null && distance(position, wanderTo) <= wanderArrive)
95
+ wanderTo = null;
96
+ if (wanderTo === null && wanderClock >= wanderInterval) {
97
+ wanderClock = 0;
98
+ const angle = rng() * Math.PI * 2;
99
+ const radius = Math.sqrt(rng()) * wander.radius;
100
+ wanderTo = [deps.home[0] + Math.cos(angle) * radius, deps.home[1], deps.home[2] + Math.sin(angle) * radius];
101
+ }
102
+ if (wanderTo === null)
103
+ return step("idle");
104
+ return step("wander", { moveTo: wanderTo, speedScale: wander.speedScale ?? 0.35 });
105
+ },
106
+ reset() {
107
+ threat.clear();
108
+ currentMode = "idle";
109
+ currentTarget = null;
110
+ evading = false;
111
+ wanderClock = 0;
112
+ wanderTo = null;
113
+ },
114
+ };
115
+ }
@@ -47,6 +47,16 @@ export interface SpawnRequest {
47
47
  point?: NavPoint;
48
48
  laneId?: number;
49
49
  }
50
+ /** Preference for picking a spawn point relative to `avoid` positions: closer, farther, or unweighted. */
51
+ export type SpawnPointDistanceBias = "near" | "far" | "none";
52
+ /** Semantic options for selecting a spawn point without exposing weighting internals. */
53
+ export interface SpawnPointSelectionOptions {
54
+ candidates: readonly NavPoint[];
55
+ avoid?: readonly NavPoint[];
56
+ random: () => number;
57
+ distanceBias?: SpawnPointDistanceBias;
58
+ biasStrength?: number;
59
+ }
50
60
  export interface DirectorStep {
51
61
  state: SpawnDirectorState;
52
62
  spawns: SpawnRequest[];
@@ -55,6 +65,9 @@ export declare function createSpawnDirectorState(config: SpawnDirectorConfig): S
55
65
  export declare function raiseAlert(state: SpawnDirectorState, amount: number): SpawnDirectorState;
56
66
  export declare function advanceWave(config: SpawnDirectorConfig, state: SpawnDirectorState): SpawnDirectorState;
57
67
  export declare function advanceSpawnDirector(config: SpawnDirectorConfig, state: SpawnDirectorState, dt: number, ctx: DirectorContext): DirectorStep;
68
+ /** Selects a candidate spawn point using a semantic distance preference and caller-supplied randomness. */
69
+ export declare function pickSpawnPoint(options: SpawnPointSelectionOptions): NavPoint | null;
70
+ /** @deprecated Pass one SpawnPointSelectionOptions object instead. */
58
71
  export declare function pickSpawnPoint(points: readonly NavPoint[], players: readonly NavPoint[], options: {
59
72
  roll: number;
60
73
  bias?: number;