Files
nethack/win/share/tiletext.c
nhmall 1f6c1d0f42 expand the glyphs
The walls for the mines, gehennom, knox, and sokoban had been
changed at the "tile"-level, with no awareness of the core game,
or non-tile interfaces.
- Expand the glyphs to include a set of walls for the main level
as well as each of those mentioned above.

Altars had been adjusted at the map_glyphinfo() level to substitute
some color variations on-the-fly for unaligned, chaotic, neutral,
lawful altars, and shrines. The tile interface had no awareness of
the feature.
- Expand the glyphs to include each of the altar variations that
had been implemented in the display code for tty-only. This required
the addition of four placeholder tiles in other.txt. Someone with
artistic skill will hopefully alter the additional tiles to better
reflect their intended purpose.

Explosions had unique tiles in the tile window port, and the display
code for tty tinkered with the colors, but the game had very little
awareness of the different types of explosions.
- Expand the glyphs to include each of the explosion types: dark,
noxious, muddy, wet, magical, fiery and frosty.

Pile-markers to represent a pile had been introduced at the
display-level, without little to no awareness by the core game.
- Expand the glyphs to include piletops, including objects,
bodys, and statues.

Recently male and female variations of tiles and monsters had been
had been introduced, but the mechanics had been mostly done at the
display-level through a marker flag. The window port interface then
had to increment the tile mapped to the glyph to get the female version
of the tile.
- Expand the glyphs to include the male and female versions of the
monsters, and their corresponding pet versions, ridden, detected
versions and statues of them.

Direct references to GLYPH_BODY_OFF and GLYPH_STATUE_OFF
in object_from_map() in pager.c were getting incomplete results.
- Add macros glyph_to_body_corpsenm(glyph) and
glyph_to_statue_corpsenm(glyph) macros for obtaining the corpsenm
value after passing the glyph_is_body() or glyph_is_statue() test.

Other relevant notes:

- The tile ordering in the win/share/*.txt tile files has been altered,
other.txt in particular.

- tilemap.c has had a lot of alterations to accommodate the expanded
glyphs. Output that is useful for troubleshooting will end up in
tilemappings.lst if OBTAIN_TILEMAP is defined during build.
It lists all of the glyphs and which tile it gets mapped to, and also
lists each tile and some of the references to it by various glyphs.

- An array glyphmap[MAXGLYPH] is now used. It has an entry for each
glyph, ordered by glyph, and once reset_glyphs(glyph) has been run, it
contains the mapped symindex, default color, glyphflags, and tile
index.
If USE_TILES is defined during build, the tile.c produced from the
tilemap utility populates the tileidx field of each array element with
a glyph-to-tile mapping for the glyph. Later on, when reset_glyphmap()
is run, the other fields of each element will get populated.

- The glyph-to-tile mapping is an added field available to a window
port via the glyphinfo struct passed in the documented interface. The
old glyph2tile[] array is gone. The various active window ports that
had been using glyph2tile[] have been updated to use the new interface
mechanism. Disclaimer: There may be some bug fixing or tidying
required in the window port code.

- reset_glyphmap() is called after config file options parsing
has finished, because some config file settings can impact the results
produced by reset_glyphmap().

- Everything that passes the glyph_is_cmap(glyph) test must
return a valid cmap value from glyph_to_cmap(glyph).

- An 'extern glyph_info glyphmap[MAX_GLYPH];' is inserted into the
top of only the files which need awareness of it, not inserted into
display.h. Presently, the only files that actually need to directly
reference the glyphmap[] array are display.c, o_init.c (for shuffling
the tiles), and the generated tile.c (if USE_TILES is defined).

- Added an MG_MALE glyphflag to complement the MG_FEMALE glyphflag.

- Provide an array for wall colorizations. reset_glyphmap() will draw
the colors from this array: int array wallcolors[sokoban_walls + 1];
The indices of the wallcolors array are main_walls (0), mines_walls
(1), gehennom_walls (2), knox_walls (3), and sokoban_walls (4).
In future, a config file option for adjusting the wall colors and/or
an 'O' option menu to do the same could be added. Right now, the
initializaton of the wallcolors[] array entries in display.c leaves the
walls at CLR_GRAY, matching the defsym color.

- Most of the display-level kludges for some of the on-the-fly
interface features have been removed from map_glyphinfo() as they
aren't needed any longer. These glyph expansions adhere more closely to
the original glyph mechanics of the game.

- Because the glyphs are re-ordered and expanded, an update to
editlevel will be required upon merge of these changes.
2021-09-18 19:51:04 -04:00

365 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 *tilename(int, int, int);
extern boolean acceptable_tilename(int, int, const char *, const char *);
static void read_text_colormap(FILE *);
static boolean write_text_colormap(FILE *);
static boolean read_txttile(FILE *, pixel (*)[TILE_X]);
static void 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,
/* Q R S T U V W */
1, 17, 18, 19, 20, 27, 22
};
void
set_grayscale(int gs)
{
grayscale = gs;
}
static void
read_text_colormap(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(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(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(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(void)
{
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(void)
{
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(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(pixel (*pixels)[TILE_X])
{
return (read_txttile(tile_file, pixels));
}
boolean
write_text_tile(pixel (*pixels)[TILE_X])
{
write_txttile(tile_file, pixels);
return TRUE;
}
int
fclose_text_file(void)
{
int ret;
ret = fclose(tile_file);
tile_file = (FILE *) 0;
return ret;
}