Skip to content
Browse files

check_resistance: split out magic resistance handling

... for readability and cleaner further changes
  • Loading branch information...
1 parent b2f4814 commit f5082c0d4b0e81d14e35eec4c9470fa2a869423d @lynxlynxlynx lynxlynxlynx committed Jun 20, 2014
Showing with 47 additions and 37 deletions.
  1. +47 −37 gemrb/core/EffectQueue.cpp
View
84 gemrb/core/EffectQueue.cpp
@@ -996,6 +996,48 @@ static int check_type(Actor* actor, Effect* fx)
return 1;
}
+// pure magic resistance
+static inline int check_magic_res(Actor *actor, Effect *fx, Actor *caster)
+{
+ //don't resist self
+ bool selective_mr = core->HasFeature(GF_SELECTIVE_MAGIC_RES);
+ if (fx->CasterID == actor->GetGlobalID()) {
+ if (selective_mr) {
+ return 0;
+ }
+ }
+
+ //magic immunity
+ ieDword val = actor->GetStat(IE_RESISTMAGIC);
+ bool resisted = false;
+
+ if (iwd2fx) {
+ // 3ed style check
+ // TODO: check if luck really affects it (i doubt it does)
+ int roll = actor->LuckyRoll(1, 20, 0);
+ ieDword check = fx->CasterLevel + roll;
+ int penetration = 0;
+ // +2/+4 level bonus from the (greater) spell penetration feat
+ if (caster && caster->HasFeat(FEAT_SPELL_PENETRATION)) {
+ penetration += 2 * caster->GetStat(IE_FEAT_SPELL_PENETRATION);
+ }
+ check += penetration;
+ resisted = (signed) check < (signed) val;
+ // ~Spell Resistance check (Spell resistance:) %d vs. (d20 + caster level + spell resistance mod) = %d + %d + %d.~
+ displaymsg->DisplayRollStringName(39673, DMC_LIGHTGREY, actor, val, roll, fx->CasterLevel, penetration);
+ } else {
+ // 2.5 style check
+ resisted = (signed) fx->random_value < (signed) val;
+ }
+ if (resisted) {
+ // we take care of irresistible spells a few checks above, so selective mr has no impact here anymore
+ displaymsg->DisplayConstantStringName(STR_MAGIC_RESISTED, DMC_WHITE, actor);
+ Log(MESSAGE, "EffectQueue", "effect resisted: %s", (char*) Opcodes[fx->Opcode].Name);
+ return 1;
+ }
+ return 2;
+}
+
//check resistances, saving throws
static bool check_resistance(Actor* actor, Effect* fx)
{
@@ -1035,45 +1077,13 @@ static bool check_resistance(Actor* actor, Effect* fx)
return false;
}
- if (pstflags && (actor->GetSafeStat(IE_STATE_ID) & (STATE_ANTIMAGIC) ) ) {
- return false;
- }
-
- //don't resist self
- bool selective_mr = core->HasFeature(GF_SELECTIVE_MAGIC_RES);
- if (fx->CasterID == actor->GetGlobalID()) {
- if (selective_mr) {
- return false;
- }
+ int magic = check_magic_res(actor, fx, caster);
+ if (magic < 2) {
+ return magic;
}
- //magic immunity
- ieDword val = actor->GetStat(IE_RESISTMAGIC);
- bool resisted = false;
-
- if (iwd2fx) {
- // 3ed style check
- // TODO: check if luck really affects it (i doubt it does)
- int roll = actor->LuckyRoll(1, 20, 0);
- ieDword check = fx->CasterLevel + roll;
- int penetration = 0;
- // +2/+4 level bonus from the (greater) spell penetration feat
- if (caster && caster->HasFeat(FEAT_SPELL_PENETRATION)) {
- penetration += 2 * caster->GetStat(IE_FEAT_SPELL_PENETRATION);
- }
- check += penetration;
- resisted = (signed) check < (signed) val;
- // ~Spell Resistance check (Spell resistance:) %d vs. (d20 + caster level + spell resistance mod) = %d + %d + %d.~
- displaymsg->DisplayRollStringName(39673, DMC_LIGHTGREY, actor, val, roll, fx->CasterLevel, penetration);
- } else {
- // 2.5 style check
- resisted = (signed) fx->random_value < (signed) val;
- }
- if (resisted) {
- // we take care of irresistible spells a few checks above, so selective mr has no impact here anymore
- displaymsg->DisplayConstantStringName(STR_MAGIC_RESISTED, DMC_WHITE, actor);
- Log(MESSAGE, "EffectQueue", "effect resisted: %s", (char*) Opcodes[fx->Opcode].Name);
- return true;
+ if (pstflags && (actor->GetSafeStat(IE_STATE_ID) & (STATE_ANTIMAGIC) ) ) {
+ return false;
}
//saving throws, bonus can be improved by school specific bonus

0 comments on commit f5082c0

Please sign in to comment.
Something went wrong with that request. Please try again.