Table of Contents

Loggy's Spellcasting AI reverse engineering notes

This is a complicated topic and won't be finished for a while.

Note for me

The battlefield location array seems to be stored with offsets of ((coord2 * 200) + coord 1) * 0x20 Or is it?

When looking for specific units in squares, it's instead (index, 0-7 inclusive + ((coord2 * 200) + coord1) * 8)

Stupid check

A spell is stupid if:

It is an offensive effect number, its aoe is greater than 600, it does not affect enemies only, and either:

"Offensive effect numbers" may include the following:

It is one of the following effects: Wrathful Skies, Fire Storm, Acid Storm, Astral Tempest, or Meteor Shower, and:

calcbestspell

Spell attribute 745/0x2e9 (found on most vanilla battle wide spells such as Doom, Wind of Death, Arcane Domination, Master Enslave, Army of Rats…) is some kind of checker for requiring a certain number of targets:

Evaluate spell score.

Evaluate spell score

When you actually are about to cast a spell...

spellunitscore

This scores how effective the AI thinks a spell is against a given victim.

Friendly bias: 1 if the victim is the same nation as you, else -1. This seems backwards, but is the reason this is usually multiplied by negative numbers

Early buff bias:

Self buff bias is 2 if the caster is the spell's target AND it is before round 2, otherwise it is 1

Work out spell's damage.

Conditional damage modifications:

Spec value modifications:

If the effect is cause affliction:

If the effect is enslave or charm, and the victim cannot be charmed/controlled, set damage to 0

If the spell doesn't affect floaters/flyers and the victim is, set damage to 0.

If your damage got reduced below one by any of the above, return a score of 0 and abort this function. [practically, this means that elemental damage > resist is a requirement for the casting AI to allow casting elemental evos on things]

For the following effects:

Your damage is considered to be 999. For everything else:

If the current damage value is greater than (victim chassis max hp + 5), set it to that value [shouldn't this be current hp instead?]

If the spell offers either (or both) an easy or hard MR check:

If MR check for half damage, multiply damage by 2/3 [shouldn't this be banded?]

If spell is defence negate OR (is not AoE and does not ignore shields), multiply damage by 2/3 [couldn't these be split and done a bit better?]

Look up the victim's chassis' strength score, and subtract 10 from it, and add the spell's damage. If the result is less than 1, consider it to be 1. This is the "strength value" going to be used for some effects later.

If the effect is buff type 1:

If the spell effect is buffs type 2:

If the spell effect is cause affliction:

For the following effects:

score = strength value * - friendly bias * 10

If the final score > 3, the victim is an enemy of the caster, and is immobilized, divide final score by 2.

If no nation has wholly routed:

If a nation HAS routed: