220 likes | 310 Views
Interactive AI. CIS 487/587 Bruce R. Maxim UM-Dearborn. Slides based on the Code from Advanced 3D Game Programming by Kenneth Finney. GUI Specification. Configurable to be key-based or automatic Player menu for queries or responses AI can respond to all player inputs
E N D
Interactive AI CIS 487/587 Bruce R. Maxim UM-Dearborn
Slides based on theCode from Advanced 3DGame Programmingby Kenneth Finney
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
Archtitecture Torque Server Torque Client ATI Queries ATI Actions ATI GUI Management Code AIT Server Management Code GUI
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";
Preparation - 2 • Add the following lines of code to the end of demo\client\scripts\default.bind.cs function TalkTo(%val) { if (%val) commandToServer('AITCOntact'); }
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);", "");
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; } }
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");
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 line exec("./ui/PlayerList.gui"); and the line exec("./scripts/AITClient.cs"); after the line exec("./scripts/centerPrint.cs");
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
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
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
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
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
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
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
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
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
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 files elf.qry, elf.rsp, orc.qry, orc.rsp are housed in the directory demo\data\AIT with the other AIT art assets
AIT Resources • The AIT art and sound assets are store in the directory demo\data\AIT
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)