diff options
author | Bardur Arantsson <bardur@scientician.net> | 2015-02-23 09:11:55 +0100 |
---|---|---|
committer | Bardur Arantsson <bardur@scientician.net> | 2015-02-23 09:11:55 +0100 |
commit | 4d799dc22d9a8632f4de31753a12586a8cba67bb (patch) | |
tree | 9cdf84f52eebf2881565050225e09302a1add06d | |
parent | 8a31e6042c46204ef8c21a8e31308887cd3e9ac0 (diff) |
Extract the two branches of get_level() into separate functions
-rw-r--r-- | src/lua_bind.cc | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/src/lua_bind.cc b/src/lua_bind.cc index e4a9bc60..c664e192 100644 --- a/src/lua_bind.cc +++ b/src/lua_bind.cc @@ -76,6 +76,28 @@ static s32b get_level_device(spell_type *spell, s32b max, s32b min) return lvl; } +static s32b get_level_device_1(s32b s, s32b max, s32b min) +{ + // Must be in "device" mode. + assert(get_level_use_stick > -1); + // Delegate + spell_type *spell = spell_at(s); + return get_level_device(spell, max, min); +} + +static s32b get_level_school_1(s32b s, s32b max, s32b min) +{ + // Delegate + s32b level; + bool_ na; + get_level_school(s, max, min, &level, &na); + // Note: It is tempting to add an assertion here for "na == FALSE" here, + // but there are cases where we haven't actually checked if the spell is + // really castable before calling this function (indirectly). Thus we + // MUST NOT assert anything about "na" as the code currently stands. + return level; +} + int get_mana(s32b s) { spell_type *spell = spell_at(s); @@ -161,13 +183,9 @@ s32b get_level(s32b s, s32b max, s32b min) { /** Ahah shall we use Magic device instead ? */ if (get_level_use_stick > -1) { - spell_type *spell = spell_at(s); - return get_level_device(spell, max, min); + return get_level_device_1(s, max, min); } else { - s32b level; - bool_ notused; - get_level_school(s, max, min, &level, ¬used); - return level; + return get_level_school_1(s, max, min); } } |