1 Interactive AI CIS 487/587 Bruce R. Maxim UM-Dearborn.

22
1 Interactive AI CIS 487/587 Bruce R. Maxim UM-Dearborn

Transcript of 1 Interactive AI CIS 487/587 Bruce R. Maxim UM-Dearborn.

Page 1: 1 Interactive AI CIS 487/587 Bruce R. Maxim UM-Dearborn.

1

Interactive AI

CIS 487/587

Bruce R. Maxim

UM-Dearborn

Page 2: 1 Interactive AI CIS 487/587 Bruce R. Maxim UM-Dearborn.

2

Slides based on theCode from Advanced 3D

Game Programmingby Kenneth Finney

Page 3: 1 Interactive AI CIS 487/587 Bruce R. Maxim UM-Dearborn.

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

Page 4: 1 Interactive AI CIS 487/587 Bruce R. Maxim UM-Dearborn.

4

Archtitecture

ATI Queries

ATI Actions

GUI

ATI GUI Management Code

AIT Server

Management Code

Torque

Client

Torque

Server

Page 5: 1 Interactive AI CIS 487/587 Bruce R. Maxim UM-Dearborn.

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";

Page 6: 1 Interactive AI CIS 487/587 Bruce R. Maxim UM-Dearborn.

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');

}

Page 7: 1 Interactive AI CIS 487/587 Bruce R. Maxim UM-Dearborn.

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);", "");

Page 8: 1 Interactive AI CIS 487/587 Bruce R. Maxim UM-Dearborn.

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; }}

Page 9: 1 Interactive AI CIS 487/587 Bruce R. Maxim UM-Dearborn.

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");

Page 10: 1 Interactive AI CIS 487/587 Bruce R. Maxim UM-Dearborn.

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");

Page 11: 1 Interactive AI CIS 487/587 Bruce R. Maxim UM-Dearborn.

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

Page 12: 1 Interactive AI CIS 487/587 Bruce R. Maxim UM-Dearborn.

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

Page 13: 1 Interactive AI CIS 487/587 Bruce R. Maxim UM-Dearborn.

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

Page 14: 1 Interactive AI CIS 487/587 Bruce R. Maxim UM-Dearborn.

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

Page 15: 1 Interactive AI CIS 487/587 Bruce R. Maxim UM-Dearborn.

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

Page 16: 1 Interactive AI CIS 487/587 Bruce R. Maxim UM-Dearborn.

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

Page 17: 1 Interactive AI CIS 487/587 Bruce R. Maxim UM-Dearborn.

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

Page 18: 1 Interactive AI CIS 487/587 Bruce R. Maxim UM-Dearborn.

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

Page 19: 1 Interactive AI CIS 487/587 Bruce R. Maxim UM-Dearborn.

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

Page 20: 1 Interactive AI CIS 487/587 Bruce R. Maxim UM-Dearborn.

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

Page 21: 1 Interactive AI CIS 487/587 Bruce R. Maxim UM-Dearborn.

21

AIT Resources

• The AIT art and sound assets are store in the directory demo\data\AIT

Page 22: 1 Interactive AI CIS 487/587 Bruce R. Maxim UM-Dearborn.

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)