-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.c
More file actions
6935 lines (6272 loc) · 184 KB
/
build.c
File metadata and controls
6935 lines (6272 loc) · 184 KB
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
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* "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.
* This file has been modified from Ken Silverman's original release
*/
/**@file build.c
* @brief master build editor source file
*
* The main implementation file for the Build Editor.
*
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "engine.h"
#include "platform.h"
#include "build.h"
#include "pragmas.h"
#include "display.h"
#include "bstub.h"
/*
#if !defined (getch) && defined(PLATFORM_UNIX)
#define getch getchar
#endif
*/
#define MAXMENUFILES 256
#define updatecrc16(crc,dat) (crc = (((crc<<8)&65535)^crctable[((((unsigned short)crc)>>8)&65535)^dat]))
static long crctable[256];
static char kensig[24];
#define KEYFIFOSIZ 64
volatile unsigned char keystatus[256]; /* Which keys on the keyboard are pressed? */
static volatile unsigned char keyfifo[KEYFIFOSIZ], keyfifoplc, keyfifoend;
static volatile unsigned char readch, oldreadch, extended, keytemp;
long vel; /* Camera Velocity in Forward-Backward direction */
long svel; /* Camera Velocity in Left-Right direction */
long angvel; /* Camera Velocity in Angular Spin */
#define NUMKEYS 19
unsigned char buildkeys[NUMKEYS] =
{
0xc8,0xd0,0xcb,0xcd,0x2a,0x9d,0x1d,0x39,
0x1e,0x2c,0xd1,0xc9,0x33,0x34,
0x9c,0x1c,0xd,0xc,0xf,
};
/* Or, in plain english, for those of us who don't speak keyboard:
unsigned char buildkeys[NUMKEYS] =
{
[UP]-released,[DOWN]-released,[LEFT]-released,[RIGHT]-released,[L.SHIFT]-pushed,[R.CTRL]-pushed,[L.CTRL]-pushed,[SPACE]-pushed,
[A]-pressed,[Z]-pressed,[PgDn]-released,[PgUp]-released,[,|<]-pressed,[.|>]-pressed,
[KPEnter]-pressed,[ENTER]-pressed,[+|=]-pressed,[-|_]-pressed,[TAB]-pressed,
};
-------------------
BUILD KEYS:
00 = Up arrow
01 = Down arrow
02 = Left arrow
03 = Right arrow
04 = Left Shift key
05 = Right Ctrl key
06 = Left Ctrl key
07 = Space
08 = A
09 = Z
10 = PageDown
11 = PageUp
12 = <
13 = >
14 = Keypad Enter
15 = Enter
16 = +
17 = -
18 = Tab
-------------------
*/
long posx; /* The camera's X position (east travel is positive, west travel negative. */
long posy; /* The camera's Y position (north travel is negative, south travel positive. */
long posz; /* The camera's Z position (upwards travel is negative, downwards travel positive. */
long horiz = 100;
short ang; /* The angle the camera is facing */
short cursectnum; /* The sector the camera is in currently. */
long hvel; /* The Z velocity of the camera, used for jumping in gravity mode. */
/* -512 is the starting value when you jump in gravity mode. */
static long synctics = 0, lockclock = 0;
extern volatile long stereomode;
extern char vgacompatible;
extern char picsiz[MAXTILES];
extern long startposx, startposy, startposz;
extern short startang, startsectnum;
extern long frameplace, pageoffset, ydim16;
extern long cachesize, artsize;
static short oldmousebstatus = 0, brightness = 0;
long zlock = 0x7fffffff, zmode = 0, whitecol, kensplayerheight = 32;
short defaultspritecstat = 0;
static short localartfreq[MAXTILES]; /* This is used to calculate the number of occurences of a tile
in the map, used mainly in the 3d tile picker (key V in 3D mode.) */
static short localartlookup[MAXTILES], localartlookupnum;
char tempbuf[4096];
char names[MAXTILES][17]; /* Reserve 17 characters to name each tile. (Names come from names.h.) */
short asksave = 0; /* Will be 1 if there are unsaved changes, 0 otherwise. */
extern short editstatus, searchit;
extern long searchx, searchy; /* search input */
extern short searchsector, searchwall, searchstat; /* search output */
extern short pointhighlight, linehighlight, highlightcnt;
/* Initial Status of Editor */
short grid = 3; /* Initial Grid Size is 3. */
short gridlock = 1; /* Grid Locking is On. */
short showtags = 1; /* Sector/Sprite/Wall labels is On. */
long zoom = 768; /* Initial Zoom factor is 768. */
long gettilezoom = 1;
int numsprites;
short highlight[MAXWALLS];
short highlightsector[MAXSECTORS], highlightsectorcnt = -1;
/*extern char textfont[128][8];*/
static char pskysearch[MAXSECTORS];
short temppicnum, tempcstat, templotag, temphitag, tempextra;
char tempshade, temppal, tempvis, tempxrepeat, tempyrepeat;
char somethingintab = 255;
static char boardfilename[13], oboardfilename[13];
static long repeatcountx, repeatcounty;
#define BUILD_MAXPATH 255
static char menuname[MAXMENUFILES][BUILD_MAXPATH+1], curpath[80], menupath[80];
static long menunamecnt, menuhighlight;
static long fillist[640];
static char scantoasc[128] =
{
0,0,'1','2','3','4','5','6','7','8','9','0','-','=',0,0,
'q','w','e','r','t','y','u','i','o','p','[',']',0,0,'a','s',
'd','f','g','h','j','k','l',';',39,'`',0,92,'z','x','c','v',
'b','n','m',',','.','/',0,'*',0,32,0,0,0,0,0,0,
0,0,0,0,0,0,0,'7','8','9','-','4','5','6','+','1',
'2','3','0','.',0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
};
static char scantoascwithshift[128] =
{
0,0,'!','@','#','$','%','^','&','*','(',')','_','+',0,0,
'Q','W','E','R','T','Y','U','I','O','P','{','}',0,0,'A','S',
'D','F','G','H','J','K','L',':',34,'~',0,'|','Z','X','C','V',
'B','N','M','<','>','?',0,'*',0,32,0,0,0,0,0,0,
0,0,0,0,0,0,0,'7','8','9','-','4','5','6','+','1',
'2','3','0','.',0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
};
/**@brief Build Movement and Accelleration routine
*
* This code handles the default turning, walking, and strafing actions.
* This function acts on buildkeys[] 0, 1, 2, 3, 5, 12, and 13.
*/
void keytimerstuff(void)
{
/* Turn and strafe with the left and right arrow keys. */
if (keystatus[buildkeys[5]] == 0) /* Is [R.Ctrl] down? */
{
/* No, it isn't, we want to turn. */
if (keystatus[buildkeys[2]] > 0) angvel = max(angvel-16,-128);
if (keystatus[buildkeys[3]] > 0) angvel = min(angvel+16,127);
}
else
{
/* Yes, it is, we want to strafe. */
if (keystatus[buildkeys[2]] > 0) svel = min(svel+8,127);
if (keystatus[buildkeys[3]] > 0) svel = max(svel-8,-128);
}
/* Move Forward */
if (keystatus[buildkeys[0]] > 0) vel = min(vel+8,127);
/* Move Backward */
if (keystatus[buildkeys[1]] > 0) vel = max(vel-8,-128);
/* Use the [<] and [>] keys to strafe, too. */
if (keystatus[buildkeys[12]] > 0) svel = min(svel+8,127);
if (keystatus[buildkeys[13]] > 0) svel = max(svel-8,-128);
/* Accelleration Limiter for Movement */
if (angvel < 0) angvel = min(angvel+12,0);
if (angvel > 0) angvel = max(angvel-12,0);
if (svel < 0) svel = min(svel+2,0);
if (svel > 0) svel = max(svel-2,0);
if (vel < 0) vel = min(vel+2,0);
if (vel > 0) vel = max(vel-2,0);
}
void __interrupt __far timerhandler(void)
{
totalclock++;
keytimerstuff();
#ifdef PLATFORM_DOS
outp(0x20,0x20);
#endif
}
void __interrupt __far keyhandler(void)
{
/*
* ryan sez: End Of Interrupt call on DOS. This seems like a
* dangerous place to put it, if you ask me, but oh well. --ryan.
*/
#ifdef PLATFORM_DOS
koutp(0x20,0x20);
#endif
oldreadch = readch; readch = _readlastkeyhit();
#if 0
printf("keyhandler() got a (0x%X) ... \n", readch);
#endif
/*
* ryan sez: these inp/outp calls read the keyboard state,
* reset the keyboard, and put the original state back in.
* This is apparently needed on some XTs, but not newer boxes, and
* obviously never on Linux. --ryan.
*/
#ifdef PLATFORM_DOS
keytemp = kinp(0x61); koutp(0x61,keytemp|128); koutp(0x61,keytemp&127);
#else
keytemp = readch;
#endif
if ((readch|1) == 0xe1) { extended = 128; return; }
if (oldreadch != readch)
{
if ((readch&128) == 0)
{
keytemp = readch+extended;
if (keystatus[keytemp] == 0)
{
keystatus[keytemp] = 1;
keyfifo[keyfifoend] = keytemp;
keyfifo[(keyfifoend+1)&(KEYFIFOSIZ-1)] = 1;
keyfifoend = ((keyfifoend+2)&(KEYFIFOSIZ-1));
}
}
else
{
keytemp = (readch&127)+extended;
keystatus[keytemp] = 0;
keyfifo[keyfifoend] = keytemp;
keyfifo[(keyfifoend+1)&(KEYFIFOSIZ-1)] = 0;
keyfifoend = ((keyfifoend+2)&(KEYFIFOSIZ-1));
}
}
extended = 0;
}
static void _initkeys(void)
{
long i;
keyfifoplc = 0; keyfifoend = 0;
for(i=0;i<256;i++) keystatus[i] = 0;
initkeys(); /* rcg06082001 platform driver-specific initialization. */
}
#define loadbyte(fil,tempbuf,bufplc,dat) \
{ \
if (bufplc == 0) \
{ \
for(bufplc=0;bufplc<4096;bufplc++) \
tempbuf[bufplc] = 0; \
bufplc = 0; \
read(fil,tempbuf,4096); \
} \
dat = tempbuf[bufplc]; \
bufplc = ((bufplc+1)&4095); \
} \
/**@brief Load Tile Names from names.h
*
* This function will load the names of special tiles into names[],
* provided the file names.h is in the current directory.
* @return -1 on failure, 0 on success.
*/
int loadnames(void)
{
char buffer[80], firstch, ch;
long fil, i, num, buffercnt, bufplc;
if ((fil = open("names.h",O_BINARY|O_RDWR,S_IREAD)) == -1) return(-1);
bufplc = 0;
do { loadbyte(fil,tempbuf,bufplc,firstch); } while (firstch != '#');
while ((firstch == '#') || (firstch == '/'))
{
do { loadbyte(fil,tempbuf,bufplc,ch); } while (ch > 32);
buffercnt = 0;
do
{
loadbyte(fil,tempbuf,bufplc,ch);
if (ch > 32) buffer[buffercnt++] = ch;
}
while (ch > 32);
num = 0;
do
{
loadbyte(fil,tempbuf,bufplc,ch);
if ((ch >= 48) && (ch <= 57)) num = num*10+(ch-48);
}
while ((ch != '\r') && (ch != '\n'));
for(i=0;i<buffercnt;i++) names[num][i] = buffer[i];
names[num][buffercnt] = 0;
loadbyte(fil,tempbuf,bufplc,firstch);
while ((firstch == '\r') || (firstch == '\n'))
loadbyte(fil,tempbuf,bufplc,firstch);
}
close(fil);
return(0);
}
static void initcrc(void)
{
long i, j, k, a;
for(j=0;j<256;j++) /* Calculate CRC table */
{
k = (j<<8); a = 0;
for(i=7;i>=0;i--)
{
if (((k^a)&0x8000) > 0)
a = ((a<<1)&65535) ^ 0x1021; /* 0x1021 = genpoly */
else
a = ((a<<1)&65535);
k = ((k<<1)&65535);
}
crctable[j] = (a&65535);
}
}
void initmenupaths(char *filename)
{
long i;
strcpy(curpath,filename);
i = 0;
while ((i < 80) && (curpath[i] != 0)) i++;
while ((i > 0) && (curpath[i] != 92)) i--;
curpath[i] = 0;
strcpy(menupath,curpath);
}
/**@brief Draw the mouse in 3D mode.
*
* This function will draw the white 3D mode cursor at
* the location [searchx, searchy].
* (The mouse routine should set these automatically.)
*/
void showmouse(void)
{
long i;
for(i=1;i<=4;i++)
{
plotpixel(searchx+i,searchy,whitecol);
plotpixel(searchx-i,searchy,whitecol);
plotpixel(searchx,searchy-i,whitecol);
plotpixel(searchx,searchy+i,whitecol);
}
}
void fixrepeats(short i)
{
long dax, day, dist;
dax = wall[wall[i].point2].x-wall[i].x;
day = wall[wall[i].point2].y-wall[i].y;
dist = ksqrt(dax*dax+day*day);
dax = wall[i].xrepeat; day = wall[i].yrepeat;
wall[i].xrepeat = (char)min(max(mulscale10(dist,day),1),255);
}
/**@brief Show the tile picker.
*
* This function will show the tile picker and let the user change a tile.
* @param tilenum The current tile (what to return if the user cancels.)
* @return The new user-selected tile.
* @remark Notes:
* Make sure you set searchstat for the right situation if you call this function yourself:
* 0: Wall tile
* 1 or 2: Ceiling or Floor tile.
* 3: Sprite
* 4: Wall Above tile (overpic) --
*
*/
long gettile(long tilenum)
{
char snotbuf[80];
long i, j, k, otilenum, topleft, gap, temp, templong;
long xtiles; /* Number of tiles that will fit horizontally on the screen. */
long ytiles; /* Number of tiles that will fit vertically on the screen. */
long tottiles; /* Total tiles that fit on the screen at once. */
/* Calculate how the tiles fit, given the tile previews are 32 pixels wide and tall. */
xtiles = (xdim>>6); ytiles = (ydim>>6); tottiles = xtiles*ytiles;
otilenum = tilenum; /* Back up the old value, in case the user cancels. */
keystatus[0x2f] = 0; /* Clear [V] */
/* Recalculate the tile occurance stats for the "choose commonly used tile" screen. */
for(i=0;i<MAXTILES;i++)
{
localartfreq[i] = 0;
localartlookup[i] = i;
}
if ((searchstat == 1) || (searchstat == 2))
for(i=0;i<numsectors;i++)
{
localartfreq[sector[i].ceilingpicnum]++;
localartfreq[sector[i].floorpicnum]++;
}
if (searchstat == 0)
for(i=0;i<numwalls;i++)
localartfreq[wall[i].picnum]++;
if (searchstat == 4)
for(i=0;i<numwalls;i++)
localartfreq[wall[i].overpicnum]++;
if (searchstat == 3)
for(i=0;i<MAXSPRITES;i++)
if (sprite[i].statnum < MAXSTATUS)
localartfreq[sprite[i].picnum]++;
gap = (MAXTILES>>1);
do
{
for(i=0;i<MAXTILES-gap;i++)
{
temp = i;
while ((localartfreq[temp] < localartfreq[temp+gap]) && (temp >= 0))
{
templong = localartfreq[temp];
localartfreq[temp] = localartfreq[temp+gap];
localartfreq[temp+gap] = templong;
templong = localartlookup[temp];
localartlookup[temp] = localartlookup[temp+gap];
localartlookup[temp+gap] = templong;
if (tilenum == temp)
tilenum = temp+gap;
else if (tilenum == temp+gap)
tilenum = temp;
temp -= gap;
}
}
gap >>= 1;
}
while (gap > 0);
localartlookupnum = 0;
while (localartfreq[localartlookupnum] > 0)
localartlookupnum++;
if (localartfreq[0] == 0)
{
tilenum = otilenum;
localartlookupnum = MAXTILES;
for(i=0;i<MAXTILES;i++)
localartlookup[i] = i;
}
topleft = ((tilenum/(xtiles<<gettilezoom))*(xtiles<<gettilezoom))-(xtiles<<gettilezoom);
if (topleft < 0) topleft = 0;
if (topleft > MAXTILES-(tottiles<<(gettilezoom<<1))) topleft = MAXTILES-(tottiles<<(gettilezoom<<1));
while ((keystatus[0x1c]|keystatus[1]) == 0)
{
drawtilescreen(topleft,tilenum);
if ((vidoption != 2) && ((vidoption != 1) || (vgacompatible == 1))) limitrate();
nextpage();
synctics = totalclock-lockclock;
lockclock += synctics;
if ((keystatus[0x37] > 0) && (gettilezoom < 2))
{
gettilezoom++;
topleft = ((tilenum/(xtiles<<gettilezoom))*(xtiles<<gettilezoom))-(xtiles<<gettilezoom);
if (topleft < 0) topleft = 0;
if (topleft > MAXTILES-(tottiles<<(gettilezoom<<1))) topleft = MAXTILES-(tottiles<<(gettilezoom<<1));
keystatus[0x37] = 0;
}
if ((keystatus[0xb5] > 0) && (gettilezoom > 0))
{
gettilezoom--;
topleft = ((tilenum/(xtiles<<gettilezoom))*(xtiles<<gettilezoom))-(xtiles<<gettilezoom);
if (topleft < 0) topleft = 0;
if (topleft > MAXTILES-(tottiles<<(gettilezoom<<1))) topleft = MAXTILES-(tottiles<<(gettilezoom<<1));
keystatus[0xb5] = 0;
}
if ((keystatus[0xcb] > 0) && (tilenum > 0))
tilenum--, keystatus[0xcb] = 0;
if ((keystatus[0xcd] > 0) && (tilenum < MAXTILES-1))
tilenum++, keystatus[0xcd] = 0;
if ((keystatus[0xc8] > 0) && (tilenum >= (xtiles<<gettilezoom)))
tilenum-=(xtiles<<gettilezoom), keystatus[0xc8] = 0;
if ((keystatus[0xd0] > 0) && (tilenum < MAXTILES-(xtiles<<gettilezoom)))
tilenum+=(xtiles<<gettilezoom), keystatus[0xd0] = 0;
if ((keystatus[0xc9] > 0) && (tilenum >= (xtiles<<gettilezoom)))
{
tilenum-=(tottiles<<(gettilezoom<<1));
if (tilenum < 0) tilenum = 0;
keystatus[0xc9] = 0;
}
if ((keystatus[0xd1] > 0) && (tilenum < MAXTILES-(xtiles<<gettilezoom)))
{
tilenum+=(tottiles<<(gettilezoom<<1));
if (tilenum >= MAXTILES) tilenum = MAXTILES-1;
keystatus[0xd1] = 0;
}
if (keystatus[0x2f] > 0) /* V */
{
keystatus[0x2f] = 0;
if (tilenum < localartlookupnum)
tilenum = localartlookup[tilenum];
else
tilenum = 0;
localartlookupnum = MAXTILES;
for(i=0;i<MAXTILES;i++)
localartlookup[i] = i;
}
if (keystatus[0x22] > 0) /* G (goto) */
{
if (tilenum < localartlookupnum) /* Automatically press 'V' */
tilenum = localartlookup[tilenum];
else
tilenum = 0;
localartlookupnum = MAXTILES;
for(i=0;i<MAXTILES;i++)
localartlookup[i] = i;
keystatus[0x22] = 0;
j = tilenum;
while (keystatus[1] == 0)
{
drawtilescreen(topleft,tilenum);
if ((vidoption != 2) && ((vidoption != 1) || (vgacompatible == 1))) limitrate();
sprintf(snotbuf,"Goto tile: %ld_ ",j);
printext256(0,0,whitecol,0,snotbuf,0);
nextpage();
for(k=0;k<10;k++)
if (keystatus[((k+9)%10)+2] > 0)
{
keystatus[((k+9)%10)+2] = 0;
i = (j*10)+k;
if (i < MAXTILES) j = i;
}
if (keystatus[0xe] > 0)
{
keystatus[0xe] = 0;
j /= 10;
}
if (keystatus[0x1c] > 0)
{
keystatus[0x1c] = 0;
tilenum = j;
break;
}
}
}
while (tilenum < topleft) topleft -= (xtiles<<gettilezoom);
while (tilenum >= topleft+(tottiles<<(gettilezoom<<1))) topleft += (xtiles<<gettilezoom);
if (topleft < 0) topleft = 0;
if (topleft > MAXTILES-(tottiles<<(gettilezoom<<1))) topleft = MAXTILES-(tottiles<<(gettilezoom<<1));
}
if (keystatus[0x1c] == 0)
{
tilenum = otilenum;
}
else
{
if (tilenum < localartlookupnum)
{
tilenum = localartlookup[tilenum];
if ((tilesizx[tilenum] == 0) || (tilesizy[tilenum] == 0))
tilenum = otilenum;
}
else
tilenum = otilenum;
}
keystatus[0x1] = 0;
keystatus[0x1c] = 0;
return(tilenum);
}
char changechar(char dachar, long dadir, char smooshyalign, char boundcheck)
{
if (dadir < 0)
{
if ((dachar > 0) || (boundcheck == 0))
{
dachar--;
if (smooshyalign > 0)
dachar = (dachar&0xf8);
}
}
else if (dadir > 0)
{
if ((dachar < 255) || (boundcheck == 0))
{
dachar++;
if (smooshyalign > 0)
{
if (dachar >= 256-8) dachar = 255;
else dachar = ((dachar+7)&0xf8);
}
}
}
return(dachar);
}
static char visited[8192];
long GetWallZPeg(long nWall)
{
long z=0, nSector, nNextSector;
nSector = sectorofwall((short)nWall);
nNextSector = wall[nWall].nextsector;
if (nNextSector == -1)
{
/* 1-sided wall */
if (wall[nWall].cstat&4) z = sector[nSector].floorz;
else z = sector[nSector].ceilingz;
}
else
{
/* 2-sided wall */
if (wall[nWall].cstat&4)
z = sector[nSector].ceilingz;
else
{
if (sector[nNextSector].ceilingz > sector[nSector].ceilingz)
z = sector[nNextSector].ceilingz; /* top step */
if (sector[nNextSector].floorz < sector[nSector].floorz)
z = sector[nNextSector].floorz; /* bottom step */
}
}
return(z);
}
void AlignWalls(long nWall0, long z0, long nWall1, long z1, long nTile)
{
long n;
/* do the x alignment */
wall[nWall1].cstat &= ~0x0108; /* Set to non-flip */
wall[nWall1].xpanning = (char)((wall[nWall0].xpanning+(wall[nWall0].xrepeat<<3))%tilesizx[nTile]);
z1 = GetWallZPeg(nWall1);
for(n=(picsiz[nTile]>>4);((1<<n)<tilesizy[nTile]);n++);
wall[nWall1].yrepeat = wall[nWall0].yrepeat;
wall[nWall1].ypanning = (char)(wall[nWall0].ypanning+(((z1-z0)*wall[nWall0].yrepeat)>>(n+3)));
}
void AutoAlignWalls(long nWall0, long ply)
{
long z0, z1, nTile, nWall1, branch, visible, nNextSector, nSector;
nTile = wall[nWall0].picnum;
branch = 0;
if (ply == 0)
{
/* clear visited bits */
memset(visited,0,sizeof(visited));
visited[nWall0] = 1;
}
z0 = GetWallZPeg(nWall0);
nWall1 = wall[nWall0].point2;
/* loop through walls at this vertex in CCW order */
while (1)
{
/* break if this wall would connect us in a loop */
if (visited[nWall1]) break;
visited[nWall1] = 1;
/* break if reached back of left wall */
if (wall[nWall1].nextwall == nWall0) break;
if (wall[nWall1].picnum == nTile)
{
z1 = GetWallZPeg(nWall1);
visible = 0;
nNextSector = wall[nWall1].nextsector;
if (nNextSector < 0)
visible = 1;
else
{
/* ignore two sided walls that have no visible face */
nSector = wall[wall[nWall1].nextwall].nextsector;
if (getceilzofslope((short)nSector,wall[nWall1].x,wall[nWall1].y) <
getceilzofslope((short)nNextSector,wall[nWall1].x,wall[nWall1].y))
visible = 1;
if (getflorzofslope((short)nSector,wall[nWall1].x,wall[nWall1].y) >
getflorzofslope((short)nNextSector,wall[nWall1].x,wall[nWall1].y))
visible = 1;
}
if (visible)
{
branch++;
AlignWalls(nWall0,z0,nWall1,z1,nTile);
/* if wall was 1-sided, no need to recurse */
if (wall[nWall1].nextwall < 0)
{
nWall0 = nWall1;
z0 = GetWallZPeg(nWall0);
nWall1 = wall[nWall0].point2;
branch = 0;
continue;
}
else
AutoAlignWalls(nWall1,ply+1);
}
}
if (wall[nWall1].nextwall < 0) break;
nWall1 = wall[wall[nWall1].nextwall].point2;
}
}
#if (defined PLATFORM_DOS)
#define statusbar_printext16 printext16
#define statusbar_printext16_noupdate printext16
#else
void statusbar_printext16(long xpos, long ypos, short col, short backcol, char name[82], char fontsize)
{
printext256(xpos, ypos + 336, col, backcol, name, fontsize);
}
void statusbar_printext16_noupdate(long xpos, long ypos, short col, short backcol, char name[82], char fontsize)
{
printext256_noupdate(xpos, ypos + 336, col, backcol, name, fontsize);
}
#endif
void printmessage16(char name[82])
{
char snotbuf[60];
long i;
i = 0;
while ((name[i] != 0) && (i < 54))
{
snotbuf[i] = name[i];
i++;
}
while (i < 54)
{
snotbuf[i] = 32;
i++;
}
snotbuf[54] = 0;
statusbar_printext16(200L, 8L, 0, 6, snotbuf, 0);
}
void printmessage256(char name[82])
{
char snotbuf[40];
long i;
i = 0;
while ((name[i] != 0) && (i < 38))
{
snotbuf[i] = name[i];
i++;
}
while (i < 38)
{
snotbuf[i] = 32;
i++;
}
snotbuf[38] = 0;
printext256(0L,0L,whitecol,0,snotbuf,0);
}
short getnumber16(char namestart[80], short num, long maxnumber)
{
char buffer[80];
long j, k, n, danum, oldnum;
danum = (long) num;
oldnum = danum;
while ((keystatus[0x1c] != 2) && (keystatus[0x1] == 0))
{
sprintf(buffer, "%s%ld_ ", namestart, danum);
printmessage16(buffer);
_idle(); /* rcg06232002 prevent hang while waiting for input. */
for(j=2;j<=11;j++)
if (keystatus[j] > 0)
{
keystatus[j] = 0;
k = j-1;
if (k == 10) k = 0;
n = (danum*10)+k;
if (n < maxnumber) danum = n;
}
if (keystatus[0xe] > 0) /* backspace */
{
danum /= 10;
keystatus[0xe] = 0;
}
if (keystatus[0x1c] == 1)
{
oldnum = danum;
keystatus[0x1c] = 2;
asksave = 1;
}
}
keystatus[0x1c] = 0;
keystatus[0x1] = 0;
return((short)oldnum);
}
short getnumber256(char namestart[80], short num, long maxnumber)
{
char buffer[80];
long j, k, n, danum, oldnum;
danum = (long)num;
oldnum = danum;
while ((keystatus[0x1c] != 2) && (keystatus[0x1] == 0))
{
drawrooms(posx,posy,posz,ang,horiz,cursectnum);
ExtAnalyzeSprites();
drawmasks();
sprintf(buffer,"%s%ld_ ",namestart,danum);
printmessage256(buffer);
nextpage();
for(j=2;j<=11;j++)
if (keystatus[j] > 0)
{
keystatus[j] = 0;
k = j-1;
if (k == 10) k = 0;
n = (danum*10)+k;
if (n < maxnumber) danum = n;
}
if (keystatus[0xe] > 0) /* backspace */
{
danum /= 10;
keystatus[0xe] = 0;
}
if (keystatus[0x1c] == 1)
{
oldnum = danum;
keystatus[0x1c] = 2;
asksave = 1;
}
}
keystatus[0x1c] = 0;
keystatus[0x1] = 0;
lockclock = totalclock; /* Reset timing */
return((short)oldnum);
}
void updatenumsprites(void)
{
long i;
numsprites = 0;
for(i=0;i<MAXSPRITES;i++)
if (sprite[i].statnum < MAXSTATUS)
numsprites++;
}
int getfilenames(char kind[6])
{
/* !!! Visual C? */
#if (defined __WATCOMC__)
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))
{
strcpy(menuname[menunamecnt],fileinfo.name);
menuname[menunamecnt][BUILD_MAXPATH] = type;
menunamecnt++;
}
}
while (_dos_findnext(&fileinfo) == 0);
#elif (defined PLATFORM_UNIX)
DIR *dir;
struct dirent *dent;
struct stat statbuf;
int add_this;
char *ptr = NULL;
int len = 0;
int subdirs = 0;
if (strcmp(kind,"SUBD") == 0)
subdirs = 1;
dir = opendir(".");
if (dir == NULL)
return(-1);
do
{
add_this = 0;
dent = readdir(dir);