summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2013-03-25 17:28:24 +0100
committerBardur Arantsson <bardur@scientician.net>2013-09-27 14:46:41 +0200
commit8cdd45b0b475e910ebe393bc96e6497b2ffeb292 (patch)
tree2a758ec26e45e02662752eda0ca7b1361c5ff198 /src
parentde312e85022558780a3357a655b9742793b6484f (diff)
Separate spell failure chance calculation for devices/school spells
Diffstat (limited to 'src')
-rw-r--r--src/lua_bind.c107
1 files changed, 60 insertions, 47 deletions
diff --git a/src/lua_bind.c b/src/lua_bind.c
index a3e2b0bb..2e8a7083 100644
--- a/src/lua_bind.c
+++ b/src/lua_bind.c
@@ -101,63 +101,76 @@ int get_mana(s32b s)
return get_level(s, mana_range.max, mana_range.min);
}
-/** Returns spell chance of failure for spell */
-s32b spell_chance(s32b s)
+/** Returns spell change of failure for spell cast from a device */
+static s32b spell_chance_device(s32b s)
{
- spell_type *s_ptr = spell_at(s);
+ spell_type *s_ptr = spell_at(s);
int level = get_level(s, 50, 1);
+ int minfail;
+ s32b chance = spell_type_failure_rate(s_ptr);
- /* Extract the base spell failure rate */
- if (get_level_use_stick > -1)
+ /* Reduce failure rate by "effective" level adjustment */
+ chance -= (level - 1);
+
+ /* Extract the minimum failure rate */
+ minfail = 15 - get_skill_scale(SKILL_DEVICE, 25);
+
+ /* Return the chance */
+ return clamp_failure_chance(chance, minfail);
+}
+
+/** Returns spell chance of failure for a school spell. */
+static s32b spell_chance_school(s32b s)
+{
+ spell_type *s_ptr = spell_at(s);
+ int level = get_level(s, 50, 1);
+ s32b chance = spell_type_failure_rate(s_ptr);
+ int mana = get_mana(s);
+ int cur_mana = get_power(s);
+ int stat = spell_type_casting_stat(s_ptr);
+ int stat_ind = p_ptr->stat_ind[stat];
+ int minfail;
+
+ /* Reduce failure rate by "effective" level adjustment */
+ chance -= 3 * (level - 1);
+
+ /* Reduce failure rate by INT/WIS adjustment */
+ chance -= 3 * (adj_mag_stat[stat_ind] - 1);
+
+ /* Not enough mana to cast */
+ if (chance < 0) chance = 0;
+ if (mana > cur_mana)
+ {
+ chance += 15 * (mana - cur_mana);
+ }
+
+ /* Extract the minimum failure rate */
+ minfail = adj_mag_fail[stat_ind];
+
+ /* Must have Perfect Casting to get below 5% */
+ if (!(has_ability(AB_PERFECT_CASTING)))
{
- int minfail;
- s32b chance = spell_type_failure_rate(s_ptr);
+ if (minfail < 5) minfail = 5;
+ }
- /* Reduce failure rate by "effective" level adjustment */
- chance -= (level - 1);
+ /* Hack -- Priest prayer penalty for "edged" weapons -DGK */
+ if ((forbid_non_blessed()) && (p_ptr->icky_wield)) chance += 25;
- /* Extract the minimum failure rate */
- minfail = 15 - get_skill_scale(SKILL_DEVICE, 25);
+ /* Return the chance */
+ return clamp_failure_chance(chance, minfail);
+}
- /* Return the chance */
- return clamp_failure_chance(chance, minfail);
+/** Returns spell chance of failure for spell */
+s32b spell_chance(s32b s)
+{
+ /* Extract the base spell failure rate */
+ if (get_level_use_stick > -1)
+ {
+ return spell_chance_device(s);
}
else
{
- s32b chance = spell_type_failure_rate(s_ptr);
- int mana = get_mana(s);
- int cur_mana = get_power(s);
- int stat = spell_type_casting_stat(s_ptr);
- int stat_ind = p_ptr->stat_ind[stat];
- int minfail;
-
- /* Reduce failure rate by "effective" level adjustment */
- chance -= 3 * (level - 1);
-
- /* Reduce failure rate by INT/WIS adjustment */
- chance -= 3 * (adj_mag_stat[stat_ind] - 1);
-
- /* Not enough mana to cast */
- if (chance < 0) chance = 0;
- if (mana > cur_mana)
- {
- chance += 15 * (mana - cur_mana);
- }
-
- /* Extract the minimum failure rate */
- minfail = adj_mag_fail[stat_ind];
-
- /* Must have Perfect Casting to get below 5% */
- if (!(has_ability(AB_PERFECT_CASTING)))
- {
- if (minfail < 5) minfail = 5;
- }
-
- /* Hack -- Priest prayer penalty for "edged" weapons -DGK */
- if ((forbid_non_blessed()) && (p_ptr->icky_wield)) chance += 25;
-
- /* Return the chance */
- return clamp_failure_chance(chance, minfail);
+ return spell_chance_school(s);
}
}