ai
<!-- zero:scaffolded-readme --> <!-- Replace the line below with what this module provides and who consumes it, then delete both comment lines. -->
ai
<!-- zero:scaffolded-readme --> <!-- Replace the line below with what this module provides and who consumes it, then delete both comment lines. -->TODO: describe this module.
Interface
What this asset declares: the schema it conforms to, what it exposes, and the rendered structured payload.
conforms to
zero/source-extract/v2game.enemy.ai — one soldier's mind. The rule this is built around is the one the whole enemy slice is judged by: A SOLDIER ONLY KNOWS WHAT HE HAS SEEN OR HEARD. There is no path from here to the player's position that does not pass through a sight check or a noise event, and nothing reads the player's coordinates directly. Lose sight and the memory holds for a while and then decays into a search of the place he was last seen — which is what makes a fight against them a fight rather than a shooting gallery with a reaction-time dial. The other half is that they FIGHT like soldiers: they break off to reload, they take ground when they have the advantage, they go to cover when they are hurt, they shoot in bursts with a pause between them, and a shot that comes from somewhere they cannot see pulls them off what they were doing. Perception is the expensive part, so it is on a clock rather than a frame — `SENSE_HZ` — and each soldier is staggered onto its own offset so the whole squad never raycasts on the same frame.
vlen(x: ?, y: ?, z: ?) → void
Small vector helpers
| arg | type | description |
|---|---|---|
| x | ? | |
| y | ? | |
| z | ? |
norm(x: ?, y: ?, z: ?) → void
| arg | type | description |
|---|---|---|
| x | ? | |
| y | ? | |
| z | ? |
angleDelta(a: ?, b: ?) → void
Shortest signed difference between two angles, in radians.
| arg | type | description |
|---|---|---|
| a | ? | |
| b | ? |
raycast(from: ?, dir: ?, dist: ?) → void
| arg | type | description |
|---|---|---|
| from | ? | |
| dir | ? | |
| dist | ? |
isSquaddie(id: ?, ignore: ?) → void
Rendering the soldier invisible to his own line of sight The squad's own bodies must not block their sight. Every check casts from one soldier's eye out to the player, and a comrade standing in the way is an occluder as real as a wall — so the trace is asked what it hit and the hit is discarded when it is another soldier.
| arg | type | description |
|---|---|---|
| id | ? | |
| ignore | ? |
new(opts: ?) → void
An agent `opts` carries what the agent needs that is not its own: the weapon it was handed, how aggressive it was generated, and where it starts its patrol.
| arg | type | description |
|---|---|---|
| opts | ? |
canSee(a: ?, eyeY: ?, tx: ?, ty: ?, tz: ?, ignore: ?) → void
Perception Can this soldier see that point? Range, then the cone, then a trace. The trace is last on purpose: it is the expensive one, and range and angle throw out almost everything for the price of a subtraction.
| arg | type | description |
|---|---|---|
| a | ? | |
| eyeY | ? | |
| tx | ? | |
| ty | ? | |
| tz | ? | |
| ignore | ? |
hear(a: ?, x: ?, y: ?, z: ?, radius: ?) → void
A noise the soldier may have heard. Gunfire carries a long way; a footstep does not.
| arg | type | description |
|---|---|---|
| a | ? | |
| x | ? | |
| y | ? | |
| z | ? | |
| radius | ? |
groundAt(x: ?, z: ?) → void
Movement Ground height under a point, so a soldier walks over a kerb instead of through it. One downward trace from well above the feet.
| arg | type | description |
|---|---|---|
| x | ? | |
| z | ? |
clearAhead(a: ?, dirX: ?, dirZ: ?) → void
Is the way ahead clear? A chest-height trace a step and a half forward. If it is not, the soldier slides along the obstruction rather than walking into it forever, which is what a straight-line seek does against a wall.
| arg | type | description |
|---|---|---|
| a | ? | |
| dirX | ? | |
| dirZ | ? |
step(a: ?, dt: ?) → void
Step the agent toward where it wants to be, at the speed its state allows.
| arg | type | description |
|---|---|---|
| a | ? | |
| dt | ? |
findCover(a: ?, fromX: ?, fromZ: ?, playerX: ?, playerY: ?, playerZ: ?) → void
Choosing where to go A position near the last known point that the player cannot see from where he is. Candidates are sampled around the point and each one is traced; the first that is both reachable and hidden wins. This is what "take cover" means here — not a cover volume, just a place that is not in his line.
| arg | type | description |
|---|---|---|
| a | ? | |
| fromX | ? | |
| fromZ | ? | |
| playerX | ? | |
| playerY | ? | |
| playerZ | ? |
searchPoint(a: ?, x: ?, z: ?) → void
Somewhere to go when he has lost the player: work outward from where he was last seen, so a squad sweeps the ground rather than standing still.
| arg | type | description |
|---|---|---|
| a | ? | |
| x | ? | |
| z | ? |
accuracyFor(a: ?, dist: ?) → void
Firing The accuracy the soldier earns at this range and in this stance. Closer is more certain; a man who has just been shot at is less.
| arg | type | description |
|---|---|---|
| a | ? | |
| dist | ? |
sense(a: ?, ctx: ?) → void
The tick One think, at the sense clock. Everything expensive lives here.
| arg | type | description |
|---|---|---|
| a | ? | |
| ctx | ? |
act(a: ?, ctx: ?, dt: ?) → void
Everything decided per frame. Cheap on purpose.
| arg | type | description |
|---|---|---|
| a | ? | |
| ctx | ? | |
| dt | ? |
tick(a: ?, dt: ?, ctx: ?) → void
Public tick Advance one soldier. `ctx` carries the world it must not reach into for itself: where the player is, whether he is alive, and the callbacks that let it tell the rest of the game what it did.
| arg | type | description |
|---|---|---|
| a | ? | |
| dt | ? | |
| ctx | ? |
Sub-parts
Everything contained inside this part. Assets are composite children (clickable cards). Files are leaf payloads. Expand any row to view its source.
Problems
Everything affecting this asset right now: its own problems, anything wrong inside it, and problems on its direct dependencies.
agent_score is exposed.+ quality × 0.35
+ performance × 0.25
± compat factor
Usability ratings
Did the part work as advertised when consumers tried to drop it in. Separate from upvotes: those are taste; this is "did it function".
Scoped to this part · feeds back into the world's score.