Commit Graph

265 Commits

Author SHA1 Message Date
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
nhkeni
acf60063d5 Add missing prototypes for static functions to avoid warnings. 2024-02-29 10:49:53 -05: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
nhmall
688ac6ffbe remove register from variable declarations 2024-02-19 16:30:07 -05:00
nhmall
0dfe92ac61 more italic support
There might be some follow-ups to this.
2024-01-29 08:40:05 -05: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
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
nhmall
0a13d759a3 more bot() tinkering 2023-11-17 09:47:39 -05:00
nhmall
8d1001842d alternative fix for menu search (':')
This avoids clearing core context variables within a window port.
2023-11-17 08:37:54 -05:00
PatR
fc52f0ef42 'menu_headings' option
If the value is "no color&none" report it as "no-color&none" in 'm O'
and for #saveoptions.

Allow "OPTIONS=menu_headings" without any color or attribute value to
mean "no-color&inverse" as it once did before the player could choose
which attribute or color was supported, and matching the default used
when 'menu_headings' hasn't been specified at all.

Accept "OPTIONS=!menu_headings", meaning "no-color&none".

Explicitly reject "OPTIONS=!menu_headings:anything".  It was rejecting
that due to blanket rejection of negated option, but reporting "can't
both have a value and be negated" whether there was any value present
or not.

For preselected menu entries when interactively choosing a new value
via the submenu of 'm O', use the current color and attribute rather
than NO_COLOR and ATR_NONE.
2023-11-14 21:33:09 -08:00
PatR
88e2ee192d perminv_mode: fix menu coloring
The submenu of 'm O' for recently added option 'perminv_mode' didn't
have color 0 changed to NO_COLOR.  On tty the entries came out blue,
on X11 they were nearly invisible.  Qt and curses didn't seem to care.

I checked all the add_menu() calls in src/*.c and managed to refrain
from the impulse to reformat, mostly.
2023-11-13 23:32:38 -08:00
nhmall
a7242760f7 consistent cast syntax 2023-11-13 19:28:19 -05:00
Pasi Kallinen
d2ca1794df Move other add_menu routines to windows.c 2023-11-13 20:12:47 +02:00
Pasi Kallinen
dd5ca5b058 Change menu_headings to accept color and attribute
Instead of just accepting an attribute, it's now possible to
use a color, or both color and attribute, for example:

OPTIONS=menu_headings:inverse
OPTIONS=menu_headings:red
OPTIONS=menu_headings:red&underline

Default is still just inverse.
This lets the player change the menu heading color without
needing to use menu colors for them.

Also makes it so the core uses NO_COLOR instead of 0, for all
the menu lines which don't have any prefedefined color.

Tested for tty, curses, x11, qt, and win32
2023-11-13 07:33:56 +02:00
SHIRAKATA Kentaro
7d007ea365 null-check argument bl before using it 2023-11-09 00:10:23 +09:00
Pasi Kallinen
2fd177ddb5 Simplify add_menu, part 2 2023-11-03 21:01:17 +02:00
Pasi Kallinen
a6051dae81 Simplify adding menu headings 2023-11-03 19:07:15 +02:00
Pasi Kallinen
1d9726f821 More #saveoptions and cond_ options
Only save the cond_ options that are different from the default.
2023-10-31 14:57:36 +02:00
PatR
6303141f1d fix #K4025 - #saveoptions vs cond_ options
Confusion between 'o_status_cond' and 'pfx_cond_'.  Still confusing
but I think now working as intended and expected.

If any cond_xyz option has been loaded from the RC file or changed via
'm O', #saveoptions still saves the full set rather than just the ones
that are different from their default value.
2023-10-31 01:19:20 -07:00
PatR
56036ed5c7 status bit: trucated gold count
Gold on status line can be truncated, so testing the display value
might miss up/down/changed highlights.  I don't think that it actually
matters since a hero cannot pick up enough gold to reach the 999999
truncation threshold.

Normal amounts still seem to highlight correctly after this.
2023-09-16 17:48:51 -07:00
PatR
2a5f03a3b4 status hilites: Hp and Pw percentages
The hitpoints and power/energy status values (and corresponding
maxima) shown on the screen are capped at 9999 to control status line
width.  The actual values can be bigger than that.  Highlights based
on percentages were doing their calculations on the potentially
truncated values rather than on the actual ones.

Add another field to the blstat[] structure, populate it for BL_HP,
BL_HPMAX, BL_ENE, and BL_EXEMAX and switch to it for their percentage
calculations.

Doesn't seem to break highlighting of 'normal' range values but hasn't
been tested for extreme ones.
2023-09-16 12:42:26 -07:00
PatR
e451966266 botl.c cleanup
Mainly miscellaneous source formatting, plus some expanded comments
and #undef of macros when done with them.
2023-09-16 10:15:05 -07:00
PatR
450efa0dc4 status hilites fix
The options menu for status hilites wouldn't work as intended if the
entries in the initblstats[] array were changed to not be in BL_xyz
order.  (No effect on current behavior since they are in that order.)
2023-09-15 12:35:42 -07:00
PatR
9f16eaa0a5 fix 'up' and 'down' status highlighting for HP
If there was a status_hilite rule for hitpoints:up, it got used for
both up and down changes.  If there was one for hitpoints:down, it got
ignored even if there was no 'up' rule.  The flag for which direction
the value changed was always positive even when the value went down.

I'm reasonably sure that at some point HP up/down worked correctly.
This problem was present in 3.6.4; I didn't go back any farther.
2023-08-05 12:50:47 -07:00
PatR
70791271dd update PR #1071 - highlighting critical HP
If status field 'hitpoints' has rules for both 'criticalhp' and 'up'
or 'down' or 'changed', make critical-hp take precedence.  Otherwise
critical-hp might never be seen because of the value changing every
move (if hero has regeneration attribute).  Normally up/down/changed
take precedence over other types of highlighting.

Something is messed up with up/down/changed HP though.  I'm seeing
the 'up' highlight when it goes either up or down and not seeing the
'down' highlight at all.  'up' and 'down' for gold work as expected.
2023-08-04 22:33:29 -07:00
vultur-cadens
df2799faff add a statushilite option for critically low HP
This allows players to specify a highlight for critically low HP in
the config file, for example:

OPTIONS=hilite_status:hitpoints/criticalhp/purple&inverse

This will cause the hitpoints field to be highlighted when HP is low
enough to be considered a major trouble.  The new "criticalhp" setting
only applies to the hitpoints field.

Since the critical HP threshold changes with level (and most of the
fractions are not integer percents) it was impossible to set
highlights to match the critical HP threshold using percentage
settings.
2023-07-13 13:58:26 -07:00
PatR
ee27ec97d1 tutorial tweaks
Replace tests against tutorial_dnum with 'In_tutorial()' predicate.

Give a message when entering the tutorial (via level change mechanism).

Likewise, give a message when resuming regular play.

If player uses #quit or ^C in the tutorial, ask whether to cut the
tutorial short and resume regular play; skip "Really quit?" if the
answer is yes.  Behavior is a bit odd for ^C + yes; it just sits there
until player types something.
2023-06-04 00:22:14 -07:00
PatR
2bbfed2183 fix github issue #1046 - tutorial anomalies
Reported by Noisytoot:  going from level tut-1 to tut-2 returned the
hero's starting equipment too soon, and exiting the tutorial from
tut-2 let the hero keep any equipment acquired within the tutorial.

Entering and leaving the tutorial was being handled by lua code in
the level description of tut-1 and adding a second level messed that
up.  I didn't see any way of handing that with level-specific lua
code so I made it become the core's responsibility.  gotolevel()
knows when the hero is moving from one dungeon branch to another so
it can recognize entry to or exit from the tutorial easily.

While fixing this, prevent #invoke of the Eye of the Aethiopica from
offering the tutorial as a candidate destination (was feasible if it
had been entered at start of game).

Not fixed:  levels visited in the tutorial become part of #overview.

Show location as "Tutorial:1" instead of "Dlvl:1" on status lines.
Only tested with tty; some interfaces handle location themselves and
may need their own fixup for this.

Fixes #1046
2023-06-03 16:39:12 -07:00
nhmall
de79240dea some comment spelling fixes 2023-03-16 22:27:01 -04:00
nhmall
ac87656855 remove a static analyzer warning from botl.c
One static analyzer warned that there was a lower bound range check
ahead of the array index, but no upper bound check.
2023-01-12 16:28:39 -05:00
nhmall
8120b74051 realign macro continuation after g to g? expansion 2022-12-07 11:24:17 -05: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
nhmall
6ab7cafb25 quiet a warning that has appeared recently
botl.c:1303:25: warning: variable 'notpresent' set but not used [-Wunused-but-set-variable]
    int i, updated = 0, notpresent = 0;
                        ^
1 warning generated.
2022-11-23 23:34:47 -05:00
PatR
220726f7ba status condition options
Option parsing rejected
|OPTIONS=!cond_X
for all valid X.

Using the menu to unselect all condition options treated that as not
having made any choice and didn't make any changes.  That would be
reasonable if nothing was preselected, but things are so unselecting
all of them is a choice.  (A bizarre one, but still should be viable.)

Mostly this deals with including cond_X options when #saveoptions is
used to write a new RC file.  It now produces something like
|OPTIONS=!cond_barehanded,cond_blind,!cond_busy,cond_conf,!cond_deaf,\
|        cond_iron,cond_fly,cond_foodPois,!cond_glowhands,cond_grab,\
|        cond_hallucinat,!cond_held,!cond_ice,cond_lava,cond_levitate,\
|        !cond_paralyzed,cond_ride,!cond_sleep,cond_slime,!cond_slip,\
|        cond_stone,cond_strngl,cond_stun,!cond_submerged,cond_termIll,\
|        !cond_tethered,!cond_trap,!cond_unconscious,!cond_woundedlegs,\
|        !cond_holding
after the last alphabetical option and before the bound keys, menu
colors, and others which aren't simple OPTIONS=X settings.  This only
happens if there is already one or more OPTIONS=cond_X entries in the
old file when it was read or if 'mO' gets used to make any changes.

Not fixed:  after my RC had something similar to the above and before
I changed status conditions to accept negation, I was getting several
"the cond_ option may not both have a value and be negated" messages
written to stdout instead of the config file error handler.  So they
vanished when the screen was initialized without providing a --More--
prompt to acknowledge that they have been seen.
2022-10-31 00:53:10 -07:00
nhmall
99a93fe50b some C99 changes
Instead of using index() macro defined to strchr, use C99 strchr.
Instead of using rindex() macro defined to strrchr, use C99 strrchr.

If you want to try building on a platform that doesn't offer those
two functions, these are available:
    define NOT_C99       /* to make some non-C99 code available */
    define NEED_INDEX    /* to define a macro for index()  */
    define NEED_RINDX    /* to define a macro for rindex() */
2022-10-29 10:54:25 -04:00
PatR
f4210542f0 enc_stat[], hu_stat[]
The definition of enc_stat[] got changed by a pull request nearly a
year ago ('const char *enc_stat[]' -> 'const char *const enc_stat[]')
but the separate declarations for it weren't changed to match.

Make the same change for hu_stat[].  Not sure why the pull request
didn't include it since the old declaration and the usage are same.

The curses one is in code that isn't used.
2022-09-10 19:30:36 -07:00
Pasi Kallinen
f156b0f660 Turn statushilites on automatically if any are defined 2022-08-14 22:32:09 +03:00
Pasi Kallinen
45613ea771 Experimental #saveoptions command
Add a #saveoptions extended command, to allow saving configuration
settings from within the game. This is still highly experimental,
and gives plenty of warnings before asking to overwrite the file.

Lack of option saving is one of the biggest complaints new players
have, so this should help with it.  More experienced players with
highly customized config file should not use this feature, as it
completely rewrites the file, removing all comments and non-config
lines.
2022-08-05 10:33:55 +03:00
PatR
672ef846fa condition mask option's menu
Not related to changes to 'O' but noticed because of those.  The menu
for selecting which status conditions to include on the status line
starts with a special entry for sorting that shouldn't be selected by
the select all and toggle all actions.
2022-08-04 14:09:19 -07:00
nhmall
2770223d10 interface groundwork for core-side color decisions
(user-side decisions really, but as it stands right now
user-side decisions/options are made and processed by the core)

add a parameter to add_menu so color can be passed
2022-06-25 13:21:51 -04:00
PatR
27c287997b tentative fix for #K3626 - segfault when swallowed
release_hold() checked for (Upolyd && sticks(g.youmonst.data)) before
checking for (u.uswallow) and it could set u.ustuck to Null while
u.uswallow remained set to 1.  dmove_core() was accessing u.ustuck->mx
and u.ustuck->my after that, resulting in a crash.

This fixes that particular case but there might be others that also
assume sticky poly'd hero should be handled before swallowed hero.
Being swallowed/engulfed needs to be handled first.
2022-06-21 12:52:29 -07:00
PatR
bbbf5f6bcc duplicate status highlight rules
Noticed earlier when testing the status_hilite_menu_fld() changes:
if you enter a duplicate rule (with different highlighting), it didn't
replace the previous one and the old rule continued to be used.

This still doesn't do replacement, but by adding the new rule at the
end of the list of rules for the specified field instead of inserting
it at the beginning, the new rule gets used.
2022-04-21 02:39:54 -07:00
PatR
0f1674a262 redo status_hilite_menu_fld() [pull request #740]
Pull request #740 by argrath removes some redundant code.  Instead
of adopting that, this rewrites the section of code in question.

The menu involved allows the user to select both "delete hilites"
and "add new hilite" but if both are selected it would only do
deletion.  It also falsely claimed to have done something if delete
was chosen but no highlights were selected to be deleted.  And it
only added one new highlight for the specified field when adding.
This supports both add and delete on the same menu invocation, for
addition it keeps adding until no new highlight is specified, and
has caller do the highlight updating if any changes are made.

Supersedes #740
2022-04-20 22:22:36 -07:00
nhkeni
b5c5496d17 Replace streq() with str_start_is(), which actually has the intended semantics.
Contributed by Michael Meyer.
2022-03-18 20:33:13 -04:00
nhkeni
7dba4f1236 Add FITSint() and FITSuint(),
which cast long long to int while panicking on overflow
2022-03-17 18:10:38 -04:00
nhkeni
1151d54500 Add and use Strlen(), like strlen() but panics on unreasonably long strings. 2022-03-16 21:42:00 -04:00
nhkeni
ff1289e828 Add Strlen(), a strlen(3) that panics if string is stupid long and returns unsigned.
First batch of changes to use it to suppress warnings.
2022-03-16 21:34:21 -04:00
nhkeni
7f484815e5 Add streq() and start finding places it fixes warnings.
Some type fixes from Michael Allison.
2022-03-16 18:50:17 -04:00
nhkeni
a64a666f78 Various type and cast bits. 2022-03-16 18:18:52 -04:00
nhkeni
81b014977d Some easy loss-of-precision fixes. 2022-03-16 17:49:29 -04:00