Reformat all C files.

I'll push a formatting guide at some point. There may still be
outstanding changes, but please feel free to resolve those as you arrive
a them.

To the best of my knowledge, there is no changes to the actual code
content, but the formatter does have the occasional bug. If you run into
an issue, please fix it!
This commit is contained in:
Sean Hunt
2015-05-09 13:43:16 -04:00
parent 167800afdf
commit 97d6fade74
270 changed files with 182649 additions and 173878 deletions
+517 -515
View File
File diff suppressed because it is too large Load Diff
+96 -97
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 ppmwrite.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 ppmwrite.c $NHDT-Date: 1431192770 2015/05/09 17:32:50 $ $NHDT-Branch: master $:$NHDT-Revision: 1.5 $ */
/* NetHack 3.6 ppmwrite.c $Date: 2009/05/06 10:59:00 $ $Revision: 1.2 $ */
/* this produces a raw ppm file, with a 15-character header of
* "P6 3-digit-width 3-digit-height 255\n"
@@ -14,8 +14,8 @@ extern long *FDECL(alloc, (unsigned int));
FILE *ppm_file;
struct ppmscreen {
int Width;
int Height;
int Width;
int Height;
} PpmScreen;
static int tiles_across, tiles_down, curr_tiles_across;
@@ -27,22 +27,22 @@ static void NDECL(WriteTileStrip);
static void
write_header()
{
(void) fprintf(ppm_file, "P6 %03d %03d 255\n",
PpmScreen.Width, PpmScreen.Height);
(void) fprintf(ppm_file, "P6 %03d %03d 255\n", PpmScreen.Width,
PpmScreen.Height);
}
static void
WriteTileStrip()
{
int i, j;
int i, j;
for (j = 0; j < TILE_Y; j++) {
for (i = 0; i < PpmScreen.Width; i++) {
(void) fputc((char)image[j][i].r, ppm_file);
(void) fputc((char)image[j][i].g, ppm_file);
(void) fputc((char)image[j][i].b, ppm_file);
}
}
for (j = 0; j < TILE_Y; j++) {
for (i = 0; i < PpmScreen.Width; i++) {
(void) fputc((char) image[j][i].r, ppm_file);
(void) fputc((char) image[j][i].g, ppm_file);
(void) fputc((char) image[j][i].b, ppm_file);
}
}
}
boolean
@@ -50,124 +50,123 @@ fopen_ppm_file(filename, type)
const char *filename;
const char *type;
{
int i;
int i;
if (strcmp(type, WRBMODE)) {
Fprintf(stderr, "using writing routine for non-writing?\n");
return FALSE;
}
ppm_file = fopen(filename, type);
if (ppm_file == (FILE *)0) {
Fprintf(stderr, "cannot open ppm file %s\n", filename);
return FALSE;
}
if (strcmp(type, WRBMODE)) {
Fprintf(stderr, "using writing routine for non-writing?\n");
return FALSE;
}
ppm_file = fopen(filename, type);
if (ppm_file == (FILE *) 0) {
Fprintf(stderr, "cannot open ppm file %s\n", filename);
return FALSE;
}
if (!colorsinmainmap) {
Fprintf(stderr, "no colormap set yet\n");
return FALSE;
}
if (!colorsinmainmap) {
Fprintf(stderr, "no colormap set yet\n");
return FALSE;
}
tiles_across = 20;
curr_tiles_across = 0;
PpmScreen.Width = 20 * TILE_X;
tiles_across = 20;
curr_tiles_across = 0;
PpmScreen.Width = 20 * TILE_X;
tiles_down = 0;
PpmScreen.Height = 0; /* will be rewritten later */
tiles_down = 0;
PpmScreen.Height = 0; /* will be rewritten later */
write_header();
write_header();
image = (pixel **)alloc(TILE_Y * sizeof(pixel *));
for (i = 0; i < TILE_Y; i++) {
image[i] = (pixel *) alloc(PpmScreen.Width * sizeof(pixel));
}
image = (pixel **) alloc(TILE_Y * sizeof(pixel *));
for (i = 0; i < TILE_Y; i++) {
image[i] = (pixel *) alloc(PpmScreen.Width * sizeof(pixel));
}
return TRUE;
return TRUE;
}
boolean
write_ppm_tile(pixels)
pixel (*pixels)[TILE_X];
{
int i, j;
int i, j;
for (j = 0; j < TILE_Y; j++) {
for (i = 0; i < TILE_X; i++) {
image[j][curr_tiles_across*TILE_X + i] = pixels[j][i];
}
}
curr_tiles_across++;
if (curr_tiles_across == tiles_across) {
WriteTileStrip();
curr_tiles_across = 0;
tiles_down++;
}
return TRUE;
for (j = 0; j < TILE_Y; j++) {
for (i = 0; i < TILE_X; i++) {
image[j][curr_tiles_across * TILE_X + i] = pixels[j][i];
}
}
curr_tiles_across++;
if (curr_tiles_across == tiles_across) {
WriteTileStrip();
curr_tiles_across = 0;
tiles_down++;
}
return TRUE;
}
int
fclose_ppm_file()
{
int i, j;
int i, j;
if (curr_tiles_across) { /* partial row */
/* fill with checkerboard, for lack of a better idea */
for (j = 0; j < TILE_Y; j++) {
for (i = curr_tiles_across * TILE_X;
i < PpmScreen.Width; i += 2 ) {
image[j][i].r = MainColorMap[CM_RED][0];
image[j][i].g = MainColorMap[CM_GREEN][0];
image[j][i].b = MainColorMap[CM_BLUE][0];
image[j][i+1].r = MainColorMap[CM_RED][1];
image[j][i+1].g = MainColorMap[CM_GREEN][1];
image[j][i+1].b = MainColorMap[CM_BLUE][1];
}
}
WriteTileStrip();
curr_tiles_across = 0;
tiles_down++;
}
if (curr_tiles_across) { /* partial row */
/* fill with checkerboard, for lack of a better idea */
for (j = 0; j < TILE_Y; j++) {
for (i = curr_tiles_across * TILE_X; i < PpmScreen.Width;
i += 2) {
image[j][i].r = MainColorMap[CM_RED][0];
image[j][i].g = MainColorMap[CM_GREEN][0];
image[j][i].b = MainColorMap[CM_BLUE][0];
image[j][i + 1].r = MainColorMap[CM_RED][1];
image[j][i + 1].g = MainColorMap[CM_GREEN][1];
image[j][i + 1].b = MainColorMap[CM_BLUE][1];
}
}
WriteTileStrip();
curr_tiles_across = 0;
tiles_down++;
}
for (i = 0; i < TILE_Y; i++) {
free((genericptr_t)image[i]);
}
free((genericptr_t)image);
for (i = 0; i < TILE_Y; i++) {
free((genericptr_t) image[i]);
}
free((genericptr_t) image);
PpmScreen.Height = tiles_down * TILE_Y;
rewind(ppm_file);
write_header(); /* update size */
PpmScreen.Height = tiles_down * TILE_Y;
rewind(ppm_file);
write_header(); /* update size */
return(fclose(ppm_file));
return (fclose(ppm_file));
}
int
main(argc, argv)
int argc;
char *argv[];
{
pixel pixels[TILE_Y][TILE_X];
pixel pixels[TILE_Y][TILE_X];
if (argc != 3) {
Fprintf(stderr, "usage: txt2ppm txtfile ppmfile\n");
exit(EXIT_FAILURE);
}
if (argc != 3) {
Fprintf(stderr, "usage: txt2ppm txtfile ppmfile\n");
exit(EXIT_FAILURE);
}
if (!fopen_text_file(argv[1], RDTMODE))
exit(EXIT_FAILURE);
if (!fopen_text_file(argv[1], RDTMODE))
exit(EXIT_FAILURE);
init_colormap();
init_colormap();
if (!fopen_ppm_file(argv[2], WRBMODE)) {
(void) fclose_text_file();
exit(EXIT_FAILURE);
}
if (!fopen_ppm_file(argv[2], WRBMODE)) {
(void) fclose_text_file();
exit(EXIT_FAILURE);
}
while (read_text_tile(pixels))
(void) write_ppm_tile(pixels);
while (read_text_tile(pixels))
(void) write_ppm_tile(pixels);
(void) fclose_text_file();
(void) fclose_ppm_file();
exit(EXIT_SUCCESS);
/*NOTREACHED*/
return 0;
(void) fclose_text_file();
(void) fclose_ppm_file();
exit(EXIT_SUCCESS);
/*NOTREACHED*/
return 0;
}
+79 -81
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 thintile.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 thintile.c $NHDT-Date: 1431192771 2015/05/09 17:32:51 $ $NHDT-Branch: master $:$NHDT-Revision: 1.8 $ */
/* NetHack 3.6 thintile.c $Date: 2012/01/10 17:47:40 $ $Revision: 1.5 $ */
/* Copyright (c) NetHack Development Team 1995 */
/* NetHack may be freely redistributed. See license for details. */
@@ -14,13 +14,13 @@
static char pixels[TILE_Y][TILE_X];
static char *tilefiles[] = { "../win/share/monsters.txt",
"../win/share/objects.txt",
"../win/share/other.txt"};
static char *tilefiles[] = { "../win/share/monsters.txt",
"../win/share/objects.txt",
"../win/share/other.txt" };
static char *thinfiles[] = { "../win/share/monthin.txt",
"../win/share/objthin.txt",
"../win/share/oththin.txt"};
static char *thinfiles[] = { "../win/share/monthin.txt",
"../win/share/objthin.txt",
"../win/share/oththin.txt" };
static FILE *infile, *outfile;
static int tilecount;
static int tilecount_per_file;
@@ -30,101 +30,99 @@ static char comment[BUFSZ];
static void
copy_colormap()
{
int r, g, b;
char c[2];
int r, g, b;
char c[2];
while (fscanf(infile, "%[A-Za-z0-9] = (%d, %d, %d) ", c, &r, &g, &b)
== 4) {
Fprintf(outfile, "%c = (%d, %d, %d)\n", c[0], r, g, b);
}
while (fscanf(infile, "%[A-Za-z0-9] = (%d, %d, %d) ", c, &r, &g, &b)
== 4) {
Fprintf(outfile, "%c = (%d, %d, %d)\n", c[0], r, g, b);
}
}
static boolean
read_txttile()
{
int i, j;
char buf[BUFSZ];
char buf2[BUFSZ];
int i, j;
char buf[BUFSZ];
char buf2[BUFSZ];
char c[2];
char c[2];
if (fscanf(infile, "# %s %d (%[^)])", buf2, &i, buf) <= 0)
return FALSE;
if (fscanf(infile, "# %s %d (%[^)])", buf2, &i, buf) <= 0)
return FALSE;
Sprintf(comment,"# tile %d (%s)", i, buf);
/* look for non-whitespace at each stage */
if (fscanf(infile, "%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(infile, "%1s", c) < 0) {
Fprintf(stderr, "unexpected EOF\n");
return FALSE;
}
pixels[j][i] = c[0];
}
}
if (fscanf(infile, "%1s ", c) < 0) {
Fprintf(stderr, "unexpected EOF\n");
return FALSE;
}
if (c[0] != '}') {
Fprintf(stderr, "didn't find expected '}'\n");
return FALSE;
}
return TRUE;
Sprintf(comment, "# tile %d (%s)", i, buf);
/* look for non-whitespace at each stage */
if (fscanf(infile, "%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(infile, "%1s", c) < 0) {
Fprintf(stderr, "unexpected EOF\n");
return FALSE;
}
pixels[j][i] = c[0];
}
}
if (fscanf(infile, "%1s ", c) < 0) {
Fprintf(stderr, "unexpected EOF\n");
return FALSE;
}
if (c[0] != '}') {
Fprintf(stderr, "didn't find expected '}'\n");
return FALSE;
}
return TRUE;
}
static void
write_thintile()
{
int i, j;
int i, j;
Fprintf(outfile, "%s\n", comment);
Fprintf(outfile, "{\n");
for (j = 0; j < TILE_Y; j++) {
Fprintf(outfile, " ");
for (i = 0; i < TILE_X; i += 2) {
(void) fputc(pixels[j][i], outfile);
}
Fprintf(outfile, "\n");
}
Fprintf(outfile, "}\n");
Fprintf(outfile, "%s\n", comment);
Fprintf(outfile, "{\n");
for (j = 0; j < TILE_Y; j++) {
Fprintf(outfile, " ");
for (i = 0; i < TILE_X; i += 2) {
(void) fputc(pixels[j][i], outfile);
}
Fprintf(outfile, "\n");
}
Fprintf(outfile, "}\n");
}
int
main(argc, argv)
int argc;
char *argv[];
{
while (filenum < 3) {
tilecount_per_file = 0;
infile = fopen(tilefiles[filenum], RDTMODE);
outfile = fopen(thinfiles[filenum], WRTMODE);
copy_colormap();
while (read_txttile()) {
write_thintile();
tilecount_per_file++;
tilecount++;
}
fclose(outfile);
fclose(infile);
printf("%d tiles processed from %s\n",
tilecount_per_file, tilefiles[filenum]);
++filenum;
}
printf("Grand total of %d tiles processed.\n", tilecount);
exit(EXIT_SUCCESS);
/*NOTREACHED*/
return 0;
while (filenum < 3) {
tilecount_per_file = 0;
infile = fopen(tilefiles[filenum], RDTMODE);
outfile = fopen(thinfiles[filenum], WRTMODE);
copy_colormap();
while (read_txttile()) {
write_thintile();
tilecount_per_file++;
tilecount++;
}
fclose(outfile);
fclose(infile);
printf("%d tiles processed from %s\n", tilecount_per_file,
tilefiles[filenum]);
++filenum;
}
printf("Grand total of %d tiles processed.\n", tilecount);
exit(EXIT_SUCCESS);
/*NOTREACHED*/
return 0;
}
/*thintile.c*/
+205 -206
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 tile2bmp.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
/* NetHack 3.6 tile2bmp.c $NHDT-Date: 1431192770 2015/05/09 17:32:50 $ $NHDT-Branch: master $:$NHDT-Revision: 1.14 $ */
/* Copyright (c) NetHack PC Development Team 1995 */
/* NetHack may be freely redistributed. See license for details. */
@@ -18,53 +18,55 @@
#include "win32api.h"
#endif
#if (TILE_X==32)
#if (TILE_X == 32)
#define COLORS_IN_USE 256
#else
/*#define COLORS_IN_USE 16 */ /* 16 colors */
#define COLORS_IN_USE 256 /* 256 colors */
/*#define COLORS_IN_USE 16 */ /* 16 colors */
#define COLORS_IN_USE 256 /* 256 colors */
#endif
#define BITCOUNT 8
extern char *FDECL(tilename, (int, int));
#define MAGICTILENO (340 + 440 + 231 + 340)
#define MAGICTILENO (340 + 440 + 231 + 340)
#if BITCOUNT==4
#define MAX_X 320 /* 2 per byte, 4 bits per pixel */
#if BITCOUNT == 4
#define MAX_X 320 /* 2 per byte, 4 bits per pixel */
#define MAX_Y 480
#else
# if (TILE_X==32)
#if (TILE_X == 32)
#define MAX_X (32 * 40)
#define MAX_Y ((MAGICTILENO * 32) / 40) * 2
# else
#else
#define MAX_X (16 * 40)
#define MAX_Y ((MAGICTILENO * 16) / 40) * 2
# endif
#endif
#endif
#endif
/* GCC fix by Paolo Bonzini 1999/03/28 */
#ifdef __GNUC__
#define PACK __attribute__((packed))
#define PACK __attribute__((packed))
#else
#define PACK
#endif
#endif
static short leshort(short x)
static short
leshort(short x)
{
#ifdef __BIG_ENDIAN__
return ((x&0xff)<<8)|((x>>8)&0xff);
return ((x & 0xff) << 8) | ((x >> 8) & 0xff);
#else
return x;
#endif
}
static long lelong(long x)
static long
lelong(long x)
{
#ifdef __BIG_ENDIAN__
return ((x&0xff)<<24)|((x&0xff00)<<8)|((x>>8)&0xff00)|((x>>24)&0xff);
return ((x & 0xff) << 24) | ((x & 0xff00) << 8) | ((x >> 8) & 0xff00)
| ((x >> 24) & 0xff);
#else
return x;
#endif
@@ -72,63 +74,63 @@ static long lelong(long x)
#ifdef __GNUC__
typedef struct tagBMIH {
unsigned long biSize;
long biWidth;
long biHeight;
unsigned short biPlanes;
unsigned short biBitCount;
unsigned long biCompression;
unsigned long biSizeImage;
long biXPelsPerMeter;
long biYPelsPerMeter;
unsigned long biClrUsed;
unsigned long biClrImportant;
unsigned long biSize;
long biWidth;
long biHeight;
unsigned short biPlanes;
unsigned short biBitCount;
unsigned long biCompression;
unsigned long biSizeImage;
long biXPelsPerMeter;
long biYPelsPerMeter;
unsigned long biClrUsed;
unsigned long biClrImportant;
} PACK BITMAPINFOHEADER;
typedef struct tagBMFH {
unsigned short bfType;
unsigned long bfSize;
unsigned short bfReserved1;
unsigned short bfReserved2;
unsigned long bfOffBits;
unsigned short bfType;
unsigned long bfSize;
unsigned short bfReserved1;
unsigned short bfReserved2;
unsigned long bfOffBits;
} PACK BITMAPFILEHEADER;
typedef struct tagRGBQ {
unsigned char rgbBlue;
unsigned char rgbGreen;
unsigned char rgbRed;
unsigned char rgbReserved;
unsigned char rgbBlue;
unsigned char rgbGreen;
unsigned char rgbRed;
unsigned char rgbReserved;
} PACK RGBQUAD;
#define UINT unsigned int
#define DWORD unsigned long
#define LONG long
#define WORD unsigned short
#define BI_RGB 0L
#define BI_RLE8 1L
#define BI_RLE4 2L
#define BI_BITFIELDS 3L
#define BI_RGB 0L
#define BI_RLE8 1L
#define BI_RLE4 2L
#define BI_BITFIELDS 3L
#endif /* __GNUC__ */
#pragma pack(1)
struct tagBMP{
struct tagBMP {
BITMAPFILEHEADER bmfh;
BITMAPINFOHEADER bmih;
#if BITCOUNT==4
#if BITCOUNT == 4
#define RGBQUAD_COUNT 16
RGBQUAD bmaColors[RGBQUAD_COUNT];
RGBQUAD bmaColors[RGBQUAD_COUNT];
#else
#if (TILE_X==32)
#if (TILE_X == 32)
#define RGBQUAD_COUNT 256
#else
/*#define RGBQUAD_COUNT 16 */
#define RGBQUAD_COUNT 256
#endif
RGBQUAD bmaColors[RGBQUAD_COUNT];
RGBQUAD bmaColors[RGBQUAD_COUNT];
#endif
#if (COLORS_IN_USE==16)
uchar packtile[MAX_Y][MAX_X];
#if (COLORS_IN_USE == 16)
uchar packtile[MAX_Y][MAX_X];
#else
uchar packtile[MAX_Y][MAX_X];
uchar packtile[MAX_Y][MAX_X];
/* uchar packtile[TILE_Y][TILE_X]; */
#endif
} PACK bmp;
@@ -140,19 +142,17 @@ FILE *tibfile2;
pixel tilepixels[TILE_Y][TILE_X];
static void FDECL(build_bmfh,(BITMAPFILEHEADER *));
static void FDECL(build_bmih,(BITMAPINFOHEADER *));
static void FDECL(build_bmptile,(pixel (*)[TILE_X]));
static void FDECL(build_bmfh, (BITMAPFILEHEADER *));
static void FDECL(build_bmih, (BITMAPINFOHEADER *));
static void FDECL(build_bmptile, (pixel(*) [TILE_X]));
char *tilefiles[] = {
#if (TILE_X == 32)
"../win/share/mon32.txt",
"../win/share/obj32.txt",
"../win/share/oth32.txt",
"../win/share/mon32.txt", "../win/share/obj32.txt",
"../win/share/oth32.txt",
#else
"../win/share/monsters.txt",
"../win/share/objects.txt",
"../win/share/other.txt",
"../win/share/monsters.txt", "../win/share/objects.txt",
"../win/share/other.txt",
#endif
};
@@ -163,7 +163,7 @@ int tiles_in_row;
int filenum;
int initflag;
int pass;
int yoffset,xoffset;
int yoffset, xoffset;
char bmpname[128];
FILE *fp;
@@ -172,190 +172,189 @@ main(argc, argv)
int argc;
char *argv[];
{
int i, j;
int i, j;
if (argc != 2) {
Fprintf(stderr, "usage: %s outfile.bmp\n", argv[0]);
exit(EXIT_FAILURE);
} else
strcpy(bmpname, argv[1]);
if (argc != 2) {
Fprintf(stderr, "usage: %s outfile.bmp\n", argv[0]);
exit(EXIT_FAILURE);
} else
strcpy(bmpname, argv[1]);
#ifdef OBSOLETE
bmpfile2 = fopen(NETHACK_PACKED_TILEFILE, WRBMODE);
if (bmpfile2 == (FILE *)0) {
Fprintf(stderr, "Unable to open output file %s\n",
NETHACK_PACKED_TILEFILE);
exit(EXIT_FAILURE);
}
bmpfile2 = fopen(NETHACK_PACKED_TILEFILE, WRBMODE);
if (bmpfile2 == (FILE *) 0) {
Fprintf(stderr, "Unable to open output file %s\n",
NETHACK_PACKED_TILEFILE);
exit(EXIT_FAILURE);
}
#endif
tilecount = 0;
xoffset = yoffset = 0;
initflag = 0;
filenum = 0;
pass = 0;
fp = fopen(bmpname,"wb");
if (!fp) {
printf("Error creating tile file %s, aborting.\n",bmpname);
exit(1);
}
while (pass < 4) {
filenum =pass % (sizeof(tilefiles) / sizeof(char *));
if (!fopen_text_file(tilefiles[filenum], RDTMODE)) {
Fprintf(stderr,
"usage: tile2bmp (from the util directory)\n");
exit(EXIT_FAILURE);
}
num_colors = colorsinmap;
if (num_colors > 62) {
Fprintf(stderr, "too many colors (%d)\n", num_colors);
exit(EXIT_FAILURE);
}
if (!initflag) {
build_bmfh(&bmp.bmfh);
build_bmih(&bmp.bmih);
for (i = 0; i < MAX_Y; ++i)
for (j = 0; j < MAX_X; ++j)
bmp.packtile[i][j] = (uchar)0;
for (i = 0; i < num_colors; i++) {
bmp.bmaColors[i].rgbRed = ColorMap[CM_RED][i];
bmp.bmaColors[i].rgbGreen = ColorMap[CM_GREEN][i];
bmp.bmaColors[i].rgbBlue = ColorMap[CM_BLUE][i];
bmp.bmaColors[i].rgbReserved = 0;
}
initflag = 1;
}
/* printf("Colormap initialized\n"); */
while (read_text_tile(tilepixels)) {
build_bmptile(tilepixels);
tilecount++;
#if BITCOUNT==4
xoffset += (TILE_X / 2);
tilecount = 0;
xoffset = yoffset = 0;
initflag = 0;
filenum = 0;
pass = 0;
fp = fopen(bmpname, "wb");
if (!fp) {
printf("Error creating tile file %s, aborting.\n", bmpname);
exit(1);
}
while (pass < 4) {
filenum = pass % (sizeof(tilefiles) / sizeof(char *));
if (!fopen_text_file(tilefiles[filenum], RDTMODE)) {
Fprintf(stderr, "usage: tile2bmp (from the util directory)\n");
exit(EXIT_FAILURE);
}
num_colors = colorsinmap;
if (num_colors > 62) {
Fprintf(stderr, "too many colors (%d)\n", num_colors);
exit(EXIT_FAILURE);
}
if (!initflag) {
build_bmfh(&bmp.bmfh);
build_bmih(&bmp.bmih);
for (i = 0; i < MAX_Y; ++i)
for (j = 0; j < MAX_X; ++j)
bmp.packtile[i][j] = (uchar) 0;
for (i = 0; i < num_colors; i++) {
bmp.bmaColors[i].rgbRed = ColorMap[CM_RED][i];
bmp.bmaColors[i].rgbGreen = ColorMap[CM_GREEN][i];
bmp.bmaColors[i].rgbBlue = ColorMap[CM_BLUE][i];
bmp.bmaColors[i].rgbReserved = 0;
}
initflag = 1;
}
/* printf("Colormap initialized\n"); */
while (read_text_tile(tilepixels)) {
build_bmptile(tilepixels);
tilecount++;
#if BITCOUNT == 4
xoffset += (TILE_X / 2);
#else
xoffset += TILE_X;
xoffset += TILE_X;
#endif
if (xoffset >= MAX_X) {
yoffset += TILE_Y;
xoffset = 0;
}
}
(void) fclose_text_file();
++pass;
}
fwrite(&bmp, sizeof(bmp), 1, fp);
fclose(fp);
Fprintf(stderr, "Total of %d tiles written to %s.\n",
tilecount, bmpname);
if (xoffset >= MAX_X) {
yoffset += TILE_Y;
xoffset = 0;
}
}
(void) fclose_text_file();
++pass;
}
fwrite(&bmp, sizeof(bmp), 1, fp);
fclose(fp);
Fprintf(stderr, "Total of %d tiles written to %s.\n", tilecount, bmpname);
exit(EXIT_SUCCESS);
/*NOTREACHED*/
return 0;
exit(EXIT_SUCCESS);
/*NOTREACHED*/
return 0;
}
static void
build_bmfh(pbmfh)
BITMAPFILEHEADER *pbmfh;
{
pbmfh->bfType = leshort(0x4D42);
pbmfh->bfSize = lelong(BMPFILESIZE);
pbmfh->bfReserved1 = (UINT)0;
pbmfh->bfReserved2 = (UINT)0;
pbmfh->bfOffBits = lelong(sizeof(bmp.bmfh) + sizeof(bmp.bmih) +
(RGBQUAD_COUNT * sizeof(RGBQUAD)));
pbmfh->bfType = leshort(0x4D42);
pbmfh->bfSize = lelong(BMPFILESIZE);
pbmfh->bfReserved1 = (UINT) 0;
pbmfh->bfReserved2 = (UINT) 0;
pbmfh->bfOffBits = lelong(sizeof(bmp.bmfh) + sizeof(bmp.bmih)
+ (RGBQUAD_COUNT * sizeof(RGBQUAD)));
}
static void
build_bmih(pbmih)
BITMAPINFOHEADER *pbmih;
{
WORD cClrBits;
int w,h;
pbmih->biSize = lelong(sizeof(bmp.bmih));
#if BITCOUNT==4
pbmih->biWidth = lelong(w = MAX_X * 2);
WORD cClrBits;
int w, h;
pbmih->biSize = lelong(sizeof(bmp.bmih));
#if BITCOUNT == 4
pbmih->biWidth = lelong(w = MAX_X * 2);
#else
pbmih->biWidth = lelong(w = MAX_X);
pbmih->biWidth = lelong(w = MAX_X);
#endif
pbmih->biHeight = lelong(h = MAX_Y);
pbmih->biPlanes = leshort(1);
#if BITCOUNT==4
pbmih->biBitCount = leshort(4);
cClrBits = 4;
pbmih->biHeight = lelong(h = MAX_Y);
pbmih->biPlanes = leshort(1);
#if BITCOUNT == 4
pbmih->biBitCount = leshort(4);
cClrBits = 4;
#else
pbmih->biBitCount = leshort(8);
cClrBits = 8;
pbmih->biBitCount = leshort(8);
cClrBits = 8;
#endif
if (cClrBits == 1)
cClrBits = 1;
else if (cClrBits <= 4)
cClrBits = 4;
else if (cClrBits <= 8)
cClrBits = 8;
else if (cClrBits <= 16)
cClrBits = 16;
else if (cClrBits <= 24)
cClrBits = 24;
else cClrBits = 32;
pbmih->biCompression = lelong(BI_RGB);
pbmih->biXPelsPerMeter = lelong(0);
pbmih->biYPelsPerMeter = lelong(0);
#if (TILE_X==32)
if (cClrBits < 24)
pbmih->biClrUsed = lelong(1<<cClrBits);
if (cClrBits == 1)
cClrBits = 1;
else if (cClrBits <= 4)
cClrBits = 4;
else if (cClrBits <= 8)
cClrBits = 8;
else if (cClrBits <= 16)
cClrBits = 16;
else if (cClrBits <= 24)
cClrBits = 24;
else
cClrBits = 32;
pbmih->biCompression = lelong(BI_RGB);
pbmih->biXPelsPerMeter = lelong(0);
pbmih->biYPelsPerMeter = lelong(0);
#if (TILE_X == 32)
if (cClrBits < 24)
pbmih->biClrUsed = lelong(1 << cClrBits);
#else
pbmih->biClrUsed = lelong(RGBQUAD_COUNT);
pbmih->biClrUsed = lelong(RGBQUAD_COUNT);
#endif
#if (TILE_X==16)
/* pbmih->biSizeImage = lelong(0); */
pbmih->biSizeImage = lelong(((w * cClrBits +31) & ~31) /8 * h);
#if (TILE_X == 16)
/* pbmih->biSizeImage = lelong(0); */
pbmih->biSizeImage = lelong(((w * cClrBits + 31) & ~31) / 8 * h);
#else
pbmih->biSizeImage = lelong(((w * cClrBits +31) & ~31) /8 * h);
pbmih->biSizeImage = lelong(((w * cClrBits + 31) & ~31) / 8 * h);
#endif
pbmih->biClrImportant = (DWORD)0;
pbmih->biClrImportant = (DWORD) 0;
}
static 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};
/* . 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
};
static void
build_bmptile(pixels)
pixel (*pixels)[TILE_X];
{
int cur_x, cur_y, cur_color, apply_color;
int x,y;
int cur_x, cur_y, cur_color, apply_color;
int x, y;
for (cur_y = 0; cur_y < TILE_Y; cur_y++) {
for (cur_x = 0; cur_x < TILE_X; cur_x++) {
for (cur_color = 0; cur_color < num_colors; cur_color++) {
if (ColorMap[CM_RED][cur_color] == pixels[cur_y][cur_x].r &&
ColorMap[CM_GREEN][cur_color]== pixels[cur_y][cur_x].g &&
ColorMap[CM_BLUE][cur_color] == pixels[cur_y][cur_x].b)
break;
}
if (cur_color >= num_colors)
Fprintf(stderr, "color not in colormap!\n");
y = (MAX_Y - 1) - (cur_y + yoffset);
apply_color = cur_color;
if (pass == 3) {
/* map to shades of gray */
if (cur_color > (SIZE(graymappings)-1))
Fprintf(stderr, "Gray mapping issue %d %d.\n",
cur_color, SIZE(graymappings)-1);
else
apply_color = graymappings[cur_color];
}
#if BITCOUNT==4
x = (cur_x / 2) + xoffset;
bmp.packtile[y][x] = cur_x%2 ?
(uchar)(bmp.packtile[y][x] | cur_color) :
(uchar)(cur_color<<4);
for (cur_y = 0; cur_y < TILE_Y; cur_y++) {
for (cur_x = 0; cur_x < TILE_X; cur_x++) {
for (cur_color = 0; cur_color < num_colors; cur_color++) {
if (ColorMap[CM_RED][cur_color] == pixels[cur_y][cur_x].r
&& ColorMap[CM_GREEN][cur_color] == pixels[cur_y][cur_x].g
&& ColorMap[CM_BLUE][cur_color] == pixels[cur_y][cur_x].b)
break;
}
if (cur_color >= num_colors)
Fprintf(stderr, "color not in colormap!\n");
y = (MAX_Y - 1) - (cur_y + yoffset);
apply_color = cur_color;
if (pass == 3) {
/* map to shades of gray */
if (cur_color > (SIZE(graymappings) - 1))
Fprintf(stderr, "Gray mapping issue %d %d.\n", cur_color,
SIZE(graymappings) - 1);
else
apply_color = graymappings[cur_color];
}
#if BITCOUNT == 4
x = (cur_x / 2) + xoffset;
bmp.packtile[y][x] = cur_x % 2
? (uchar)(bmp.packtile[y][x] | cur_color)
: (uchar)(cur_color << 4);
#else
x = cur_x + xoffset;
bmp.packtile[y][x] = (uchar)apply_color;
x = cur_x + xoffset;
bmp.packtile[y][x] = (uchar) apply_color;
#endif
}
}
}
}
}
+343 -361
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 tilemap.c $NHDT-Date: 1431183539 2015/05/09 14:58:59 $ $NHDT-Branch: master $:$NHDT-Revision: 1.22 $ */
/* NetHack 3.6 tilemap.c $NHDT-Date: 1431192771 2015/05/09 17:32:51 $ $NHDT-Branch: master $:$NHDT-Revision: 1.23 $ */
/* SCCS Id: @(#)tilemap.c 3.5 2000/06/04 */
/* NetHack may be freely redistributed. See license for details. */
@@ -10,7 +10,7 @@
#include "hack.h"
const char * FDECL(tilename, (int, int));
const char *FDECL(tilename, (int, int));
void NDECL(init_tilemap);
void FDECL(process_substitutions, (FILE *));
@@ -27,50 +27,49 @@ extern void FDECL(exit, (int));
#define MON_GLYPH 1
#define OBJ_GLYPH 2
#define OTH_GLYPH 3 /* fortunately unnecessary */
#define OTH_GLYPH 3 /* fortunately unnecessary */
/* note that the ifdefs here should be the opposite sense from monst.c/
* objects.c/rm.h
*/
struct conditionals {
int sequence, predecessor;
const char *name;
int sequence, predecessor;
const char *name;
} conditionals[] = {
#ifndef CHARON /* not supported yet */
{ MON_GLYPH, PM_HELL_HOUND, "Cerberus" },
{ MON_GLYPH, PM_HELL_HOUND, "Cerberus" },
#endif
/* commented out in monst.c at present */
{ MON_GLYPH, PM_SHOCKING_SPHERE, "beholder" },
{ MON_GLYPH, PM_BABY_SILVER_DRAGON, "baby shimmering dragon" },
{ MON_GLYPH, PM_SILVER_DRAGON, "shimmering dragon" },
{ MON_GLYPH, PM_JABBERWOCK, "vorpal jabberwock" },
{ MON_GLYPH, PM_VAMPIRE_LORD, "vampire mage" },
/* commented out in monst.c at present */
{ MON_GLYPH, PM_SHOCKING_SPHERE, "beholder" },
{ MON_GLYPH, PM_BABY_SILVER_DRAGON, "baby shimmering dragon" },
{ MON_GLYPH, PM_SILVER_DRAGON, "shimmering dragon" },
{ MON_GLYPH, PM_JABBERWOCK, "vorpal jabberwock" },
{ MON_GLYPH, PM_VAMPIRE_LORD, "vampire mage" },
#ifndef CHARON /* not supported yet */
{ MON_GLYPH, PM_CROESUS, "Charon" },
{ MON_GLYPH, PM_CROESUS, "Charon" },
#endif
#ifndef MAIL
{ MON_GLYPH, PM_FAMINE, "mail daemon" },
{ MON_GLYPH, PM_FAMINE, "mail daemon" },
#endif
/* commented out in monst.c at present */
{ MON_GLYPH, PM_SHAMAN_KARNOV, "Earendil" },
{ MON_GLYPH, PM_SHAMAN_KARNOV, "Elwing" },
/* commented out in monst.c at present */
{ MON_GLYPH, PM_CHROMATIC_DRAGON, "Goblin King" },
{ MON_GLYPH, PM_NEANDERTHAL, "High-elf" },
/* objects commented out in objects.c at present */
{ OBJ_GLYPH, SILVER_DRAGON_SCALE_MAIL, "shimmering dragon scale mail" },
{ OBJ_GLYPH, SILVER_DRAGON_SCALES, "shimmering dragon scales" },
/* allow slime mold to look like slice of pizza, since we
* don't know what a slime mold should look like when renamed anyway
*/
/* commented out in monst.c at present */
{ MON_GLYPH, PM_SHAMAN_KARNOV, "Earendil" },
{ MON_GLYPH, PM_SHAMAN_KARNOV, "Elwing" },
/* commented out in monst.c at present */
{ MON_GLYPH, PM_CHROMATIC_DRAGON, "Goblin King" },
{ MON_GLYPH, PM_NEANDERTHAL, "High-elf" },
/* objects commented out in objects.c at present */
{ OBJ_GLYPH, SILVER_DRAGON_SCALE_MAIL, "shimmering dragon scale mail" },
{ OBJ_GLYPH, SILVER_DRAGON_SCALES, "shimmering dragon scales" },
/* allow slime mold to look like slice of pizza, since we
* don't know what a slime mold should look like when renamed anyway
*/
#ifndef MAIL
{ OBJ_GLYPH, SCR_STINKING_CLOUD+4, "stamped / mail" },
{ OBJ_GLYPH, SCR_STINKING_CLOUD + 4, "stamped / mail" },
#endif
{ 0, 0, 0}
{ 0, 0, 0 }
};
/*
* Some entries in glyph2tile[] should be substituted for on various levels.
* The tiles used for the substitute entries will follow the usual ones in
@@ -80,20 +79,17 @@ struct conditionals {
* overlap in the future.
*/
struct substitute {
int first_glyph, last_glyph;
const char *sub_name; /* for explanations */
const char *level_test;
} substitutes[] = {
{ GLYPH_CMAP_OFF + S_vwall, GLYPH_CMAP_OFF + S_trwall,
"mine walls", "In_mines(plev)" },
{ GLYPH_CMAP_OFF + S_vwall, GLYPH_CMAP_OFF + S_trwall,
"gehennom walls", "In_hell(plev)" },
{ GLYPH_CMAP_OFF + S_vwall, GLYPH_CMAP_OFF + S_trwall,
"knox walls", "Is_knox(plev)" },
{ GLYPH_CMAP_OFF + S_vwall, GLYPH_CMAP_OFF + S_trwall,
"sokoban walls", "In_sokoban(plev)" }
};
int first_glyph, last_glyph;
const char *sub_name; /* for explanations */
const char *level_test;
} substitutes[] = { { GLYPH_CMAP_OFF + S_vwall, GLYPH_CMAP_OFF + S_trwall,
"mine walls", "In_mines(plev)" },
{ GLYPH_CMAP_OFF + S_vwall, GLYPH_CMAP_OFF + S_trwall,
"gehennom walls", "In_hell(plev)" },
{ GLYPH_CMAP_OFF + S_vwall, GLYPH_CMAP_OFF + S_trwall,
"knox walls", "Is_knox(plev)" },
{ GLYPH_CMAP_OFF + S_vwall, GLYPH_CMAP_OFF + S_trwall,
"sokoban walls", "In_sokoban(plev)" } };
#ifdef TILETEXT
@@ -104,140 +100,139 @@ const char *
tilename(set, entry)
int set, entry;
{
int i, j, condnum, tilenum;
static char buf[BUFSZ];
int i, j, condnum, tilenum;
static char buf[BUFSZ];
/* Note: these initializers don't do anything except guarantee that
we're linked properly.
*/
monst_init();
objects_init();
(void) def_char_to_objclass(']');
/* Note: these initializers don't do anything except guarantee that
we're linked properly.
*/
monst_init();
objects_init();
(void) def_char_to_objclass(']');
condnum = tilenum = 0;
condnum = tilenum = 0;
for (i = 0; i < NUMMONS; i++) {
if (set == MON_GLYPH && tilenum == entry)
return mons[i].mname;
tilenum++;
while (conditionals[condnum].sequence == MON_GLYPH &&
conditionals[condnum].predecessor == i) {
if (set == MON_GLYPH && tilenum == entry)
return conditionals[condnum].name;
condnum++;
tilenum++;
}
}
if (set == MON_GLYPH && tilenum == entry)
return "invisible monster";
for (i = 0; i < NUMMONS; i++) {
if (set == MON_GLYPH && tilenum == entry)
return mons[i].mname;
tilenum++;
while (conditionals[condnum].sequence == MON_GLYPH
&& conditionals[condnum].predecessor == i) {
if (set == MON_GLYPH && tilenum == entry)
return conditionals[condnum].name;
condnum++;
tilenum++;
}
}
if (set == MON_GLYPH && tilenum == entry)
return "invisible monster";
tilenum = 0; /* set-relative number */
for (i = 0; i < NUM_OBJECTS; i++) {
/* prefer to give the description - that's all the tile's
* appearance should reveal */
if (set == OBJ_GLYPH && tilenum == entry) {
if ( !obj_descr[i].oc_descr )
return obj_descr[i].oc_name;
if ( !obj_descr[i].oc_name )
return obj_descr[i].oc_descr;
tilenum = 0; /* set-relative number */
for (i = 0; i < NUM_OBJECTS; i++) {
/* prefer to give the description - that's all the tile's
* appearance should reveal */
if (set == OBJ_GLYPH && tilenum == entry) {
if (!obj_descr[i].oc_descr)
return obj_descr[i].oc_name;
if (!obj_descr[i].oc_name)
return obj_descr[i].oc_descr;
Sprintf(buf, "%s / %s",
obj_descr[i].oc_descr,
obj_descr[i].oc_name);
return buf;
}
Sprintf(buf, "%s / %s", obj_descr[i].oc_descr,
obj_descr[i].oc_name);
return buf;
}
tilenum++;
while (conditionals[condnum].sequence == OBJ_GLYPH &&
conditionals[condnum].predecessor == i) {
if (set == OBJ_GLYPH && tilenum == entry)
return conditionals[condnum].name;
condnum++;
tilenum++;
}
}
tilenum++;
while (conditionals[condnum].sequence == OBJ_GLYPH
&& conditionals[condnum].predecessor == i) {
if (set == OBJ_GLYPH && tilenum == entry)
return conditionals[condnum].name;
condnum++;
tilenum++;
}
}
tilenum = 0; /* set-relative number */
for (i = 0; i < (MAXPCHARS - MAXEXPCHARS); i++) {
if (set == OTH_GLYPH && tilenum == entry) {
if (*defsyms[i].explanation) {
return defsyms[i].explanation;
tilenum = 0; /* set-relative number */
for (i = 0; i < (MAXPCHARS - MAXEXPCHARS); i++) {
if (set == OTH_GLYPH && tilenum == entry) {
if (*defsyms[i].explanation) {
return defsyms[i].explanation;
} else {
Sprintf(buf, "cmap %d", tilenum);
return buf;
}
}
tilenum++;
while (conditionals[condnum].sequence == OTH_GLYPH &&
conditionals[condnum].predecessor == i) {
if (set == OTH_GLYPH && tilenum == entry)
return conditionals[condnum].name;
condnum++;
tilenum++;
}
}
/* explosions */
tilenum = MAXPCHARS - MAXEXPCHARS;
i = entry - tilenum;
if (i < (MAXEXPCHARS * EXPL_MAX)) {
if (set == OTH_GLYPH) {
static const char *explosion_types[] = { /* hack.h */
"dark", "noxious", "muddy", "wet",
"magical", "fiery", "frosty"
};
Sprintf(buf, "explosion %s %d",
explosion_types[i / MAXEXPCHARS], i % MAXEXPCHARS);
return buf;
}
}
tilenum += (MAXEXPCHARS * EXPL_MAX);
return buf;
}
}
tilenum++;
while (conditionals[condnum].sequence == OTH_GLYPH
&& conditionals[condnum].predecessor == i) {
if (set == OTH_GLYPH && tilenum == entry)
return conditionals[condnum].name;
condnum++;
tilenum++;
}
}
/* explosions */
tilenum = MAXPCHARS - MAXEXPCHARS;
i = entry - tilenum;
if (i < (MAXEXPCHARS * EXPL_MAX)) {
if (set == OTH_GLYPH) {
static const char *explosion_types[] = {
/* hack.h */
"dark", "noxious", "muddy", "wet", "magical", "fiery",
"frosty"
};
Sprintf(buf, "explosion %s %d", explosion_types[i / MAXEXPCHARS],
i % MAXEXPCHARS);
return buf;
}
}
tilenum += (MAXEXPCHARS * EXPL_MAX);
i = entry - tilenum;
if (i < (NUM_ZAP << 2)) {
if (set == OTH_GLYPH) {
Sprintf(buf, "zap %d %d", i/4, i%4);
return buf;
}
}
tilenum += (NUM_ZAP << 2);
i = entry - tilenum;
if (i < (NUM_ZAP << 2)) {
if (set == OTH_GLYPH) {
Sprintf(buf, "zap %d %d", i / 4, i % 4);
return buf;
}
}
tilenum += (NUM_ZAP << 2);
i = entry - tilenum;
if (i < WARNCOUNT) {
if (set == OTH_GLYPH) {
Sprintf(buf, "warning %d", i);
return buf;
}
}
tilenum += WARNCOUNT;
i = entry - tilenum;
if (i < WARNCOUNT) {
if (set == OTH_GLYPH) {
Sprintf(buf, "warning %d", i);
return buf;
}
}
tilenum += WARNCOUNT;
for (i = 0; i < SIZE(substitutes); i++) {
j = entry - tilenum;
if (j <= substitutes[i].last_glyph - substitutes[i].first_glyph) {
if (set == OTH_GLYPH) {
Sprintf(buf, "sub %s %d", substitutes[i].sub_name, j);
return buf;
}
}
tilenum += substitutes[i].last_glyph
- substitutes[i].first_glyph + 1;
}
for (i = 0; i < SIZE(substitutes); i++) {
j = entry - tilenum;
if (j <= substitutes[i].last_glyph - substitutes[i].first_glyph) {
if (set == OTH_GLYPH) {
Sprintf(buf, "sub %s %d", substitutes[i].sub_name, j);
return buf;
}
}
tilenum += substitutes[i].last_glyph - substitutes[i].first_glyph + 1;
}
Sprintf(buf, "unknown %d %d", set, entry);
return buf;
Sprintf(buf, "unknown %d %d", set, entry);
return buf;
}
#else /* TILETEXT */
#else /* TILETEXT */
#define TILE_FILE "tile.c"
#define TILE_FILE "tile.c"
#ifdef AMIGA
# define SOURCE_TEMPLATE "NH:src/%s"
#define SOURCE_TEMPLATE "NH:src/%s"
#else
# ifdef MAC
# define SOURCE_TEMPLATE ":src:%s"
# else
# define SOURCE_TEMPLATE "../src/%s"
# endif
#ifdef MAC
#define SOURCE_TEMPLATE ":src:%s"
#else
#define SOURCE_TEMPLATE "../src/%s"
#endif
#endif
short tilemap[MAX_GLYPH];
@@ -264,229 +259,215 @@ int lastmontile, lastobjtile, lastothtile;
void
init_tilemap()
{
int i, j, condnum, tilenum;
int corpsetile, swallowbase;
int i, j, condnum, tilenum;
int corpsetile, swallowbase;
for (i = 0; i < MAX_GLYPH; i++) {
tilemap[i] = -1;
}
for (i = 0; i < MAX_GLYPH; i++) {
tilemap[i] = -1;
}
corpsetile = NUMMONS + NUM_INVIS_TILES + CORPSE;
swallowbase= NUMMONS + NUM_INVIS_TILES + NUM_OBJECTS + S_sw_tl;
corpsetile = NUMMONS + NUM_INVIS_TILES + CORPSE;
swallowbase = NUMMONS + NUM_INVIS_TILES + NUM_OBJECTS + S_sw_tl;
/* add number compiled out */
for (i = 0; conditionals[i].sequence; i++) {
switch (conditionals[i].sequence) {
case MON_GLYPH:
corpsetile++;
swallowbase++;
break;
case OBJ_GLYPH:
if (conditionals[i].predecessor < CORPSE)
corpsetile++;
swallowbase++;
break;
case OTH_GLYPH:
if (conditionals[i].predecessor < S_sw_tl)
swallowbase++;
break;
}
}
/* add number compiled out */
for (i = 0; conditionals[i].sequence; i++) {
switch (conditionals[i].sequence) {
case MON_GLYPH:
corpsetile++;
swallowbase++;
break;
case OBJ_GLYPH:
if (conditionals[i].predecessor < CORPSE)
corpsetile++;
swallowbase++;
break;
case OTH_GLYPH:
if (conditionals[i].predecessor < S_sw_tl)
swallowbase++;
break;
}
}
condnum = tilenum = 0;
for (i = 0; i < NUMMONS; i++) {
tilemap[GLYPH_MON_OFF+i] = tilenum;
tilemap[GLYPH_PET_OFF+i] = tilenum;
tilemap[GLYPH_DETECT_OFF+i] = tilenum;
tilemap[GLYPH_RIDDEN_OFF+i] = tilenum;
tilemap[GLYPH_BODY_OFF+i] = corpsetile;
j = GLYPH_SWALLOW_OFF + 8*i;
tilemap[j] = swallowbase;
tilemap[j+1] = swallowbase+1;
tilemap[j+2] = swallowbase+2;
tilemap[j+3] = swallowbase+3;
tilemap[j+4] = swallowbase+4;
tilemap[j+5] = swallowbase+5;
tilemap[j+6] = swallowbase+6;
tilemap[j+7] = swallowbase+7;
tilenum++;
while (conditionals[condnum].sequence == MON_GLYPH &&
conditionals[condnum].predecessor == i) {
condnum++;
tilenum++;
}
}
tilemap[GLYPH_INVISIBLE] = tilenum++;
lastmontile = tilenum - 1;
condnum = tilenum = 0;
for (i = 0; i < NUMMONS; i++) {
tilemap[GLYPH_MON_OFF + i] = tilenum;
tilemap[GLYPH_PET_OFF + i] = tilenum;
tilemap[GLYPH_DETECT_OFF + i] = tilenum;
tilemap[GLYPH_RIDDEN_OFF + i] = tilenum;
tilemap[GLYPH_BODY_OFF + i] = corpsetile;
j = GLYPH_SWALLOW_OFF + 8 * i;
tilemap[j] = swallowbase;
tilemap[j + 1] = swallowbase + 1;
tilemap[j + 2] = swallowbase + 2;
tilemap[j + 3] = swallowbase + 3;
tilemap[j + 4] = swallowbase + 4;
tilemap[j + 5] = swallowbase + 5;
tilemap[j + 6] = swallowbase + 6;
tilemap[j + 7] = swallowbase + 7;
tilenum++;
while (conditionals[condnum].sequence == MON_GLYPH
&& conditionals[condnum].predecessor == i) {
condnum++;
tilenum++;
}
}
tilemap[GLYPH_INVISIBLE] = tilenum++;
lastmontile = tilenum - 1;
for (i = 0; i < NUM_OBJECTS; i++) {
tilemap[GLYPH_OBJ_OFF+i] = tilenum;
tilenum++;
while (conditionals[condnum].sequence == OBJ_GLYPH &&
conditionals[condnum].predecessor == i) {
condnum++;
tilenum++;
}
}
lastobjtile = tilenum - 1;
for (i = 0; i < NUM_OBJECTS; i++) {
tilemap[GLYPH_OBJ_OFF + i] = tilenum;
tilenum++;
while (conditionals[condnum].sequence == OBJ_GLYPH
&& conditionals[condnum].predecessor == i) {
condnum++;
tilenum++;
}
}
lastobjtile = tilenum - 1;
for (i = 0; i < (MAXPCHARS - MAXEXPCHARS); i++) {
tilemap[GLYPH_CMAP_OFF+i] = tilenum;
tilenum++;
while (conditionals[condnum].sequence == OTH_GLYPH &&
conditionals[condnum].predecessor == i) {
condnum++;
tilenum++;
}
}
for (i = 0; i < (MAXPCHARS - MAXEXPCHARS); i++) {
tilemap[GLYPH_CMAP_OFF + i] = tilenum;
tilenum++;
while (conditionals[condnum].sequence == OTH_GLYPH
&& conditionals[condnum].predecessor == i) {
condnum++;
tilenum++;
}
}
for (i = 0; i < (MAXEXPCHARS * EXPL_MAX); i++) {
tilemap[GLYPH_EXPLODE_OFF+i] = tilenum;
tilenum++;
while (conditionals[condnum].sequence == OTH_GLYPH &&
conditionals[condnum].predecessor == (i + MAXPCHARS)) {
condnum++;
tilenum++;
}
}
for (i = 0; i < (MAXEXPCHARS * EXPL_MAX); i++) {
tilemap[GLYPH_EXPLODE_OFF + i] = tilenum;
tilenum++;
while (conditionals[condnum].sequence == OTH_GLYPH
&& conditionals[condnum].predecessor == (i + MAXPCHARS)) {
condnum++;
tilenum++;
}
}
for (i = 0; i < NUM_ZAP << 2; i++) {
tilemap[GLYPH_ZAP_OFF+i] = tilenum;
tilenum++;
while (conditionals[condnum].sequence == OTH_GLYPH &&
conditionals[condnum].predecessor == (i + MAXEXPCHARS)) {
condnum++;
tilenum++;
}
}
for (i = 0; i < NUM_ZAP << 2; i++) {
tilemap[GLYPH_ZAP_OFF + i] = tilenum;
tilenum++;
while (conditionals[condnum].sequence == OTH_GLYPH
&& conditionals[condnum].predecessor == (i + MAXEXPCHARS)) {
condnum++;
tilenum++;
}
}
for (i = 0; i < WARNCOUNT; i++) {
tilemap[GLYPH_WARNING_OFF+i] = tilenum;
tilenum++;
}
for (i = 0; i < WARNCOUNT; i++) {
tilemap[GLYPH_WARNING_OFF + i] = tilenum;
tilenum++;
}
#ifndef STATUES_LOOK_LIKE_MONSTERS
/* statue patch: statues still use the same glyph as in vanilla */
for ( i = 0; i < NUMMONS; i++) {
tilemap[GLYPH_STATUE_OFF+i] = tilemap[GLYPH_OBJ_OFF+STATUE];
}
/* statue patch: statues still use the same glyph as in vanilla */
for (i = 0; i < NUMMONS; i++) {
tilemap[GLYPH_STATUE_OFF + i] = tilemap[GLYPH_OBJ_OFF + STATUE];
}
#endif
lastothtile = tilenum - 1;
lastothtile = tilenum - 1;
#ifdef STATUES_LOOK_LIKE_MONSTERS
/* skip over the substitutes to get to the grayscale statues */
for (i = 0; i < SIZE(substitutes); i++) {
tilenum += substitutes[i].last_glyph - substitutes[i].first_glyph + 1;
}
/* skip over the substitutes to get to the grayscale statues */
for (i = 0; i < SIZE(substitutes); i++) {
tilenum += substitutes[i].last_glyph - substitutes[i].first_glyph + 1;
}
/* statue patch: statues look more like the monster */
condnum = 0; /* doing monsters again, so reset */
for (i = 0; i < NUMMONS; i++) {
tilemap[GLYPH_STATUE_OFF+i] = tilenum;
tilenum++;
while (conditionals[condnum].sequence == MON_GLYPH &&
conditionals[condnum].predecessor == i) {
condnum++;
tilenum++;
}
}
laststatuetile = tilenum - 1;
/* statue patch: statues look more like the monster */
condnum = 0; /* doing monsters again, so reset */
for (i = 0; i < NUMMONS; i++) {
tilemap[GLYPH_STATUE_OFF + i] = tilenum;
tilenum++;
while (conditionals[condnum].sequence == MON_GLYPH
&& conditionals[condnum].predecessor == i) {
condnum++;
tilenum++;
}
}
laststatuetile = tilenum - 1;
#endif
}
const char *prolog[] = {
"",
"",
"void",
"substitute_tiles(plev)",
"d_level *plev;",
"{",
"\tint i;",
""
};
const char *prolog[] = { "", "", "void", "substitute_tiles(plev)",
"d_level *plev;", "{", "\tint i;", "" };
const char *epilog[] = {
"}"
};
const char *epilog[] = { "}" };
/* write out the substitutions in an easily-used form. */
void
process_substitutions(ofp)
FILE *ofp;
{
int i, j, k, span, start;
int i, j, k, span, start;
fprintf(ofp, "\n\n");
fprintf(ofp, "\n\n");
j = 0; /* unnecessary */
span = -1;
for (i = 0; i < SIZE(substitutes); i++) {
if (i == 0
|| substitutes[i].first_glyph != substitutes[j].first_glyph
|| substitutes[i].last_glyph != substitutes[j].last_glyph) {
j = i;
span++;
fprintf(ofp, "short std_tiles%d[] = { ", span);
for (k = substitutes[i].first_glyph;
k < substitutes[i].last_glyph; k++)
fprintf(ofp, "%d, ", tilemap[k]);
fprintf(ofp, "%d };\n",
tilemap[substitutes[i].last_glyph]);
}
}
j = 0; /* unnecessary */
span = -1;
for (i = 0; i < SIZE(substitutes); i++) {
if (i == 0 || substitutes[i].first_glyph != substitutes[j].first_glyph
|| substitutes[i].last_glyph != substitutes[j].last_glyph) {
j = i;
span++;
fprintf(ofp, "short std_tiles%d[] = { ", span);
for (k = substitutes[i].first_glyph;
k < substitutes[i].last_glyph; k++)
fprintf(ofp, "%d, ", tilemap[k]);
fprintf(ofp, "%d };\n", tilemap[substitutes[i].last_glyph]);
}
}
for (i = 0; i < SIZE(prolog); i++) {
fprintf(ofp, "%s\n", prolog[i]);
}
j = -1;
span = -1;
start = lastothtile + 1;
for (i = 0; i < SIZE(substitutes); i++) {
if (i == 0
|| substitutes[i].first_glyph != substitutes[j].first_glyph
|| substitutes[i].last_glyph != substitutes[j].last_glyph) {
if (i != 0) { /* finish previous span */
fprintf(ofp, "\t} else {\n");
fprintf(ofp, "\t\tfor (i = %d; i <= %d; i++)\n",
substitutes[j].first_glyph,
substitutes[j].last_glyph);
fprintf(ofp, "\t\t\tglyph2tile[i] = std_tiles%d[i - %d];\n",
span, substitutes[j].first_glyph);
fprintf(ofp, "\t}\n\n");
}
j = i;
span++;
}
if (i != j) fprintf(ofp, "\t} else ");
fprintf(ofp, "\tif (%s) {\n", substitutes[i].level_test);
fprintf(ofp, "\t\tfor (i = %d; i <= %d; i++)\n",
substitutes[i].first_glyph,
substitutes[i].last_glyph);
fprintf(ofp, "\t\t\tglyph2tile[i] = %d + i - %d;\n",
start, substitutes[i].first_glyph);
start += substitutes[i].last_glyph - substitutes[i].first_glyph + 1;
}
/* finish last span */
fprintf(ofp, "\t} else {\n");
fprintf(ofp, "\t\tfor (i = %d; i <= %d; i++)\n",
substitutes[j].first_glyph,
substitutes[j].last_glyph);
fprintf(ofp, "\t\t\tglyph2tile[i] = std_tiles%d[i - %d];\n",
span, substitutes[j].first_glyph);
fprintf(ofp, "\t}\n\n");
for (i = 0; i < SIZE(prolog); i++) {
fprintf(ofp, "%s\n", prolog[i]);
}
j = -1;
span = -1;
start = lastothtile + 1;
for (i = 0; i < SIZE(substitutes); i++) {
if (i == 0 || substitutes[i].first_glyph != substitutes[j].first_glyph
|| substitutes[i].last_glyph != substitutes[j].last_glyph) {
if (i != 0) { /* finish previous span */
fprintf(ofp, "\t} else {\n");
fprintf(ofp, "\t\tfor (i = %d; i <= %d; i++)\n",
substitutes[j].first_glyph,
substitutes[j].last_glyph);
fprintf(ofp, "\t\t\tglyph2tile[i] = std_tiles%d[i - %d];\n",
span, substitutes[j].first_glyph);
fprintf(ofp, "\t}\n\n");
}
j = i;
span++;
}
if (i != j)
fprintf(ofp, "\t} else ");
fprintf(ofp, "\tif (%s) {\n", substitutes[i].level_test);
fprintf(ofp, "\t\tfor (i = %d; i <= %d; i++)\n",
substitutes[i].first_glyph, substitutes[i].last_glyph);
fprintf(ofp, "\t\t\tglyph2tile[i] = %d + i - %d;\n", start,
substitutes[i].first_glyph);
start += substitutes[i].last_glyph - substitutes[i].first_glyph + 1;
}
/* finish last span */
fprintf(ofp, "\t} else {\n");
fprintf(ofp, "\t\tfor (i = %d; i <= %d; i++)\n",
substitutes[j].first_glyph, substitutes[j].last_glyph);
fprintf(ofp, "\t\t\tglyph2tile[i] = std_tiles%d[i - %d];\n", span,
substitutes[j].first_glyph);
fprintf(ofp, "\t}\n\n");
for (i = 0; i < SIZE(epilog); i++) {
fprintf(ofp, "%s\n", epilog[i]);
}
for (i = 0; i < SIZE(epilog); i++) {
fprintf(ofp, "%s\n", epilog[i]);
}
fprintf(ofp, "\nint total_tiles_used = %d;\n", start);
lastothtile = start - 1;
fprintf(ofp, "\nint total_tiles_used = %d;\n", start);
lastothtile = start - 1;
}
int main()
int
main()
{
register int i;
char filename[30];
@@ -499,25 +480,26 @@ int main()
*/
Sprintf(filename, SOURCE_TEMPLATE, TILE_FILE);
if (!(ofp = fopen(filename, "w"))) {
perror(filename);
exit(EXIT_FAILURE);
perror(filename);
exit(EXIT_FAILURE);
}
fprintf(ofp,"/* This file is automatically generated. Do not edit. */\n");
fprintf(ofp,"\n#include \"hack.h\"\n\n");
fprintf(ofp,"short glyph2tile[MAX_GLYPH] = {\n");
fprintf(ofp,
"/* This file is automatically generated. Do not edit. */\n");
fprintf(ofp, "\n#include \"hack.h\"\n\n");
fprintf(ofp, "short glyph2tile[MAX_GLYPH] = {\n");
for (i = 0; i < MAX_GLYPH; i++) {
fprintf(ofp,"%2d,%c", tilemap[i], (i % 12) ? ' ' : '\n');
fprintf(ofp, "%2d,%c", tilemap[i], (i % 12) ? ' ' : '\n');
}
fprintf(ofp,"%s};\n", (i % 12) ? "\n" : "");
fprintf(ofp, "%s};\n", (i % 12) ? "\n" : "");
process_substitutions(ofp);
fprintf(ofp,"\n#define MAXMONTILE %d\n", lastmontile);
fprintf(ofp,"#define MAXOBJTILE %d\n", lastobjtile);
fprintf(ofp,"#define MAXOTHTILE %d\n", lastothtile);
fprintf(ofp, "\n#define MAXMONTILE %d\n", lastmontile);
fprintf(ofp, "#define MAXOBJTILE %d\n", lastobjtile);
fprintf(ofp, "#define MAXOTHTILE %d\n", lastothtile);
fprintf(ofp,"\n/*tile.c*/\n");
fprintf(ofp, "\n/*tile.c*/\n");
fclose(ofp);
exit(EXIT_SUCCESS);
@@ -525,4 +507,4 @@ int main()
return 0;
}
#endif /* TILETEXT */
#endif /* TILETEXT */
+224 -221
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 tiletext.c $NHDT-Date: 1430640200 2015/05/03 08:03:20 $ $NHDT-Branch: master $:$NHDT-Revision: 1.7 $ */
/* NetHack 3.6 tiletext.c $NHDT-Date: 1431192770 2015/05/09 17:32:50 $ $NHDT-Branch: master $:$NHDT-Revision: 1.10 $ */
/* NetHack 3.6 tiletext.c $Date: 2009/05/06 10:59:03 $ $Revision: 1.4 $ */
/* SCCS Id: @(#)tiletext.c 3.5 1999/10/24 */
/* NetHack may be freely redistributed. See license for details. */
@@ -19,41 +19,44 @@ 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" };
#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" };
static const char *text_sets[] = { "monsters.txt", "objects.txt",
"other.txt" };
#endif
extern const char *FDECL(tilename, (int, int));
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]));
static boolean FDECL(read_txttile, (FILE *, pixel (*)[TILE_X]));
static void FDECL(write_txttile, (FILE *, pixel (*)[TILE_X]));
/* Ugh. DICE doesn't like %[A-Z], so we have to spell it out... */
#define FORMAT_STRING \
"%[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.] = (%d, %d, %d) "
#define FORMAT_STRING \
"%[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.] = " \
"(%d, %d, %d) "
static void
read_text_colormap(txtfile)
FILE *txtfile;
{
int i, r, g, b;
char c[2];
int i, r, g, b;
char c[2];
for (i = 0; i < MAXCOLORMAPSIZE; i++)
color_index[i] = -1;
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;
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
@@ -62,26 +65,28 @@ static boolean
write_text_colormap(txtfile)
FILE *txtfile;
{
int i;
char c;
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;
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;
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
@@ -89,82 +94,78 @@ read_txttile(txtfile, pixels)
FILE *txtfile;
pixel (*pixels)[TILE_X];
{
int ph, i, j, k;
char buf[BUFSZ], ttype[BUFSZ];
const char *p;
char c[2];
int ph, i, j, k;
char buf[BUFSZ], ttype[BUFSZ];
const char *p;
char c[2];
if (fscanf(txtfile, "# %s %d (%[^)])", ttype, &i, buf) <= 0)
return FALSE;
ph = strcmp(ttype, "placeholder") == 0;
if (fscanf(txtfile, "# %s %d (%[^)])", ttype, &i, buf) <= 0)
return FALSE;
if (!ph && strcmp(ttype,"tile") != 0)
Fprintf(stderr,
"Keyword \"%s\" unexpected for entry %d\n",
ttype, i);
ph = strcmp(ttype, "placeholder") == 0;
if (tile_set != 0) {
/* check tile name, but not relative number, which will
* change when tiles are added
*/
p = tilename(tile_set, tile_set_indx);
if (p && strcmp(p, buf)) {
Fprintf(stderr, "warning: for tile %d (numbered %d) of %s,\n",
tile_set_indx, i, text_sets[tile_set-1]);
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 (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;
}
if (!ph && strcmp(ttype, "tile") != 0)
Fprintf(stderr, "Keyword \"%s\" unexpected for entry %d\n", ttype, i);
if (tile_set != 0) {
/* check tile name, but not relative number, which will
* change when tiles are added
*/
p = tilename(tile_set, tile_set_indx);
if (p && strcmp(p, buf)) {
Fprintf(stderr, "warning: for tile %d (numbered %d) of %s,\n",
tile_set_indx, i, text_sets[tile_set - 1]);
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 (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(*c))
;
ungetc(*c, txtfile);
/* 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(*c))
;
ungetc(*c, txtfile);
#endif
return TRUE;
return TRUE;
}
static void
@@ -172,84 +173,84 @@ write_txttile(txtfile, pixels)
FILE *txtfile;
pixel (*pixels)[TILE_X];
{
const char *p;
const char *type;
int i, j, k;
const char *p;
const char *type;
int i, j, k;
if ( memcmp(placeholder, pixels, sizeof(placeholder)) == 0 )
type = "placeholder";
else
type = "tile";
if (memcmp(placeholder, pixels, sizeof(placeholder)) == 0)
type = "placeholder";
else
type = "tile";
if (tile_set == 0)
Fprintf(txtfile, "# %s %d (unknown)\n", type, tile_set_indx);
else {
p = tilename(tile_set, tile_set_indx);
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++;
if (tile_set == 0)
Fprintf(txtfile, "# %s %d (unknown)\n", type, tile_set_indx);
else {
p = tilename(tile_set, tile_set_indx);
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");
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;
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];
}
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;
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++;
}
}
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
@@ -257,78 +258,80 @@ fopen_text_file(filename, type)
const char *filename;
const char *type;
{
const char *p;
int i;
const char *p;
int i;
if (tile_file != (FILE *)0) {
Fprintf(stderr, "can only open one text file at at time\n");
return FALSE;
}
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;
}
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;
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+1;
}
tile_set_indx = 0;
tile_set = 0;
for (i = 0; i < SIZE(text_sets); i++) {
if (!strcmp(p, text_sets[i]))
tile_set = i + 1;
}
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;
}
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;
}
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));
return (read_txttile(tile_file, pixels));
}
boolean
write_text_tile(pixels)
pixel (*pixels)[TILE_X];
{
write_txttile(tile_file, pixels);
return TRUE;
write_txttile(tile_file, pixels);
return TRUE;
}
int
fclose_text_file()
{
int ret;
int ret;
ret = fclose(tile_file);
tile_file = (FILE *)0;
return ret;
ret = fclose(tile_file);
tile_file = (FILE *) 0;
return ret;
}