diff options
author | Ryan Riegel <rriegs@gmail.com> | 2011-05-13 18:18:33 -0400 |
---|---|---|
committer | Jude Brown <bookofjude@users.sourceforge.net> | 2011-08-03 20:32:41 +1000 |
commit | 4cc71b6cb0a60b39c938dffd5390925da03930b3 (patch) | |
tree | 5d1e82124a0d51fa6b22b0ef61c6bcebc00bd596 /crawl-ref/source/l_item.cc | |
parent | 380cb09ff0b716c97f064a4740248ceaf02698b6 (diff) | |
download | crawl-ref-4cc71b6cb0a60b39c938dffd5390925da03930b3.tar.gz crawl-ref-4cc71b6cb0a60b39c938dffd5390925da03930b3.zip |
Several user-callable Lua functions. (#3967)
Added several Lua-callable functions for enhanced reasoning about items,
monsters, and player state.
Signed-off-by: Jude Brown <bookofjude@users.sourceforge.net>
Diffstat (limited to 'crawl-ref/source/l_item.cc')
-rw-r--r-- | crawl-ref/source/l_item.cc | 53 |
1 files changed, 52 insertions, 1 deletions
diff --git a/crawl-ref/source/l_item.cc b/crawl-ref/source/l_item.cc index a4b4925b7c..b6f02654e0 100644 --- a/crawl-ref/source/l_item.cc +++ b/crawl-ref/source/l_item.cc @@ -15,6 +15,7 @@ #include "command.h" #include "env.h" #include "enum.h" +#include "food.h" #include "invent.h" #include "item_use.h" #include "itemprop.h" @@ -283,8 +284,10 @@ static const char *amulet_types[] = "resist mutation" }; -IDEF(subtype) +static int l_item_do_subtype (lua_State *ls) { + UDATA_ITEM(item); + if (item) { const char *s = NULL; @@ -343,6 +346,8 @@ IDEF(subtype) return (2); } +IDEFN(subtype, do_subtype); + IDEF(cursed) { bool cursed = item && item_ident(*item, ISFLAG_KNOW_CURSE) @@ -351,6 +356,13 @@ IDEF(cursed) return (1); } +IDEF(tried) +{ + bool tried = item && item_type_tried(*item); + lua_pushboolean(ls, tried); + return (1); +} + IDEF(worn) { int worn = get_equip_slot(item); @@ -488,6 +500,16 @@ IDEF(is_ranged) return (1); } +IDEF(is_throwable) +{ + if (!item || !item->defined()) + return (0); + + lua_pushboolean(ls, is_throwable(&you, *item)); + + return (1); +} + IDEF(dropped) { if (!item || !item->defined()) @@ -508,6 +530,16 @@ IDEF(can_cut_meat) return (1); } +IDEF(is_bad_food) +{ + if (!item || !item->defined()) + return (0); + + lua_pushboolean(ls, is_bad_food(*item)); + + return (1); +} + IDEF(artefact) { if (!item || !item->defined()) @@ -897,6 +929,21 @@ static int l_item_equipped_at(lua_State *ls) return (1); } +static int l_item_fired_item(lua_State *ls) +{ + int q = you.m_quiver->get_fire_item(); + + if (q < 0 || q >= ENDOFPACK) + return (0); + + if (q != -1 && !fire_warn_if_impossible(true)) + clua_push_item(ls, &you.inv[q]); + else + lua_pushnil(ls); + + return (1); +} + static int l_item_inslot(lua_State *ls) { int index = luaL_checkint(ls, 1); @@ -921,6 +968,7 @@ static ItemAccessor item_attrs[] = { "class", l_item_class }, { "subtype", l_item_subtype }, { "cursed", l_item_cursed }, + { "tried", l_item_tried }, { "worn", l_item_worn }, { "name", l_item_name }, { "name_coloured", l_item_name_coloured }, @@ -936,8 +984,10 @@ static ItemAccessor item_attrs[] = { "equip_type", l_item_equip_type }, { "weap_skill", l_item_weap_skill }, { "is_ranged", l_item_is_ranged }, + { "is_throwable", l_item_is_throwable }, { "dropped", l_item_dropped }, { "can_cut_meat", l_item_can_cut_meat }, + { "is_bad_food", l_item_is_bad_food }, { "pluses", l_item_pluses }, { "destroy", l_item_destroy }, { "dec_quantity", l_item_dec_quantity }, @@ -975,6 +1025,7 @@ static const struct luaL_reg item_lib[] = { "swap_slots", l_item_swap_slots }, { "pickup", l_item_pickup }, { "equipped_at", l_item_equipped_at }, + { "fired_item", l_item_fired_item }, { "inslot", l_item_inslot }, { NULL, NULL }, }; |