1 /* NetHack 3.6 tile2bin.c $NHDT-Date: 1457207041 2016/03/05 19:44:01 $ $NHDT-Branch: chasonr $:$NHDT-Revision: 1.9 $ */
2 /* Copyright (c) NetHack PC Development Team 1993, 1994, 1995 */
3 /* NetHack may be freely redistributed. See license for details. */
8 * Initial Creation M.Allison 93/10/21
9 * ifndef MONITOR_HEAP for heaputil.c P.Winner 94/03/12
10 * added Borland C _stklen variable Y.Sapir 94/05/01
11 * fixed to use text tiles from win/share M.Allison 95/01/31
30 #if defined(_MSC_VER) && _MSC_VER >= 700
31 #pragma warning(disable : 4309) /* initializing */
32 #pragma warning(disable : 4018) /* signed/unsigned mismatch */
33 #pragma warning(disable : 4131) /* old style declarator */
34 #pragma warning(disable : 4127) /* conditional express. is constant */
38 extern unsigned _stklen
= STKSIZ
;
41 /* Produce only a planar file if building the overview file; with packed
42 files, we can make overview-size tiles on the fly */
43 #if defined(OVERVIEW_FILE) && defined(PACKED_FILE)
47 extern char *FDECL(tilename
, (int, int));
50 char masktable
[8] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 };
51 char charcolors
[MAXCOLORMAPSIZE
];
53 struct overview_planar_cell_struct planetile
;
55 struct planar_cell_struct planetile
;
61 char packtile
[TILE_Y
][TILE_X
];
66 pixel pixels
[TILE_Y
][TILE_X
];
67 struct tibhdr_struct tibheader
;
69 static void FDECL(write_tibtile
, (int));
70 static void FDECL(write_tibheader
, (FILE *, struct tibhdr_struct
*));
71 static void FDECL(build_tibtile
, (pixel(*) [TILE_X
], BOOLEAN_P
));
72 static void NDECL(remap_colors
);
75 char *tilefiles
[] = { "../win/share/monsters.txt", "../win/share/objects.txt",
76 "../win/share/other.txt" };
78 char *tilefiles
[] = { "../win/share/monthin.txt", "../win/share/objthin.txt",
79 "../win/share/oththin.txt" };
95 unsigned num_monsters
= 0;
98 Fprintf(stderr
, "usage: tile2bin (from the util directory)\n");
103 #ifndef OVERVIEW_FILE
104 tibfile1
= fopen(NETHACK_PLANAR_TILEFILE
, WRBMODE
);
106 tibfile1
= fopen(NETHACK_OVERVIEW_TILEFILE
, WRBMODE
);
108 if (tibfile1
== (FILE *) 0) {
109 Fprintf(stderr
, "Unable to open output file %s\n",
110 #ifndef OVERVIEW_FILE
111 NETHACK_PLANAR_TILEFILE
);
113 NETHACK_OVERVIEW_TILEFILE
);
120 tibfile2
= fopen(NETHACK_PACKED_TILEFILE
, WRBMODE
);
121 if (tibfile2
== (FILE *) 0) {
122 Fprintf(stderr
, "Unable to open output file %s\n",
123 NETHACK_PACKED_TILEFILE
);
128 newtime
= localtime(&aclock
);
133 while (filenum
< 3) {
134 if (!fopen_text_file(tilefiles
[filenum
], RDTMODE
)) {
136 "usage: tile2bin (from the util or src directory)\n");
139 num_colors
= colorsinmap
;
140 if (num_colors
> 62) {
141 Fprintf(stderr
, "too many colors (%d)\n", num_colors
);
147 paletteptr
= tibheader
.palette
;
148 for (i
= 0; i
< num_colors
; i
++) {
149 *paletteptr
++ = ColorMap
[CM_RED
][i
],
150 *paletteptr
++ = ColorMap
[CM_GREEN
][i
],
151 *paletteptr
++ = ColorMap
[CM_BLUE
][i
];
156 while (read_text_tile(pixels
)) {
157 build_tibtile(pixels
, FALSE
);
158 write_tibtile(tilecount
);
162 (void) fclose_text_file();
164 num_monsters
= tilecount
;
169 /* Build the statue glyphs */
170 if (!fopen_text_file(tilefiles
[0], RDTMODE
)) {
172 "usage: tile2bin (from the util or src directory)\n");
176 while (read_text_tile(pixels
)) {
177 build_tibtile(pixels
, TRUE
);
178 write_tibtile(tilecount
);
182 (void) fclose_text_file();
184 #if defined(_MSC_VER)
185 tibheader
.compiler
= MSC_COMP
;
186 #elif defined(__BORLANDC__)
187 tibheader
.compiler
= BC_COMP
;
188 #elif defined(__GO32__)
189 tibheader
.compiler
= DJGPP_COMP
;
191 tibheader
.compiler
= OTHER_COMP
;
194 strncpy(tibheader
.ident
, "NetHack 3.6 MSDOS Port binary tile file", 80);
195 strncpy(tibheader
.timestamp
, asctime(newtime
), 24);
196 tibheader
.timestamp
[25] = '\0';
197 tibheader
.tilecount
= tilecount
;
198 tibheader
.numcolors
= num_colors
;
200 tibheader
.tilestyle
= PLANAR_STYLE
;
201 write_tibheader(tibfile1
, &tibheader
);
202 (void) fclose(tibfile1
);
203 #ifndef OVERVIEW_FILE
204 Fprintf(stderr
, "Total of %d planar tiles written to %s.\n", tilecount
,
205 NETHACK_PLANAR_TILEFILE
);
207 Fprintf(stderr
, "Total of %d planar tiles written to %s.\n", tilecount
,
208 NETHACK_OVERVIEW_TILEFILE
);
213 tibheader
.tilestyle
= PACKED_STYLE
;
214 write_tibheader(tibfile2
, &tibheader
);
215 Fprintf(stderr
, "Total of %d packed tiles written to %s.\n", tilecount
,
216 NETHACK_PACKED_TILEFILE
);
217 (void) fclose(tibfile2
);
226 write_tibheader(fileptr
, tibhdr
)
228 struct tibhdr_struct
*tibhdr
;
230 if (fseek(fileptr
, 0L, SEEK_SET
)) {
231 Fprintf(stderr
, "Error writing header to tile file\n");
233 fwrite(tibhdr
, sizeof(struct tibhdr_struct
), 1, fileptr
);
237 build_tibtile(pixels
, statues
)
238 pixel (*pixels
)[TILE_X
];
241 static int graymappings
[] = {
242 /* . A B C D E F G H I J K L M N O P */
243 0, 1, 17, 18, 19, 20, 27, 22, 23, 24, 25, 26, 21, 15, 13, 14, 14
246 unsigned char co_mask
, tmp
;
249 #ifndef OVERVIEW_FILE
250 memset((void *) &planetile
, 0, sizeof(struct planar_cell_struct
));
252 memset((void *) &planetile
, 0,
253 sizeof(struct overview_planar_cell_struct
));
256 for (j
= 0; j
< TILE_Y
; j
++) {
257 for (i
= 0; i
< TILE_X
; i
++) {
258 for (k
= 0; k
< num_colors
; k
++) {
259 if (ColorMap
[CM_RED
][k
] == pixels
[j
][i
].r
260 && ColorMap
[CM_GREEN
][k
] == pixels
[j
][i
].g
261 && ColorMap
[CM_BLUE
][k
] == pixels
[j
][i
].b
)
265 Fprintf(stderr
, "color not in colormap!\n");
271 } else if (k
== 13) {
282 co_mask
= masktable
[i
- 8];
285 co_mask
= masktable
[i
];
293 fprintf(stderr
, "Warning: pixel value %d in 16 color bitmap\n", k
);
296 tmp
= planetile
.plane
[0].image
[j
][co_off
];
297 planetile
.plane
[0].image
[j
][co_off
] =
298 (k
& 0x0008) ? (tmp
| co_mask
) : (tmp
& ~co_mask
);
300 tmp
= planetile
.plane
[1].image
[j
][co_off
];
301 planetile
.plane
[1].image
[j
][co_off
] =
302 (k
& 0x0004) ? (tmp
| co_mask
) : (tmp
& ~co_mask
);
304 tmp
= planetile
.plane
[2].image
[j
][co_off
];
305 planetile
.plane
[2].image
[j
][co_off
] =
306 (k
& 0x0002) ? (tmp
| co_mask
) : (tmp
& ~co_mask
);
308 tmp
= planetile
.plane
[3].image
[j
][co_off
];
309 planetile
.plane
[3].image
[j
][co_off
] =
310 (k
& 0x0001) ? (tmp
| co_mask
) : (tmp
& ~co_mask
);
311 #endif /* PLANAR_FILE */
317 write_tibtile(recnum
)
323 #ifndef OVERVIEW_FILE
324 fpos
= ((long) (recnum
) * (long) sizeof(struct planar_cell_struct
))
325 + (long) TIBHEADER_SIZE
;
328 ((long) (recnum
) * (long) sizeof(struct overview_planar_cell_struct
))
329 + (long) TIBHEADER_SIZE
;
331 if (fseek(tibfile1
, fpos
, SEEK_SET
)) {
332 Fprintf(stderr
, "Error seeking before planar tile write %d\n",
335 #ifndef OVERVIEW_FILE
336 fwrite(&planetile
, sizeof(struct planar_cell_struct
), 1, tibfile1
);
338 fwrite(&planetile
, sizeof(struct overview_planar_cell_struct
), 1,
345 ((long) (recnum
) * (long) sizeof(packtile
)) + (long) TIBHEADER_SIZE
;
346 if (fseek(tibfile2
, fpos
, SEEK_SET
)) {
347 Fprintf(stderr
, "Error seeking before packed tile write %d\n",
350 fwrite(&packtile
, sizeof(packtile
), 1, tibfile2
);
359 swap
= ColorMap
[CM_RED
][13];
360 ColorMap
[CM_RED
][13] = ColorMap
[CM_RED
][16];
361 ColorMap
[CM_RED
][16] = swap
;
362 swap
= ColorMap
[CM_GREEN
][13];
363 ColorMap
[CM_GREEN
][13] = ColorMap
[CM_GREEN
][16];
364 ColorMap
[CM_GREEN
][16] = swap
;
365 swap
= ColorMap
[CM_BLUE
][13];
366 ColorMap
[CM_BLUE
][13] = ColorMap
[CM_BLUE
][16];
367 ColorMap
[CM_BLUE
][16] = swap
;