From 8f73f926b154aceeac23a95528da356e11399302 Mon Sep 17 00:00:00 2001 From: PatR Date: Fri, 3 Apr 2020 11:42:17 -0700 Subject: [PATCH] groundwork: u.twoweap manipulation Toggle u.twoweap on or off in just one place. --- include/extern.h | 1 + src/bones.c | 7 ++++++- src/do_wear.c | 4 ++-- src/dothrow.c | 6 +++--- src/u_init.c | 8 ++++---- src/uhitm.c | 2 +- src/wield.c | 13 ++++++++++--- src/worn.c | 6 +++--- src/zap.c | 4 ++-- 9 files changed, 32 insertions(+), 19 deletions(-) diff --git a/include/extern.h b/include/extern.h index c8cabacc7..05e1dab3d 100644 --- a/include/extern.h +++ b/include/extern.h @@ -2989,6 +2989,7 @@ E int NDECL(dotwoweapon); E void NDECL(uwepgone); E void NDECL(uswapwepgone); E void NDECL(uqwepgone); +E void FDECL(set_twoweap, (BOOLEAN_P)); E void NDECL(untwoweapon); E int FDECL(chwepon, (struct obj *, int)); E int FDECL(welded, (struct obj *)); diff --git a/src/bones.c b/src/bones.c index 50e3b2b3e..e8d0a721a 100644 --- a/src/bones.c +++ b/src/bones.c @@ -231,7 +231,12 @@ int x, y; { struct obj *otmp; - u.twoweap = 0; /* ensure curse() won't cause swapwep to drop twice */ + /* when dual-wielding, the second weapon gets dropped rather than welded if + it becomes cursed; ensure that that won't happen here by ending dual-wield */ + u.twoweap = FALSE; /* bypass set_twoweap() */ + + /* all inventory is dropped (for the normal case), even non-droppable things + like worn armor and accessories, welded weapon, or cursed loadstones */ while ((otmp = g.invent) != 0) { obj_extract_self(otmp); /* when turning into green slime, all gear remains held; diff --git a/src/do_wear.c b/src/do_wear.c index 882294818..c365fc0d8 100644 --- a/src/do_wear.c +++ b/src/do_wear.c @@ -2467,12 +2467,12 @@ do_takeoff() if (!cursed(uwep)) { setuwep((struct obj *) 0); You("are empty %s.", body_part(HANDED)); - u.twoweap = FALSE; + set_twoweap(FALSE); /* u.twoweap = FALSE [ought to be in setuwep()] */ } } else if (doff->what == W_SWAPWEP) { setuswapwep((struct obj *) 0); You("no longer have a second weapon readied."); - u.twoweap = FALSE; + set_twoweap(FALSE); /* u.twoweap = FALSE; [ought to be in setuswapwep()] */ } else if (doff->what == W_QUIVER) { setuqwep((struct obj *) 0); You("no longer have ammunition readied."); diff --git a/src/dothrow.c b/src/dothrow.c index 50e2f07bd..54326bb36 100644 --- a/src/dothrow.c +++ b/src/dothrow.c @@ -1193,7 +1193,7 @@ struct obj *oldslot; /* for thrown-and-return used with !fixinv */ if (obj->owornmask & W_QUIVER) /* in case addinv() autoquivered */ setuqwep((struct obj *) 0); setuwep(obj); - u.twoweap = twoweap; + set_twoweap(twoweap); /* u.twoweap = twoweap */ } else if (u.dz < 0) { (void) toss_up(obj, rn2(5) && !Underwater); } else if (u.dz > 0 && u.usteed && obj->oclass == POTION_CLASS @@ -1217,7 +1217,7 @@ struct obj *oldslot; /* for thrown-and-return used with !fixinv */ (void) encumber_msg(); if (wep_mask && !(obj->owornmask & wep_mask)) { setworn(obj, wep_mask); - u.twoweap = twoweap; + set_twoweap(twoweap); /* u.twoweap = twoweap */ } clear_thrownobj = TRUE; goto throwit_return; @@ -1352,7 +1352,7 @@ struct obj *oldslot; /* for thrown-and-return used with !fixinv */ if (obj->owornmask & W_QUIVER) setuqwep((struct obj *) 0); setuwep(obj); - u.twoweap = twoweap; + set_twoweap(twoweap); /* u.twoweap = twoweap */ if (cansee(g.bhitpos.x, g.bhitpos.y)) newsym(g.bhitpos.x, g.bhitpos.y); } else { diff --git a/src/u_init.c b/src/u_init.c index 1d9b01d44..4b0e9f74a 100644 --- a/src/u_init.c +++ b/src/u_init.c @@ -603,7 +603,7 @@ u_init() uarm = uarmc = uarmh = uarms = uarmg = uarmf = 0; uwep = uball = uchain = uleft = uright = 0; uswapwep = uquiver = 0; - u.twoweap = 0; + u.twoweap = FALSE; /* bypass set_twoweap() */ u.ublessed = 0; /* not worthy yet */ u.ugangr = 0; /* gods not angry */ u.ugifts = 0; /* no divine gifts bestowed */ @@ -1114,11 +1114,11 @@ register struct trobj *trop; if (obj->oclass == ARMOR_CLASS) { if (is_shield(obj) && !uarms && !(uwep && bimanual(uwep))) { setworn(obj, W_ARMS); - /* Prior to 3.6.2 this used to unset uswapwep if it was set, but - wearing a shield doesn't prevent having an alternate + /* Prior to 3.6.2 this used to unset uswapwep if it was set, + but wearing a shield doesn't prevent having an alternate weapon ready to swap with the primary; just make sure we aren't two-weaponing (academic; no one starts that way) */ - u.twoweap = FALSE; + set_twoweap(FALSE); /* u.twoweap = FALSE */ } else if (is_helmet(obj) && !uarmh) setworn(obj, W_ARMH); else if (is_gloves(obj) && !uarmg) diff --git a/src/uhitm.c b/src/uhitm.c index e9d724129..1f07140ae 100644 --- a/src/uhitm.c +++ b/src/uhitm.c @@ -1149,7 +1149,7 @@ int dieroll; if (jousting < 0) { pline("%s shatters on impact!", Yname2(obj)); /* (must be either primary or secondary weapon to get here) */ - u.twoweap = FALSE; /* untwoweapon() is too verbose here */ + set_twoweap(FALSE); /* u.twoweap = FALSE; untwoweapon() is too verbose */ if (obj == uwep) uwepgone(); /* set g.unweapon */ /* minor side-effect: broken lance won't split puddings */ diff --git a/src/wield.c b/src/wield.c index 6e58f682f..01e7fde95 100644 --- a/src/wield.c +++ b/src/wield.c @@ -719,13 +719,20 @@ drop_uswapwep() dropx(obj); } +void +set_twoweap(on_off) +boolean on_off; +{ + u.twoweap = on_off; +} + int dotwoweapon() { /* You can always toggle it off */ if (u.twoweap) { You("switch to your primary weapon."); - u.twoweap = 0; + set_twoweap(FALSE); /* u.twoweap = FALSE */ update_inventory(); return 0; } @@ -734,7 +741,7 @@ dotwoweapon() if (can_twoweapon()) { /* Success! */ You("begin two-weapon combat."); - u.twoweap = 1; + set_twoweap(TRUE); /* u.twoweap = TRUE */ update_inventory(); return (rnd(20) > ACURR(A_DEX)); } @@ -785,7 +792,7 @@ untwoweapon() { if (u.twoweap) { You("can no longer use two weapons at once."); - u.twoweap = FALSE; + set_twoweap(FALSE); /* u.twoweap = FALSE */ update_inventory(); } return; diff --git a/src/worn.c b/src/worn.c index b2ed54714..ad23cc404 100644 --- a/src/worn.c +++ b/src/worn.c @@ -66,7 +66,7 @@ long mask; impossible("Setworn: mask = %ld.", wp->w_mask); if (oobj) { if (u.twoweap && (oobj->owornmask & (W_WEP | W_SWAPWEP))) - u.twoweap = 0; + set_twoweap(FALSE); /* u.twoweap = FALSE */ oobj->owornmask &= ~wp->w_mask; if (wp->w_mask & ~(W_SWAPWEP | W_QUIVER)) { /* leave as "x = x y", here and below, for broken @@ -120,8 +120,8 @@ register struct obj *obj; if (!obj) return; - if (obj == uwep || obj == uswapwep) - u.twoweap = 0; + if (u.twoweap && (obj == uwep || obj == uswapwep)) + set_twoweap(FALSE); /* u.twoweap = FALSE */ for (wp = worn; wp->w_mask; wp++) if (obj == *(wp->w_obj)) { /* in case wearing or removal is in progress or removal diff --git a/src/zap.c b/src/zap.c index 192e32fac..dd7ee93fa 100644 --- a/src/zap.c +++ b/src/zap.c @@ -1629,12 +1629,12 @@ int id; if (was_twohanded || !bimanual(otmp) || !uarms) setuwep(otmp); if (was_twoweap && uwep && !bimanual(uwep)) - u.twoweap = TRUE; + set_twoweap(TRUE); /* u.twoweap = TRUE */ } else if ((new_wornmask & W_SWAPWEP) != 0L) { if (was_twohanded || !bimanual(otmp)) setuswapwep(otmp); if (was_twoweap && uswapwep) - u.twoweap = TRUE; + set_twoweap(TRUE); /* u.twoweap = TRUE */ } else if ((new_wornmask & W_QUIVER) != 0L) { setuqwep(otmp); } else if (new_wornmask) {