AI Documentation

From The DarkMod Wiki
Jump to navigationJump to search

This should be the starting point when trying to learn how the AI code in The Dark Mod is working.

General Coding

As of November 2007, a new AI coding framework has been introduced to further modularise the AI code. See AI Framework for more information.

Here is a small list of tutorials:

AI Variables

See here for a list of important AI (script) variables and how they behave: AI Variables

Alertness

All AI in The Dark Mod can have five distinct levels of alertness, indicated by an Alert Index ranging from 0 to 5:

  • Alert Index 0: Idle, not suspicious
  • Alert Index 1: Observant
  • Alert Index 2: Suspicious
  • Alert Index 3: Searching
  • Alert Index 4: Agitated Searching
  • Alert Index 5: Combat, Chasing Enemy

Despite these states, the actual alert level of an AI is seamless (internally stored in a float), the current Alert Index is changed when the threshold for a given index is exceeded. These thresholds can be set for each AI in its spawnargs, if a mapper wants to mess with that.

The thresholds are stored in the AI's member variables (thresh_1 to thresh_5). Idle AI have their alertlevel below thresh_1.

Changing Alertness

The Alert Level of any AI must be changed through calling idAI::SetAlertLevel with no exceptions! Directly manipulating the AI_AlertNum is not ok, because the SetAlertLevel method also keeps the AI_AlertIndex and other stuff in sync. Note that calling SetAlertLevel will most probably trigger an AI State change in the next frame, unless the current State does not allow it.

Incoming audio, tactile and visual alerts must go through idAI::AlertAI without exceptions. This way the probability checks are performed before the call to SetAlertLevel is invoked.