fix #K3968 - objfree: obj not worn

New feature to sometimes hit twice for skilled martial-arts/bare-handed
was unconditionally using uswapwep for the second hit.  If it was a
breakable object, hitting could break it and produce impossible "objfree:
obj not free".

Only use uswapwep for u.twoweap; use Null for second bare-handed hit.
This commit is contained in:
PatR
2023-08-01 10:28:21 -07:00
parent 025edeb443
commit 9d9042e94b
2 changed files with 8 additions and 3 deletions

View File

@@ -743,7 +743,8 @@ static boolean
hitum(struct monst *mon, struct attack *uattk)
{
boolean malive, wep_was_destroyed = FALSE;
struct obj *wepbefore = uwep;
struct obj *wepbefore = uwep,
*secondwep = u.twoweap ? uswapwep : (struct obj *) 0;
int tmp, dieroll, mhit, armorpenalty, attknum = 0,
x = u.ux + u.dx, y = u.uy + u.dy, oldumort = u.umortality;
@@ -787,11 +788,12 @@ hitum(struct monst *mon, struct attack *uattk)
mon_maybe_unparalyze(mon);
dieroll = rnd(20);
mhit = (tmp > dieroll || u.uswallow);
malive = known_hitum(mon, uswapwep, &mhit, tmp, armorpenalty, uattk,
malive = known_hitum(mon, secondwep, &mhit, tmp, armorpenalty, uattk,
dieroll);
/* second passive counter-attack only occurs if second attack hits */
if (mhit)
(void) passive(mon, uswapwep, mhit, malive, AT_WEAP, !uswapwep);
(void) passive(mon, secondwep, mhit, malive, AT_WEAP,
secondwep && !uswapwep);
}
gt.twohits = 0;
return malive;