Skip to content

Commit

Permalink
track the handedness of the hero
Browse files Browse the repository at this point in the history
Don't make either LEFT_HANDED or RIGHT_HANDED be an advantage
or a disadvantage.

use suggested macros
  • Loading branch information
nhmall committed Dec 2, 2023
1 parent 8ee8d89 commit e4e8eea
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 17 deletions.
10 changes: 10 additions & 0 deletions include/you.h
Expand Up @@ -421,6 +421,11 @@ struct you {
Bitfield(uburied, 1); /* you're buried */
Bitfield(uedibility, 1); /* blessed food detect; sense unsafe food */
Bitfield(usaving_grace, 1); /* prevents death once */
Bitfield(uhandedness, 1); /* There is no advantage for either handedness.
The distinction is only for flavor variation
and for use in messages. */
#define RIGHT_HANDED 0x00
#define LEFT_HANDED 0x01

unsigned udg_cnt; /* how long you have been demigod */
struct u_event uevent; /* certain events have happened */
Expand Down Expand Up @@ -538,4 +543,9 @@ struct _hitmon_data {
/* hero at (x,y)? */
#define u_at(x,y) ((x) == u.ux && (y) == u.uy)

#define URIGHTY (u.uhandedness == RIGHT_HANDED)
#define ULEFTY (u.uhandedness == LEFT_HANDED)
#define RING_ON_PRIMARY (ULEFTY ? uleft : uright)
#define RING_ON_SECONDARY (ULEFTY ? uright : uleft)

#endif /* YOU_H */
27 changes: 20 additions & 7 deletions src/do_wear.c
Expand Up @@ -2159,7 +2159,9 @@ accessory_or_armor_on(struct obj *obj)
}
if (uwep) {
res = !uwep->bknown; /* check this before calling welded() */
if ((mask == RIGHT_RING || bimanual(uwep)) && welded(uwep)) {
if (((mask == RIGHT_RING && URIGHTY)
|| (mask == LEFT_RING && ULEFTY)
|| bimanual(uwep)) && welded(uwep)) {
const char *hand = body_part(HAND);

/* welded will set bknown */
Expand Down Expand Up @@ -2387,9 +2389,18 @@ glibr(void)
boolean leftfall, rightfall, wastwoweap = FALSE;
const char *otherwep = 0, *thiswep, *which, *hand;

leftfall = (uleft && !uleft->cursed
&& (!uwep || !(welded(uwep) && ULEFTY)
|| !bimanual(uwep)));
rightfall = (uright && !uright->cursed
&& (!uwep || !(welded(uwep) && URIGHTY)
|| !bimanual(uwep)));
/*
leftfall = (uleft && !uleft->cursed
&& (!uwep || !welded(uwep) || !bimanual(uwep)));
rightfall = (uright && !uright->cursed && (!welded(uwep)));
*/

if (!uarmg && (leftfall || rightfall) && !nolimbs(gy.youmonst.data)) {
/* changed so cursed rings don't fall off, GAN 10/30/86 */
Your("%s off your %s.",
Expand Down Expand Up @@ -2422,7 +2433,7 @@ glibr(void)
if (otmp->quan > 1L)
otherwep = makeplural(otherwep);
hand = body_part(HAND);
which = "left ";
which = URIGHTY ? "left " : "right "; /* text for the off hand */
Your("%s %s%s from your %s%s.", otherwep, xfl ? "also " : "",
otense(otmp, "slip"), which, hand);
xfl++;
Expand Down Expand Up @@ -2453,10 +2464,12 @@ glibr(void)
}
hand = body_part(HAND);
which = "";
if (bimanual(otmp))
if (bimanual(otmp)) {
hand = makeplural(hand);
else if (wastwoweap)
which = "right "; /* preceding msg was about left */
} else if (wastwoweap) {
/* preceding msg was about non-dominant hand */
which = URIGHTY ? "right " : "left ";
}
pline("%s %s%s %s%s from your %s%s.",
!strncmp(thiswep, "corpse", 6) ? "The" : "Your",
otherwep ? "other " : "", thiswep, xfl ? "also " : "",
Expand Down Expand Up @@ -2511,7 +2524,7 @@ stuck_ring(struct obj *ring, int otyp)
if (nolimbs(gy.youmonst.data) && uamul
&& uamul->otyp == AMULET_OF_UNCHANGING && uamul->cursed)
return uamul;
if (welded(uwep) && (ring == uright || bimanual(uwep)))
if (welded(uwep) && ((ring == RING_ON_PRIMARY) || bimanual(uwep)))
return uwep;
if (uarmg && uarmg->cursed)
return uarmg;
Expand Down Expand Up @@ -2556,7 +2569,7 @@ select_off(register struct obj *otmp)
}
glibdummy = cg.zeroobj;
why = 0; /* the item which prevents ring removal */
if (welded(uwep) && (otmp == uright || bimanual(uwep))) {
if (welded(uwep) && ((otmp == RING_ON_PRIMARY) || bimanual(uwep))) {
Sprintf(buf, "free a weapon %s", body_part(HAND));
why = uwep;
} else if (uarmg && (uarmg->cursed || Glib)) {
Expand Down
13 changes: 11 additions & 2 deletions src/objnam.c
Expand Up @@ -1406,7 +1406,15 @@ doname_base(
tethered ? "tethered " : "", /* aklys */
/* avoid "tethered wielded in right hand" for twoweapon */
(twoweap_primary && !tethered) ? "wielded" : "weapon",
twoweap_primary ? "right " : "", hand_s);
URIGHTY ? "right " : "left ",
/*
(twoweap_primary && URIGHTY)
? "right "
: (twoweap_primary && ULEFTY)
? "left "
: "",
*/
hand_s);
if (!Blind) {
if (gw.warn_obj_cnt && obj == uwep
&& (EWarn_of_mon & W_WEP) != 0L)
Expand All @@ -1423,7 +1431,8 @@ doname_base(
}
if (obj->owornmask & W_SWAPWEP) {
if (u.twoweap)
Sprintf(eos(bp), " (wielded in left %s)", body_part(HAND));
Sprintf(eos(bp), " (wielded in %s %s)",
URIGHTY ? "left" : "right", body_part(HAND));
else
/* TODO: rephrase this when obj isn't a weapon or weptool */
Sprintf(eos(bp), " (alternate weapon%s; not wielded)",
Expand Down
5 changes: 4 additions & 1 deletion src/u_init.c
Expand Up @@ -602,7 +602,7 @@ knows_class(char sym)
void
u_init(void)
{
register int i;
int i;
struct u_roleplay tmpuroleplay = u.uroleplay; /* set by rcfile options */

flags.female = flags.initgend;
Expand Down Expand Up @@ -903,6 +903,9 @@ u_init(void)
break;
}

/* roughly based on distribution in human population */
u.uhandedness = rn2(10) ? RIGHT_HANDED : LEFT_HANDED;

if (discover)
ini_inv(Wishing);

Expand Down
12 changes: 6 additions & 6 deletions src/uhitm.c
Expand Up @@ -5384,12 +5384,12 @@ hmonas(struct monst *mon)
verb = (mattk->aatyp == AT_TUCH) ? "touch" : "claws";
/* decide if silver-hater will be hit by silver ring(s);
for 'multi_claw' where attacks alternate right/left,
assume 'even' claw or touch attacks use right hand
or paw, 'odd' ones use left for ring interaction;
even vs odd is based on actual attacks rather
than on index into mon->dat->mattk[] so that {bite,
claw,claw} instead of {claw,claw,bite} doesn't
make poly'd hero mysteriously become left-handed */
assume 'even' claw or touch attacks use dominant hand
or paw, 'odd' ones use non-dominant hand for ring
interaction; even vs odd is based on actual attacks
rather than on index into mon->dat->mattk[] so that
{bite,claw,claw} instead of {claw,claw,bite} doesn't
make poly'd hero mysteriously switch handedness */
odd_claw = !odd_claw;
specialdmg = special_dmgval(&gy.youmonst, mon,
W_ARMG
Expand Down
4 changes: 3 additions & 1 deletion src/wield.c
Expand Up @@ -194,8 +194,10 @@ ready_weapon(struct obj *wep)
tmp = thestr;
else
tmp = "";
pline("%s%s %s to your %s!", tmp, aobjnam(wep, "weld"),
pline("%s%s %s to your %s%s!", tmp, aobjnam(wep, "weld"),
(wep->quan == 1L) ? "itself" : "themselves", /* a3 */
bimanual(wep) ? "" :
(URIGHTY ? "dominant right " : "dominant left "),
bimanual(wep) ? (const char *) makeplural(body_part(HAND))
: body_part(HAND));
set_bknown(wep, 1);
Expand Down

0 comments on commit e4e8eea

Please sign in to comment.