diff options
author | Bardur Arantsson <bardur@scientician.net> | 2012-05-30 05:33:44 +0200 |
---|---|---|
committer | Bardur Arantsson <bardur@scientician.net> | 2012-05-30 20:08:05 +0200 |
commit | 1b9ce2b53e26ed2d983efb9da10eb2be89d6d705 (patch) | |
tree | 1e1a6071fdf11515bf9f3e98fc83b7117045a241 /src/lua_bind.c | |
parent | fbc40366c8a50a695fcb913c5f25d717330e9672 (diff) |
Lua: Migrate spell schools to C
Diffstat (limited to 'src/lua_bind.c')
-rw-r--r-- | src/lua_bind.c | 35 |
1 files changed, 8 insertions, 27 deletions
diff --git a/src/lua_bind.c b/src/lua_bind.c index 0c099c00..34a89613 100644 --- a/src/lua_bind.c +++ b/src/lua_bind.c @@ -168,25 +168,17 @@ bool_ get_com_lua(cptr prompt, int *com) return (TRUE); } -/* Spell schools */ -s16b new_school(int i, cptr name, s16b skill) -{ - schools[i].name = string_make(name); - schools[i].skill = skill; - return (i); -} - school_type *grab_school_type(s16b num) { return (&schools[num]); } /* Change this fct if I want to switch to learnable spells */ -s32b lua_get_level(s32b s, s32b lvl, s32b max, s32b min, s32b bonus) +s32b lua_get_level(spell_type *spell, s32b lvl, s32b max, s32b min, s32b bonus) { s32b tmp; - tmp = lvl - ((school_spells[s].skill_level - 1) * (SKILL_STEP / 10)); + tmp = lvl - ((spell->skill_level - 1) * (SKILL_STEP / 10)); if (tmp >= (SKILL_STEP / 10)) /* We require at least one spell level */ tmp += bonus; @@ -209,6 +201,7 @@ 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; + spell_type *spell = spell_at(s); /* No max specified ? assume 50 */ if (max <= 0) { @@ -223,16 +216,16 @@ s32b get_level_device(s32b s, s32b max, s32b min) 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) + if (lvl - ((spell->skill_level + 1) * SKILL_STEP) >= get_level_max_stick * SKILL_STEP) { - lvl = (get_level_max_stick + school_spells[s].skill_level - 1) * SKILL_STEP; + lvl = (get_level_max_stick + spell->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); + lvl = lua_get_level(spell, lvl, max, min, 0); return lvl; } @@ -257,19 +250,6 @@ s32b spell_chance(s32b s) } } -void get_level_school(s32b s, s32b max, s32b min, s32b *level, bool_ *na) -{ - if (level != NULL) - { - *level = exec_lua(format("local lvl, na = get_level_school(%d, %d, %d); return lvl", s, max, min)); - } - - if (na != NULL) - { - *na = exec_lua(format("local lvl, na = get_level_school(%d, %d, %d); return (na == \"n/a\")", s, max, min)); - } -} - s32b get_level(s32b s, s32b max, s32b min) { /** Ahah shall we use Magic device instead ? */ @@ -277,7 +257,8 @@ s32b get_level(s32b s, s32b max, s32b min) return get_level_device(s, max, min); } else { s32b level; - get_level_school(s, max, min, &level, NULL); + bool_ notused; + get_level_school(s, max, min, &level, ¬used); return level; } } |