AI Director

AI Director is a system in WARFRAME that monitors and controls gameplay experience within missions in order to engage players and create a replayable gameplay loop in procedurally randomized and generated environments. It leverages Tile Set level design and enemy AI to deliver engaging gameplay flow throughout mission levels.
==General==
The AI Director is responsible for multiple duties:
*Measuring current gameplay intensity
*Controlling mission pace
*Enemy spawns
Every mission type has their own complications and objectives so the AI Director's behavior is adaptive to match the intended mission flow as defined by the developers.
For example, Exterminate missions require a minimum amount of enemies that spawn so players can complete the objective. Since the indended mission flow is linear, enemies will spawn in groups in front of players throughout the level instead of all at once to create a feeling of progression and bursts of intense gameplay. In most cases, the AI Director will spawn weaker enemies at the start of a mission (like Butchers or Lancers) and tougher enemies at the end (like Eximus Bombards) to create a sense of mission progression by gradually increasing gameplay difficulty.
For Survival missions, players are encouraged to explore branching rooms for Life Support Capsules and to move to centralized locations to activate the next Life Support Tower. So enemy spawns are spread out to attack players all on sides and to pressure them to move towards large centralized rooms for engagement.
==Technical==
For the AI Director to perform its job successfully, it needs to determine:
*A scoring metric for measuring gameplay intensity
*How Tile Sets are structured to know where enemies can spawn and the context of player actions (e.g. are players moving towards or away from the objective?)
*Available enemy types to spawn
*Maximum/minimum number of enemies that can be active at any time
*Associated weightings to enemy types so there is a fair distribution of enemy types in engagements
*Player's progress into a mission objective
===Intensity Score Metric===
Intensity score is arbitrary number value (say between 0 and 100) that measures the gameplay intensity experienced by a specific player. The higher the number, the more "intense" or "active" the player is. Each player in a squad has their own intensity score.
When players move through a level, they will encounter enemies, traps, or hazards that serve as a threat to the player, meaning those entities have the ability to harm the player in some way. A player's threat increases with more, tougher, and closer enemies. The enemy counterpart of this idea is also called Threat Level.
Players use their resources to combat against their threats. These can be categorized into defensive (health and shields) and offensive types (ammo, energy, abilities).
 Low Intensity Situation
Threat 	 	 	 	 	
Resource	 	 	 	 	
 	↑ 0	100 ↑	100 ↑	100 ↑	100 ↑
 High Intensity Situation
Threat 	 	 	 	 	
Resource	 	 	 	 	
 	↑ 0	100 ↑	100 ↑	100 ↑	100 ↑
A measurement of intensity can be formed based on the player's threat and resource level. A low gameplay intensity can be inferred if the threat level is low and the player has used not much of their resources to fight against their threats. Conversely, if the threat level is high and the player has used lots of resources, then the player is strugging to defeat their enemies and thus are in a high intense gameplay.
Intensity score is increased proportional to the normalized ratio of damage received to the player's total health and shields. It can also be increased proportional to the distance between the player and the enemy they just killed (e.g. the closer the enemy, the higher the "intensity"). The intensity score stays the same as long as the player is being targeted by an enemy, otherwise it will slowly decrease over time.
===Controlling Pacing===
Mission pacing is primarily controlled by enemy spawns as they usually are the main gameplay obstacle between the players and the main objective(s). Enemies are the source of combat encounters as they try to kill players or destroy objectives to put the mission into a fail state.
When intensity is low, the AI Director will start spawning enemies ahead of the players' mission path until it hits the mission's max enemy count or if the intensity score is at its maximum value. The AI Director will wait until the player kills nearby enemy combatants, reducing their intensity score, before spawning more enemies to increase the intensity again.
For dynamic and rhythmic gameplay pacing, enemy numbers will vary throughout a level depending on the tiles' block type. Connector tiles (e.g. corridors) are typically small and so have lower intensity limits. Intermediate tiles are larger combat spaces so they have higher limits and the objective tile will have the highest limit in a mission. In other words, players will usually see more and tougher enemies as they get closer to the objective and less when they move away from it.
Since each player has their own intensity score, they can all have different levels of gameplay engagement within the same mission.
===Enemy Spawning===
When the AI Director needs to spawn an enemy, it will look into the mission's available enemy types, each enemy's spawn probability, and each enemy's maximum spawn limit. For example, a Corpus Excavation mission may have the following enemy spawn specifications:
 Sample Corpus Excavation Enemy Spec*
Enemy Name 	Probability	Max Enemy Count	Tier^
Crewman 	100% 	0 	0
Prod Crewman 	25% 	6 	0
MOA 	60% 	0 	0
Shield Osprey 	100% 	3 	1
Detron Crewman 	50% 	0 	1
Shockwave MOA 	100% 	3 	2
Oxium Osprey 	5% 	3 	3
Sniper Crewman 	25% 	4 	3
Anti MOA 	100% 	2 	3
Fusion MOA 	100% 	3 	4
Elite Crewman 	100% 	2 	4
Corpus Tech 	100% 	3 	5
Railgun MOA 	100% 	3 	5
Power Carrier 	100% 	4 	0
Nullifier Crewman	10% 	0 	0
Mine Osprey 	15% 	0 	0
**Not representative of actual in-game enemy spec
*^Where tier represents an enemy's rank; the higher the number, the later the enemy will spawn into a mission (e.g. tougher enemies will spawn towards end of mission)
When an enemy is finally chosen, the AI Director needs to pick where on the level to spawn the enemy. The enemy must be spawned in a location where it will have the most effect on gameplay but not in direct line-of-sight of players or else their immersion is broken. Usually, enemies are spawned ahead of where players' are going, but close enough for engagement (like within the next two tiles or so). The AI Director uses a breadth-first search algorithm on the level's TacMap to find the nearest spawn points starting at a player's location.
Sample psuedocode on how the game chooses where to spawn an enemy:
 Add players' areas to open list
 While open list is not empty:
 	Pop area off front of open list
 	If area has not yet been visited:
 		Mark area as visited
 
 	If area is valid to keep:
 		Push area onto keep list
 
 	If area is valid to expand:
 		For each neighbor of area in the TacMap:
 			Push neighbor onto back of open list
 
 
 For each area in keep list:
 	For each spawnPoint in area:
 		If spawnPoint is enabled and not in use:
 			Push spawnPoint onto availableSpawns list
 
 // GaussianRand will generate a psuedorandom number based on a Gaussian distribution 
 // with mean 0 and standard deviation 0.5
 SelectedSpawnIdx = GaussianRand(0, availableSpawns.size)
 Return availableSpawns[SelectedSpawnIdx]
==Further Reading==
*
*
*
*Dynamic game difficulty balancing on Wikipedia
*
==References==
==See Also==
*Enemy Behavior
*Tile Sets
*RNG
Category:Mechanics
Category:Development