diff options
-rw-r--r-- | lib/core/s_aux.lua | 17 | ||||
-rw-r--r-- | lib/mods/theme/core/s_aux.lua | 17 | ||||
-rw-r--r-- | src/cmd6.c | 4 | ||||
-rw-r--r-- | src/externs.h | 1 | ||||
-rw-r--r-- | src/lua_bind.c | 32 | ||||
-rw-r--r-- | src/spells.pkg | 4 |
6 files changed, 39 insertions, 36 deletions
diff --git a/lib/core/s_aux.lua b/lib/core/s_aux.lua index 5e514081..8ae69749 100644 --- a/lib/core/s_aux.lua +++ b/lib/core/s_aux.lua @@ -401,23 +401,6 @@ function spell_in_book(book, spell) return FALSE end --- Returns spell chance of failure for spell -function spell_chance(s) - local chance, s_ptr - - s_ptr = spell(s) - - -- Extract the base spell failure rate - if get_level_use_stick > -1 then - chance = lua_spell_device_chance(s_ptr.fail, get_level(s, 50), s_ptr.skill_level) - else - chance = lua_spell_chance(s_ptr.fail, get_level(s, 50), s_ptr.skill_level, get_mana(s), get_power(s), get_spell_stat(s)) - end - - -- Return the chance - return chance -end - function check_affect(s, name, default) local s_ptr = __tmp_spells[s] local a diff --git a/lib/mods/theme/core/s_aux.lua b/lib/mods/theme/core/s_aux.lua index 5e514081..8ae69749 100644 --- a/lib/mods/theme/core/s_aux.lua +++ b/lib/mods/theme/core/s_aux.lua @@ -401,23 +401,6 @@ function spell_in_book(book, spell) return FALSE end --- Returns spell chance of failure for spell -function spell_chance(s) - local chance, s_ptr - - s_ptr = spell(s) - - -- Extract the base spell failure rate - if get_level_use_stick > -1 then - chance = lua_spell_device_chance(s_ptr.fail, get_level(s, 50), s_ptr.skill_level) - else - chance = lua_spell_chance(s_ptr.fail, get_level(s, 50), s_ptr.skill_level, get_mana(s), get_power(s), get_spell_stat(s)) - end - - -- Return the chance - return chance -end - function check_affect(s, name, default) local s_ptr = __tmp_spells[s] local a @@ -3683,7 +3683,7 @@ void do_cmd_use_staff(void) ident = FALSE; /* get the chance */ - chance = exec_lua(format("return spell_chance(%d)", o_ptr->pval2)); + chance = spell_chance(o_ptr->pval2); /* Extract object flags */ object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); @@ -3877,7 +3877,7 @@ void do_cmd_aim_wand(void) set_stick_mode(o_ptr); /* get the chance */ - chance = exec_lua(format("return spell_chance(%d)", o_ptr->pval2)); + chance = spell_chance(o_ptr->pval2); /* Extract object flags */ object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); diff --git a/src/externs.h b/src/externs.h index 9ac54884..e5d80c19 100644 --- a/src/externs.h +++ b/src/externs.h @@ -1797,6 +1797,7 @@ extern spell_type *grab_spell_type(s16b num); extern school_type *grab_school_type(s16b num); extern s32b lua_get_level(s32b s, s32b lvl, s32b max, s32b min, s32b bonus); extern s32b get_level_device(s32b s, s32b max, s32b min); +extern s32b spell_chance(s32b s); extern s32b lua_spell_chance(s32b chance, int level, int skill_level, int mana, int cur_mana, int stat); extern s32b lua_spell_device_chance(s32b chance, int level, int base_level); diff --git a/src/lua_bind.c b/src/lua_bind.c index 38e334ce..05e1c743 100644 --- a/src/lua_bind.c +++ b/src/lua_bind.c @@ -297,6 +297,38 @@ s32b get_level_device(s32b s, s32b max, s32b min) return lvl; } +static int get_level(s32b s) { + return exec_lua(format("return get_level(%d, 50)", s)); +} + +static int get_mana(s32b s) { + return exec_lua(format("return get_mana(%d)", s)); +} + +static int get_power(s32b s) { + return exec_lua(format("return get_power(%d)", s)); +} + +static int get_spell_stat(s32b s) { + return exec_lua(format("return get_spell_stat(%d)", s)); +} + +/** Returns spell chance of failure for spell */ +s32b spell_chance(s32b s) +{ + int get_level_use_stick = exec_lua("return get_level_use_stick"); + spell_type *s_ptr = &school_spells[s]; + int level = get_level(s); + + /* Extract the base spell failure rate */ + if (get_level_use_stick > -1) { + return lua_spell_device_chance(s_ptr->fail, level, s_ptr->skill_level); + } else { + return lua_spell_chance(s_ptr->fail, level, s_ptr->skill_level, get_mana(s), get_power(s), get_spell_stat(s)); + } +} + + s32b lua_spell_chance(s32b chance, int level, int skill_level, int mana, int cur_mana, int stat) { int minfail; diff --git a/src/spells.pkg b/src/spells.pkg index 9f8ddaaa..2705737b 100644 --- a/src/spells.pkg +++ b/src/spells.pkg @@ -2355,6 +2355,10 @@ extern s32b lua_get_level(s32b s, s32b lvl, s32b max, s32b min, s32b bonus); /** Get level of device */ extern s32b get_level_device(s32b s, s32b max, s32b min); +/** Get change of failure for spell. */ +extern s32b spell_chance(s32b s); + + /** @fn lua_spell_chance(s32b chance, int level, int skill_level, int mana, int cur_mana, int stat) * @dgonly * @brief Get the chance a spell will fail.\n |