]> granicus.if.org Git - nethack/commitdiff
Fix fire auto-swapweaponing to polearm
authorPasi Kallinen <paxed@alt.org>
Thu, 17 Feb 2022 07:12:03 +0000 (09:12 +0200)
committerPasi Kallinen <paxed@alt.org>
Thu, 17 Feb 2022 07:12:07 +0000 (09:12 +0200)
When you have a polearm as secondary weapon, have a fireassist on,
and press 'f' to fire, the code tries to swapweapon to the polearm.
This failed badly and got stuck in a loop if you were also wearing
a shield - as polearms are two-handed and shield prevents wielding
those.

Add a new "command failed" result, and clear the command queue
in that case. Also make swapweapon and wield actually return
the ECMD flags back to the rhack loop.

include/hack.h
src/cmd.c
src/wield.c

index 9628fa977a9590abcf5d218a41e0ac7916fb1622..2ed2e882d2fb6550c08f1374a442860c2086e0ad 100644 (file)
@@ -543,6 +543,7 @@ enum bodypart_types {
 #define ECMD_OK     0x00 /* cmd done successfully */
 #define ECMD_TIME   0x01 /* cmd took time, uses up a turn */
 #define ECMD_CANCEL 0x02 /* cmd canceled by user */
+#define ECMD_FAIL   0x04 /* cmd failed to finish, maybe with a yafm */
 
 /* values returned from getobj() callback functions */
 enum getobj_callback_returns {
index 1188c77bd96e0bd3f363f9702db759be27a75bb2..4b8272a8d006303b328ce1d34c4271cf2582fdc3 100644 (file)
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -3976,9 +3976,9 @@ rhack(char *cmd)
                 prefix_seen = 0;
                 was_m_prefix = FALSE;
             }
-            if ((res & ECMD_CANCEL)) {
+            if ((res & (ECMD_CANCEL|ECMD_FAIL))) {
                 /* command was canceled by user, maybe they declined to
-                   pick an object to act on. */
+                   pick an object to act on, or command failed to finish */
                 reset_cmd_vars(TRUE);
                 prefix_seen = 0;
                 cmdq_ec = NULL;
index fbec5db1f7ca15671993faa6b5d7de097938e2fb..1c3b549c0f5acfe292d6e03c2f58a7f083020dfc 100644 (file)
@@ -168,6 +168,7 @@ ready_weapon(struct obj *wep)
         You("cannot wield a two-handed %s while wearing a shield.",
             is_sword(wep) ? "sword" : wep->otyp == BATTLE_AXE ? "axe"
                                                               : "weapon");
+        res = ECMD_FAIL;
     } else if (!retouch_object(&wep, FALSE)) {
         res = ECMD_TIME; /* takes a turn even though it doesn't get wielded */
     } else {
@@ -420,7 +421,7 @@ dowield(void)
         setuswapwep(oldwep);
     untwoweapon();
 
-    return result ? ECMD_TIME : ECMD_OK;
+    return result;
 }
 
 /* the #swap command - swap wielded and secondary weapons */
@@ -466,7 +467,7 @@ doswapweapon(void)
     if (u.twoweap && !can_twoweapon())
         untwoweapon();
 
-    return result ? ECMD_TIME : ECMD_OK;
+    return result;
 }
 
 /* the #quiver command */