summaryrefslogtreecommitdiffstats
path: root/crawl-ref
diff options
context:
space:
mode:
authorpauldubois <pauldubois@c06c8d41-db1a-0410-9941-cceddc491573>2008-03-16 01:53:55 +0000
committerpauldubois <pauldubois@c06c8d41-db1a-0410-9941-cceddc491573>2008-03-16 01:53:55 +0000
commitfcffc0bf3760f37f5fe969cdef0bfe5746fa8676 (patch)
tree13ef0891b7c994499c1b93f59988c3010ebd7a89 /crawl-ref
parentbea6f1793e9d3bf56739fefe6b546f837d143130 (diff)
downloadcrawl-ref-fcffc0bf3760f37f5fe969cdef0bfe5746fa8676.tar.gz
crawl-ref-fcffc0bf3760f37f5fe969cdef0bfe5746fa8676.zip
Pull yes or no questions requiring a typed "yes" into into a yes_or_no(),
analagous to "yesno". Tested with zot,lava,water,quit. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@3666 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref')
-rw-r--r--crawl-ref/source/acr.cc7
-rw-r--r--crawl-ref/source/command.cc11
-rw-r--r--crawl-ref/source/command.h6
-rw-r--r--crawl-ref/source/player.cc20
-rw-r--r--crawl-ref/source/stuff.cc21
-rw-r--r--crawl-ref/source/stuff.h1
6 files changed, 32 insertions, 34 deletions
diff --git a/crawl-ref/source/acr.cc b/crawl-ref/source/acr.cc
index 950925d330..519c787b7b 100644
--- a/crawl-ref/source/acr.cc
+++ b/crawl-ref/source/acr.cc
@@ -426,7 +426,7 @@ static void handle_wizard_command( void )
mpr( "If you continue, your game will not be scored!", MSGCH_WARN );
#endif
- if (!yesno( "Do you really want to enter wizard mode?", false, 'n' ))
+ if (!yesno( "Do you really want to enter wizard mode? ", false, 'n' ))
return;
you.wizard = true;
@@ -2274,7 +2274,10 @@ void process_command( command_type cmd )
break;
case CMD_QUIT:
- quit_game();
+ if (yes_or_no("Are you sure you want to quit"))
+ ouch(INSTANT_DEATH, 0, KILLED_BY_QUITTING);
+ else
+ canned_msg(MSG_OK);
break;
case CMD_GET_VERSION:
diff --git a/crawl-ref/source/command.cc b/crawl-ref/source/command.cc
index fbd81cb619..a72f8a4b50 100644
--- a/crawl-ref/source/command.cc
+++ b/crawl-ref/source/command.cc
@@ -60,17 +60,6 @@ static void list_wizard_commands();
static const char *command_string( int i );
#endif
-void quit_game(void)
-{
- char buf[10];
- mpr("Are you sure you want to quit (enter \"yes\" to confirm)? ",
- MSGCH_PROMPT);
- if (!cancelable_get_line(buf, sizeof buf) && !strcasecmp(buf, "yes"))
- ouch(INSTANT_DEATH, 0, KILLED_BY_QUITTING);
- else
- canned_msg(MSG_OK);
-}
-
static const char *features[] = {
"Stash-tracking",
diff --git a/crawl-ref/source/command.h b/crawl-ref/source/command.h
index 4be25f8946..47dcd293d8 100644
--- a/crawl-ref/source/command.h
+++ b/crawl-ref/source/command.h
@@ -20,12 +20,6 @@
/* ***********************************************************************
* called from: acr
* *********************************************************************** */
-void quit_game(void);
-
-// last updated 12may2000 {dlb}
-/* ***********************************************************************
- * called from: acr
- * *********************************************************************** */
void version(void);
diff --git a/crawl-ref/source/player.cc b/crawl-ref/source/player.cc
index a07fed0ba1..7dacf48f4c 100644
--- a/crawl-ref/source/player.cc
+++ b/crawl-ref/source/player.cc
@@ -160,12 +160,8 @@ bool move_player_to_grid( int x, int y, bool stepped, bool allow_shift,
{
if (trap_type_at_xy(x,y) == TRAP_ZOT)
{
- mpr("Do you really want to step into the Zot trap? "
- "(Confirm with \"yes\".) ", MSGCH_PROMPT);
-
- char buf[10];
- if (cancelable_get_line(buf, sizeof buf)
- || strcasecmp(buf, "yes"))
+ if (! yes_or_no("Do you really want to step into the %s",
+ "Zot trap"))
{
canned_msg(MSG_OK);
you.turn_is_over = false;
@@ -212,15 +208,9 @@ bool move_player_to_grid( int x, int y, bool stepped, bool allow_shift,
if (stepped && !force && !you.duration[DUR_CONF])
{
- mprf(MSGCH_PROMPT,
- "Do you really want to step into the %s? "
- "(Confirm with \"yes\".) ",
- (new_grid == DNGN_LAVA ? "lava" : "deep water"));
-
- char buf[10];
- if (cancelable_get_line(buf, sizeof buf)
- || strcasecmp(buf, "yes"))
- {
+ if (! yes_or_no("Do you really want to step into the %s",
+ (new_grid == DNGN_LAVA ? "lava" : "deep water")))
+ {
canned_msg(MSG_OK);
return (false);
}
diff --git a/crawl-ref/source/stuff.cc b/crawl-ref/source/stuff.cc
index c9d6ecb22d..caca339a08 100644
--- a/crawl-ref/source/stuff.cc
+++ b/crawl-ref/source/stuff.cc
@@ -763,6 +763,27 @@ void canned_msg(canned_message_type which_message)
return;
} // end canned_msg()
+// Like yesno, but requires a full typed answer.
+// Unlike yesno, prompt should have no trailing space.
+// Returns true if the user typed "yes", false if something else or cancel.
+bool yes_or_no( const char* fmt, ... )
+{
+ char buf[200];
+ va_list args;
+ va_start(args, fmt);
+ vsnprintf(buf, sizeof buf, fmt, args);
+ va_end(args);
+ buf[sizeof(buf)-1] = 0;
+
+ mprf(MSGCH_PROMPT, "%s? (Confirm with \"yes\".) ", buf);
+
+ if (cancelable_get_line(buf, sizeof buf))
+ return false;
+ if (strcasecmp(buf, "yes") != 0)
+ return false;
+ return true;
+}
+
// jmf: general helper (should be used all over in code)
// -- idea borrowed from Nethack
bool yesno( const char *str, bool safe, int safeanswer, bool clear_after,
diff --git a/crawl-ref/source/stuff.h b/crawl-ref/source/stuff.h
index 54214fb8b8..7517b589cd 100644
--- a/crawl-ref/source/stuff.h
+++ b/crawl-ref/source/stuff.h
@@ -70,6 +70,7 @@ void redraw_screen();
void canned_msg(canned_message_type which_message);
+bool yes_or_no( const char* fmt, ... );
typedef std::map<int, int> explicit_keymap;
bool yesno( const char * str, bool safe = true, int safeanswer = 0,
bool clear_after = true, bool interrupt_delays = true,