Resisting spells

feydras

Prince
Joined
Apr 10, 2006
Messages
398
Location
Seattle
What formula is used to determine when a spell is resisted? I see the modifiers like +40% chance to resist but can't find any mention of the base chance and how or if that is affected by a unit's level of strength. And this time i did do a search of Xienwolf's manual before asking although it is certainly possible i missed the info.

Specifically i'm wondering about Domination. I've seen it work a couple times when paired with Metamagic III (makes spells harder to resist) but it still gets resisted quite easily by any unit worth taking.
 
In GlobalDefinesAlt.xml:
Code:
<Define>
        <DefineName>SPELL_RESIST_CHANCE_BASE</DefineName>
        <iDefineIntVal>20</iDefineIntVal>
    </Define>
    <Define>
        <DefineName>SPELL_RESIST_CHANCE_MAX</DefineName>
        <iDefineIntVal>100</iDefineIntVal>
    </Define>
    <Define>
        <DefineName>SPELL_RESIST_CHANCE_MIN</DefineName>
        <iDefineIntVal>5</iDefineIntVal>
    </Define>


I believe Resistance only applies to spells with <bResistable>1</bResistable>

Spells also have a <iResistModify> tag that can make them easier or harder to resist.

I'm not really sure if strength normally factors in at all, but it is hardcoded into how the domination spell's picks a target.

Edit: looking in the SDK,
Code:
int CvUnit::getResistChance(CvUnit* pCaster, int iSpell)
{
    if (isImmuneToSpell(pCaster, iSpell))
    {
        return 100;
    }
    int iResist = GC.getDefineINT("SPELL_RESIST_CHANCE_BASE");
	iResist += getLevel() * 5;
    iResist += getResist();
    iResist += pCaster->getResistModify();
    iResist += GC.getSpellInfo((SpellTypes)iSpell).getResistModify();
    if (plot()->isCity())
    {
        iResist += plot()->getPlotCity()->getResistMagic();
    }
	if (iResist >= GC.getDefineINT("SPELL_RESIST_CHANCE_MAX"))
	{
		iResist = GC.getDefineINT("SPELL_RESIST_CHANCE_MAX");
	}
	if (iResist <= GC.getDefineINT("SPELL_RESIST_CHANCE_MIN"))
	{
		iResist = GC.getDefineINT("SPELL_RESIST_CHANCE_MIN");
	}
	return iResist;
}
So resistance isn't modified by strength, but it is by level.
 
From the DLL of 031c (shouldn't be different now, I just haven't downloaded the new one yet).

Code:
int CvUnit::getResistChance(CvUnit* pCaster, int iSpell)
{
[COLOR="LightBlue"]    if (isImmuneToSpell(pCaster, iSpell))
    {
        return 100;
    }[/COLOR]
    int iResist = GC.getDefineINT("SPELL_RESIST_CHANCE_BASE");
[COLOR="LightBlue"]    iResist += getLevel() * 5;[/COLOR]
    iResist += getResist();
[COLOR="LightBlue"]    iResist += pCaster->getResistModify();[/COLOR]
    iResist += GC.getSpellInfo((SpellTypes)iSpell).getResistModify();
[COLOR="LightBlue"]    if (plot()->isCity())
    {
        iResist += plot()->getPlotCity()->getResistMagic();
    }[/COLOR]
	if (iResist >= GC.getDefineINT("SPELL_RESIST_CHANCE_MAX"))
	{
		iResist = GC.getDefineINT("SPELL_RESIST_CHANCE_MAX");
	}
[COLOR="LightBlue"]	if (iResist <= GC.getDefineINT("SPELL_RESIST_CHANCE_MIN"))
	{
		iResist = GC.getDefineINT("SPELL_RESIST_CHANCE_MIN");
	}[/COLOR]
	return iResist;
}

So, if the unit is immune to magic, resist chance is 100, no further questions. Otherwise:

  • Base resistance is 20%
    [*] +5 per Level of Target
  • +Modifiers of the Target (Resistance Promotions mostly. Should all be Positive)
    [*]+Modifiers of Caster (All of them should be negatives that I know of. Mostly it is from Channeling, Metamagic and Towers)
  • +any modifier on the spell (so a positive modifier on a spell means easy to resist, a negative means hard to resist)
    [*]+Modifiers from the City (I don't think there are any available from Cities any more, with Ring of Warding having been removed)
  • Checks to ensure that the value is smaller than 100. Sets it to 100 if not.
    [*]Checks to ensure that the value is higher than 5. Sets it to 5 if not.


And that is how it is calculated.
 
Top Bottom