Commit Graph

16419 Commits

Author SHA1 Message Date
PatR
1bfde1eb6a itermonarr comments
Fix several typos/thinkos about 'itermonsiz' and remove an obsolete
remark about 'monarr'.
2024-01-26 11:57:01 -08:00
Pasi Kallinen
39fb072a92 Simplify rhack and parse
AFAICT, we only used the first char of the "command_line" string.
Just turn it into int to hold the key the main input loop parse() got.

Shouldn't have any functional difference.
2024-01-26 15:19:24 +02:00
PatR
17414c500a more monster iteration
Re-use the array allocated for iterating over all monsters during
monster movement much of the time.  It was being allocated from
scratch for each round of monster movement, then freed after they
moved, then repeated the next round.
2024-01-25 23:59:32 -08:00
PatR
9cd1a571ae more weight tweaks
Update some potential weight issues.  Eggs won't hatch when in
containers so they weren't affected but add some bulletproofing.
Corpse revival from inside containers was already ok too, so
effectively there's no change except for making container_weight() be
global instead of local to mkobj.c.
2024-01-25 23:09:12 -08:00
PatR
ec4691a859 fewer human corpses
When a low-level trap is created with a dead pseudo-adventurer,
usually make a player monster when the human case gets picked.

They have default level and no inventory.  They should probably be
given montraits that force low level but this doesn't do that.
2024-01-25 14:12:05 -08:00
nhmall
fa672fa1ba some utf8map corrections
Correct a color value and remove an unnecessary variable
2024-01-25 16:45:58 -05:00
PatR
4512e85e58 fix hero Strength
The recent acurr() changes introduced a bug that caused Str less
than 25 to be limited to 18/07.  25 was treated correctly as a
special case but 18/01 through 18/100 and 19 through 24 were not.
The cap of 25 imposed on the other characteristics is the same as
encoded Str 18/07.
2024-01-25 13:17:23 -08:00
PatR
500cbb0b11 comment typo 2024-01-25 12:20:00 -08:00
PatR
1c08982d56 Strlen_()
Restore its ability to reject a string longer than will fit within
size_t that was lost by moving away from strnlen().  Determine the
length inline rather than using strlen().

Move it from hacklib.c to alloc.c so that utility programs have easy
access, and remove the copy of it from dlb_main.c.

Fix a logic bug in str_start_is().  If a string was considered to
be too long, it exited the loop when n was 0 but also performed
post-decrement.  So after the loop, n would be -1 and the 'if (n==0)'
test would fail.  panic() would occur if the initial string matched
and happened to be LARGEST_INT-1 characters long.
2024-01-25 12:16:39 -08:00
Pasi Kallinen
47fa2eb000 Split kicking non-door terrain out of dokick 2024-01-25 21:43:55 +02:00
PatR
4be4f55ccf some reformatting for utf8map.c
and a few omitted 'const's for some constant pointers to constant
characters.

utf8map.c is missing date, branch, and revision tags on its first line.
2024-01-25 11:22:01 -08:00
Pasi Kallinen
cc599cb6cd Split up doengrave
doengrave was the largest function by far, so split it up into smaller
ones.  Use a structure to hold the dozens of variables needed all over it.
Should have no difference in behaviour, but I haven't tested everything.
2024-01-25 18:32:05 +02:00
nhmall
8aadfd794c comment updates
The comments referred to the function pointer variable before those
changed names, so this assumes that they still should.
2024-01-24 18:51:12 -05:00
PatR
de5864b7b4 comment typo 2024-01-24 14:56:21 -08:00
PatR
90d515b6ab fix #K4091 - losexp() assert(u.ulevel < 30) fail
Previously reported via github pull request #1188 as an out of bounds
access to u.uhpinc[], followed by issue #1189 when it was closed, the
backtrace accompanying new assertion failure provided more information
that led to figuring out the problem.

Only mattered for the debug fuzzer; wouldn't happen in regular play.

When the hero dies during fuzzing, the fuzzer sometimes restores lost
levels via blessed potion of restore ability.  If that happened to a
hero who died by being life-drained while at level 1 then losexp()'s
assumption that life-saved hero was still level 1 got violated.  If
levels had been lost all the way down from a peak of 30, restoration
to u.ulevel==30 resulted in invalid array indexing into u.uhpinc[],
then failure of 'assert(u.ulevel >= 0 && u.ulevel < MAXULEV)' which
was added to avoid that.

Pull request #1188 and issue #1189 are already closed, but they hadn't
actually been solved yet.

Fixes #1188
Fixes #1189
2024-01-24 14:31:26 -08:00
Pasi Kallinen
c2ddd2a7c2 Fix some object weight problems
There were few places where the object weight was not updated:

- container when the contents were broken by impact
- starting to eat but getting stopped by rotten food
- using lua, container when putting an object inside it
- when a single egg of a larger stack hatched
2024-01-24 17:58:54 +02:00
Pasi Kallinen
cd74a2a99e Fix Juiblex attacking without knowing your location
Juiblex could expel the hero over water, they'd get relocated to
a safe location, but Juiblex was still thinking they were at
the location it expelled them.
2024-01-24 17:50:04 +02:00
PatR
576dd10bdd fix #K4088 and #K4089 - ring formatting
+/-N for charged rings with known enchantment was clobbering the
BUC formatting that had occurred earlier.  #K4088 thought it was a
problem with the implicit_cursed option; followup #K4089 from same
user correctly pointed out that the problem was present for any BUC
state.

This is the same line of code that inadvertently omitted the space
between +/-N and "ring of <type>".  That was fixed by commit
1a2b2a8cae a couple of days ago.

While in doname(), fix a potential issue calling corpse_xname().
That assigns a new value to gx.xnamep, clobbering the value that
doname() relied on when it was first called (but doesn't look at
again, so doesn't matter now but could conceivably in the future).
2024-01-24 00:37:09 -08:00
PatR
ab4991930a alloc(0)
Have alloc() treat a request for 0 bytes as if it was one for
'sizeof (long)' bytes so that the issue of malloc(0) maybe yielding
NULL becomes moot.

I think instances of attempting to allocate 0 bytes should probably
still be checked for and made to avoid calling alloc(0).  Assuming
that alloc() will clean up requests for nothing feels sloppy.
2024-01-23 23:56:29 -08:00
PatR
78252de3bc fix memory leak in iter_mons_safe()
While hunting for a memory leak in object allocation--which I haven't
found yet--I discovered one in monster movement.  iter_mons_safe()
allocates an array of (monst *) pointers for the monsters on the
current level, loops over that array to call a function for each
one, then frees the array.  But if the game ends while that called
function is running, execution never returns to iter_mons_safe() so
it wasn't able to free the memory.

Since that can happen at most once per game, it wasn't a signifcant
leak.  This fixes it anyway.

There was a second issue:  make sure that iter_mons_safe() doesn't
call alloc(0) to make the temporary array for zero monsters when
there aren't any on the level.  That might not be able to happen for
monster movement but the routine is written to be more general than
just movement.  alloc(0) could confuse the MONITOR_HEAP code.  In
C89/C90 I think malloc(0) is allowed to return NULL (don't recall
for sure; maybe that was just known pre-standard behavior for some
implementations).  Null return would trigger a panic even without
MONITOR_HEAP.  Don't know about C99 and later.
2024-01-23 23:04:06 -08:00
PatR
1d165f20ee supply_chest fix fix
Reordering some tests to put the cheapest one first accidentally
removed a negation, unintentionally changing the semantics.
2024-01-23 16:52:39 -08:00
nhmall
ebd09e94f6 nonnull update for m_harmless_trap()
Both arguments are immediately dereferenced.
2024-01-23 18:50:35 -05:00
PatR
267daeaa0f supply chest fixes for "odd encumbrance behavior"
Changing the quantity to 2 (50:50 chance) when creating a potion of
healing (also 50:50 chance for each attempt) to place inside a supply
chest wasn't updating the potion stack's weight, resulting in the odd
encumbrance behavior that was reported last December.

Taking the stack out of the container doesn't fix the weight but
drinking one of the potions splits the stack of 2 into two stacks
of 1 and does update the weight for both.  That gives the hero higher
encumbrance when the formerly weightless one has its proper weight.
Finishing drinking the potion uses it up, removing second potion's
weight again.  When below an encumbrance threshold by the weight of
one potion or less, player will see encumbrance increase and then
decrease, with healing message given before both due to sequencing.

Supply chests weren't having their own weight updated when they were
populated, so would behave as if empty if hero carried them around.
Removing something, breaking something by kicking the chest, or adding
something would update its weight to match its contents.

I also noticed a refutation (or should that be rebuttable?) to my own
remarks in this:

| commit cd91d0630b
| Author: PatR <rankin@nethack.org>
| Date:   Sat Dec 30 17:10:39 2023 -0800
|
| github issue #1180 - humans and murder
|
| Issue reported by Umbire:  reviving a human corpse into a human
| monster and then killing it entails murder penalty even when it is
| hostile.
|
| This is probably a non-issue.  Human monsters tend to not leave
| human corpses, they leave shopkeeper corpses or sergeant corpses
[...]

Dead fake hero corpses placed at trap locations on early levels are
leaving plain human|dwarf|elf|gnome|orc corpses rather than fake
player monster ones (which are always human but resurrect as player
monsters rather than as plain humans), so there are more plain human
corpses now than there were in 3.6.x or early to-be-3.7.  I've added
a comment about the situation.
2024-01-23 15:42:19 -08:00
Pasi Kallinen
829f9f65f7 Split out harmless-to-monster trap
Also make the code much easier to understand, and
more-or-less match hero trap triggering.
2024-01-23 19:01:34 +02:00
Pasi Kallinen
7fa74d0199 Add LAVAWALL to linedup blocking 2024-01-23 18:37:16 +02:00
nhmall
b2f7c56e95 adjust comment wording for beyond 3.6 2024-01-23 11:00:23 -05:00
Pasi Kallinen
90cc3102f5 Don't use static buffer 2024-01-23 17:56:02 +02:00
Pasi Kallinen
a45f07c9b4 Comment typo 2024-01-23 17:32:32 +02:00
Pasi Kallinen
50df01c3e1 Split out empty hands menu option text 2024-01-23 17:27:07 +02:00
Pasi Kallinen
70d8d9e0d1 Unify getting coords or region from lua table 2024-01-23 13:37:16 +02:00
Pasi Kallinen
bce7c69e77 Unify wake up and scare a monster by music 2024-01-23 13:23:51 +02:00
Pasi Kallinen
49338ebb0a Split gem color randomization 2024-01-23 13:07:52 +02:00
PatR
03827fd184 pull request #1178 - PYEC data.base entry
Pull request from entrez:  revise the Platinum Yendorian Express Card
data.base entry for style and remove out of date assertion that it is
unreadable.

Closes #1178
2024-01-22 17:13:43 -08:00
Michael Meyer
3025e05579 Copyedit PYEC encyclopedia entry
I initially went in here to change the description of "unreadable" text
on the card, since it has been possible to read it in-game since commit
870b124 in 2015.  Then I also ended up making some edits to stylistic
issues I noticed, primarily varying vocabulary to eliminate the
repetition/reuse of words in phrases like "an /ancient/ artifact...
inscribed with /ancient/ runes" and "when /carried/, it grants the one
who /carries/ it ESP, and reduces all spell damage done to the
/carrier/".  The result is a little bit tighter and I think reads
somehwat better.
2024-01-22 17:13:13 -08:00
PatR
bba6942082 remove unused variable 2024-01-22 17:10:14 -08:00
PatR
5540e266c4 pull request #1174 - trapeffect code cleanup
Pull request from entrez:  some old trap code became obsolete or
at least less useful when the trap routine was split into separate
routines for each type of trap.  The type of trap currently being
handled is already known by each of those routines.

Closes #1174
2024-01-22 17:04:02 -08:00
Michael Meyer
a3e8d8eacb Clean up trapeffect code a little bit
Some minor cleanup of artifacts from the splitting up of trap effects
into the various trapeffect_foo functions: consolidate redundant
variables in trapeffect_pit (tt vs ttype), and simplify the definition
of 'inescapable' traps a couple functions (since the functions are now
specialized to a particular trap, it's unnecessary to check ttype
there in determining whether it's an inescapable Sokoban pit or hole).
2024-01-22 17:02:59 -08:00
PatR
36fef49306 pull request #1177 - saving bones
Pull request from janne-hmp:  defer releasing the memory for the
current level by having savebones() using write mode rather than
write+free mode.  nh_terminate() -> freedyanmicdata() will free the
current level.

Matters for 3rd party html dumplog (which nethack doesn't support).

The commit message is misformatted and misleading but it's a bit
late to fix that now.

Closes #1177
2024-01-22 16:56:41 -08: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
PatR
77d7c449e0 build fix for dlb 2024-01-22 13:31:48 -08:00
PatR
fabc9033aa loadstone bit
If your inventory is full and you aren't already carrying a loadstone,
you can pick one up into the overflow slot.  But if you are already
carrying one and the one you're trying to pick up won't merge with it
(only criterium that matters would be BUC state, I think), you can't
pick it up and get a message saying so.  If loadstone isn't known
yet, the message always referred to it as "gray stone" rather than
"stone called <whatever-you-called-it>".
2024-01-22 13:25:32 -08:00
PatR
7c1512fa99 avoid strnlen()
Replace the single strnlen() use with strlen() so as not to require
something from posix.1 (2008) when we supposedly only require c99.

If someone manages to produce a string that's longer than will fit
within size_t, strlen()'s length count will wrap and Strlen_() might
not notice.  Since size_t has to be at least 32 bits, that doesn't
seem like something to worry about.

If checking for size_t overflow is considered essential, we should
just switch to counting the length via an in-line loop that imposes
a similar limit to strnlen().
2024-01-22 12:59:51 -08:00
nhmall
7f8c7dda64 Merge branch 'rotten-rottables' of https://github.com/bitofhope/NetHack into NetHack-3.7 2024-01-22 11:08:30 -05:00
Pasi Kallinen
baeb1d925f Change some ints to coordxy 2024-01-22 17:02:40 +02:00
PatR
5d90499148 doname bounds checking bits
When ready to return, check for overlooked overflow (shouldn't happen)
and panic, or report the first excessively long but not overflown
description to paniclog, similar to xname.

Make ConcUpdate() more robust by not needing bp_eos to be previously
set.  Less efficient but I think that boat has left the barn?  :=}

Fix a comment typo.
2024-01-21 17:43:55 -08:00
Pasi Kallinen
96902f4ff0 Split populating a random maze 2024-01-21 22:48:41 +02:00
PatR
13ff565a67 github issue #1201 - Forcefighting webs
Issue reported by Umbire:  suggestion to always destroy adjacent webs
via 'F'<dir> if wielding Sting or Fire Brand.

Sting already did that; this adds Fire Brand.

This also augments the #untrap command when wielding either of those,
or any other blade.  And rephrases successful untrap message
"You remove {the or your} {bear trap or webbing} from Fido." to
"You extract Fido from {the or your} {bear trap or web}." since the
trap remains intact.

Forcefight and #untrap against webs ought to be reconciled to remove
[some of] their differences and/or share code.  But not by me...

Closes #1201
2024-01-21 11:58:44 -08:00
nhmall
81b45f92c8 static analyzer bit in sounds.c 2024-01-21 14:09:46 -05:00
PatR
9e640fb14e gcc warning fix
Avoid two new warnings in xname_flags() about strncpy() not supplying
a terminating '\0'.  That's exactly why strncpy() was being used.

The gcc manual lists -Wno-stringop-truncation to suppress the warning
but not -Wstringup-truncation to voluntarily enable it, so the pragma
stuff in warnings.h probably won't work for this.  Just switch from
strncpy() to memcpy() instead even though it seems like obfuscation.
2024-01-21 11:01:45 -08:00
nhmall
d4f04fbdc8 static analyzer bit in options.c
Analyzer didn't like the use of strchr on an incomplete type.
Move the guts into a function in o_init.c.
2024-01-21 13:38:25 -05:00