• entries
    436
  • comments
    1179
  • views
    764009

Scripted AI

Sign in to follow this  

134 views

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.
Sign in to follow this  


3 Comments


Recommended Comments

Guest Anonymous Poster

Posted

Lua is good..... for me to poop on

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now