Commit Graph

7564 Commits

Author SHA1 Message Date
PatR
5489b3ebd9 command queue handling in getobj, yn_function
Mostly attempting to clean up potential error handling but I don't
have any error cases to test with.  Doesn't seem to break anything
when there aren't any errors....
2022-04-19 13:53:40 -07:00
PatR
2356690054 mon_leaving_level followup 2022-04-19 12:30:23 -07:00
PatR
be3d9bcd1a item-action refinements for name/call and read
Switch the verb from "name" to "call" for type-naming.  Format menu
choices for name or call of unique items more carefully.

Read actions got some extra details so move them out of the main
item-action routine to avoid cluttering it up.

Avoid "r - Study the spellbook" for novels.  It's changed for known
Book of the Dead too, but I'm not sure "r - Examine the tome" conveys
"read" sufficiently.  ("Read" and "peruse" seem too mundane for it;
perhaps it should revert to "study" even though the hero isn't
attempting to learn a spell from it.)

Change "r - cast the spell on this scroll" to "r - read this scroll
to activate its magic".  Leave off the last phrase if it's a known
scroll of blank paper or scroll of mail.
2022-04-19 12:26:54 -07:00
Pasi Kallinen
af7db2f8f1 Fix panic on thrown potion of acid when swallowed
When you're swallowed and throw a missile that kills the swallower,
the thrown missile is picked up by the swallower before death.
This caused a panic when you threw a potion, which was first picked up
by the swallower, which upon death dropped the potion on the floor,
but then throw code was trying to destroy the potion ...
2022-04-19 15:00:00 +03:00
PatR
9f0e511b00 item-action name/call
Add opportunity to name an individual object or call the type of an
object to the context-sensitive inventory item-actions.
2022-04-19 04:33:01 -07:00
PatR
6880d37b33 mon_leaving_level
From 6 year old email:  m_detach (monster death or removal from play)
and relmon (monster migrating to another level) both take a monster
off the map but they weren't consistent with each other.  Change them
to use a common routine for that.

I'm not sure whether the inconsistencies resulted in any bugs.  The
email was concerned about handling for monsters that emit light, but
those aren't actually common to the two removal methods and turned
out to be ok.
2022-04-18 12:01:17 -07:00
Pasi Kallinen
262e178243 Unify mhitm magic attack negation checks 2022-04-18 19:14:40 +03:00
Pasi Kallinen
d7eb95cbf0 Minor code dedup in sp_lev 2022-04-18 13:38:01 +03:00
PatR
54189e795b more queued commands
This attempts to make item-actions, #herecmd, and #therecmd be more
robust.  When rhack() or yn_function() take queued input off cmdq
and get something unexpected, discard the rest of the queue.

It also fixes the two crash cases that entrez reported.  There are
bound to be others though.

I think a lot of actions that can be executed by queued input are
going to need nomul(0) calls to handle repeat counts that should be
ended early if something unexpected happens or something expected
fails to happen.  But that clears cmdq so may be tricky to decide
where to use.
2022-04-17 13:36:38 -07:00
PatR
ec4749914a drink_ok() tweak
Fix a comment typo and change the 'if obj/!obj' logic to be like what
was recently added to eat_ok()/offer_ok()/tin_ok().
2022-04-17 01:39:34 -07:00
PatR
52cfe40d33 eating, drinking via #herecmdmenu
Fix eat floor food and drink from dungeon feature via #herecmdmenu.
That uses queued commands, but those two actions were changed to
skip the floor when queued input was present because asking about
floor items interfered with context-sensitive inventory item-actions.

I was misled by a comment that says it couldn't insert an m-prefix;
that was for treating the 'm' key as typed text rather than as a
command.  There's no problem with inserting a #reqmenu command which
is what 'm' is these days.  So item actions can force 'm' to skip the
floor and go directly to inventory, also the #eat and #quaff commands
don't have to alter their behavior when queued input is pending so
the #herecmdmenu usage for them gets fixed.
2022-04-16 15:32:41 -07:00
PatR
d4acb9385e & (whatdoes) enhancement?
Using '&#' or '?f#' showed "#  perform an extended command (##)".
The "(##)" part looks rather silly and is not helpful.  Expand the
text a little and omit command name for that particular command:
"#  enter and perform an extended command".
2022-04-16 14:28:27 -07:00
PatR
18755668b1 \#repeat bit
The comment preceding new 'savech_extcmd()' said that the core didn't
care whether it was given the full command name or just enough leading
substring to be unambiguous.  Then it tested the string against
"repeat" which contradicts that comment.  Didn't seem to be an actual
problem because "#repeat" is not flagged for auto-completion, but fix
the code to match the intent of the comment and reword the comment to
match the code.
2022-04-16 12:38:10 -07:00
PatR
31affa0722 ^A/#repeat vs extended commands
Fix '#repeat' for tty; both it and ^A can repeat an extended command.

Fix both for curses; they can repeat an extended command instead of
just repeating the initial '#' to start getting an extended command.

X11 (tested), Qt (tested), and probably Windows GUI (not tested)
behave the same as before:  ^A (or #repeat) after an extended command
just repeats the # to run the dialog to get an extended command.

I hope this introduces fewer bugs than it fixes but I don't think I'd
bet on that....
2022-04-16 01:52:12 -07:00
PatR
4485515872 context-sensitive inventory item-action quaff
Picking a potion from inventory and then picking 'quaff this potion'
from the context menu needed handling similar to eat/offer/tin:  skip
floor candidates.  If you were on a fountain or sink, picked a potion
from inventory and then the quaff option for it, you weren't prompted
to drink from the fountain but you were prompted for what potion to
drink instead of using the one that had already been picked to
initiate drinkig.
2022-04-15 12:09:17 -07:00
PatR
12a63216a7 ^A fix
If you used ^A to repeat a command which had taken no time, the
repeat execution would take time.  This fixes that.  Also, give some
feedback when trying to repeat an invalid command.

Internals bit: don't use 'X == cmd_from_func(do_repeat)' to decide
whether key X is the key for #repeat.  Both X and Y might be bound to
that action and cmd_from_func() could return Y rather than X.

There is another ^A bug that I haven't figured out how to fix:
 t ESC   start to throw but don't finish
 ^A      nothing seems to happen
 ^A      "You don't have that object."
The first ^A repeats 't', doesn't display a prompt for what to throw,
but does request input for it.  The second ^A fulfills that input and
doesn't match any inventory item.  Either 't' shouldn't have been put
into the do-again buffer or do-again handling should have ceased when
it was taken out and there was no further remembered input, so that
normal prompting would resume.  My tentative attempts for both those
approaches didn't work.
2022-04-15 11:45:50 -07:00
PatR
ad46090732 fix github issue #734 - ^A crash
Issue #734 reported as "parse function" by Meklon2007:  the change
yesterday intended to make ^A work for commands that were preceded
by a prefix was triggering a crash if used after a keystroke that's
not assigned to any command.

'M^A' or '~^A' would segfault by derefencing a null pointer when
checking whether 'M' or '~' was a prefix.  This prevents the check
attempt from doing that, but a better fix would be to not put the
invalid command keystroke into the do-again buffer in the first
place.

Fixes #734
2022-04-15 10:07:19 -07:00
Pasi Kallinen
cb02ce88c5 Revisit the Valkyrie goal level hack
Instead of hardcoding the lava terrain change in core, if the stairs
are created in a fixed location, force the terrain to room floor first.
Move the surrounding lava changing to room floor to the Val-goal lua
file.
2022-04-15 18:52:49 +03:00
PatR
a15b587b81 fix a comment
At one point temp_resist() was boolean and when it was changed to
long the comment preceding it wasn't updated.
2022-04-15 00:45:35 -07:00
PatR
da35dfe48e fix #K3577 - F+dir followed by ^A moved dir
Reported by luxidream via the web contact form and also as github
issue #732: using the repeat command after F+direction would take a
step in direction if there was no target to fight.

The direction was being repeated without the F prefix.  It wasn't
specific to F; m+dir misbehaved too.  This fix seems to work but it
should be replaced with something more robust.

Fixes #732
2022-04-14 18:59:23 -07:00
PatR
554ebc0f4c temporary? fix for github issue #730 - stairs \
placed on lava spot on Valkyrie goal level

Reported by k2, arriving at the final level of the Valkyrie quest
can issue a recently added impossible
| mkstairs: placing stairs up on molten lava at <68,13>
The report said it was easy to reproduce, but it took me multiple
tries (so not hard to do, but not a sure thing on any given attempt).

The stairs on that level are placed at specific coordinates that
are outside the pre-mapped area, so there's no guarantee that their
spot will be suitable for stairs.  The underlying terrian changes
from lava to stair, but only after the warning about molten lava.

This hack solves that particular level but is not a general solution
for this type of thing.  When about to make stairs on a lava spot,
change that spot to normal floor first.  Plus 50:50 chance to change
each adjacent lava spot to floor too so that there's decent chance
for some elbow room upon arrival.

Also, turn the no-flip attribute off for that level so that 'fixed'
location of the stairs can occur in four different places.

Fixes #730
2022-04-14 10:50:23 -07:00
Pasi Kallinen
43856fe023 Fix uninitialized var in dip 2022-04-14 18:59:03 +03:00
PatR
9c2a5cbcb8 fix github issue #731 - accessing freed memory \
after charging causes a ring to explode

Reported by gebulmer:  if charging exploded a ring, the ring's memory
got freed but the stale pointer was passed to cap_spe() which accessed
it again.  Fix by setting the object pointer to Null after using up
the ring.  This was a post-3.6 bug.

Fixes #731
2022-04-13 13:34:14 -07:00
PatR
670b7edf1d eating/offering/tinning
Make being offered floor food and declining behave similarly to
being offered a chance to drink from or dip into a fountain and
declining:  insert "else" into
| "You don't have anything [else] to {eat | offer | tin}."
when there is nothing applicable in inventory.
2022-04-13 13:03:14 -07:00
PatR
436604e547 more potion drinking/dipping
Simplify the recently added handling for inserting "else" into
| You don't have anything [else] to {drink | dip into}.
after declining to use a fountain/pool/sink at the spot when not
carrying any potions.
2022-04-13 12:13:13 -07:00
PatR
feac8c8f68 'm' prefix for drinking and dipping
Allow the player to precede q/#quaff or M-d/#dip with the 'm' prefix
to skip asking about fountains, sinks, or pools if one of those
happens to be present, similar to how using it for e/#eat skips food
on the floor and goes straight to inventory.

If you use it and don't have any potions, you'll get "you don't have
anything to drink" or "you don't have anything to dip into", same as
when there is no suitable dungeon feature present combined with no
potions.  However, if an applicable dungeon feature is present and
you don't use the prefix but answer 'no' to drink from fountain,&c
and you don't have any potions, "else" will be inserted into the
message: "you don't have anything else to drink".

A big part of the diff is just a change in indentation level for
code that is now inside 'if (!iflags.menu_requested) {' ... '}'.
2022-04-13 03:14:39 -07:00
PatR
60c504dd40 context-sensitive inventory - action sequencing
rhack() normally calls parse(), parse() sets context.move to True
assuming that the player's next action will take game time, then
when it returns, rhack() sets context.move back to False if the
assumption turned out to be incorrect.  But when performing actions
after picking something in inventory, rhack() doesn't call parse()
so context.move is left at False.

This was hidden by making the inventory command take game time if
the player picked an item and set up an action to be done with it
even though the action hadn't taken place yet.  So time was being
accounted for but if the hero didn't get consecutive moves then
monsters got their turn between the shouldn't-take-time inventory
command and the ought-to-behave-like-normal-command queued action.

My initial attempt to fix this (before figuring out how context.move
works) by stopping inventory from taking time didn't work because
queued item-actions stopped taking time too, or rather the fact that
they took no time became exposed.  This second attempt doesn't have
that problem and I think it is correct.
2022-04-12 14:56:38 -07:00
PatR
11543620f9 context-sensitive dipping
Normally dipping gets the thing to dip first and what to dip it
into second and the item-action handling knows that.  I'm not sure
why that wasn't working as intended and I couldn't figure out how
to make it do that, so went another way:  this adds an internal
extended command that executes an alternate dip routine which gets
the potion to dip into first and the thing to dip into it second.

The #dip command should allow an 'm' prefix to skip fountains and
pools, similar to how eating accepts it to skip food on the floor.
But this doesn't implement that.
2022-04-12 02:20:40 -07:00
PatR
699a25c00b shop repair revisited
This repair behavior should be closer to the orginal, except without
the old sequencing issues.
2022-04-11 17:53:09 -07:00
PatR
53e10d582d context-sensitive invent: corpses
Picking a corpse while looking at inventory issued a menu that had
entry for eating that and if on an altar another one for offering
that.  Picking the eat or offer choice worked as long as there
weren't any other corpses on the ground or altar.  If there were
others, they'd be skipped but you'd get prompted for which item in
inventory to eat or offer instead of operating on the one that was
used to initiate the action.
2022-04-11 15:02:44 -07:00
PatR
f68b90e1ea inventory context: drop and wield
For context-sensitive actions when picking an item from inventory,
exclude drop and wield from the choices if the item is being worn.

Move 'O'ffer into alphabetical order.

Formatting: fix a couple of cases of '&&' or '||' placed at the end
of first half of a split line instead of at the start of second half.
2022-04-11 11:34:53 -07:00
Pasi Kallinen
28e416da3a Add moving on the trap to the mouse menu 2022-04-11 15:08:50 +03:00
Pasi Kallinen
503b85b1cf Add spell casting to mouse menu 2022-04-11 14:54:12 +03:00
PatR
7b351bc20d add #tip to context-sensitive invent
Add a menu option for #tip when selecting a container from inventory.
Also, move the recently added 'unwield' option to the order it gets
placed in the menu for primary weapon:  before 'a' because it's
spelled '-'.
2022-04-11 02:18:41 -07:00
PatR
fbbcd7c9cb object bypass bit sanity for container contents
Noticed when adding a 'tip container' choice to item-actions for
context sensitive inventory (update pending).  Putting items into a
container with menustyle traditional and then takiing them out with
the #tip command while 'sanity_check' is On would produce warnings
once they were on the floor.

askchain() uses object bypassing to be able to cope with multi-drop
potentially changing invent, and it tried to reset that when done.
But it did so with the original object list (invent in this case)
and that doesn't reset individual objects that have been moved to
any other list.  The between-turn resetting of bypass bits wasn't
doing so for container contents.  The sanity check wasn't--still
isn't--checking those either, so it wasn't noticeable while items
were still inside the container.  But taking them out with #tip
doesn't touch any bypass bits, so between-turn reset isn't triggered
and the items that came out of the container with bypass set
continued to have it set while on floor.  sanity_check complained.

Change clear_bypasses() to handle container contents, and change
askchain() to call it instead of just clearing bypasses for whatever
is left of its input chain.  (The latter probably isn't necessary
now that the between-turn cleanup deals with contents.)
2022-04-11 02:16:22 -07:00
Pasi Kallinen
32fa807050 When autopicking objects, you can count to two
Show "two" instead of "a few" when autopicking up objects, and
there's some left you didn't pick up.
2022-04-11 11:31:32 +03:00
PatR
4195722df6 context-sensitive inventory
Add '-' choice if player picks wielded weapon.  'w-' is effectively
the unwield command but a normal inventory list doesn't present '-'
as something that can be picked, so there's no context menu entry
that can suggest wielding it.

Make 't' clearer.  Don't offer it as a choice when selected item is
worn, distinguish between throwing and shooting, and introduce a bit
of plural handling.

Since we aren't using a magic 'A' command to "equip" and "unequip",
make the uses of P/R/T/W match up with how they normally operate so
that player can learn them while using item menus.

Do something similar for offer vs sacrifice.
2022-04-10 12:22:21 -07:00
PatR
138d34198e getobj vs CMDQ handling
The queued command handling rejected a non-object even in cases where
getobj()'s object callback would accept it.
2022-04-10 12:14:07 -07:00
PatR
58bc545cc6 \#dotypeinv ('I') - show title for inventory subset
When asking for an inventory subset for one of the meta-classes that
can generate output which spans object classes (so B,U,C,X, and P),
insert a title at the start of the resulting inventory list.  (Iu and
Ix produce alternate output that already includes a title.)

Also, stop handling '$' differently for menustyles traditional and
combination from full and partial.  'I$' was running the '$' command
for the first two styles but just showing the inventory entry for
gold for the last two.  Change to the latter for all styles.
2022-04-10 06:52:39 -07:00
Pasi Kallinen
ec4fafcf53 Fix erroneous test_move params 2022-04-10 12:52:39 +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
PatR
dadbea1d8c preliminary fix for github issue #726 - restdamage
Reported by entrez, restoring a saved game runs the shop wall/floor
damage repair routine.  It was taking place before attached ball
and chain were fully restored so the repair routine treated them as
ordinary objects if they happened to be in a wall gap that gets
fixed on the same turn as restore takes place.  They could end up
being moved to a spot that's too far from the hero and then trigger
an impossible "b&c distance".

This restores ball and chain before shop damage repair takes place
so the repair routine deals with them sanely and the impossible won't
occur any more.  However, the repair still happens before the current
level's map has been displayed and that looks pretty strange during
the shopkeeper's message.  Also, if the hero and the ball start on
opposite sides of the gap, after the gap is repaired the ball will
still be shown as a remembered object at its old spot even though it
ends up being located at the hero's feet.

Closes #726

but more work is needed...
2022-04-09 12:02:30 -07:00
PatR
ea15bc05ec formatting attached ball and chain
When punished, the ball gets formatted as
| heavy iron ball (chained to you)
but the chain was just "iron chain".  Since iron golems leave some
of those behind, doname() shouldn't just assume that you know which
chain is locked to your leg.  Change the formatting for uchain to
| iron chain (attached to you)
2022-04-09 11:45:43 -07:00
PatR
daadb53ec0 refine setworn()'s impossible()
If setworn() issues "Setworn: mask = 1234.", format the number in
hexadecimal so that the high bits are easier to decipher.  Noticed
when experimenting with ball and chain where the decimal values of
their worn-masks are beyond the range of powers of 2 I recognize.
2022-04-09 11:40:47 -07:00
PatR
d52e6732a8 fix github issue #722 - unique monster's corpse
Issue #722 posted by copperwater and commented on by Entrez:  both
shk_your() and the() inserted "the" in front of a unique monster's
corpse, yielding "the Lord Surtur's corpse glows iridescently" and
"the Lord Surtur's corpse drops to the floor."

Teach both of those routines to skip "the" when used for monsters
with personal names.  It now omits "the" for "Medusa's corpse" but
still gives "the Oracle's corpse".

shk_your() operates on an object and can deal explicitly with corpses
of named monsters.  the() operates on text and has to guess whether
it is being used in a similar situation.  Right now the guess is just
"is there an apostrophe present?" and might need further refinement.

Fixes #722
2022-04-09 10:15:34 -07:00
Pasi Kallinen
e53a4c0abd Context sensitive item usage from inventory
Allow selecting an item from inventory and show a menu of actions
applicable for that particular item. Some of the entries might
be slightly spoilerish (eg. it'll reveal that you can read T-shirts),
but the improved usability for new players is more than worth it.

Generally known as "item actions", this was first implemented
in AceHack by Alex Smith.
2022-04-09 15:28:23 +03:00
PatR
dde1ae2e9b prayer timeout bit
It was theoretically possible to reduce prayer timeout by angering
your god.  I'm not sure whether that could actually happen but add
code to avoid it.
2022-04-08 14:48:55 -07:00
Michael Meyer
6bf7ba991f Fix: object detection vs mimic statue disguise
Cursed potions of object detection were showing all mimics disguised as
statues as 'i' glyphs, because object_detect used PM_TENGU as the
corpsenm of any mimic disguise.  Instead, use MCORPSENM when available
so that hidden mimics will be mapped with glyphs corresponding to their
actual disguises.
2022-04-08 10:22:14 -07:00
Michael Meyer
bf53ff9de5 Add message for failed fountain monster detection
When the fountain quaffing monster detection effect was triggered on a
level without any monsters, no message would be printed.  I think this
was the only scenario where drinking from a fountain wouldn't print
anything, so it stood out as unusual.

Print a messsage in the case monster detection fails, to make it
consistent with other fountain effects and ensure it's clear the hero
did still drink from the fountain on that turn.  I used "the water
tastes like nothing" for the (sort of tenuous) connection to there being
nothing living on the level, but there might be a better message to put
in there.
2022-04-08 10:11:20 -07:00
copperwater
99715e005f Make sure xstart and ystart are always zero when not in_mklev
Running #wizloadlua to run Lua scripts that use coordinates in any way
would work differently if you were on certain levels for the first time
versus leaving and returning to them. This is because various bits of
level creation routines can leave xstart and ystart set to non-zero
values, which are then zeroed at some point when leaving and returning
to the level.

Since xstart and ystart are only relevant to level creation and lua
commands, this fixes the problem by zeroing them after leaving mklev
routines. (Saving them with the level doesn't work because xstart and
ystart are relative to the last used des.map, of which there could be
multiple, e.g. in Asmodeus's level or if two map-based themed rooms
happen to generate. I can envision a more complex solution in which
every des.map used in the level can be associated with an identifier,
whose xstart and ystart are saved for use by later post-level-creation
lua scripts, but currently I just want to make them consistent between
level visits.)
2022-04-08 10:05:43 -07:00