@its-not-rocket-science/ananke 0.1.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 (311) hide show
  1. package/CHANGELOG.md +135 -0
  2. package/LICENSE +21 -0
  3. package/README.md +2199 -0
  4. package/STABLE_API.md +266 -0
  5. package/dist/src/anatomy/anatomy-compiler.d.ts +14 -0
  6. package/dist/src/anatomy/anatomy-compiler.js +277 -0
  7. package/dist/src/anatomy/anatomy-contracts.d.ts +94 -0
  8. package/dist/src/anatomy/anatomy-contracts.js +1 -0
  9. package/dist/src/anatomy/anatomy-helpers.d.ts +82 -0
  10. package/dist/src/anatomy/anatomy-helpers.js +233 -0
  11. package/dist/src/anatomy/anatomy-schema.d.ts +28 -0
  12. package/dist/src/anatomy/anatomy-schema.js +388 -0
  13. package/dist/src/anatomy/index.d.ts +4 -0
  14. package/dist/src/anatomy/index.js +4 -0
  15. package/dist/src/archetypes.d.ts +87 -0
  16. package/dist/src/archetypes.js +285 -0
  17. package/dist/src/arena.d.ts +173 -0
  18. package/dist/src/arena.js +695 -0
  19. package/dist/src/bridge/bridge-engine.d.ts +46 -0
  20. package/dist/src/bridge/bridge-engine.js +252 -0
  21. package/dist/src/bridge/index.d.ts +4 -0
  22. package/dist/src/bridge/index.js +5 -0
  23. package/dist/src/bridge/interpolation.d.ts +64 -0
  24. package/dist/src/bridge/interpolation.js +130 -0
  25. package/dist/src/bridge/mapping.d.ts +33 -0
  26. package/dist/src/bridge/mapping.js +54 -0
  27. package/dist/src/bridge/types.d.ts +94 -0
  28. package/dist/src/bridge/types.js +2 -0
  29. package/dist/src/campaign.d.ts +141 -0
  30. package/dist/src/campaign.js +235 -0
  31. package/dist/src/channels.d.ts +15 -0
  32. package/dist/src/channels.js +20 -0
  33. package/dist/src/chronicle.d.ts +124 -0
  34. package/dist/src/chronicle.js +232 -0
  35. package/dist/src/collective-activities.d.ts +154 -0
  36. package/dist/src/collective-activities.js +247 -0
  37. package/dist/src/competence/acoustic.d.ts +101 -0
  38. package/dist/src/competence/acoustic.js +242 -0
  39. package/dist/src/competence/catalogue.d.ts +30 -0
  40. package/dist/src/competence/catalogue.js +241 -0
  41. package/dist/src/competence/crafting.d.ts +35 -0
  42. package/dist/src/competence/crafting.js +88 -0
  43. package/dist/src/competence/engineering.d.ts +53 -0
  44. package/dist/src/competence/engineering.js +108 -0
  45. package/dist/src/competence/framework.d.ts +68 -0
  46. package/dist/src/competence/framework.js +694 -0
  47. package/dist/src/competence/index.d.ts +12 -0
  48. package/dist/src/competence/index.js +13 -0
  49. package/dist/src/competence/interspecies.d.ts +81 -0
  50. package/dist/src/competence/interspecies.js +108 -0
  51. package/dist/src/competence/language.d.ts +79 -0
  52. package/dist/src/competence/language.js +115 -0
  53. package/dist/src/competence/naturalist.d.ts +97 -0
  54. package/dist/src/competence/naturalist.js +187 -0
  55. package/dist/src/competence/navigation.d.ts +24 -0
  56. package/dist/src/competence/navigation.js +48 -0
  57. package/dist/src/competence/performance.d.ts +125 -0
  58. package/dist/src/competence/performance.js +210 -0
  59. package/dist/src/competence/teaching.d.ts +64 -0
  60. package/dist/src/competence/teaching.js +121 -0
  61. package/dist/src/competence/willpower.d.ts +74 -0
  62. package/dist/src/competence/willpower.js +114 -0
  63. package/dist/src/crafting/index.d.ts +55 -0
  64. package/dist/src/crafting/index.js +229 -0
  65. package/dist/src/crafting/manufacturing.d.ts +83 -0
  66. package/dist/src/crafting/manufacturing.js +165 -0
  67. package/dist/src/crafting/materials.d.ts +53 -0
  68. package/dist/src/crafting/materials.js +120 -0
  69. package/dist/src/crafting/recipes.d.ts +75 -0
  70. package/dist/src/crafting/recipes.js +233 -0
  71. package/dist/src/crafting/workshops.d.ts +61 -0
  72. package/dist/src/crafting/workshops.js +170 -0
  73. package/dist/src/debug.d.ts +86 -0
  74. package/dist/src/debug.js +76 -0
  75. package/dist/src/derive.d.ts +21 -0
  76. package/dist/src/derive.js +88 -0
  77. package/dist/src/describe.d.ts +29 -0
  78. package/dist/src/describe.js +276 -0
  79. package/dist/src/dialogue.d.ts +122 -0
  80. package/dist/src/dialogue.js +266 -0
  81. package/dist/src/dist.d.ts +20 -0
  82. package/dist/src/dist.js +39 -0
  83. package/dist/src/downtime.d.ts +89 -0
  84. package/dist/src/downtime.js +391 -0
  85. package/dist/src/economy.d.ts +116 -0
  86. package/dist/src/economy.js +182 -0
  87. package/dist/src/emotional-contagion.d.ts +142 -0
  88. package/dist/src/emotional-contagion.js +274 -0
  89. package/dist/src/equipment.d.ts +206 -0
  90. package/dist/src/equipment.js +598 -0
  91. package/dist/src/faction.d.ts +102 -0
  92. package/dist/src/faction.js +237 -0
  93. package/dist/src/generate.d.ts +35 -0
  94. package/dist/src/generate.js +166 -0
  95. package/dist/src/index.d.ts +42 -0
  96. package/dist/src/index.js +54 -0
  97. package/dist/src/inheritance.d.ts +69 -0
  98. package/dist/src/inheritance.js +136 -0
  99. package/dist/src/inventory.d.ts +194 -0
  100. package/dist/src/inventory.js +637 -0
  101. package/dist/src/item-durability.d.ts +69 -0
  102. package/dist/src/item-durability.js +308 -0
  103. package/dist/src/legend.d.ts +97 -0
  104. package/dist/src/legend.js +269 -0
  105. package/dist/src/lod.d.ts +9 -0
  106. package/dist/src/lod.js +84 -0
  107. package/dist/src/metrics.d.ts +51 -0
  108. package/dist/src/metrics.js +91 -0
  109. package/dist/src/model3d.d.ts +138 -0
  110. package/dist/src/model3d.js +214 -0
  111. package/dist/src/mythology.d.ts +101 -0
  112. package/dist/src/mythology.js +308 -0
  113. package/dist/src/narrative-render.d.ts +42 -0
  114. package/dist/src/narrative-render.js +194 -0
  115. package/dist/src/narrative-stress.d.ts +123 -0
  116. package/dist/src/narrative-stress.js +183 -0
  117. package/dist/src/narrative.d.ts +44 -0
  118. package/dist/src/narrative.js +257 -0
  119. package/dist/src/party.d.ts +70 -0
  120. package/dist/src/party.js +226 -0
  121. package/dist/src/polity.d.ts +262 -0
  122. package/dist/src/polity.js +398 -0
  123. package/dist/src/presets.d.ts +42 -0
  124. package/dist/src/presets.js +170 -0
  125. package/dist/src/progression.d.ts +170 -0
  126. package/dist/src/progression.js +256 -0
  127. package/dist/src/quest-generators.d.ts +76 -0
  128. package/dist/src/quest-generators.js +534 -0
  129. package/dist/src/quest.d.ts +239 -0
  130. package/dist/src/quest.js +520 -0
  131. package/dist/src/relationships-effects.d.ts +75 -0
  132. package/dist/src/relationships-effects.js +219 -0
  133. package/dist/src/relationships.d.ts +104 -0
  134. package/dist/src/relationships.js +347 -0
  135. package/dist/src/replay.d.ts +47 -0
  136. package/dist/src/replay.js +82 -0
  137. package/dist/src/rng.d.ts +9 -0
  138. package/dist/src/rng.js +37 -0
  139. package/dist/src/settlement-services.d.ts +67 -0
  140. package/dist/src/settlement-services.js +267 -0
  141. package/dist/src/settlement.d.ts +143 -0
  142. package/dist/src/settlement.js +419 -0
  143. package/dist/src/sim/action.d.ts +28 -0
  144. package/dist/src/sim/action.js +12 -0
  145. package/dist/src/sim/aging.d.ts +95 -0
  146. package/dist/src/sim/aging.js +243 -0
  147. package/dist/src/sim/ai/decide.d.ts +10 -0
  148. package/dist/src/sim/ai/decide.js +267 -0
  149. package/dist/src/sim/ai/perception.d.ts +12 -0
  150. package/dist/src/sim/ai/perception.js +54 -0
  151. package/dist/src/sim/ai/personality.d.ts +54 -0
  152. package/dist/src/sim/ai/personality.js +202 -0
  153. package/dist/src/sim/ai/presets.d.ts +2 -0
  154. package/dist/src/sim/ai/presets.js +28 -0
  155. package/dist/src/sim/ai/system.d.ts +6 -0
  156. package/dist/src/sim/ai/system.js +13 -0
  157. package/dist/src/sim/ai/targeting.d.ts +8 -0
  158. package/dist/src/sim/ai/targeting.js +42 -0
  159. package/dist/src/sim/ai/types.d.ts +14 -0
  160. package/dist/src/sim/ai/types.js +1 -0
  161. package/dist/src/sim/body.d.ts +9 -0
  162. package/dist/src/sim/body.js +32 -0
  163. package/dist/src/sim/bodyplan.d.ts +161 -0
  164. package/dist/src/sim/bodyplan.js +677 -0
  165. package/dist/src/sim/capability.d.ts +135 -0
  166. package/dist/src/sim/capability.js +8 -0
  167. package/dist/src/sim/combat.d.ts +21 -0
  168. package/dist/src/sim/combat.js +77 -0
  169. package/dist/src/sim/commandBuilders.d.ts +11 -0
  170. package/dist/src/sim/commandBuilders.js +39 -0
  171. package/dist/src/sim/commands.d.ts +71 -0
  172. package/dist/src/sim/commands.js +8 -0
  173. package/dist/src/sim/condition.d.ts +35 -0
  174. package/dist/src/sim/condition.js +21 -0
  175. package/dist/src/sim/cone.d.ts +40 -0
  176. package/dist/src/sim/cone.js +44 -0
  177. package/dist/src/sim/context.d.ts +68 -0
  178. package/dist/src/sim/context.js +1 -0
  179. package/dist/src/sim/density.d.ts +14 -0
  180. package/dist/src/sim/density.js +33 -0
  181. package/dist/src/sim/disease.d.ts +141 -0
  182. package/dist/src/sim/disease.js +353 -0
  183. package/dist/src/sim/entity.d.ts +251 -0
  184. package/dist/src/sim/entity.js +19 -0
  185. package/dist/src/sim/events.d.ts +25 -0
  186. package/dist/src/sim/events.js +5 -0
  187. package/dist/src/sim/explosion.d.ts +40 -0
  188. package/dist/src/sim/explosion.js +40 -0
  189. package/dist/src/sim/formation-unit.d.ts +138 -0
  190. package/dist/src/sim/formation-unit.js +197 -0
  191. package/dist/src/sim/formation.d.ts +12 -0
  192. package/dist/src/sim/formation.js +54 -0
  193. package/dist/src/sim/frontage.d.ts +30 -0
  194. package/dist/src/sim/frontage.js +84 -0
  195. package/dist/src/sim/grapple.d.ts +100 -0
  196. package/dist/src/sim/grapple.js +480 -0
  197. package/dist/src/sim/hazard.d.ts +104 -0
  198. package/dist/src/sim/hazard.js +201 -0
  199. package/dist/src/sim/hydrostatic.d.ts +58 -0
  200. package/dist/src/sim/hydrostatic.js +117 -0
  201. package/dist/src/sim/impairment.d.ts +20 -0
  202. package/dist/src/sim/impairment.js +162 -0
  203. package/dist/src/sim/indexing.d.ts +7 -0
  204. package/dist/src/sim/indexing.js +7 -0
  205. package/dist/src/sim/injury.d.ts +54 -0
  206. package/dist/src/sim/injury.js +66 -0
  207. package/dist/src/sim/intent.d.ts +26 -0
  208. package/dist/src/sim/intent.js +7 -0
  209. package/dist/src/sim/kernel.d.ts +45 -0
  210. package/dist/src/sim/kernel.js +1992 -0
  211. package/dist/src/sim/kinds.d.ts +64 -0
  212. package/dist/src/sim/kinds.js +56 -0
  213. package/dist/src/sim/knockback.d.ts +50 -0
  214. package/dist/src/sim/knockback.js +82 -0
  215. package/dist/src/sim/limb.d.ts +48 -0
  216. package/dist/src/sim/limb.js +78 -0
  217. package/dist/src/sim/medical.d.ts +32 -0
  218. package/dist/src/sim/medical.js +33 -0
  219. package/dist/src/sim/morale.d.ts +69 -0
  220. package/dist/src/sim/morale.js +92 -0
  221. package/dist/src/sim/mount.d.ts +150 -0
  222. package/dist/src/sim/mount.js +225 -0
  223. package/dist/src/sim/nutrition.d.ts +74 -0
  224. package/dist/src/sim/nutrition.js +168 -0
  225. package/dist/src/sim/occlusion.d.ts +8 -0
  226. package/dist/src/sim/occlusion.js +71 -0
  227. package/dist/src/sim/push.d.ts +11 -0
  228. package/dist/src/sim/push.js +79 -0
  229. package/dist/src/sim/ranged.d.ts +44 -0
  230. package/dist/src/sim/ranged.js +69 -0
  231. package/dist/src/sim/seeds.d.ts +3 -0
  232. package/dist/src/sim/seeds.js +16 -0
  233. package/dist/src/sim/sensory-extended.d.ts +103 -0
  234. package/dist/src/sim/sensory-extended.js +181 -0
  235. package/dist/src/sim/sensory.d.ts +38 -0
  236. package/dist/src/sim/sensory.js +109 -0
  237. package/dist/src/sim/skills.d.ts +70 -0
  238. package/dist/src/sim/skills.js +69 -0
  239. package/dist/src/sim/sleep.d.ts +107 -0
  240. package/dist/src/sim/sleep.js +215 -0
  241. package/dist/src/sim/spatial.d.ts +8 -0
  242. package/dist/src/sim/spatial.js +59 -0
  243. package/dist/src/sim/step/capability.d.ts +8 -0
  244. package/dist/src/sim/step/capability.js +77 -0
  245. package/dist/src/sim/step/concentration.d.ts +9 -0
  246. package/dist/src/sim/step/concentration.js +25 -0
  247. package/dist/src/sim/step/effects.d.ts +17 -0
  248. package/dist/src/sim/step/effects.js +96 -0
  249. package/dist/src/sim/step/energy.d.ts +3 -0
  250. package/dist/src/sim/step/energy.js +31 -0
  251. package/dist/src/sim/step/hazards.d.ts +4 -0
  252. package/dist/src/sim/step/hazards.js +19 -0
  253. package/dist/src/sim/step/injury.d.ts +10 -0
  254. package/dist/src/sim/step/injury.js +353 -0
  255. package/dist/src/sim/step/morale.d.ts +11 -0
  256. package/dist/src/sim/step/morale.js +130 -0
  257. package/dist/src/sim/step/movement.d.ts +5 -0
  258. package/dist/src/sim/step/movement.js +172 -0
  259. package/dist/src/sim/step/push.d.ts +11 -0
  260. package/dist/src/sim/step/push.js +79 -0
  261. package/dist/src/sim/step/substances.d.ts +3 -0
  262. package/dist/src/sim/step/substances.js +75 -0
  263. package/dist/src/sim/substance.d.ts +38 -0
  264. package/dist/src/sim/substance.js +57 -0
  265. package/dist/src/sim/systemic-toxicology.d.ts +109 -0
  266. package/dist/src/sim/systemic-toxicology.js +263 -0
  267. package/dist/src/sim/team.d.ts +9 -0
  268. package/dist/src/sim/team.js +37 -0
  269. package/dist/src/sim/tech.d.ts +36 -0
  270. package/dist/src/sim/tech.js +46 -0
  271. package/dist/src/sim/terrain.d.ts +121 -0
  272. package/dist/src/sim/terrain.js +141 -0
  273. package/dist/src/sim/testing.d.ts +13 -0
  274. package/dist/src/sim/testing.js +100 -0
  275. package/dist/src/sim/thermoregulation.d.ts +77 -0
  276. package/dist/src/sim/thermoregulation.js +161 -0
  277. package/dist/src/sim/tick.d.ts +3 -0
  278. package/dist/src/sim/tick.js +3 -0
  279. package/dist/src/sim/toxicology.d.ts +52 -0
  280. package/dist/src/sim/toxicology.js +104 -0
  281. package/dist/src/sim/trace.d.ts +141 -0
  282. package/dist/src/sim/trace.js +1 -0
  283. package/dist/src/sim/tuning.d.ts +16 -0
  284. package/dist/src/sim/tuning.js +42 -0
  285. package/dist/src/sim/vec3.d.ts +14 -0
  286. package/dist/src/sim/vec3.js +31 -0
  287. package/dist/src/sim/weapon_dynamics.d.ts +102 -0
  288. package/dist/src/sim/weapon_dynamics.js +142 -0
  289. package/dist/src/sim/weather.d.ts +95 -0
  290. package/dist/src/sim/weather.js +105 -0
  291. package/dist/src/sim/world.d.ts +52 -0
  292. package/dist/src/sim/world.js +1 -0
  293. package/dist/src/sim/wound-aging.d.ts +120 -0
  294. package/dist/src/sim/wound-aging.js +223 -0
  295. package/dist/src/species.d.ts +106 -0
  296. package/dist/src/species.js +664 -0
  297. package/dist/src/story-arcs.d.ts +17 -0
  298. package/dist/src/story-arcs.js +276 -0
  299. package/dist/src/tech-diffusion.d.ts +80 -0
  300. package/dist/src/tech-diffusion.js +185 -0
  301. package/dist/src/traits.d.ts +25 -0
  302. package/dist/src/traits.js +178 -0
  303. package/dist/src/types.d.ts +117 -0
  304. package/dist/src/types.js +1 -0
  305. package/dist/src/units.d.ts +41 -0
  306. package/dist/src/units.js +64 -0
  307. package/dist/src/weapons.d.ts +20 -0
  308. package/dist/src/weapons.js +824 -0
  309. package/dist/src/world-generation.d.ts +52 -0
  310. package/dist/src/world-generation.js +301 -0
  311. package/package.json +74 -0
@@ -0,0 +1,251 @@
1
+ import type { IndividualAttributes, EnergyState, PersonalityTraits } from "../types.js";
2
+ import type { WillpowerState } from "../competence/willpower.js";
3
+ import type { Loadout } from "../equipment.js";
4
+ import type { TraitId } from "../traits.js";
5
+ import type { SpeciesPhysiology } from "../species.js";
6
+ import type { Vec3 } from "./vec3.js";
7
+ import type { ConditionState } from "./condition.js";
8
+ import type { InjuryState } from "./injury.js";
9
+ import type { IntentState, AIState } from "./intent.js";
10
+ import type { ActionState } from "./action.js";
11
+ import type { SkillMap } from "./skills.js";
12
+ import type { BodyPlan } from "./bodyplan.js";
13
+ import type { ActiveSubstance } from "./substance.js";
14
+ import type { CapabilitySource, PendingActivation } from "./capability.js";
15
+ import type { ActiveVenom } from "./toxicology.js";
16
+ import type { LimbState } from "./limb.js";
17
+ import type { ExtendedSenses } from "./sensory-extended.js";
18
+ import type { ActiveIngestedToxin, CumulativeExposureRecord, WithdrawalState } from "./systemic-toxicology.js";
19
+ import type { TraumaState } from "./wound-aging.js";
20
+ import type { DiseaseState, ImmunityRecord } from "./disease.js";
21
+ import type { AgeState } from "./aging.js";
22
+ import type { SleepState } from "./sleep.js";
23
+ import type { MountState } from "./mount.js";
24
+ /** Phase 12B: state for an active concentration aura (castTime_ticks = -1 effect). */
25
+ export interface ConcentrationState {
26
+ sourceId: string;
27
+ effectId: string;
28
+ targetId?: number;
29
+ }
30
+ import { Q } from "../units.js";
31
+ import { CompiledAnatomyModel } from "../anatomy/anatomy-contracts.js";
32
+ import { AnatomyHelperRegistry } from "../anatomy/anatomy-helpers.js";
33
+ export type GrapplePosition = "standing" | "prone" | "pinned";
34
+ export interface GrappleState {
35
+ holdingTargetId: number;
36
+ heldByIds: number[];
37
+ gripQ: Q;
38
+ position: GrapplePosition;
39
+ }
40
+ /**
41
+ * Core entity shape.
42
+ *
43
+ * Fields are annotated with one of three stability tiers:
44
+ *
45
+ * - **`@core`** — Required by `stepWorld` on every tick. Always present; never optional.
46
+ * Removing or renaming any `@core` field is a Tier 1 breaking change.
47
+ *
48
+ * - **`@subsystem(name)`** — Optional state consumed only by a specific sub-module
49
+ * (`src/sim/sleep.ts`, `src/sim/aging.ts`, etc.). Omitting a subsystem field disables that
50
+ * module's behaviour for this entity; the kernel continues to run correctly without it.
51
+ * Adding new optional subsystem fields is never a breaking change.
52
+ *
53
+ * - **`@extension`** — Not consumed by Ananke at all. Reserved for host-application data
54
+ * that travels alongside entities (e.g. renderer-side metadata, network session IDs).
55
+ * Currently no built-in fields carry this tag; hosts may add their own `?` fields freely.
56
+ */
57
+ export interface Entity {
58
+ /** @core Unique entity identifier — must be stable across ticks. */
59
+ id: number;
60
+ /** @core Combat team / allegiance used by attack resolution and AI targeting. */
61
+ teamId: number;
62
+ /** @core Physical and cognitive capabilities (mass, force, reaction time, etc.). */
63
+ attributes: IndividualAttributes;
64
+ /** @core Energy reserve and fatigue accumulator — drained by movement and combat. */
65
+ energy: EnergyState;
66
+ /**
67
+ * @subsystem(willpower) Cognitive stamina reserve — depleted by sustained concentration,
68
+ * replenished by rest. Consumed by `src/competence/willpower.ts`.
69
+ */
70
+ willpower?: WillpowerState;
71
+ /** @core Equipped items: weapons, armour, held objects. */
72
+ loadout: Loadout;
73
+ /** @core Permanent trait flags that modify combat and skill outcomes. */
74
+ traits: TraitId[];
75
+ /**
76
+ * @subsystem(skills) Per-skill proficiency map.
77
+ * Consumed by skill-contest resolution in `src/sim/combat.ts` and `src/sim/ai/`.
78
+ */
79
+ skills?: SkillMap;
80
+ /**
81
+ * @subsystem(anatomy) Body plan defining injury segments, mass distribution, and
82
+ * data-driven impairment tables. Consumed by `src/sim/injury.ts`, `src/model3d.ts`,
83
+ * and the anatomy compiler.
84
+ */
85
+ bodyPlan?: BodyPlan;
86
+ /**
87
+ * @subsystem(pharmacology) Active pharmacological substances currently in the bloodstream.
88
+ * Consumed by `src/sim/substance.ts`.
89
+ */
90
+ substances?: ActiveSubstance[];
91
+ /**
92
+ * @subsystem(nutrition) Consumable food items and counts.
93
+ * Consumed by the nutrition accumulator in `src/sim/kernel.ts` when present.
94
+ */
95
+ foodInventory?: Map<string, number> | undefined;
96
+ /**
97
+ * @subsystem(anatomy) Molting state for arthropod-type entities.
98
+ * Active molt: segments in `softeningSegments` take reduced kinetic structural damage.
99
+ * When `ticksRemaining` reaches 0, `regeneratesViaMolting` segments receive partial repair.
100
+ * Consumed by `src/sim/injury.ts`.
101
+ */
102
+ molting?: {
103
+ active: boolean;
104
+ ticksRemaining: number;
105
+ /** Segment IDs currently softening — take reduced kinetic structural damage (×q(0.70)). */
106
+ softeningSegments: string[];
107
+ };
108
+ /** @core World-space position in fixed-point metres (`SCALE.m` = 1 m). */
109
+ position_m: Vec3;
110
+ /** @core Velocity in fixed-point metres per second (`SCALE.mps` = 1 m/s). */
111
+ velocity_mps: Vec3;
112
+ /** @core Movement and defence intent derived from the previous tick's commands. */
113
+ intent: IntentState;
114
+ /** @core Attack cooldowns, swing momentum, weapon-bind state. */
115
+ action: ActionState;
116
+ /** @core Physiological condition: fear, morale, sensory modifiers, fatigue, thermal. */
117
+ condition: ConditionState;
118
+ /** @core Per-region damage, shock, consciousness, fluid loss, death flag. */
119
+ injury: InjuryState;
120
+ /** @core Active grapple relationships, grip strength, positional lock. */
121
+ grapple: GrappleState;
122
+ /**
123
+ * @subsystem(ai) AI decision state (target selection, last-seen position, threat map).
124
+ * Consumed by `src/sim/ai/system.ts`; absent for player-controlled or scripted entities.
125
+ */
126
+ ai?: AIState;
127
+ /**
128
+ * @subsystem(capability) Attached capability sources (mana pools, fusion cells, divine
129
+ * reserves). Consumed by `src/sim/capability.ts`.
130
+ */
131
+ capabilitySources?: CapabilitySource[];
132
+ /**
133
+ * @subsystem(armour) Mutable resist state for ablative armour items.
134
+ * Key = item id; value = remaining resist in joules.
135
+ * Initialised automatically by `stepWorld` for entities with ablative items.
136
+ */
137
+ armourState?: Map<string, {
138
+ resistRemaining_J: number;
139
+ }>;
140
+ /**
141
+ * @subsystem(capability) In-flight capability activation — cleared on completion or
142
+ * concentration break. Consumed by `src/sim/capability.ts`.
143
+ */
144
+ pendingActivation?: PendingActivation;
145
+ /**
146
+ * @subsystem(capability) Active concentration aura — cleared when willpower reserve
147
+ * depletes or shock interrupts. Consumed by `src/sim/capability.ts`.
148
+ */
149
+ activeConcentration?: ConcentrationState;
150
+ /**
151
+ * @subsystem(faction) Faction membership identifier.
152
+ * Consumed by `src/faction.ts` and AI targeting.
153
+ */
154
+ faction?: string;
155
+ /**
156
+ * @subsystem(party) Adventuring party membership identifier.
157
+ * Consumed by `src/party.ts` for morale and formation bonuses.
158
+ */
159
+ party?: string | undefined;
160
+ /**
161
+ * @subsystem(faction) Entity-level faction-standing overrides.
162
+ * Map<factionId, Q> — takes priority over faction-default standings when set.
163
+ * Consumed by `src/faction.ts`.
164
+ */
165
+ reputations?: Map<string, number>;
166
+ /**
167
+ * @subsystem(thermoregulation) Species-level physiological overrides.
168
+ * Consumed by `src/sim/thermoregulation.ts` for heat/cold stress modelling.
169
+ */
170
+ physiology?: SpeciesPhysiology | undefined;
171
+ /**
172
+ * @subsystem(toxicology) Active venom/toxin injections — ticked at 1 Hz.
173
+ * Consumed by `src/sim/toxicology.ts`.
174
+ */
175
+ activeVenoms?: ActiveVenom[];
176
+ /**
177
+ * @subsystem(anatomy) Per-limb state for multi-limb entities (octopoids, arachnids).
178
+ * Consumed by `src/sim/limb.ts`.
179
+ */
180
+ limbStates?: LimbState[];
181
+ /**
182
+ * @subsystem(ai) Individual AI personality traits (aggression, caution, loyalty).
183
+ * Consumed by `src/sim/ai/personality.ts`.
184
+ */
185
+ personality?: PersonalityTraits;
186
+ /**
187
+ * @subsystem(sensory) Extended sensory modalities (echolocation, electroreception,
188
+ * olfaction). Consumed by `src/sim/sensory-extended.ts`.
189
+ */
190
+ extendedSenses?: ExtendedSenses;
191
+ /**
192
+ * @subsystem(toxicology) Active ingested toxins (alcohol, sedatives, alkaloids, heavy
193
+ * metals, radiation). Consumed by `src/sim/systemic-toxicology.ts`.
194
+ */
195
+ activeIngestedToxins?: ActiveIngestedToxin[];
196
+ /**
197
+ * @subsystem(toxicology) Cumulative lifetime dose records for heavy metals and radiation.
198
+ * Consumed by `src/sim/systemic-toxicology.ts`.
199
+ */
200
+ cumulativeExposure?: CumulativeExposureRecord[];
201
+ /**
202
+ * @subsystem(toxicology) Active withdrawal states from addictive toxin removal.
203
+ * Consumed by `src/sim/systemic-toxicology.ts`.
204
+ */
205
+ withdrawal?: WithdrawalState[];
206
+ /**
207
+ * @subsystem(wound-aging) PTSD-like trauma state accumulated from severe shock events.
208
+ * Reduces effective fear threshold via `deriveFearThresholdMul`.
209
+ * Consumed by `src/sim/wound-aging.ts`.
210
+ */
211
+ traumaState?: TraumaState;
212
+ /**
213
+ * @subsystem(disease) Active systemic disease states (incubating or symptomatic).
214
+ * Consumed by `src/sim/disease.ts`.
215
+ */
216
+ activeDiseases?: DiseaseState[];
217
+ /**
218
+ * @subsystem(disease) Post-recovery immunity records preventing re-infection.
219
+ * Consumed by `src/sim/disease.ts`.
220
+ */
221
+ immunity?: ImmunityRecord[];
222
+ /**
223
+ * @subsystem(aging) Elapsed life-seconds for aging calculations.
224
+ * Consumed by `src/sim/aging.ts`.
225
+ */
226
+ age?: AgeState;
227
+ /**
228
+ * @subsystem(sleep) Sleep-phase state, debt accumulator, and continuous wake time.
229
+ * Consumed by `src/sim/sleep.ts`.
230
+ */
231
+ sleep?: SleepState;
232
+ /**
233
+ * @subsystem(mount) Rider/mount pair state for cavalry and mounted combat.
234
+ * Consumed by `src/sim/mount.ts`.
235
+ */
236
+ mount?: MountState;
237
+ /**
238
+ * @subsystem(anatomy) Compiled anatomy model — cached on first access by
239
+ * `ensureAnatomyRuntime`. Do not set manually.
240
+ */
241
+ compiledAnatomy?: CompiledAnatomyModel;
242
+ /**
243
+ * @subsystem(anatomy) Anatomy helper registry — cached on first access by
244
+ * `ensureAnatomyRuntime`. Do not set manually.
245
+ */
246
+ anatomyHelpers?: AnatomyHelperRegistry;
247
+ }
248
+ export declare function ensureAnatomyRuntime(e: Entity): {
249
+ model?: CompiledAnatomyModel;
250
+ helpers?: AnatomyHelperRegistry;
251
+ };
@@ -0,0 +1,19 @@
1
+ import { createAnatomyHelpers } from "../anatomy/anatomy-helpers.js";
2
+ import { compileAnatomyDefinition } from "../anatomy/anatomy-compiler.js";
3
+ export function ensureAnatomyRuntime(e) {
4
+ if (!e.bodyPlan)
5
+ return {};
6
+ if (!e.compiledAnatomy) {
7
+ const compiled = compileAnatomyDefinition(e.bodyPlan);
8
+ if (!compiled.ok)
9
+ return {};
10
+ e.compiledAnatomy = compiled.model;
11
+ }
12
+ if (!e.anatomyHelpers) {
13
+ e.anatomyHelpers = createAnatomyHelpers(e.compiledAnatomy);
14
+ }
15
+ return {
16
+ model: e.compiledAnatomy,
17
+ helpers: e.anatomyHelpers,
18
+ };
19
+ }
@@ -0,0 +1,25 @@
1
+ import type { Weapon } from "../equipment.js";
2
+ import type { Q } from "../units.js";
3
+ export interface ImpactEvent {
4
+ kind: "impact";
5
+ attackerId: number;
6
+ targetId: number;
7
+ /** Segment id of the struck region (BodyRegion string for humanoid; arbitrary string for other body plans). */
8
+ region: string;
9
+ energy_J: number;
10
+ protectedByArmour: boolean;
11
+ blocked: boolean;
12
+ parried: boolean;
13
+ weaponId: string;
14
+ wpn: Weapon;
15
+ hitQuality: Q;
16
+ shieldBlocked: boolean;
17
+ /** Phase 26: effective striking mass (weapon head + body fraction, or projectile mass) in SCALE.kg units. */
18
+ massEff_kg?: number;
19
+ /** Phase 27: projectile velocity at impact point (pre-armour, post-drag) in SCALE.mps units. */
20
+ v_impact_mps?: number;
21
+ }
22
+ export declare function sortEventsDeterministic<T extends {
23
+ attackerId: number;
24
+ targetId: number;
25
+ }>(ev: T[]): void;
@@ -0,0 +1,5 @@
1
+ export function sortEventsDeterministic(ev) {
2
+ ev.sort((a, b) => a.attackerId !== b.attackerId ? a.attackerId - b.attackerId :
3
+ a.targetId !== b.targetId ? a.targetId - b.targetId :
4
+ 0);
5
+ }
@@ -0,0 +1,40 @@
1
+ import type { I32, Q } from "../units.js";
2
+ /**
3
+ * Point-source explosion specification.
4
+ *
5
+ * `fragmentCount` is the expected number of fragment hits on an average
6
+ * body-sized target at the blast epicentre (dist = 0). At distance d it
7
+ * scales quadratically with the same falloff as blast energy. Set it to
8
+ * reflect how many fragments realistically hit a human-sized target up close,
9
+ * not the total count of fragments ejected (which would be spread over a sphere).
10
+ */
11
+ export interface BlastSpec {
12
+ /** Peak blast energy at epicentre (J; SCALE.J = 1 so this is SI joules directly). */
13
+ blastEnergy_J: number;
14
+ /** Effective blast radius (SCALE.m fixed-point). */
15
+ radius_m: I32;
16
+ /** Expected fragment hits on a body-sized target at the epicentre (dist = 0). */
17
+ fragmentCount: number;
18
+ /** Mass of each fragment (SCALE.kg fixed-point; e.g. to.kg(0.005) = 5 for 5 g). */
19
+ fragmentMass_kg: I32;
20
+ /** Fragment ejection speed (m/s raw integer; e.g. 300 for a typical grenade). */
21
+ fragmentVelocity_mps: number;
22
+ }
23
+ /**
24
+ * Blast energy fraction (Q) delivered to a target at squared fixed-point
25
+ * distance `distSq_m2` from the epicentre.
26
+ * Quadratic falloff: frac = max(0, 1 − dist²/radius²).
27
+ * Returns 0 when distSq_m2 ≥ radius_m².
28
+ */
29
+ export declare function blastEnergyFracQ(spec: BlastSpec, distSq_m2: number): Q;
30
+ /**
31
+ * Expected number of fragment hits on a target at squared distance `distSq_m2`.
32
+ * May be fractional; caller should round stochastically with a seed roll for
33
+ * the fractional part.
34
+ */
35
+ export declare function fragmentsExpected(spec: BlastSpec, distSq_m2: number): number;
36
+ /**
37
+ * Kinetic energy (J) of a single fragment at squared distance `distSq_m2`.
38
+ * KE = 0.5 × mass × velocity²; attenuated by the quadratic falloff.
39
+ */
40
+ export declare function fragmentKineticEnergy(spec: BlastSpec, distSq_m2: number): number;
@@ -0,0 +1,40 @@
1
+ // src/sim/explosion.ts — Phase 10: blast and fragmentation physics
2
+ import { SCALE, q, mulDiv } from "../units.js";
3
+ /**
4
+ * Blast energy fraction (Q) delivered to a target at squared fixed-point
5
+ * distance `distSq_m2` from the epicentre.
6
+ * Quadratic falloff: frac = max(0, 1 − dist²/radius²).
7
+ * Returns 0 when distSq_m2 ≥ radius_m².
8
+ */
9
+ export function blastEnergyFracQ(spec, distSq_m2) {
10
+ const radiusSq = spec.radius_m * spec.radius_m;
11
+ if (distSq_m2 >= radiusSq)
12
+ return q(0);
13
+ return mulDiv(radiusSq - distSq_m2, SCALE.Q, radiusSq);
14
+ }
15
+ /**
16
+ * Expected number of fragment hits on a target at squared distance `distSq_m2`.
17
+ * May be fractional; caller should round stochastically with a seed roll for
18
+ * the fractional part.
19
+ */
20
+ export function fragmentsExpected(spec, distSq_m2) {
21
+ const fracQ = blastEnergyFracQ(spec, distSq_m2);
22
+ if (fracQ <= 0)
23
+ return 0;
24
+ return spec.fragmentCount * fracQ / SCALE.Q;
25
+ }
26
+ /**
27
+ * Kinetic energy (J) of a single fragment at squared distance `distSq_m2`.
28
+ * KE = 0.5 × mass × velocity²; attenuated by the quadratic falloff.
29
+ */
30
+ export function fragmentKineticEnergy(spec, distSq_m2) {
31
+ const fracQ = blastEnergyFracQ(spec, distSq_m2);
32
+ if (fracQ <= 0)
33
+ return 0;
34
+ // KE_base = mass_kg_real × vel² / 2
35
+ // = (fragmentMass_kg / SCALE.kg) × fragmentVelocity_mps² / 2
36
+ // = fragmentMass_kg × velocity² / (2 × SCALE.kg)
37
+ const keBase = Math.trunc((spec.fragmentMass_kg * spec.fragmentVelocity_mps * spec.fragmentVelocity_mps) /
38
+ (2 * SCALE.kg));
39
+ return mulDiv(keBase, fracQ, SCALE.Q);
40
+ }
@@ -0,0 +1,138 @@
1
+ /**
2
+ * Phase 6 — Formation System
3
+ *
4
+ * Pure computation module for tactical formation mechanics:
5
+ * - Shield walls: adjacent shield-bearers pool block coverage
6
+ * - Rank depth: entities sorted by forward projection; front/rear split
7
+ * - Casualty fill: rear-rank entities promote when front rank is lost
8
+ * - Push of pike: total formation momentum from mass × velocity
9
+ * - Formation cohesion: morale bonus / rout-contagion penalty
10
+ *
11
+ * No Entity or WorldState imports — callers extract the needed values and
12
+ * pass plain numbers / maps. All arithmetic is integer fixed-point.
13
+ */
14
+ import { type Q } from "../../src/units.js";
15
+ export type FormationShape = "line" | "shield_wall" | "wedge" | "column";
16
+ export interface FormationUnit {
17
+ id: string;
18
+ name: string;
19
+ shape: FormationShape;
20
+ entityIds: number[];
21
+ }
22
+ export interface RankSplit {
23
+ /** Entity IDs nearest the enemy (most-forward projection). */
24
+ frontRank: number[];
25
+ /** Entity IDs behind the front rank. */
26
+ rearRank: number[];
27
+ }
28
+ export interface FormationMomentum {
29
+ /**
30
+ * Total formation momentum in (SCALE.kg × m/s) units.
31
+ * Divide by SCALE.kg (= 1000) to obtain physical kg·m/s.
32
+ */
33
+ momentum_Skg_mps: number;
34
+ /** Number of entities that contributed (speed > 0). */
35
+ entityCount: number;
36
+ }
37
+ export interface FormationCohesionState {
38
+ /** True when intact fraction ≥ FORMATION_INTACT_THRESHOLD. */
39
+ intact: boolean;
40
+ /** Fraction of entities still alive and not routed, as a Q value. */
41
+ intactFrac_Q: Q;
42
+ /** Per-tick fear decay bonus when formation is intact. */
43
+ moraleBonus_Q: Q;
44
+ /** Per-tick fear increment when formation integrity has collapsed. */
45
+ moralePenalty_Q: Q;
46
+ }
47
+ /**
48
+ * Efficiency of shield coverage sharing between adjacent bearers.
49
+ * Each additional bearer beyond the first contributes at this fraction.
50
+ */
51
+ export declare const SHIELD_SHARING_FRAC: Q;
52
+ /** Hard cap on combined shield wall coverage. */
53
+ export declare const SHIELD_WALL_MAX_COVERAGE: Q;
54
+ /** Default rank depth used to split front/rear ranks (2 m in SCALE.m). */
55
+ export declare const RANK_DEPTH_DEFAULT_m: number;
56
+ /**
57
+ * Minimum intact fraction for a formation to be considered cohesive.
58
+ * Below this threshold the rout-contagion penalty applies instead of the
59
+ * morale bonus.
60
+ */
61
+ export declare const FORMATION_INTACT_THRESHOLD: Q;
62
+ /** Fear decay bonus per tick granted to entities in an intact formation. */
63
+ export declare const FORMATION_MORALE_BONUS: Q;
64
+ /** Fear increment per tick when formation integrity has collapsed. */
65
+ export declare const FORMATION_MORALE_PENALTY: Q;
66
+ /** Per-tick fear decay granted per alive formation ally (vs q(0.002) unaffiliated). */
67
+ export declare const FORMATION_ALLY_FEAR_DECAY: Q;
68
+ /** Maximum number of formation allies counted for the fear decay bonus. */
69
+ export declare const FORMATION_ALLY_DECAY_CAP = 8;
70
+ /**
71
+ * Compute the combined block coverage of a shield wall.
72
+ *
73
+ * The bearer with the highest individual coverage contributes at full strength.
74
+ * Each subsequent bearer (sorted descending by coverage) contributes at
75
+ * SHIELD_SHARING_FRAC efficiency, modelling timing gaps and partial overlap
76
+ * between adjacent shields.
77
+ *
78
+ * Result is capped at SHIELD_WALL_MAX_COVERAGE = q(1.0).
79
+ */
80
+ export declare function computeShieldWallCoverage(coverageFracs: readonly Q[]): Q;
81
+ /**
82
+ * Split formation entity IDs into front and rear ranks.
83
+ *
84
+ * Each entity position is projected onto the facing direction. The entity
85
+ * with the greatest projection defines depth = 0. Entities within
86
+ * `rankDepth_m` of the frontmost entity are placed in the front rank; the
87
+ * rest go to the rear rank. Both ranks are sorted front-to-back.
88
+ *
89
+ * @param entityIds IDs to split
90
+ * @param positions Map: entity ID → {x, y} in SCALE.m
91
+ * @param facingDirQ Unit vector with components in Q units (SCALE.Q = 1.0)
92
+ * @param rankDepth_m Depth of front rank in SCALE.m (default: RANK_DEPTH_DEFAULT_m)
93
+ */
94
+ export declare function deriveRankSplit(entityIds: readonly number[], positions: ReadonlyMap<number, {
95
+ x: number;
96
+ y: number;
97
+ }>, facingDirQ: {
98
+ x: number;
99
+ y: number;
100
+ }, rankDepth_m?: number): RankSplit;
101
+ /**
102
+ * Promote rear-rank entities to fill vacancies left by front-rank losses.
103
+ *
104
+ * Returns new front and rear rank arrays with dead entities removed and
105
+ * replacements drawn from the front of the (alive) rear rank.
106
+ */
107
+ export declare function stepFormationCasualtyFill(rankSplit: RankSplit, deadIds: ReadonlySet<number>): RankSplit;
108
+ /**
109
+ * Compute the total forward momentum of a formation (push-of-pike model).
110
+ *
111
+ * `momentum_Skg_mps` is in (SCALE.kg × m/s) units — i.e. fixed-point mass
112
+ * multiplied by real-valued speed (speed already divided by SCALE.mps).
113
+ * Divide by SCALE.kg (= 1000) to obtain physical kg·m/s.
114
+ *
115
+ * Only entities with speed > 0 contribute.
116
+ *
117
+ * @param masses_Skg Entity masses in SCALE.kg units
118
+ * @param speeds_Smps Entity speeds (magnitude) in SCALE.mps units
119
+ */
120
+ export declare function computeFormationMomentum(masses_Skg: readonly number[], speeds_Smps: readonly number[]): FormationMomentum;
121
+ /**
122
+ * Derive the morale state of a formation from casualty / rout status.
123
+ *
124
+ * An entity is counted as lost if its ID appears in `deadOrRoutedIds`.
125
+ * When intactFrac_Q ≥ FORMATION_INTACT_THRESHOLD the formation grants a fear
126
+ * decay bonus; below it a rout-contagion penalty applies instead.
127
+ *
128
+ * An empty formation is considered vacuously intact but grants no bonus.
129
+ */
130
+ export declare function deriveFormationCohesion(entityIds: readonly number[], deadOrRoutedIds: ReadonlySet<number>): FormationCohesionState;
131
+ /**
132
+ * Compute the per-tick fear decay bonus from alive formation allies.
133
+ *
134
+ * Returns a larger bonus than the unaffiliated ally coefficient (q(0.002)):
135
+ * formation allies grant q(0.004) each, capped at FORMATION_ALLY_DECAY_CAP
136
+ * allies. Result is a Q value to be added to the entity's fear decay term.
137
+ */
138
+ export declare function deriveFormationAllyFearDecay(aliveFormationAllyCount: number): Q;