Scripted AI

Published August 25, 2005
Advertisement
I've finished handing off control of monster AI to the Lua script system. This is a new direction for me, as I've never done scripted AI before. Although I made heavy use of Lua in Golem 1 for random generation, the only control afforded over monster behaviors was via the setting of various probabilities used in decision making; all of the actual 'thinking' was done in the engine code, and so behaviors were pretty much canned. It was very difficult, if not impossible, to do very much special casing for unique monsters and NPC personality.

Now, each monster (or NPC in general) has a Think script object that is executed each time the monster needs to figure out what to do next. Eventually, I may either do multiple levels of Think (for level of detail reasons), or I'll finesse the Sleeping state to not call Think, and only when an event has occured to disturb the monster from Sleeping to Idle or other, only then will Think be called. Should save the performance hit of calling Think on monsters far off-screen and non-disturbed. Alternatively, if I go with a level-of-detail AI, monsters would have separate scripts for each level. However, I don't really want to be calling Think on Sleeping monsters, so it is likely I will not go this route.

I'm currently struggling with a bit of a problem. It is possible to compile Lua script down to bytecode for possibly faster execution times, something that would certainly be desirable for a Think script since they may be called by many objects every update. However, I have yet to find an obvious way of pre-compiling a loaded script to bytecode and being able to execute it. Right now, I'm simply storing the plain-text strings for the scripts, which can be either loaded from file or generated on the fly as necessary. However, every time the script is executed it must be compiled on the fly, and I would like to do away with this intermediate compilation. Perusing the source for Lua 4.0 (which this project uses, based as it is on old Accidental code) I can find no immediately obvious way of doing this. The only code paths that seem to handle compiled bytecode are along the lua_dofile route, and there is weirdness in that code path that defies easy implementation of what I have in mind. I'm pretty sure I can hack something together. Phantom is helping me on this problem as well, so hopefully between the two of us we can figure out the best way to do this.

I might get around to posting a few images sometime this weekend, when I've prettied up a few things. Then again, I might not. We'll see.
Previous Entry FSM
Next Entry Python
0 likes 3 comments

Comments

JTippetts
Ha ha! You don't fool me with your Anonymous posting, sir! [grin]
August 26, 2005 11:03 PM
evolutional
Damned APs ;)
August 28, 2005 05:55 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement