diff options
-rw-r--r-- | lib/core/s_aux.lua | 31 | ||||
-rw-r--r-- | lib/mods/theme/core/s_aux.lua | 31 | ||||
-rw-r--r-- | src/externs.h | 1 | ||||
-rw-r--r-- | src/lua_bind.c | 34 | ||||
-rw-r--r-- | src/spells.pkg | 3 |
5 files changed, 42 insertions, 58 deletions
diff --git a/lib/core/s_aux.lua b/lib/core/s_aux.lua index ec609b04..5e514081 100644 --- a/lib/core/s_aux.lua +++ b/lib/core/s_aux.lua @@ -200,35 +200,6 @@ function get_level_school(s, max, min) return lvl, nil end --- This is the function to use when casting through a stick -function get_level_device(s, max, min) - local lvl - - -- No max specified ? assume 50 - if not max then - max = 50 - end - - lvl = s_info[SKILL_DEVICE + 1].value - lvl = lvl + (get_level_use_stick * SKILL_STEP) - - -- Sticks are limited - if lvl - ((spell(s).skill_level + 1) * SKILL_STEP) >= get_level_max_stick * SKILL_STEP then - lvl = (get_level_max_stick + spell(s).skill_level - 1) * SKILL_STEP - end - - -- / 10 because otherwise we can overflow a s32b and we can use a u32b because the value can be negative - -- The loss of information should be negligible since 1 skill = 1000 internally - lvl = lvl / 10 - if not min then - lvl = lua_get_level(s, lvl, max, 1, 0) - else - lvl = lua_get_level(s, lvl, max, min, 0) - end - - return lvl -end - -- The real get_level, works for schooled magic and for innate powers get_level_use_stick = -1 get_level_max_stick = -1 @@ -236,6 +207,8 @@ function get_level(s, max, min) if type(s) == "number" then -- Ahah shall we use Magic device instead ? if get_level_use_stick > -1 then + if not max then max = 50 end + if not min then min = 1 end return get_level_device(s, max, min) else local lvl, na = get_level_school(s, max, min) diff --git a/lib/mods/theme/core/s_aux.lua b/lib/mods/theme/core/s_aux.lua index ec609b04..5e514081 100644 --- a/lib/mods/theme/core/s_aux.lua +++ b/lib/mods/theme/core/s_aux.lua @@ -200,35 +200,6 @@ function get_level_school(s, max, min) return lvl, nil end --- This is the function to use when casting through a stick -function get_level_device(s, max, min) - local lvl - - -- No max specified ? assume 50 - if not max then - max = 50 - end - - lvl = s_info[SKILL_DEVICE + 1].value - lvl = lvl + (get_level_use_stick * SKILL_STEP) - - -- Sticks are limited - if lvl - ((spell(s).skill_level + 1) * SKILL_STEP) >= get_level_max_stick * SKILL_STEP then - lvl = (get_level_max_stick + spell(s).skill_level - 1) * SKILL_STEP - end - - -- / 10 because otherwise we can overflow a s32b and we can use a u32b because the value can be negative - -- The loss of information should be negligible since 1 skill = 1000 internally - lvl = lvl / 10 - if not min then - lvl = lua_get_level(s, lvl, max, 1, 0) - else - lvl = lua_get_level(s, lvl, max, min, 0) - end - - return lvl -end - -- The real get_level, works for schooled magic and for innate powers get_level_use_stick = -1 get_level_max_stick = -1 @@ -236,6 +207,8 @@ function get_level(s, max, min) if type(s) == "number" then -- Ahah shall we use Magic device instead ? if get_level_use_stick > -1 then + if not max then max = 50 end + if not min then min = 1 end return get_level_device(s, max, min) else local lvl, na = get_level_school(s, max, min) diff --git a/src/externs.h b/src/externs.h index 0475a2b9..9ac54884 100644 --- a/src/externs.h +++ b/src/externs.h @@ -1796,6 +1796,7 @@ extern s16b new_spell(int i, cptr name); 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 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 67b75ee6..38e334ce 100644 --- a/src/lua_bind.c +++ b/src/lua_bind.c @@ -263,6 +263,40 @@ s32b lua_get_level(s32b s, s32b lvl, s32b max, s32b min, s32b bonus) return lvl; } +/** This is the function to use when casting through a stick */ +s32b get_level_device(s32b s, s32b max, s32b min) +{ + int lvl; + int get_level_use_stick = exec_lua("return get_level_use_stick"); + int get_level_max_stick = exec_lua("return get_level_max_stick"); + + /* No max specified ? assume 50 */ + if (max <= 0) { + max = 50; + } + /* No min specified ? */ + if (min <= 0) { + min = 1; + } + + lvl = s_info[SKILL_DEVICE].value; + lvl = lvl + (get_level_use_stick * SKILL_STEP); + + /* Sticks are limited */ + if (lvl - ((school_spells[s].skill_level + 1) * SKILL_STEP) >= get_level_max_stick * SKILL_STEP) + { + lvl = (get_level_max_stick + school_spells[s].skill_level - 1) * SKILL_STEP; + } + + /* / 10 because otherwise we can overflow a s32b and we can use a u32b because the value can be negative + -- The loss of information should be negligible since 1 skill = 1000 internally + */ + lvl = lvl / 10; + lvl = lua_get_level(s, lvl, max, min, 0); + + return lvl; +} + 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 e785de0d..9f8ddaaa 100644 --- a/src/spells.pkg +++ b/src/spells.pkg @@ -2352,6 +2352,9 @@ extern school_type *grab_school_type @ school(s16b num); */ 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); + /** @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 |