Commit Graph

3788 Commits

Author SHA1 Message Date
nhmall
f1be2eaffa add --dumpmongen to view mongen_order[] array 2025-02-14 09:38:29 -05:00
nhmall
a68bc3b3fb fix tamed pet issue #1379
fixes #1379
2025-02-12 23:26:03 -05:00
nhmall
fe4cb7a626 make rank() static again 2025-02-05 20:03:06 -05:00
nhmall
0d543a8fae remove a set_uasmon() call from iter_mons() processing
Reported by hackemslashem.
2025-02-05 07:57:25 -05:00
nhmall
c24786430f 'struct former' -> 'struct ebones'
Some variants were already using a similar approach
using a struct called 'ebones', so adopt the same naming
so NetHack-3.7, hardfought, and some variants are using
the same name.

As before there are fields in the struct that are not
currently used by NetHack-3.7, but the intent is that
hardfought save and bones files can be loaded by
NetHack-3.7 without code modification, for debugging
bug reports.

This invalidates existing save and bones files.
2025-02-04 15:16:42 -05:00
PatR
b44a547153 fix resistance breakage
The Mitre of Holiness commit broke resistance handling.  This seems
to work correctly.
2025-02-03 23:20:07 -08:00
PatR
a311f4b467 fix issue #1362 - carrying Mitre of Holiness
Issue reported by elunna:  the definition of the Mitre of Holiness
specifies that carrying it should confer fire resistance but that
didn't work.

The Mitre's definition (added in 3.1.0) has always included that,
but such a capability had never been implemented.  Wearing it didn't
confer fire resistance either--its definition doesn't bother to
specify a 'defend' attribute since the 'carry' one should cover that.

This adds carrying capability for damage types fire, cold, sleep,
disintegration, electrity, poison, acid, and petrification.  Fire is
still specified by the Mitre; none of the others are currently used.

Fixes #1362
2025-02-03 11:42:36 -08:00
nhmall
d65d0062a9 follow-up: evolve placeholder content to match variant
suggestion by paxed

Increments EDITLEVEL again.
2025-02-02 12:53:58 -05:00
nhmall
d331029b03 more clobber-detection 2025-02-02 09:08:48 -05:00
nhmall
bda3437eab bump EDITLEVEL 2025-02-02 09:00:21 -05:00
nhmall
d785f7a649 add two unused fields for hardfought save compatability
There are two hardfought code additions that render save and bones files incompatible
with the upstream NetHack-3.7, and that makes testing with hardfought
save and bones files more challenging than it needs to be, when
investigating and troubleshooting bug reports.

Add some unused fields to advance towards achieving save file parity with
hardfought, which is a significant source of play-testing for NetHack-3.7.

1) the elbereth field addition to u_conduct

This adds an unused placeholder field named 'hf_reserved1', at the appropriate
place in u_conduct to achieve struct field parity with the one in use on
hardfought.

2) hardfought adds a field to struct monst:
    char former_rank[25]; /* for bones' ghost rank in their former life */

Instead of adding that to every monst, this adds a new mextra struct
named 'former', which currently contains the equivalent 25-character
field called 'rank' which can hold the content that was in the
former_rank[25] field. That way, the field will only be added when it
is needed.

A pull request https://github.com/k21971/NetHack37/pull/2 has been
done on hardfought to do it the same way (untested there as of yet).

Even though NetHack-3.7 does not utilize that information presently,
this will be a further step toward allowing hardfought-generated save
and bones files to be used for troubleshooting, without modification,
on a similar architecture running stock NetHack-3.7 code.

That savefile parity won't be achieved until the after the
hardfought pull-request mentioned above (or equivalent) is merged.

As this change will not be compatible with existing save and bones
files, it will be accompanied with an EDITLEVEL increment.
2025-02-02 09:00:05 -05:00
nhmall
d74624abbd add mexta field to simplify detection of overwrite
Because this invalidates existing save and bones files,
an increment of EDITLEVEL will accompany this.
2025-02-02 08:30:48 -05:00
nhmall
6431f4727c comment instructions in mextra.h updated 2025-02-01 14:09:58 -05:00
nhmall
61f969e88b follow-up for put_saddle_on_mon()
Commit 1acc2727 helped ensure that the which_armor(mtmp, W_SADDLE)
test at the top of put_saddle_on_mon() wouldn't lead to an obj
leak.

This commit covers off the adjacent can_saddle() test in
put_saddle_on_mon(), because if that failed, it could also lead
to a memory leak of the saddle obj passed by the caller.

- have put_saddle_on_mon() create and use its own saddle obj
  if a NULL saddle obj is passed, instead of having to do that
  in the caller.
- where an existing saddle obj needs to be passed from the caller,
  ensure that the caller has done its own can_saddle(mon) check prior
  to calling put_saddle_on_mon(), so that the can_saddle() test
  in put_saddle_on_mon() won't fail.
- lastly, add an impossible() to put_saddle_on_mon() to catch
  a failure when a saddle obj is passed from the caller and either
  test has failed, just in case. That should not happen with any of
  the existing cases now, but it will provide some bullet-proofing
  for new code, new callers.
2025-01-20 14:37:46 -05:00
Pasi Kallinen
991a1dbe43 Fix exploding landmine and boulders next to lava
Same issue as with breaking a wand of digging in commit 7ce0751a
2025-01-20 19:26:12 +02:00
nhmall
3a64b404e3 Remove an unused macro that conflicts with pdcursesmod
In file included from ../include/config.h:723:0,
                 from ../include/hack.h:10,
                 from files.c:8:
../include/global.h:519:24: error: expected ')' before '<=' token
 #define unctrl(c) ((c) <= C('z') ? (0x60 | (c)) : (c))
                        ^
../lib/pdcursesmod/curses.h:1686:16: note: in expansion of macro 'unctrl'
 PDCEX  char   *unctrl(chtype);
                ^~~~~~
2025-01-19 22:36:38 -05:00
nhmall
9da836fb4a more follow-up: Qt build fix 2025-01-19 21:55:36 -05:00
nhmall
d992155f1f follow-up for tradstdc.h
remove a duplicate comment
2025-01-19 21:20:52 -05:00
nhmall
3221665f5a updates to tradstdc.h
Define a macro NH_C to provide a shorter & simpler way to test for
which C standard the build is being carried out under (c99 or c23).

 NH_C > 202300L     Being compiled under C23 or greater
 NH_C > 199900L     Being compiled under C99 or greater
 NH_C > 198900L     Being compiled under C89 or greater,
                    or C std could not be determined.

While NetHack only requires c99, we've been taking advantage
of some c23 features (attributes), if they are available,
to allow the use of ATTRNORETURN/NORETURN and FALLTHROUGH on
compilers other than gcc.

Also add some comment documentation to tradstdc.h about NetHack's
use of c99.

The sys/unix/Makefile.top change overcomes a warning in the
Makefile-generated nhlua.h. That warning arises under some compilers
that rely on attribute [[noreturn]] ahead of a declaration
(NetHack macro ATTRNORETURN), rather than the trailing gcc
__attribute((noreturn)) (NetHack macro NORETURN). The sed command
is modified to include ATTRNORETURN at the start of the declaration
in addition to the NORETURN at the end of the declaration, in the
generated file. That's the same combination that's used for the
declaration of other functions that don't return.
2025-01-19 20:51:46 -05:00
nhmall
b2f4b687c1 yet another coordxy bit 2025-01-14 11:33:30 -05:00
nhmall
a513b41748 more coordxy consistency, mklev.c 2025-01-14 11:17:41 -05:00
nhmall
2354fef2d6 be more consistent with coordxy in mkmap.c
Also closes #1365
2025-01-14 10:32:36 -05:00
nhmall
1bb0f89b82 Merge branch 'check_version' of https://github.com/argrath/NetHack into NetHack-3.7 2025-01-13 08:24:15 -05:00
nhmall
62fe9e83c6 Merge branch 'xytod' of https://github.com/argrath/NetHack into NetHack-3.7 2025-01-13 08:23:52 -05:00
SHIRAKATA Kentaro
36443c965b second argument of check_version() can take NULL
There is a code path starting at restore.c line 830.

    (void) validate(nhfp, (char *) 0, FALSE);
2025-01-13 13:57:40 +09:00
nhmall
e08a9671dc another follow-up: another bit is needed
breaks savefiles and bones.
2025-01-12 14:08:15 -05:00
nhmall
bee21e3447 fix K4318
Reported by paxed. A potion of oil, that was already in the midst of exploding,
got picked up through spot_effects(), which led to it merging with
another potion of oil and the freeing of the original obj.

The original obj pointer was still held by breakobj(), and breakobj()
proceeded to delete the obj (again).

Function nesting:

 1    spelleffects()
 2     -> weffects()
 3      -> bhit()
 4       -> bhitpile()
 5        -> bhito(obj ...)
 6         -> hero_breaks(obj ...)
 7          -> breakobj(obj ...)
 8           -> explode_oil(obj ...)
 9            -> splatter_burning_oil()
10             -> explode()
11              -> zap_over_floor()
12               -> melt_ice()
13                -> spot_effects()
14                 -> pickup()
15                  -> pickup_object(obj ...)
16                   -> pick_obj(obj ...)
17                    -> addinv(obj ...)
18                     -> addinv_core0(obj ...)
19                      -> merged(obj ...)
20                       -> obfree(obj ...)
21                        -> dealloc_obj(obj ...)

 8           -> delobj(obj ...)
 9            -> delobj_core(obj ...)
10             -> obfree(obj ...)
11              -> dealloc_obj(obj ...)
12               -> impossible("obj already deleted)

This marks the exploding potion with LOST_EXPLODING, so that it won't
get picked up, or merged with another object during the long
sequence of functions, and that should take care of 15-21 above.
2025-01-12 13:50:25 -05: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
SHIRAKATA Kentaro
9b7bcf67ba change the type of xytod()'s return value to int
xytod()'s return value is an index, so its type should be int, not coordxy.
2025-01-12 14:37:13 +09:00
PatR
a490ce5759 remove trailing spaces from src/*.c, include/*.h 2025-01-10 01:30:49 -08: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
4392f5fa4e Fix vision in some cases with boulder falling into pool
We can't just unconditionally unblock vision for a location when a boulder
falls into a pool, because the location may also have a (poison) cloud on it.
2025-01-06 19:46:38 +02:00
nhmall
be5143bb74 window-port updates
Remove start_screen() and end_screen() from the
Window-port interface.

They were only ever used by tty, and there was a comment
carried to several window-ports about how they "really
should go away. They are tty-specific"

term_start_screen() and term_end_screen() are part of
terminal/NO_TERMS supporting routines now.
2025-01-04 23:38:34 -05:00
nhmall
37758c7e48 some tty updates
Add a note about NO_TERMS to include/wintty.h for clarity.

Rename tty_startup and tty_shutdown to term_startup() and
term_shutdown(). They are found in termcap.c for !NO_TERMS
like most of the other term_ routines, as well as having
versions for several of the NO_TERMS platforms. They aren't
part of the tty_interface called from the core. The tty
implementation does call and rely on them.

Remove some conditional #ifdef's around term_shutdown()
(formerly tty_shutdown()) and just ensure that all the
tty platforms have an implementation that they can link
with, even if it is just a stub presently.

Put the protype for nethack_exit in extern.h to reduce
maintenance to a single spot, and remove it from other
locations. A warning in the msdos cross-compile led to
this change.
2025-01-04 19:01:34 -05:00
Pasi Kallinen
1ef3167ca0 Steed #monster breath feedback
Using #monster to make the steed use the breath weapon often
failed because the steed did not want to breathe at weak or
too strong monsters.
Make #monster force the steed use the breath, and if there is
no targets available, make the steed make some noise as feedback.
2025-01-04 16:37:14 +02:00
PatR
ce947600e5 discoverying water walking boots
If water walking boots haven't been discovered yet and underwater
hero rises to the surface when putting a pair on, discover them.

(Sinking while removing such on water already discovers them.)
2025-01-02 23:12:15 -08:00
nhmall
d3c57e1b42 fix reported crash of TTY_PERM_INVENT segfaulting
Options processing can be early, even before ttyDisplay is allocated.
If we find that TTY_PERM_INVENT initialization is happening too early,
just set a marker (iflags.perm_invent_pending) to try again a bit later.

The changes in win/share are just to be able to sucessfully
reproduce the original issue on Windows. It was easily reproduced
on Unix, just by building with TTY_PERM_INVENT in include/config.h
and setting OPTIONS=perm_invent in config file.
2025-01-02 11:46:15 -05:00
copperwater
2d4f9893ad Enable more ways to specify monster inventory in special levels
This originated with a bug in NerfHack in which the developer specified
an inventory for a quest nemesis, but neglected to include the Bell of
Opening in it. Since monsters' inventory contents from makemon() were
tossed out completely, this caused a situation where the Bell was
deleted and the game was unwinnable. The first part of this change is
guarding against that by adding mdrop_special_objs before discarding the
inventory. This does create a possibility where if the programmer *does*
specify a nemesis get the Bell item in their inventory, while neglecting
to remove its special case generation in makemon.c, it would generate
twice - but two Bells is better than none.

Working on that fix led me to think about a limitation of the current
sp_lev.c behavior. You could either have a monster generate with its
species-typical inventory by not specifying an inventory for it, or you
could have it generate with custom inventory but then have to use that
to clumsily reproduce the normal inventory's complex chances and
conditionals in mongets(). So the remainder of this commit implements
another flag for des.monster(), keep_default_invent, that allows for
more flexibility in two ways:

1. When des.monster() contains an inventory function and
   keep_default_invent is true, the monster will retain everything it
   gets from makemon() and the objects in the inventory function are in
   ADDITION to those. This is useful for augmenting a monster's default
   kit with something to make them more threatening, or just more loot.
2. When des.monster contains no inventory function and
   keep_default_invent is false, the monster will get NO inventory even
   if its species is normally supposed to. I'm not sure where exactly
   this would be used, but it doesn't hurt to have it available.

When keep_default_invent is not specified at all, the behavior remains
the same as it is now - if inventory is provided, default items are
discarded, and if not, they are kept.
2025-01-02 08:07:50 +02:00
nhmall
35f2ca44e2 update year in COPYRIGHT_BANNER_A to 2025 2025-01-01 08:46:41 -05:00
nhmall
eacfa202d9 soundlib selection in config file wasn't working
When there was more than one option #define'd
selection was not working correctly.
2024-12-30 12:54:12 -05:00
nhmall
a62c62fd96 follow-up for --showpaths
Ensure that memory allocations are freed up.

Windows:
  Fix a Windows compiler warning.
  Fix an undefined link symbol.
2024-12-22 20:45:55 -05:00
nhmall
57f86662fd try harder to have --showpaths succeed
This helps avoid a potential chicken-and-egg scenario
with the system configuration file (sysconf).

If sysconf wasn't accessible at the expected location, it
caused an immediate exit, without relaying any helpful
information. That happened even when using:
    'nethack --showpaths'

That's particularly unhelpful, because the --showpaths
output might have been useful towards understanding where
NetHack was looking for such things.

That left you without an easy recourse to identify where
the game is looking for the sysconf file. That might be
especially troublesome if you didn't build the game
yourself.
2024-12-22 19:58:52 -05: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
Pasi Kallinen
cc31017265 Use NO_MATERIAL instead of a magic number 2024-12-20 19:39:16 +02:00
nhmall
45b2a6c49a more C standard progress
There was a transcription error in the comments in cstd.h for
the standard list of header files, where only the description
remained for <stdlib.h>, not the name of the file itself.

Remove several extraneous inclusions of the standard C99 headers.

Tested on the following afterwards:
Linux (using hints/linux.370) including tty, curses, qt6, and X11
macOS (using hints/macOS.370) including tty, curses, qt5, and X11
Windows MSYS2 using sys/windows/GNUmakefile
Windows Visual Studio using sys/windows/Makefile.nmake
msdos cross-compile on Ubuntu using djgpp cross-compiler
2024-12-20 10:32:38 -05:00
PatR
837da48621 fix issue #1340 - winter wolf, hellhound alignment
Issue reported by k21971:  winter wolf cub and hellhound pup were
defined with alignment -5 (chaotic) while winter wolf and hellhound
were 0 (neutral).

K2 suggested that winter wolf plus cub both be neutral and hellhound
plus pup both be chaotic but I've gone another way:  both cub and
pup are now 0 and both adults are -5.

Fixes #1340
2024-12-19 19:59:13 -08:00
PatR
8a7f3b2b6b more issue #1303
Various bits I had in progress before Michael's commit.

Mainly forget engravings when bones are saved instead of leaving them
flagged as seen for the next hero who gets the level.
2024-12-19 18:18:11 -08:00
nhmall
21d35e768c bump EDITLEVEL for previous two commits DEC19-2024 2024-12-19 17:54:55 -05:00
nhmall
111ef1e1a5 consume a bit in obj.h for future resolution of a TODO in bones.c
Since EDITLEVEL is being incremented for the previous patch anyway,
add the "name_from" bit to the obj struct now, as groundwork for
the code change mentioned in a TODO comment in bones.c:

            /* strip user-supplied names */
            /* Statue and some corpse names are left intact,
               presumably in case they came from score file.
               [TODO: this ought to be done differently--names
               which came from such a source or came from any
               stoned or killed monster should be flagged in
               some manner; then we could just check the flag
               here and keep "real" names (dead pets, &c) while
               discarding player notes attached to statues.] */
            if (has_oname(otmp)
                && !(otmp->oartifact || otmp->otyp == STATUE
                     || otmp->otyp == SPE_NOVEL
                     || (otmp->otyp == CORPSE
                         && otmp->corpsenm >= SPECIAL_PM))) {
                free_oname(otmp);
            }

Also, the bitfield per-byte groupings identified in the struct
weren't accurately reflected, so rearrange the Bitfields,
and correct the per-byte groupings.

This invalidates existing save files and bones.
2024-12-19 17:54:14 -05:00
nhmall
f7853be3dc fix GitHub issue 1303 related to engravings
GitHub issue reported by ars3niy:
https://github.com/NetHack/NetHack/issues/1303

@ars3niy commented on Oct 27:
Stepping on a square with a dust or "graffiti" engraving while blind
produces no message because presumably you can't read them by swiping
the floor with your hands, however the engraving glyph still shows up on
the map afterwards. While this helps zen players, it looks like a bug.

@ville-v commented 3 days ago:
Searching while blind also reveals the engravings. Here is a save file
demonstrating the issue.
[...]

This adds an erevealed bit to engravings, to accompany the the eread
bit that is already there.

eread:      refers to the text of the engraving
erevealed:  refers to the engraving map symbol

Hopefully, this resolves issue 1303 without creating additional bugs.

This invalidates existing save files and bones.

Fixes #1303
2024-12-19 17:53:43 -05:00