Commit Graph

142 Commits

Author SHA1 Message Date
nhkeni
9c0ed8ae63 NOSTATICFN for src/* 2024-03-14 17:41:51 -04:00
RainRat
a3658f85ac fix typos 2024-02-28 20:15:56 -08:00
nhmall
688ac6ffbe remove register from variable declarations 2024-02-19 16:30:07 -05:00
janne-hmp
22d26b7653 Saving a bones file should not free memory; the function really_done will be using that information after the call to savebones, resulting in a heap-use-after-free error (and possibly later in a double-free in nh_terminate if things get that far). 2024-01-22 16:31:51 -08:00
nhmall
25a8c258e6 replace x >= LOW_PM with ismnum(x) shorthand macro 2024-01-11 14:01:10 -05:00
nhmall
e138f497ff static analyzer bits for bones.c
src/bones.c(646): warning: Using uninitialized memory 'oldbonesid'.
src/bones.c(646): warning: String 'oldbonesid' might not be zero-terminated.

Also help prevent a buffer overflow on corrupt or ill-formed bones.
2023-12-27 10:49:21 -05:00
nhmall
c5a5b55c15 nonnull for some static functions during recent analysis 2023-12-16 10:51:59 -05:00
Pasi Kallinen
3c421da746 Previous hero rising as undead in bones retains intrinsics 2023-12-15 16:03:26 +02:00
Michael Meyer
1736f3caaa Add 'pickup_stolen' option
Add pickup_stolen option to autopick items stolen from you by a nymph or
monkey, even if they don't match your normal autopickup settings.
Replace was_dropped, was_thrown with a 2-bit bitfield that can contain
values LOST_DROPPED, LOST_THROWN, and LOST_STOLEN (or 0), since they
should all be mutually exclusive anyway as they track the most recent
way the item left the hero's inventory.

[Rebase/merge conflict fixed up.  PR]
2023-12-08 15:19:54 -08:00
Michael Meyer
d7d1c1476d Add option to exclude dropped items from autopick
This is based on a feature in UnNetHack (and I think some other variants
as well).  If the hero intentionally drops an item with 'pickup_dropped'
disabled, don't autopick it back up when walking over that square again.

Typically when the player drops an item, it's because she doesn't want
it in her inventory any more, and this option stops autopickup from
defeating that goal (especially useful for tasks like stash management
without a container).  Players have come up with workarounds to this
problem like toggling autopickup when approaching their stash pile or
adding name-based autopickup exceptions to allow them to exclude
individual items from autopickup, but this behavior should reduce the
need for those things.

I think 'pickup_dropped' is a little unfortunate because it suggests
equivalence to 'pickup_thrown' (i.e. any dropped items will be
automatically picked up regardless of autopickup exceptions).  Calling
it something like 'nopick_dropped' might be better, but as far as I can
tell options cannot start with the word 'no' because it's interpreted as
a negation of the rest of the option name.
2023-12-08 15:19:04 -08:00
nhmall
7d22a2c7b9 uhandedness follow-up
boomerang trajectory
bones
2023-12-02 20:25:37 -05:00
PatR
ea57b9d8ca bones fix - clear monst->seen_resistance
When saving bones, forget observations of current hero's resistances
because they'll be stale when the bones are used in a future game.
2023-12-01 23:05:11 -08:00
nhmall
14faa682c4 improve selectsave handling for Windows
If there were outdated savefiles encountered during
startup, each individual one was getting a wait_synch
that required a <return> even though a message window
wasn't being used at that point.

Allow suppression of the individual per-file wait_synch()
calls on Windows, so that a single one can be done once
the selectsave processing is overwith.

This was a little messy because an indicator had to flow
down through validate(), uptodate(), etc.

There shouldn't be any change in how things behave on
any non-Windows platforms.
2023-09-22 15:14:53 -04:00
PatR
9079250cfc testing for Vlad
Redo the check for whether a monster is Vlad when deciding whether to
keep it out of a bones file.  Use the new check in find_defensive()
where Vlad won't waste a turn attempting to use a wand of digging when
in his undiggable own tower.  (Failing to check for vampshifted Vlad
in the latter case wasn't actually a bug because if/when shifted,
he's unable to use items so couldn't attempt to use wand of digging.
Switch to the new check anyway.)
2023-06-09 16:09:26 -07:00
PatR
17d867d084 fix github issue #1038 - vampshifted Vlad in bones
Reported by vultur-cadens:  if Vlad made it to a level which allowed
bones and was in wolf or bat or cloud form when the hero died, he
would not be excluded from the bones file as intended.  When those
bones got loaded in another game, Vlad would become flagged as
extinct.  If that happened before his own level was reached, he
wouldn't be created when hero arrived thus there would be no way to
acquire the Candelabrum of Invocation.  (Even if his vampshifted
form had been carrying it, it wouldn't be present in the bones data
because it would have been converted into candles.)

Fixes #1038
2023-05-28 15:17:51 -07:00
nhmall
ba5356603a yn()
A number of C compiler suites have a math.h library that includes a yn()
function name that conflicts with NetHack's yn() macro:
"The y0(), y1(), and yn() functions are Bessel functions of the second kind,
for orders 0, 1, and n, respectively. The argument x must be positive. The
argument n should be greater than or equal to zero. If n is less than zero,
there will be a negative exponent in the result."

At one point, isaac64.h included math.h, although that has since been removed.

Some libraries used in NetHack (Qt for one) do include math.h and that required
build work-arounds to avoid the conflict.

Rename the NetHack macro from yn() to y_n() and avoid the math.h conflict
altogether, eliminating the need for that particular work-around.
2023-01-12 16:04:40 -05: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
Pasi Kallinen
aa09f3eef5 Use macro unhideable_trap 2022-07-18 13:27:39 +03:00
nhmall
3004cf2d34 be more consistent with coordinates 2022-07-02 09:10:03 -04:00
nhmall
30b557f7d5 change xchar to other typedefs
One of the drivers of this change was that screen coordinates require a
type that can hold values greater than 127. Parameters to the window
port routines require a large type in order to be able to have values
a fair bit larger than COLNO and ROWNO passed to them, particularly for
their use to the right of the map window.

This splits the uses of xchar into 3 different situations, and adjusts
their type and size:

                        xchar
                          |
               -----------------------
               |          |          |
            coordxy     xint16     xint8

coordxy: Actual x or y coordinates for various things (moved to 16-bits).

xint16:  Same data size as coordxy, but for non-coordinate use (16-bits).

xint8:   There are only a few use cases initially, where it was very
         plain to see that the variable could remain as 8-bits, rather
         than be bumped to 16-bits.  There are probably more such cases
         that could be changed after additional review.

Note: This first changed all xchar variables to coordxy. Some were
reviewed and got changed to xint16 or xint8 when it became apparent that
their usage was not for coordinates.

This increments EDITLEVEL in patchlevel.h
2022-06-30 23:48:18 -04:00
nhmall
a518d82c54 no quotes in WINDOWPORT macro invocation 2022-06-29 22:13:28 -04:00
PatR
01fb6a703f Some cleanup for saving bones 2022-06-11 00:09:14 -07:00
Pasi Kallinen
4a01c8fbd7 Monster list iterator
Add some basic functions to iterate through the monster list,
ignoring dead monsters. Mainly just to allow splitting up code
into discrete functions.

Not quite happy with the get_iter_mons_xy - should probably have
a pointer to iterator data struct, which gets passed through instead,
but this works for now.
2022-04-24 13:03:47 +03:00
PatR
593c3532fc more shop damage repair
Stop attempting to catch up for lost time for shop damage repair
when getlev() loads a previousl visited level.  Normal shopkeeper
behavior will take care of that.

Also, fixes the display related aspects of shop damage repair
interacting with ball and chain.  They don't happen when its done
while the map is being shown.
2022-04-09 15:55:21 -07:00
nhkeni
81b014977d Some easy loss-of-precision fixes. 2022-03-16 17:49:29 -04:00
PatR
77dc522a62 artifact tracking again
Redo the recent artifact creation stuff by replacing several nearly
identical routines with one more general one.  Also adds a tracking
bit for one or two more creation methods.  That changed artiexist[]
from an array of structs holding 8 or less bits to one holding 9, so
bump EDITLEVEL in case the total size changed.
2022-03-12 17:25:54 -08:00
PatR
7a335eb030 more artifact tracking
This should have been broken up into multiple pieces but they're
all lumped together.  I did ultimately throw away a fourth change.

Implement artiexist[].bones and artiexist[].rndm artifact creation
tracking bits that were added recently.  Doesn't need to increment
EDITLEVEL this time.

Add a new wizard mode feature:  if you use `a to show discovered
artifacts, it will prompt about whether to show the tracking bits
for all artifacts instead.  If not using menustyle traditional,
you need at least one artifact to have been discovered in order to
have 'a' choice available when selecting what class of discovered
objects to show for the '`' command.

artifact_gift(), aritfact_wish(), and so forth return a value that
none of the existing callers use, so cast their calls to (void).
2022-03-11 11:00:44 -08:00
PatR
d37fa4138a found_artifact() groundwork
Lay groundwork for generating a log event when finding an artifact
on the floor or carried by a monster.  This part should not produce
any change in behavior.

Move g.artidisco[] and g.artiexist[] out of the instance_globals
struct back to local within artifact.c.  They are both initialized
at the start of a game (and only used in that file) so don't need
to be part of any bulk reinitialization if restart-instead-of-exit
ever gets implemented.

Convert artiexist[] from an array of booleans to an array of structs
containing a pair of bitfields.  artiexist[].exists is a direct
replacement for the boolean; artiexist[].found is new but not put to
any significant use yet.  If will be used to suppress the future
found-an-artifact event for cases where a more specific event (like
crowning or divine gift as #offer reward) is already produced.

Remove g.via_naming altogether and add an extra argument to oname()
calls to replace it.

Add an extra argument to artifact_exists() calls.
2022-03-07 02:06:55 -08:00
Pasi Kallinen
8e91320d2f Use u_at macro 2022-02-23 20:28:55 +02:00
Pasi Kallinen
176d5b8463 Bones piles can be ransacked by adjacent monsters
If a bones file is created, any object-liking monster next to
where hero died has a chance of grabbing objects from hero's
inventory.

This comes from xNetHack by copperwater <aosdict@gmail.com>.
2021-09-19 21:20:32 +03:00
copperwater
89835554d8 Fix: gold dragon scale mail remained lit in bones
This is caused by the bones-pile-making routine using artifact_light()
as a test for whether it needs to call end_burn. Gold dragon scale mail
uses artifact_light(), but only returns true when its owornmask is set.
But owornmask was getting zeroed right before artifact_light() is
called. Fix is to move it right after instead.

Tested that Sunsword is not affected by this (created bones while
wearing gold dragon scales and wielding Sunsword in a dark area; when
returning to them, no light was emitted from the gravesite) because it
always returns true in artifact_light() irrespective of owornmask.
2021-08-21 22:52:10 -07:00
nhmall
f963c5aca7 switch source tree from k&r to c99 2021-01-26 21:06:16 -05:00
Michael Meyer
6ae7818346 Refactor bones search loop
Using a for loop instead of an if and a do/while makes the code much
more clear and concise, so that it's easier to understand what the
function does at a glance.  The actual approach to iterating through the
current level's bones files and searching for a match is more or less
unchanged.
2020-12-30 22:42:48 -05:00
Michael Meyer
47884d63ac Merge branch 'NetHack-3.7' into fix322 2020-12-30 14:05:16 -05:00
nhmall
0c3b9642e4 pmnames mons gender naming plus a window port interface change
add MALE, FEMALE, and gender-neutral names for individual monster species
to the mons array. The gender-neutral name (NEUTRAL) is mandatory, the
MALE and FEMALE versions are not.

replace code uses of the mname field of permonst with one of the three
potentially-available gender-specific names.

consolidate some separate mons entries that differed only by species into a
single mons entry (caveman, cavewoman and priest,priestess etc.)

consolidate several "* lord" and "* queen/* king" monst entries into
their single species, and allow both genders on some where it makes some
sense (there is probably more work and cleanup to come out of this at some
point, and the chosen gender-neutral name variations are not cast in stone
if someone has better suggestions).

related function or macro additions:
    pmname(pm, gender) to get the gender variation of the permonst name. It
    guards against monsters that haven't got anything except NEUTRAL naming
    and falls back to the NEUTRAL version if FEMALE and MALE versions are
    missing.

    Ugender to obtain the current hero gender.
    Mgender(mtmp) to obtain the gender of a monster

While the code can safely refer directly to pmnames[NEUTRAL] safely in the
code because it always exists, the other two (pmnames[MALE] and
pmnames[FEMALE] may not exist so use:
    pmname(ptr, gidx)
      where -ptr is a permonst *
            -gidx is an index into the pmnames array field of the
             permonst struct
pmname() checks for a valid index and checks for null-pointers for
pmnames[MALE] and pmnames[FEMALE], and will fall back to pmnames[NEUTRAL] if
the pointer requested if the requested variation is unavailable, or if the
gidx is out-of-range.

Allow code to specify makemon flags to request female or male (via MM_MALE
and MM_FEMALE flags respectively)to makedefs, since the species alone doesn't
distinguish male/female anymore. Specifying MM_MALE or MM_FEMALE won't
override the pm M2_MALE and M2_FEMALE flags on a mons[] entry.

male and female tiles have been added to win/share/monsters.txt.
The majority are duplicated placeholders except for those that were
separate mons entries before. Perhaps someone will contribute artwork in the
future to make the male and female variations visually distinguishable.

tilemapping via has the MALE tile indexes in the glyph2tile[]
array produced at build time. If a window port has information that the
FEMALE tile is required, it just has to increment the index returned
from the glyph2tile[] array by 1.

statues already preserved gender of the monster through STATUE_FEMALE
and STATUE_MALE, so ensure that pmnames takes that into consideration.

I expect some refinement will be required after broad play-testing puts it to
the test.

    consolidate caveman,cavewoman and priest,priestess monst.c entries etc

This commit will require a bump of editlevel in patchlevel.h because it alters
the index numbers of the monsters due to the consolidation of some. Those
index numbers are saved in some other structures, even though the mons[] array
itself is not part of the savefile.

Window Port Interface Change

Also add a parameter to print_glyph to convey additional information beyond
the glyph to the window ports. Every single window port was calling back to
mapglyph for the information anyway, so just included it in the interface and
produce the information right in the display core.

The mapglyph() function uses will be eliminated, although there are still some
in the code yet to be dealt with.

win32, tty, x11, Qt, msdos window ports have all had adjustments done to
utilize the new parameter instead of calling mapglyph, but some of those
window ports have not been thoroughly tested since the changes.

Interface change additional info:

    print_glyph(window, x, y, glyph, bkglyph, *glyphmod)
            -- Print the glyph at (x,y) on the given window.  Glyphs are
               integers at the interface, mapped to whatever the window-
               port wants (symbol, font, color, attributes, ...there's
               a 1-1 map between glyphs and distinct things on the map).
            -- bkglyph is a background glyph for potential use by some
               graphical or tiled environments to allow the depiction
               to fall against a background consistent with the grid
               around x,y. If bkglyph is NO_GLYPH, then the parameter
               should be ignored (do nothing with it).
                -- glyphmod provides extended information about the glyph
               that window ports can use to enhance the display in
               various ways.
                    unsigned int glyphmod[NUM_GLYPHMOD]
               where:
                    glyphmod[GM_TTYCHAR]  is the text characters associated
                                          with the original NetHack display.

                    glyphmod[GM_FLAGS]    are the special flags that denote
                                          additional information that window
                                          ports can use.

                    glyphmod[GM_COLOR] is the text character
                                       color associated with the original
                                       NetHack display.

Support for including the glyphmod info in the display glyph buffer
alongside the glyph itself was added and is the default operation.
That can be turned off by defining UNBUFFERED_GLYPHMOD at compile time.
With UNBUFFERED_GLYPHMOD operation, a call will be placed to map_glyphmod()
immediately prior to every print_glyph() call.
2020-12-26 11:23:23 -05:00
nhmall
ac9ba38449 file header bump from "NetHack 3.6" to "NetHack 3.7" 2020-08-03 22:07:36 -04:00
Michael Meyer
61cc0e3d51 Formatting 2020-07-22 09:25:05 -04:00
PatR
74e0be478a remove old bonesid workaround
Noticed when the comment about "this can go away when compatibility
with 3.6.x is no longer needed" was modified recently.  Make it and
the code it applied to go away.
2020-07-17 10:14:24 -07:00
Michael Meyer
5a2c94f8e3 Rollback changes to NHDT-Date 2020-07-13 11:16:18 -04:00
Michael Meyer
742216540c Check bones data directly for deja vu messages
After modifications to amnesia, `deja vu' messages are now displayed
upon entering a level containing bones of a previous character of the
current player. This test is done simply by checking for a ghost on the
level that shares a name with the current character.

However, since ghosts generated in other circumstances (such as in the
Valley of the Dead and other special levels) can have names pulled
randomly from the high score list, etc, this message can be displayed on
non-bones levels where a ghost has been generated with the character's
name. Additionally, when a bones pile doesn't include a ghost (such as
when the character in question was slimed, killed by a wraith, etc), the
`deja vu' message will not be displayed when it should be. This is all
described in in NetHack/NetHack#322.

This commit changes the method of testing for `familiarity' by adding a
function to iterate through any bones data for the current level,
searching for a match to the hero's name.

Should fix NetHack/NetHack#322.
2020-07-13 01:06:48 -04:00
nhmall
1443ceecc5 more patchlevel consolidation 2020-07-07 08:55:11 -04:00
nhmall
5a437b336a remove SYSFLAGS and MFLOPPY code
A check into github issue 364 confirmed that
ba6edbe5dc
had incorrectly updated the bwrite sizeof entry for sysflags.

The SYSFLAGS and MFLOPPY code is all in the outdated part of the tree, so just
remove it rather than re-correct it.

Closes #364
Closes #207
2020-07-05 08:50:13 -04: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
a213811975 stone/unexplored glyph follow-up
typo
2020-02-13 17:37:55 -05:00
nhmall
d37fa196b2 make a distinction between rock and unexplored area
This adds a pair of new glyphs: GLYPH_UNEXPLORED and GLYPH_NOTHING

GLYPH_UNEXPLORED is meant to be the glyph for areas of the map that
haven't been explored yet.

GLYPH_NOTHING is a glyph that represents that which cannot be seen,
for instance the dark part of a room when the dark_room option is
not set.  Since the symbol for stone can now be overridden to
a players choice, it no longer made sense using S_stone for the
dark areas of the room with dark_room off. This allows the same
intended result even if S_stone symbol is mapped to something visible.

GLYPH_UNEXPLORED is what areas of the map get initialized to now
instead of STONE.

This adds a pair of new symbols: S_unexplored and S_nothing.

S_nothing is meant to be left as an unseen character (space) in
order to achieve the intended effect on the display.

S_unexplored is the symbol that is mapped to GLYPH_UNEXPLORED, and
is a distinct symbol from S_stone, even if they are set to the same
character. They don't have to be set to the same character.

Hopefully there are minimal bugs, but it is a deviation from a
fairly long-standing approach so there could be some unintended
glitches that will need repair.
2020-02-08 00:48:03 -05:00
nhmall
1dfab5fe11 remove an argument that is no longer necessary from a few functions
Passing a boolean 'ghostly' argument to some functions that are also passed
an NHFILE * is unnecessary now.
2020-02-02 22:54:44 -05:00
PatR
0166239a22 simplify achievement tracking for special objects
This turned out to be a lot more work than I anticipated, but it is
definitely simpler (other than having #wizmakemap take achievements
away if you replace the level that contains the 'prize', which wasn't
handled before).

I cheated and made Mine's End into a no-bones level because the new
flagging scheme for luckstone, bag, and amulet can't carry over from
one game to another.  It probably should have been no-bones all along.
Sokoban didn't have this issue because it's already no-bones.

Existing save files are invalidated.
2020-01-24 13:54:23 -08:00
nhmall
480c3eb6e0 include/lev.h is an empty header file so just get rid of it 2019-12-14 17:18:48 -05:00
nhmall
2dad98d55e Xcode updates 2019-12-14 10:53:12 -05:00
nhmall
2592db64e3 Merge branch 'NetHack-3.7' 2019-12-13 17:41:03 -05:00