# Team Strategy

Plan what each bot will do when it is alone and what changes when it has allies. A good pair can cover more angles, defend a pickup route, or turn a short stun into sustained damage. Each bot still needs its own legal weapon and a fallback for a destroyed or distant teammate.

## Assign roles and make room

In Battle Setup you can use two to four teams with up to three bots on each. Members of a team start near one another and face the arena center. Ranked leaderboard battles use one bot per team. Test coordinated pilots in a team practice or custom battle.

- **Lead or intercept.** Put a resilient or fast bot where it can choose the first engagement. Give it a route around enemy blockers and a way to back out of its allies' firing lanes.
- **Follow up at a different angle.** A Railgun or Beam Laser bot can track the same enemy from one side. A different angle reduces traffic at the leader's position and gives the team a second line when the opponent retreats. Keep your own firing and movement rules if the designated target disappears.
- **Time control for usable shots.** An EMP is valuable when one or more allies are in range and ready to fire. A Repulsor can open a route away from a close attacker. A Graviton can pull a target into a short-range ally's reach, but it can also spoil a predicted shot. Tell allies about a planned control window with time to react.
- **Leave a recovery lane.** Avoid sending every bot to the same point. Use offset goals or different approach angles. If you are close to a teammate, pick a route beside it. Living bots block movement for both teams under either friendly-fire setting.

`teamState()` includes the caller and destroyed seats, ordered by seat. Each row has its match-local `id`, `seat`, and `alive` status. Living rows also report heading, mobility, stun, cloak, weapon readiness, and coarse hull, energy, and ammo bands. Join those rows to `scan()['allies']` by ID for positions. A cloaked living teammate remains visible to your team. The roster's `hasReadyWeapon` reports availability from the current resources and cooldowns. It gives no guarantee of alignment or range.

For a consistent leader, choose the lowest living seat on each pilot. Use the roster to detect when it is destroyed. An ally that is stunned or low on resources can yield a role by publishing a short status update. Treat the status as advisory and fall back to your own scan if it expires.

## Share what changes a decision

| Interface | Use it for | Timing and limit |
| --- | --- | --- |
| `signal()` and `signals()` | A location ping of kind `enemy`, `help`, or `pickup`. | One send per tick. Teammates read it on the next tick. |
| `sendTeamMessage()` and `teamMessages()` | Events and instructions such as a target ID, a planned volley, or a request to use another lane. Broadcast or address one living teammate. | Two sends per tick. Delivery is next tick. TTL is 1–40 ticks, default 20. Reads return at most 12 newest matches in delivery order and leave them in the mailbox. |
| `publishTeamData()` and `teamData()` | Current role or intent that allies may consult repeatedly, such as the position you plan to hold. | Two writes or clears per tick, one per key, and four retained keys per writer. TTL is 1–80 ticks. Writes become visible next tick. |
| `claimTeamObjective()` and `teamClaims()` | Which ally intends to collect a visible pickup. | Claim `pickup` with its scanned ID. TTL is 1–80 ticks, default 40. Results are visible next tick. |

Message topics and shared-data keys use a lowercase letter followed by up to 31 lowercase letters, digits, periods, underscores, or hyphens. Payloads are JSON-compatible arrays of up to 256 encoded bytes, four array levels, and 32 values including the outer array. At 20 ticks per second, a 20-tick message lasts one second after delivery. Send when intent changes or at a modest refresh rate. Use message IDs or `deliveredTick` to avoid repeatedly acting on the same request, and check `actionResults()` for delivery and arbitration outcomes. A shared value can outlast its writer until its TTL, so confirm the owner's status if that value affects routing.

In this target-selection block, the leader broadcasts a focus every eight ticks. Followers match it against their own current scan and keep a local fallback. After this block, apply your usual range, aim, and risk checks to `$target`.

```php
<?php
$team = $pilot->teamState();
$enemies = $pilot->scan()['enemies'];
$target = $enemies[0] ?? null;
$leader = null;
foreach ($team['roster'] as $member) {
    if ($member['alive']) {
        $leader = $member['id'];
        break;
    }
}

if ($team['participantId'] === $leader) {
    if ($target !== null && $team['tick'] % 8 === 0) {
        $pilot->sendTeamMessage('focus', ['id' => $target['id']], null, 12);
    }
} elseif ($leader !== null) {
    $mail = $pilot->teamMessages('focus', $leader);
    $focus = null;
    foreach ($mail['messages'] as $message) {
        $focus = $message['payload']['id'] ?? null;
    }
    foreach ($enemies as $enemy) {
        if ($enemy['id'] === $focus) {
            $target = $enemy;
            break;
        }
    }
}
```

## Coordinate pickups and fire

A pickup claim reserves a team assignment. Actual collection still goes to a bot inside the pickup radius. With pilots active, the closest eligible bot collects it and the lower participant ID breaks an exact distance tie. Use `estimateMove()` and resource bands to decide which ally should go. If another teammate holds the claim, route your bot outside the collection radius. Release your own claim if you give up the route. A claim expires when its owner is destroyed, its TTL runs out, or its pickup is collected or disappears.

With friendly fire off, allied bots are skipped by hit tests and allied weapon effects cannot damage, stun, push, or pull them. With friendly fire on, teammates are eligible for those effects, including projectile contacts, splash, and control waves. Your own direct weapons and self-centered pulses skip their source. Missiles can hit their own launcher with splash when friendly fire is on.

Use the same ground point for `estimateFriendlyFire()` as for directional `fire()`, or pass only the slot for a centered effect. With friendly fire enabled, a nonempty `atRisk` list is a reason to hold fire or use another angle. The estimate projects nominal geometry at launch and is limited to the contacts in the snapshot. Later motion, launch spread, early collision, and hidden contacts can change the outcome. Missile forecasts list allies, so leave your own clearance around the possible impact point as well. Refresh a pending shot with `aim()` or cancel it before an ally crosses its line.

## Practice the handoffs

Try **Team communication** with Squad Scout as a teammate to see basic pings. In **Contested pickups**, verify that the bot with the claim drives toward the item and its ally takes a separate route. In **Allied fire risk**, look for an ally crossing the firing line and check why the pilot held or released its shot. Inspect the authorized practice trace for structured team results. Ordinary replay downloads omit private team messages and shared data.

Try the same team on each seat, after the lead bot is destroyed, and on a different arena size. Compare with each pilot running solo to see what the coordination adds. [Combat Strategy](combat-strategy.md) · [Pilot API](pilot-api.md) · [Testing](testing.md) · [Examples](examples.md)
