Commit Graph

107 Commits

Author SHA1 Message Date
nhmall
4e19221e55 variable 'display' causes shadow variable warnings in X11 build
display.botl      -> disp.botl
display.botlx     -> disp.botlx
display.time_botl -> disp.time_botl
2024-01-05 05:58:51 -05:00
nhmall
49a5d043c0 consistent use of TRUE vs 1 with botl and botlx 2024-01-04 23:48:38 -05:00
nhmall
22e52ee905 bundle the display-related hints, that tell bot() and others
that an update is required, into a struct. Remove it from
context since there is no reason to save those.
2024-01-04 23:16:27 -05:00
nhmall
36e8e504c2 another static analyzer bit for wield.c
src/wield.c(745): warning: Dereferencing NULL pointer 'obj'.
See line 685 for an earlier location where this can occur

In wield_tool(), the comparisons against uwep were intended
for when uwep wasn't null.

gcc/clang analyzers now have some awareness of obj arg being
notnull for wield_tool() since the extern.h prototypes
were changed to declare that, but other compilers/analyzers
do not necessarily have that information, and this:
    'if (obj == uwep)'
would be a match if both were NULL.
2023-12-24 15:38:06 -05:00
nhmall
3bc8af9836 static analyzer bit for wield.c
src/wield.c(254): warning: Dereferencing NULL pointer 'wep'.
See line 190 for an earlier location where this can occur

This seems to be a case where an unnecessary null test (A) caused
the analyzer to call into question whether or not wep
is null at (B):

    if (!wep) {
    } else if (wep->otyp == CORPSE && cant_wield_corpse(wep)) {
    } else if (uarms && bimanual(wep)) {
    } else if (!retouch_object(&wep, FALSE)) {
    } else {
        /* Weapon WILL be wielded after this point */
        if (will_weld(wep)) {
        } else {
        }
        if (was_twoweap && !u.twoweap && flags.verbose) {
        }
        /* KMH -- Talking artifacts are finally implemented */
A ==>   if (wep && wep->oartifact) {
        }
        if (artifact_light(wep) && !wep->lamplit) {
        }
B ==>   if (wep->unpaid) {
        }
    }

Removing the extraneous wep test from (A) resolves the complaint.
2023-12-24 14:47:08 -05:00
nhmall
e4e8eea4e8 track the handedness of the hero
Don't make either LEFT_HANDED or RIGHT_HANDED be an advantage
or a disadvantage.

use suggested macros
2023-12-02 11:23:43 -05:00
nhmall
d7fef5f194 avoid another magic number
Some of the hardcoded +1 scattered about are likely
invlet_gold or invlet_overflow, but I didn't hunt those down.
2023-11-30 11:15:32 -05:00
PatR
585e6373b5 drop_uswapwep()
drop_uswapwep() avoided calling makeplural() in a pline which also
had a call to Yobjname2(), with a comment about the possibility of
clobbering its static return buffer.  uswapwep might be a stack that
results in Yobjname2 indirectly calling makeplural to produce a
plural description.  But makeplural() has used xname's pool of obufs
since before uswapwep became a thing, so the code was evidently
cloned from some other out of date usage.

I was going to just move the makeplural() call into pline() but it
dawned on me that uswapwep must be one handed, so don't pluralize
hands at all.  And since uswapwep might have the same description as
uwep, explicitly mention "left hand" to distinguish.
2023-11-29 11:23:25 -08:00
PatR
f6e70bbc58 two-weapon combat on/off via inventory item action
When testing 'm )' I noticed that weapon and alternate weapon weren't
offering the chance to toggle two-weapon mode.  When already on,
providing it as a choice to toggle it off is simple, but when at is
off that isn't the case.  There are lots of reasons why attempting
to toggle it on might fail and it is silly to offer as a choice if
failure is sure to occur.  This tries to filter out the majority of
reasons why the player can't toggle it on when deciding whether to
include 'X' as a choice.
2023-11-28 01:15:04 -08:00
nhmall
76d328d86a gi.invalid_obj -> hands_obj 2023-11-11 19:49:38 -05:00
nhmall
314a2a9489 use gi.invalid_obj instead of cg.zeroobj
cg.zeroobj was originally added (under its previous unprefixed name)
for providing a one-line way to zero out the fields of a struct obj.

    struct obj tempobj;
    tempobj = cg.zeroobj;

    initfn(struct obj *otmp)
    {
        if (otmp)
            *otmp = cg.zeroobj;
    }

More recently, the address of cg.zeroobj began to be used as a return
flag to indicate some things, but the 'const struct obj zeroobj' wasn't
an ideal fit for the purpose and required a number of casts, including
casting away const.

Provide a better fitting variable (gi.invalid_obj) and eliminate a
number of casts.
2023-11-10 11:07:49 -05:00
nhmall
6cbefc7c2d Revert "granular verbose message suppression mechanics"
This reverts commit be76727265.
2023-10-29 20:39:07 -04:00
PatR
dd05f5183e addinv_nomerge()
Replace several instances of
 obj->nomerge = 1;
 addinv(obj);
 obj->nomerge = 0;
with new
 addinv_nomerge(obj);
and add various related comments.
2023-09-19 14:40:33 -07:00
PatR
0e761c3e30 talking artifact inconsistency
To get the Magic Mirror of Merlin to speak, you could apply it in
any direction (or wield it).  To get the Master Key of Thievery to
speak, you had to apply it toward an adjacent doorway or down while
on a container (or wield it).  Make the key behave like the mirror.
2023-03-18 21:47:34 -07:00
PatR
df7e575500 fix issue #949 - dropping welded iron ball
If punished and the attached iron ball was both cursed and wielded,
falling while going down stairs would drop it instead of leaving it
welded to hero's hand. ( Didn't happen for iron ball that wasn't
chained to hero's leg.)

I thought that this was going to be a one or two line fix but ball
and chain stuff is never that simple.

Fixes #949
2022-12-15 13:48:59 -08:00
nhmall
02a48aa8cf split g into multiple structures
The consolidation of global variables from scattered source
files into decl.c and declared in decl.h was begun in 3.7.0.
Their placement in common files was done for centralized
initialization and potential re-initialization during a
"play again" scenario.

It wasn't really necessary for all of them to be housed in a
single huge structure to meet the "play again" requirement,
and the single huge structure has been a little unwieldy when
it comes to maintenance.

Following this commit, instead of one single extremely large structure
named 'g' to house all of the relocated global variables, they
are distributed into several ga through gz.

To make things easy for the developer, each variable is placed
into the struct corresponding to the starting letter of the variable.
That way, no lookup is required in order to know which struct houses
a particular variable, it is a simple match to the starting letter
for all the centralized global variables.

A global variable named 'amulets', would be found in ga.
    ga.amulets
     ^ ^
A global varable named 'move', would be found in gm.
    gm.moves
     ^ ^
A global variable named 'val_for_n_or_more' would be found in gv.
    gv.val_for_n_or_more
     ^ ^
A global variable named 'youmonst' would be found in gy.
    gy.youmonst
     ^ ^
2022-11-29 21:53:21 -05:00
nhmall
c825e6839f redundant comparison code
: #define is_weptool(o) \
:    ((o)->oclass == TOOL_CLASS && objects[(o)->otyp].oc_skill != P_NONE)
2022-09-05 11:16:43 -04:00
Pasi Kallinen
9be2e581b7 Macros for checking is object artifact 2022-08-12 19:37:34 +03:00
nhmall
be76727265 granular verbose message suppression mechanics
Switch to using a macro invocation Verbos(n, s) in place of the
flags.verbose checks.

Provide the mechanics for individual suppression of any of the
existing messages that were considered verbose.

Mechanics only - this code update does not provide any means of
setting the suppression bits.

iflags.verbose = 0
is still a master suppression of all the verbose messages.

iflags.verbose = 1
turns on the verbose messages only for those whose suppression
bit is 0 (not set).
2022-06-09 13:53:20 -04:00
PatR
9abec79df8 "empty handed" vs "bare handed"
When not wielding anything, ^X reports "you are empty handed" if
wearing gloves or "you are bare handed" if no gloves.  The ')',
'w-', and 'A)' commands were using "empty handed" unconditionally.
Make them be consisitent with ^X.

After this, body part HANDED is no longer used anywhere except in
body_part().
2022-04-25 01:31:34 -07:00
PatR
40d0caa157 'f'ire revamp
The fire command could claim that time passed when it hadn't (fill
quiver with ammo, which takes no time, then queue commands to switch
to matching launcher, which should also take no time while queueing,
only during subsequent execution).

If quiver is empty or has ammo in it, give wielded thrown-and-return
weapon (aklys) priority over filling quiver or switching to ammo's
launcher.  Don't do that if quiver has non-ammo in it, otherwise
players running Valks who wield Mjollnir with super strength but
want to throw quivered daggers would complain.

When player is being asked what to fill the quiver with, use the
\#quiver command to do that.  Using it honors a count to split a
stack, handles switching uwep or uswapwep to uquiver, and gives
feedback.  This is actually a fairly substantial change.

For 'fireassist', when switching to a launcher that isn't already
uswapwep pick one known to be blessed or uncursed over one having
unknown BUC status.  But use the latter as last resort.
2022-04-23 02:12:21 -07:00
PatR
385a9a7fde encumbrance checks
I polymorphed into something wimpy and became overloaded or even
overtaxed so I dropped everything.  The status line still showed
overloaded or overtaxed until my next move.  That didn't happen in
3.6.x or 3.4.3 but I didn't pursue trying to figure out what caused
this misbehavior.

I wanted to add an encumber_msg() call to freeinv() but that would
cause message sequencing issues.  Instead, add a call to it in a
few places where items are leaving hero's inventory, particularly
for the chain of calls for dropping stuff.  I've left it off in a
bunch of other potential places.

Also add a few missing (void) casts where the return value of
existing encumber_msg() calls is being ignored.
2022-03-22 10:48:23 -07:00
Pasi Kallinen
390429545e Wield and swapweapon ext cmd fail return values 2022-02-17 11:06:35 +02:00
Pasi Kallinen
953a534cc5 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.
2022-02-17 09:12:07 +02:00
PatR
cfd753dd12 command prefix handling
Investigating github issue #664 by argrath turned up a more
significant problem.  Prefixes other than 'm' preceding commands
that don't use a prefix didn't get rejected but didn't do anything.

Fixes #664
2022-02-06 11:51:00 -08:00
Pasi Kallinen
68b822e4dc Add "user canceled" as extended command return value
Instead of returning ECMD_OK, the commands now return ECMD_CANCEL
when user declined to pick a direction or an object to act on.

Note that this can be ORed with ECMD_TIME, if the command still
took a turn.

For now this has no gameplay meaning.
2022-01-08 20:04:57 +02:00
Pasi Kallinen
d53cd28d46 Make extended commands return defined flags
Instead of returning 0 or 1, we'll now use ECMD_OK or ECMD_TURN.
These have the same meaning as the hardcoded numbers; ECMD_TURN
means the command uses a turn.

In future, could add eg. a flag denoting "user cancelled command"
or "command failed", and should clear eg. the cmdq.

Mostly this was simply replacing return values with the defines
in the extended commands, so hopefully I didn't break anything.
2021-12-30 19:16:33 +02:00
Pasi Kallinen
76f77ee0cc Add assistance to fire-command
Allows the fire-command to autowield a launcher; it will now
do either swapweapon or wield an appropriate launcher, if you
have ammo quivered.

This assistance can be turned off with the fireassist boolean option.

Adds a rudimentary command queue, which allows the code to add keys
or extended commands into the queue, and they're executed as if
the user did them.  Time passes normally when doing the queue,
and the queue will get cleared if hero is interrupted.
2021-06-16 13:14:32 +03:00
PatR
c3ccd93a88 fix pull request #469 - multiple '$' invent slots
Assigning a partial stack of gold to quiver (Qnn$) resulted in
an extra '$' slot in inventory, one for the unquivered part and
another for the quivered part.

Throwing a non-quivered partial stack of gold at self (tnn$.)
also resulted in an extra '$' slot after throwing at self was
rejected.

For the first case, reject the quiver-subset-of-gold attempt.
For both cases, recombine the two stacks back to original amount.

Fixes #469
2021-03-16 12:29:22 -07:00
nhmall
f963c5aca7 switch source tree from k&r to c99 2021-01-26 21:06:16 -05:00
copperwater
0b638592a4 Refactor getobj() to use callbacks on candidate objects
This replaces the arcane system previously used by getobj where the
caller would pass in a "string" whose characters were object class
numbers, with the first up to four characters being special constants
that effectively acted as flags and had to be in a certain order.
Because there are many places where getobj must behave more granularly
than just object class filtering, this was supplemented by over a
hundred lines enumerating all these special cases and "ugly checks", as
well as other ugly code spread around in getobj callers that formatted
the "string".

Now, getobj callers pass in a callback which will return one of five
possible values for any given object in the player's inventory. The
logic of determining the eligibility of a given object is handled in the
caller, which greatly simplifies the code and makes it clearer to read.
Particularly since there's no real need to cram everything into one if
statement.

This is related to pull request #77 by FIQ; it's largely a
reimplementation of its callbacks system, without doing a bigger than
necessary refactor of getobj or adding the ability to select a
floor/trap/dungeon feature with getobj. Differences in implementation
are mostly minor:
- using enum constants for returns instead of magic numbers
- 5 possible return values for callbacks instead of 3, due to trying to
  make it behave exactly as it did previously. PR #77 would sometimes
  outright exclude objects because it lacked semantics for invalid
  objects that should be selectable anyway, or give slightly different
  messages.
- passing a bitmask of flags to getobj rather than booleans (easier to
  add more flags later - such as FIQ's "allow floor features" flag, if
  that becomes desirable)
- renaming some of getobj's variables to clearer versions
- naming all callbacks consistently with "_ok"
- generally more comments explaining things

The callbacks use the same logic from getobj_obj_exclude,
getobj_obj_exclude_too and getobj_obj_acceptable_unlisted (and in a few
cases, from special cases still within getobj). In a number of them, I
added comments suggesting possible further refinements to what is and
isn't eligible (e.g. should a bullwhip really be presented as a
candidate for readying a thrown weapon?)

This also removed ALLOW_COUNT and ALLOW_NONE, relics of the old system,
and moved ALLOW_ALL's definition into detect.c which is the only place
it's used now (unrelated to getobj). The ALLOW_ALL functionality still
exists as the GETOBJ_PROMPT flag, because its main use is to force
getobj to prompt for input even if nothing is valid.

I did not refactor ggetobj() as part of this change.
2021-01-07 11:06:58 -05:00
PatR
9e33d658a4 conflicting 'bullets'
This was pointed out several years ago.  Since tho different
'static bullets[]' contain different values, give them distinct
names.
2020-12-05 12:32:52 -08:00
nhmall
ac9ba38449 file header bump from "NetHack 3.6" to "NetHack 3.7" 2020-08-03 22:07:36 -04:00
PatR
f694f3b644 add missing two-weapon feedback
When dual-wielding and you wield a different weapon, two weapon combat
was silently toggled off even when the new weapon was eligible to be
dual-wielded.  If the verbose flag is On, explicitly tell the player
when wielding something toggles off two-weapon mode.  Wielding '-' is
an exception because you already get told that you're empty handed.
2020-04-07 07:40:33 -07:00
PatR
d07595db2c dual-wielding tweaks
Reject arrows and darts as candidates for wielding two weapons at
once.

Make the check for being able to two-weapon when polymorphed be more
robust.  Instead of just testing whether the monster form's second
atttack is a weapon attack and then assuming that the first one is
too, test the first three to validate that at least two of those are
AT_WEAP.  The existing code works but seemed fragile.
2020-04-06 06:12:25 -07:00
PatR
8f73f926b1 groundwork: u.twoweap manipulation
Toggle u.twoweap on or off in just one place.
2020-04-03 11:42:17 -07:00
nhmall
ffd9eedb2c condtests[bl_bareh] requires a couple of additional g.context.botl = 1 2020-02-08 11:03:46 -05:00
PatR
4b2ba5acc7 twoweapon tweaks
Don't allow dual-wielding if either wielded or alternate weapon
(or both) is a launcher:  bow, crossbow, or sling.  (I thought that
this had been addressed ages ago.)

Refine the "can't twoweapon" feedback.  The message for having
either or both hands empty is the same, but sentence construction
is different.  The not-a-weapon feedback is slightly different, now
mentioning whether it's the wielded or alternate weapon which isn't
allowed.  The case where neither are acceptable still just reports
uwep; mentioning both it and uswapwep would be too verbose.

Make more things be described as "(wielded)" instead of "(weapon in
hand)".  It was just stacks with quantity more than 1.  That's now
joined by ammo and missiles (any stack size, but in reality just 1
since greater was already being caught here) and any quantity of
non-weapon, non-weptool.  It's overridden if dual-wielding so that
right/left stay matched.

When dual-wielding, list primary as "(wielded in right hand)" and
secondary as "(wielded in left hand)" instead of "(weapon in hand)"
and "(wielded in other hand)".  The vaguer wording was better for
bows since they're held in the off hand but now that they can't be
dual-wielded that doesn't matter.  (Single-wielding a bow is still
"(weapon in hand)".)

When not dual-wielding, the item in the alternate weapon slot is
still described as "(alternate weapon; not wielded)" even if it's
not actually a weapon.  I couldn't think of better phrasing.
2020-01-04 18:22:04 -08:00
nhmall
663bb188da twoweapon message adjustment
There was a concern that some things resulted in "is not a weapon"
when trying to twoweapon, then were subsequently refered to in
menus as "weapon in hand."

Remove any perceived inconsistency by simply adjusting the first
message.
2019-12-31 10:02:54 -05:00
Pasi Kallinen
2dda1c43b2 Fix heap-use-after-free when rewielding partial stack 2019-12-29 17:28:15 +02:00
PatR
6aabc78c83 'w-' object lost panic
After the "make 'w' parallel with 'Q'" patch, wielding bare hands
was erroneously treating object id 0 as a split of zeroobj.  That
isn't in inventory so seems 'lost'.  Fixed by testing for nonzero.
There was another bug:  you could wield a partial stack even if your
current weapon was cursed.  Fixed by reordering if/else-if/end-if.
2019-12-24 03:26:34 -08:00
PatR
0f1284f068 wielding partial stack
If you're wielding a stack of N items, issuing the command to quiver
them asks whether you want to quiver N-1 of them (implicitly leaving
one wielded).  If you answer no then you're asked whether to quiver
all of them.  You could also give a count when picking the item to be
quivered and the stack would be split based on that.

However, if you have a stack of N items quivered, issuing the command
to wield them just did so, leaving the quiver empty.  And picking an
item ignored any count, so even explicitly asking for 1 (out of N)
wielded the whole stack.  Change 'w' to parallel 'Q'; if you try to
wield a quivered stack, you'll be asked whether to wield just 1 of
them.  For no, ask whether to wield the whole stack.  Or you can give
an explicit count when picking any stack in inventory to wield.

Both 'w' and 'Q' probably ought to handle the alternate/secondary
weapon similarly when it contains a stack.  This doesn't address that.
2019-12-22 14:51:05 -08:00
nhmall
0d34f43830 remove STATIC_DCL, STATIC_OVL, STATIC_VAR, STATIC_PTR from core 2019-07-14 17:24:58 -04:00
nhmall
bfc4445537 Merge branch 'NetHack-3.6' 2019-06-05 08:08:32 -04:00
PatR
43afa91ff8 fix #H8850 - bless/curse state in perm_invent
Changing an inventory item's bknown flag wasn't followed by a call to
update_inventory() in many circumstances, so information which should
have appeared wasn't showing up until some other event triggered an
update.
2019-06-04 10:50:24 -07:00
nhmall
58f2218c4e Merge branch 'NetHack-3.6.2' 2019-01-09 07:24:18 -05:00
Bart House
769ad91cc3 mthrowu, nhlan, options, regions, rip and role globals moved to g. 2018-12-25 16:26:27 -08:00
Bart House
0763046c38 zeroX, tc_gbl_data and fqn_prefix moved to instance globals. 2018-12-25 08:09:37 -08:00
Bart House
1c65e6afe0 context to g.context 2018-12-25 07:29:38 -08:00
Bart House
8c1a4d9a97 invent, youmonst, hackdir moved to g. 2018-12-24 21:04:15 -08:00