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>2009-01-06 21:20:56 +0000
committerj-p-e-g <j-p-e-g@c06c8d41-db1a-0410-9941-cceddc491573>2009-01-06 21:20:56 +0000
commita2df2a7e984468efba235d355daa9d00ed54103f (patch)
tree2c8884c9881cb3672df74d73d25ff863389377ce /crawl-ref/source/dat/lua
parentef970c20a9d2ecb98d5838d779c1790a449d0f33 (diff)
downloadcrawl-ref-a2df2a7e984468efba235d355daa9d00ed54103f.tar.gz
crawl-ref-a2df2a7e984468efba235d355daa9d00ed54103f.zip
Greatly improve eating interface, as suggested in FRs 1923273 and 2018733.
When you now press 'e' the following takes place: 1) If you can eat chunks, the game builds a list out of all chunks on the floor and in your inventory, sorted by age [1], and prompts you to eat them [2]. 2) If none are found, or you decline all of them you get prompted for non-chunk food items on the floor. 3) Prompt for non-chunk food in your inventory. 4) Open up the food menu of your inventory. Because of the way lua works, there's currently a problem that in the early stages (1-3) "q" (now also accepts Escape) will cause to skip ahead to the next stage rather than leaving the process entirely, which is of course less than optimal. I also added two new options [1] prefer_safe_chunks (defaults to true) which will offer clean chunks before contaminated ones, even if the latter happens to be older [2] easy_eat_chunks (defaults to false) which causes the prompting to be skipped for safe (i.e. clean) chunks, so you will automatically eat the oldest chunk that applies. This is ignored for undead characters. I also got rid of the outdated safechnk.lua and chnkdata.lua seeing how chunk effects are no longer spoily information. Added a new wizmode command: Ctrl-H, which allows you to set your character's hunger state. (Hopefully this will make Vampire testing easier.) Also fix 2488374: "Controlled Flight being named upon levitation even if its type is already known. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@8282 c06c8d41-db1a-0410-9941-cceddc491573
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