nhmall [Tue, 24 Jan 2023 04:50:43 +0000 (23:50 -0500)]
take initial stab at macsound interface
Use macOS AppKit framework routines for a first cut at a
macsound soundlib interface.
Requires WANT_MACSOUND=1 on build.
Nothing has been done to move the stock sounds into the resources
of a bundle, so after building, if you want to try the stock sounds
out:
cp sound/wav/*.wav ~/Library/Sounds
Because the NSSound macOS routines always do the search, supposedly
the following locations are searched in this order:
1. the application’s main bundle
2. ~/Library/Sounds
3. /Library/Sounds
4. /Network/Library/Sounds
5. /System/Library/Sounds
Although not specifically implemented as of yet, it may be pretty
close to being able to put soundeffects wav files (by se_ name)
into ~/Library/Sounds working for the SND_SOUNDEFFECTS_AUTOMAP feature.
Feedback is welcome. Contributions for improving it are even more
welcome.
The new soundlib supporting file is named
sound/macsound/macsound.m since it's got objective C in it.
Known bugs and glitches:
The Hero_playnotes on a set of 5 notes goes too fast, so there
needs to be a slight delay added between the note of a multi-note
play.
PatR [Mon, 23 Jan 2023 19:38:15 +0000 (11:38 -0800)]
reimplement pull request #944 - grave contents
Pull request from entrez: if bones left dead hero's corpse on top
of a new grave, don't find a corpse or summon a zombie when digging
the grave up. It also removed the chance that a ghoul might be
summoned when engraving on a headstone, switching to zombie or mummy
instead.
Rather than adopting the pull request, this retains summoning a
ghoul via engraving and adds the possibly of doing so when kicking
a headstone. Having a ghoul prowl around the grave is independent
of whether there is a corpse or zombie inside the grave. To achieve
this, another flag in 'struct rm' is needed; the single bit for
'disturbed' isn't sufficient. The bigger 'flags' field wasn't in
use for graves so commandeer that for new 'emptygrave'. 'disturbed'
still uses the 'horizontal' bit in order to have engraving and/or
kicking summon at most one ghoul.
nhmall [Mon, 23 Jan 2023 12:42:06 +0000 (07:42 -0500)]
comment out sample.c inclusion in Makefile.nmake
Makefile.nmake
A sample file that was tested for compilability was left in
the Makefile. Harmless if you have the sample.c in the right
place on your machine. Fatal to the build if you do not.
Pasi Kallinen [Mon, 23 Jan 2023 06:05:22 +0000 (08:05 +0200)]
Increment editlevel
Commit 0f257ec538242d (nhlua.c static analyzer fix) changed
a variable from long to unsigned, but the var is also saved
to the save file, so broke save compat.
nhmall [Sun, 22 Jan 2023 18:29:44 +0000 (13:29 -0500)]
further utilize sound interface - part 2
Expand windsound to support SNDCAP_USERSOUNDS (existing),
SNDCAP_SOUNDEFFECTS, SNDCAP_HEROMUSIC.
Place a small number of wav files into sound/wav that are considered
more specific to some game stuff in the core, namely: playing
instruments by the hero, squeaky board traps. The intention is that
those ones can be integrated into the game without requiring user
file deposits or mappings. Building soundlib support for sound/windsound
searches for them as resources, so they should "just work."
No actual instrument playback is available in the base sound/windsound
soundlib implementation (yet, at least), so it works around that in
a cheap way by using the note-variant wav sounds to concoct the
notes. There are better ways of doing music generation than that,
of course, but this will do in the early going. Any other soundlib
port (such as Qt) can probably easily do the exact same thing. If it
can play USER_SOUNDS, it can almost certainly use the
sound/wav/se_squeak*.wav and sound/wav/sound_*.wav files for
SND_HEROMUSIC and squeaky board sounds soundeffects.
A few of the se_ sounds in sound/wav are free yet licensed, and
there is a file called attributions.txt to meticulously attempt
to comply with the two license variations involved.
SND_SOUNDEFFECTS_AUTOMAP
If SND_SOUNDEFFECTS_AUTOMAP is defined, and a SND_LIB_ interface
that supports SNDPROC_SOUNDEFFECTS is also defined to integrate
soundlib support, the following gets added:
o If sounddir is defined (existing longstanding feature that's
been used with USER_SOUNDS for many, many years) any wav file
present in SOUNDDIR with a name that matches one of the defined
sound effects in include/sndproc.h will get played each time
that soundeffect comes up. So, just drop appropriate wav files
into sounddir and rename it to match.
No tedious config file entries are required to get soundeffects.
[ The only config file change required is to
set SOUNDDIR to point to your directory with the wav files.
Note: SOUNDDIR only works in your config file if NetHack
was built with USER_SOUNDS defined. ]
This is new so there may certainly be some bugs in here.
Please kindly report them if you encounter any.
For those that don't read C very well, these are the file names
that should trigger the SOUNDEFFECTS_AUTOMAP, assuming it is working.
PatR [Sun, 22 Jan 2023 09:43:20 +0000 (01:43 -0800)]
fit git issue #960 - out-of-bounds array access
Issue reported by argrath: if getoptstr() executed its loop to
find the latest phase that set a role/race/gender/alignment option
value, the first iteration of the loop would use an index that's
out of bounds.
The code in question is wrong but happens to not be used, so the
out of bounds access doesn't occur. Fix the value for the first
iteration in case the offending code eventually gets used.
Michael Meyer [Thu, 5 Jan 2023 18:27:39 +0000 (13:27 -0500)]
Fix: underwater vision update frequency
Underwater vision was updated only once per turn, so if the hero had
more than one move per turn it could cause some spots to be left behind
on the map. For example, after moving around underwater while very fast
for a while:
}
}}}
}}}}
} }}@}
} }}}
Not only does the radius of vision appear to "smear" temporarily, but if
the hero moves fast enough, isolated spots can be left entirely behind
(since the normal underwater vision update only clears nearby spots, not
the entire map). Both these effects are visible in the example above.
The fix in this commit is to update the frequency of underwater vision
updates to "once-per-time-taken" rather than "once-per-turn", so that it
updates with every move. I'm not sure if it needs to happen more
frequently than that (i.e. in the "once-per-input" section) but I might
be overlooking something.
Also add missing punctuation to the message for applying a lamp
underwater.
Pasi Kallinen [Sat, 21 Jan 2023 14:52:17 +0000 (16:52 +0200)]
Hit and wake sleeping monster makes it growl
Unless you kill the monster with one hit, it'll wake up
cranky and make noise - waking up other sleeping monsters.
This was a bit tricky with all the message sequencing; I tested
all the hit/throw/fire/zap combos I could think of, and it took
a while to get things looking right.
PatR [Sat, 21 Jan 2023 09:52:04 +0000 (01:52 -0800)]
analyzer vs eat.c
scan-build from llvm-14 (clang) doesn't complain about bite() or
maybe_finished_meal() so this is unlikely to fix those. But this
does fix one bogus complaint it has for doeat(). Testing whether
the result from touchfood() is Null was fooling it into thinking
that that was a possibility when it's not.
Also, use plain 1 and 0 instead of TRUE and FALSE when assigning
to the victual bit-fields. The analyzer doesn't care but the type
was mismatched due to the cast to (boolean) hidden in their macro
definitions.
Pasi Kallinen [Sat, 21 Jan 2023 08:05:44 +0000 (10:05 +0200)]
Unify monster-consumes-object
This code was in three different places; pet eating,
monster eating metal, and monster eating other objects.
Other than very minor changes (eg. rustproofing completely
protects pets from bad effects, rustproof items are no longer
giving apport, and monsters eating corpses are healed), it
should behave the same as before... But I haven't exhaustively
gone through every iteration.
nhmall [Sat, 21 Jan 2023 01:51:31 +0000 (20:51 -0500)]
fix misplaced brace; also relocate Soundeffect()
The brace added to dokick was misplaced - it should have included
the You_hear() as well.
The puts the code back the way it was, and relocates the Soundeffect().
The Soundeffect should play whether the hero is Blind or not, and the
Soundeffect() macro already includes a Deaf guard.
PatR [Sat, 21 Jan 2023 01:18:27 +0000 (17:18 -0800)]
new static analyzer fix - nhlua.c
Cope with get_nh_lua_variable() possibly returning Null.
Either or both of the DISABLE_WARNING_UNREACHABLE_CODE and
RESTORE_WARNING_UNREACHABLE_CODE in the vicinity looked misplaced so
I took them out. They may need to be added back in.
That macro definition checks for the hero not being Deaf; it checks
to ensure that the active soundlib interface has a non-null
sound_soundeffect() function pointer; and it checks to ensure
that the active soundlib interface has declared that it supports
soundeffects by setting the SNDCAP_SOUNDEFFECTS bit in its sndcap
entry. That just means that the interface routines are prepared to
accept and deal with the calls from the core, whether or not it
actually produces the desired soundeffect.
Pasi Kallinen [Fri, 20 Jan 2023 12:35:30 +0000 (14:35 +0200)]
Fix mouse menu movement
When using mouse to move to a location next to the hero,
the test_move result was reversed, causing the click to fall
in to the travel case instead of normal movement.
nhmall [Thu, 19 Jan 2023 23:51:42 +0000 (18:51 -0500)]
add an interface for sound libraries
Groundwork for a more versatile interface for using
sound libraries. A lot of sound libraries work across
multiple platforms.
The current NetHack sound stuff is quite limited.
Binaries can have a variety of window ports linked into
them, and it makes sense to have something similar for
sound.
This tries to set things up in a more soundlib-centric way,
rather than inserting things in a platform-centric way.
It establishes a new top-level directory sound (akin to win
for the window interface routines, or "window-port") where
sound-related additions and sndprocs and support files can be
added and used across platforms.
The default interface is nosound and the 'nosound' interface
is in src/sounds.c
The interface for 'windsound', which contains the same minimal
USER_SOUNDS support using built-in routines that has been in the
windows port for a long time is added to
sound/windsound/windsound.c.
For now, the sound interface support for 'qtsound' has been added
to the existing Qt files win/Qt/qt_bind.h and win/Qt/qt_bind.cpp,
and a note has been placed in sound/qtsound/README.md to avoid
confusion.
PatR [Thu, 19 Jan 2023 06:00:57 +0000 (22:00 -0800)]
add Japanese item names to discoveries list
When playing as a Samurai, add things like "osaku" to the discoveries
list even though they don't have separate descriptions to be used
when not yet discovered. Non-magic ones are pre-discovered and
players can now use the '\' command to figure out what things like
"tanko" mean without resorting to '/?'.
"wooden harp" has been getting changed to "koto (harp)"; make that be
| koto [wooden harp] (koto)
"magic harp" has been staying as "magic harp (harp)"; add it to the
list of Japanese item names. Since it's magic it isn't pre-discovered.
Once discovered it becomes
| magic koto [magic harp] (koto)
Those two needed special case handling, none of the other items did
aside from forcing them to be discoverable when lacking descriptions.
The discoveries list now has things like
| wakizashi [short sword]
| naginata [glaive] (single-edged polearm)
| gunyoki [food ration]
if--and only if--the hero is a Samurai.
PatR [Wed, 18 Jan 2023 19:57:49 +0000 (11:57 -0800)]
pacify static analyzer - vision.c
Include some assertions to convince the analyzer that some pointers
can't be Null. They're Null if 'vis_func' is non-Null but only used
when that function pointer is Null and they have values.
If there's a macro that's defined when the analyzer is running and
undefined when not--or vice versa--it could be used to control NDEBUG
and avoid the assertion code when not analyzing. That's a bit like
using fake code to pacify 'lint'; however, since the assertions should
never fail, suppressing them isn't really switching to fake code.
I reordered a couple of macros so that the set of them matches the
comment which precedes them and refers to "the last three". It is
referring to the three within the block comment rather than the macro
defintions but putting those in the same order removes any ambiguity.
PatR [Wed, 18 Jan 2023 00:31:59 +0000 (16:31 -0800)]
maybe pacify static analyzer - eat.c
The complaint is that victual.canchoke might be used without having
been initialized. I'm fairly sure that that isn't correct but get
dizzy trying to trace through the eating code.
PatR [Tue, 17 Jan 2023 18:42:00 +0000 (10:42 -0800)]
pacify static analyzer - dog.c
This is similar to the earlier potential fix that I didn't like,
but I think think one is better.
The analyzer claimed that 'fptr' might be Null inside the switch
case for
|struct permonst *fptr = NULL;
|if (obj->otyp == CORPSE || ...) fptr = &mons[obj->corpsenm];
|switch (obj->otyp) { case CORPSE: ... /* dereference 'fptr' */ }
even though it will always have a non-Null value for otyp==CORPSE.
Make the assignment of 'fptr' unconditional. mons[NUMMONS] is
valid and won't match any actual monster. In this case it will
only be used when initializing fptr, never when fptr gets used.
Pasi Kallinen [Tue, 17 Jan 2023 18:07:24 +0000 (20:07 +0200)]
Level temperature
Allow setting a per-level "temperature": hot, cold, or temperate
via special level flags. Currently it only affects some messages
in Gehennom, but it could be expanded to ice melting, water freezing,
or monster generation, for example.
Pasi Kallinen [Mon, 16 Jan 2023 07:40:05 +0000 (09:40 +0200)]
Fix deleting worn object
When going down stairs while punished, if you had quivered a mirror
and the mirror was dropped because you fell down the stairs, it would
not have been unequiped.
PatR [Sun, 15 Jan 2023 19:04:35 +0000 (11:04 -0800)]
generic object fix
When hallucinating, random object selection for objects was including
the new generic objects. It was already excluding 'strange object'
by using 'rn2(NUM_OBJECTS - 1) + 1' to skip objects[0]; changing that
to be 'rn2(NUM_OBJECTS - MAXOCLASSES) + MAXOCLASSES' will skip the
first 18 objects, 'strange object' plus the 17 generic objects.
(I'm trying to convince myself that there's no off-by-1 or off-by-N
error and think I've succeeded.)
PatR [Sun, 15 Jan 2023 09:45:14 +0000 (01:45 -0800)]
strange object vs generic objects
Try to fix a fuzzer issue. I wasn't able to reproduce it so am not
sure whether this actually fixes it. A mimic seemed to be mimicking
object #1 (generic ILLOBJ_CLASS object which shouldn't occur) rather
than #0 (strange object). Strange object always has dknown==1 and
generic objects should always have dknown==0 but farlook of mystery
object #1 had its dknown flag set.
An earlier fix to force non-Null oc_name when formatting objects in
order to pacify the static analyzer might have been the reason that
the problem couldn't be reproduced.
This includes a few miscellaneous changes made while unsuccessfully
hunting for the problem.
PatR [Sat, 14 Jan 2023 07:55:37 +0000 (23:55 -0800)]
another static analyzer bit - cast_protection()
The code tested u.uswallow and then accessed u.ustuck. Under normal
circumstances that works fine but it could be a problem if the two
fields got out of synch. This ought to fix the analyzer complaint
and avoid any trouble with mondata access.
PatR [Sat, 14 Jan 2023 07:41:23 +0000 (23:41 -0800)]
another static analyzer bit - Japanese_item_name()
The analyzer complained that the second call to Japanese_item_name()
might return Null after the first one didn't.
| if (Role_if(PM_SAMURAI) && Japanese_item_name(otyp))
| actualnm = Japanese_item_name(otyp);
even though the code involved is self-contained and deterministic.
Then later in obj_typename() 'actualnm' gets passed to strcat() or
strcpy() where Null isn't acceptable.
Could probably fix that by caching and reusing the first return value:
| if (Role_if(PM_SAMURAI) && (jname = Japanese_item_name(otyp)) != 0)
| actualnm = jname;
but I went a different route, revising that routine to take a second
argument:
| if (Role_if(PM_SAMURAI))
| actualnm = Japanese_item_name(otyp, actualnm);
It now passes back 'actualnm' instead of Null when no substitution
takes place.
The recent introduction of generic objects without names meant that
'actualnm' could actually be Null, but generic objects only occur
for map glyphs and only when dknown is 0, so the actual-name field
shouldn't ever be get used for them. Give actualnm a fallback value
just in case.
Wishing is a place that loops over all of objects[] so have it skip
the generic objects. They're all flagged no-wish so weren't being
chosen, but explicitly skipping them makes the intention clear.
Redo the restore_waterlevel() code a bit to eliminate a static
analyzer complaint. The previous code would not have done the right
thing if 'gb.bbubbles' was already non-Null, but that should not be
possible. I didn't backtrack to make sure that it was always Null
at the time restore_waterlevel() gets called.
Pasi Kallinen [Thu, 12 Jan 2023 21:15:51 +0000 (23:15 +0200)]
Deadly afflictions and resistances for safe_wait
Amend the safe_wait so it still waits if you have a deadly property,
even if you have a resistance to it.
External resistances do not protect against already existing
deadly properties, for example becoming deadly ill is not cured
even if you wear a green dragon scale mail.
nhmall [Thu, 12 Jan 2023 21:04:40 +0000 (16:04 -0500)]
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.
nhmall [Thu, 12 Jan 2023 20:38:15 +0000 (15:38 -0500)]
more ATTNORETURN
A recent commit to alloc.c by Keni drew attention to the fact that
there are extern prototypes scattered around in various .c files.
Those can make use of ATTRNORETURN (non-gcc compilers and C23) the
same way the prototypes in extern.h can, and they were overlooked
when ATTRNORETURN was first added.
nhmall [Thu, 12 Jan 2023 18:10:33 +0000 (13:10 -0500)]
add some tile credit where it is due
Since tile files can now contain comments, incorporate the comments
that accompanied some contributions that were adopted back when
male and female tile differentiation became possible.
If the original contributing artist wants to alter their name or handle
that was used in any of the credits, or wants to change any comment text,
please send your corrections to devteam@nethack.org.
Or, better yet, do a pull request with your desired alterations.
Alternatively, if they are fine as they are, a note to devteam@nethack.org
acknowledging that would be welcome, but certainly not required.
PatR [Thu, 12 Jan 2023 11:12:56 +0000 (03:12 -0800)]
fix github issue #955 - tile2bmp bounds failure
Issue reported by argrath: building with 'address sanitizing'
reported tile2bmp writing out of array bounds after the addition
of the generic object tiles.
'MAGICTILENO' in tile2bmp.c is extremely fragile. It was already
inaccurate before the generic tiles, but had a big enough value to
handle the final row of tiles prior to that.
PatR [Tue, 10 Jan 2023 22:33:21 +0000 (14:33 -0800)]
displaying generic objects
Add 17 fake objects to objects[], one for each object class. All
specific color as gray. They're grouped at the start--actually near
the start since "strange object" is still objects[0]--rather than
being among the objects for each class. init_object() knows to start
at [MAXOCLASSES] instead of [0]; other code that loops through every
object might need adjusting.
For potions, non-stone gems, and non-novel/non-Book_of_the_Dead
spellbooks that don't have obj->dknown set, display the corresponding
generic object rather the object itself. Fixes the longstanding bug
of seeing color for not-yet-seen objects whose primary distinguishing
characteristic is their color. Walking next to a generic object
while able to see its spot will set dknown and redraw as specific.
It's slightly disconcerting to have objects change as you reach them;
I hope it's just a matter of becoming used to that. (If there is any
code still changing the hero's location manually instead of using
u_on_newpos(), it should be changed to use that routine.)
Most of the new tiles are just a big rendering of punctuation
characters. The potion, gem, and spellbook ones could be cloned from
a specific object in their class and then have the color removed. I
started out that way but wasn't happy with the result. I'm not
artisticly inclined; hopefully someone else will do better. Each of
them is preceded by a comment beginning with "#_"; the underscore
isn't required, just being used to make the comments stand out a bit.
Pasi Kallinen [Mon, 9 Jan 2023 20:25:23 +0000 (22:25 +0200)]
More interesting Gehennom levels
Instead of just plain old boring mazes, spice up Gehennom by
occasionally adding lava, iron bars, or even mines-style levels
(with lava, of course).
Of the fixed Gehennom levels, only Asmodeus' lair has been changed
to add some random lava pools.
Also some lua fixes and changes:
- Fixed a selection negation bounding box being wrong.
- Fixed a selection negated and ORed returning wrong results.
- des.map now returns a selection of the map grids it touched.
- When using des.map contents-function the commands following the
map are not relative to it.