Commit Graph

240 Commits

Author SHA1 Message Date
Alex Smith
89473216ae Iron footwear and traps balance fixes
Any sort of iron footwear now protects from traps, and polymorph
traps change one sort of iron footwear into a different sort of
iron footwear (removing any incentive to try to farm them, because
you will see both options very quickly).
2026-04-14 16:51:20 +01:00
Alex Smith
4d043a6f9c Monsters require experience using wands before they can hit with them
It takes time for an early-game monster to acclimatize itself to the
power of an attack wand: in much the same way as a nervous human may
quite possibly miss with their first attempt to use a gun in combat,
an early-game monster will always miss on its first use of an attack
wand (but from then on will understand how they work and get over
their nerves, and will hit as normal).

This is a balance change based on observed results from tournaments:
guarding against deaths to early-game attack wands requires an
unusually cautious playstyle which isn't much fun (and might not
always be possible even for the best players), so it is quite common
for them to be the cause of random deaths that it wasn't worth trying
to avoid. Although trying to dodge a monster who found an attack wand
is fun, you only actually get that fun if something makes you aware
of the danger: the monster missing with the wand is a clear way to
demonstrate the danger and let the player know that now is the right
time to take precautions.

This change could theoretically have broken saves, but probably
doesn't due to there having been a spare bit in struct monst.  Just
in case, it is being pushed together with other save-breaking changes
to avoid the need for multiple bumps to EDITLEVEL.
2026-03-19 03:55:10 +00:00
PatR
0d2752d05d more cursed potion of invisibility
Give feedback if a visible monster drinks a potion of invisibility
that happens to be cursed so monster fails to become invisible, or if
hero hits a visible monster with a cursed potion of invisibility and
it fails to become invisible.
2026-02-16 19:51:04 -08:00
PatR
a561538c2a cursed potions of invisibility for monsters
Extend the recently changed behavior for cursed potion of invisibility.

Monsters won't drink potions of invisibility if already invisible so
can't accidentally or voluntarily make themselves visible again, but
let player make them become visible by hitting them with thrown or
wielded cursed potion of invisibility.

They don't have any concept of temporary invisibility that might let
them remain invisible while losing permanent invisibility, so they
just lose the latter and immediately become visible.
2026-02-12 10:33:09 -08:00
nhmall
fcd9f5468c some coordxy follow-up
Return a couple of variables that actually held a direction back
to int from coordxy.

bhit() takes int params instead of coordxy.

boomhit() takes int params instead of coordxy.

xytod() renamed to xytodir(), and takes int params (promotion will handle
coordxy params).

dtoxy(coord *, int) renamed to dirtocoord(coord *, int).
2026-02-11 09:40:25 -05:00
nhmall
b76d4338be avoid a reported obuf reuse in use_misc()
Report: https://github.com/NetHack/NetHack/issues/1486

Resolves #1486
2026-02-09 08:39:21 -05:00
Pasi Kallinen
01928276d5 Monsters use wand of teleportation more 2026-01-03 11:04:13 +02:00
Alex Smith
8c29b20010 Accurately track which items have been discovered, even if not #named
This fixes a couple of bugs: a long-standing bug in which writing a
scroll by label could fail even if you've already seen a scroll with
that label (due to the game not tracking whether or not you've seen a
scroll if it doesn't have a name); and a somewhat newer bug in which
spellbooks auto-identified by Wizard knowledge were marked as having
been encountered (rather than as known but not encountered).

Breaks save file compatibility, but not bones files.
2025-11-25 22:42:38 +00:00
nhmall
f4a6da2e52 save/restore changes - part 2
This is the second of a series of changes related to save/restore.

    No EDITLEVEL bump has been included, because although the code
    is changed extensively by this, the content of the savefiles have
    not been changed.

    Push the use of the structlevel bwrite() and mread() function use
    out of the core and into sfstruct.c. This is groundwork for upcoming
    changes.

    In the core, replace the bwrite() and mread() calls with the
    use of type-specific savefile output (Sfo) and savefile
    input (Sfi) macros.  The macros are defined in a new header file
    savefile.h, which also contains the prototypes for the sfo_* and
    sfi_* functions that the macros ultimately expand to. The functions
    themselves are in src/sfbase.c.

    On C99, each Sfo or Sfi macro expansion refers directly to the
    corresponding  type-specific sfo_* or sfi_* function.

    If C23 or later is is use, the majority (all but 3 types) of the
    macros refer to a single _Generic output routine sfo(nhfp, dt, tag),
    and a single _Generic input routine sfi(nhfp, dt, tag), which handles
    the dispatch of the type-specific underlying functions. This was
    somewhat experimental, but turned out to be practical because the
    compiler would gripe if the type for a variable was not included in
    the _Generic when passed as an argument, so it could be fixed.

    This alters the savefile verication process by having a common set
    return values for the related functions such as uptodate(),
    check_version(), etc. The new return values return more information
    about savefile incompatibilities, beyond failure/sucess. The
    additional information will be useful for an upcoming addition.
    The expanded return values are:
     SF_UPTODATE                     (0) everything matched and looks good
     SF_OUTDATED                     (1) savefile is outdated
     SF_CRITICAL_BYTE_COUNT_MISMATCH (2) critical size count mismatch
     SF_DM_IL32LLP64_ON_ILP32LL64    (3) Windows x64 savefile on x86
     SF_DM_I32LP64_ON_ILP32LL64      (4) Unix 64 savefile on x86
     SF_DM_ILP32LL64_ON_I32LP64      (5) x86 savefile on Unix 64
     SF_DM_ILP32LL64_ON_IL32LLP64    (6) x86 savefile on Windows x64
     SF_DM_I32LP64_ON_IL32LLP64      (7) Unix 64 savefile on Windows x64
     SF_DM_IL32LLP64_ON_I32LP64      (8) Windows x64 savefile on Unix 64
     SF_DM_MISMATCH                  (9) some other mismatch
    The callers in the core have been adjusted to deal with the expanded
    return values.

    Other miscellaneous inclusions:

       - go.oracle_loc -> svo.oracle_loc.
       - add a bit (1UL << 30) to  called SFCTOOL_BIT as groundwork
         for changes to follow.
2025-05-25 15:03:13 -04:00
PatR
8fe02c2a7c analyzer "lint" for muse.c fix
Overzealous change yesterday.  For use_defensive(), the unicorn
horn case already has guards for Null item and the added one
issues bogus panic() when a unicorn or ki-rin uses its own horn.
2025-01-20 08:39:33 -08:00
PatR
df06fc36f2 analyzer lint for m[o-u]*.c
The changes to muse.c are more extensive that most.  The many new
panic calls could be simplified by assigning a dummy object for the
trap cases.
2025-01-20 00:58:06 -08:00
Alex Smith
97e0e934e8 Use a common funcion for all monster healing
Previously, the code for monster healing was repeated every time it
was needed; this commit sends it all through a common function, which
will make it easier to make changes to how monster healing works in
the future.

This is just a code reorganisation and won't have any gameplay
effect unless I made a mistake.
2025-01-12 18:20:13 +00:00
Pasi Kallinen
843b02ec1d Add vision sanity checking, fix more vision
- Add a vision sanity checking routine

- Recalc block point when digging a door for temporary clouds

- Add recalc_block_point after cvt_sdoor_to_door, because doorways
  on the Rogue level have no doors, and otherwise the sanity checking
  would complain.  This doesn't actually change how the Rogue level
  vision works, as it uses a different vision system

- Monster using a trap in a secret corridor revealed the corridor,
  but didn't unblock the vision unless you saw the location
2025-01-09 17:28:24 +02:00
Pasi Kallinen
274b15cd77 Fix vision when xorn digs down on a wall
A xorn inside a wall using a wand of digging to dig down, the vision
was still blocked at that location.
2025-01-06 20:11:35 +02:00
Pasi Kallinen
72fb06a40a Unhide monster moving over to teleport trap 2024-12-28 20:31:45 +02:00
nhmall
f6a5236beb follow-up to #1343 fix for telepathic hero
telepathic hero can discern which particular monster just
read a scroll, even though he cannot see the monster
2024-12-20 15:30:37 -05:00
nhmall
a35e5779f6 heard incantation: don't trump telepathy with 'I'
GitHub 1343 report by @ars3niy:
"When you are blind and see with telepathy a monster whom you then hear read
a scroll, said monster turns into an "I". While it reveals which one exactly
read the scroll, it is strange that you can no longer see it with telepathy
until it moves to another square."

Fixes #1343
2024-12-20 13:04:08 -05:00
Pasi Kallinen
1849985214 Accessibility: more message locations pt 4 2024-12-14 15:51:55 +02:00
nhmall
0792e5fe9e expand implicit fallthrough detection to non-gcc compilers
gcc has recognized various "magic comments" for white-listing
occurrences of implicit fallthrough in switch statements for
a long time:

    The range and shape of "falls through" comments accepted are
    contingent upon the level of the warning. (The default level is =3.)

    -Wimplicit-fallthrough=0 disables the warning altogether.
    -Wimplicit-fallthrough=1 treats any kind of comment as a "falls through" comment.
    -Wimplicit-fallthrough=2 essentially accepts any comment that contains something
     that matches (case insensitively) "falls?[ \t-]*thr(ough|u)" regular expression.
    -Wimplicit-fallthrough=3 case sensitively matches a wide range of regular
     expressions, listed in the GCC manual. E.g., all of these are accepted:
        /* Falls through. */
        /* fall-thru */
        /* Else falls through. */
        /* FALLTHRU */
        /* ... falls through ... */
       etc.
    -Wimplicit-fallthrough=4 also, case sensitively matches a range of regular
     expressions but is much more strict than level =3.
    -Wimplicit-fallthrough=5 doesn't recognize any comments.

Plenty of other compilers did not recognize the gcc comment convention,
and up until now the compiler warning for detecting unintended
fallthrough had to be suppressed on other compilers. That's because the code
in NetHack has been relying on the gcc approach, and only the gcc approach.

The C23 standard introduces an attribute [[fallthrough]] for the
functionality, when implicit fallthrough warnings have been enabled.

Several popular compilers already support that, or a very similar attribute
style approach, today, even ahead of their C23 support:

       C compiler                       whitelist approach
       ---------------------------   -------------------------------------
       C23 conforming compilers         [[fallthrough]]

       clang versions supporting
       standards prior to
       C23                              __attribute__((__fallthrough__))

       Microsoft Visual Studio
       since VS 2022 17.4.
       The warning C5262 controls
       whether the implict
       fallthrough is detected and
       warned about with
       /std:clatest.                    [[fallthrough]]

This adds support to NetHack for the attribute approach by inserting a
macro FALLTHROUGH to the existing cases that require white-listing, so
other compilers can analyze things too.

The definition of the FALLTHROUGH macro is controlled in include/tradstdc.h.

The gcc comment approach has also been left in place at this time.
2024-11-30 14:16:27 -05:00
nhmall
1dbba0f63b rename IS_ROCK() macro to IS_OBSTRUCTED()
It has included trees since they were added, so give it a
more fitting name.
2024-11-09 11:12:42 -05:00
PatR
5653da2c54 find_offensive() bit
Move a couple of variable initializations past some early returns
that might make them unnecessary.
2024-10-02 23:16:50 -07:00
PatR
cc1066b1ff some reformatting (3 of 4) 2024-09-05 15:55:24 -07:00
nhmall
6c0ae092c6 distinguish global variables that get written to savefile
The g? structs had a mix of variables that were written to
the savefile, and those that were not.

For better clarity and to distinguish those that end up in
the savefile, relocate some g? variables that get written
directly to the savefile into different structs.

This updates EDITLEVEL, although technically it probably
didn't need to, since savefile contents are not changing.

Details:

    gb.bases            -> svb.bases
    gb.bbubbles         -> svb.bbubbles
    gb.branches         -> svb.branches
    gc.context          -> svc.context
    gd.disco            -> svd.disco
    gd.dndest           -> svd.dndest
    gd.doors            -> svd.doors
    gd.doors_alloc      -> svd.doors_alloc
    gd.dungeon_topology -> svd.dungeon_topology
    gd.dungeons         -> svd.dungeons
    ge.exclusion_zones  -> sve.exclusion_zones
    gh.hackpid          -> svh.hackpid
    gi.inv_pos          -> svi.inv_pos
    gk.killer           -> svk.killer
    gl.lastseentyp      -> svl.lastseentyp
    gl.level            -> svl.level
    gl.level_info       -> svl.level_info
    gm.mapseenchn       -> svm.mapseenchn
    gm.moves            -> svm.moves
    gm.mvitals          -> svm.mvitals
    gn.n_dgns           -> svn.n_dgns
    gn.n_regions        -> svn.n_regions
    gn.nroom            -> svn.nroom
    go.oracle_cnt       -> svo.oracle_cnt
    gp.pl_character     -> svp.pl_character
    gp.pl_fruit         -> svp.pl_fruit
    gp.plname           -> svp.plname
    gp.program_state    -> svp.program_state
    gq.quest_status     -> svq.quest_status
    gr.rooms            -> svr.rooms
    gs.sp_levchn        -> svs.sp_levchn
    gs.spl_book         -> svs.spl_book
    gt.timer_id         -> svt.timer_id
    gt.tune             -> svt.tune
    gu.updest           -> svu.updest
    gx.xmax             -> svx.xmax
    gx.xmin             -> svx.xmin
    gy.ymax             -> svy.ymax
    gy.ymin             -> svy.ymin

Related note:
There are some pointer variables that are heads of chains that were not
moved from 'g?' to 'sv?', because they are not actually written to the
savefile directly, but the objects/monst/trap/lightsource/timer in the
chains they point to are. That can be changed, if desired.
Examples: gi.invent, gm.migrating_objs, gb.billobjs, gm.migrating_mons,
          gf.ftrap, gl.light_base, gt.timer_base
2024-07-13 14:57:50 -04:00
Pasi Kallinen
a72b95e4bc Accessibility: more message locations
Add a new pline_mon() which sets the message location
to the monster location.

Add locations to several trap messages.
2024-06-13 19:04:33 +03:00
SHIRAKATA Kentaro
ce9abbc52d split monster escaping the dungeon into separate function 2024-05-31 10:27:31 -07:00
Pasi Kallinen
2ebbd13f79 Fix boulder over a hole or a pit dug by a monster
When a monster digs down and creates a pit or a hole,
drop the boulder at the location into it.
2024-05-28 19:10:36 +03:00
PatR
c8b8f8767e MUSE wand of striking
Some code to stop a monster's zap of a wand of striking short if it
gets destroyed by hitting and destroying a drawbridge is no longer
needed with the new deferred obj deletion.
2024-05-07 12:14:54 -07:00
Pasi Kallinen
a6c5d967d2 Fix bhit/mbhit hitting destroyed objects
A monster zapped a wand of striking, hitting a burning potion
of oil, which destroyed items in the same square, and the ray was
checking destroyed item.  Similar thing with a ray done by hero.

The code currently stops checking the objects in the location
if a next object in the chain was destroyed - an improvement
would be to gather all the objects into an array and iterate
over that instead of relying on the nexthere pointer.
2024-05-07 16:05:00 +03:00
nhkeni
22d64456a6 staticfn followup 2024-03-29 13:45:27 -04:00
nhkeni
54c3dd35ac Merge branch 'keni-staticfn' into NetHack-3.7 2024-03-16 09:38:21 -04:00
nhkeni
9c0ed8ae63 NOSTATICFN for src/* 2024-03-14 17:41:51 -04:00
PatR
9ee55d87eb fix pull request #1223 - wand of striking by monst
Pull request by elunna with assistance by entrez tried to fix up
wand of striking discovery when the wand is zapped by a monster.

The fix didn't match the intended behavior (which may or may not be
the desired behavior...), so this skips the code in the pull request.
[I can't post comments on github anymore since I declined to switch
to their 2-factor authentication.  But I can still read submissions
without logging in.]

This also tries to fix a couple of inconsistencies between zapping
by the hero versus by a monster.  If the zap "boinged" :-) due to
target's magic resistance, zap by hero didn't discover the wand but
zap by monster did.  Conversely, a zap by the hero that reached a
target and missed did discover it but one by a monster did not.

Now a zap of not-yet-discovered wand of striking by the hero which
hits, whether or not the hit gets resisted, will become discovered
provided that the spot where target is hit can be seen (the target
itself need not be), and one which misses or which can't be seen
hitting something will no longer be.

Supersedes #1223
Closes #1223
2024-03-13 13:28:05 -07:00
nhmall
688ac6ffbe remove register from variable declarations 2024-02-19 16:30:07 -05:00
Pasi Kallinen
57747535af Add m_next2u, analogous to m_next2m and next2u 2024-01-19 21:53:25 +02:00
Pasi Kallinen
679c312d4d Message location for monster hurling a potion 2024-01-14 17:21:48 +02:00
nhmall
97e4c0f34a another comment bit 2024-01-11 14:44:58 -05:00
nhmall
25a8c258e6 replace x >= LOW_PM with ismnum(x) shorthand macro 2024-01-11 14:01:10 -05:00
Pasi Kallinen
58031920dc Fix monsters using escape items unnecessarily
Monsters were using escape items when they couldn't move due to
being surrounded by other monsters.  This was most evident in
Fort Ludios, where the alarm woke up all the monsters and they
would then read all the teleport scrolls.

Usually this doesn't matter, as special rooms full of monsters
are asleep.

Hardcode this fix for the Ludios only, otherwise you could trap
two monsters next to each other in a boulder fort, and they
would be happy to stay in there...
2024-01-11 19:31:37 +02:00
Mika Kuoppala
c4d3ca00ce src/muse: Avoid touch_petrifies check if bad corpsenm
EGGs can have non permanent monster based corpsenm assigned
(-1). Before doing the touch_petrifies check, make sure
that we have valid corpsenm.
2024-01-06 12:06:55 -08:00
Pasi Kallinen
0a8f919ff3 Make monsters not use camera when hero resists blindness 2023-12-16 23:34:16 +02:00
PatR
dc02eb3e4f more MUSE WAND_STRING (should be WAND_STRIKING)
Reverse part of commit 8b5e9eadb1.
Shouldn't use get_obj_location(obj,...) to try to figure out if obj
has been deleted.  That routine uses obj->where rather than scanning
the various object lists and doing that when obj has been deleted
would access stale memory.
2023-12-12 20:15:50 -08:00
PatR
8b5e9eadb1 more drawbridge destruction - MUSE WAN_STRING
A zap from a wand of striking shouldn't hit a drawbridge if it is
just passing over the span's spot when the bridge is closed.  This
change matches the 3.7 behavior when the zap is performed by the hero.
It does hit if passing over that same spot when the bridge is open or
if it hits the portcullis spot whether open or closed.

Also, simplify the handling for the wand's destruction.  It still
ends the zap early if that happens even though logically the rest of
the zap range should still be targetted.
2023-12-12 16:07:36 -08:00
PatR
c9ef210378 fix #K4061 - wand with "interesting effect"
Report was for an impossible "What an interesting effect (%d)" which
the fuzzer turned into a panic.  Monster on the drawbridge zapped
toward the open portcullis, destroying the bridge and killing itself.
Wand was made of wood and burned up in lava under the fallen span.
Freeing the object zeroed it rather than leaving stale data, and the
zap continued while referencing freed memory that looked like it had
type STRANGE_OBJECT, triggering the impossible.

This will make a monster-induced zap stop early if a drawbridge
incident destroys the wand.  That isn't the best possible fix
because the zap should continue despite the wand's destruction, but
at least it will now avoid triggering "intestsing effect".
2023-12-11 21:04:12 -08:00
PatR
6c38bfeba2 fix #K4042 - visible but unreachable teleport trap
If a monster fled from the hero by intentionally jumping into a vault
teleporter located in a niche which was still hidden and the hero
saw it happen, the trap would be mapped but the niche would remain as
a secret corridor spot.  The hero couldn't move onto the trap until
searching or wall kicking or other map disclosing activity converted
the spot into regular corridor.

Trap doors in hidden niches did already change the secret corridor
into normal corridor to unhide the trap's spot, but only if the hero
saw it happen.  Now the terrain change occurs even if hero doesn't
see it; only mapping the trap depends on that.

While testing the fix, I noticed that a monster jumping onto a vault
teleporter was teleporting randomly rather than being sent to the
vault, unlike when triggering such a trap by accident.  The code has
changed for 3.7 but this bug was already present in earlier versions.
2023-12-02 15:05:45 -08:00
PatR
97238fc01a github issue #1157 - wand of striking
Issue reported by elunna:  hero witnessing a wand of striking being
zapped by a monster didn't have that type of wand become discovered.
Monsters observing hero resisting--or failing to resist--the effect
on hero didn't learn about target's current resistance capability.

Barely tested.

Fixes #1157
2023-11-30 16:37:07 -08:00
SHIRAKATA Kentaro
5f6535728d remove unnecessary condition on use_offensive()
`otmp` here is always non-null, otherwise it leads segv at earlier code.
2023-11-29 11:27:20 -08:00
nhmall
04082a2033 Remove TEXTCOLOR build option 2023-11-22 16:01:58 -05: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
Pasi Kallinen
491cc9933f Unhide a water monster using a polymorph trap 2023-08-08 16:49:03 +03:00