summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/dat/lua
diff options
context:
space:
mode:
authorj-p-e-g <j-p-e-g@c06c8d41-db1a-0410-9941-cceddc491573>2008-06-10 07:41:27 +0000
committerj-p-e-g <j-p-e-g@c06c8d41-db1a-0410-9941-cceddc491573>2008-06-10 07:41:27 +0000
commitaa3717c904d5d25c9f58f5d17e66379966f00a8f (patch)
treeb0e55eb934017aada2332593ee8aa8979aeb9b58 /crawl-ref/source/dat/lua
parent172979dfbcd139f1adba90624340e9e6e5184cae (diff)
downloadcrawl-ref-aa3717c904d5d25c9f58f5d17e66379966f00a8f.tar.gz
crawl-ref-aa3717c904d5d25c9f58f5d17e66379966f00a8f.zip
Move pickup_butcher_tool.txt into (the recently freed) pickup.lua,
re-enable it (whoops) and clean up its code. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@5698 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/dat/lua')
-rw-r--r--crawl-ref/source/dat/lua/pickup.lua65
1 files changed, 65 insertions, 0 deletions
diff --git a/crawl-ref/source/dat/lua/pickup.lua b/crawl-ref/source/dat/lua/pickup.lua
new file mode 100644
index 0000000000..e1306f1b83
--- /dev/null
+++ b/crawl-ref/source/dat/lua/pickup.lua
@@ -0,0 +1,65 @@
+---------------------------------------------------------------------------
+-- eat.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
+ 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 string.find( item.name(it, "a"), weap ) then
+ return true
+ end
+ end
+ return false
+ else
+ return string.find( skill, "Blades" ) or skill == "Axes"
+ end
+end
+
+function ch_autopickup(it)
+ if item.class(it, true) == "weapon" then
+
+ -- 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
+
+ -- The item is not a good butchering tool, either.
+ if item.cursed(it) or not can_butcher(it) 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
+ 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