summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--crawl-ref/source/acr.cc4
-rw-r--r--crawl-ref/source/clua.cc20
-rw-r--r--crawl-ref/source/dat/clua/userbase.lua12
-rw-r--r--crawl-ref/source/delay.cc15
-rw-r--r--crawl-ref/source/delay.h1
-rw-r--r--crawl-ref/source/enum.h4
-rw-r--r--crawl-ref/source/player.cc3
7 files changed, 55 insertions, 4 deletions
diff --git a/crawl-ref/source/acr.cc b/crawl-ref/source/acr.cc
index 7f3502d00e..166c029f5c 100644
--- a/crawl-ref/source/acr.cc
+++ b/crawl-ref/source/acr.cc
@@ -1502,7 +1502,7 @@ static void _input()
_center_cursor();
- if (you_are_delayed())
+ if (you_are_delayed() && current_delay_action() != DELAY_MACRO_PROCESS_KEY)
{
if (you.time_taken)
_world_reacts();
@@ -1534,6 +1534,8 @@ static void _input()
cursor_control con(true);
#endif
+ clear_macro_process_key_delay();
+
crawl_state.waiting_for_command = true;
c_input_reset(true);
diff --git a/crawl-ref/source/clua.cc b/crawl-ref/source/clua.cc
index 3edabd36f0..477d772a40 100644
--- a/crawl-ref/source/clua.cc
+++ b/crawl-ref/source/clua.cc
@@ -1810,6 +1810,25 @@ static int crawl_sendkeys(lua_State *ls)
return (0);
}
+// Tell Crawl to process one command.
+static int crawl_process_command(lua_State *ls)
+{
+ const bool will_process =
+ current_delay_action() == DELAY_MACRO || !you_are_delayed();
+
+ if (will_process)
+ {
+ // This should only be called from a macro delay, but run_macro
+ // may not have started the macro delay; do so now.
+ if (!you_are_delayed())
+ start_delay(DELAY_MACRO, 1);
+ start_delay(DELAY_MACRO_PROCESS_KEY, 1);
+ }
+
+ lua_pushboolean(ls, will_process);
+ return (1);
+}
+
static int crawl_playsound(lua_State *ls)
{
const char *sf = luaL_checkstring(ls, 1);
@@ -2137,6 +2156,7 @@ static const struct luaL_reg crawl_lib[] =
{ "kbhit", crawl_kbhit },
{ "flush_input", crawl_flush_input },
{ "sendkeys", crawl_sendkeys },
+ { "process_command", crawl_process_command },
{ "playsound", crawl_playsound },
{ "runmacro", crawl_runmacro },
{ "bindkey", crawl_bindkey },
diff --git a/crawl-ref/source/dat/clua/userbase.lua b/crawl-ref/source/dat/clua/userbase.lua
index fe2dcf4d8e..9183a0e380 100644
--- a/crawl-ref/source/dat/clua/userbase.lua
+++ b/crawl-ref/source/dat/clua/userbase.lua
@@ -112,3 +112,15 @@ 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/delay.cc b/crawl-ref/source/delay.cc
index b8752d97d0..638897114b 100644
--- a/crawl-ref/source/delay.cc
+++ b/crawl-ref/source/delay.cc
@@ -631,6 +631,12 @@ static void _xom_check_corpse_waste()
xom_is_stimulated(64 + (191 * food_need / 6000));
}
+void clear_macro_process_key_delay()
+{
+ if (current_delay_action() == DELAY_MACRO_PROCESS_KEY)
+ _pop_delay();
+}
+
void handle_delay( void )
{
if (!you_are_delayed())
@@ -638,6 +644,10 @@ void handle_delay( void )
delay_queue_item &delay = you.delay_queue.front();
+ // If a Lua macro wanted Crawl to process a key normally, early exit.
+ if (delay.type == DELAY_MACRO_PROCESS_KEY)
+ return;
+
if (!delay.started)
{
switch (delay.type)
@@ -1516,7 +1526,8 @@ void run_macro(const char *macroname)
}
else
{
- start_delay(DELAY_MACRO, 1);
+ if (!you_are_delayed())
+ start_delay(DELAY_MACRO, 1);
}
#else
stop_delay();
@@ -1854,7 +1865,7 @@ static const char *delay_names[] =
"jewellery_on", "memorise", "butcher", "bottle_blood", "offer_corpse",
"weapon_swap", "passwall", "drop_item", "multidrop", "ascending_stairs",
"descending_stairs", "recite", "run", "rest", "travel", "macro",
- "interruptible", "uninterruptible"
+ "macro_process_key", "interruptible", "uninterruptible"
};
// Gets a delay given its name.
diff --git a/crawl-ref/source/delay.h b/crawl-ref/source/delay.h
index 5f65eabec8..dd47926e18 100644
--- a/crawl-ref/source/delay.h
+++ b/crawl-ref/source/delay.h
@@ -77,6 +77,7 @@ bool is_run_delay(int delay);
bool is_being_butchered(const item_def &item, bool just_first = true);
bool is_vampire_feeding( void );
void stop_butcher_delay();
+void clear_macro_process_key_delay();
const char *activity_interrupt_name(activity_interrupt_type ai);
activity_interrupt_type get_activity_interrupt(const std::string &);
diff --git a/crawl-ref/source/enum.h b/crawl-ref/source/enum.h
index 6a2f7b7642..23d4e15c44 100644
--- a/crawl-ref/source/enum.h
+++ b/crawl-ref/source/enum.h
@@ -741,6 +741,10 @@ enum delay_type
DELAY_MACRO,
+ // In a macro delay, a stacked delay to tell Crawl to read and act on
+ // one input command.
+ DELAY_MACRO_PROCESS_KEY,
+
DELAY_INTERRUPTIBLE, // simple interruptible delay
DELAY_UNINTERRUPTIBLE, // simple uninterruptible delay
diff --git a/crawl-ref/source/player.cc b/crawl-ref/source/player.cc
index f796518b40..7a66a9538a 100644
--- a/crawl-ref/source/player.cc
+++ b/crawl-ref/source/player.cc
@@ -6416,7 +6416,8 @@ int player::melee_evasion(const actor *act) const
{
return (player_evasion()
- ((!act || act->visible()) ? 0 : 10)
- - (you_are_delayed()? 5 : 0));
+ - (you_are_delayed()
+ && !is_run_delay(current_delay_action())? 5 : 0));
}
void player::heal(int amount, bool max_too)