AI

Magic Combat and AI

There are things that devs and modders have tried to implement, but haven’t really come close to being successful at.  One of the most obvious and saddest examples is the AI versus player’s spell protections.  When the AI casts a spell like Spell Deflection, the player sees both the name of the spell as the enemy’s action, and can tell by the graphic overlay if the spell is still functioning in later rounds.  He also knows whether this spell is deflection, reflection, or absorption, and can act accordingly.  He can also easily keep up with how much of a beating the protection has taken, and can tailor his actions.

Sadly, the AI cannot come close to this level of knowledge.  BG only has two conditions to check for spell protections, HasBounceEffect and HasImmunityEffect.  The first returns true if the target has any reflection effects; this would be fine, except that this also includes spells that reflect physical projectiles like arrows.  The AI can’t tell the difference between the 6th level priest spell Physical Mirror and the 5th level mage spell Minor Spell Turning.

The second trigger, HasImmunityEffect, is even worse.  It returns true if the target is immune or protected, not from just spells, but from secondary applied effects like icon displays, visual effects, and display strings.  This means that HasImmEff will return true even if the player has only cast Remove Fear on himself, since part of that spell is protecting from the Fear visual effect, the string that says “Charname panicked”, and the Panicked icon.  The AI is unable to distinguish between Remove Fear, Minor Globe of Invulnerability, Spell Immunity, or Chaotic Commands.

In many effects exists a hardcoded setting of a variable, either as STATE or STATS (IDS files), that can be checked by a script to help with targeting.  For example, charm effects automatically set the STATE_CHARMED as true, so that when the charm is ended, whether by duration or dispelling, the STATE is also reset to zero.  Spells that apply an effect that does not have this hardcoded convenience can use the simple workaround of manually setting a STATS as a part of the spell.  There’s even enough room in the STATS and STATE IDS files to add new entries.  The venerable Detectable Spells mod, in use by many AI mods, does this with Spell Deflection for the various deflecting anti-magic spells.

The problem with this — and it’s a big one — is that it cannot account for the spell running out by decrementation (being used up by spells cast at it), and so only resets by either duration or dispelling. What you get is the ultimate in inefficiency:  You’ll see AI mages wasting a 6th level Pierce Magic spell to take a down a 3rd level Minor Spell Deflection that only has 1 spell level of protection left.  These are crippling mistakes that only the AI can make, not the player, and as such, are yet another opportunity for the player to inadvertently (or not) exploit the suboptimal AI.  Even the better AI mods are unable to overcome this deficiency.

Advertisements