Commit Graph

549 Commits

Author SHA1 Message Date
nhmall
6c0ae092c6 distinguish global variables that get written to savefile
The g? structs had a mix of variables that were written to
the savefile, and those that were not.

For better clarity and to distinguish those that end up in
the savefile, relocate some g? variables that get written
directly to the savefile into different structs.

This updates EDITLEVEL, although technically it probably
didn't need to, since savefile contents are not changing.

Details:

    gb.bases            -> svb.bases
    gb.bbubbles         -> svb.bbubbles
    gb.branches         -> svb.branches
    gc.context          -> svc.context
    gd.disco            -> svd.disco
    gd.dndest           -> svd.dndest
    gd.doors            -> svd.doors
    gd.doors_alloc      -> svd.doors_alloc
    gd.dungeon_topology -> svd.dungeon_topology
    gd.dungeons         -> svd.dungeons
    ge.exclusion_zones  -> sve.exclusion_zones
    gh.hackpid          -> svh.hackpid
    gi.inv_pos          -> svi.inv_pos
    gk.killer           -> svk.killer
    gl.lastseentyp      -> svl.lastseentyp
    gl.level            -> svl.level
    gl.level_info       -> svl.level_info
    gm.mapseenchn       -> svm.mapseenchn
    gm.moves            -> svm.moves
    gm.mvitals          -> svm.mvitals
    gn.n_dgns           -> svn.n_dgns
    gn.n_regions        -> svn.n_regions
    gn.nroom            -> svn.nroom
    go.oracle_cnt       -> svo.oracle_cnt
    gp.pl_character     -> svp.pl_character
    gp.pl_fruit         -> svp.pl_fruit
    gp.plname           -> svp.plname
    gp.program_state    -> svp.program_state
    gq.quest_status     -> svq.quest_status
    gr.rooms            -> svr.rooms
    gs.sp_levchn        -> svs.sp_levchn
    gs.spl_book         -> svs.spl_book
    gt.timer_id         -> svt.timer_id
    gt.tune             -> svt.tune
    gu.updest           -> svu.updest
    gx.xmax             -> svx.xmax
    gx.xmin             -> svx.xmin
    gy.ymax             -> svy.ymax
    gy.ymin             -> svy.ymin

Related note:
There are some pointer variables that are heads of chains that were not
moved from 'g?' to 'sv?', because they are not actually written to the
savefile directly, but the objects/monst/trap/lightsource/timer in the
chains they point to are. That can be changed, if desired.
Examples: gi.invent, gm.migrating_objs, gb.billobjs, gm.migrating_mons,
          gf.ftrap, gl.light_base, gt.timer_base
2024-07-13 14:57:50 -04: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
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
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
d5546d3384 revise curses_raw_print()
For curses, behave like tty by keeping a count of messages issued via
raw_print, then if that is non-zero issue a prompt and require the
player to acknowledge them before it erases the screen.  Mainly so
that complaints during RC file processing will be seen.

For tty, force getret() to be an unconditional routine instead of
sometimes a routine, sometimes a macro which calls another routine.
2024-05-17 14:38:17 -07:00
Pasi Kallinen
a57d0e6f4f Curses: add support for the palette config option
Depends on CHANGE_COLOR compile-time option.

Also allow multiple palette-definitions in the config file.
2024-04-13 12:01:43 +03:00
PatR
7da370d74a experimental hitpointbar change
For tty, make hitpointbar blink if current HP falls to the critical
HP threshold.  Doesn't require status highlighting.  Not changed:
when status highlighting is active, use the HP color but force the
attribute to be inverse (plus blink if the criterium is met) rather
than whatever the HP highlight specifies.

For curses, do the same thing.  It used to honor HP attribute for
hitpointbar, now it behaves the same as tty:  always inverse, maybe
combined with blink.  The new code assumes that inverse and color
can be turned off without turning off active blink in the process.

I had intended to make hitpointbar be a full-fledged status field
(which happens to be rendered on top of title) so that it could be
highlighted differently from hit points (mainly so that one could
highlight up and down changes while the other showed percentages).
This is less versatile than that but much simpler.
2024-04-11 11:06:29 -07:00
Pasi Kallinen
c4d4bafb44 Fix NO_TERMS compile, rename func
... to match others, from tty_curs_set to term_curs_set
2024-04-02 14:31:33 +03:00
Pasi Kallinen
7030b0b9fe tty: hide cursor unless waiting for user input
Use vi (cursor_invisible) and ve (cursor_normal) to hide and show
cursor, if the terminal supports those.  This way on a slower
connection the cursor doesn't jump all over the place when doing
map or menu updates.
2024-04-02 10:28:20 +03:00
PatR
dddfd66e7a undo recent DECgraphics optimizations
Unresolved display issues with rxvt-unicode after the optimizations
dealing with switching between DECgraphics line-drawing character set
and normal character set.

Effectively comment them out rather than revert the commits.
2024-03-31 15:49:16 -07:00
nhmall
652b94ab41 another fix reinstatement 2024-03-25 09:57:53 -04:00
nhmall
2b6d1fa942 reinstate a warning fix 2024-03-25 09:53:52 -04:00
nhmall
7f2af9698f put wintty.c and termcap.c logic to previous 2024-03-25 09:38:54 -04:00
nhmall
e3409fd4af reinstate 256 color 2024-03-24 23:47:24 -04:00
nhmall
4d453193cf wintty.c double-check ordering of color on/off 2024-03-24 21:41:32 -04:00
nhmall
750cf7f619 rename glyphmap nhcolor field to customcolor 2024-03-24 11:04:31 -04:00
nhmall
0b3a0f1b72 follow-up: fix a wintty.c text substitution error 2024-03-24 07:17:40 -04:00
PatR
d2928ce2ba symset customization warning fixes 2024-03-23 13:39:23 -07:00
nhmall
ba00dc9066 sever extracolors from utf8map and ENHANCED_SYMBOLS
move the custom color data into its own field in the glyphmap
and disassociate it from the unicode/utf8 stuff.

move the glyphcache stuff during options processing and parsing
into new file glyphs.c and out of utf8map.c, and make it
general, and not part of ENHANCED_SYMBOLS.

Do the groundwork for allowing glyph color customizations to
work when any symset is loaded and not restrict it only to
the enhanced1 H_UTF8 symsets.

The customizations in effect are still affiliated with a particular
symset.

Also closes #1224, but the PR itself references a data structure
made obsolete by this commit. The curses comment from the PR was
added into the code.

The PR also made several suggestions, but only the first
one has been included in this commit (and no longer based on
the handler), that being:
"allow defining colors if other symbol handling modes are used
(possibly limited to the standard 16 colors)."

FredrIQ also wrote the following suggestions in PR#1224:

Something I was also contemplating, unrelated to implementation of this
support in curses, would be the ability for the following:

allow defining colors if other symbol handling modes are used (possibly limited to the standard 16 colors)
allow defining attributes (for example: glyph:G_pet_female_kitten:U+0066/red/underline)
allow specifying glyphs as wildcards for defining global color/attribute changes

Something I also want to see are keywords for "don't change the current defined data". If this
were to be added, you could for example do this:
OPTIONS=glyph:G_*_fox:U+0064/blue
OPTIONS=glyph:G_statue_*:basechar/gray/underline
for "make all foxes use a blue color, make all statues gray with underline" without needing
to specify the relevant character for every statue. This ("basechar", "basefg", etc)
should perhaps also be added for MENUCOLORS and statushilites, so that you can, for
example, underline all items being worn without needing to specify a bunch of
near-duplicate rules for combining BUC colors + underline worn items
as per #1064
2024-03-23 15:36:22 -04:00
nhmall
6619d10d90 ENHANCED_SYMBOLS: store all CLR_ colors specially
The 0x1000000 bit (NH_BASIC_COLOR bit) was used to mark
CLR_BLACK when storing it in u->ucolor. Now, all of the basic CLR_*
colors are stored that way.

The NH_BASIC_COLOR bit indicates that the value in u->ucolor is
not an rgb value, rather it is one of the 0-15 basic NetHack colors.
The window-ports need to strip the NH_BASIC_COLOR bit off before using
it for color changes.
2024-03-03 18:31:11 -05:00
Pasi Kallinen
53778ee507 Use single define for max message history
... instead of having every windowport define their own variant.
Affects tty, curses, X11, and Windows GUI.
2024-03-03 11:34:59 +02:00
RainRat
a3658f85ac fix typos 2024-02-28 20:15:56 -08:00
PatR
41a5565403 new 'showvers' option
Add options 'showvers' (boolean) and 'versinfo' (numeric mask) to
show nethack's version on the status lines during play.  It won't be
particularly interesting to ordinary players but should be useful
when making screenshots or video to be streamed, or for someone who
switches between git branches or between nethack and variants.

I worked on this several months back but it was combined with
unfinished changes to 'hitpointbar'.  I've separated it out so that
it can be put into use.  When enabled, one or more components of
"<name> <branch> <version>" will be shown right justified after
status conditions.  At present the default is "<branch>" if that is
available and overall status isn't 'released', or "<version>" if
'released' or if branch isn't available.  That might need some
refinement.

It works as intended for tty and curses, although some abbreviation
mechanism would be useful if/when the program resorts to abbreviating
status conditions to make things narrow enough to fit.

For X11, it works ok for fancy_status:True (the default, controlled
via NetHack.ad settings) but is messed up for tty-style status.  The
text is positioned correctly but there are gaps in it, making it
appear garbled, similar to what I saw when I tried and failed to
implement statuslines:3 for X11.  [It might be due to having empty
condition widgets be 1 pixel wide instead of being totally removed
but I don't think the situation is that simple.]

For Qt, if the text needs to be truncated in order to fit, the center
portion of the string will be shown, discarding parts from the left
and right.  That ought to discard from left and retain rightmost
portion instead.

For win32|mswin|Win GUI, no attempt to support it has been included.
Things should be ok when 'showvers' is left as False (the default)
but I don't know what will happen if that gets toggled to True.  At a
minimum, the version info won't be right justified.  The information,
or at least some of it, is displayed in the game window's title bar
so there isn't any pressing need to add it to status, but toggling
the option will need to behave sensibly if it doesn't already.
2024-02-28 11:47:16 -08:00
nhkeni
3f5d1d3a36 split DUMPLOG
DUMPLOG requests the DUMPLOG feature as it does now
DUMPLOG_CORE requests the internal buffering only (used for CRASHREPORT)

This allows CRASHREPORT to access recent messages without performing
any file I/O.
2024-02-20 21:42:05 -05:00
nhmall
688ac6ffbe remove register from variable declarations 2024-02-19 16:30:07 -05:00
PatR
5ef51a88d4 more DECgraphics tinkering 2024-02-19 11:04:29 -08:00
PatR
9226a5dea6 couple of DECgraphics optimizations
If a termcap entry for ending attributes and color also contains
the code to switch from secondary font back to primary (HE_resets_AS
hack), maybe strip the AS code out of HE (and clear the HE_resets_AS
flag) when setting up DECgraphics.  Affects whether nethack sends
extra AS sequences while rendering a run of VT line-drawing chars.
My HE doesn't reset AS so that aspect hasn't been exercized.

When switching back and forth between normal and line-drawing,
defer the switch away from line-drawing if the character will be
rendered the same in both character sets (uppercase letter, digit,
most punctuation).  That might just defer the AE, but could skip it
and next AS depending on what characters are written.  The cycle
might repeat an arbitrary number of times, avoiding sending many
AS+AE combinations rather than just one.

Both of these optimizations are pretty small but reducing the number
of characters sent from a server to a remote user is worthwhile.
2024-02-18 15:01:21 -08:00
PatR
2e6802d2b3 potential DECgraphics optimization
Add a comment about something that occurred to me when fixing the
^C-during-DECgraphics-output situation several days ago.  I don't
think there's any compelling reason to avoid this optimization, but
this only describes it without actually implementing it.
2024-02-17 03:28:40 -08:00
PatR
73feb80a00 fix #K4097 - ^C during DECgraphics on tty
For tty, if ^C interrupt occurred while the terminal was displaying
VT line drawing characters, it wouldn't finish updating the map and
switch back to regular characters, so the "Really quit?" prompt was
illegible.

Rather than muck about with the signal handler, just add a fixup to
tty_putstr() since prompting ultimately uses putstr(WIN_MESSAGE).
Reproducing the situation isn't straightforward; I didn't even try.
2024-02-03 16:22:45 -08:00
nhmall
d3dd9277f9 follow-up 1 for italic 2024-01-29 10:00:06 -05:00
nhmall
0dfe92ac61 more italic support
There might be some follow-ups to this.
2024-01-29 08:40:05 -05:00
Pasi Kallinen
fd8b2b58d1 petattr: Change accepted parameters, add support for tty 2024-01-28 10:05:42 +02:00
nhmall
4e19221e55 variable 'display' causes shadow variable warnings in X11 build
display.botl      -> disp.botl
display.botlx     -> disp.botlx
display.time_botl -> disp.time_botl
2024-01-05 05:58:51 -05:00
nhmall
49a5d043c0 consistent use of TRUE vs 1 with botl and botlx 2024-01-04 23:48:38 -05:00
nhmall
22e52ee905 bundle the display-related hints, that tell bot() and others
that an update is required, into a struct. Remove it from
context since there is no reason to save those.
2024-01-04 23:16:27 -05:00
PatR
36c5843103 TTY_PERM_INVENT crash fix
The change 3 weeks ago for #4059 (to fix tty perm_invent memory leak)
resulted in nethack crashing during exit if built with TTY_PERM_INVENT
enabled and ending the game when perm_invent window isn't displayed.

This exits cleanly with or without perm_invent being shown and avoids
the memory leak which triggered the prior change.
2023-12-28 14:25:39 -08:00
nhmall
0006ff7d01 Merge branch 'combo_msg_window_vs_getlin' of https://github.com/entrez/NetHack into NetHack-3.7 2023-12-10 10:39:58 -05:00
PatR
4140a0023c fix #4059 - TTY_PERM_INVENT not freeing memory
As part of the tty resize handling revision, code dealing with the
perm_invent window was moved out of tty_destroy_nhwindow() was moved
into a separate routine.  The new routine would have been called for
a window of NHW_PERMINVENT, but WIN_INVENT doesn't have that type,
just ordinary NHW_MENU, so the cleanup wasn't happening, resulting in
a memory leak.
2023-12-07 18:36:14 -08:00
PatR
634f492827 fix #K4058 - tty: perm_invent fixes
I think this fixes all problems with the boundary boz drawn around
perm_invent.  Also, if you enabled perm_invent in inuse_only mode
while there are already more items in use than would fix in the
available number of lines, it wasn't switching to two columns until
the next update_inventory().  And the new color handling wasn't
incorporate into tty_refresh_inventory() so after a corner window
clobbered some of perm_invent, it got redrawn but without color,
again until the next update_inventory().

With any luck this fixes more bugs than it introduces....
2023-12-07 03:22:44 -08:00
PatR
7c20bf4afa tty: term_start_color(NO_COLOR)
Make term_start_color() more versatile.  If it gets passed NO_COLOR
then it performs term_end_color().  Should be able to streamline
some of the color handling this way although this hasn't done so.
2023-12-07 02:52:41 -08:00
nhmall
11a926c4cc TTY_PERM_INVENT: menucolors colors text, not inv letter
This diff is slightly inflated because I relocated a tty function
within win/tty/wintty.c.
2023-12-06 15:41:06 -05:00
nhmall
45856e3b5b follow-up: bordercolor lacked have expected offset 2023-12-06 13:49:33 -05:00
nhmall
8018fe64cf remove an outdated TODO: comment in wintty.c
A comment made reference to something that is fulfilled by
the core now, but that probably wasn't the case when that
comment was originally added.
2023-12-06 13:42:28 -05:00
nhmall
54332f5598 TTY_PERM_INVENT: honor color passed by add_menu()
Features like menucolors and so forth, are now done in the
core, and passed to the window interfaces via add_menu().

TTY_PERM_INVENT was disregarding the passed color value.

That can be turned off by the option !menucolors.

If a way to turn off menucolors in TTY_PERM_INVENT (or
perhaps in any perm_invent implementation), while keeping
it on for other menus, then a new option will be required.
2023-12-06 13:30:33 -05:00
PatR
1b1c45d3ce TTY_PERM_INVENT perminv_mode=inuse
Revise the tty permanent inventory window's in-use mode to be able to
switch back and forth between one full width panel and two side-by-side
half width panels on the fly as needs dictate.

A lot of trial and error involved but I think it has reached a state
where it is reliable, and the smaller number of lines required at
present can probably be viable for actual usage.  At the moment it
requires at least 10 extra lines below the standard tty mesg+map+stat
display, 34 lines total for statuslines:2 or 35 for statuslines:3.
The top and bottom of the 10 or more extra lines get drawn as boundary
lines using wall characters, leaving 8 lines for full width or 16 half
lines when 8 isn't enough.  If more that 16 items are in use (maybe
lots of lit candles forced into separate inventory slots or a
menagerie on leashes), the excess get skipped.  However, it will use
more lines if they are available.  Prior to a few days ago it was
requiring 17 extra lines and able to show 15 items as full lines only,
unable to take advantage of more lines when available.
2023-12-06 02:19:41 -08:00
PatR
2d8ba944e1 add some flexibility to TTY_PERM_INVENT
Allow perm_invent to be enabled with 1 less line when statuslines==2
by not reserving a line for statuslines==3.  If the player changes
that from 2 to 3, the perm_invent window is torn down and repositioned
one line lower if that will fit.  If it won't fit, it won't reenable.

Temporarily(?) allow perminv_mode==InUse to be enabled with room for
only 8 lines instead of requiring 15.  It will use more than 8 if are
more rows.

8 happens to be the amount (via 1+21+3+(1+8+1)) that will fit within
35 lines which is the biggest I can make fit on may laptop without
switching to a smaller font.  Switching is a nuisance, worse than that
for the font tiny enough to fit the full perm_invent.

ToDo:  if in-use won't fit in the number of lines allotted, switch to
two columns before resorting to ignoring the excess.

Maybe:  allow fewer lines for full perm_invent too and use the '|'
command to scroll them.  Might be too clumsy to be worthwhile.
2023-12-04 13:20:25 -08:00
nhmall
706232faf0 invlet_basic follow-up 2023-11-30 11:23:29 -05:00
nhmall
d7fef5f194 avoid another magic number
Some of the hardcoded +1 scattered about are likely
invlet_gold or invlet_overflow, but I didn't hunt those down.
2023-11-30 11:15:32 -05:00
Michael Meyer
79cdcff7e4 Fix: msg_window:combination and TTY getlin() ^P
The ability to use ^P from within a TTY getlin prompt didn't work with
msg_window:combination: it's a combination (unsurprisingly) of 'full'
and 'single', but hooked_tty_getlin() was treating it like 'full': i.e.
expecting everything to be displayed at once, with doprev_message()
returning only once the user was finished reading.  I didn't even know
^P was supposed to be accessible from a getlin prompt until Pat's recent
commit 5120764, because I have always used msg_window:combination -- I
had come up with a system where I'd name a potion thrown at me "xx",
check the previous messages with ^P, and then rename it from the
discoveries list.  This will be a lot easier!
2023-11-30 01:06:28 -05:00