Commit Graph

8339 Commits

Author SHA1 Message Date
Ray Chason
ea84598613 Remove some debug code 2022-12-10 13:13:28 -05:00
Ray Chason
c7431d6942 Reimplement glyph cache as a hash table 2022-12-10 12:27:18 -05:00
Ray Chason
d5bc738812 Replace Snprintf with faster Strcpy 2022-12-10 12:27:18 -05:00
Ray Chason
b9ef6e6bb9 Define a tail pointer for the glyph list
Use the tail pointer to add new glyphs, avoiding the need to traverse
the list.
2022-12-10 12:27:18 -05:00
Ray Chason
e556af78ec Use pointer assignments to generate glyph names 2022-12-10 12:25:56 -05:00
Ray Chason
d90cd6d7d2 Skip match_sym for G_ lines 2022-12-10 12:25:56 -05:00
Ray Chason
d70bdeab3b Fill the glyph cache when switching symbol sets 2022-12-10 12:25:55 -05:00
Ray Chason
7dc1106ec1 Sort the glyph cache and search it with bsearch
Also, recognize G_slime_mold and G_piletop_slime_mold when the fruit
has been set.
2022-12-10 12:25:55 -05:00
PatR
7c0c0ba66a shop sanity check of the day...
If a pet picks up a no_charge item in a shop and gets teleported out,
clear that flag.  (It's already being cleared for non-pets as soon as
they pick any item up.)
2022-12-09 12:55:39 -08:00
PatR
9fa08b383f shopping objects, unpaid and no_charge, what else?
Revise sanity_check to acknowledge that buried objects might be unpaid
or no_charge.  (For unpaid, drop shop-owned object in a gap in the
shop wall or in the free spot; for no_charge, drop something the shk
doesn't care about, or drop any hero-owned item and decline to sell.
Dig a pit.  Push or drop a boulder to fill the pit.)

Change 'I' to look for unpaid objects on the floor and for buried ones
when deciding when to include 'u' in the list of candidate object
classes and pseudo-classes.

Change 'Iu' to mention buried unpaid objects as well as floor ones.
For both non-invent categories, show a combined count without cost
info.

Have sanity_check of monster inventory test for unpaid and no_charge.

When a monster (including pet) picks up an item that's marked unpaid
(so one dropped on shop boundary, not an ordinary for-sale one), take
it off hero's shopping bill.  If dropped--pet behavior or monster
death--inside the shop, it will become for-sale rather than no_charge
or back on bill.  [Removal from bill is needed to prevent an unpaid
object ending up outside the shop if a monster carries it out, and
current sanity_check complains about an unpaid item in mon->minvent.]
2022-12-09 04:18:20 -08:00
PatR
e335171071 no_charge sanity
When a shopkeeper becomes angry, clear the no_charge flag for all
floor objects on the level, even if they happen to be in another
shopkeeper's shop.  Should prevent sanity_check warnings if/when the
angry shk leaves the shop, and once the shk is pacified, items in
the shop that used to be available for free will become for-sale.
2022-12-08 02:36:50 -08:00
PatR
f1a471c139 some shk.c formatting 2022-12-08 01:06:09 -08:00
PatR
4a965bbd83 boulder pushing feedback
Redo the details about giving or suppressing "with great effort you
push the boulder".  It works the same except that if push a different
boulder than previously, you'll get a new message.  If you do it
while riding, you have the same lack-of-message for successive pushes
instead of getting a message every turn.

Don't exercise strength when pushing a boulder if poly'd into a giant.
2022-12-07 16:45:35 -08:00
Pasi Kallinen
85137bb76a Fix skipping attacks if hero moved away
Recent change by me caused a bug where a monster was trying
to attack after hero was moved away by the previous attacks.
2022-12-07 21:51:50 +02:00
nhmall
8120b74051 realign macro continuation after g to g? expansion 2022-12-07 11:24:17 -05:00
Patric Mueller
68f9ef8aa6 Followup to "suicide by wand", remove redundant an() 2022-12-07 15:54:30 +01:00
PatR
0d4cf0323c shop wall repair vs unpaid shop goods
Take unpaid shop items off the bill if they're on the floor and
wall repair moves them from the shop boundary to all the way inside
the shop.

I don't think it's possible for items to be moved out of the shop
except for the very special case of moving into an adjacent shop
which shares the wall, so clearing no_charge for an item that is no
longer inside a shop is academic.
2022-12-07 02:02:08 -08:00
PatR
e48e08a93b topten.c comments 2022-12-06 17:41:44 -08:00
PatR
f52a8e48b1 suicide by wand
If hero zaps self with a wand and the result is fatal, report the
death as "zapped himself with <a wand of sometype>" rather than just
"zapped himself with a wand".
2022-12-06 11:41:24 -08:00
PatR
e724034995 unpaid sanity_check: leaving shop via recoil
Throwing while levitating or getting hit for knockback effect could
move hero carrying unpaid items out of a shop.  If that happened,
sanity_check complained that unpaid items weren't in a tended shop.

Check for entering and leaving special rooms during recoil same as
gets done for ordinary movement.  Leaving a shop via recoil or
knockback while owing a bill now gets treated as robbery immediately
rather than waiting until hero voluntarily moves to another spot
after recoil has finished.
2022-12-06 10:57:14 -08:00
PatR
20392a68fd yet more shop sanity checking
Reconcile boulder pushing with no_charge sanity checking.  The hack.c
part comes from entrez.

Pushing a for-sale boulder from inside the shop to the shop's boundary
("free spot", doorway, or gap in wall) adds it to the shop bill even
though it's still on the floor.  Leaving the shop without paying for
it is a robbery.  Also, pushing an unpaid boulder that's on the shop
boundary to any spot that's all the way outside the shop is robbery.
2022-12-05 23:05:20 -08:00
nhmall
215808abd1 clear up a few gcc warnings 2022-12-05 23:19:38 -05:00
nhmall
d4968e752e fix pair of prototype differences between date.c and mdlib.c 2022-12-05 13:39:46 -05:00
nhmall
b86109e9fa Merge branch 'windows-makefile' into NetHack-3.7 2022-12-05 13:27:25 -05:00
nhmall
485797ee8c rework windows nmake file
Keep object files separate between gui and tty builds as they
are not the same binary on windows.

The stubs.c file will no longer be necessary.
2022-12-05 13:21:19 -05:00
PatR
a7b714ec5c no_charge items sanity - shop theft
More unpaid/no_charge sanity checking.  If a shop contained any
no_charge objects and was robbed, they would be left no_charge and
trigger sanity check warnings (no_charge in "untended shop") once
the shopkeeper got past any Kops in the way and exited the shop.
Earlier testing didn't wait around long enough for that exit to
happen.

Clear no_charge as soon as the robbery is detected.
2022-12-04 08:59:22 -08:00
PatR
9e3f5502a3 farlook /[mMoO] feedback, take II
Redo the way coordinate pairs are lined up for /m /O &c.

Original
|   <8,9>  $  gold pieces
| <10,10>  *  rocks
|  <9,12>  %  newt corpse
Previous
|  <8, 9>  $  gold pieces
| <10,10>  *  rocks
|  <9,12>  %  newt corpse
Now
|  <8,9>   $  gold pieces
| <10,10>  *  rocks
|  <9,12>  %  newt corpse

Override right justification instead of inserting a space.  It looks
better for the situation where all y values are 1 digit.
2022-12-03 23:51:00 -08:00
PatR
9329c7881d another no_charge sanity check
Kicking a no_charge item out of a shop wasn't clearing the item's
no_charge flag so trigger sanity warnings.
2022-12-03 17:57:29 -08:00
PatR
d2b3a9670a obj->no_charge insanity
An object in a shop that was marked no_charge and got removed from
the shop by means other than the hero picking it up (test case
teleported it out while hero was inside shop) was left with the
no_charge bit set.  It's supposed to only be set for objects inside
shops so was triggering the recently added no_charge sanity checks.

Changing stolen_value() to have it pass the reset_nocharge arg to
billable() solves this but could have unanticipated results with
other stealing from shops.
2022-12-02 15:13:57 -08:00
PatR
345c2e1cb6 farlook /[mMoO] feedback
When /m or /M or /o or /O shows monsters or objects with locations
displayed as map coordinates, make those line up by their commas.

Old
|   <8,9>  $  gold pieces
| <10,10>  *  rocks
|  <9,12>  %  newt corpse
New
|  <8, 9>  $  gold pieces
| <10,10>  *  rocks
|  <9,12>  %  newt corpse
(The data is gathered by row so implicitly sorted by y.)

If someone is crazy enough to set ROWNO to three digits, values
will only line up by the comma when all values have row less than
100 or all are 100+.  Setting COLNO to three digits isn't an issue
unless the total witdh of "<" + xxx + "," + yy ">" is more than 8
(which would push object class letter and object description one or
more extra columns to the right, messing up overall alignment but
still showing accurate data).
2022-12-02 01:40:54 -08:00
PatR
b3002a36b3 alternate fix issue #938 - use-after-free
If you kill an engulfer and get dropped onto a level teleporter or
magic portal, wait until end of turn to perform the level change.
The code to finish off killing the engulfer was left with a stale
pointer for the monster when level change happens immediately.

The level change was being forced to be immediate so that something
noticable happened before being asked for what to name a teleport
scroll read while cursed or confused, but such scrolls become
discovered these days.  So when no prompting for what to call the
scroll takes place, there's no need to change levels instantly.

This issue was just fixed but this commit is simpler.  The previous
fix is left in place in case some other level change path is--or
becomes--possible.
2022-12-01 16:15:45 -08:00
PatR
54aa047ec9 \#wizkill fix
When running #wizkill, if hero was swallowed and you killed the
engulfer and that dropped hero onto a level teleporter, the targetting
loop for selecting the next monster to kill kept going after changing
to another level.  Terminate #wizkill if killing something sends you
to a different level.

Not fixed, and an old bug, or variation of one:  the cursor got
positioned at the coordinates of your spot on the prior level even
though the part of the new level where you actually arrived was
displayed.

The hack.c and trap.c bits are just reformatting.
2022-12-01 15:36:40 -08:00
Pasi Kallinen
81fb185cea Recalc mon-hits-you distance variables
When a monster could first knock you back and then grab you,
the game would emit impossible, because the knockback moved you
but the distance variables used for the grab attack were not
updated.

Update the range variables within the loop iterating through
the monster attacks.
2022-12-01 19:57:24 +02:00
Pasi Kallinen
47c194fd56 Avoid segfault when null obj passed to water_damage 2022-12-01 13:29:52 +02:00
PatR
2f09bcba31 more shop billing object sanity
Used up items moved to the billobjs list still have obj->unpaid set.
That should probably be cleared since it has no meaning there, but
this hasn't done that.

For those keeping score:  unpaid checking has triggered three false
positives (so far) and found one bug.
2022-12-01 02:23:01 -08:00
nhmall
4ede5f1cd4 Use-after-free with engulfer in xkilled #938
If you were on a level teleporter, the spoteffects() call after
the hero gets expelled could end up going to a new level and
freeing all the monst chains from the level you were originally
engulfed on.

    #0 0xba0507 in free
    #1 0x87feda in dealloc_monst src/mon.c:2369
    #2 0x880a02 in dmonsfree src/mon.c:2194
    #3 0x9a7aa2 in savelev_core src/save.c:507
    #4 0x9a7a21 in savelev src/save.c:466
    #5 0x71eb9d in goto_level src/do.c:1483
    #6 0x71833f in deferred_goto src/do.c:1903
    #7 0xa2533f in level_tele src/teleport.c:1117
    #8 0xa2567b in level_tele_trap src/teleport.c:1198
    #9 0xa5c007 in trapeffect_level_telep src/trap.c:1861
    #10 0xa5f856 in trapeffect_selector src/trap.c:2497
    #11 0xa47497 in dotrap src/trap.c:2586
    #12 0x7d669b in spoteffects src/hack.c:2859
    #13 0x89d495 in xkilled src/mon.c:3187

The latter parts of xkilled() after the spoteffects() call would
then attempt to dereference the free'd monst pointer.

Save a copy of the monst struct prior to spoteffects() if you were
expelled, then point at the reference copy afterwards.

Resolves #938
2022-12-01 03:48:11 -05:00
nhmall
cf1a46afa6 Merge branch 'cursed-gold-detection' of https://github.com/vultur-cadens/NetHack into NetHack-3.7 2022-11-30 23:18:09 -05:00
vultur-cadens
fdfee3880c Fix autodescribe after reading a cursed scroll of gold detection
Autodescribe was not updating during browse_map() when the cursor was
moved over a gold glyph that was actually a trap, causing the trap to
be described as the previous square that the cursor was on (probably
"unexplored area") instead of as gold pieces.  This was especially
noticeable when using OPTIONS=whatis_coord:m, because the coordinate
was not updating when moving the cursor over the trap.
2022-11-30 17:34:00 -08:00
Michael Meyer
5cf6042ca4 Fix: potential use-after-free in expels()
An engulfing monster can expel you onto a level teleporter or other
level-changing trap, in which case it may (under highly specific
circumstances[1]) no longer have been in memory by the time mtmp->mx/my
were accessed to see whether the "Brrooaa" message should be printed.
It also doesn't make much sense to print that message by the time you've
already fallen through a portal, trapdoor, etc, onto another level, so I
think moving it before the spoteffects() call kills two birds with one
stone.

[1] The highly specific circumstances: you must die due to illness or
some other timeout (or generally die on your own turn rather than the
monsters' turn, since this ensures the level change isn't deferred until
the end of the turn), while engulfed above a level teleporter [or maybe
another similar trap -- I tested with a level teleporter], and be
lifesaved, while positioned such that the engulfer can't follow you
through the levelport after expulsion (e.g. surrounded by other
monsters).  It may happen under some other conditions too, but even if
so it's pretty rare and was tough to reproduce.
2022-11-30 14:54:05 -08:00
PatR
7099bf63de more #936 - water vs potions of acid
Pull request #936 took away the destruction of potions of acid ("acid
and water don't mix") if they survived water_damage().  Restore that
by forcing them to not survive.  Exception:  if they're greased and
pass the 50:50 chance of retaining the grease, they aren't destroyed.
2022-11-30 14:49:11 -08:00
Michael Meyer
75ff2fa5fc Fix: use-after-free when fountain dipping
A potion of acid could be destroyed and freed by dipping into a
fountain, then dereferenced after the fact -- both when checking its
type immediately after the water_damage() call (as was noticed by
hackemslashem and amateurhour on IRC), and also in the later switch/case
a few lines further down in dipfountain().

I basically reversed the original 'er != ER_DESTROYED' test here: as it
was before this, I think the only thing that could hit it was a greased
potion of acid, which would survive the initial dip due to the grease.
Such a potion would be silently deleted.  Potions of acid which were
actually destroyed by water_damage, on the other hand, could be allowed
to continue down to the switch/case of further effects (and associated
dereferences).  I think this makes more sense in reverse, with potions
that were protected by grease actually being protected and producing
normal dip effects, and potions of acid which exploded causing an early
return with no further effects.  This effectively prevents the various
use-after-free scenarios that were possible, too.
2022-11-30 12:54:26 -08:00
Michael Meyer
263e48c6f7 Tell player when water damage removes grease
This was totally silent, which -- at least for me -- has led to quite a
few cases of believing my bag or cloak is still greased when it actually
wore off the last time I took a dip.  I think telling the player that
the grease has worn off would be helpful, and is consistent with other
types of water damage.

The message is printed even if you are blind, since that seems to be
true of all the other messages in water_damage().  I am not sure if that
makes complete sense (especially for ones like a scroll fading -- some
like water getting into a bag could be sensed by touch) but I didn't
change anything there.
2022-11-30 12:54:26 -08:00
vultur-cadens
bfe7f2740a Fix autodescribe after reading a cursed scroll of gold detection
Autodescribe was not updating during browse_map() when the cursor was
moved over a gold glyph that was actually a trap, causing the trap to
be described as the previous square that the cursor was on (probably
"unexplored area") instead of as gold pieces.  This was especially
noticeable when using OPTIONS=whatis_coord:m, because the coordinate
was not updating when moving the cursor over the trap.
2022-11-30 12:44:15 -08: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
PatR
e64ed2859d unpaid object: sanity check, teleporting, 'I u'
It turns out that there are some objects marked unpaid that aren't
carried by the hero, so the recent sanity check for unpaid/no_charge
could complain.  Unpaid items dropped on the shop boundary (gap in
shop wall, doorway, shk's free spot) stayed unpaid when dropped onto
the floor, similar to recent change for pushed shop-owned boulders.
Don't give sanity complaints for those.  They could be all the way
inside a shop too, where unpaid items in a gap in the shop wall got
pushed into the shop when the wall was repaired.  (Possibly those
should come off the bill instead of remaining unpaid.)

Teleporting items out of a shop was marking them unpaid instead of
treating that as robbery.  That's a bug caught by the sanity check.
rloco() was also marking shop items which got teleported from one
spot inside the shop to another spot inside the same shop as unpaid.
Fix both of those things.  Also, if an unpaid item on the boundary
gets teleported all the way inside, take it off the bill.

Change 'I u' to mention whether there are additional unpaid items on
the floor somewhere since they won't be part of unpaid inventory and
they're not on the used-up bill either.  It might occasionally help
the player figure out why the shopkeeper won't let the hero out of
the shop.
2022-11-29 13:55:42 -08:00
PatR
8836b32128 github issue #935 - disarming swallowed hero
Issue reported by AndrioCelos:  bullwhip using monster was able to
snatch hero's weapon when hero was engulfed.

Fix is trivial:  when a monster is choosing an item to use, don't
pick bullwhip if hero is engulfed.  Regular attack attempts already
skip engulfed hero.

Fixes #935
2022-11-28 02:08:49 -08:00
PatR
223818ff41 github issue #934 - hearing unseem mon read scroll
Issue reported by Melon2007:  when non-deaf hero heard an unseen
monster read a scroll, the monster's type was identified accurately
(unless distorted by hallucination).  That was intentional but it
doesn't seem plausible for the hero's hearing to be that acute.
Change it to report the monster type accurately if not hallucinating
and monster is the same species as the hero (as the current form if
hero is poly'd), otherwise report it as "someone" when it's humanoid,
otherwise as "something".

Also, if the monster is heard at a spot that would be visible if
hero could see, draw a "remembered, unseen monster" glyph there.

Fixes #934
2022-11-28 01:44:19 -08:00
PatR
73f69a99cb paranoid-pray vs do-again
If paranoid_confirm settings include praying, don't put the answer
to "are you sure you want to pray?" into the do-again buffer where ^A
would use it to ignore confirmation if prayer is repeated.  And for
wizard mode, when confirmation is 'y' then the answer to "force the
gods to be pleased?" has to be suppressed from the do-again buffer too
or it would be used by subsequent ^A to answer "are you sure?".

This is basically a band-aid just for #pray.  There are probably other
confirmations that should be suppressed from do-again instead of being
reusable.  The rest of the paranoid_confirm ones should be ok because
they require "yes" and that doesn't end up in the do-again buffer, but
there are bound to be other confirmations that shouldn't automatically
be re-used during repetition.
2022-11-26 15:59:01 -08:00
PatR
270f4ceeef gitpub issue #933: feedback for throwing w/ count
Issue reported by Meklon2007:  typing arrow keys when a menu is open
can end up with hidden counts.  That's a Windows thing and this
makes no attempt to address it.  (That's also a user error since
menus don't support arrow key use.)  It shows up more for throwing
that for other things because fetching an object from inventory for
throwing attempts to enforce a count limit during item selection
that other actions don't.

But feedback could also be odd if you explicitly specify a count
since the rejection wasn't attempting to distinguish throwing more
than one from throwing more than you have.  This changes things so
that with invent of
|$ - 3 gold pieces
|a - a dagger
|b - 3 darts
t4$ now yields   "You only have 3."  instead of  throwing all 3
t4a now yields   "You only have 1."  instead of "you can only throw one"
t2b still yields "You can only throw one at a time."
t4b now yields   "You only have 2 and can only throw one at a time."
In each case, it will reprompt rather than terminate the throw.

"Only one at a time" was already in place when multi-shot throwing/
shooting was introduced and became iffy then, but the way to try to
throw a specific amount is via a repeat count before t rather than
by choosing a subset when selecting the inventory item for t.  The
count prefix method also works for f which doesn't otherwise provide
an opportunity to specify count since inventory item is preselected
via quiver.

Someone might want to reopen the arrow behavior as a Windows issue
but I'm not sure how that would be fixed other than by eliminating
its attempt to be user-friendly in converting arrows into movement
direction keystrokes.

Closes #933
2022-11-26 02:25:27 -08:00
nhmall
4b04b1e6ac expand support for noreturn declarations
Although gcc specifies support for declaring a function as
noreturn after the function name and parameters, other compilers
do so via an attribute at the start of the declaration. Add some
macro support for the attribute-at-the-beginning method:
  o MS Visual Studio compiler
  o Upcoming C23 standard (untested at this point)
2022-11-24 00:51:42 -05:00