# `QuakeServer.Builtins`
[🔗](https://github.com/jaman/quake_server/blob/v0.1.0/lib/quake_server/builtins.ex#L1)

The engine functions a QuakeC program calls by number, as FTE runs them for a server
program: vectors and angles, entities and models, traces, sounds, monster movement,
searches, console variables, messages and level changes. Where FTE's rule depends on
the kind of program, a QuakeWorld program is one whose `crc` is 54730.

`call/3` takes the server (the QuakeC host), the builtin number and the argument
count; arguments are read from the program's parameter slots and the result written
to its return slot.

`error` (10) prints its arguments joined, as a line. With the console variable
`developer` set it then prints `break statement` and the program goes on; otherwise it
raises `QuakeC.Exec.Error` with the message `Program error: ` and the text, which ends
the call into the program. `objerror` (11) prints `Program error: ` and its arguments
joined, removes `self` and stops every running function (`QuakeC.Exec.abort/1`).
`breakpoint` (6) prints `break statement`; `dprint` (25) prints its arguments joined
while `developer` is set.

`random` (7) is FTE's: a step of 1/32768 from 0 up to 1, offset by half a step so it is
never 0 or 1; with one argument it is scaled by it, with two it runs from the first
toward the second. `ftos` (26) and `vtos` (27) write numbers as
`QuakeServer.Builtins.Text` does, `ftos` as `%5.1f` while `pr_brokenfloatconvert` is
set.

`findradius` (22) chains, through the field its third argument names (`chain` without
one), every entity whose centre (with `sv_gameplayfix_findradiusdistancetobox` set,
nearest point of its box) lies within the radius, the last found first; an entity with
`solid` 0 is left out unless its `flags` hold 16384 (`FL_FINDABLE_NONSOLID`) or
`sv_gameplayfix_blowupfallenzombies` is set.

`setmodel` (3) sets `model` and `modelindex` and then sizes the entity by the model's
box: always for a world submodel (`*n`); for any model when the program is not a
QuakeWorld one or `sv_gameplayfix_setmodelsize_qw` is set; otherwise only for a model
that was found and is not a Quake alias model; any other keeps its size. The entity is
linked either way.

# `call`

```elixir
@spec call(QuakeServer.Server.t(), non_neg_integer() | String.t(), non_neg_integer()) ::
  QuakeServer.Server.t()
```

Run builtin `number`, or the game's own function for a program function its source
replaces (`c:QuakeServer.Source.replacements/0`), called by that function's name.

# `put_trace`

```elixir
@spec put_trace(
  QuakeServer.Server.t(),
  QuakeServer.World.Trace.t() | Cauldron3D.Hull.Trace.t()
) ::
  QuakeServer.Server.t()
```

Set the program's `trace_` globals from `trace` (`set_trace_globals`): with
`sv_gameplayfix_honest_tracelines` at 0 a trace that started inside something reports
a fraction of 1.

# `trace`

```elixir
@spec trace(
  QuakeServer.Server.t(),
  Cauldron3D.Vec.t(),
  Cauldron3D.Vec.t(),
  Cauldron3D.Vec.t(),
  Cauldron3D.Vec.t(),
  number(),
  non_neg_integer()
) :: QuakeServer.Server.t()
```

Trace a box from `from` to `to` for `entity` and set the program's `trace_` globals
from what it hit, as `traceline` and `tracebox` do: `flags` is the program's `MOVE_`
bits (`QuakeServer.World.trace/7`), the mover's `hull` field left out.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
