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:
The enemy has less than 3 mages, and the caster's army size outnumbers the opponent's by more than 20 times
The enemy has less than 3 mages, the caster's army size outnumbers the opponent by more than 10 times, and the caster's side has less than 50 troops
"Offensive effect numbers" may include the following:
2, damage [1]
3, fatigue damage [1]
4, cause fear type 1 [1]
7, poison damage [1]
8, remove fatigue? [-1]
9, undocumented
10, bless/buff type 1 [-1]
11, cause affliction [1]
13, heal [-1]
23, buff type 2 [-1]
24, damage x3 vs demon/undead [1]
28, enslave [1]
29, charm [1]
32, damage x3 vs larger
33, damage x2 vs smaller
66, paralysis [1]
67, weakness [1]
72, stream of life [1]
73, damage x2 vs magic being [1]
74, damage (raise as soulless on kill) [1]
96, shatter [1]
97, cause fear type 2 [1]
134, chain lightning [1]
142, salt damage [1]
test 43, edge of field summon
test 99 petrify [1]
test 103 drain life [1]
test 105 disbelieve [1]
test 107 damage demons only [1]
test 128 stun/fascinate [1]
test 129 interrupt damage [1]
124, undocumented [1]
It is one of the following effects: Wrathful Skies, Fire Storm, Acid Storm, Astral Tempest, or Meteor Shower, and:
The caster outnumbers the enemy more than 20 to 1, and there are less than 3 enemy mages
None of the following three conditions are met:
Caster's army size ⇐ enemy army size * 10
Enemy army size is 50+ units
Enemy has greater than two mages
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:
If combat round 2+, this is always 1.
In assassination, this is 2 - round
In other cases, this is (2 - round)*2
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:
If damage x3 vs undead/demon, mult by 3 if victim is demon or undead
If damage x2 vs demon, mult by 2 if victim is demon
If undocumented effect 124, mult by 2 if victim is undead
If salt damage, set damage to 0 if victim has no salt vuln
If x2 vs magic beings or x2 vs magic being unlife damage, mult by 2 if victim magic being
If shatter, set damage to 0 if victim not inanimate
If disbelieve dmg, set damage to 0 if victim not an illusion
If petrification, set damage to 0 if victim is a stone being
If magic duel, set damage to 0 if victim has no astral level
If fear, set damage to 0 if victim's base morale is 20+ or victim is gone berserk
If fatigue damage, divide damage by 2 if victim is 130+ fatigue
If polymorph, set damage to 0 if victim has polymorph immunity or is already the creature type the spell is trying to turn them into
Spec value modifications:
If sacreds only, zero damage if victim is sacred or prophet or god
If the spell is a fire effect, subtract victim's fire res
If the spell is a cold effect, subtract victim's cold res
If the spell is a poison effect, subtract victim's poison res
If the spell is a shock effect, subtract victim's shock res
If the spell doesn't affect mindless and the victim is mindless, set damage to 0
If the spell doesn't affect void sanity and the victim has it, set damage to 0
If the spell affects animals only and the target is not an animal, set damage to 0
If the spell affects demons/undead only and the target isn't, set damage to 0
If the spell doesn't affect undead and the target is, set damage to 0
If the spell doesn't affect demons and the target is, set damage to 0
If the spell affects magic beings only and the target isn't, set damage to 0
If the spell affects air breathers only and the target isn't, set damage to 0
If the spell does fatigue damage and the target is 0 enc, set damage to 0 [THIS ONE MAY BE CONTROVERSIAL]
If the spell affects enemies only and the target is friendly, set damage to 0
If the spell affects friendlies only and the target is hostile, set damage to 0
If the effect is cause affliction:
If the spell sets things on fire and the victim can't be set on fire, set damage to 0
If the spell freezes things and the victim can't be frozen, set damage to 0
If the spell blinds things and the victim has blind fighting, set damage to 0
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:
4 fear
10 buff type 1
11 cause affliction
15 returning
17 temp morale boost
23 buff type 2
27 magic duel
54 polymorph
81 battlefield enchantment
101 age caster
108 banish to other plane
116 swallow if smaller
121 swallow size 1+2 only
133 time stop
500-699 add effect to effect slots
Your damage is considered to be 999. For everything else:
If spell is AN, add 1 to damage.
If spell is AP, add (1 - (victim's prot/2))
Otherwise, add (1 - victim's prot)
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 the spell offers an easy mr check, consider victim's mr as 4 higher.
If the spell does not offer a normal MR check, and (user's pen bonus + 8) ⇐ (victim's MR + 4), multiply damage by 2/3. [shouldn't this be banded like regular MR? This means that easy MR soul slay will be preferred to normal soul slay vs high MR targets…]
If the spell offers a normal MR check, do the first one that applies:
if (mr >= pen bonus + 23), divide damage by 24
if (mr >= pen bonus + 20), divide damage by 12
if (mr >= pen bonus + 17), divide damage by 6
if (mr >= pen bonus + 14), divide damage by 3
if (mr >= pen bonus + 11), divide damage by 2
if (mr >= pen bonus + 8), multiply damage by 2/3
Otherwise, do nothing to damage
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 victim has all the buffs this spell applies already, return 0
If the spell has blessing:
If the spell contains luck, and the victim is neither inanimate nor undead:
If the spell contains +prec:
If the unit's fatigue is 71+, score is 1
If the unit has no non-holy paths or 70+ fatigue, score is 5 * friendly bias * early buff bias
Otherwise, it is 30 * friendly bias * early buff bias
If the spell contains airshield:
If the enemy has 0 units with ranged weapons, the score is simply the friendly bias
If there is a storm, (victim's current HP)/2 * friendly bias * self buff bias * early buff bias
Otherwise, victim's current HP * friendly bias * self buff bias * early buff bias * 3
If the spell contains barkskin and the recipient doesn't have stone or ironskin:
If the victim's chassis base natural protection is less than 8, victim current HP * friendly bias * self buff bias * early buff bias * 2
Otherwise, (victim current HP/10) * friendly bias * self buff bias * early buff bias
If the spell contains stoneskin and the recipient doesn't have ironskin:
If the victim's chassis base natural protection is less than 13, victim current HP * friendly bias * self buff bias * early buff bias * 4
Otherwise, (victim current HP/2) * friendly bias * self buff bias * early buff bias
If the spell contains ironskin:
If the victim's chassis base natural protection is less than 17, victim current HP * friendly bias * self buff bias * early buff bias * 8
Otherwise, (victim current HP) * 2 * friendly bias * self buff bias * early buff bias
If the spell contains regeneration, and the recipient's current regeneration value is less than 100%:
If the spell contains the legions of steel buff, and the recipient has some armor:
If the spell contains the strength buff:
If the spell contains the heat aura buff
If the spell contains piercing resistance, and the unit does not have it (innately or from buff) already:
If the spell contains bludgeon resistance, and the unit does not have it (innately or from buff) already:
If the spell contains slashing resistance, and the unit does not have it (innately or from buff) already:
If the spell confers gone berserk:
If the victim has magic paths, score is friendly bias * -100 [THIS MAKES IT BE TARGETED AS A VERY OFFENSIVE EFFECT]
If the victim has no ranged weapons, score is victim current HP * friendly bias * 3
Otherwise, score is (victim current HP / 5) * friendly bias
If the spell confers pain transfer:
score = min(1, (number of available blood slaves - 5) * 3) * friendly bias * self buff bias * early buff bias
If the caster's skill in the path is less than 2, divide score by 2 (rounded up)
If the spell confers +10 Poison Res, and the recipient has less than 20 PR:
If foul vapors is cast, victim's current HP * friendly bias * self buff bias * early buff bias * 3
If the enemy has any nature mages or creatures with poison aura, victim's current HP * friendly bias * self buff bias * early buff bias
Otherwise, just friendly bias
If the spell confers +5 fire res, and the recipient has less than 20 FR:
If fire storm and/or heat from hell are cast, victim's current HP * friendly bias * self buff bias * early buff bias * 4
If the enemy has any fire mages or creatures with fire shield (innate or buffed), victim's current HP * friendly bias * self buff bias * early buff bias
Otherwise, just friendly bias
If the spell confers +5 shockres, and the recipient has less than 20 SR:
If wrathful skies is cast, victim's current HP * friendly bias * self buff bias * early buff bias * 4
If the enemy has any air mages, victim's current HP * friendly bias * self buff bias * early buff bias
Otherwise, just friendly bias
If the spell confers +5 cold res, and the recipient has less than 20 CR:
If grip of winter is cast, victim's current HP * friendly bias * self buff bias * early buff bias * 4
If the enemy has any water mages or creatures with chill aura (buffed only?), victim's current HP * friendly bias * self buff bias * early buff bias
Otherwise, just friendly bias
If the spell grants chill aura
If all enemies have cold resistance, score = 1
If the spell is self cast and the caster is a communion master, score = 1
score = (victim's current hp * friendly bias)/3, to a minimum of 1
add the cold aura buff to the victim
add the spellscore of "area10 cold dmg 3" to this [this is almost certainly the cause of why things refuse to cast it]
remove the cold aura buff to the victim [this is so the victim gets to see what their cold res would be for the spellscore]
If the spell confers communion master, and the victim is not already a communion master:
If the spell confers communion slave, and the victim is not an innate caster, a com slave already, and there are friendly non-comslave mages in the battle:
If the spell confers flight and the victim isn't flying already:
If the spell confers quickness:
If the spell confers AP weapons, and the recipent has a weapon:
If the spell confers astral weapons, and the recipient has a weapon:
If the spell confers life after death:
If the spell confers holy avenger:
If the spell confers enlarge, and the recipient's size < 6:
If the spell confers sermon of courage +1 mor, and the recipient's morale < 20:
If the spell confers flaming arrows and the recipient has a ranged weapon:
If the spell confers +4 mr:
If the enemy has no mages, score = friendly bias * self buff bias * early buff bias * 2
Otherwise, score = victim's current HP * friendly bias * self buff bias * early buff bias
If the spell confers etherealness and the victim isn't ethereal innately:
If the spell confers protective force and the victim has less than 17 prot force already:
If the spell effect is buffs type 2:
If the victim has all the buffs this spell confers already, return 0.
If the spell confers twist fate:
If the spell confers invuln 25:
If the recipient's prot < 22, score = min(45000, victim current HP * friendly bias * self buff bias * early buff bias * 50)
Otherwise, score = friendly bias
If the spell confers invuln 15 and does not confer invuln 25:
If the recipient's prot < 12, score = min(45000, victim current HP * friendly bias * self buff bias * early buff bias * 50)
Otherwise, score = friendly bias
If the spell confers invuln 15 to wolves only, and neither of the two above invuln effects, and the victim is a wolf:
If the recipient's prot < 13, score = min(45000, victim current HP * friendly bias * self buff bias * early buff bias * 50)
Otherwise, score = friendly bias
If the spell confers power of the spheres:
If the recipient has no non-holy paths, score = 0
Otherwise, score = friendly bias * self buff bias * early buff bias * 25
If the spell confers mossbody:
If the recipient has less than 50 PR, score = victim's current HP * friendly bias * self buff bias * early buff bias * 2
Otherwise, score = victim's current HP * friendly bias * self buff bias * early buff bias * 5
If the spell confers soul vortex:
If the recipient is the caster, and is a communion master, score = 1
TODO: this is complicated but it is looking at positions of units, likely penalised for friendlies and + for enemies?
If the spell confers charge body 20AN:
If the spell confers fire shield and the recipient has no fire shield already:
? if the enemy has both fire mages and fire resistant units, score = friendly bias
? if the enemy has only one of these things, score = current HP * friendly bias * early buff bias
Otherwise:
If the spell confers astral shield:
If the spell confers water shield:
If the spell confers mistform:
If the spell confers swiftness, and the recipient is not immobile:
If the spell confers hell power:
If the spell confers fire power:
If the spell confers water power:
If the spell confers earth power:
If the spell confers reinvigoration and the recipient does not have earth power:
If the recipient has no nonholy paths, score = friendly bias * early buff bias * self buff bias * 3
Otherwise, score = friendly bias * early buff bias * self buff bias * 15
If the spell confers regeneration:
If the spell confers storm power:
If there is no storm, score = 1
Otherwise, score = friendly bias * early buff bias * self buff bias * 20
If the spell confers nature power:
If the spell confers unholy power:
If the spell confers fear:
If the spell confers phoenix pyre:
If the caster is the recipient and they are a communion master, score = 1
Otherwise, score = friendly bias * early buff bias * 150
If the spell confers mirror image:
If the spell confers awakened tattoos and the recipient has tattoos:
If the spell effect is cause affliction:
If the victim has all afflictions caused by this spell, return 0
If the spell causes disease, the victim is not undead, the victim is not a demon, and the victim has less than 100 disease resistance:
If the spell causes curse and the victim is not a blood slave:
If the spell causes plague:
If the spell causes curse of stones and the victim is not a blood slave:
If the spell causes entangle and the victim is not a blood slave:
If the spell causes web:
If the spell causes netting:
If the spell causes rage:
If the spell causes confusion:
If the spell causes decay:
If the spell causes slow:
If the spell causes bleeding:
If the spell causes broken armor:
If the spell causes rusted equipment:
If the spell causes blind:
If the spell causes chest wounds:
If the spell causes limps:
If the spell causes cripple:
If the spell causes earthgrip:
If the spell causes fire bonds:
If the spell causes false fetters:
If the spell causes slime:
If the spell sets things on fire, and the victim can be set on fire:
If the spell freezes things, and the victim can be frozen:
If the spell shrinks victims:
If the spell causes sleep:
For the following effects:
score = strength value * - friendly bias * 10
For unlife damage or unlife damage x2 vs magic beings:
For magic duel:
For drain life:
For fear:
If the victim is already routed, score 0
Otherwise, score = strength value * - friendly bias * 5
For poison HP damage and capped poison damage:
For fatigue damage:
For interrupt damage:
If the victim has no magic skill, score 0 [mundane commanders casting spells via items will not be targeted]
score = (victim's max HP * (strength value + 25) * - friendly bias) / 32
For weakening spells:
For spells that directly add age:
For paralyze damage:
If the victim is already paralyzed for 10+ ticks, OR (strength value/2) is less than paralysis ticks:
otherwise, score = (victim current HP * - friendly bias * strength value)/4
For stun/fascination:
If the victim is stun immune, score 0
If the victim is stunned for 2000-4999 ticks, score = 2
If the victim is stunned for 5000+ ticks, score = 0
Otherwise, score = victim current HP * - friendly bias * 2
For effects 500-599 (capped add unit effect) inclusive:
If the victim does not have the effect already:
If the spell confers damage reversal, score = victim current HP * friendly bias * 15
If the spell confers desiccation, score = victim current HP * - friendly bias * 2
If the spell confers anything else, score = 1
If the victim has the effect already at some magnitude [NOTE: this checks TOTAL magnitude already, not what is in slots, which means that a unit that has 10 FR will refuse to put +10FR into their slots with these spells, despite the fact units will happily use the +5 buff until 20+]:
If the spell is trying to add less magnitude than the effect has already, score = 0
If the spell confers damage reversal, score = victim current HP * friendly bias * 10
If the spell confers desiccation, score = victim current HP * - friendly bias
If the spell confers anything else, score = 1
For effects 600-699 (uncapped add unit effect) inclusive:
If the spell horror marks:
If the spell applies encase in ice, and the target's encase in ice value is less than 100:
score = max(2, victim prot - 17) * victim current HP * - friendly bias
If the victim already has any amount of encase in ice, score = above score / (encase in ice value / 20 + 2)
Any other case scores 0
For stream of life:
For enslave and charm:
For polymorph:
For plane banishment:
If the victim has no void sanity and there is a source of astral fetters on the battlefield, score = 0
Otherwise, score = victim current HP * - friendly bias * 100
For healing spells:
For fatigue removal spells:
For the unused temp morale boost effect:
For returning:
For blink:
For either kind of armour damage spells:
Any other effects score 0
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: