1    | /*   SCCS Id: @(#)thintile.c   3.3     95/11/26                     */
2    | /*   Copyright (c) NetHack Development Team 1995                    */
3    | /*   NetHack may be freely redistributed.  See license for details. */
4    | 
5    | /* Create a set of overview tiles by eliminating even pixels in original */
6    | 
7    | #include "config.h"
8    | #include "tile.h"
9    | 
10   | #ifdef __GO32__
11   | #include <unistd.h>
12   | #endif
13   | 
14   | static char pixels[TILE_Y][TILE_X];
15   | 
16   | static char *tilefiles[] = {	"../win/share/monsters.txt",
17   | 				"../win/share/objects.txt",
18   | 				"../win/share/other.txt"};
19   | 
20   | static char *thinfiles[] = {	"../win/share/monthin.txt",
21   | 				"../win/share/objthin.txt",
22   | 				"../win/share/oththin.txt"};
23   | static FILE *infile, *outfile;
24   | static int tilecount;
25   | static int tilecount_per_file;
26   | static int filenum;
27   | static char comment[BUFSZ];
28   | 
29   | static void
30   | copy_colormap()
31   | {
32   | 	int i, r, g, b;
33   | 	char c[2];
34   | 
35   | 	while (fscanf(infile, "%[A-Za-z0-9] = (%d, %d, %d) ", c, &r, &g, &b)
36   | 								== 4) {
37   | 		Fprintf(outfile, "%c = (%d, %d, %d)\n", c[0], r, g, b);
38   | 	}
39   | }
40   | 
41   | static boolean
42   | read_txttile()
43   | {
44   | 	int i, j, k;
45   | 	char buf[BUFSZ];
46   | 	const char *p;
47   | 	char c[2];
48   | 
49   | 
50   | 	if (fscanf(infile, "# tile %d (%[^)])", &i, buf) <= 0)
51   | 		return FALSE;
52   | 	
53   | 	Sprintf(comment,"# tile %d (%s)", i, buf);
54   | 	
55   | 	/* look for non-whitespace at each stage */
56   | 	if (fscanf(infile, "%1s", c) < 0) {
57   | 		Fprintf(stderr, "unexpected EOF\n");
58   | 		return FALSE;
59   | 	}
60   | 	if (c[0] != '{') {
61   | 		Fprintf(stderr, "didn't find expected '{'\n");
62   | 		return FALSE;
63   | 	}
64   | 	for (j = 0; j < TILE_Y; j++) {
65   | 		for (i = 0; i < TILE_X; i++) {
66   | 			if (fscanf(infile, "%1s", c) < 0) {
67   | 				Fprintf(stderr, "unexpected EOF\n");
68   | 				return FALSE;
69   | 			}
70   | 			pixels[j][i] = c[0];
71   | 		}
72   | 	}
73   | 	if (fscanf(infile, "%1s ", c) < 0) {
74   | 		Fprintf(stderr, "unexpected EOF\n");
75   | 		return FALSE;
76   | 	}
77   | 	if (c[0] != '}') {
78   | 		Fprintf(stderr, "didn't find expected '}'\n");
79   | 		return FALSE;
80   | 	}
81   | 	return TRUE;
82   | }
83   | 
84   | static void
85   | write_thintile()
86   | {
87   | 	const char *p;
88   | 	int i, j, k;
89   | 
90   | 
91   | 	Fprintf(outfile, "%s\n", comment);
92   | 	Fprintf(outfile, "{\n");
93   | 	for (j = 0; j < TILE_Y; j++) {
94   | 		Fprintf(outfile, "  ");
95   | 		for (i = 0; i < TILE_X; i += 2) {
96   | 			(void) fputc(pixels[j][i], outfile);
97   | 		}
98   | 		Fprintf(outfile, "\n");
99   | 	}
100  | 	Fprintf(outfile, "}\n");
101  | }
102  | int
103  | main(argc, argv)
104  | int argc;
105  | char *argv[];
106  | {
107  | 	boolean x;
108  | 	
109  | 	while (filenum < 3) {
110  | 		tilecount_per_file = 0;
111  | 		infile = fopen(tilefiles[filenum], RDTMODE);
112  | 		outfile = fopen(thinfiles[filenum], WRTMODE);
113  | 		copy_colormap();
114  | 		while (read_txttile()) {
115  | 				write_thintile();
116  | 				tilecount_per_file++;
117  | 				tilecount++;
118  | 		}
119  | 		fclose(outfile);
120  | 		fclose(infile);
121  | 		printf("%d tiles processed from %s\n",
122  | 			tilecount_per_file, tilefiles[filenum]);
123  | 		++filenum;
124  | 	}
125  | 	printf("Grand total of %d tiles processed.\n", tilecount);
126  | 	exit(EXIT_SUCCESS);
127  | 	/*NOTREACHED*/
128  | 	return 0;
129  | }
130  | 
131  | /*thintile.c*/