diff options
author | Bardur Arantsson <bardur@scientician.net> | 2012-04-02 22:10:00 +0200 |
---|---|---|
committer | Bardur Arantsson <bardur@scientician.net> | 2012-04-07 15:28:25 +0200 |
commit | a77005060dac93cfdd5cdfdf7dc849e0f5207f60 (patch) | |
tree | 50fcc8d4f1ad5120547113f248e2ece67fc7dd5c | |
parent | 2d8ba33e34c0cbab8b7db8bbd972f1b18b28b199 (diff) |
Lua: Move get_level_{use,max}_stick bits to C
-rw-r--r-- | lib/core/s_aux.lua | 26 | ||||
-rw-r--r-- | lib/mods/theme/core/s_aux.lua | 26 | ||||
-rw-r--r-- | src/cmd6.c | 7 | ||||
-rw-r--r-- | src/externs.h | 5 | ||||
-rw-r--r-- | src/lua_bind.c | 20 | ||||
-rw-r--r-- | src/spells.pkg | 3 | ||||
-rw-r--r-- | src/util.c | 13 | ||||
-rw-r--r-- | src/util.pkg | 15 | ||||
-rw-r--r-- | src/variable.c | 2 |
9 files changed, 32 insertions, 85 deletions
diff --git a/lib/core/s_aux.lua b/lib/core/s_aux.lua index 8ae69749..29b22fd7 100644 --- a/lib/core/s_aux.lua +++ b/lib/core/s_aux.lua @@ -201,22 +201,10 @@ function get_level_school(s, max, min) end -- The real get_level, works for schooled magic and for innate powers -get_level_use_stick = -1 -get_level_max_stick = -1 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) - return lvl - end - else - return get_level_power(s, max, min) - end + if not max then max = 50 end + if not min then min = 1 end + return %get_level(s, max, min) end -- Can we cast the spell ? @@ -249,14 +237,6 @@ function get_power_name(s) end end --- Get the level of a power -function get_level_power(s, max, min) - if not max then max = 50 end - if not min then min = 1 end - - return value_scale(s.get_current_level(), 50, max, min) -end - -- Changes the amount of power(mana, piety, whatever) for the spell function adjust_power(s, x) if check_affect(s, "piety", FALSE) then diff --git a/lib/mods/theme/core/s_aux.lua b/lib/mods/theme/core/s_aux.lua index 8ae69749..29b22fd7 100644 --- a/lib/mods/theme/core/s_aux.lua +++ b/lib/mods/theme/core/s_aux.lua @@ -201,22 +201,10 @@ function get_level_school(s, max, min) end -- The real get_level, works for schooled magic and for innate powers -get_level_use_stick = -1 -get_level_max_stick = -1 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) - return lvl - end - else - return get_level_power(s, max, min) - end + if not max then max = 50 end + if not min then min = 1 end + return %get_level(s, max, min) end -- Can we cast the spell ? @@ -249,14 +237,6 @@ function get_power_name(s) end end --- Get the level of a power -function get_level_power(s, max, min) - if not max then max = 50 end - if not min then min = 1 end - - return value_scale(s.get_current_level(), 50, max, min) -end - -- Changes the amount of power(mana, piety, whatever) for the spell function adjust_power(s, x) if check_affect(s, "piety", FALSE) then @@ -3616,12 +3616,15 @@ void set_stick_mode(object_type *o_ptr) s32b bonus = o_ptr->pval3 & 0xFFFF; s32b max = o_ptr->pval3 >> 16; - exec_lua(format("get_level_use_stick = %d; get_level_max_stick = %d", bonus, max)); + get_level_use_stick = bonus; + get_level_max_stick = max; } + /* Remove 'stick mode' */ void unset_stick_mode() { - exec_lua("get_level_use_stick = -1; get_level_max_stick = -1"); + get_level_use_stick = -1; + get_level_max_stick = -1; } diff --git a/src/externs.h b/src/externs.h index e5d80c19..dd305c07 100644 --- a/src/externs.h +++ b/src/externs.h @@ -1431,7 +1431,6 @@ extern s32b rescale(s32b x, s32b max, s32b new_max); extern bool_ input_box(cptr text, int y, int x, char *buf, int max); extern void draw_box(int y, int x, int h, int w); extern void display_list(int y, int x, int h, int w, cptr title, cptr *list, int max, int begin, int sel, byte sel_color); -extern s32b value_scale(int value, int vmax, int max, int min); extern int ask_menu(cptr ask, char **items, int max); extern cptr get_player_race_name(int pr, int ps); extern cptr get_month_name(int month, bool_ full, bool_ compact); @@ -1798,9 +1797,13 @@ 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 get_level(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); +extern s32b get_level_max_stick; +extern s32b get_level_use_stick; + extern cave_type *lua_get_cave(int y, int x); extern void set_target(int y, int x); extern void get_target(int dir, int *y, int *x); diff --git a/src/lua_bind.c b/src/lua_bind.c index 05e1c743..82b802f2 100644 --- a/src/lua_bind.c +++ b/src/lua_bind.c @@ -267,8 +267,6 @@ s32b lua_get_level(s32b s, s32b lvl, s32b max, s32b min, s32b bonus) 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) { @@ -297,10 +295,6 @@ 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)); } @@ -316,9 +310,8 @@ static int get_spell_stat(s32b 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); + int level = get_level(s, 50, 1); /* Extract the base spell failure rate */ if (get_level_use_stick > -1) { @@ -328,6 +321,17 @@ s32b spell_chance(s32b s) } } +s32b get_level(s32b s, s32b max, s32b min) +{ + /** Ahah shall we use Magic device instead ? */ + if (get_level_use_stick > -1) { + return get_level_device(s, max, min); + } else { + int level = exec_lua(format("local lvl, na = get_level_school(%d, %d, %d); return lvl", s, max, min)); + return level; + } +} + s32b lua_spell_chance(s32b chance, int level, int skill_level, int mana, int cur_mana, int stat) { diff --git a/src/spells.pkg b/src/spells.pkg index 2705737b..cbbc2dc5 100644 --- a/src/spells.pkg +++ b/src/spells.pkg @@ -2358,6 +2358,9 @@ extern s32b get_level_device(s32b s, s32b max, s32b min); /** Get change of failure for spell. */ extern s32b spell_chance(s32b s); +/** Get level of spell */ +extern s32b get_level(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 @@ -4318,19 +4318,6 @@ bool_ prefix(cptr s, cptr t) } /* - * Rescale a value - */ -s32b value_scale(int value, int vmax, int max, int min) -{ - s32b full_max = max - min; - - value = (value * full_max) / vmax; - value += min; - - return value; -} - -/* * Displays a box */ void draw_box(int y, int x, int h, int w) diff --git a/src/util.pkg b/src/util.pkg index d13f74e6..183a28f2 100644 --- a/src/util.pkg +++ b/src/util.pkg @@ -1499,21 +1499,6 @@ extern cptr get_player_race_name(int pr, int ps); */ extern void quit(cptr str); -/** @fn value_scale(int value, int vmax, int max, int min) - * @brief Rescale a value - * @param value Number \n the original value - * @brief Original value - * @param vmax Number \n the maximum the original value can be - * @brief Original maximum - * @param max Number \n the maximum new value - * @brief New maximum - * @param min Number \n the minimum new value - * @brief New minimum - * @return Number \n The rescaled value - * @note (see file util.c) - */ -extern s32b value_scale(int value, int vmax, int max, int min); - /* * compass, approximate_distance */ diff --git a/src/variable.c b/src/variable.c index c6a23758..9ed084b4 100644 --- a/src/variable.c +++ b/src/variable.c @@ -1170,6 +1170,8 @@ bool_ easy_open = TRUE; bool_ easy_disarm = TRUE; bool_ easy_tunnel = FALSE; +s32b get_level_max_stick = -1; +s32b get_level_use_stick = -1; /* * Maximum size of the wilderness map |