From fcffc0bf3760f37f5fe969cdef0bfe5746fa8676 Mon Sep 17 00:00:00 2001 From: pauldubois Date: Sun, 16 Mar 2008 01:53:55 +0000 Subject: 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 --- crawl-ref/source/acr.cc | 7 +++++-- crawl-ref/source/command.cc | 11 ----------- crawl-ref/source/command.h | 6 ------ crawl-ref/source/player.cc | 20 +++++--------------- crawl-ref/source/stuff.cc | 21 +++++++++++++++++++++ crawl-ref/source/stuff.h | 1 + 6 files changed, 32 insertions(+), 34 deletions(-) (limited to 'crawl-ref') 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 @@ -16,12 +16,6 @@ #include "enum.h" -// last updated 12may2000 {dlb} -/* *********************************************************************** - * called from: acr - * *********************************************************************** */ -void quit_game(void); - // last updated 12may2000 {dlb} /* *********************************************************************** * called from: acr 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 explicit_keymap; bool yesno( const char * str, bool safe = true, int safeanswer = 0, bool clear_after = true, bool interrupt_delays = true, -- cgit v1.2.3-54-g00ecf