summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/dat/lua
diff options
context:
space:
mode:
Diffstat (limited to 'crawl-ref/source/dat/lua')
-rw-r--r--crawl-ref/source/dat/lua/chnkdata.lua35
-rw-r--r--crawl-ref/source/dat/lua/eat.lua107
-rw-r--r--crawl-ref/source/dat/lua/safechnk.lua37
3 files changed, 19 insertions, 160 deletions
diff --git a/crawl-ref/source/dat/lua/chnkdata.lua b/crawl-ref/source/dat/lua/chnkdata.lua
deleted file mode 100644
index bfc93be699..0000000000
--- a/crawl-ref/source/dat/lua/chnkdata.lua
+++ /dev/null
@@ -1,35 +0,0 @@
--- SPOILER WARNING
---
--- This file contains spoiler information. Do not read or use this file if you
--- don't want to be spoiled. Further, the Lua code in this file may use this
--- spoily information to take actions on your behalf. If you don't want
--- automatic exploitation of spoilers, don't use this.
---
----------------------------------------------------------------------------
--- chnkdata.lua:
--- Raw data on chunks of meat, auto-extracted from mon-data.h.
---
--- To use this, add this line to your init.txt:
--- lua_file = lua/chnkdata.lua
---
--- This file has no directly usable functions, but is needed by gourmand.lua
--- and enables auto_eat_chunks in eat.lua.
----------------------------------------------------------------------------
-
-sc_cont = {"program bug","ettin","goblin","jackal","manticore","orc","ugly thing","two-headed ogre","hobgoblin","ogre","troll","orc warrior","orc wizard","orc knight","minotaur","beast","iron devil","orc sorcerer","","","hell knight","necromancer","wizard","orc priest","orc high priest","human","gnoll","earth elemental","fire elemental","air elemental","Ice Fiend","Shadow Fiend","spectral warrior","pulsating lump","rock troll","stone giant","flayed ghost","insubstantial wisp","vapour","ogre-mage","dancing weapon","elf","war dog","grey rat","giant mosquito","fire giant","frost giant","firedrake","deep troll","giant blowfly","swamp dragon","swamp drake","hill giant","giant cockroach","white imp","lemure","ufetubus","manes","midge","neqoxec","hellwing","smoke demon","ynoxinul","Executioner","Blue Death","Balrug","Cacodemon","demonic crawler","sun demon","shadow imp","shadow wraith","Mnoleg","Lom Lobon","Cerebov","Gloorx Vloq","orc warlord","deep elf soldier","deep elf fighter","deep elf knight","deep elf mage","deep elf summoner","deep elf conjurer","deep elf priest","deep elf high priest","deep elf demonologist","deep elf annihilator","deep elf sorcerer","deep elf death mage","Terence","Jessica","Ijyb","Sigmund","Blork the orc","Edmund","Psyche","Erolcha","Donald","Urug","Michael","Joseph","Snorg","Erica","Josephine","Harold","Norbert","Jozef","Agnes","Maud","Louise","Francis","Frances","Rupert","Wayne","Duane","Xtahua","Norris","Frederick","Margery","Boris","Geryon","Dispater","Asmodeus","Antaeus","Ereshkigal","vault guard","Killer Klown","ball lightning","orb of fire","boggart","quicksilver dragon","iron dragon","skeletal warrior","","&","warg","","","komodo dragon"}
-sc_pois = {"killer bee","killer bee larva","quasit","scorpion","yellow wasp","giant beetle","kobold","queen bee","kobold demonologist","big kobold","wolf spider","brain worm","boulder beetle","giant mite","hydra","mottled dragon","brown snake","death yak","bumblebee","redback","spiny worm","golden dragon","elephant slug","green rat","orange rat","black snake","giant centipede","iron troll","naga","yellow snake","red wasp","soldier ant","queen ant","ant larva","spiny frog","orange demon","Green Death","giant amoeba","giant slug","giant snail","boring beetle","naga mage","naga warrior","brown ooze","azure jelly","death ooze","acid blob","ooze","shining eye","greater naga","eye of devastation","gila monster"}
-sc_hcl = {"necrophage","ghoul"}
-sc_mut = {"guardian naga","eye of draining","giant orange brain","great orb of eyes","glowing shapeshifter","shapeshifter","very ugly thing"}
-
-function sc_to_hash(list)
- local hash = { }
- for _, i in ipairs(list) do
- hash[i] = true
- end
- return hash
-end
-
-sc_cont = sc_to_hash( sc_cont )
-sc_pois = sc_to_hash( sc_pois )
-sc_hcl = sc_to_hash( sc_hcl )
-sc_mut = sc_to_hash( sc_mut )
diff --git a/crawl-ref/source/dat/lua/eat.lua b/crawl-ref/source/dat/lua/eat.lua
index c29f043456..ff335f1a8c 100644
--- a/crawl-ref/source/dat/lua/eat.lua
+++ b/crawl-ref/source/dat/lua/eat.lua
@@ -1,108 +1,39 @@
---------------------------------------------------------------------------
-- eat.lua:
--- Prompts to eat chunks from inventory.
+-- Prompts to eat food in the following order:
+-- 1) for chunks on the floor *and* in inventory, sorted by age
+-- 2) for non-chunks on the floor
+-- 3) for non-chunks in inventory
+-- 4) opens the food menu of your inventory
--
-- To use this, add this line to your init.txt:
-- lua_file = lua/eat.lua
--
-- See c_eat in this file if you want to tweak eating behaviour further.
---------------------------------------------------------------------------
-function prompt_eat(i)
- local iname = item.name_coloured(i, "a")
- if item.quantity(i) > 1 then
- iname = "one of " .. iname
- end
- crawl.mpr("Eat " .. iname .. "?", "prompt")
-
- local res
- res = crawl.getch()
- if res == 27 then
- res = "escape"
- elseif res < 32 or res > 127 then
- res = ""
- else
- res = string.lower(string.format("%c", res))
- end
- return res
-end
-
-function chunk_maybe_safe(chunk)
- local rot = food.rotting(chunk)
- local race = you.race()
-
- if rot then
- return you.saprovorous() > 0
- end
-
- return true
-end
-
-function is_chunk_safe(chunk)
- local rot = food.rotting(chunk)
- local race = you.race()
-
- -- Check if the user has sourced safechunk.lua and chnkdata.lua
- if not (sc_cont and sc_pois and sc_hcl and sc_mut and sc_safechunk) then
- return false
- end
-
- local cname = item.name(chunk)
- local mon
- _, _, mon = string.find(cname, "chunk of (.+) flesh")
-
- return sc_safechunk(rot, race, mon)
-end
-- Called by Crawl. Note that once Crawl sees a c_eat function, it bypasses the
-- built-in (e)at command altogether.
--
-function c_eat(floor, inv)
- -- To enable auto_eat_chunks, you also need to source chnkdata.lua and
- -- safechunk.lua. WARNING: These files contain spoily information.
- local auto_eat_chunks = options.auto_eat_chunks == "yes" or
- options.auto_eat_chunks == "true"
-
- if auto_eat_chunks then
- local all = { }
- for _, it in ipairs(floor) do table.insert(all, it) end
- for _, it in ipairs(inv) do table.insert(all, it) end
-
- for _, it in ipairs(all) do
- if food.ischunk(it) and food.can_eat(it) and is_chunk_safe(it) then
- local iname = item.name(it, "a")
- if item.quantity(it) > 1 then
- iname = "one of " .. iname
- end
- crawl.mpr("Eating " .. iname)
- food.eat(it)
- return
- end
- end
+function c_eat()
+ -- Prompt to eat chunks off floor/inventory, sorted by age.
+ -- Returns true if the player chose to eat a chunk.
+ if food.prompt_eat_chunks() then
+ return
end
- -- Prompt to eat chunks off the floor. Returns true if the player chose
- -- to eat a chunk.
+ -- Prompt to eat a non-chunk off the floor. Returns true if the player
+ -- ate something.
if food.prompt_floor() then
return
end
-
- for i, it in ipairs(inv) do
- -- If we have chunks in inventory that the player can eat, prompt.
- if food.ischunk(it) and food.can_eat(it) and chunk_maybe_safe(it) then
- local answer = prompt_eat(it)
- if answer == "q" then
- break
- end
- if answer == "escape" then
- return
- end
- if answer == "y" or answer == "e" then
- food.eat(it)
- return
- end
- end
+
+ -- Prompt to eat a non-chunk from the inventory. Returns true if the player
+ -- ate something.
+ if food.prompt_inventory() then
+ return
end
- -- Allow the player to choose a snack from inventory
- food.prompt_inventory()
+ -- Allow the player to choose a snack from inventory.
+ food.prompt_inv_menu()
end
diff --git a/crawl-ref/source/dat/lua/safechnk.lua b/crawl-ref/source/dat/lua/safechnk.lua
deleted file mode 100644
index 447981f141..0000000000
--- a/crawl-ref/source/dat/lua/safechnk.lua
+++ /dev/null
@@ -1,37 +0,0 @@
--- SPOILER WARNING
---
--- This file contains spoiler information. Do not read or use this file if you
--- don't want to be spoiled. Further, the Lua code in this file may use this
--- spoily information to take actions on your behalf. If you don't want
--- automatic exploitation of spoilers, don't use this.
---
----------------------------------------------------------------------------
--- safechunk.lua:
--- Determines whether a chunk of meat is safe for your character to eat.
---
--- To use this, add this line to your init.txt:
--- lua_file = lua/safechunk.lua
---
--- This file has no directly usable functions, but is needed by gourmand.lua
--- and enables auto_eat_chunks in eat.lua.
----------------------------------------------------------------------------
-
-function sc_safechunk(rot, race, mon)
- if rot then
- if you.saprovorous() < 2 then
- return false
- end
- end
-
- if sc_pois[mon] and you.res_poison() > 0 then
- return true
- end
-
- if sc_hcl[mon] or sc_mut[mon] then
- return race == "Ghoul"
- end
-
- -- Only contaminated and clean chunks remain, in theory. We'll accept
- -- either
- return true
-end