summaryrefslogtreecommitdiff
path: root/src/lua_bind.c
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2012-04-02 22:10:00 +0200
committerBardur Arantsson <bardur@scientician.net>2012-04-07 15:28:25 +0200
commit2d8ba33e34c0cbab8b7db8bbd972f1b18b28b199 (patch)
tree3eaf296530d4776da4fd21e86ff85b6aab7d4432 /src/lua_bind.c
parent6b85af588b8ef4d219bc011b7c31df07a314ba0c (diff)
Lua: Move spell_chance() to C
Diffstat (limited to 'src/lua_bind.c')
-rw-r--r--src/lua_bind.c32
1 files changed, 32 insertions, 0 deletions
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;