summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source
diff options
context:
space:
mode:
authorj-p-e-g <j-p-e-g@c06c8d41-db1a-0410-9941-cceddc491573>2009-01-25 18:45:25 +0000
committerj-p-e-g <j-p-e-g@c06c8d41-db1a-0410-9941-cceddc491573>2009-01-25 18:45:25 +0000
commitdd016fa36134c00a8c1f919aba25b872bcba4751 (patch)
treed96ffedd99acfc3f9503cba5faa9bc7a5da26301 /crawl-ref/source
parent8c0ebd4d4cfbab6437fd1d62c64523683f29ab4d (diff)
downloadcrawl-ref-dd016fa36134c00a8c1f919aba25b872bcba4751.tar.gz
crawl-ref-dd016fa36134c00a8c1f919aba25b872bcba4751.zip
* Move eating logic from lua to C again, so as to handle more than
boolean responses (eat, skip, cancel). * Remove the now deprecated eat.lua. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@8746 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source')
-rw-r--r--crawl-ref/source/clua.cc4
-rw-r--r--crawl-ref/source/dat/lua/eat.lua39
-rw-r--r--crawl-ref/source/food.cc68
-rw-r--r--crawl-ref/source/food.h4
-rw-r--r--crawl-ref/source/item_use.cc2
5 files changed, 38 insertions, 79 deletions
diff --git a/crawl-ref/source/clua.cc b/crawl-ref/source/clua.cc
index e75261e300..f3acf7d44f 100644
--- a/crawl-ref/source/clua.cc
+++ b/crawl-ref/source/clua.cc
@@ -1618,7 +1618,7 @@ static int food_do_eat(lua_State *ls)
{
bool eaten = false;
if (!you.turn_is_over)
- eaten = eat_food(false);
+ eaten = eat_food(-1);
lua_pushboolean(ls, eaten);
return (1);
}
@@ -1627,7 +1627,7 @@ static int food_prompt_eat_chunks(lua_State *ls)
{
int eaten = 0;
if (!you.turn_is_over)
- eaten = eat_chunks();
+ eaten = prompt_eat_chunks();
lua_pushboolean(ls, (eaten != 0));
return (1);
diff --git a/crawl-ref/source/dat/lua/eat.lua b/crawl-ref/source/dat/lua/eat.lua
deleted file mode 100644
index ff335f1a8c..0000000000
--- a/crawl-ref/source/dat/lua/eat.lua
+++ /dev/null
@@ -1,39 +0,0 @@
----------------------------------------------------------------------------
--- eat.lua:
--- 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.
----------------------------------------------------------------------------
-
--- Called by Crawl. Note that once Crawl sees a c_eat function, it bypasses the
--- built-in (e)at command altogether.
---
-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 a non-chunk off the floor. Returns true if the player
- -- ate something.
- if food.prompt_floor() then
- return
- 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_inv_menu()
-end
diff --git a/crawl-ref/source/food.cc b/crawl-ref/source/food.cc
index e71c73af4d..b43b43556d 100644
--- a/crawl-ref/source/food.cc
+++ b/crawl-ref/source/food.cc
@@ -734,21 +734,6 @@ void lua_push_inv_items(lua_State *ls = NULL)
}
}
-static bool _userdef_eat_food()
-{
-#ifdef CLUA_BINDINGS
- lua_push_floor_items(clua.state());
- lua_push_inv_items();
- bool ret = clua.callfn("c_eat", 2, 0);
- if (!ret && clua.error.length())
- mpr(clua.error.c_str());
-
- return (ret);
-#else
- return (false);
-#endif
-}
-
bool prompt_eat_inventory_item(int slot)
{
if (inv_count() < 1)
@@ -816,7 +801,7 @@ bool prompt_eat_inventory_item(int slot)
}
// [ds] Returns true if something was eaten.
-bool eat_food(bool run_hook, int slot)
+bool eat_food(int slot)
{
if (you.is_undead == US_UNDEAD)
{
@@ -833,18 +818,25 @@ bool eat_food(bool run_hook, int slot)
return (false);
}
- // If user hook ran, we don't know whether something
- // was eaten or not...
- if (run_hook && _userdef_eat_food())
- return (false);
-
- if (igrd(you.pos()) != NON_ITEM && slot == -1)
+ int result;
+ // Skip the prompts if we already know what we're eating.
+ if (slot == -1)
{
- const int res = eat_from_floor(false);
- if (res == 1)
- return (true);
- if (res == -1)
- return (false);
+ result = prompt_eat_chunks();
+ if (result == 1 || result == -1)
+ return (result > 0);
+
+ if (result != -2) // else skip ahead to inventory
+ {
+ if (igrd(you.pos()) != NON_ITEM)
+ {
+ result = eat_from_floor(true);
+ if (result == 1)
+ return (true);
+ if (result == -1)
+ return (false);
+ }
+ }
}
return (prompt_eat_inventory_item(slot));
@@ -1505,11 +1497,13 @@ bool eat_from_inventory()
return (false);
}
-bool eat_chunks()
+// Returns -1 for cancel, 1 for eaten, 0 for not eaten,
+// -2 for skip to inventory.
+int prompt_eat_chunks()
{
// Herbivores cannot eat chunks.
if (player_mutation_level(MUT_HERBIVOROUS) == 3)
- return (false);
+ return (0);
bool found_valid = false;
std::vector<item_def *> chunks;
@@ -1587,7 +1581,7 @@ bool eat_chunks()
}
else
{
- mprf(MSGCH_PROMPT, "%s %s%s? (ye/n/q)",
+ mprf(MSGCH_PROMPT, "%s %s%s? (ye/n/q/i?)",
(you.species == SP_VAMPIRE ? "Drink blood from" : "Eat"),
((item->quantity > 1) ? "one of " : ""),
item_name.c_str());
@@ -1599,7 +1593,11 @@ bool eat_chunks()
case ESCAPE:
case 'q':
canned_msg(MSG_OK);
- return (false);
+ return (-1);
+ case 'i':
+ case '?':
+ // Skip ahead to the inventory.
+ return (-2);
case 'e':
case 'y':
if (can_ingest(item->base_type, item->sub_type, false))
@@ -1616,7 +1614,7 @@ bool eat_chunks()
if (in_inventory(*item))
{
eat_inventory_item(item->link);
- return (true);
+ return (1);
}
else
{
@@ -1625,9 +1623,9 @@ bool eat_chunks()
if (ilink != NON_ITEM)
{
eat_floor_item(ilink);
- return (true);
+ return (1);
}
- return (false);
+ return (0);
}
}
break;
@@ -1638,7 +1636,7 @@ bool eat_chunks()
}
}
- return (false);
+ return (0);
}
static const char *_chunk_flavour_phrase(bool likes_chunks)
diff --git a/crawl-ref/source/food.h b/crawl-ref/source/food.h
index 8ce977e6ee..f2da9ef993 100644
--- a/crawl-ref/source/food.h
+++ b/crawl-ref/source/food.h
@@ -49,7 +49,7 @@ bool butchery(int which_corpse = -1);
/* ***********************************************************************
* called from: acr
* *********************************************************************** */
-bool eat_food(bool run_hook = true, int slot = -1);
+bool eat_food(int slot = -1);
// last updated 19jun2000 {dlb}
@@ -94,7 +94,7 @@ void eat_floor_item(int item_link);
int eat_from_floor(bool skip_chunks = true);
bool eat_from_inventory();
-bool eat_chunks();
+int prompt_eat_chunks();
bool food_change(bool suppress_message = false);
void eat_inventory_item(int which_inventory_slot);
diff --git a/crawl-ref/source/item_use.cc b/crawl-ref/source/item_use.cc
index ce003911da..269984cfa6 100644
--- a/crawl-ref/source/item_use.cc
+++ b/crawl-ref/source/item_use.cc
@@ -5385,7 +5385,7 @@ void tile_item_use(int idx)
// intentional fall-through for Vampires
case OBJ_FOOD:
if (check_warning_inscriptions(item, OPER_EAT))
- eat_food(false, idx);
+ eat_food(idx);
return;
case OBJ_BOOKS: