summaryrefslogtreecommitdiffstats
path: root/crawl-ref
diff options
context:
space:
mode:
authorzelgadis <zelgadis@c06c8d41-db1a-0410-9941-cceddc491573>2008-06-10 03:52:19 +0000
committerzelgadis <zelgadis@c06c8d41-db1a-0410-9941-cceddc491573>2008-06-10 03:52:19 +0000
commit145e46fadae9d99f1a002450fdf4fd9356bfced4 (patch)
tree39d738f59c58ee2764c4fe81749e4d47b4df4af2 /crawl-ref
parent95a217139ca96e4b51cb6a9deed9807fe22fd0d9 (diff)
downloadcrawl-ref-145e46fadae9d99f1a002450fdf4fd9356bfced4.tar.gz
crawl-ref-145e46fadae9d99f1a002450fdf4fd9356bfced4.zip
Added some C lua functions to simplify pickup_butcher_tool.txt. Also,
pickup_butcher_tool.txt now takes claws mutation and whether or not your god likes butchery into account. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@5692 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref')
-rw-r--r--crawl-ref/settings/pickup_butcher_tool.txt56
-rw-r--r--crawl-ref/source/clua.cc31
2 files changed, 51 insertions, 36 deletions
diff --git a/crawl-ref/settings/pickup_butcher_tool.txt b/crawl-ref/settings/pickup_butcher_tool.txt
index 3257d9967d..d6408811d1 100644
--- a/crawl-ref/settings/pickup_butcher_tool.txt
+++ b/crawl-ref/settings/pickup_butcher_tool.txt
@@ -1,47 +1,33 @@
# Pick up a butchering weapon if we don't already have one
-
< do
-local function can_butcher(it)
- if item.name(it):find("distort", 0, true) then
+local function can_butcher(it, name)
+ if not item.can_cut_meat(it) then
return false
end
- local skill = item.weap_skill(it)
- -- have to handle polearms separately, since only some of them can butcher
- if skill == "Polearms" or skill == "Staves" then
- local butcherable_polearms = {
- "scythe", "lajatang", "halberd", "bardiche", "glaive"
- }
- for _, weap in ipairs(butcherable_polearms) do
- if item.name(it):find(weap, 0, true) then return true end
- end
+ if item.cursed(it) then
+ return false
+ end
+ if name:find("distort", 0, true) then
return false
- else
- return skill:find("Blades", 0, true) or skill == "Axes"
end
+ return true
end
-function pickup_butcher(it)
- if item.class(it, true) == "weapon" then
- local need_blade = true
- -- Trolls and Ghouls don't need weapons to butcher things, and Mummies
- -- and Spriggans can't eat chunks. Ideally, we could detect a player
- -- with the claws mutation here too, but that's not currently possible
- if you.race() == "Troll" or
- you.race() == "Ghoul" or
- you.race() == "Mummy" or
- you.race() == "Spriggan" then
- need_blade = false
- else
- for _, inv_it in pairs(item.inventory()) do
- if item.class(inv_it, true) == "weapon" and
- can_butcher(inv_it) then
- need_blade = false
- end
- end
- end
- return need_blade and not item.cursed(it) and can_butcher(it)
- else
+function pickup_butcher(it, name)
+ if you.has_claws() > 0 then
+ return false
+ end
+ if not you.can_consume_corpses() and not you.god_likes_butchery() then
+ return false
+ end
+ if not can_butcher(it, name) then
return false
end
+ for _, inv_it in pairs(item.inventory()) do
+ if can_butcher(inv_it, item.name(inv_it)) then
+ return false
+ end
+ end
+ return true
end
add_autopickup_func(pickup_butcher)
end >
diff --git a/crawl-ref/source/clua.cc b/crawl-ref/source/clua.cc
index 87b4dd3028..41945a89f7 100644
--- a/crawl-ref/source/clua.cc
+++ b/crawl-ref/source/clua.cc
@@ -725,6 +725,10 @@ LUARET1(you_good_god, boolean,
LUARET1(you_evil_god, boolean,
lua_isstring(ls, 1) ? is_evil_god(str_to_god(lua_tostring(ls, 1)))
: is_evil_god(you.religion))
+LUARET1(you_god_likes_butchery, boolean,
+ lua_isstring(ls, 1) ?
+ god_likes_butchery(str_to_god(lua_tostring(ls, 1))) :
+ god_likes_butchery(you.religion))
LUARET2(you_hp, number, you.hp, you.hp_max)
LUARET2(you_mp, number, you.magic_points, you.max_magic_points)
LUARET1(you_hunger, string, hunger_level())
@@ -761,7 +765,7 @@ LUARET1(you_see_grid, boolean,
LUARET1(you_see_grid_no_trans, boolean,
see_grid_no_trans(luaL_checkint(ls, 1), luaL_checkint(ls, 2)))
LUARET1(you_can_smell, boolean, player_can_smell())
-
+LUARET1(you_has_claws, number, you.has_claws(false))
void lua_push_floor_items(lua_State *ls);
static int you_floor_items(lua_State *ls)
@@ -799,6 +803,15 @@ static int l_you_abils(lua_State *ls)
return (1);
}
+static int you_can_consume_corpses(lua_State *ls)
+{
+ lua_pushboolean(ls,
+ can_ingest(OBJ_FOOD, FOOD_CHUNK, true, false, false)
+ || can_ingest(OBJ_CORPSES, CORPSE_BODY, true, false, false)
+ );
+ return (1);
+}
+
static const struct luaL_reg you_lib[] =
{
{ "turn_is_over", you_turn_is_over },
@@ -834,6 +847,9 @@ static const struct luaL_reg you_lib[] =
{ "flying", you_flying },
{ "transform", you_transform },
+ { "god_likes_butchery", you_god_likes_butchery },
+ { "can_consume_corpses", you_can_consume_corpses },
+
{ "stop_activity", you_stop_activity },
{ "floor_items", you_floor_items },
@@ -846,6 +862,7 @@ static const struct luaL_reg you_lib[] =
{ "see_grid", you_see_grid },
{ "see_grid_no_trans", you_see_grid_no_trans },
{ "can_smell", you_can_smell },
+ { "has_claws", you_has_claws },
{ NULL, NULL },
};
@@ -1454,6 +1471,17 @@ static int l_item_dropped(lua_State *ls)
return (1);
}
+static int l_item_can_cut_meat(lua_State *ls)
+{
+ LUA_ITEM(item, 1);
+ if (!item || !is_valid_item(*item))
+ return (0);
+
+ lua_pushboolean(ls, can_cut_meat(*item));
+
+ return (1);
+}
+
static int l_item_artefact(lua_State *ls)
{
LUA_ITEM(item, 1);
@@ -1518,6 +1546,7 @@ static const struct luaL_reg item_lib[] =
{ "equip_type", l_item_equip_type },
{ "weap_skill", l_item_weap_skill },
{ "dropped", l_item_dropped },
+ { "can_cut_meat", l_item_can_cut_meat },
{ NULL, NULL },
};