Commit Graph

16999 Commits

Author SHA1 Message Date
PatR
7fa328fda3 redo itemized shop billing for containers
Finish shop changes begun in 2674a9904d.

Fix the longstanding bug where shop paying with itemized buying would
reveal container contents if any unpaid items were inside containers,
regardless of whether the containers' contents were known yet, even
when the container was a locked box/chest or a cursed bag of holding.
Paying by menu made that be more noticeable but it has been present
ever since itemized paying was introduced.  I can't find any old bug
reports for it though.  I did find an old message of mine that claims
it's in bugzilla with a "#Hnnnn" tag.

This changes how buying containers and their contained items behaves.
It's now an all or nothing operation.  Itemized billing will list
the container but not contents, and to buy what is inside you need
to pay for the whole thing as a single unit.  If the container itself
is unpaid then its price is part of that item's total cost.  If it is
hero-owned than it is listed as an item to buy but doesn't increase
the cost derived from its unpaid contents.  (If you decline to pay,
hero will still own the container and still owe for unpaid contents.)
2024-07-02 14:52:49 -07:00
PatR
14d0e48e73 less verbose sanity checking
If the 'sanity_check' option triggers a warning, don't show the
"Program in disorder!  (Save and restore might fix this.)" and
"Report these messages to <devteam>." messages and also don't run
the crash report submission.

Doesn't affect the fuzzer because it escalates impossible() to
panic() before reaching those extra messages.
2024-07-01 00:44:42 -07:00
PatR
dc9d0e279f suppress sanity_check for invalid command ESC
If sanity_check starts spewing out warnings, don't run it again if
player types ESC when the program finally asks for the next command
(rather than --More--).

Also, some reformatting of the main command table.
2024-06-30 17:33:41 -07:00
PatR
02ddbf001b shk.c menu-pay comments 2024-06-28 09:04:55 -07:00
PatR
17e0385f0e shk.c and priest.c vs 'onefile' 2024-06-28 08:31:49 -07:00
PatR
2674a9904d github issue #1249 - menu pay of contained items
Issue reported by ars3niy:  unpaid containers containing one or
more other unpaid items appear on the menu for 'p' along with
separate menu entries for those other items.  Buying the container
buys the contents too, then if any of the contents were also picked
in the menu, an attempt will be made to pay for them separately.
Since they are no longer on the bill by that point, that triggers
an impossible warning.

This fixes that by paying for the container but not its contents.
(Temporarily, until more extensive changes get implemented.)  Then
those contents will still be on the bill.  It they've been chosen
in the 'p' menu, paying for them will work as expected.

This also fixes the pay menu for the case where the bill contains
any instances of a partly used up portion of some stack and also
the unpaid intact portion of the same stack.  With itemized billing,
you are allowed to buy the used up portion separately, then maybe
drop the unpaid portion.  (If you try to pay for the intact portion,
the shk won't accept the payment and will tell you to pay for the
used up portion first.)  With the recently added menu for billing,
they were lumped together as a single item and you had to pay for
their whole stack.

And it fixes a much older bug dealing with the cheapest item on
the shop bill.  If you don't have enough to pay for that, the rest
of buying gets skipped.  But stacks that had used up and intact
portions were lumping those together instead of separately checking
the two portions for possibly being the cheapest, so it was possible
to have enough gold to pay for one portion but be told that you
couldn't affort to pay for anything.  If it was the intact portion,
you wouldn't be able to buy it anyway, but if the cheapest item was
used up portion, being told you didn't have enough gold was wrong.

This commit does not fix the longstanding bug that itemized billing
reveals the contents of containers which haven't been opened.  It
was intended to do so but I've run out of steam.

(There is groundwork for that, where buying a container would
include payment for its unpaid contents without revealing what those
are, and they couldn't be purchased separately unless they get taken
out of the container.  Uncommenting '#define CONTAINED_BUYING' will
enable it, with updated pay menu handling but without being able to
pay for non-empty containers.)

Fixes #1249
2024-06-27 14:13:39 -07:00
PatR
0604b3ea22 github PR #1259 - counts in curses menus
Pull request from mkuoppal:  curses menu handling could go out of
bounds accessing array groupaccels[] if strange input gave a false
positive for STDC's isdigit().  Discovered by debug fuzzer.

Failure was triggering an error by the undefined behavior sanitizer.

[randomkey() ought to return int rather than char.]

Closes #1259
2024-06-22 23:40:27 -07:00
Mika Kuoppala
238d501cce win/curses: Check input range in menu selection fallthrough
curletter is screened to be in valid range in all
other switch/case branches except in the default case,
which is fallthrough.

Add check for valid range in here also, otherwise
array might be addressed with invalid offset.

This should fix the following, found
with UBSAN and #debugfuzzer:

../win/curses/cursdial.c:1558:49: runtime error: index -154 out of bounds for type 'char [256]'
0x5f3857eff140 in menu_get_selections ../win/curses/cursdial.c:1558
0x5f3857ef78c8 in curses_display_nhmenu ../win/curses/cursdial.c:801
0x5f3857edd390 in curses_select_menu ../win/curses/cursmain.c:768
2024-06-22 23:31:22 -07:00
PatR
54138bbbe3 'Ix' fix
This took me a while to track down.  I noticed it while drinking
unpaid potions but didn't expect the issue to be potion-specific.
Affects paying shop bill in addition to examining [former] inventory.

Start with a stack of 3 unpaid potions.
Iu
a - 3 potions of healing (unpaid)
Ix
no used up items

Drink one.
qa
Iu
a - 2 potions of healing (unpaid)
Ix
x - potion of healing

So, far everything's normal.  Note that 'x' is an arbitrary letter
used for expended items when shown in inventory style rather than an
inventory letter or menu choice.

Drink another.
qa
Iu
a - a potion of healing (unpaid)
Ix
x - potion of healing
x - potion of healing

Drink the last one.
qa
Iu
no unpaid items
Ix
x - potion of healing
x - potion of healing
x - potion of healing

In 3.4.3, these last two Ix cases would have had single lines of
'x - 2 potions of healing' and 'x - 3 potions of healing', respectively.

After this fix, they will again--unless potion stack 'a' was wielded,
readied as alt-weapon, or quivered.
2024-06-21 15:32:46 -07:00
PatR
bf1e3d3e56 more obj->where == OBJ_DELETED 2024-06-21 14:26:48 -07:00
PatR
d5d646a9e9 ancient comment typo/thinko
Change "it gets size gets reduced" to "its size gets reduced".
This was present in 3.4.3, doubtless even ealier.
2024-06-21 13:32:21 -07:00
PatR
07de17d747 obj->where == OBJ_DELETED
The list of possible object locations used when formatting obj->where
wasn't updated when the objs_deleted list was introduced.  If object
sanity checking ever tried to report it for something, it would have
been described as "unknown[9]" rather than as the intended "deleted".
2024-06-21 12:57:31 -07:00
PatR
0cc134bb95 \#force feedback
A fairly recent change to improve the message given when hero isn't
able to force a locked chest due to type of weapon or weapons being
wielded had one of the text substitutions backwards.  If wielding 1
dart, it gave
|You can't force anything with those weapon.
and if wielding more than 1,
|You can't force anything with that weapons.
2024-06-18 14:12:21 -07:00
PatR
a2c2e0b1c6 fix github issue #1250 and #1229 - ^A issues
Reported by ars3nly as "#1250: Repeating #sit causes a sitting loop",
with a followup comment describing how to reproduce easily, and by
Umbire as "#1229: Curses and extended command menus".  Repeat count
from previous command carried over to current command when ^A was
used to re-run the current one.

Reset 'last_command_count' every time a repeat count is obtained,
even when the new one is 0.  This is a much simpler fix than what
was used with several previous attempts, but it seems to be working.

The do-again code is convoluted, but the tricky bit was the fact
that this problem only happened when number_pad was On with repeat
counts entered as 'n<digits>'.  I still don't understand that aspect,
but it wasn't happening for count of simple '<digits>', making
reproducing it by someone who doesn't use number_pad be difficult....

Closes #1229
Closes #1250
2024-06-17 15:17:50 -07:00
Pasi Kallinen
078e22be2e Query menu for hide or spin web monster ability 2024-06-17 18:12:12 +03:00
PatR
c2f717cd65 altmeta vs number_pad
While testing a potential fix for issue #1250, I discovered that
using the altmeta option, to simulate typing Alt+x to get M-x via
typing 'ESC x', didn't work after a count prefixed by 'n' when in
number_pad mode.  It did work as intended for !number_pad when a
repeat count prefix is entered via digits without 'n'.

This doesn't solve #1250, which also occurs for number_pad but not
for !number_pad.
2024-06-17 04:23:34 -07:00
Pasi Kallinen
78bf0db5b3 Fix copypaste error 2024-06-15 19:04:57 +03:00
Pasi Kallinen
89ea47f702 Monsters can track hero through fixed teleport traps
Also make fixed teleport traps always trigger when entered.
2024-06-15 18:44:30 +03:00
PatR
4e1b6411bf comment thinko 2024-06-14 12:22:16 -07:00
Pasi Kallinen
951401e52a Allow fixed-destination teleport traps
Add a theme room with multiple visible teleportation traps
which will always teleport to specific locations in the same level.

Teleport trap change from xNetHack by copperwater <aosdict@gmail.com>.
2024-06-14 19:50:20 +03:00
Pasi Kallinen
a8099edca6 Accessibility: message locations 2024-06-14 13:33:48 +03:00
PatR
24e06171db fix issue #1256 - no_of_wizards incorrect \
if Wizard escapes the dungeon

Reported by vultur-cadens:  a fix to prevent quest feedback when quest
nemesis is removed from the game during bones creation introduced a
regression for an earlier fix that kept context.no_of_wizards up to
date if the Wizard of Yendor escapes the dungeon without dying.

Change 'wizdead()' to 'wizdeadorgone()' and call it from m_detach()
for mongone() as well as for mondead().

Fixes #1256
2024-06-13 12:18:17 -07:00
Pasi Kallinen
30d2eeea41 Accessibility: more monster message locations, pt 2 2024-06-13 19:41:41 +03:00
Pasi Kallinen
6c1a883f90 Accessibility: more monster message locations 2024-06-13 19:27:34 +03: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
nhmall
a86b9e6899 update tested versions of Visual Studio 2024-06-13 2024-06-13 09:05:01 -04:00
PatR
73f46845ca refine wizard mode throne #sit 2024-06-12 12:35:08 -07:00
PatR
9896a81d6c wizard mode control of throne sitting outcome
When debugging, allow player to choose which outcome for #sit on a
throne (just 1 to 13; no menu; player has to check source to figure
out what the values mean).  Also when the chance to use up the throne
afterward comes up, prompt whether to honor it (similar to drying up
a fountain).

Added to ease testing for github issue #1250 but I still haven't been
able to produce anything odd with ^A after #sit whether or not it was
preceded by a counted action that got interrupted before the count
expired.
2024-06-11 14:15:33 -07:00
PatR
b9baaeb139 comment thinko 2024-06-10 12:09:19 -07:00
nhmall
d04c0f00ed follow-up bit (from leading tab replacements) 2024-06-10 11:02:52 -04:00
nhmall
588b3ae92f replace some leading tabs that had crept in 2024-06-10 10:57:59 -04:00
PatR
bc897ac69c fixes entry type fix, plus expansion 2024-06-09 14:30:40 -07:00
PatR
05cbbc7181 fix PR #1254 - avoid signed integer overflow
Pull request from mkuoppal:  avoid integer overflow when user types
digits and they're combined into a number by successively multiplying
intermediate value by 10 and adding new digit.  Needed to avoid
triggering undefined behavior if the value overflows the largest
signed integer (actually long int).

This is a much more general fix than the code in the pull request,
which imposed an arbitrary limit for one aspect of tty input.

I'm not convinced that integer.h was the right place to add the new
AppendLongDigit() macro.  I may not have caught all the places where
it is needed.  files.c accumulates a value from digits but uses
unsigned int, so overflow won't trigger undefined behavior (although
it presumably ends up with a different value than what was intended).
options.c and coloratt.c accumulate smaller integers and have a limit
on the number of digits they'll use, so can't overflow.

Fixes #1254
2024-06-09 14:17:14 -07:00
PatR
50e9b7f404 out of date 'struct gi' bit 2024-06-09 11:17:54 -07:00
Mika Kuoppala
20f8af224b hints/linux.370: Add support for ubsan (undefined behaviour sanitizer) for gcc
This will add an option to compile and link nethack executable
with ubsan and catch undefined behaviour errors on runtime.
2024-06-09 09:34:57 -04:00
PatR
6718a8af1f fire_damage() vs containers
Containers can't become fireproofed so the line of code in
fire_damage() which tested for that led to confusion.

Also, add missing handling for statues as containers.
2024-06-08 15:22:08 -07:00
PatR
304f18ae16 gdb vs 'gi'
I was trying to examine gi.invent (via
  print ((struct instance_globals_i *)&gi).invent
don't ask...) and gdb gave me very confusing rejections that don't
occur with other g<letter>.variables.  It turned out that gdb was
treating 'gi' as a type rather than as a variable reference.

I suspect it was because Qt was included so linking used C++ mode,
and C++ handles struct names differently from C.  Anyway, renaming
'struct gi' to 'struct glyphinfo' made the mystery problem go away.
2024-06-08 15:04:28 -07:00
PatR
d7008f8fe5 fix #K4189 - dorecover() bug
Restoring was hiding unhidden mimics and if that chose an object
other than boulder of gold pieces, it called mkobj() before an
array used by that routine was initialized.  The result was warning
"rnd(0) attempted" when NH_DEVEL_STATUS wasn't set to 'released' or
divide by 0 crash if it was set to that.

Restore should not be catching up for lost time when unpacking a
save file into individual level files, and if it hadn't done that
it wouldn't hide mimics who aren't currently hidden.

In addition to avoiding that, this also moves the initialization of
the offending mkobj array sooner.

[3.6 didn't use that array so wasn't susceptible to this.  It is
hiding unhidden mimics during what should be a strictly bookkeeping
operation though.]
2024-06-08 13:34:12 -07:00
PatR
d02028fe66 more issue #1253 - shape change vs Eleberth
I happened to restore a save file left over from testing yesterday's
attempt to fix github issue #1253 and had a werejackal change from
human to beast while next to my hero on "Elbereth", then attack me.

This should be sufficient to prevent that.  I'm not sure why the
previous fix attempt seemed to be adequate when testing it.  The new
fix relies on the previous one.
2024-06-05 22:58:44 -07:00
PatR
cfb053157a fix github issue #1253 - shape change vs Elbereth
Issue reported by chadministratorwastaken:  were-creature that was
ignoring Elbereth while in human form would make one more attack
after changing into creature form.

Have new_were() make an onscary() check when changing to beast form
while next to the hero.  Do likewise for polymorphing creature.

Fixes #1253
2024-06-04 23:59:39 -07:00
PatR
8652262105 DEBUGFILES
Fetching a value of DEBUGFILES from the environment to enable
debugpline() messages was intended to operate in wizard mode only
but that wasn't enforced.
2024-06-04 14:53:17 -07:00
PatR
cf2a97dea4 tty invisible cursor
Make the cursor visible when performing a shell escape or pushing
nethack into the background.
2024-06-04 14:45:00 -07:00
nhmall
16ac21297a update tested versions of Visual Studio 2024-05-04 2024-06-04 07:45:23 -04:00
nhmall
8b0ea3f204 remove inappropriate PDCURSES use of stdin,stdout
Use of stdout and stdin was inappropriate for general curses.
Windows GUI links with PDCURSES wingui code.
2024-06-04 06:46:25 -04:00
PatR
6f8ed4c589 tty_curs() again
Honor the objection to an earlier change to tty_curs(), despite the
fact that it seems delusional.  Four integer comparisons per cursor
positioning call affect the throughput of cmov(), but only if the
program is built without DEBUG defined?
2024-06-03 23:23:14 -07:00
PatR
ad0153a328 tty_curs() debugpline()
More analyzer induced hackery.  If tty_curs() discovers that the x,y
passed to it are no good, don't use them, even if that results in
the next output being in the wrong place.

The old issue of behaving differently when built with DEBUG defined
versus when it is not defined is fixed in a different way.
2024-06-03 14:20:21 -07:00
PatR
2ab477459f DEBUGFILES setup
Check getenv("DEBUGFILES") unconditionally during startup rather
than waiting until it's needed.

Might prevent the static analyzer from getting so aggravated.
Most likely not though, but should make debugpline() less fragile
if it gets called during a panic or a signal.
2024-06-03 14:16:49 -07:00
PatR
61d3cce4b8 fix static analyzer complaint in remove_room()
Since croom and maxroom both point to elements in the rooms[] array,
the complaint that the memcpy() in

| if (croom != maxroom)
|  memcpy(croom, maxroom, sizeof (struct room));

might have overlapping source and destination is bogus.  The fix is
trivial but not vetted by the analyzer.
2024-06-03 09:28:38 -07:00
Pasi Kallinen
4e29c9b282 Fix eating non-pyrolisk egg effect 2024-06-03 17:40:50 +03:00
Pasi Kallinen
2bec685bae Pyrolisk eggs explode when broken 2024-06-02 10:50:58 +03:00