AI

Artificial Intelligence is simply a game's attempt to mimic intelligence and behaviour, typically associated with a creature or thing. It is important to remember that convincing AI can help define the feel of the game almost as much as the visual aspects. In JK and MotS, AI files are what helps each interactive "thing" behave realistically (or as "realistic" as the game engine allows for), by defining a base set of 'instincts' which, when various conditions are met, will trigger the AI character (usually a 3do model) to respond.


File Extension Details

For both JK and MotS, there are three possible types of AI file, identifiable by the file's extension. The extension itself relates to the intended difficulty level of the game.

  • .ai0 - Used for easy difficulty setting.
  • .ai - Used for medium difficulty setting.
  • .ai2 - Used for hard difficulty setting.


Typically, the AI should react quicker/fire more frequently, etc, as the difficulty levels increase, but this does not necessarily have to be the case and is left to the discretion of the editor.


Ideally, whilst there should be an AI file for each corresponding difficulty level, this may not always be the case. When this situation arises, the game engine defaults to an ".ai" file type, when no other AI file is provided. Similarly, if, for example, only an ".ai2" file exists (with no ".ai0" or ".ai" equivalents found in the resource), that same ".ai2" file is used for all difficulty levels.


File Placement Location

All AI file types should be placed under the misc/ai directory of your project or GOB/GOO. Please note that you do not need separate "AI0" or "AI2" directories.


Setting an AI Class to apply to a Character

JK and MotS's AI files control the behavioural "instincts" that a character should possess. Without an AI file attached, the character just stands there in your level, completely oblivious to its surroundings; it will still register damage if it is hurt and play a damaged/recoil keyframe, but it will only move if you bump or "push" the character. There is therefore no sort of interaction and the purpose of having the character in the level to begin with is questionable.


There are three different approaches for setting an actor's AI class:

  1. Direct Template Modification
  2. JED "AICLASS" Attribute
  3. COG Verbs


Direct Template Modification

    jk_actor    3dmodel=actor3DO.3do puppet=actor.pup   aiclass=AIFileForActorHere.ai

This technique is good for applying a global AI class to a particular type of actor (eg: all stormtroopers should have the same behavioural instincts).


JED "AICLASS" Attribute

''Key'' | Value
-------------------------------
AICLASS | AIFileForActorHere.ai

This technique makes it possible to set level-specific AI for an individual actor. In JED (the following method has not been tested in JKEdit), by clicking on the "add property" and typing in "aiclass" (NB: not case sensitive), allows the associated attribute value to be a valid/existing AI file, which is loaded either from the current project directory's misc/ai subdirectory or from pre-exisiting JK/MotS GOB/GOO files.


COG Verbs


##
# JK and MotS compliant Cog Script
#
# Set 4 "things"' AI classes upon startup and modify
# the AI class, upon entering a sector.
#
##
symbols
	message	startup
	message	entered
	sector	triggerSector	linkid=1
	int	i=0		local
	int	numActors=4	local
	thing	theAIActor0
	thing	theAIActor1
	thing	theAIActor2
	thing	theAIActor3
	ai	initialAI
	ai	alteredAI
end

#=============================================================================
#=============================================================================

code

	startup:
		for (i=0 ; i<numActors ; i=i+1)
			AISetClass (theAIActor0[i], initialAI);
	return;


	#=====================================================================


	entered:
		if (GetSenderID() == 1) {	// match the linkid
			for (i=0 ; i<numActors ; i=i+1)
				AISetClass (theAIActor0[i], alteredAI);
		}
	return;
	
	#=====================================================================

end

This technique provides the potential for swopping AI files for characters dynamically, depending on their surroundings and current environment. However, this aspect borders more on the realm of cogging and not explicity AI files.


An AI File's Header

Each AI file you write should include a comment header, for example:

    ##
    # JK/MotS AI File
    #
    # FILENAME.AI
    #
    # Header Text
    # All "comment" code is prefixed with the "#" symbol
    #
    ##

Although these headers are not compulsory, it makes life easier for editors to follow, as well as helping to "jog your memory" if you can't remember the specific nature of the AI File.


The AI Setup Line

The line below is the AI Setup Line. It is the first line in the AI file (the first "real" line that the game engine processes) and details what the basic AI attribute values should be. Each attribute and its accompanying value are comma delimited. All instinct lines (described in the next section) are listed after the setup line. Only one instance of this line is allowed per AI file. The order of each attribute does not seem to matter; the game engine appears to process the setup line as a complete entity (although alignment and rank are usually the first attributes).


Attributes in square brackets "[ ]" are not used by all AI files, as addressed below:

    alignment= , rank=0.5, fov= , [maxstep= ], sightdist= , heardist= , [accuracy= ]
  1. The "alignment" attribute's value in the AI Setup Line may be one of two values (if JK) or one of three values (if MotS). These are: -1.0 (nemesis/opponent) or 0.0 (neutral/pedestrians) [ or 1.0 (Ally/Friend) ].
  2. The "rank" attribute in LEC's files always has a value of 0.5. This is redundant: why or for what purpose this instinct is included is unknown. Perhaps, LEC intended to implement this as part of a "squad feature", but experienced problems/time-complexity issues with its execution.
  3. The "fov" ("field of view") attribute typically ranges between 170° to 180°. Valid boundaries must be >0 and <360.
  4. The "maxstep" attribute sets the maximum jump/fall height allowed for the AI character. They will not attempt to "drop/fall" from a height greater than this value, nor will they attempt a vertical jump which is greater than this value.
  5. The "sightdist" attribute sets the maximum distance that the AI can "see" to (JKUs).
  6. The "heardist" attribute allows the AI to be able to "hear" all noises within this proximity (JKUs).
  7. The "accuracy" attribute sets the accuracy figure for any projectiles the AI attacks with. Despite other offsets (such as the "PrimaryFire"'s accuracy instinct), this overides everything! The attribute value must be within the range of 0.0 and 1.0.


Other Related Notes

  • Water-based opponents always have an "accuracy" value of 1.00 (at least ones with a "bite" do - there are only 2 examples to go on in JK and both use this value), with a "maxstep" value of 0.0 . Water Cycs seem to be the exception to this rule with a "maxstep" value of 1.0 .
  • Flying-based oppenents do NOT have a "maxstep" setting in the AI setup line.
  • Droids seem to have a "maxstep" setting of 0.0 . Presumably by convention, droids don't fly in JK. On a speculative basis, it is presumed that droids/robots would be treated as flying by setting the appropriate "thing/physics/actor" flags via COG or template modification.
  • Jedi / Dark Jedi do NOT have an "accuracy" setting. It is thought that this is offset by providing them with a "SaberFighting" instinct.
  • Turret Guns do NOT use either a "maxstep" or "accuracy" setting.
  • When saving an AI file, the extension you give it will be one of three formats. These are *.ai0 (easy) or *.ai (medium) or *.ai2 (hard). Normally you would define a marginally different file for each difficulty level. If however you decide to supply only one AI file-type, then JK and MotS will use that one file for all levels of gameplay. As stated by the JK Specs:
"There are 3 types of AI files for 3 difficulty levels. 
If a level is played on Easy, JK automatically uses files with the ".AI0" extension. 
On Hard, the ".AI2" files are used. 
On Medium (and if there are no extra AI0 & AI2 files), the .AI files are used.

The AI files do not influence the outward appearence of an enemy, nor [do] they define which weapons a character has. 
They only specify the character of the character (and his weapons)." 


Available Instincts

The following is a list of all available instincts. MotS supports an extended number of instincts, which are not parsed by the JK game engine, and so are marked accordingly. Note that whilst the following list is not case sensitive, it is highly recommended that editors adhere to the "CamelCase" style of coding (capitalisation for each new word).


In alphebetical order, these instincts are:

Sources

JK Specs

  • Create:
This page was last modified 21:06, 3 December 2005.   This page has been accessed 1,553 times.