summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/l_item.cc
diff options
context:
space:
mode:
authorJude Brown <bookofjude@users.sourceforge.net>2009-12-28 18:05:19 +1000
committerJude Brown <bookofjude@users.sourceforge.net>2009-12-28 20:20:40 +1000
commit679e8fa7154cce598b7fe4946f1c7f7bbe0f72c9 (patch)
treed186cfdd4c141d9807465e234a06fbf1c0d18aff /crawl-ref/source/l_item.cc
parente4e726475b5ffaafebe48a0eaf25991a2632ed11 (diff)
downloadcrawl-ref-679e8fa7154cce598b7fe4946f1c7f7bbe0f72c9.tar.gz
crawl-ref-679e8fa7154cce598b7fe4946f1c7f7bbe0f72c9.zip
Item quantity adjustment wrappers for dLua.
Diffstat (limited to 'crawl-ref/source/l_item.cc')
-rw-r--r--crawl-ref/source/l_item.cc49
1 files changed, 49 insertions, 0 deletions
diff --git a/crawl-ref/source/l_item.cc b/crawl-ref/source/l_item.cc
index 80bbc88df9..e8dc23a2b1 100644
--- a/crawl-ref/source/l_item.cc
+++ b/crawl-ref/source/l_item.cc
@@ -686,6 +686,53 @@ static int l_item_do_destroy(lua_State *ls)
return (1);
}
+static int l_item_do_dec_quantity(lua_State *ls)
+{
+ ASSERT_DLUA;
+
+ LUA_ITEM(item, 1);
+ if (!item || !item->is_valid())
+ {
+ lua_pushboolean(ls, false);
+ return (1);
+ }
+
+ // The quantity to reduce by.
+ int quantity = luaL_checkint(ls, 2);
+
+ bool destroyed = false;
+
+ if (in_inventory(*item))
+ destroyed = dec_inv_item_quantity(item->link, quantity);
+ else
+ destroyed = dec_mitm_item_quantity(item->index(), quantity);
+
+ lua_pushboolean(ls, destroyed);
+ return (1);
+}
+
+static int l_item_do_inc_quantity(lua_State *ls)
+{
+ ASSERT_DLUA;
+
+ LUA_ITEM(item, 1);
+ if (!item || !item->is_valid())
+ {
+ lua_pushboolean(ls, false);
+ return (1);
+ }
+
+ // The quantity to increase by.
+ int quantity = luaL_checkint(ls, 2);
+
+ if (in_inventory(*item))
+ inc_inv_item_quantity(item->link, quantity);
+ else
+ inc_mitm_item_quantity(item->index(), quantity);
+
+ return (0);
+}
+
static const struct luaL_reg item_lib[] =
{
{ "artefact", l_item_artefact },
@@ -717,6 +764,8 @@ static const struct luaL_reg item_lib[] =
{ "dropped", l_item_dropped },
{ "can_cut_meat", l_item_can_cut_meat },
{ "destroy", l_item_do_destroy },
+ { "dec_quantity", l_item_do_dec_quantity },
+ { "inc_quantity", l_item_do_inc_quantity },
{ NULL, NULL },
};