@origingame/engine 0.0.0-stage → 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 (158) hide show
  1. package/bin/og.mjs +25 -0
  2. package/dist/web/origin-engine.d.ts +1233 -0
  3. package/dist/web/origin-engine.js +8628 -0
  4. package/dist/web/origin-engine_bg.wasm +0 -0
  5. package/dist/web/origin-engine_bg.wasm.d.ts +366 -0
  6. package/dist/web-publish/origin-engine-lanes.js +8509 -0
  7. package/dist/web-publish/origin-engine-lanes_bg.wasm +0 -0
  8. package/dist/web-publish/origin-engine.d.ts +1176 -0
  9. package/dist/web-publish/origin-engine.js +8313 -0
  10. package/dist/web-publish/origin-engine_bg.wasm +0 -0
  11. package/dist/web-publish/origin-engine_bg.wasm.d.ts +347 -0
  12. package/dist/web-publish/snippets/wasm-bindgen-rayon-38edf6e439f6d70d/src/workerHelpers.no-bundler.js +77 -0
  13. package/dist/web-publish-2d/origin-engine-lanes.js +8509 -0
  14. package/dist/web-publish-2d/origin-engine-lanes_bg.wasm +0 -0
  15. package/dist/web-publish-2d/origin-engine.d.ts +1176 -0
  16. package/dist/web-publish-2d/origin-engine.js +8313 -0
  17. package/dist/web-publish-2d/origin-engine_bg.wasm +0 -0
  18. package/dist/web-publish-2d/origin-engine_bg.wasm.d.ts +347 -0
  19. package/dist/web-publish-2d/snippets/wasm-bindgen-rayon-38edf6e439f6d70d/src/workerHelpers.no-bundler.js +77 -0
  20. package/knowledge/README.md +31 -0
  21. package/knowledge/knowledge.json +13 -0
  22. package/knowledge/looks/catalogue.json +1871 -0
  23. package/knowledge/package.json +33 -0
  24. package/knowledge/rules/platform.json +329 -0
  25. package/knowledge/scaffold/README.md +27 -0
  26. package/knowledge/scaffold/distribution.json +48 -0
  27. package/knowledge/scaffold/origin-engine.json +19 -0
  28. package/knowledge/scaffold/template/.origin/setup +14 -0
  29. package/knowledge/scaffold/template/LICENSES.md +23 -0
  30. package/knowledge/scaffold/template/README.md +37 -0
  31. package/knowledge/scaffold/template/assets/ai/guard.ogt +48 -0
  32. package/knowledge/scaffold/template/assets/audio/click.ogt +9 -0
  33. package/knowledge/scaffold/template/assets/fonts/NotoSansSC-Regular-subset.ttf.ogt +12 -0
  34. package/knowledge/scaffold/template/assets/fonts/OFL.txt +93 -0
  35. package/knowledge/scaffold/template/assets/looks/origin-game.ogt +12 -0
  36. package/knowledge/scaffold/template/assets/nav/yard.ogt +27 -0
  37. package/knowledge/scaffold/template/assets/scenes/main.ogt +34 -0
  38. package/knowledge/scaffold/template/assets/strings/en.ogt +14 -0
  39. package/knowledge/scaffold/template/assets/textures/stone_n.png.ogt +7 -0
  40. package/knowledge/scaffold/template/gitattributes +22 -0
  41. package/knowledge/scaffold/template/package.json +18 -0
  42. package/knowledge/scaffold/template/project.ogt +25 -0
  43. package/knowledge/scaffold/template/src/main.ts +246 -0
  44. package/knowledge/scaffold/template/tests/guard.og.ts +67 -0
  45. package/knowledge/scaffold/template/tests/smoke.og.ts +43 -0
  46. package/knowledge/scaffold/template/tsconfig.json +17 -0
  47. package/knowledge/scripts/lib.ts +203 -0
  48. package/knowledge/scripts/mount.ts +210 -0
  49. package/knowledge/scripts/pack.ts +24 -0
  50. package/knowledge/scripts/scaffold.ts +72 -0
  51. package/knowledge/scripts/validate.ts +749 -0
  52. package/knowledge/skills/og-ai/SKILL.md +386 -0
  53. package/knowledge/skills/og-audio/SKILL.md +191 -0
  54. package/knowledge/skills/og-build/SKILL.md +330 -0
  55. package/knowledge/skills/og-core/SKILL.md +285 -0
  56. package/knowledge/skills/og-feel/SKILL.md +385 -0
  57. package/knowledge/skills/og-game/SKILL.md +1479 -0
  58. package/knowledge/skills/og-i18n/SKILL.md +220 -0
  59. package/knowledge/skills/og-platform-sdk/SKILL.md +199 -0
  60. package/knowledge/skills/og-taste/SKILL.md +537 -0
  61. package/knowledge/skills/og-ui/SKILL.md +444 -0
  62. package/knowledge/wiki/ai.md +627 -0
  63. package/knowledge/wiki/anim.md +1187 -0
  64. package/knowledge/wiki/atmosphere.md +636 -0
  65. package/knowledge/wiki/audio.md +732 -0
  66. package/knowledge/wiki/camera.md +711 -0
  67. package/knowledge/wiki/commands.md +357 -0
  68. package/knowledge/wiki/game.md +220 -0
  69. package/knowledge/wiki/i18n.md +213 -0
  70. package/knowledge/wiki/index.md +1027 -0
  71. package/knowledge/wiki/input.md +1714 -0
  72. package/knowledge/wiki/load.md +1280 -0
  73. package/knowledge/wiki/math.md +166 -0
  74. package/knowledge/wiki/nav.md +1154 -0
  75. package/knowledge/wiki/physics.md +3142 -0
  76. package/knowledge/wiki/platform.md +857 -0
  77. package/knowledge/wiki/probe.md +1692 -0
  78. package/knowledge/wiki/reflect.md +285 -0
  79. package/knowledge/wiki/render.md +3511 -0
  80. package/knowledge/wiki/rng.md +393 -0
  81. package/knowledge/wiki/stream.md +376 -0
  82. package/knowledge/wiki/system.md +197 -0
  83. package/knowledge/wiki/systems.md +43 -0
  84. package/knowledge/wiki/terrain.md +727 -0
  85. package/knowledge/wiki/tilemap.md +422 -0
  86. package/knowledge/wiki/time.md +150 -0
  87. package/knowledge/wiki/transform.md +230 -0
  88. package/knowledge/wiki/tween.md +580 -0
  89. package/knowledge/wiki/ui.md +8000 -0
  90. package/knowledge/wiki/world.md +909 -0
  91. package/package.json +68 -4
  92. package/schema/api.schema.json +29675 -0
  93. package/shell/README.md +22 -0
  94. package/shell/brand/README.md +23 -0
  95. package/shell/brand/icon-192.png +0 -0
  96. package/shell/brand/icon-512.png +0 -0
  97. package/shell/brand/mark-on-paper.svg +6 -0
  98. package/shell/brand/origin-mark.svg +5 -0
  99. package/shell/brand/origin-motion.css +251 -0
  100. package/shell/brand/tokens.css +20 -0
  101. package/shell/brand.ts +132 -0
  102. package/shell/page.ts +715 -0
  103. package/shell/platform.ts +203 -0
  104. package/shell/player.ts +238 -0
  105. package/shell/shell.css +185 -0
  106. package/shell/sw.ts +177 -0
  107. package/shell/transport.ts +515 -0
  108. package/shell/wire.ts +369 -0
  109. package/src/e6.ts +69 -0
  110. package/src/env.d.ts +100 -0
  111. package/src/generated/abi.ts +980 -0
  112. package/src/index.ts +193 -0
  113. package/src/node/audio.ts +86 -0
  114. package/src/node/build.ts +109 -0
  115. package/src/node/device.ts +981 -0
  116. package/src/node/doctor.ts +60 -0
  117. package/src/node/index.ts +102 -0
  118. package/src/node/platform.ts +24 -0
  119. package/src/node/playtest-run.ts +249 -0
  120. package/src/node/png.ts +130 -0
  121. package/src/node/polish.ts +976 -0
  122. package/src/node/run.ts +373 -0
  123. package/src/node/web-build.ts +808 -0
  124. package/src/p2.ts +35 -0
  125. package/src/platform-local.ts +211 -0
  126. package/src/playtest.ts +131 -0
  127. package/src/runtime.ts +1509 -0
  128. package/src/systems/cameras.ts +247 -0
  129. package/src/ui-kit/bind.ts +141 -0
  130. package/src/ui-kit/huds.ts +303 -0
  131. package/src/ui-kit/index.ts +36 -0
  132. package/src/ui-kit/menus.ts +187 -0
  133. package/src/ui-kit/settings.ts +131 -0
  134. package/src/ui-kit/store.ts +222 -0
  135. package/src/ui-kit/story.ts +89 -0
  136. package/src/ui-kit/util.ts +106 -0
  137. package/src/web/a11y.ts +429 -0
  138. package/src/web/audio-worklet.ts +193 -0
  139. package/src/web/audio.ts +307 -0
  140. package/src/web/basis.ts +239 -0
  141. package/src/web/gamepad.ts +123 -0
  142. package/src/web/host.ts +166 -0
  143. package/src/web/input.ts +237 -0
  144. package/src/web/lanes.ts +21 -0
  145. package/src/web/play.ts +20 -0
  146. package/src/web/rpc-ring.ts +110 -0
  147. package/src/web/settle.ts +122 -0
  148. package/src/web/shell.ts +643 -0
  149. package/src/web/text-input.ts +248 -0
  150. package/src/web/worker.ts +1002 -0
  151. package/types/bindings.json +13654 -0
  152. package/types/index.d.ts +20090 -0
  153. package/vendor/basis/LICENSE +201 -0
  154. package/vendor/basis/NOTICE +15 -0
  155. package/vendor/basis/README.md +18 -0
  156. package/vendor/basis/basis_transcoder.js +19 -0
  157. package/vendor/basis/basis_transcoder.wasm +0 -0
  158. package/README.md +0 -3
@@ -0,0 +1,627 @@
1
+ <!-- Generated from crates/og-api/api.ogt by `og api gen`. Do not edit: `og api check` fails on any difference; change api.ogt and regenerate. -->
2
+
3
+ # The `ai` module
4
+
5
+ Enemy and NPC AI as data: behaviour trees and state machines in `.ogt` files of `type behaviour` (og-ai §3 has every line), perception (sight cones checked against physics occlusion, hearing of spatial sounds and game noises) and a blackboard per agent.
6
+
7
+ An entity with an og.AiAgent (and an og.Transform) thinks in the og.ai system before the game's systems: perception first, then its tree or machine, whose running action moves it through its og.NavAgent (og.nav plans and walks after the game's systems) or runs one of the game's commands (GameDesc.commands, with the agent's entity handle as its first argument) before the next tick.
8
+
9
+ Conditions read blackboard keys (declared, set by actions or og.ai.set, or built in: self, position, sees, heard, target, targetPosition, targetDistance, lastSeen, sinceSeen, heardAt, sinceHeard, elapsed), the agent's component fields (`Health.hp`) and resource fields (`Game.alarm`), and compare them with a literal or with another key or field read each time (`check Foe.hp below Tuning.fleeHp`), so thresholds live in a tuning resource. og.ai.restart starts a behaviour afresh. Deterministic; memories and blackboards are in snapshots. `dump_ai:<entity>` writes an agent's state, running node and blackboard.
10
+
11
+ - **TypeScript**: functions are the namespace `og.ai`; components, resources and events are tokens on `og`.
12
+ - **Publish builds**: kept (members may override).
13
+ - **Skill**: `og-ai`, which teaches the module (how much of it to use, and how to prove it).
14
+ - **Index**: [every module and name](index.md).
15
+
16
+ ```ogt
17
+ module ai {
18
+ # declarations follow, each quoted below
19
+ ```
20
+
21
+ <sub>`api.ogt` line 7262</sub>
22
+
23
+ ## Contents
24
+
25
+ | Name | Kind | Summary |
26
+ |---|---|---|
27
+ | [`Behaviour`](#type-Behaviour) | handle | A loaded behaviour tree or state machine. |
28
+ | [`Behaviour()`](#column-Behaviour) | column kind | A Behaviour handle field. |
29
+ | [`AI_RUNNING`](#const-AI_RUNNING) | constant | AiAgent.status: the tree or state is still running. |
30
+ | [`AI_SUCCESS`](#const-AI_SUCCESS) | constant | AiAgent.status: the tree succeeded on the last think. |
31
+ | [`AI_FAILURE`](#const-AI_FAILURE) | constant | AiAgent.status: the tree failed on the last think. |
32
+ | [`og.AiAgent`](#record-AiAgent) | component | An entity that thinks with a behaviour. Give it an og.NavAgent to move and an og.Perception to see and hear. |
33
+ | [`og.Perception`](#record-Perception) | component | What an agent sees and hears. It sees the nearest og.Perceivable of another team within `sight`, inside the `fov` cone around `forward` (or the way it last moved), unless a collider is in the way; it hears a spatial sound that starts (og.SoundStarted) or a game noise (og.ai.noise) within `hearing` times its loudness, except its own: a sound of its entity or of an entity under it (og.Parent), or a noise whose NoiseDesc.source is one of them. |
34
+ | [`og.Perceivable`](#record-Perceivable) | component | Something agents of other teams can see. |
35
+ | [`og.AiChanged`](#record-AiChanged) | event | An agent's state or running node changed (systems read it the tick after). |
36
+ | [`BehaviourInfo`](#type-BehaviourInfo) | struct | A loaded behaviour. |
37
+ | [`NoiseDesc`](#type-NoiseDesc) | desc struct | A noise agents may hear next tick. |
38
+ | [`AiDescription`](#type-AiDescription) | struct | What an agent is doing. |
39
+ | [`og.ai.load`](#fn-load) | function | A cooked behaviour (an `.ogt` of `type behaviour`, validated by og cook). |
40
+ | [`og.ai.parse`](#fn-parse) | function | A behaviour from text, now (tests and generated behaviours; assets go through og cook). |
41
+ | [`og.ai.get`](#fn-get) | function | A blackboard value of an agent as of its last think. |
42
+ | [`og.ai.set`](#fn-set) | function | Set a blackboard value of an agent: a number, a boolean, a point `{x, y, z}` or an entity handle `{entity}`. |
43
+ | [`og.ai.restart`](#fn-restart) | function | Start an agent's behaviour afresh at its next think, as a new behaviour would: a machine in its initial state (its enter actions run again), a tree at its root, every timer and cooldown reset, the blackboard back to the declared keys, wander's centre where it then stands, and what it saw and heard forgotten. Actions without a speed keep the speed it first started with. For a new run or a respawn; an agent that has not thought yet starts afresh anyway. |
44
+ | [`og.ai.noise`](#fn-noise) | function | Make a noise agents may hear next tick (a gunshot, a door, a thrown stone). |
45
+ | [`og.ai.describe`](#fn-describe) | function | What an agent is doing: its state, the node it runs and the path to it, its status, its blackboard and its target. |
46
+
47
+ ## Functions
48
+
49
+ <a id="fn-load"></a>
50
+
51
+ ### `og.ai.load`
52
+
53
+ A cooked behaviour (an `.ogt` of `type behaviour`, validated by og cook).
54
+
55
+ ```ts
56
+ og.ai.load(world: World, path: string): Result<BehaviourInfo>
57
+ ```
58
+
59
+ | Parameter | Type | Optional | Doc |
60
+ |---|---|---|---|
61
+ | `world` | `World` | no | The world. |
62
+ | `path` | `string` | no | The behaviour asset, such as `ai/slime.ogt`. |
63
+
64
+ **Returns** `Result<BehaviourInfo>`: Refused for a path that is not a cooked behaviour.
65
+
66
+ Binding symbol `og_ai_load` · publish builds: kept
67
+
68
+ ```ogt
69
+ fn load {
70
+ doc "A cooked behaviour (an `.ogt` of `type behaviour`, validated by og cook)."
71
+ param world World "The world."
72
+ param path String "The behaviour asset, such as `ai/slime.ogt`."
73
+ returns Result.BehaviourInfo "Refused for a path that is not a cooked behaviour."
74
+ }
75
+ ```
76
+
77
+ <sub>`api.ogt` line 7434</sub>
78
+
79
+ <a id="fn-parse"></a>
80
+
81
+ ### `og.ai.parse`
82
+
83
+ A behaviour from text, now (tests and generated behaviours; assets go through og cook).
84
+
85
+ ```ts
86
+ og.ai.parse(world: World, text: string): Result<BehaviourInfo>
87
+ ```
88
+
89
+ | Parameter | Type | Optional | Doc |
90
+ |---|---|---|---|
91
+ | `world` | `World` | no | The world. |
92
+ | `text` | `string` | no | The behaviour's `.ogt` text. |
93
+
94
+ **Returns** `Result<BehaviourInfo>`: Refused with the first error's line and the fix.
95
+
96
+ Binding symbol `og_ai_parse` · publish builds: kept
97
+
98
+ ```ogt
99
+ fn parse {
100
+ doc "A behaviour from text, now (tests and generated behaviours; assets go through og cook)."
101
+ param world World "The world."
102
+ param text String "The behaviour's `.ogt` text."
103
+ returns Result.BehaviourInfo "Refused with the first error's line and the fix."
104
+ }
105
+ ```
106
+
107
+ <sub>`api.ogt` line 7441</sub>
108
+
109
+ <a id="fn-get"></a>
110
+
111
+ ### `og.ai.get`
112
+
113
+ A blackboard value of an agent as of its last think.
114
+
115
+ ```ts
116
+ og.ai.get(world: World, entity: Entity, key: string): unknown
117
+ ```
118
+
119
+ | Parameter | Type | Optional | Doc |
120
+ |---|---|---|---|
121
+ | `world` | `World` | no | The world. |
122
+ | `entity` | `Entity` | no | The agent. |
123
+ | `key` | `string` | no | The key. |
124
+
125
+ **Returns** `unknown`: A number, a boolean, a point `{x, y, z}`, an entity handle, or null for an unknown key or an agent that has not thought.
126
+
127
+ Binding symbol `og_ai_get` · publish builds: kept
128
+
129
+ ```ogt
130
+ fn get {
131
+ doc "A blackboard value of an agent as of its last think."
132
+ param world World "The world."
133
+ param entity Entity "The agent."
134
+ param key String "The key."
135
+ returns Json "A number, a boolean, a point `{x, y, z}`, an entity handle, or null for an unknown key or an agent that has not thought."
136
+ }
137
+ ```
138
+
139
+ <sub>`api.ogt` line 7448</sub>
140
+
141
+ <a id="fn-set"></a>
142
+
143
+ ### `og.ai.set`
144
+
145
+ Set a blackboard value of an agent: a number, a boolean, a point `{x, y, z}` or an entity handle `{entity}`.
146
+
147
+ ```ts
148
+ og.ai.set(world: World, entity: Entity, key: string, value: unknown): Result<void>
149
+ ```
150
+
151
+ | Parameter | Type | Optional | Doc |
152
+ |---|---|---|---|
153
+ | `world` | `World` | no | The world. |
154
+ | `entity` | `Entity` | no | The agent. |
155
+ | `key` | `string` | no | The key; built-in keys are refused. |
156
+ | `value` | `unknown` | no | The value. |
157
+
158
+ **Returns** `Result<void>`: Refused for an agent that has not thought yet, a built-in key or another kind of value.
159
+
160
+ Binding symbol `og_ai_set` · publish builds: kept
161
+
162
+ ```ogt
163
+ fn set {
164
+ doc "Set a blackboard value of an agent: a number, a boolean, a point `{x, y, z}` or an entity handle `{entity}`."
165
+ param world World "The world."
166
+ param entity Entity "The agent."
167
+ param key String "The key; built-in keys are refused."
168
+ param value Json "The value."
169
+ returns Result.Void "Refused for an agent that has not thought yet, a built-in key or another kind of value."
170
+ }
171
+ ```
172
+
173
+ <sub>`api.ogt` line 7456</sub>
174
+
175
+ <a id="fn-restart"></a>
176
+
177
+ ### `og.ai.restart`
178
+
179
+ Start an agent's behaviour afresh at its next think, as a new behaviour would: a machine in its initial state (its enter actions run again), a tree at its root, every timer and cooldown reset, the blackboard back to the declared keys, wander's centre where it then stands, and what it saw and heard forgotten. Actions without a speed keep the speed it first started with. For a new run or a respawn; an agent that has not thought yet starts afresh anyway.
180
+
181
+ ```ts
182
+ og.ai.restart(world: World, entity: Entity): Result<void>
183
+ ```
184
+
185
+ | Parameter | Type | Optional | Doc |
186
+ |---|---|---|---|
187
+ | `world` | `World` | no | The world. |
188
+ | `entity` | `Entity` | no | The agent. |
189
+
190
+ **Returns** `Result<void>`: Refused for a world without og.ai.
191
+
192
+ Binding symbol `og_ai_restart` · publish builds: kept
193
+
194
+ ```ogt
195
+ fn restart {
196
+ doc "Start an agent's behaviour afresh at its next think, as a new behaviour would: a machine in its initial state (its enter actions run again), a tree at its root, every timer and cooldown reset, the blackboard back to the declared keys, wander's centre where it then stands, and what it saw and heard forgotten. Actions without a speed keep the speed it first started with. For a new run or a respawn; an agent that has not thought yet starts afresh anyway."
197
+ param world World "The world."
198
+ param entity Entity "The agent."
199
+ returns Result.Void "Refused for a world without og.ai."
200
+ }
201
+ ```
202
+
203
+ <sub>`api.ogt` line 7465</sub>
204
+
205
+ <a id="fn-noise"></a>
206
+
207
+ ### `og.ai.noise`
208
+
209
+ Make a noise agents may hear next tick (a gunshot, a door, a thrown stone).
210
+
211
+ ```ts
212
+ og.ai.noise(world: World, desc?: NoiseDesc): Result<void>
213
+ ```
214
+
215
+ | Parameter | Type | Optional | Doc |
216
+ |---|---|---|---|
217
+ | `world` | `World` | no | The world. |
218
+ | `desc` | `NoiseDesc` | yes | Where and how loud. |
219
+
220
+ **Returns** `Result<void>`: Refused for a world without og.ai.
221
+
222
+ Binding symbol `og_ai_noise` · publish builds: kept
223
+
224
+ ```ogt
225
+ fn noise {
226
+ doc "Make a noise agents may hear next tick (a gunshot, a door, a thrown stone)."
227
+ param world World "The world."
228
+ param desc NoiseDesc "Where and how loud."
229
+ returns Result.Void "Refused for a world without og.ai."
230
+ }
231
+ ```
232
+
233
+ <sub>`api.ogt` line 7472</sub>
234
+
235
+ <a id="fn-describe"></a>
236
+
237
+ ### `og.ai.describe`
238
+
239
+ What an agent is doing: its state, the node it runs and the path to it, its status, its blackboard and its target.
240
+
241
+ ```ts
242
+ og.ai.describe(world: World, entity: Entity): AiDescription | null
243
+ ```
244
+
245
+ | Parameter | Type | Optional | Doc |
246
+ |---|---|---|---|
247
+ | `world` | `World` | no | The world. |
248
+ | `entity` | `Entity` | no | The agent. |
249
+
250
+ **Returns** `AiDescription | null`: Null for an entity that has not thought.
251
+
252
+ Binding symbol `og_ai_describe` · publish builds: kept
253
+
254
+ ```ogt
255
+ fn describe {
256
+ doc "What an agent is doing: its state, the node it runs and the path to it, its status, its blackboard and its target."
257
+ param world World "The world."
258
+ param entity Entity "The agent."
259
+ returns Option.AiDescription "Null for an entity that has not thought."
260
+ }
261
+ ```
262
+
263
+ <sub>`api.ogt` line 7479</sub>
264
+
265
+ ## Components, resources and events
266
+
267
+ <a id="record-AiAgent"></a>
268
+
269
+ ### `og.AiAgent` (component)
270
+
271
+ An entity that thinks with a behaviour. Give it an og.NavAgent to move and an og.Perception to see and hear.
272
+
273
+ Token `og.AiAgent`, registered under the schema name `og.AiAgent`; its value type is `AiAgent`.
274
+
275
+ | Field | Type | Default | Range | Unit | Notes | Doc |
276
+ |---|---|---|---|---|---|---|
277
+ | `behaviour` | `Behaviour` | `0` | — | — | — | The behaviour it runs (og.ai.load); 0 runs nothing. |
278
+ | `active` | `boolean` | `true` | — | — | — | Thinks while true. |
279
+ | `thinkEvery` | `number` | `1` | 1 … 600 | `ticks` | — | Thinks every this many ticks (1: every tick); agents are staggered by their order. |
280
+ | `status` | `number` | `0` | — | — | read only | AI_RUNNING, AI_SUCCESS or AI_FAILURE after the last think (0 before the first; written by og.ai). |
281
+ | `state` | `number` | `0` | — | — | read only | The state machine's state, an index into BehaviourInfo.states (written by og.ai). |
282
+ | `node` | `number` | `0` | — | — | read only | The node it ran last, an index into BehaviourInfo.nodes (written by og.ai). |
283
+ | `changes` | `number` | `0` | — | — | read only | Times the state or the running node changed (written by og.ai). |
284
+
285
+ ```ogt
286
+ component AiAgent {
287
+ doc "An entity that thinks with a behaviour. Give it an og.NavAgent to move and an og.Perception to see and hear."
288
+ field behaviour Behaviour "The behaviour it runs (og.ai.load); 0 runs nothing."
289
+ field active bool "Thinks while true." {
290
+ default true
291
+ }
292
+ field thinkEvery u32 "Thinks every this many ticks (1: every tick); agents are staggered by their order." {
293
+ default 1
294
+ min 1
295
+ max 600
296
+ unit ticks
297
+ }
298
+ field status u32 "AI_RUNNING, AI_SUCCESS or AI_FAILURE after the last think (0 before the first; written by og.ai)." {
299
+ readonly true
300
+ }
301
+ field state u32 "The state machine's state, an index into BehaviourInfo.states (written by og.ai)." {
302
+ readonly true
303
+ }
304
+ field node u32 "The node it ran last, an index into BehaviourInfo.nodes (written by og.ai)." {
305
+ readonly true
306
+ }
307
+ field changes u32 "Times the state or the running node changed (written by og.ai)." {
308
+ readonly true
309
+ }
310
+ }
311
+ ```
312
+
313
+ <sub>`api.ogt` line 7281</sub>
314
+
315
+ <a id="record-Perception"></a>
316
+
317
+ ### `og.Perception` (component)
318
+
319
+ What an agent sees and hears. It sees the nearest og.Perceivable of another team within `sight`, inside the `fov` cone around `forward` (or the way it last moved), unless a collider is in the way; it hears a spatial sound that starts (og.SoundStarted) or a game noise (og.ai.noise) within `hearing` times its loudness, except its own: a sound of its entity or of an entity under it (og.Parent), or a noise whose NoiseDesc.source is one of them.
320
+
321
+ Token `og.Perception`, registered under the schema name `og.Perception`; its value type is `Perception`.
322
+
323
+ | Field | Type | Default | Range | Unit | Notes | Doc |
324
+ |---|---|---|---|---|---|---|
325
+ | `sight` | `number` | `8` | 0 … 500 | `m` | tunable | How far it sees. |
326
+ | `fov` | `number` | `120` | 0 … 360 | `deg` | tunable | The width of its view cone (360: all round). |
327
+ | `eyeHeight` | `number` | `0` | -10 … 10 | `m` | — | Its eyes are this far above its position (+y). |
328
+ | `occlude` | `boolean` | `true` | — | — | — | Colliders hide what is behind them. |
329
+ | `occluders` | `number` | `0` | — | — | — | Collision layers that block sight (0: every layer). |
330
+ | `hearing` | `number` | `6` | 0 … 500 | `m` | tunable | How far it hears a sound of loudness 1 (a source's volume). |
331
+ | `memory` | `number` | `3` | 0 … 600 | `s` | tunable | How long a lost target stays its target. |
332
+ | `team` | `number` | `0` | — | — | — | Its team: it perceives og.Perceivable entities of other teams. |
333
+ | `forward` | `Vector3` | `{ x: 0, y: 0, z: 0 }` | — | — | — | Where it looks; zero: the way it last moved (before it moves, the way its Transform faces: +Z in 3D, +X in 2D). |
334
+ | `target` | `Entity` | `0` | — | — | read only | What it sees or remembers seeing (written by og.ai). |
335
+ | `sees` | `boolean` | `false` | — | — | read only | It sees the target now (written by og.ai). |
336
+ | `lastSeen` | `Vector3` | `{ x: 0, y: 0, z: 0 }` | — | `m` | read only | Where it last saw the target (written by og.ai). |
337
+ | `sinceSeen` | `number` | `1000000` | — | `s` | read only | Seconds since it last saw a target (written by og.ai; 1e6 before the first time). |
338
+ | `heard` | `boolean` | `false` | — | — | read only | It heard something this tick (written by og.ai). |
339
+ | `heardAt` | `Vector3` | `{ x: 0, y: 0, z: 0 }` | — | `m` | read only | Where it last heard something (written by og.ai). |
340
+ | `sinceHeard` | `number` | `1000000` | — | `s` | read only | Seconds since it last heard something (written by og.ai; 1e6 before the first time). |
341
+
342
+ ```ogt
343
+ component Perception {
344
+ doc "What an agent sees and hears. It sees the nearest og.Perceivable of another team within `sight`, inside the `fov` cone around `forward` (or the way it last moved), unless a collider is in the way; it hears a spatial sound that starts (og.SoundStarted) or a game noise (og.ai.noise) within `hearing` times its loudness, except its own: a sound of its entity or of an entity under it (og.Parent), or a noise whose NoiseDesc.source is one of them."
345
+ field sight f32 "How far it sees." {
346
+ default 8
347
+ min 0
348
+ max 500
349
+ unit m
350
+ tunable true
351
+ }
352
+ field fov f32 "The width of its view cone (360: all round)." {
353
+ default 120
354
+ min 0
355
+ max 360
356
+ unit deg
357
+ tunable true
358
+ }
359
+ field eyeHeight f32 "Its eyes are this far above its position (+y)." {
360
+ min -10
361
+ max 10
362
+ unit m
363
+ }
364
+ field occlude bool "Colliders hide what is behind them." {
365
+ default true
366
+ }
367
+ field occluders u32 "Collision layers that block sight (0: every layer)."
368
+ field hearing f32 "How far it hears a sound of loudness 1 (a source's volume)." {
369
+ default 6
370
+ min 0
371
+ max 500
372
+ unit m
373
+ tunable true
374
+ }
375
+ field memory f32 "How long a lost target stays its target." {
376
+ default 3
377
+ min 0
378
+ max 600
379
+ unit s
380
+ tunable true
381
+ }
382
+ field team u32 "Its team: it perceives og.Perceivable entities of other teams."
383
+ field forward Vector3 "Where it looks; zero: the way it last moved (before it moves, the way its Transform faces: +Z in 3D, +X in 2D)."
384
+ field target Entity "What it sees or remembers seeing (written by og.ai)." {
385
+ readonly true
386
+ }
387
+ field sees bool "It sees the target now (written by og.ai)." {
388
+ readonly true
389
+ }
390
+ field lastSeen Vector3 "Where it last saw the target (written by og.ai)." {
391
+ unit m
392
+ readonly true
393
+ }
394
+ field sinceSeen f32 "Seconds since it last saw a target (written by og.ai; 1e6 before the first time)." {
395
+ default 1000000
396
+ unit s
397
+ readonly true
398
+ }
399
+ field heard bool "It heard something this tick (written by og.ai)." {
400
+ readonly true
401
+ }
402
+ field heardAt Vector3 "Where it last heard something (written by og.ai)." {
403
+ unit m
404
+ readonly true
405
+ }
406
+ field sinceHeard f32 "Seconds since it last heard something (written by og.ai; 1e6 before the first time)." {
407
+ default 1000000
408
+ unit s
409
+ readonly true
410
+ }
411
+ }
412
+ ```
413
+
414
+ <sub>`api.ogt` line 7307</sub>
415
+
416
+ <a id="record-Perceivable"></a>
417
+
418
+ ### `og.Perceivable` (component)
419
+
420
+ Something agents of other teams can see.
421
+
422
+ Token `og.Perceivable`, registered under the schema name `og.Perceivable`; its value type is `Perceivable`.
423
+
424
+ | Field | Type | Default | Range | Unit | Notes | Doc |
425
+ |---|---|---|---|---|---|---|
426
+ | `team` | `number` | `1` | — | — | — | Its team (agents of the same team ignore it). |
427
+ | `eyeHeight` | `number` | `0` | -10 … 10 | `m` | — | Agents look at a point this far above its position (+y). |
428
+
429
+ ```ogt
430
+ component Perceivable {
431
+ doc "Something agents of other teams can see."
432
+ field team u32 "Its team (agents of the same team ignore it)." {
433
+ default 1
434
+ }
435
+ field eyeHeight f32 "Agents look at a point this far above its position (+y)." {
436
+ min -10
437
+ max 10
438
+ unit m
439
+ }
440
+ }
441
+ ```
442
+
443
+ <sub>`api.ogt` line 7377</sub>
444
+
445
+ <a id="record-AiChanged"></a>
446
+
447
+ ### `og.AiChanged` (event)
448
+
449
+ An agent's state or running node changed (systems read it the tick after).
450
+
451
+ Token `og.AiChanged`, registered under the schema name `og.AiChanged`; its value type is `AiChanged`.
452
+
453
+ | Field | Type | Default | Range | Unit | Notes | Doc |
454
+ |---|---|---|---|---|---|---|
455
+ | `entity` | `Entity` | `0` | — | — | — | The agent. |
456
+ | `state` | `number` | `0` | — | — | — | Its state now. |
457
+ | `node` | `number` | `0` | — | — | — | The node it runs now. |
458
+ | `status` | `number` | `0` | — | — | — | AI_RUNNING, AI_SUCCESS or AI_FAILURE. |
459
+
460
+ ```ogt
461
+ event AiChanged {
462
+ doc "An agent's state or running node changed (systems read it the tick after)."
463
+ field entity Entity "The agent."
464
+ field state u32 "Its state now."
465
+ field node u32 "The node it runs now."
466
+ field status u32 "AI_RUNNING, AI_SUCCESS or AI_FAILURE."
467
+ }
468
+ ```
469
+
470
+ <sub>`api.ogt` line 7389</sub>
471
+
472
+ ## Types
473
+
474
+ <a id="type-Behaviour"></a>
475
+
476
+ ### `Behaviour` (handle)
477
+
478
+ A loaded behaviour tree or state machine.
479
+
480
+ A generational handle: a number the engine hands out. A dead handle is an error value, never a crash.
481
+
482
+ ```ogt
483
+ handle Behaviour "A loaded behaviour tree or state machine."
484
+ ```
485
+
486
+ <sub>`api.ogt` line 7268</sub>
487
+
488
+ <a id="type-BehaviourInfo"></a>
489
+
490
+ ### `BehaviourInfo` (struct)
491
+
492
+ A loaded behaviour.
493
+
494
+ | Field | Type | Default | Range | Unit | Notes | Doc |
495
+ |---|---|---|---|---|---|---|
496
+ | `behaviour` | `Behaviour` | `0` | — | — | — | What AiAgent.behaviour takes. |
497
+ | `name` | `string` | `""` | — | — | — | Its name. |
498
+ | `kind` | `string` | `""` | — | — | — | tree or machine. |
499
+ | `states` | `readonly string[]` | `[]` | — | — | — | A machine's states, by index (AiAgent.state). |
500
+ | `nodes` | `readonly string[]` | `[]` | — | — | — | Its nodes' names, by index (AiAgent.node). |
501
+ | `keys` | `readonly string[]` | `[]` | — | — | — | Its declared blackboard keys. |
502
+
503
+ ```ogt
504
+ struct BehaviourInfo {
505
+ doc "A loaded behaviour."
506
+ field behaviour Behaviour "What AiAgent.behaviour takes."
507
+ field name String "Its name."
508
+ field kind String "tree or machine."
509
+ field states List.String "A machine's states, by index (AiAgent.state)."
510
+ field nodes List.String "Its nodes' names, by index (AiAgent.node)."
511
+ field keys List.String "Its declared blackboard keys."
512
+ }
513
+ ```
514
+
515
+ <sub>`api.ogt` line 7397</sub>
516
+
517
+ <a id="type-NoiseDesc"></a>
518
+
519
+ ### `NoiseDesc` (desc struct)
520
+
521
+ A noise agents may hear next tick.
522
+
523
+ A desc: every field may be omitted and takes its default; `{}` is valid.
524
+
525
+ | Field | Type | Default | Range | Unit | Notes | Doc |
526
+ |---|---|---|---|---|---|---|
527
+ | `position` | `Vector3` | `{ x: 0, y: 0, z: 0 }` | — | `m` | — | Where it is. |
528
+ | `loudness` | `number` | `1` | 0 … 100 | — | — | How loud: heard within Perception.hearing times this. |
529
+ | `source` | `Entity` | `0` | — | — | — | Who makes it (0: nobody): that entity, and the agents it is under (og.Parent), do not hear it. |
530
+
531
+ ```ogt
532
+ struct NoiseDesc {
533
+ doc "A noise agents may hear next tick."
534
+ desc true
535
+ field position Vector3 "Where it is." {
536
+ unit m
537
+ }
538
+ field loudness f32 "How loud: heard within Perception.hearing times this." {
539
+ default 1
540
+ min 0
541
+ max 100
542
+ }
543
+ field source Entity "Who makes it (0: nobody): that entity, and the agents it is under (og.Parent), do not hear it."
544
+ }
545
+ ```
546
+
547
+ <sub>`api.ogt` line 7407</sub>
548
+
549
+ <a id="type-AiDescription"></a>
550
+
551
+ ### `AiDescription` (struct)
552
+
553
+ What an agent is doing.
554
+
555
+ | Field | Type | Default | Range | Unit | Notes | Doc |
556
+ |---|---|---|---|---|---|---|
557
+ | `behaviour` | `string` | `""` | — | — | — | Its behaviour's name. |
558
+ | `kind` | `string` | `""` | — | — | — | tree or machine. |
559
+ | `state` | `string` | `""` | — | — | — | A machine's state (empty for a tree). |
560
+ | `node` | `string` | `""` | — | — | — | The node it ran last, such as `chase`. |
561
+ | `path` | `string` | `""` | — | — | — | The path to it from the root, such as `selector > sequence chase > chase`. |
562
+ | `status` | `string` | `""` | — | — | — | running, success or failure. |
563
+ | `blackboard` | `unknown` | `null` | — | — | — | Its blackboard, keys to numbers, booleans, points and entity handles. |
564
+ | `sees` | `boolean` | `false` | — | — | — | It sees its target. |
565
+ | `target` | `Entity` | `0` | — | — | — | Its target (0: none). |
566
+
567
+ ```ogt
568
+ struct AiDescription {
569
+ doc "What an agent is doing."
570
+ field behaviour String "Its behaviour's name."
571
+ field kind String "tree or machine."
572
+ field state String "A machine's state (empty for a tree)."
573
+ field node String "The node it ran last, such as `chase`."
574
+ field path String "The path to it from the root, such as `selector > sequence chase > chase`."
575
+ field status String "running, success or failure."
576
+ field blackboard Json "Its blackboard, keys to numbers, booleans, points and entity handles."
577
+ field sees bool "It sees its target."
578
+ field target Entity "Its target (0: none)."
579
+ }
580
+ ```
581
+
582
+ <sub>`api.ogt` line 7421</sub>
583
+
584
+ ## Column kinds
585
+
586
+ Each is a factory, `Behaviour(value?, options?)`, that makes one field of a component or resource layout.
587
+
588
+ | Column | Value | Typed array | Stride | Doc |
589
+ |---|---|---|---|---|
590
+ | <a id="column-Behaviour"></a>`Behaviour` | `Behaviour` | `Uint32Array` | 2 | A Behaviour handle field. |
591
+
592
+ ```ogt
593
+ column Behaviour {
594
+ doc "A Behaviour handle field."
595
+ array Uint32Array
596
+ stride 2
597
+ value Behaviour
598
+ }
599
+ ```
600
+
601
+ <sub>`api.ogt` line 7270</sub>
602
+
603
+ ## Constants
604
+
605
+ | Constant | Type | Value | Doc |
606
+ |---|---|---|---|
607
+ | <a id="const-AI_RUNNING"></a>`AI_RUNNING` | `number` | `1` | AiAgent.status: the tree or state is still running. |
608
+ | <a id="const-AI_SUCCESS"></a>`AI_SUCCESS` | `number` | `2` | AiAgent.status: the tree succeeded on the last think. |
609
+ | <a id="const-AI_FAILURE"></a>`AI_FAILURE` | `number` | `3` | AiAgent.status: the tree failed on the last think. |
610
+
611
+ ```ogt
612
+ const AI_RUNNING u32 1 "AiAgent.status: the tree or state is still running."
613
+ ```
614
+
615
+ <sub>`api.ogt` line 7277</sub>
616
+
617
+ ```ogt
618
+ const AI_SUCCESS u32 2 "AiAgent.status: the tree succeeded on the last think."
619
+ ```
620
+
621
+ <sub>`api.ogt` line 7278</sub>
622
+
623
+ ```ogt
624
+ const AI_FAILURE u32 3 "AiAgent.status: the tree failed on the last think."
625
+ ```
626
+
627
+ <sub>`api.ogt` line 7279</sub>