Commit Graph

3650 Commits

Author SHA1 Message Date
nhmall
526571b1f7 another follow-up for magic number replacement 2025-03-19 14:12:03 -04:00
nhmall
a943c4c10b replace some weight-related magic numbers
adds a header file include/nhconst.h  (I'm open to a better name)
2025-03-19 13:29:58 -04:00
nhmall
0bdf9830e6 throw-and-return weapons used by monsters
Resolves #1338
2025-03-16 15:37:49 -04:00
Pasi Kallinen
b2c071bc66 Fix rare door in corner of room bug
There were couple reports of doors being generated in a corner
of a room.  This happened for randomly generated irregular rooms,
because the code that was deciding if a corridor starting or
ending location was good did not handle irregular rooms at all.

This changes the corridor code so it can now generate start and
end points properly for any valid position in irregular rooms,
instead of only on the edges.  This means the corridor sometimes
meanders a bit more than before, because it tries to find
the end point away from the edge of the room rectangle.

Also added is sanity checking for the randomly generated rooms
and corridors level, testing for door placement and room connectivity.

And another fix for a rare special case where dig_corridor
created a zero-tile long corridor; the entrance door was placed,
but there was nothing behind it.

Fixes github #1269 and #1385
2025-03-16 09:46:53 +02:00
nhmall
b169b79d36 dump monster and obj weights using --dumpweights 2025-03-15 19:55:49 -04:00
nhmall
3b15e4fff2 a pair of duplicate #include statements in hack.h 2025-03-09 09:51:12 -04:00
nhmall
ceee6aff31 pointer decl style consistency; use any_types enum 2025-03-06 07:20:16 -05:00
nhmall
fd49242015 botl.c follow-up 2025-03-05 08:55:27 -05:00
nhmall
ebeebcc427 Merge branch 'removemagic' of https://github.com/mkuoppal/NetHack into NetHack-3.7 2025-03-05 07:59:43 -05:00
PatR
518842ce19 typo fix 2025-02-28 11:37:05 -08:00
PatR
82c6804516 X11: avoid null-pointer-subtraction warnings
Most recent version of XQuartz, same as before.  Unfortunately,
newer version of macOS => newer version of Xcode and its command
line tools => newer version of clang => emulating newer version of
gcc which defaults to a more recent version of StdC, I suppose, or
perhaps our hints are specifying that.  Whichever, it has resulted
in a bunch of complaints about XtOffset() used in win/X11/winX.c:
|warning: performing pointer subtraction with a null pointer has\
 undefined behavior [-Wnull-pointer-subtraction]

Adding -wno-null-pointer-subtraction to X11FLAGS silences them,
but that would require figuring out which versions of gcc and
clang added -Wnull-pointer-subtraction and its negation.  Revising
XtOffset() to include the ptrdiff_t casts eliminates the warnings,
avoiding the need for version conditionals to deal with X11FLAGS.
2025-02-28 10:38:50 -08:00
Keni
372ebd9d80 NOSTATICFN/NONOSTATICFN typos and logic fixes 2025-02-17 11:50:55 -05:00
Pasi Kallinen
3cb7819c81 Split monster goal coordinate out of mstrategy field
Instead of packing a coordinate into unsigned long, store the goal in
a coord struct, making the code a bit cleaner.  Monster struct is
of course slightly bigger, but that should not really matter.
No change in monster behaviour.

Breaks saves and bones.
2025-02-16 10:46:21 +02:00
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