Files
nethack/win/share/tiletext.c
nhmall 0c3b9642e4 pmnames mons gender naming plus a window port interface change
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.
2020-12-26 11:23:23 -05:00

374 lines
10 KiB
C

/* NetHack 3.7 tiletext.c $NHDT-Date: 1596498342 2020/08/03 23:45:42 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.17 $ */
/* Copyright (c) 2016 by Pasi Kallinen */
/* NetHack may be freely redistributed. See license for details. */
#include "config.h"
#include "tile.h"
pixval ColorMap[3][MAXCOLORMAPSIZE];
int colorsinmap;
pixval MainColorMap[3][MAXCOLORMAPSIZE];
int colorsinmainmap;
static short color_index[MAXCOLORMAPSIZE];
static int num_colors;
static char charcolors[MAXCOLORMAPSIZE];
static int placeholder_init = 0;
static pixel placeholder[TILE_Y][TILE_X];
static FILE *tile_file;
static int tile_set, tile_set_indx;
#if (TILE_X == 8)
static const char *text_sets[] = { "monthin.txt", "objthin.txt",
"oththin.txt" };
#else
static const char *text_sets[] = { "monsters.txt", "objects.txt",
"other.txt" };
#endif
extern const char *FDECL(tilename, (int, int, int));
extern boolean FDECL(acceptable_tilename, (int, int, const char *, const char *));
static void FDECL(read_text_colormap, (FILE *));
static boolean FDECL(write_text_colormap, (FILE *));
static boolean FDECL(read_txttile, (FILE *, pixel (*)[TILE_X]));
static void FDECL(write_txttile, (FILE *, pixel (*)[TILE_X]));
enum { MONSTER_SET, OBJECT_SET, OTHER_SET};
/* Ugh. DICE doesn't like %[A-Z], so we have to spell it out... */
#define FORMAT_STRING \
"%[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.] = " \
"(%d, %d, %d) "
static int grayscale = 0;
/* grayscale color mapping */
static const int graymappings[] = {
/* . A B C D E F G H I J K L M N O P */
0, 1, 17, 18, 19, 20, 27, 22, 23, 24, 25, 26, 21, 15, 13, 14, 14
};
void
set_grayscale(g)
int g;
{
grayscale = g;
}
static void
read_text_colormap(txtfile)
FILE *txtfile;
{
int i, r, g, b;
char c[2];
for (i = 0; i < MAXCOLORMAPSIZE; i++)
color_index[i] = -1;
num_colors = 0;
while (fscanf(txtfile, FORMAT_STRING, c, &r, &g, &b) == 4) {
color_index[(int) c[0]] = num_colors;
ColorMap[CM_RED][num_colors] = r;
ColorMap[CM_GREEN][num_colors] = g;
ColorMap[CM_BLUE][num_colors] = b;
num_colors++;
}
colorsinmap = num_colors;
}
#undef FORMAT_STRING
static boolean
write_text_colormap(txtfile)
FILE *txtfile;
{
int i;
char c;
num_colors = colorsinmainmap;
if (num_colors > 62) {
Fprintf(stderr, "too many colors (%d)\n", num_colors);
return FALSE;
}
for (i = 0; i < num_colors; i++) {
if (i < 26)
c = 'A' + i;
else if (i < 52)
c = 'a' + i - 26;
else
c = '0' + i - 52;
charcolors[i] = c;
Fprintf(
txtfile, "%c = (%d, %d, %d)\n", c, (int) MainColorMap[CM_RED][i],
(int) MainColorMap[CM_GREEN][i], (int) MainColorMap[CM_BLUE][i]);
}
return TRUE;
}
static boolean
read_txttile(txtfile, pixels)
FILE *txtfile;
pixel (*pixels)[TILE_X];
{
int ph, i, j, k, reslt;
char buf[BUFSZ], ttype[BUFSZ], gend[BUFSZ];
const char *p;
char c[2];
static int gidx = 0;
gend[0] = '\0';
if (tile_set == MONSTER_SET)
reslt = fscanf(txtfile, "# %s %d (%[^,],%[^)])", ttype, &i, buf, gend);
else
reslt = fscanf(txtfile, "# %s %d (%[^)])", ttype, &i, buf);
if (reslt <= 0)
return FALSE;
if (tile_set == MONSTER_SET && gend[0] == 'f')
gidx = 1;
ph = strcmp(ttype, "placeholder") == 0;
if (!ph && strcmp(ttype, "tile") != 0)
Fprintf(stderr, "Keyword \"%s\" unexpected for entry %d\n", ttype, i);
/* check tile name, but not relative number, which will
* change when tiles are added
*/
p = tilename(tile_set, tile_set_indx, gidx);
if (p && strcmp(p, buf)
&& !acceptable_tilename(tile_set, tile_set_indx, buf, p)) {
Fprintf(stderr, "warning: for tile %d (numbered %d) of %s,\n",
tile_set_indx, i, text_sets[tile_set]);
Fprintf(stderr, "\tfound '%s' while expecting '%s'\n", buf, p);
}
tile_set_indx++;
/* look for non-whitespace at each stage */
if (fscanf(txtfile, "%1s", c) < 0) {
Fprintf(stderr, "unexpected EOF\n");
return FALSE;
}
if (c[0] != '{') {
Fprintf(stderr, "didn't find expected '{'\n");
return FALSE;
}
for (j = 0; j < TILE_Y; j++) {
for (i = 0; i < TILE_X; i++) {
if (fscanf(txtfile, "%1s", c) < 0) {
Fprintf(stderr, "unexpected EOF\n");
return FALSE;
}
k = color_index[(int) c[0]];
if (grayscale) {
if (k > (SIZE(graymappings) - 1))
Fprintf(stderr, "Gray mapping issue %d > %d.\n", k,
SIZE(graymappings) - 1);
else
k = graymappings[k];
}
if (k == -1)
Fprintf(stderr, "color %c not in colormap!\n", c[0]);
else {
pixels[j][i].r = ColorMap[CM_RED][k];
pixels[j][i].g = ColorMap[CM_GREEN][k];
pixels[j][i].b = ColorMap[CM_BLUE][k];
}
}
}
if (ph) {
/* remember it for later */
memcpy(placeholder, pixels, sizeof(placeholder));
}
if (fscanf(txtfile, "%1s ", c) < 0) {
Fprintf(stderr, "unexpected EOF\n");
return FALSE;
}
if (c[0] != '}') {
Fprintf(stderr, "didn't find expected '}'\n");
return FALSE;
}
#ifdef _DCC
/* DICE again... it doesn't seem to eat whitespace after the } like
* it should, so we have to do so manually.
*/
while ((*c = fgetc(txtfile)) != EOF && isspace((uchar) *c))
;
ungetc(*c, txtfile);
#endif
return TRUE;
}
static void
write_txttile(txtfile, pixels)
FILE *txtfile;
pixel (*pixels)[TILE_X];
{
const char *p;
const char *type;
int i = 0, j, k;
if (memcmp(placeholder, pixels, sizeof(placeholder)) == 0)
type = "placeholder";
else
type = "tile";
if (tile_set == MONSTER_SET) {
for (i = 0; i < 2; ++i) {
Fprintf(txtfile, "# %s %d (unknown,%s)\n", type, tile_set_indx,
i ? "female" : "male");
if (i == 0)
tile_set_indx++;
}
} else {
p = tilename(tile_set, tile_set_indx, i);
if (p)
Fprintf(txtfile, "# %s %d (%s)\n", type, tile_set_indx, p);
else
Fprintf(txtfile, "# %s %d (null)\n", type, tile_set_indx);
}
tile_set_indx++;
Fprintf(txtfile, "{\n");
for (j = 0; j < TILE_Y; j++) {
Fprintf(txtfile, " ");
for (i = 0; i < TILE_X; i++) {
for (k = 0; k < num_colors; k++) {
if (ColorMap[CM_RED][k] == pixels[j][i].r
&& ColorMap[CM_GREEN][k] == pixels[j][i].g
&& ColorMap[CM_BLUE][k] == pixels[j][i].b)
break;
}
if (k >= num_colors)
Fprintf(stderr, "color not in colormap!\n");
(void) fputc(charcolors[k], txtfile);
}
Fprintf(txtfile, "\n");
}
Fprintf(txtfile, "}\n");
}
/* initialize main colormap from globally accessed ColorMap */
void
init_colormap()
{
int i;
colorsinmainmap = colorsinmap;
for (i = 0; i < colorsinmap; i++) {
MainColorMap[CM_RED][i] = ColorMap[CM_RED][i];
MainColorMap[CM_GREEN][i] = ColorMap[CM_GREEN][i];
MainColorMap[CM_BLUE][i] = ColorMap[CM_BLUE][i];
}
}
/* merge new colors from ColorMap into MainColorMap */
void
merge_colormap()
{
int i, j;
for (i = 0; i < colorsinmap; i++) {
for (j = 0; j < colorsinmainmap; j++) {
if (MainColorMap[CM_RED][j] == ColorMap[CM_RED][i]
&& MainColorMap[CM_GREEN][j] == ColorMap[CM_GREEN][i]
&& MainColorMap[CM_BLUE][j] == ColorMap[CM_BLUE][i])
break;
}
if (j >= colorsinmainmap) { /* new color */
if (colorsinmainmap >= MAXCOLORMAPSIZE) {
Fprintf(stderr,
"Too many colors to merge -- excess ignored.\n");
}
j = colorsinmainmap;
MainColorMap[CM_RED][j] = ColorMap[CM_RED][i];
MainColorMap[CM_GREEN][j] = ColorMap[CM_GREEN][i];
MainColorMap[CM_BLUE][j] = ColorMap[CM_BLUE][i];
colorsinmainmap++;
}
}
}
boolean
fopen_text_file(filename, type)
const char *filename;
const char *type;
{
const char *p;
int i;
if (tile_file != (FILE *) 0) {
Fprintf(stderr, "can only open one text file at at time\n");
return FALSE;
}
tile_file = fopen(filename, type);
if (tile_file == (FILE *) 0) {
Fprintf(stderr, "cannot open text file %s\n", filename);
return FALSE;
}
p = rindex(filename, '/');
if (p)
p++;
else
p = filename;
tile_set = 0;
for (i = 0; i < SIZE(text_sets); i++) {
if (!strcmp(p, text_sets[i]))
tile_set = i;
}
tile_set_indx = 0;
if (!strcmp(type, RDTMODE)) {
/* Fill placeholder with noise */
if (!placeholder_init) {
placeholder_init++;
for (i = 0; i < (int) sizeof placeholder; i++)
((char *) placeholder)[i] = i % 256;
}
read_text_colormap(tile_file);
if (!colorsinmainmap)
init_colormap();
else
merge_colormap();
return TRUE;
} else if (!strcmp(type, WRTMODE)) {
if (!colorsinmainmap) {
Fprintf(stderr, "no colormap set yet\n");
return FALSE;
}
return (write_text_colormap(tile_file));
} else {
Fprintf(stderr, "bad mode (%s) for fopen_text_file\n", type);
return FALSE;
}
}
boolean
read_text_tile(pixels)
pixel (*pixels)[TILE_X];
{
return (read_txttile(tile_file, pixels));
}
boolean
write_text_tile(pixels)
pixel (*pixels)[TILE_X];
{
write_txttile(tile_file, pixels);
return TRUE;
}
int
fclose_text_file()
{
int ret;
ret = fclose(tile_file);
tile_file = (FILE *) 0;
return ret;
}