Choose Your Language

Friday 30 January 2015

AI AI .... Oh!

Old MacDonald may not have had many issues keeping his animals in check, but the beast known as the AI in NWN can certainly be a tricky issue to tame. In the last week or so, I have been looking at the AI (Artificial Intelligence) when it comes to NPCs using spells. While I was running a combat test, I noted that the spell casters would prefer to run into close melee combat rather than cast their spells. This was certainly not going to work for me, and so I decided to take a closer look and see if I could make my spell casters do what they should be doing best ... and cast their spells when entering combat.

There's Gonna Be A Fight!
Eventually, I managed to narrow down the problem to two areas of code, which with a little adjustment to my own code, managed to make the spell casters behave more intelligently, and cast their spells. The two adjustments included:-

1) Where possible, switch to using the function HenchDetermineCombatRound rather than using the ActionAttack function. I thought the latter function would have triggered the former, but this is not the case. (Obvious in hindsight.) Using the former function throws the NPC into immediately using its combat AI code, whereas the latter makes the NPC close to attack before thinking about it.

2) Update my own AI script (used for many other combat situations, including things like healing and weapon choice) to make reference to the older NWN function DetermineCombatRound if the NPC is a spell caster. This older function appears to give better results than the newer one (mentioned in 1 above). Therefore, while I use the newer HenchDetermineCombatRound to initiate the AI for the NPC, I actually re-direct the AI to use the older DetermineCombatRound function via my own AI script.

The end result of making these two adjustments is that my spell casters definitely use their spells before entering combat.

Combat Begins! The spell casters cast from the back!

Creatures Summoned! Now for their next trick!

Other Testing

While testing, I also discovered some other issues that needed fixing. (Some due to later updates I had made that affected the very early stuff.):-

1) Fixed creatures dropping their "creature items" due to a new ID system I had implemented.
2) Fixed a container found on a creature that was using an OC GUI that does not work.
3) Fixed creature auras that were clashing with my NPC detection aura system.
4) Fixed/Updated a Scroll GUI trigger system to use newer functions to allow more script calls.

There were a handful of other minor issues that I fixed along the way and which I encountered as I did another quick play test. In the coming weeks, I hope to carry on finishing conversations and finishing area scripts.

No comments: