From ca996d2ca6059e9ce53b54f620bc70cdf31df3f5 Mon Sep 17 00:00:00 2001 From: Matthew Cline Date: Tue, 24 Nov 2009 02:44:49 -0800 Subject: Fix crawl.process_keys(), add crawl.redraw_stats() --- crawl-ref/source/dat/clua/userbase.lua | 12 ------- crawl-ref/source/l_crawl.cc | 57 ++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 12 deletions(-) (limited to 'crawl-ref/source') diff --git a/crawl-ref/source/dat/clua/userbase.lua b/crawl-ref/source/dat/clua/userbase.lua index 9183a0e380..fe2dcf4d8e 100644 --- a/crawl-ref/source/dat/clua/userbase.lua +++ b/crawl-ref/source/dat/clua/userbase.lua @@ -112,15 +112,3 @@ end function add_no_autopickup_func(func) table.insert(chk_deny_autopickup, func) end - --- Sends the characters in keys as keyboard input to crawl, then requests --- that Crawl process one command. -function crawl.process_keys(keys, yield_value) - if yield_value == nil then - yield_value = true - end - - crawl.sendkeys(keys) - crawl.process_command() - coroutine.yield(yield_value) -end \ No newline at end of file diff --git a/crawl-ref/source/l_crawl.cc b/crawl-ref/source/l_crawl.cc index 22901c08be..aebb011182 100644 --- a/crawl-ref/source/l_crawl.cc +++ b/crawl-ref/source/l_crawl.cc @@ -10,6 +10,7 @@ #include "l_libs.h" #include "cio.h" +#include "command.h" #include "delay.h" #include "directn.h" #include "format.h" @@ -20,6 +21,7 @@ #include "message.h" #include "notes.h" #include "options.h" +#include "output.h" #include "player.h" #include "random.h" #include "religion.h" @@ -232,6 +234,40 @@ static int crawl_process_command(lua_State *ls) return (1); } +static int crawl_process_keys(lua_State *ls) +{ + if (you_are_delayed() || you.turn_is_over) + { + luaL_error(ls, "Cannot currently process new keys"); + return (0); + } + + const char* keys = luaL_checkstring(ls, 1); + + if (strlen(keys) == 0) + { + luaL_argerror(ls, 1, "Must have at least one key to process."); + return (0); + } + + command_type cmd = key_to_command(keys[0], KMC_DEFAULT); + + if (cmd == CMD_NO_CMD) + { + luaL_argerror(ls, 1, "First key is invalid command"); + return (0); + } + + flush_input_buffer(FLUSH_BEFORE_COMMAND); + for (int i = 1, len = strlen(keys); i < len; i++) + macro_buf_add(keys[i]); + + process_command(cmd); + + return (0); +} + + static int crawl_playsound(lua_State *ls) { const char *sf = luaL_checkstring(ls, 1); @@ -592,6 +628,7 @@ static const struct luaL_reg crawl_clib[] = { "flush_input", crawl_flush_input }, { "sendkeys", crawl_sendkeys }, { "process_command", crawl_process_command }, + { "process_keys", crawl_process_keys }, { "playsound", crawl_playsound }, { "runmacro", crawl_runmacro }, { "bindkey", crawl_bindkey }, @@ -648,6 +685,25 @@ LUAFN(_crawl_redraw_view) return (0); } +LUAFN(_crawl_redraw_stats) +{ + you.wield_change = true; + you.redraw_quiver = true; + you.redraw_hit_points = true; + you.redraw_magic_points = true; + you.redraw_strength = true; + you.redraw_intelligence = true; + you.redraw_dexterity = true; + you.redraw_experience = true; + you.redraw_armour_class = true; + you.redraw_evasion = true; + you.redraw_status_flags = 0xFFFFFFFF; + + print_stats(); + return (0); +} + + #ifdef UNIX LUAFN(_crawl_millis) { @@ -718,6 +774,7 @@ static const struct luaL_reg crawl_dlib[] = { "args", _crawl_args }, { "mark_milestone", _crawl_milestone }, { "redraw_view", _crawl_redraw_view }, +{ "redraw_stats", _crawl_redraw_stats }, { "god_speaks", _crawl_god_speaks }, #ifdef UNIX { "millis", _crawl_millis }, -- cgit v1.2.3-54-g00ecf