ACTOR AI EXPLAINED  v1-01-2003  Release 1  © RTCM Reaper_Man

/!\ Attention: These FAQ's where written before the development of EDuke, many limits do not apply anymore.

These CON FAQs was written because I believe that there is no one place where CON information can be found - from the simplest ideas to the most complex effects. After the fall of Dukeworld and 3D Portal, a web-edition of the CON FAQ seems to have been lost, and that leaves Duke RTCM as the only other source of CON information. Though they do have information on CONs and how to edit them, I don't believe that this information is easily understood by the newest of newbie's.

The information here is for those newbie's, moderate programmers', and the experts alike. Know one knows everything there is to know about CONs, or any computer programming language for that matter. Everyone has their own style and their own ideas, and that leads to the limitless possibilities.

These FAQs are not a solid piece of work - it is an ever changing, ever evolving compilation of the DukeC programming language - the unofficial name of the CON language.

Enjoy!

Contents

Contents

 

This section is a little thick. I would suggest reading it slowly, at least twice.

The ai primitive is just part of the way artificial intelligence works in Duke. It is the definitions of several AI types that begins the whole artificial intelligence process. Lets look at some AI definitions for the Pigcop actor:

ai AIPIGSEEKENEMY APIGWALK PIGWALKVELS seekplayer
ai AIPIGSHOOTENEMY APIGSHOOT PIGSTOPPED faceplayer
ai AIPIGFLEEENEMY APIGWALK PIGWALKVELS fleeenemy
ai AIPIGSHOOT APIGSHOOT PIGSTOPPED faceplayer
ai AIPIGDODGE APIGRUN PIGRUNVELS dodgebullet
ai AIPIGCHARGE APIGRUN PIGRUNVELS seekplayer
ai AIPIGDIVING APIGDIVE PIGSTOPPED faceplayer
ai AIPIGDYING APIGDYING PIGSTOPPED faceplayer
ai AIPIGSHRINK APIGWALK SHRUNKVELS fleeenemy
ai AIPIGGROW APIGGROW PIGSTOPPED faceplayerslow
ai AIPIGHIT APIGHIT PIGSTOPPED faceplayer

Holy shit, thats tough. Before we get into anything major, lets take a first look at what we can tell:

1) The ai primitive must proceed anything else in the definition
2) Though it is not necissary, it is good practice to put AI before the name of every AI definition
3) Each of the ai definitions must have a unique name
4) Each ai definition must have 4 items following it
Ok, now that we have some basic understanding of AI definitions, lets take a closer look at what's following the ai primitive.

The first line following the ai primitive is a name for the AI definition. Like I said before, it is not necessary to have the letters AI before the names of you AI definitions, but it is a good idea to do so. This way you don't get the names of your AI definitions mixed up with action or move definitions, and have duplicate name errors during compiling.

The second line in the AI definition is the name of the action that is to be played when the AI routine is called. For example, if you were to code a DOG actor, it's AI definitions might look like this:

action ADOGWALK  0  4  5  1 12
action ADOGRUN  20  4  5  1  8

...

ai AIDOGWALK ADOGWALK DOGWALKVELS randomangle
ai AIDOGRUN  ADOGRUN  DOGRUNVELS  randomangle

When the ai routine AIDOGWALK is called, the DOG actor starts playing the action ADOGWALK. When the ai routine AIDOGRUN is called, it starts playing the action ADOGRUN.

The third line is exactly the same as the second, except it defines the movement for that AI routine instead of the action.

The last line in the AI definition is probably the most important. It tells what basic AI routine to have the AI definition run when it is called. Thats a little hard to understand, so lets modify our DOG actor to see if I can clear it up:

ai AIDOGWALK   ADOGWALK   DOGWALKVELS randomangle
ai AIDOGRUN    ADOGRUN    DOGRUNVELS  seekplayer
ai AIDOGATTACK ADOGATTACK DOGSTOPPED  faceplayer

First, the basic routines for the AI definitions have been changed. The first routine, AIDOGWALK, has a basic routine randomangle. The basic routine randomangle does exactly that, picks a random angle when AIDOGWALK is called and keeps heading that direction, playing the action ADOGWALK and moving at DOGWALKVELS speed. The DOG actor will only pick another randomangle when AIDOGWALK routine is called again.

The second routine, AIDOGRUN, has a basic routine seekplayer. The basic routine seekplayer is a bit more complicated. Every time it is called, it finds the distance between the DOG actor and the player, decides which direction would be the best to take in order to get to the player, and heads in that direction. Since the player and the DOG actor are probably both moving, it is a good idea to call any AI definition with the basic routine seekplayer as often as possible.

The last routine, AIDOGATTACK, has a basic routine faceplayer. The basic routine faceplayer is probably one of the simpilest basic routines in the language. It does exactly what it says, faces the player at all times. If we were able to get a BUILD-style map, we would be able to see that the DOG actor's tail is constantly looking in the direction of the player.

Note - There are 12 basic AI routines, and they are all listed and explained in the PRIMITIVE_LIST.

Defining your AI types for your actor is just the beginning part of the long process of AI coding. I would consider writing AI effectivly and properly one of the hardest parts of CON coding. Since both the actor and the player are constantly moving, it can be difficult to get the code perfect and work the way you want it to.

I will go through the next steps in the AI coding process in the BASIC_ACTOR3 page.