summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorharanp <haranp@c06c8d41-db1a-0410-9941-cceddc491573>2007-11-13 12:37:07 +0000
committerharanp <haranp@c06c8d41-db1a-0410-9941-cceddc491573>2007-11-13 12:37:07 +0000
commit38f4816dab5c71b632cc06748f531282f158e91c (patch)
tree4984aa0b0d734a18a8833136df0874261520163a
parentf19ffb0cf2b7db6897674d73191525cb54831723 (diff)
downloadcrawl-ref-38f4816dab5c71b632cc06748f531282f158e91c.tar.gz
crawl-ref-38f4816dab5c71b632cc06748f531282f158e91c.zip
'q' (or Escape) when prompted for food on the floor now cancels out of
eating completely, rather than moving to inventory. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@2847 c06c8d41-db1a-0410-9941-cceddc491573
-rw-r--r--crawl-ref/source/clua.cc12
-rw-r--r--crawl-ref/source/food.cc56
-rw-r--r--crawl-ref/source/food.h2
-rw-r--r--crawl-ref/source/stuff.cc5
4 files changed, 35 insertions, 40 deletions
diff --git a/crawl-ref/source/clua.cc b/crawl-ref/source/clua.cc
index 2bca2b3562..3f9c7b55b9 100644
--- a/crawl-ref/source/clua.cc
+++ b/crawl-ref/source/clua.cc
@@ -1510,10 +1510,14 @@ static int food_do_eat(lua_State *ls)
static int food_prompt_floor(lua_State *ls)
{
- bool eaten = false;
- if (!you.turn_is_over && (eaten = eat_from_floor()))
- burden_change();
- lua_pushboolean(ls, eaten);
+ int eaten = 0;
+ if (!you.turn_is_over)
+ {
+ eaten = eat_from_floor();
+ if ( eaten == 1 )
+ burden_change();
+ }
+ lua_pushboolean(ls, (eaten != 0));
return (1);
}
diff --git a/crawl-ref/source/food.cc b/crawl-ref/source/food.cc
index 7ab07cd9c7..3ee75ea83d 100644
--- a/crawl-ref/source/food.cc
+++ b/crawl-ref/source/food.cc
@@ -14,6 +14,8 @@
#include "AppHdr.h"
#include "food.h"
+#include <sstream>
+
#include <string.h>
// required for abs() {dlb}:
#include <stdlib.h>
@@ -505,8 +507,11 @@ bool eat_food(bool run_hook)
if (igrd[you.x_pos][you.y_pos] != NON_ITEM)
{
- if (eat_from_floor())
- return (true);
+ const int res = eat_from_floor();
+ if ( res == 1 )
+ return true;
+ if ( res == -1 )
+ return false;
}
return (prompt_eat_from_inventory());
@@ -728,10 +733,11 @@ void eat_floor_item(int item_link)
dec_mitm_item_quantity( item_link, 1 );
}
-bool eat_from_floor(void)
+// return -1 for cancel, 1 for eaten, 0 for not eaten
+int eat_from_floor()
{
if (you.flight_mode() == FL_LEVITATE)
- return (false);
+ return 0;
bool need_more = false;
for (int o = igrd[you.x_pos][you.y_pos]; o != NON_ITEM; o = mitm[o].link)
@@ -745,37 +751,21 @@ bool eat_from_floor(void)
(item.base_type != OBJ_CORPSES || item.sub_type != CORPSE_BODY))
continue;
- mprf( MSGCH_PROMPT,
- "%s %s%s?", you.species == SP_VAMPIRE ? "Drink blood from" : "Eat",
- (item.quantity > 1) ? "one of " : "",
- item.name(DESC_NOCAP_A).c_str() );
-
- // If we're prompting now, we don't need a -more- when
- // breaking out, because the prompt serves as a -more-. Of
- // course, the prompt can re-set need_more to true.
- need_more = false;
-
- unsigned char keyin = tolower( getch() );
-
- if (keyin == 0)
+ std::ostringstream prompt;
+ prompt << (you.species == SP_VAMPIRE ? "Drink blood from" : "Eat")
+ << ' ' << ((item.quantity > 1) ? "one of " : "")
+ << item.name(DESC_NOCAP_A) << '?';
+ const int ans = yesnoquit( prompt.str().c_str(), true, 0, false );
+ if ( ans == -1 ) // quit
+ return -1;
+ else if ( ans == 1 )
{
- getch();
- keyin = 0;
- }
-
- if (keyin == 'q')
- return (false);
-
- if (keyin == 'y')
- {
- if (!can_ingest( item.base_type, item.sub_type, false ))
+ if (can_ingest(item.base_type, item.sub_type, false))
{
- need_more = true;
- continue;
+ eat_floor_item(o);
+ return 1;
}
-
- eat_floor_item(o);
- return (true);
+ need_more = true;
}
}
@@ -1578,7 +1568,7 @@ static bool vampire_consume_corpse(int mons_type, int mass,
else if (wearing_amulet(AMU_THE_GOURMAND))
{
food_value = mass/3 + random2(you.experience_level * 5);
- mpr("Slurps.");
+ mpr("Slurp.");
did_god_conduct(DID_DRINK_BLOOD, 8);
}
else
diff --git a/crawl-ref/source/food.h b/crawl-ref/source/food.h
index 94dceeceec..2aba226354 100644
--- a/crawl-ref/source/food.h
+++ b/crawl-ref/source/food.h
@@ -88,7 +88,7 @@ bool can_ingest(int what_isit, int kindof_thing, bool suppress_msg,
void eat_floor_item(int item_link);
-bool eat_from_floor(void);
+int eat_from_floor();
void eat_from_inventory(int which_inventory_slot);
diff --git a/crawl-ref/source/stuff.cc b/crawl-ref/source/stuff.cc
index 29c03cd096..bd81b38303 100644
--- a/crawl-ref/source/stuff.cc
+++ b/crawl-ref/source/stuff.cc
@@ -14,6 +14,7 @@
*/
#include "AppHdr.h"
+#include "cio.h"
#include "database.h"
#include "direct.h"
#include "message.h"
@@ -776,7 +777,7 @@ int yesnoquit( const char* str, bool safe, int safeanswer, bool clear_after )
int tmp = getchm(KC_CONFIRM);
- if ( tmp == ESCAPE || tmp == 'q' || tmp == 'Q' )
+ if ( tmp == CK_ESCAPE || tmp == 'q' || tmp == 'Q' )
return -1;
if ((tmp == ' ' || tmp == '\r' || tmp == '\n') && safeanswer)
@@ -797,7 +798,7 @@ int yesnoquit( const char* str, bool safe, int safeanswer, bool clear_after )
else if (tmp == 'Y')
return 1;
else
- mpr("[Y]es or [N]o only, please.");
+ mpr("[Y]es, [N]o or [Q]uit only, please.");
}
}