diff options
author | Neil Moore <neil@s-z.org> | 2013-08-19 16:07:09 -0400 |
---|---|---|
committer | Neil Moore <neil@s-z.org> | 2013-08-19 16:07:09 -0400 |
commit | fc9ecc9c442cacfe3f6e02b5bf5c8d9a349a9029 (patch) | |
tree | 154b574d49a061faa0fa85ae3438b20f4addaf9a /crawl-ref/source/l_you.cc | |
parent | fd4ef7346cba1e68562eca8c8e5a0566f28b0bbf (diff) | |
download | crawl-ref-fc9ecc9c442cacfe3f6e02b5bf5c8d9a349a9029.tar.gz crawl-ref-fc9ecc9c442cacfe3f6e02b5bf5c8d9a349a9029.zip |
New Lua methods you.ability_table(), you.spell_table().
These return a table with letters as keys and spell/ability names as
values. Previously, finding the spell on a given letter required
cross-referencing the results of you.spells() and you.spell_letters().
Now it is as simple as you.spell_table()["a"]
Diffstat (limited to 'crawl-ref/source/l_you.cc')
-rw-r--r-- | crawl-ref/source/l_you.cc | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/crawl-ref/source/l_you.cc b/crawl-ref/source/l_you.cc index 45a896e693..231c903b62 100644 --- a/crawl-ref/source/l_you.cc +++ b/crawl-ref/source/l_you.cc @@ -241,6 +241,27 @@ static int l_you_spell_letters(lua_State *ls) return 1; } +static int l_you_spell_table(lua_State *ls) +{ + lua_newtable(ls); + + char buf[2]; + buf[1] = 0; + + for (int i = 0; i < 52; ++i) + { + buf[0] = index_to_letter(i); + const spell_type spell = get_spell_by_letter(buf[0]); + if (spell == SPELL_NO_SPELL) + continue; + + lua_pushstring(ls, buf); + lua_pushstring(ls, spell_title(spell)); + lua_rawset(ls, -3); + } + return 1; +} + static int l_you_abils(lua_State *ls) { lua_newtable(ls); @@ -271,6 +292,24 @@ static int l_you_abil_letters(lua_State *ls) return 1; } +static int l_you_abil_table(lua_State *ls) +{ + lua_newtable(ls); + + char buf[2]; + buf[1] = 0; + + vector<talent> talents = your_talents(false); + for (int i = 0, size = talents.size(); i < size; ++i) + { + buf[0] = talents[i].hotkey; + lua_pushstring(ls, buf); + lua_pushstring(ls, ability_name(talents[i].which)); + lua_rawset(ls, -3); + } + return 1; +} + static int you_can_consume_corpses(lua_State *ls) { lua_pushboolean(ls, @@ -374,8 +413,10 @@ static const struct luaL_reg you_clib[] = { "time" , you_time }, { "spells" , l_you_spells }, { "spell_letters", l_you_spell_letters }, + { "spell_table" , l_you_spell_table }, { "abilities" , l_you_abils }, { "ability_letters", l_you_abil_letters }, + { "ability_table", l_you_abil_table }, { "name" , you_name }, { "race" , you_race }, { "class" , you_class }, |