1 interactive ai cis 487/587 bruce r. maxim um-dearborn
TRANSCRIPT
1
Interactive AI
CIS 487/587
Bruce R. Maxim
UM-Dearborn
2
Slides based on theCode from Advanced 3D
Game Programmingby Kenneth Finney
3
GUI Specification
• Configurable to be key-based or automatic• Player menu for queries or responses• AI can respond to all player inputs• AI can act on all player inputs• Means to display AI character portrait• AI turns to face player• Should not activate if NPC is not AI player• Use flat text files for query and response tables
4
Archtitecture
ATI Queries
ATI Actions
GUI
ATI GUI Management Code
AIT Server
Management Code
Torque
Client
Torque
Server
5
Preparation - 1
• Add the following lines of code to the end of demo\client\defaults.cs to create global variables used by several modules$pref::AIT::DataPath = "demo/data/AIT/";
$pref::AIT::MaxOptions = 100;
$pref::AIT::QueryColour = "\c1";
$pref::AIT::ActionColour = "\c5";
6
Preparation - 2
• Add the following lines of code to the end of demo\client\scripts\default.bind.csfunction TalkTo(%val)
{
if (%val)
commandToServer('AITCOntact');
}
7
Preparation - 3
• Add the following lines of code to the end of demo\client\scripts\default.bind.cs// Binds letter q to the make contact function TalkTo
// and reserves the numeral keys for use in the GUI
moveMap.bind(keyboard, q, TalkTo);
moveMap.bindCmd(keyboard, "1", "SelectAnswer(1);", "");
…
moveMap.bindCmd(keyboard, "8", "SelectAnswer(8);", "");
moveMap.bindCmd(keyboard, "9", "SelectAnswer(9);", "");
moveMap.bindCmd(keyboard, "0", "SelectAnswer(10);", "");
8
Preparation - 4
• Add the following lines of code to the end of demo\client\scripts\default.bind.cs// Gives the numeral keys their default meanings when not// in AIT query dialog function OutOfAITFunction(%NUmber){ switch(%NUmber) { case 1: commandToServer('use',"Crossbow"); case 2: %Number = 0; … case 9: %Number = 0; case 0: %Number = 0; }}
9
Preparation - 5
• Add the following line of code to the end of demo\server\defaults.cs$Pref::Server::AITPath = "demo/data/AIT/"
• Add the following lines of code to the function onServerCreated after the line exec(“./crossbow”); demo\server\scripts\game.cs exec("./AITServer.cs");
exec("./AITCommands.cs");
10
Preparation - 6
• Add the following line of code to the end of demo\client\init.cs to the function initClient
exec("./ui/AITGui.gui");
after the lineexec("./ui/PlayerList.gui");
and the lineexec("./scripts/AITClient.cs");
after the lineexec("./scripts/centerPrint.cs");
11
Preparation - 7
• Always delete the following files after making changes to preferences and defaults (Torque creates them dynamically when the engine exits)
demo\client\config.cs
demo\client\config.cs.dso
demo\client\prefs.cs
demo\client\prefs.cs.dso
demo\server\prefs.cs
demo\server\prefs.cs.dso
12
AITServer - 1
• Add the code from the file AITServer.cs to the directory demo\server\scripts
• The functions GetActionEntry and Get Action extract the response actions from the response table file
• AITMessageClient sends information to the AIClient code for the NPC talking to the player
13
AITServer - 2
• Function serverCmdAITAnswer sends a message to the server and waits for is answer (encoded as an index to the action table)
• Function serverCmdAITContact begins the dialog when player presses the q key when within range of the NPC (will either respond with the action script or a busy message)
• Function AITBusy makes sure the NPC is busy doing something other the talking
14
AITServer - 3
• Function CheckAITStatus checks to see whether the player has wandered out of range of the NPC or it needs to check for another query
• The AIT-system-aware AI is spawned into the game using SpawnAI (like we did in AIGuard)
• The fuction TestAIT is a test function containing several preset values to artwork and scripts
15
AITClient Module - 1
• The file AITClient.cs needs to be copied into the directory demo\client\scripts
• The functions GetActionEntry and GetAction are the same as those on the server side
• Function clientCmdCloseAIT shuts down the AIT GUI when ordered to by the server
• Function clientCmdAITMessage posts the info pased by the server on the GUI
16
AITClient Module - 2
• Function OnAITMessage – locates the bitmap used the the character mugshot
and the AITScript file– locates the response and any audio by looking
through the query table– Assembles and answer and formats it for the GUI
• The method AITAnswer::OnURL directs queries to AITQuery::OnURL which assembles the info from the query
17
AITClient Module - 3
• Function PlayAITSound plays the sound if it can find the specified .wav file
• Function SelectAnswer is the function we used in the key bindings, it either selects an answer from the GUI or returns the numeric key to its original purpose
18
AITCommands Module
• Copy the code in the file AITCommands.cs to the directory demo\server\scripts
• The functions behave pretty much like theit names imply
19
AITGui Module
• Copy the file AITGui.gui to the directory demo\client\ui
• The formatting and syntax is important or the GUI will not compile
20
AITScript Files
• These are specially formatted files that look are lot like html
• The .qry files contain the indexed query tables and the .rsp files contain the indexed response files
• The required fileself.qry, elf.rsp, orc.qry, orc.rsp
are housed in the directory demo\data\AIT with the other AIT art assets
21
AIT Resources
• The AIT art and sound assets are store in the directory demo\data\AIT
22
Testing the AIT System
• Once you are inside the FPS demo, open the console and type
testAIT();
• Your task now is to find the NPC chat palyer without getting killed by the AIGuards
• Once you find the NPQ type q and then use the menus (the NPC will kill you if you ask it to do so)