From: Pasi Kallinen Date: Thu, 17 Feb 2022 07:12:03 +0000 (+0200) Subject: Fix fire auto-swapweaponing to polearm X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=953a534cc52cdf685dc3892f51ea004fd770f524;p=nethack Fix fire auto-swapweaponing to polearm 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. --- diff --git a/include/hack.h b/include/hack.h index 9628fa977..2ed2e882d 100644 --- a/include/hack.h +++ b/include/hack.h @@ -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 { diff --git a/src/cmd.c b/src/cmd.c index 1188c77bd..4b8272a8d 100644 --- 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; diff --git a/src/wield.c b/src/wield.c index fbec5db1f..1c3b549c0 100644 --- a/src/wield.c +++ b/src/wield.c @@ -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 */