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 | 6b85af588b8ef4d219bc011b7c31df07a314ba0c (patch) | |
tree | 8a2d76f7256c412c1e75c812025c8baca9e59a61 /src/lua_bind.c | |
parent | 7121520f1b7e564bd59287a11d4a8f89e999ea82 (diff) |
Lua: Move get_level_device() to C
Diffstat (limited to 'src/lua_bind.c')
-rw-r--r-- | src/lua_bind.c | 34 |
1 files changed, 34 insertions, 0 deletions
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; |