add MALE, FEMALE, and gender-neutral names for individual monster species
to the mons array. The gender-neutral name (NEUTRAL) is mandatory, the
MALE and FEMALE versions are not.
replace code uses of the mname field of permonst with one of the three
potentially-available gender-specific names.
consolidate some separate mons entries that differed only by species into a
single mons entry (caveman, cavewoman and priest,priestess etc.)
consolidate several "* lord" and "* queen/* king" monst entries into
their single species, and allow both genders on some where it makes some
sense (there is probably more work and cleanup to come out of this at some
point, and the chosen gender-neutral name variations are not cast in stone
if someone has better suggestions).
related function or macro additions:
pmname(pm, gender) to get the gender variation of the permonst name. It
guards against monsters that haven't got anything except NEUTRAL naming
and falls back to the NEUTRAL version if FEMALE and MALE versions are
missing.
Ugender to obtain the current hero gender.
Mgender(mtmp) to obtain the gender of a monster
While the code can safely refer directly to pmnames[NEUTRAL] safely in the
code because it always exists, the other two (pmnames[MALE] and
pmnames[FEMALE] may not exist so use:
pmname(ptr, gidx)
where -ptr is a permonst *
-gidx is an index into the pmnames array field of the
permonst struct
pmname() checks for a valid index and checks for null-pointers for
pmnames[MALE] and pmnames[FEMALE], and will fall back to pmnames[NEUTRAL] if
the pointer requested if the requested variation is unavailable, or if the
gidx is out-of-range.
Allow code to specify makemon flags to request female or male (via MM_MALE
and MM_FEMALE flags respectively)to makedefs, since the species alone doesn't
distinguish male/female anymore. Specifying MM_MALE or MM_FEMALE won't
override the pm M2_MALE and M2_FEMALE flags on a mons[] entry.
male and female tiles have been added to win/share/monsters.txt.
The majority are duplicated placeholders except for those that were
separate mons entries before. Perhaps someone will contribute artwork in the
future to make the male and female variations visually distinguishable.
tilemapping via has the MALE tile indexes in the glyph2tile[]
array produced at build time. If a window port has information that the
FEMALE tile is required, it just has to increment the index returned
from the glyph2tile[] array by 1.
statues already preserved gender of the monster through STATUE_FEMALE
and STATUE_MALE, so ensure that pmnames takes that into consideration.
I expect some refinement will be required after broad play-testing puts it to
the test.
consolidate caveman,cavewoman and priest,priestess monst.c entries etc
This commit will require a bump of editlevel in patchlevel.h because it alters
the index numbers of the monsters due to the consolidation of some. Those
index numbers are saved in some other structures, even though the mons[] array
itself is not part of the savefile.
Window Port Interface Change
Also add a parameter to print_glyph to convey additional information beyond
the glyph to the window ports. Every single window port was calling back to
mapglyph for the information anyway, so just included it in the interface and
produce the information right in the display core.
The mapglyph() function uses will be eliminated, although there are still some
in the code yet to be dealt with.
win32, tty, x11, Qt, msdos window ports have all had adjustments done to
utilize the new parameter instead of calling mapglyph, but some of those
window ports have not been thoroughly tested since the changes.
Interface change additional info:
print_glyph(window, x, y, glyph, bkglyph, *glyphmod)
-- Print the glyph at (x,y) on the given window. Glyphs are
integers at the interface, mapped to whatever the window-
port wants (symbol, font, color, attributes, ...there's
a 1-1 map between glyphs and distinct things on the map).
-- bkglyph is a background glyph for potential use by some
graphical or tiled environments to allow the depiction
to fall against a background consistent with the grid
around x,y. If bkglyph is NO_GLYPH, then the parameter
should be ignored (do nothing with it).
-- glyphmod provides extended information about the glyph
that window ports can use to enhance the display in
various ways.
unsigned int glyphmod[NUM_GLYPHMOD]
where:
glyphmod[GM_TTYCHAR] is the text characters associated
with the original NetHack display.
glyphmod[GM_FLAGS] are the special flags that denote
additional information that window
ports can use.
glyphmod[GM_COLOR] is the text character
color associated with the original
NetHack display.
Support for including the glyphmod info in the display glyph buffer
alongside the glyph itself was added and is the default operation.
That can be turned off by defining UNBUFFERED_GLYPHMOD at compile time.
With UNBUFFERED_GLYPHMOD operation, a call will be placed to map_glyphmod()
immediately prior to every print_glyph() call.
581 lines
11 KiB
C
581 lines
11 KiB
C
/* NetHack 3.7 safeproc.c */
|
|
/* Copyright (c) Michael Allison, 2018 */
|
|
/* NetHack may be freely redistributed. See license for details. */
|
|
|
|
/* must #define SAFEPROCS in xxxconf.h or via CFLAGS or this won't compile */
|
|
#include "hack.h"
|
|
|
|
/*
|
|
* ***********************************************************
|
|
* This is a complete WindowPort implementation that can be
|
|
* assigned to the windowproc function pointers very early
|
|
* in the startup initialization, perhaps immediately even.
|
|
* It requires only the following call:
|
|
* windowprocs = *get_safe_procs(0);
|
|
*
|
|
* The game startup can trigger functions in other modules
|
|
* that make assumptions on a WindowPort being available
|
|
* and bad things can happen if any function pointers are
|
|
* null at that time.
|
|
*
|
|
* Some ports prior to 3.6.2 made attempts to early init
|
|
* various pieces of one of their WindowPorts, but that
|
|
* caused conflicts if that particular WindowPort wasn't
|
|
* the one that the user ended up selecting in their
|
|
* config file later. The WindowPort interfaced was designed
|
|
* to allow multiple WindowPorts to be linked into the same
|
|
* game binary.
|
|
*
|
|
* The base functions established by a call to get_safe_procs()
|
|
* accomplish the goal of preventing crashes, but not much
|
|
* else.
|
|
*
|
|
* There are also a few additional functions provided in here
|
|
* that can be selected optionally to provide some startup
|
|
* functionality for getting messages out to the user about
|
|
* issues that are being experienced during startup in
|
|
* general or during options parsing. The ones in here are
|
|
* deliberately free from any platforms or OS specific code.
|
|
* Please leave them using stdio C routines as much as
|
|
* possible. That isn't to say you can't do fancier functions
|
|
* prior to initialization of the primary WindowPort, but you
|
|
* can provide those platform-specific functions elsewhere,
|
|
* and assign them the same way that these more generic versions
|
|
* are assigned.
|
|
*
|
|
* The additional platform-independent, but more functional
|
|
* routines provided in here should be assigned after the
|
|
* windowprocs = *get_safe_procs(n)
|
|
* call.
|
|
*
|
|
* Usage:
|
|
*
|
|
* windowprocs = *get_safe_procs(0);
|
|
* initializes a set of winprocs function pointers that ensure
|
|
* none of the function pointers are left null, but that's all
|
|
* it does.
|
|
*
|
|
* windowprocs = *get_safe_procs(1);
|
|
* initializes a set of winprocs functions pointers that ensure
|
|
* none of the function pointers are left null, but also
|
|
* provides some basic output and input functionality using
|
|
* nothing other than C stdio routines (no platform-specific
|
|
* or OS-specific code).
|
|
*
|
|
* ***********************************************************
|
|
*/
|
|
|
|
struct window_procs safe_procs = {
|
|
"safe-startup", 0L, 0L,
|
|
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, /* color availability */
|
|
safe_init_nhwindows, safe_player_selection, safe_askname, safe_get_nh_event,
|
|
safe_exit_nhwindows, safe_suspend_nhwindows, safe_resume_nhwindows,
|
|
safe_create_nhwindow, safe_clear_nhwindow, safe_display_nhwindow,
|
|
safe_destroy_nhwindow, safe_curs, safe_putstr, safe_putmixed,
|
|
safe_display_file, safe_start_menu, safe_add_menu, safe_end_menu,
|
|
safe_select_menu, safe_message_menu, safe_update_inventory, safe_mark_synch,
|
|
safe_wait_synch,
|
|
#ifdef CLIPPING
|
|
safe_cliparound,
|
|
#endif
|
|
#ifdef POSITIONBAR
|
|
safe_update_positionbar,
|
|
#endif
|
|
safe_print_glyph, safe_raw_print, safe_raw_print_bold, safe_nhgetch,
|
|
safe_nh_poskey, safe_nhbell, safe_doprev_message, safe_yn_function,
|
|
safe_getlin, safe_get_ext_cmd, safe_number_pad, safe_delay_output,
|
|
#ifdef CHANGE_COLOR /* the Mac uses a palette device */
|
|
safe_change_color,
|
|
#ifdef MAC
|
|
safe_change_background, set_safe_font_name,
|
|
#endif
|
|
safe_get_color_string,
|
|
#endif
|
|
safe_start_screen, safe_end_screen, safe_outrip,
|
|
safe_preference_update,
|
|
safe_getmsghistory, safe_putmsghistory,
|
|
safe_status_init,
|
|
safe_status_finish, safe_status_enablefield,
|
|
safe_status_update,
|
|
safe_can_suspend,
|
|
};
|
|
|
|
struct window_procs *
|
|
get_safe_procs(optn)
|
|
int optn;
|
|
{
|
|
if (optn) {
|
|
/* include the slightly more functional stdc versions */
|
|
safe_procs.win_raw_print = stdio_raw_print;
|
|
safe_procs.win_raw_print_bold = stdio_raw_print_bold;
|
|
safe_procs.win_nhgetch = stdio_nhgetch;
|
|
safe_procs.win_wait_synch = stdio_wait_synch;
|
|
if (optn == 2)
|
|
safe_procs.win_raw_print = stdio_nonl_raw_print;
|
|
}
|
|
return &safe_procs;
|
|
}
|
|
|
|
/*ARGSUSED*/
|
|
void
|
|
safe_init_nhwindows(argcp, argv)
|
|
int *argcp UNUSED;
|
|
char **argv UNUSED;
|
|
{
|
|
return;
|
|
}
|
|
|
|
void
|
|
safe_player_selection()
|
|
{
|
|
return;
|
|
}
|
|
|
|
void
|
|
safe_askname()
|
|
{
|
|
return;
|
|
}
|
|
|
|
void
|
|
safe_get_nh_event()
|
|
{
|
|
return;
|
|
}
|
|
|
|
void
|
|
safe_suspend_nhwindows(str)
|
|
const char *str;
|
|
{
|
|
return;
|
|
}
|
|
|
|
void
|
|
safe_resume_nhwindows()
|
|
{
|
|
return;
|
|
}
|
|
|
|
void
|
|
safe_exit_nhwindows(str)
|
|
const char *str;
|
|
{
|
|
return;
|
|
}
|
|
|
|
winid
|
|
safe_create_nhwindow(type)
|
|
int type;
|
|
{
|
|
return WIN_ERR;
|
|
}
|
|
|
|
void
|
|
safe_clear_nhwindow(window)
|
|
winid window;
|
|
{
|
|
return;
|
|
}
|
|
|
|
/*ARGSUSED*/
|
|
void
|
|
safe_display_nhwindow(window, blocking)
|
|
winid window;
|
|
boolean blocking;
|
|
{
|
|
return;
|
|
}
|
|
|
|
void
|
|
safe_dismiss_nhwindow(window)
|
|
winid window;
|
|
{
|
|
return;
|
|
}
|
|
|
|
void
|
|
safe_destroy_nhwindow(window)
|
|
winid window;
|
|
{
|
|
return;
|
|
}
|
|
|
|
void
|
|
safe_curs(window, x, y)
|
|
winid window;
|
|
int x, y;
|
|
{
|
|
return;
|
|
}
|
|
|
|
void
|
|
safe_putstr(window, attr, str)
|
|
winid window;
|
|
int attr;
|
|
const char *str;
|
|
{
|
|
return;
|
|
}
|
|
|
|
void
|
|
safe_putmixed(window, attr, str)
|
|
winid window;
|
|
int attr;
|
|
const char *str;
|
|
{
|
|
return;
|
|
}
|
|
|
|
void
|
|
safe_display_file(fname, complain)
|
|
const char *fname;
|
|
boolean complain;
|
|
{
|
|
return;
|
|
}
|
|
|
|
void
|
|
safe_start_menu(window, mbehavior)
|
|
winid window;
|
|
unsigned long mbehavior;
|
|
{
|
|
return;
|
|
}
|
|
|
|
/*ARGSUSED*/
|
|
/*
|
|
* Add a menu item to the beginning of the menu list. This list is reversed
|
|
* later.
|
|
*/
|
|
void
|
|
safe_add_menu(window, glyph, identifier, ch, gch, attr, str, itemflags)
|
|
winid window; /* window to use, must be of type NHW_MENU */
|
|
int glyph UNUSED; /* glyph to display with item (not used) */
|
|
const anything *identifier; /* what to return if selected */
|
|
char ch; /* keyboard accelerator (0 = pick our own) */
|
|
char gch; /* group accelerator (0 = no group) */
|
|
int attr; /* attribute for string (like safe_putstr()) */
|
|
const char *str; /* menu string */
|
|
unsigned int itemflags; /* itemflags such as marked as selected */
|
|
{
|
|
return;
|
|
}
|
|
|
|
/*
|
|
* End a menu in this window, window must a type NHW_MENU.
|
|
*/
|
|
void
|
|
safe_end_menu(window, prompt)
|
|
winid window; /* menu to use */
|
|
const char *prompt; /* prompt to for menu */
|
|
{
|
|
return;
|
|
}
|
|
|
|
int
|
|
safe_select_menu(window, how, menu_list)
|
|
winid window;
|
|
int how;
|
|
menu_item **menu_list;
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
/* special hack for treating top line --More-- as a one item menu */
|
|
char
|
|
safe_message_menu(let, how, mesg)
|
|
char let;
|
|
int how;
|
|
const char *mesg;
|
|
{
|
|
return '\033';
|
|
}
|
|
|
|
void
|
|
safe_update_inventory()
|
|
{
|
|
return;
|
|
}
|
|
|
|
void
|
|
safe_mark_synch()
|
|
{
|
|
}
|
|
|
|
void
|
|
safe_wait_synch()
|
|
{
|
|
}
|
|
|
|
#ifdef CLIPPING
|
|
void
|
|
safe_cliparound(x, y)
|
|
int x, y;
|
|
{
|
|
}
|
|
#endif /* CLIPPING */
|
|
|
|
/*
|
|
* safe_print_glyph
|
|
*
|
|
* Print the glyph to the output device. Don't flush the output device.
|
|
*/
|
|
void
|
|
safe_print_glyph(window, x, y, glyph, bkglyph, glyphmod)
|
|
winid window;
|
|
xchar x, y;
|
|
int glyph;
|
|
int bkglyph UNUSED;
|
|
int glyphmod[NUM_GLYPHMOD] UNUSED;
|
|
{
|
|
return;
|
|
}
|
|
|
|
void
|
|
safe_raw_print(str)
|
|
const char *str;
|
|
{
|
|
return;
|
|
}
|
|
|
|
void
|
|
safe_raw_print_bold(str)
|
|
const char *str;
|
|
{
|
|
return;
|
|
}
|
|
|
|
int
|
|
safe_nhgetch()
|
|
{
|
|
return '\033';
|
|
}
|
|
|
|
/*
|
|
* return a key, or 0, in which case a mouse button was pressed
|
|
* mouse events should be returned as character postitions in the map window.
|
|
* Since normal tty's don't have mice, just return a key.
|
|
*/
|
|
/*ARGSUSED*/
|
|
int
|
|
safe_nh_poskey(x, y, mod)
|
|
int *x, *y, *mod;
|
|
{
|
|
return '\033';
|
|
}
|
|
|
|
void
|
|
win_safe_init(dir)
|
|
int dir;
|
|
{
|
|
return;
|
|
}
|
|
|
|
#ifdef POSITIONBAR
|
|
void
|
|
safe_update_positionbar(posbar)
|
|
char *posbar;
|
|
{
|
|
return;
|
|
}
|
|
#endif /* POSITIONBAR */
|
|
|
|
/*
|
|
* safe_status_init()
|
|
* -- initialize the port-specific data structures.
|
|
*/
|
|
void
|
|
safe_status_init()
|
|
{
|
|
return;
|
|
}
|
|
|
|
boolean
|
|
safe_can_suspend()
|
|
{
|
|
return FALSE;
|
|
}
|
|
|
|
void
|
|
safe_nhbell()
|
|
{
|
|
return;
|
|
}
|
|
|
|
int
|
|
safe_doprev_message()
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
char
|
|
safe_yn_function(query, resp, def)
|
|
const char *query;
|
|
const char *resp;
|
|
char def;
|
|
{
|
|
return '\033';
|
|
}
|
|
|
|
/*ARGSUSED*/
|
|
void
|
|
safe_getlin(prompt, outbuf)
|
|
const char *prompt UNUSED;
|
|
char *outbuf;
|
|
{
|
|
Strcpy(outbuf, "\033");
|
|
}
|
|
|
|
int
|
|
safe_get_ext_cmd()
|
|
{
|
|
return '\033';
|
|
}
|
|
|
|
void
|
|
safe_number_pad(mode)
|
|
int mode;
|
|
{
|
|
return;
|
|
}
|
|
|
|
void
|
|
safe_delay_output()
|
|
{
|
|
return;
|
|
}
|
|
|
|
void
|
|
safe_start_screen()
|
|
{
|
|
return;
|
|
}
|
|
|
|
void
|
|
safe_end_screen()
|
|
{
|
|
return;
|
|
}
|
|
|
|
void
|
|
safe_outrip(tmpwin, how, when)
|
|
winid tmpwin;
|
|
int how;
|
|
time_t when;
|
|
{
|
|
return;
|
|
}
|
|
|
|
/*ARGSUSED*/
|
|
void
|
|
safe_preference_update(pref)
|
|
const char *pref UNUSED;
|
|
{
|
|
return;
|
|
}
|
|
|
|
char *
|
|
safe_getmsghistory(init)
|
|
boolean init UNUSED;
|
|
{
|
|
return (char *) 0;
|
|
}
|
|
|
|
void
|
|
safe_putmsghistory(msg, is_restoring)
|
|
const char *msg;
|
|
boolean is_restoring;
|
|
{
|
|
}
|
|
|
|
void
|
|
safe_status_finish()
|
|
{
|
|
}
|
|
|
|
void
|
|
safe_status_enablefield(fieldidx, nm, fmt, enable)
|
|
int fieldidx;
|
|
const char *nm;
|
|
const char *fmt;
|
|
boolean enable;
|
|
{
|
|
}
|
|
|
|
/* call once for each field, then call with BL_FLUSH to output the result */
|
|
void
|
|
safe_status_update(idx, ptr, chg, percent, color, colormasks)
|
|
int idx;
|
|
genericptr_t ptr;
|
|
int chg UNUSED, percent UNUSED, color UNUSED;
|
|
unsigned long *colormasks UNUSED;
|
|
{
|
|
}
|
|
|
|
/**************************************************************
|
|
* These are some optionally selectable routines that add
|
|
* some base functionality over the safe_* versions above.
|
|
* The safe_* versions are primarily designed to ensure that
|
|
* there are no null function pointers remaining at early
|
|
* game startup/initialization time.
|
|
*
|
|
* The slightly more functional versions in here should be kept
|
|
* free of platform-specific code or OS-specific code. If you
|
|
* want to use versions that involve platform-specific or
|
|
* OS-specific code, go right ahead but use your own replacement
|
|
* version of the functions in a platform-specific or
|
|
* OS-specific source file, not in here.
|
|
***************************************************************/
|
|
|
|
/* Add to your code: windowprocs.win_raw_print = stdio_wait_synch; */
|
|
void
|
|
stdio_wait_synch()
|
|
{
|
|
char valid[] = {' ', '\n', '\r', '\033', '\0'};
|
|
|
|
fprintf(stdout, "--More--");
|
|
(void) fflush(stdout);
|
|
while (!index(valid, nhgetch()))
|
|
;
|
|
}
|
|
|
|
/* Add to your code: windowprocs.win_raw_print = stdio_raw_print; */
|
|
void
|
|
stdio_raw_print(str)
|
|
const char *str;
|
|
{
|
|
if (str)
|
|
fprintf(stdout, "%s\n", str);
|
|
return;
|
|
}
|
|
|
|
/* no newline variation, add to your code:
|
|
windowprocs.win_raw_print = stdio_nonl_raw_print; */
|
|
void
|
|
stdio_nonl_raw_print(str)
|
|
const char *str;
|
|
{
|
|
if (str)
|
|
fprintf(stdout, "%s", str);
|
|
return;
|
|
}
|
|
|
|
/* Add to your code: windowprocs.win_raw_print_bold = stdio_raw_print_bold; */
|
|
void
|
|
stdio_raw_print_bold(str)
|
|
const char *str;
|
|
{
|
|
stdio_raw_print(str);
|
|
return;
|
|
}
|
|
|
|
/* Add to your code: windowprocs.win_nhgetch = stdio_nhgetch; */
|
|
int
|
|
stdio_nhgetch()
|
|
{
|
|
return getchar();
|
|
}
|
|
|
|
|
|
/* safeprocs.c */
|