I’ve made some improvements to the creature AI, using a lot of the information from this article as a starting point. Different creatures now behave in different ways…most still act like they used to, blindly charging at you and attacking you. But they can also be (and become) hostile to other creatures, and fight them rather than you! Some types of creatures will even be friendly to you if you’re possessing one of their own. They also have the ability to get scared and run away, or, for more long-range creatures, try to maintain a minimum distance.
These behaviors can also be combined to result in interesting behavior. For a good example, we have Tourists. Tourists are now “hostile” to all other creatures, but they won’t attack outright. They prefer to hover around their target without getting too close, occasionally taking pictures, and running away if they’re approached. Occasionally, the creature they take a picture of will get pissed off and start chasing them trying to attack them.
They’re a nuisance, because their camera flash will stun you, but if they’re focused on one of your enemies they can be helpful, because the camera flash will stun your enemies, too!
Sidenote: Before I had the maintain-minimum-distance code in and set the tourists as hostile to other creatures, they’d roam around the level attacking other creatures. Since I also hadn’t finished the code that makes creatures hostile to things that attack them, they offered no resistance, so the tourists were basically traveling around killing everything. Games as social commentary!
This new system also has better support for passive creatures. For example, Snailpeople are described as peaceful. In the old game, they’d only attack you if you attacked them, except that the way the AI was written, they weren’t aggressive enough to pursue you if you attacked them and then ran away, or were attacking them with a spell from far away. Now, they’ll ignore you if you leave them alone, but if you hurt them, they’ll chase you with no forgiveness. Some creatures also ignore you unless you get too close to them.
The new AI also includes AI for follower creatures, so they’re slightly better now, finding their own targets to attack rather than waiting for you to target something. Creatures are also able to follow other creatures, for example necromancers now spawn with a few zombie followers.
All of these improvements do come at a cost though. On my 6-year-old laptop, the new AI code is 10 times slower than the old code. Not much of an issue, for my computer it now takes a 10,000th of a second per creature rather than a 100,000th of a second, so there’s no noticeable change. But if it gets too much slower, there would be (and actually, there was, before I improved a certain part of the code that was being unreasonably slow).
There are still some improvements I’d like to make, but we’ll have to see how much of a hit they cause performance.