It's very bad practice to comment every line. It's unnecessary and makes this very unreadable.
Okay, a couple of issues off the bat:
Setting loop_checks to 0 is a very bad idea. You should be able to do an event loop without needing this.
Also, putting all the rpg guts in AI.dm is poor form for a library and not super for a demo- split it to its own file as it shouldn't be necessary for a simple AI loop.
The loop itself seems to use states to determine activity, but instead of having 1 var reflecting mob state, you have a bunch (active, fighter, etc).
I would recommend you take a look at Deadron's event loop to see a good implementation of an event loop and simple behavior schemes.