-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvmap7.c
397 lines (349 loc) · 9.76 KB
/
convmap7.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
// "Build Engine & Tools" Copyright (c) 1993-1997 Ken Silverman
// Ken Silverman's official web site: "http://www.advsys.net/ken"
// See the included license file "BUILDLIC.TXT" for license info.
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#ifdef PLATFORM_DOS
#include <io.h>
#include <sys\types.h>
#include <sys\stat.h>
#include <dos.h>
#include "dos_compat.h"
#else
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "unix_compat.h"
#endif
#define NEWMAPVERSION 7
#define MAXMENUFILES 1024
#define MAXSECTORS 1024
#define MAXWALLS 8192
#define MAXSPRITES 4096
#define MAXSTATUS 1024
#define MAXTILES 4096
static char menuname[MAXMENUFILES][32];
static long menunamecnt;
#ifdef PLATFORM_DOS
#pragma pack(push,1);
#endif
typedef struct
{
unsigned short wallptr, wallnum;
short ceilingpicnum, floorpicnum;
short ceilingheinum, floorheinum;
long ceilingz, floorz;
signed char ceilingshade, floorshade;
char ceilingxpanning, floorxpanning;
char ceilingypanning, floorypanning;
char ceilingstat, floorstat;
char ceilingpal, floorpal;
char visibility;
short lotag, hitag, extra;
} sectortype;
typedef struct
{
long x, y;
short point2, nextsector, nextwall;
short picnum, overpicnum;
signed char shade;
char pal;
short cstat;
unsigned char xrepeat, yrepeat, xpanning, ypanning;
short lotag, hitag, extra;
} walltype;
typedef struct
{
long x, y, z;
short cstat;
signed char shade;
char pal, clipdist;
unsigned char xrepeat, yrepeat;
signed char xoffset, yoffset;
short picnum, ang, xvel, yvel, zvel, owner;
short sectnum, statnum;
short lotag, hitag, extra;
} spritetype;
//40 bytes
typedef struct
{
short wallptr, wallnum;
long ceilingz, floorz;
short ceilingstat, floorstat;
short ceilingpicnum, ceilingheinum;
signed char ceilingshade;
char ceilingpal, ceilingxpanning, ceilingypanning;
short floorpicnum, floorheinum;
signed char floorshade;
char floorpal, floorxpanning, floorypanning;
char visibility, filler;
short lotag, hitag, extra;
} newsectortype;
//32 bytes
typedef struct
{
long x, y;
short point2, nextwall, nextsector, cstat;
short picnum, overpicnum;
signed char shade;
char pal, xrepeat, yrepeat, xpanning, ypanning;
short lotag, hitag, extra;
} newwalltype;
//44 bytes
typedef struct
{
long x, y, z;
short cstat, picnum;
signed char shade;
char pal, clipdist, filler;
unsigned char xrepeat, yrepeat;
signed char xoffset, yoffset;
short sectnum, statnum;
short ang, owner, xvel, yvel, zvel;
short lotag, hitag, extra;
} newspritetype;
#ifdef PLATFORM_DOS
#pragma pack(pop);
#endif
//**************************************************************************
static sectortype sector[MAXSECTORS];
static walltype wall[MAXWALLS];
static spritetype sprite[MAXSPRITES];
static newsectortype newsector[MAXSECTORS];
static newwalltype newwall[MAXWALLS];
static newspritetype newsprite[MAXSPRITES];
static long posx, posy, posz, mapversion;
static short ang, cursectnum, numsectors, numwalls, numsprites;
// Function definitions
void convmap(char *filename);
int loadoldboard(char *filename);
int savenewboard(char *filename);
int getfilenames(char *kind);
void sortfilenames(void);
int main(int argc, char **argv)
{
long i;
if (argc != 2)
{
printf("CONVMAP%d [filespec] by Ken Silverman\n",NEWMAPVERSION);
printf("This CONVMAP%d.EXE converts map version %d to map version %d\n",NEWMAPVERSION,NEWMAPVERSION-1,NEWMAPVERSION);
exit(0);
}
menunamecnt = 0;
getfilenames(argv[1]);
sortfilenames();
if (menunamecnt == 0)
{
printf("CONVMAP%d [filespec] by Ken Silverman\n",NEWMAPVERSION);
printf("This CONVMAP%d.EXE converts map version %d to map version %d\n",NEWMAPVERSION,NEWMAPVERSION-1,NEWMAPVERSION);
printf("File not found\n");
exit(0);
}
printf("Converting map version %d to map version %d\n",NEWMAPVERSION-1,NEWMAPVERSION);
for(i=0;i<menunamecnt;i++)
convmap(menuname[i]);
return(0);
}
void convmap(char *filename)
{
long i;
if (strchr(filename,'.') == 0) strcat(filename,".map");
if ((i = loadoldboard(filename)) < 0)
{
if (i == -1)
{
printf("%s not found.\n",filename);
}
if (i == -2)
{
if (mapversion == NEWMAPVERSION)
printf("%s already map version %d.\n",filename,NEWMAPVERSION);
else
printf("CANNOT CONVERT %s!\n",filename);
}
return;
}
for(i=0;i<numsectors;i++)
{
newsector[i].ceilingz = sector[i].ceilingz;
newsector[i].floorz = sector[i].floorz;
newsector[i].wallptr = sector[i].wallptr;
newsector[i].wallnum = sector[i].wallnum;
newsector[i].ceilingpicnum = sector[i].ceilingpicnum;
newsector[i].ceilingheinum = max(min(((long)sector[i].ceilingheinum)<<5,32767),-32768);
if ((sector[i].ceilingstat&2) == 0) newsector[i].ceilingheinum = 0;
newsector[i].ceilingshade = sector[i].ceilingshade;
newsector[i].ceilingpal = sector[i].ceilingpal;
newsector[i].ceilingxpanning = sector[i].ceilingxpanning;
newsector[i].ceilingypanning = sector[i].ceilingypanning;
newsector[i].floorpicnum = sector[i].floorpicnum;
newsector[i].floorheinum = max(min(((long)sector[i].floorheinum)<<5,32767),-32768);
if ((sector[i].floorstat&2) == 0) newsector[i].floorheinum = 0;
newsector[i].floorshade = sector[i].floorshade;
newsector[i].floorpal = sector[i].floorpal;
newsector[i].floorxpanning = sector[i].floorxpanning;
newsector[i].floorypanning = sector[i].floorypanning;
newsector[i].ceilingstat = sector[i].ceilingstat;
newsector[i].floorstat = sector[i].floorstat;
newsector[i].visibility = sector[i].visibility;
newsector[i].filler = 0;
newsector[i].lotag = sector[i].lotag;
newsector[i].hitag = sector[i].hitag;
newsector[i].extra = sector[i].extra;
}
for(i=0;i<numwalls;i++)
{
newwall[i].x = wall[i].x;
newwall[i].y = wall[i].y;
newwall[i].point2 = wall[i].point2;
newwall[i].nextwall = wall[i].nextwall;
newwall[i].nextsector = wall[i].nextsector;
newwall[i].cstat = wall[i].cstat;
newwall[i].picnum = wall[i].picnum;
newwall[i].overpicnum = wall[i].overpicnum;
newwall[i].shade = wall[i].shade;
newwall[i].pal = wall[i].pal;
newwall[i].xrepeat = wall[i].xrepeat;
newwall[i].yrepeat = wall[i].yrepeat;
newwall[i].xpanning = wall[i].xpanning;
newwall[i].ypanning = wall[i].ypanning;
newwall[i].lotag = wall[i].lotag;
newwall[i].hitag = wall[i].hitag;
newwall[i].extra = wall[i].extra;
}
for(i=0;i<numsprites;i++)
{
newsprite[i].x = sprite[i].x;
newsprite[i].y = sprite[i].y;
newsprite[i].z = sprite[i].z;
newsprite[i].cstat = sprite[i].cstat;
newsprite[i].picnum = sprite[i].picnum;
newsprite[i].shade = sprite[i].shade;
newsprite[i].pal = sprite[i].pal;
newsprite[i].clipdist = sprite[i].clipdist;
newsprite[i].filler = 0;
newsprite[i].xrepeat = sprite[i].xrepeat;
newsprite[i].yrepeat = sprite[i].yrepeat;
newsprite[i].xoffset = sprite[i].xoffset;
newsprite[i].yoffset = sprite[i].yoffset;
newsprite[i].sectnum = sprite[i].sectnum;
newsprite[i].statnum = sprite[i].statnum;
newsprite[i].ang = sprite[i].ang;
newsprite[i].owner = sprite[i].owner;
newsprite[i].xvel = sprite[i].xvel;
newsprite[i].yvel = sprite[i].yvel;
newsprite[i].zvel = sprite[i].zvel;
newsprite[i].lotag = sprite[i].lotag;
newsprite[i].hitag = sprite[i].hitag;
newsprite[i].extra = sprite[i].extra;
}
mapversion = NEWMAPVERSION;
if (savenewboard(filename) == 0)
printf("%s successfully converted.\n",filename);
else
printf("%s NOT converted for some stupid reason.\n",filename);
}
int loadoldboard(char *filename)
{
long fil;
if ((fil = open(filename,O_BINARY|O_RDWR,S_IREAD)) == -1)
return(-1);
read(fil,&mapversion,4);
if (mapversion != NEWMAPVERSION-1)
{
close(fil);
return(-2);
}
read(fil,&posx,4);
read(fil,&posy,4);
read(fil,&posz,4);
read(fil,&ang,2);
read(fil,&cursectnum,2);
read(fil,&numsectors,2);
read(fil,§or[0],sizeof(sectortype)*numsectors);
read(fil,&numwalls,2);
read(fil,&wall[0],sizeof(walltype)*numwalls);
read(fil,&numsprites,2);
read(fil,&sprite[0],sizeof(spritetype)*numsprites);
close(fil);
return(0);
}
int savenewboard(char *filename)
{
long fil;
if ((fil = open(filename,O_BINARY|O_TRUNC|O_CREAT|O_WRONLY,UC_PERMS)) == -1)
return(-1);
//Version control
write(fil,&mapversion,4);
//Starting position
write(fil,&posx,4);
write(fil,&posy,4);
write(fil,&posz,4);
write(fil,&ang,2);
write(fil,&cursectnum,2);
//Sectors
write(fil,&numsectors,2);
write(fil,&newsector[0],sizeof(newsectortype)*numsectors);
//Walls
write(fil,&numwalls,2);
write(fil,&newwall[0],sizeof(newwalltype)*numwalls);
//Sprites
write(fil,&numsprites,2);
write(fil,&newsprite[0],sizeof(newspritetype)*numsprites);
close(fil);
return(0);
}
int getfilenames(char *kind)
{
short type;
struct find_t fileinfo;
if (strcmp(kind,"SUBD") == 0)
{
strcpy(kind,"*.*");
if (_dos_findfirst(kind,_A_SUBDIR,&fileinfo) != 0)
return(-1);
type = 1;
}
else
{
if (_dos_findfirst(kind,_A_NORMAL,&fileinfo) != 0)
return(-1);
type = 0;
}
do
{
if ((type == 0) || ((fileinfo.attrib&16) > 0))
if ((fileinfo.name[0] != '.') || (fileinfo.name[1] != 0))
{
if (menunamecnt < MAXMENUFILES)
{
strcpy(menuname[menunamecnt],fileinfo.name);
menuname[menunamecnt][16] = type;
menunamecnt++;
}
//else
// printmessage("Too many files! (max=MAXMENUFILES)");
}
}
while (_dos_findnext(&fileinfo) == 0);
return(0);
}
void sortfilenames(void)
{
char sortbuffer[32];
long i, j, k;
for(i=1;i<menunamecnt;i++)
for(j=0;j<i;j++)
{
k = 0;
while ((menuname[i][k] == menuname[j][k]) && (menuname[i][k] != 0) && (menuname[j][k] != 0))
k++;
if (menuname[i][k] < menuname[j][k])
{
memcpy(&sortbuffer[0],&menuname[i][0],sizeof(menuname[0]));
memcpy(&menuname[i][0],&menuname[j][0],sizeof(menuname[0]));
memcpy(&menuname[j][0],&sortbuffer[0],sizeof(menuname[0]));
}
}
}