> ## Documentation Index
> Fetch the complete documentation index at: https://docs.eucaengine.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Units & roles

> Compose a playable unit — health, team, auto-combat, gold, and a role label — from genre-neutral gameplay components in one spawn call, then read back exactly the components it stamped. Built end to end on a local server.

A "hero" in Euca is not a special type — it is a **generic entity composed from gameplay
components**. You spawn it with flags that map one-to-one onto components: `health`→`Health`,
`team`→`Team`, `combat`→an `AutoCombat` bundle, `gold`/`gold_bounty`/`xp_bounty`→the economy
components, and `role` is a label (`EntityRole::Hero`). One `POST /spawn` stamps the whole bundle.
This builds on the genre-neutral [gameplay](/systems/gameplay-and-combat) primitives; every command
is real and runnable against a [local server](/quickstart), with output captured from one.

The full Dota-style hero kit (mana, abilities, base/growth stats) is assembled by the **MOBA example
game** (`games/euca-moba`), not by the generic HTTP surface — see [MOBA systems](/systems/moba).

## Compose a unit

**Spawn an entity with gameplay components.** The flat keys on `/spawn` each add a component; omit one
and that component is left off. This is exactly what the CLI front-end `euca entity create --role hero --combat --gold …` sends.

```bash theme={null}
curl -s -X POST http://localhost:3917/spawn -H 'Content-Type: application/json' -d '{
  "mesh":"sphere","color":"cyan","position":[-7,0.5,0],"health":500,"team":1,
  "combat":true,"combat_damage":30,"combat_range":2,"combat_speed":4,"combat_cooldown":0.8,
  "role":"hero","gold":600,"gold_bounty":300,"xp_bounty":200}'
# {"entity_id":103,"entity_generation":0}
```

The same call over the CLI:

```bash theme={null}
euca entity create --mesh sphere --color cyan "--position=-7,0.5,0" \
  --health 500 --team 1 --combat --combat-damage 30 --combat-range 2 \
  --combat-speed 4 --combat-cooldown 0.8 --role hero \
  --gold 600 --gold-bounty 300 --xp-bounty 200
```

**Read the entity back.** `/entities/{id}` shows precisely the components the flags stamped on — `Health`,
`Team`, `Gold`, a `Level(1)` (added alongside gold), and `EntityRole::Hero`. There is **no** mana,
ability set, or base/growth stats: those are the MOBA game's hero kit, not the generic spawn.

```bash theme={null}
curl -s http://localhost:3917/entities/103
# {"id":103,"generation":0,
#  "transform":{"position":[0.0,0.0,0.0], ...},
#  "velocity":{"linear":[0.0,0.0,0.0],"angular":[0.0,0.0,0.0]},
#  "health":[500.0,500.0],"team":1,"gold":600,"level":1,"role":"Hero"}
```

After one `/step`, the transform propagates to the spawn `position`:

```bash theme={null}
curl -s -X POST http://localhost:3917/step -H 'Content-Type: application/json' -d '{"ticks":1}'
curl -s http://localhost:3917/entities/103
# {..., "transform":{"position":[-7.0,0.5,0.0], ...}, "health":[500.0,500.0], "role":"Hero"}
```

## What each flag maps to

| Flag (spawn key / CLI)                                                                      | Component(s) added                                                             |
| ------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------ |
| `health` / `--health`                                                                       | `Health(current, max)`                                                         |
| `team` / `--team`                                                                           | `Team`                                                                         |
| `combat` (+ `combat_damage`/`combat_range`/`combat_speed`/`combat_cooldown`/`combat_style`) | an `AutoCombat` bundle (detect → chase → attack), plus `Velocity` for movement |
| `gold` / `--gold`                                                                           | `Gold` **and** `Level(1)`                                                      |
| `gold_bounty` / `--gold-bounty`, `xp_bounty` / `--xp-bounty`                                | `GoldBounty` / `XpBounty` (paid to the killer)                                 |
| `role` / `--role` (`hero`/`minion`/`tower`/`structure`)                                     | `EntityRole` label                                                             |
| `player` / `--player`                                                                       | `PlayerHero` marker                                                            |
| `spawn_point` / `--spawn-point`                                                             | marks a team respawn location                                                  |

## Behavior and gotchas

The things you only learn by running it:

* **A unit is just components — there is no hero registry or template.** The deleted `/hero/define`,
  `/hero/select`, and `/hero/list` routes are gone (they 404). You compose a unit per-spawn from the flags
  above; re-create it with different flags to change it.
* **`gold` adds `Level(1)`, not just `Gold`.** Spawning with `gold` also stamps a `Level(1)` so leveling
  and bounties have something to read; you get `"level":1` back even though you passed only `gold`.
* **`combat` needs its sub-flags to be useful.** `combat:true` alone enables the auto-combat behavior but
  with default numbers; pass `combat_damage`/`combat_range`/`combat_cooldown` (and `combat_speed:0` for a
  stationary tower) to tune it. See [Gameplay & combat](/systems/gameplay-and-combat).
* **`transform.position` is `[0,0,0]` until the first `/step`.** The component state is correct
  immediately; the transform is just unpropagated until the tick loop runs — see
  [Simulation](/systems/simulation).
* **Mana, abilities, and stat growth are the MOBA game's hero kit.** They are inserted in Rust by
  `euca-moba`'s `spawn_hero`, not by `/spawn`. There is no generic HTTP route that attaches an
  `AbilitySet` — see [Abilities & status effects](/systems/abilities-and-status-effects).

## Endpoints

| Method | Path                        | Description                                                 |
| ------ | --------------------------- | ----------------------------------------------------------- |
| `POST` | `/spawn`                    | Create an entity, composing components from the flags above |
| `GET`  | `/entities/{id}`            | Read back the entity with all its components                |
| `POST` | `/entities/{id}/components` | Add/update components on an existing entity                 |

The combat, economy, and team primitives a unit is built from live on
[Gameplay & combat](/systems/gameplay-and-combat); items and the gold economy are on
[Inventory & economy](/systems/inventory-and-economy).

## Status

* **Shipped, all headless** — composing a unit from gameplay components in one spawn call (health,
  team, auto-combat, gold + level, bounties, role), with read-back of exactly the stamped components.
* **MOBA hero kit** (mana, abilities, base/growth stats) ships in the
  [MOBA example game](/systems/moba), assembled in-engine rather than over the generic HTTP surface.

<Card title="Entity & spawn endpoints" icon="user-shield" href="/api-reference/introduction" horizontal>
  The spawn and entity endpoints, with request and response schemas.
</Card>
