# IFF & Teams

IFF stands for Identification Friend or Foe. Every ship in a mission belongs to a team, and every team has a defined relationship with every other team. Those relationships determine how ships behave toward one another: whether they attack, ignore, or treat each other as allies.

## Team relationships

Team relationships are defined in `iff_defs.tbl`, not in the mission file. The common defaults are:

Team | Typical role
--- | ---
Friendly | Player's side. Ships the player can target for orders and that friendly AI protects.
Hostile | Enemy. Ships that actively attack Friendly ships.
Neutral | Neither side. Not attacked unless attacked first.
Unknown | Unidentified. Treated as neutral until scanned or otherwise identified.
Traitor | Formerly friendly ships that have turned hostile. Attacked by all sides.

Mods can define additional teams and custom relationships between them. The teams available in your mission depend on what `iff_defs.tbl` provides for the loaded mod.

## What team membership affects

- AI targeting - ships attack any ship they have a hostile relationship with and avoid attacking allies.
- Escort and guard behavior - AI set to guard a ship will also engage enemies threatening it.
- Comm menu - the player can only issue orders to ships on the Friendly team.
- HUD - target brackets, colors, and the hostile/friendly indicators on the radar all derive from IFF relationships.
- SEXPs — many SEXP operators accept a team argument to act on all ships of a given team at once.

## Changing team at runtime

A ship's team can be changed during the mission using SEXPs. This is how defection scenarios work: reassigning a ship to the Traitor or Hostile team immediately causes former allies to engage it.

The Team field in the Ship Editor sets the team at mission start. Runtime changes are made through SEXPs and are not reflected back in the editor.