# AI

Ship AI behavior in FSO is controlled by three layered systems: the AI profile, the AI class, and AI goals and orders. Each layer handles a different aspect of behavior and they work together at runtime.

## AI profile

The AI profile is a mission-wide setting chosen in Mission Specs. It is primarily a difficulty scaling system: it defines per-difficulty-level values for things like damage multipliers, weapon fire delays, turn time, shield recharge rates, and aim behavior; controlling how the mission feels across the Very Easy through Insane difficulty range. Profiles also contain a large set of behavioral flags that toggle specific AI behaviors on or off.

Profiles are defined in `ai_profiles.tbl` and missions select from that list; custom profiles cannot be defined inside the mission file itself. If no profile is specified, the table's default profile is used. Most missions are fine with the default.

## AI class

The AI class is a named skill preset assigned to individual ships. It controls the skill level of that specific ship within the envelope set by the profile; how well it aims, how it maneuvers, how it uses afterburners, and so on.

Every ship class has a default AI class defined in its table entry. The Ship Editor lets you override that default for a specific ship instance, and individual turrets can be given their own AI class in the Weapons dialog.

## AI goals and orders

Goals and orders are specific tasks assigned to a ship or wing: attack a target, guard a ship, dock with a vessel, fly a waypoint path, and so on. There are two ways to set them:

- Initial orders - set in the Initial Orders dialog. These are the tasks a ship starts the mission with.
- Runtime goals - issued via SEXPs during the mission, typically from events. These override or supplement initial orders.

When a ship has multiple active goals, it pursues them in priority order. Priority is a value from 1 to 200 where higher values take precedence. Goals issued by the player via the comm menu use priorities in the 90–100 range, so goals with a priority above 89 may outrank player orders.

## How the layers interact

Think of it as: the profile sets the rules of the game, the class sets how skilled the ship is within those rules, and the goals and orders tell the ship what to do. A high-skill AI class given a low-priority goal can still be overridden by a player order; a locked-in high-priority goal will hold regardless of player input.