Adding AI Scripting to the Single Player Game
by Dairyman

 

If you have implemented the Single Player Quake III Game using the tutorials provided on this site you'll notice that the AI controlled characters are fairly limited in what you can have them do. They can move around and wait for enemies to appear, then attack, but not much else. They certainly can not be used for creating cut scenes, as you have virtually no control of their actions.

To give us complete control of an AI character's actions, and to increase their intelligence, we need to be able to script their AI. This tutorial will take you through the code changes necessary to add AI scripting based on that used by Return to Castle Wolfenstein to the Single Player Game. Along the way we will also add the ability to create scripted cut scenes, as well as beefing up the intelligence of AI characters that are not controlled by a script.

Important Prerequisites

Adding the scripted AI feature is a large project and it has some prerequisites that must be completed before you can start on it. First of all, you must have added the code changes required for the Single Player Game including the Single Player Entities and the Making Corpses Disappear sections. Secondly, you must have added the Scripted Camera code changes including the three additions to the scripted cameras (Stop Camera command, Multiple Cameras and the trap_stopCamera function). Without all these code changes the AI scripting will not compile or work properly.

Code Changes

AI scripting requires code changes to the quake3, cgame, game and ui projects. As with the single player game tutorial, the changes to the ui project will be only for the TA scripted UI rather than the regular Q3 UI. We will look at the code changes for each project separately.

Changes to the Single Player Game

As part of the AI scripting system, changes have been made to the single player game that have an effect other than through scripting. These changes are detailed in the following section.

Entity Changes and Additions

To implement the AI scripting system, changes had to be made to the NPC entity definitions and several new entities were added to the source code. Information about these changes and additions is in the following section.

Using Scripts in a Game

While much of the AI scripts are similar to the RTCW AI scripts there are enough differences that this section will be a complete guide on how to use AI scripting in a single player game. It will cover the basic concepts of this style of AI scripting and will provide a listing of all the commands and events that are supported, as well as examples of scripts.

Downloads

Due to the massive changes required for this project, a number of source files are avalible as a download. The packages include the source files that pertain to the NPCs in the game and cgame projects as well as the complete source for those projects.

One of the packages avalible for download is a sample cut scene that duplicates, more or less, the opening cut scene from the RTCW level The Crypt. The map is just an open room but the script shows how a cut scene is implemented using scripted NPCs and switching cameras.

For those that wish to check out the cut scene but don't want to have to compile their own exe and dlls there is also a package on the Downloads page containing the exe, dlls, ui scripts and graphics plus the cut scene data. You just have to add the NPC Asset Package and the Quake 3 pak files to check out the Crypt cut scene.

 

Return toTutorial Index