diff options
Diffstat (limited to 'crawl-ref')
-rw-r--r-- | crawl-ref/source/acr.cc | 14 | ||||
-rw-r--r-- | crawl-ref/source/defines.h | 6 | ||||
-rw-r--r-- | crawl-ref/source/enum.h | 4 | ||||
-rw-r--r-- | crawl-ref/source/externs.h | 1 | ||||
-rw-r--r-- | crawl-ref/source/initfile.cc | 1 | ||||
-rw-r--r-- | crawl-ref/source/item_use.cc | 3 | ||||
-rw-r--r-- | crawl-ref/source/macro.cc | 153 | ||||
-rw-r--r-- | crawl-ref/source/macro.h | 1 | ||||
-rw-r--r-- | crawl-ref/source/message.cc | 32 | ||||
-rw-r--r-- | crawl-ref/source/view.cc | 10 |
10 files changed, 168 insertions, 57 deletions
diff --git a/crawl-ref/source/acr.cc b/crawl-ref/source/acr.cc index 716b02ed66..b6baf494ac 100644 --- a/crawl-ref/source/acr.cc +++ b/crawl-ref/source/acr.cc @@ -1102,6 +1102,14 @@ void process_command( command_type cmd ) start_running( RDIR_RIGHT, RMODE_START ); break; + case CMD_DISABLE_MORE: + Options.show_more_prompt = false; + break; + + case CMD_ENABLE_MORE: + Options.show_more_prompt = true; + break; + case CMD_TOGGLE_AUTOPICKUP: toggle_flag( &Options.autopickup_on, "Autopickup"); break; @@ -2528,6 +2536,8 @@ command_type keycode_to_command( keycode_type key ) { switch ( key ) { + case KEY_MACRO_DISABLE_MORE: return CMD_DISABLE_MORE; + case KEY_MACRO_ENABLE_MORE: return CMD_ENABLE_MORE; case 'b': return CMD_MOVE_DOWN_LEFT; case 'h': return CMD_MOVE_LEFT; case 'j': return CMD_MOVE_DOWN; @@ -2648,7 +2658,9 @@ keycode_type get_next_keycode() flush_input_buffer( FLUSH_BEFORE_COMMAND ); keyin = unmangle_direction_keys(getch_with_command_macros()); - mesclr(); + + if (!is_synthetic_key(keyin)) + mesclr(); return (keyin); } diff --git a/crawl-ref/source/defines.h b/crawl-ref/source/defines.h index 9f8beea1ba..70c24277e5 100644 --- a/crawl-ref/source/defines.h +++ b/crawl-ref/source/defines.h @@ -292,4 +292,10 @@ #define MIN(x, y) MINIMUM(x, y) + +// Synthetic keys: +#define KEY_MACRO_MORE_PROTECT -10 +#define KEY_MACRO_DISABLE_MORE -1 +#define KEY_MACRO_ENABLE_MORE -2 + #endif diff --git a/crawl-ref/source/enum.h b/crawl-ref/source/enum.h index 739482db13..28a846bb8b 100644 --- a/crawl-ref/source/enum.h +++ b/crawl-ref/source/enum.h @@ -750,6 +750,10 @@ enum command_type CMD_TARGET_WIZARD_MAKE_FRIENDLY, CMD_TARGET_HELP, + // Disable/enable -more- prompts. + CMD_DISABLE_MORE, + CMD_ENABLE_MORE, + // [ds] Silently ignored, requests another round of input. CMD_NEXT_CMD diff --git a/crawl-ref/source/externs.h b/crawl-ref/source/externs.h index d0ffac011f..9eef79ac7f 100644 --- a/crawl-ref/source/externs.h +++ b/crawl-ref/source/externs.h @@ -1462,6 +1462,7 @@ public: bool autopickup_on; bool autoprayer_on; + bool show_more_prompt; bool show_turns; // Show turns used in HUD. diff --git a/crawl-ref/source/initfile.cc b/crawl-ref/source/initfile.cc index 2630d96752..234ee6cc57 100644 --- a/crawl-ref/source/initfile.cc +++ b/crawl-ref/source/initfile.cc @@ -568,6 +568,7 @@ void game_options::reset_options() autopickup_on = true; autoprayer_on = false; + show_more_prompt = true; show_turns = false; diff --git a/crawl-ref/source/item_use.cc b/crawl-ref/source/item_use.cc index 278be8f1b2..f35db305b5 100644 --- a/crawl-ref/source/item_use.cc +++ b/crawl-ref/source/item_use.cc @@ -48,6 +48,7 @@ #include "items.h" #include "itemname.h" #include "itemprop.h" +#include "macro.h" #include "misc.h" #include "monplace.h" #include "monstuff.h" @@ -1218,6 +1219,7 @@ void shoot_thing(void) if (you.berserker) { canned_msg(MSG_TOO_BERSERK); + flush_input_buffer( FLUSH_ON_FAILURE ); return; } @@ -1226,6 +1228,7 @@ void shoot_thing(void) if (item == ENDOFPACK) { mpr("No suitable missiles."); + flush_input_buffer( FLUSH_ON_FAILURE ); return; } diff --git a/crawl-ref/source/macro.cc b/crawl-ref/source/macro.cc index b665301499..e220e95432 100644 --- a/crawl-ref/source/macro.cc +++ b/crawl-ref/source/macro.cc @@ -40,8 +40,9 @@ #include <deque> #include <vector> -#include <stdio.h> // for snprintf -#include <ctype.h> // for tolower +#include <cstdio> // for snprintf +#include <cctype> // for tolower +#include <cstdlib> #include "externs.h" #include "stuff.h" @@ -213,12 +214,36 @@ static void buf2keyseq(const char *buff, keyseq &k) } } +static int read_key_code(std::string s) +{ + if (s.empty()) + return (0); + + int base = 10; + if (s[0] == 'x') + { + s = s.substr(1); + base = 16; + } + else if (s[0] == '^') + { + // ^A = 1, etc. + return (1 + toupper(s[1]) - 'A'); + } + + char *tail; + return strtol(s.c_str(), &tail, base); +} + /* * Takes as argument a string, and returns a sequence of keys described - * by the string. Most characters produce their own ASCII code. There - * are two special cases: + * by the string. Most characters produce their own ASCII code. These + * are the cases: * \\ produces the ASCII code of a single \ - * \{123} produces 123 (decimal) + * \{123} produces 123 (decimal) + * \{^A} produces 1 (Ctrl-A) + * \{x40} produces 64 (hexadecimal code) + * \{!more} or \{!m} disables -more- prompt until the end of the macro. */ static keyseq parse_keyseq( std::string s ) { @@ -231,26 +256,29 @@ static keyseq parse_keyseq( std::string s ) buf2keyseq(s.c_str(), v); return (v); } - - for (std::string::iterator i = s.begin(); i != s.end(); i++) + + bool more_reset = false; + for (int i = 0, size = s.length(); i < size; ++i) { - char c = *i; + char c = s[i]; switch (state) { case 0: // Normal state - if (c == '\\') { + if (c == '\\') state = 1; - } else { + else v.push_back(c); - } break; case 1: // Last char is a '\' - if (c == '\\') { + if (c == '\\') + { state = 0; v.push_back(c); - } else if (c == '{') { + } + else if (c == '{') + { state = 2; num = 0; } @@ -258,15 +286,29 @@ static keyseq parse_keyseq( std::string s ) break; case 2: // Inside \{} - if (c == '}') { - v.push_back(num); - state = 0; - } else if (c >= '0' && c <= '9') { - num = num * 10 + c - '0'; - } - // XXX Error handling + { + const std::string::size_type clb = s.find('}', i); + if (clb == std::string::npos) + break; + + const std::string arg = s.substr(i, clb - i); + if (!more_reset && (arg == "!more" || arg == "!m")) + { + more_reset = true; + v.push_back(KEY_MACRO_MORE_PROTECT); + } + else + { + const int key = read_key_code(arg); + if (key) + v.push_back(key); + } + + state = 0; + i = clb; break; } + } } return (v); @@ -295,10 +337,14 @@ static std::string vtostr( const keyseq &seq ) for (keyseq::const_iterator i = v->begin(); i != v->end(); i++) { if (*i <= 32 || *i > 127) { - char buff[10]; - - snprintf( buff, sizeof(buff), "\\{%d}", *i ); - s += std::string( buff ); + if (*i == KEY_MACRO_MORE_PROTECT) + s += "\\{!more}"; + else + { + char buff[20]; + snprintf( buff, sizeof(buff), "\\{%d}", *i ); + s += std::string( buff ); + } // Removing the stringstream code because its highly // non-portable. For starters, people and compilers @@ -353,15 +399,30 @@ static void macro_del( macromap &mapref, keyseq key ) mapref.erase( key ); } - /* * Adds keypresses from a sequence into the internal keybuffer. Ignores * macros. */ -static void macro_buf_add( keyseq actions ) +static void macro_buf_add( const keyseq &actions, bool reverse = false ) { - for (keyseq::iterator i = actions.begin(); i != actions.end(); i++) - Buffer.push_back(*i); + keyseq act(actions.size()); + bool need_more_reset = false; + for (keyseq::const_iterator i = actions.begin(); i != actions.end(); + ++i) + { + int key = *i; + if (key == KEY_MACRO_MORE_PROTECT) + { + key = KEY_MACRO_DISABLE_MORE; + need_more_reset = true; + } + act.push_back(key); + } + if (need_more_reset) + act.push_back(KEY_MACRO_ENABLE_MORE); + + Buffer.insert( reverse? Buffer.begin() : Buffer.end(), + act.begin(), act.end() ); } /* @@ -377,7 +438,8 @@ void macro_buf_add( int key ) * Adds keypresses from a sequence into the internal keybuffer. Does some * O(N^2) analysis to the sequence to replace macros. */ -static void macro_buf_add_long( keyseq actions, macromap &keymap = Keymaps[KC_DEFAULT] ) +static void macro_buf_add_long( keyseq actions, + macromap &keymap = Keymaps[KC_DEFAULT] ) { keyseq tmp; @@ -400,7 +462,8 @@ static void macro_buf_add_long( keyseq actions, macromap &keymap = Keymaps[KC_DE // Found a macro. Add the expansion (action) of the // macro into the buffer. - if (result.size() > 0) { + if (result.size() > 0) + { macro_buf_add( result ); break; } @@ -436,7 +499,7 @@ static void macro_buf_apply_command_macro( void ) // find the longest match from the start of the buffer and replace it while (tmp.size() > 0) { - keyseq result = Macros[tmp]; + const keyseq &result = Macros[tmp]; if (result.size() > 0) { @@ -444,10 +507,7 @@ static void macro_buf_apply_command_macro( void ) for (unsigned int i = 0; i < tmp.size(); i++) Buffer.pop_front(); - // Add macro to front: - for (keyseq::reverse_iterator k = result.rbegin(); k != result.rend(); k++) - Buffer.push_front(*k); - + macro_buf_add(result, true); break; } @@ -582,7 +642,15 @@ int getch_with_command_macros( void ) void flush_input_buffer( int reason ) { if (Options.flush_input[ reason ]) - Buffer.clear(); + { + while (!Buffer.empty()) + { + const int key = Buffer.front(); + Buffer.pop_front(); + if (key == KEY_MACRO_ENABLE_MORE) + Options.show_more_prompt = true; + } + } } void macro_add_query( void ) @@ -739,3 +807,16 @@ void macro_userfn(const char *keys, const char *regname) // requires a mapping of key names to whatever getch() spits back, unlikely // to happen in a hurry. } + +bool is_synthetic_key(int key) +{ + switch (key) + { + case KEY_MACRO_ENABLE_MORE: + case KEY_MACRO_DISABLE_MORE: + case KEY_MACRO_MORE_PROTECT: + return (true); + default: + return (false); + } +} diff --git a/crawl-ref/source/macro.h b/crawl-ref/source/macro.h index 9d8fa4f126..e5b507d531 100644 --- a/crawl-ref/source/macro.h +++ b/crawl-ref/source/macro.h @@ -45,6 +45,7 @@ void macro_userfn(const char *keys, const char *registryname); void macro_buf_add(int key); bool is_userfunction(int key); +bool is_synthetic_key(int key); const char *get_userfunction(int key); diff --git a/crawl-ref/source/message.cc b/crawl-ref/source/message.cc index a82d5ffd07..be11e734db 100644 --- a/crawl-ref/source/message.cc +++ b/crawl-ref/source/message.cc @@ -649,22 +649,24 @@ void mesclr( bool force ) void more(void) { - char keypress = 0; - - if (Options.tutorial_left) - message_out(crawl_view.msgsz.y - 1, - LIGHTGREY, - "--more-- " - "Press Ctrl-P to reread old messages", - 2, false); - else - message_out(crawl_view.msgsz.y - 1, - LIGHTGREY, "--more--", 2, false); - - do - keypress = getch(); - while (keypress != ' ' && keypress != '\r' && keypress != '\n'); + if (Options.show_more_prompt) + { + char keypress = 0; + + if (Options.tutorial_left) + message_out(crawl_view.msgsz.y - 1, + LIGHTGREY, + "--more-- " + "Press Ctrl-P to reread old messages", + 2, false); + else + message_out(crawl_view.msgsz.y - 1, + LIGHTGREY, "--more--", 2, false); + do + keypress = getch(); + while (keypress != ' ' && keypress != '\r' && keypress != '\n'); + } mesclr(true); } // end more() diff --git a/crawl-ref/source/view.cc b/crawl-ref/source/view.cc index b65d2c8ede..0be4619683 100644 --- a/crawl-ref/source/view.cc +++ b/crawl-ref/source/view.cc @@ -2179,7 +2179,7 @@ static int find_feature(unsigned char feature, int curs_x, int curs_y, int x = cx + dx, y = cy + dy; if (!in_bounds(x, y)) continue; - if (is_feature(feature, x, y + 1)) + if (is_feature(feature, x, y)) { ++matchcount; if (!ignore_count--) @@ -2240,8 +2240,8 @@ static int find_feature( const std::vector<coord_def>& features, if (forward? !ignore_count-- : --ignore_count == 1) { // We want to cursor to (x,y) - *move_x = coord.x - (start_x + curs_x); - *move_y = coord.y - (start_y + curs_y); + *move_x = coord.x - (start_x + curs_x - 1); + *move_y = coord.y - (start_y + curs_y - 1); return matchcount; } else if (!forward || firstx == -1) @@ -2256,8 +2256,8 @@ static int find_feature( const std::vector<coord_def>& features, // We found something, but ignored it because of an ignorecount if (firstx != -1) { - *move_x = firstx - (start_x + curs_x); - *move_y = firsty - (start_y + curs_y); + *move_x = firstx - (start_x + curs_x - 1); + *move_y = firsty - (start_y + curs_y - 1); return firstmatch; } return 0; |