From 2d8ba33e34c0cbab8b7db8bbd972f1b18b28b199 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 2 Apr 2012 22:10:00 +0200 Subject: Lua: Move spell_chance() to C --- src/lua_bind.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/lua_bind.c') 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; -- cgit v1.2.3