summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorj-p-e-g <j-p-e-g@c06c8d41-db1a-0410-9941-cceddc491573>2008-06-10 08:15:13 +0000
committerj-p-e-g <j-p-e-g@c06c8d41-db1a-0410-9941-cceddc491573>2008-06-10 08:15:13 +0000
commitba35a3c7bbee2e937f3091002803476340d18787 (patch)
treee0fb3bb7ac545c5bad5730755a0589dd109ec0b7
parentaa3717c904d5d25c9f58f5d17e66379966f00a8f (diff)
downloadcrawl-ref-ba35a3c7bbee2e937f3091002803476340d18787.tar.gz
crawl-ref-ba35a3c7bbee2e937f3091002803476340d18787.zip
Integrate recent changes to the butchering function, and add commenting.
Sorry about that, guys! git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@5699 c06c8d41-db1a-0410-9941-cceddc491573
-rw-r--r--crawl-ref/source/dat/lua/pickup.lua78
1 files changed, 33 insertions, 45 deletions
diff --git a/crawl-ref/source/dat/lua/pickup.lua b/crawl-ref/source/dat/lua/pickup.lua
index e1306f1b83..a07f82e21c 100644
--- a/crawl-ref/source/dat/lua/pickup.lua
+++ b/crawl-ref/source/dat/lua/pickup.lua
@@ -1,65 +1,53 @@
---------------------------------------------------------------------------
--- eat.lua:
+-- pickup.lua:
-- Pick up a butchering weapon if we don't already have one.
--- This requires ) to be in the autopickup option line.
--
-- To use this, add this line to your init.txt:
-- lua_file = lua/pickup.lua
---------------------------------------------------------------------------
-function can_butcher(it)
- if item.name(it):find("distort", 0, true) then
+local function can_butcher(it, name)
+ -- Item can't be used to cut meat.
+ 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"
- }
+ -- Don't make the user wield a known cursed weapon.
+ if item.cursed(it) then
+ return false
+ end
- for _, weap in ipairs(butcherable_polearms) do
- if string.find( item.name(it, "a"), weap ) then
- return true
- end
- end
+ -- Nor a known distortion weapon.
+ if name:find("distort", 0, true) then
return false
- else
- return string.find( skill, "Blades" ) or skill == "Axes"
end
+
+ -- Else we're good.
+ return true
end
-function ch_autopickup(it)
- if item.class(it, true) == "weapon" then
+function pickup_butcher(it, name)
+ -- If you can butcher with your claws you don't need a butchering tool.
+ if you.has_claws() > 0 then
+ return false
+ end
- -- 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
- return false
- end
+ -- Same if you don't ever need to butcher corpses.
+ if not you.can_consume_corpses() and not you.god_likes_butchery() then
+ return false
+ end
- -- The item is not a good butchering tool, either.
- if item.cursed(it) or not can_butcher(it) then
- return false
- end
+ -- Can this item even be used for butchering?
+ if not can_butcher(it, name) then
+ return false
+ end
- -- Check the inventory for butchering tools.
- local inv = item.inventory()
- for _, inv_it in ipairs(inv) do
- if item.class(inv_it, true) == "weapon"
- and can_butcher(inv_it)
- and not item.cursed(inv_it) then
- return false
- end
+ -- Do we already have a butchering tool?
+ for _, inv_it in pairs(item.inventory()) do
+ if can_butcher(inv_it, item.name(inv_it)) then
+ return false
end
end
-
- -- If we got here, we found no butchering tool in the inventory
- -- AND this weapon is a good candidate tool for a butchering tool.
- -- Ergo: pick it up.
return true
-end \ No newline at end of file
+ end
+
+add_autopickup_func(pickup_butcher) \ No newline at end of file