-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.c
More file actions
6422 lines (5615 loc) · 194 KB
/
game.c
File metadata and controls
6422 lines (5615 loc) · 194 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
*/
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#ifdef USE_PERL
#include "buildperl.h"
#endif
#include "platform.h"
#include "cache1d.h"
#include "pragmas.h"
#include "display.h"
#include "build.h"
#include "engine.h"
#include "names.h"
#define TIMERINTSPERSECOND PLATFORM_TIMER_HZ
#define MOVESPERSECOND 40
#define TICSPERFRAME 3
#define MOVEFIFOSIZ 256
#define EYEHEIGHT (32<<8) /* Normally (32<<8), (51<<8) to make mirrors happy */
/* KenBuild-specific networking functions. */
void initmultiplayers(char damultioption, char dacomrateoption, char dapriority);
void uninitmultiplayers(void);
void sendlogon(void);
void sendlogoff(void);
short getpacket(short *otherconnectindex, char *bufptr);
void sendpacket(short otherconnectindex, unsigned char *bufptr, short messleng);
int getoutputcirclesize(void);
void waitforeverybody(void);
/*
* Not interested in implementing these sound functions in a
* platform-independent manner for KenBuild. Anyone? --ryan.
*/
#if (defined PLATFORM_DOS)
void initsb(char dadigistat, char damusistat, long dasamplerate,
char danumspeakers, char dabytespersample,
char daintspersec, char daquality);
void uninitsb(void);
int loadsong(char *filename);
void musicon(void);
void musicoff(void);
void wsayfollow(char *dafilename, long dafreq, long davol,
long *daxplc, long *dayplc, char followstat);
void wsay(char *dafilename, long dafreq, long volume1, long volume2);
void preparesndbuf(void);
void setears(long daposx, long daposy, long daxvect, long dayvect);
#else /* stubs for non-DOS platforms... */
#ifndef __FILE__
#define __FILE__ "game.c"
#endif
#ifndef __LINE__
#define __LINE__ -1
#endif
static int audio_disabled = 0;
void initsb(char dadigistat, char damusistat, long dasamplerate,
char danumspeakers, char dabytespersample,
char daintspersec, char daquality)
{
#if 0
audio_disabled = (SDL_Init(SDL_INIT_AUDIO) == -1);
if (audio_disabled)
{
fprintf(stderr, "BUILDSDL: SDL_Init(SDL_INIT_AUDIO) failed!\n");
fprintf(stderr, "BUILDSDL: SDL_GetError() says \"%s\".\n", SDL_GetError());
fprintf(stderr, "BUILDSDL: We'll continue without sound.\n");
audio_disabled = 1;
return;
} /* if */
#else
audio_disabled = 1;
fprintf(stderr, "%s, line %d; initsb(): STUB.\n", __FILE__, __LINE__);
#endif
} /* initsb */
void uninitsb(void)
{
fprintf(stderr, "%s, line %d; uninitsb(): STUB.\n", __FILE__, __LINE__);
} /* uninitsb */
int loadsong(char *filename)
{
fprintf(stderr, "%s, line %d; loadsong(): STUB.\n", __FILE__, __LINE__);
return 0;
} /* loadsong */
void musicon(void)
{
fprintf(stderr, "%s, line %d; musicon(): STUB.\n", __FILE__, __LINE__);
} /* musicon */
void musicoff(void)
{
fprintf(stderr, "%s, line %d; musicoff(): STUB.\n", __FILE__, __LINE__);
} /* musicoff */
void wsayfollow(char *dafilename, long dafreq, long davol,
long *daxplc, long *dayplc, char followstat)
{
fprintf(stderr, "%s, line %d; wsayfollow(): STUB.\n", __FILE__, __LINE__);
} /* wsayfollow */
void wsay(char *dafilename, long dafreq, long volume1, long volume2)
{
fprintf(stderr, "%s, line %d; wsay(): STUB.\n", __FILE__, __LINE__);
} /* wsay */
void preparesndbuf(void)
{
fprintf(stderr,"%s, line %d; preparesndbuf(): STUB.\n", __FILE__, __LINE__);
} /* preparesndbuf */
void setears(long daposx, long daposy, long daxvect, long dayvect)
{
/* fprintf(stderr, "%s, line %d; setears(): STUB.\n", __FILE__, __LINE__); */
} /* setears */
#endif /* !defined PLATFORM_DOS */
/***************************************************************************
KEN'S TAG DEFINITIONS: (Please define your own tags for your games)
sector[?].lotag = 0 Normal sector
sector[?].lotag = 1 If you are on a sector with this tag, then all sectors
with same hi tag as this are operated. Once.
sector[?].lotag = 2 Same as sector[?].tag = 1 but this is retriggable.
sector[?].lotag = 3 A really stupid sector that really does nothing now.
sector[?].lotag = 4 A sector where you are put closer to the floor
(such as the slime in DOOM1.DAT)
sector[?].lotag = 5 A really stupid sector that really does nothing now.
sector[?].lotag = 6 A normal door - instead of pressing D, you tag the
sector with a 6. The reason I make you edit doors
this way is so that can program the doors
yourself.
sector[?].lotag = 7 A door the goes down to open.
sector[?].lotag = 8 A door that opens horizontally in the middle.
sector[?].lotag = 9 A sliding door that opens vertically in the middle.
-Example of the advantages of not using BSP tree.
sector[?].lotag = 10 A warping sector with floor and walls that shade.
sector[?].lotag = 11 A sector with all walls that do X-panning.
sector[?].lotag = 12 A sector with walls using the dragging function.
sector[?].lotag = 13 A sector with some swinging doors in it.
sector[?].lotag = 14 A revolving door sector.
sector[?].lotag = 15 A subway track.
sector[?].lotag = 16 A true double-sliding door.
wall[?].lotag = 0 Normal wall
wall[?].lotag = 1 Y-panning wall
wall[?].lotag = 2 Switch - If you flip it, then all sectors with same hi
tag as this are operated.
wall[?].lotag = 3 Marked wall to detemine starting dir. (sector tag 12)
wall[?].lotag = 4 Mark on the shorter wall closest to the pivot point
of a swinging door. (sector tag 13)
wall[?].lotag = 5 Mark where a subway should stop. (sector tag 15)
wall[?].lotag = 6 Mark for true double-sliding doors (sector tag 16)
wall[?].lotag = 7 Water fountain
wall[?].lotag = 8 Bouncy wall!
sprite[?].lotag = 0 Normal sprite
sprite[?].lotag = 1 If you press space bar on an AL, and the AL is tagged
with a 1, he will turn evil.
sprite[?].lotag = 2 When this sprite is operated, a bomb is shot at its
position.
sprite[?].lotag = 3 Rotating sprite.
sprite[?].lotag = 4 Sprite switch.
sprite[?].lotag = 5 Basketball hoop score.
KEN'S STATUS DEFINITIONS: (Please define your own statuses for your games)
status = 0 Inactive sprite
status = 1 Active monster sprite
status = 2 Monster that becomes active only when it sees you
status = 3 Smoke on the wall for chainguns
status = 4 Splashing sprites (When you shoot slime)
status = 5 Explosion!
status = 6 Travelling bullet
status = 7 Bomb sprial-out explosion
status = 8 Player!
status = 9 EVILALGRAVE shrinking list
status = 10 EVILAL list
status = 11 Sprite respawning list
status = 12 Sprite which does not respawn (Andy's addition)
status = MAXSTATUS Non-existent sprite (this will be true for your
code also)
**************************************************************************/
typedef struct
{
long x, y, z;
} point3d;
typedef struct
{
signed char fvel, svel, avel;
short bits;
} input;
static long screentilt = 0;
void __interrupt __far timerhandler(void);
#define KEYFIFOSIZ 64
void __interrupt __far keyhandler(void);
volatile char keystatus[256], keyfifo[KEYFIFOSIZ], keyfifoplc, keyfifoend;
volatile char readch, oldreadch, extended, keytemp;
static long fvel, svel, avel;
static long fvel2, svel2, avel2;
#define NUMOPTIONS 8
#define NUMKEYS 19
static long vesares[13][2] = {
{320,200},{360,200},{320,240},{360,240},{320,400},
{360,400},{640,350},{640,400},{640,480},{800,600},
{1024,768},{1280,1024},{1600,1200}
};
static char option[NUMOPTIONS] = {0,0,0,0,0,0,1,0};
static char keys[NUMKEYS] =
{
0xc8,0xd0,0xcb,0xcd,0x2a,0x9d,0x1d,0x39,
0x1e,0x2c,0xd1,0xc9,0x33,0x34,
0x9c,0x1c,0xd,0xc,0xf,
};
static long digihz[7] = {6000,8000,11025,16000,22050,32000,44100};
static char frame2draw[MAXPLAYERS];
static long frameskipcnt[MAXPLAYERS];
#define LAVASIZ 128
#define LAVALOGSIZ 7
#define LAVAMAXDROPS 32
static char lavabakpic[(LAVASIZ+4)*(LAVASIZ+4)], lavainc[LAVASIZ];
static long lavanumdrops, lavanumframes;
static long lavadropx[LAVAMAXDROPS], lavadropy[LAVAMAXDROPS];
static long lavadropsiz[LAVAMAXDROPS], lavadropsizlookup[LAVAMAXDROPS];
static long lavaradx[24][96], lavarady[24][96], lavaradcnt[32];
/* Shared player variables */
static long posx[MAXPLAYERS], posy[MAXPLAYERS], posz[MAXPLAYERS];
static long horiz[MAXPLAYERS], zoom[MAXPLAYERS], hvel[MAXPLAYERS];
static short ang[MAXPLAYERS], cursectnum[MAXPLAYERS], ocursectnum[MAXPLAYERS];
static short playersprite[MAXPLAYERS], deaths[MAXPLAYERS];
static long lastchaingun[MAXPLAYERS];
static long health[MAXPLAYERS], flytime[MAXPLAYERS];
static short oflags[MAXPLAYERS];
static short numbombs[MAXPLAYERS];
static short numgrabbers[MAXPLAYERS]; /* Andy did this */
static short nummissiles[MAXPLAYERS]; /* Andy did this */
static char dimensionmode[MAXPLAYERS];
static char revolvedoorstat[MAXPLAYERS];
static short revolvedoorang[MAXPLAYERS], revolvedoorrotang[MAXPLAYERS];
static long revolvedoorx[MAXPLAYERS], revolvedoory[MAXPLAYERS];
/* ENGINE CONTROLLED MULTIPLAYER VARIABLES: */
extern short numplayers, myconnectindex;
extern short connecthead, connectpoint2[MAXPLAYERS]; /* Player linked list variables (indeces, not connection numbers) */
static long nummoves;
/*
* Bug: NUMSTATS used to be equal to the greatest tag number,
* so that the last statrate[] entry was random memory junk
* because stats 0-NUMSTATS required NUMSTATS+1 bytes. -Andy
*/
#define NUMSTATS 13
static signed char statrate[NUMSTATS] = {-1,0,-1,0,0,0,1,3,0,3,15,-1,-1};
/* Input structures */
static char networkmode; /* 0 is 2(n-1) mode, 1 is n(n-1) mode */
static long locselectedgun, locselectedgun2;
static input loc, oloc, loc2;
static input ffsync[MAXPLAYERS], osync[MAXPLAYERS], _sync[MAXPLAYERS];
/* Input faketimerhandler -> movethings fifo */
static long movefifoplc, movefifoend[MAXPLAYERS];
static input baksync[MOVEFIFOSIZ][MAXPLAYERS];
/* Game recording variables */
static long reccnt, recstat = 1;
static input recsync[16384][2];
static signed char otherlag[MAXPLAYERS] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
static long averagelag[MAXPLAYERS] = {512,512,512,512,512,512,512,512,512,512,512,512,512,512,512,512};
static long fakemovefifoplc;
static long myx, myy, myz, omyx, omyy, omyz, myzvel;
static long myhoriz, omyhoriz;
static short myang, omyang, mycursectnum;
static long myxbak[MOVEFIFOSIZ], myybak[MOVEFIFOSIZ], myzbak[MOVEFIFOSIZ];
static long myhorizbak[MOVEFIFOSIZ];
static short myangbak[MOVEFIFOSIZ];
/* MULTI.OBJ sync state variables */
extern char syncstate;
/* GAME.C sync state variables */
static char syncstat, syncval[MOVEFIFOSIZ], othersyncval[MOVEFIFOSIZ];
static long syncvaltottail, syncvalhead, othersyncvalhead, syncvaltail;
static char detailmode = 0, ready2send = 0;
static long ototalclock = 0, gotlastpacketclock = 0, smoothratio;
static long oposx[MAXPLAYERS], oposy[MAXPLAYERS], oposz[MAXPLAYERS];
static long ohoriz[MAXPLAYERS], ozoom[MAXPLAYERS];
static short oang[MAXPLAYERS];
static point3d osprite[MAXSPRITES];
#define MAXINTERPOLATIONS 1024
static long numinterpolations = 0, startofdynamicinterpolations = 0;
static long oldipos[MAXINTERPOLATIONS];
static long bakipos[MAXINTERPOLATIONS];
static long *curipos[MAXINTERPOLATIONS];
extern long cachecount, transarea;
static char playerreadyflag[MAXPLAYERS];
/* Miscellaneous variables */
static char packbuf[MAXXDIM];
static char tempbuf[MAXXDIM], boardfilename[80];
static short tempshort[MAXSECTORS];
static short screenpeek = 0, oldmousebstatus = 0, brightness = 0;
static short screensize, screensizeflag = 0;
static short neartagsector, neartagwall, neartagsprite;
static long lockclock, neartagdist, neartaghitdist;
extern long frameplace, pageoffset, ydim16;
static long globhiz, globloz, globhihit, globlohit;
/* volatile long stereomode = 0; */
extern long stereowidth, stereopixelwidth;
extern volatile long activepage;
/* Over the shoulder mode variables */
static long cameradist = -1, cameraang = 0, cameraclock = 0;
/* Board animation variables */
#define MAXMIRRORS 64
static short mirrorwall[MAXMIRRORS], mirrorsector[MAXMIRRORS], mirrorcnt;
static short floormirrorsector[64], floormirrorcnt;
static short turnspritelist[16], turnspritecnt;
static short warpsectorlist[64], warpsectorcnt;
static short xpanningsectorlist[16], xpanningsectorcnt;
static short ypanningwalllist[64], ypanningwallcnt;
static short floorpanninglist[64], floorpanningcnt;
static short dragsectorlist[16], dragxdir[16], dragydir[16], dragsectorcnt;
static long dragx1[16], dragy1[16], dragx2[16], dragy2[16], dragfloorz[16];
static short swingcnt, swingwall[32][5], swingsector[32];
static short swingangopen[32], swingangclosed[32], swingangopendir[32];
static short swingang[32], swinganginc[32];
static long swingx[32][8], swingy[32][8];
static short revolvesector[4], revolveang[4], revolvecnt;
static long revolvex[4][16], revolvey[4][16];
static long revolvepivotx[4], revolvepivoty[4];
static short subwaytracksector[4][128], subwaynumsectors[4], subwaytrackcnt;
static long subwaystop[4][8], subwaystopcnt[4];
static long subwaytrackx1[4], subwaytracky1[4];
static long subwaytrackx2[4], subwaytracky2[4];
static long subwayx[4], subwaygoalstop[4], subwayvel[4], subwaypausetime[4];
static short waterfountainwall[MAXPLAYERS], waterfountaincnt[MAXPLAYERS];
static short slimesoundcnt[MAXPLAYERS];
/* Variables that let you type messages to other player */
static char getmessage[162], getmessageleng;
static long getmessagetimeoff;
static char typemessage[162], typemessageleng = 0, typemode = 0;
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,
};
/*
* These variables are for animating x, y, or z-coordinates of sectors,
* walls, or sprites (They are NOT to be used for changing the [].picnum's)
* See the setanimation(), and getanimategoal() functions for more details.
*/
#define MAXANIMATES 512
static long *animateptr[MAXANIMATES], animategoal[MAXANIMATES];
static long animatevel[MAXANIMATES], animateacc[MAXANIMATES], animatecnt = 0;
/* These parameters are in exact order of sprite structure in BUILD.H */
#define spawnsprite(newspriteindex2,x2,y2,z2,cstat2,shade2,pal2, \
clipdist2,xrepeat2,yrepeat2,xoffset2,yoffset2,picnum2,ang2, \
xvel2,yvel2,zvel2,owner2,sectnum2,statnum2,lotag2,hitag2,extra2) \
{ \
spritetype *spr2; \
newspriteindex2 = insertsprite(sectnum2,statnum2); \
spr2 = &sprite[newspriteindex2]; \
spr2->x = x2; spr2->y = y2; spr2->z = z2; \
spr2->cstat = cstat2; spr2->shade = shade2; \
spr2->pal = pal2; spr2->clipdist = clipdist2; \
spr2->xrepeat = xrepeat2; spr2->yrepeat = yrepeat2; \
spr2->xoffset = xoffset2; spr2->yoffset = yoffset2; \
spr2->picnum = picnum2; spr2->ang = ang2; \
spr2->xvel = xvel2; spr2->yvel = yvel2; spr2->zvel = zvel2; \
spr2->owner = owner2; \
spr2->lotag = lotag2; spr2->hitag = hitag2; spr2->extra = extra2; \
copybuf(&spr2->x,&osprite[newspriteindex2].x,3); \
show2dsprite[newspriteindex2>>3] &= ~(1<<(newspriteindex2&7)); \
if (show2dsector[sectnum2>>3]&(1<<(sectnum2&7))) \
show2dsprite[newspriteindex2>>3] |= (1<<(newspriteindex2&7)); \
} \
void __interrupt __far timerhandler(void)
{
totalclock++;
/* _chain_intr(oldtimerhandler); */
#ifdef PLATFORM_DOS
outp(0x20,0x20);
#endif
}
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. */
}
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[(int) keytemp])
{
keystatus[(int) keytemp] = 1;
keyfifo[(int) keyfifoend] = keytemp;
keyfifo[(int) (keyfifoend+1)&(KEYFIFOSIZ-1)] = 1;
keyfifoend = ((keyfifoend+2)&(KEYFIFOSIZ-1));
}
}
else
{
keytemp = (readch&127)+extended;
keystatus[(int) keytemp] = 0;
keyfifo[(int) keyfifoend] = keytemp;
keyfifo[(int) (keyfifoend+1)&(KEYFIFOSIZ-1)] = 0;
keyfifoend = ((keyfifoend+2)&(KEYFIFOSIZ-1));
}
}
extended = 0;
}
void initlava(void)
{
long x, y, z, r;
for(z=0;z<32;z++) lavaradcnt[z] = 0;
for(x=-16;x<=16;x++)
for(y=-16;y<=16;y++)
{
r = ksqrt(x*x + y*y);
lavaradx[r][lavaradcnt[r]] = x;
lavarady[r][lavaradcnt[r]] = y;
lavaradcnt[r]++;
}
for(z=0;z<16;z++)
lavadropsizlookup[z] = 8 / (ksqrt(z)+1);
for(z=0;z<LAVASIZ;z++)
lavainc[z] = klabs((((z^17)>>4)&7)-4)+12;
lavanumdrops = 0;
lavanumframes = 0;
}
#if (defined USE_I386_ASM)
#if (defined __WATCOMC__)
long addlava(int param);
#pragma aux addlava =\
"mov al, byte ptr [ebx-133]",\
"mov dl, byte ptr [ebx-1]",\
"add al, byte ptr [ebx-132]",\
"add dl, byte ptr [ebx+131]",\
"add al, byte ptr [ebx-131]",\
"add dl, byte ptr [ebx+132]",\
"add al, byte ptr [ebx+1]",\
"add al, dl",\
parm [ebx]\
modify exact [eax edx]
#elif (defined __GNUC__)
static long addlava (int i1)
{
long retval;
__asm__ __volatile__ (
"\n\t"
"movb -133(%%edi), %%al\n\t"
"movb -1(%%edi), %%dl\n\t"
"addb -132(%%edi), %%al\n\t"
"addb 131(%%edi), %%dl\n\t"
"addb -131(%%edi), %%al\n\t"
"addb 132(%%edi), %%dl\n\t"
"addb 1(%%edi), %%al\n\t"
"addb %%dl, %%al\n\t"
: "=a" (retval) : "D" (i1) : "edx", "cc", "memory");
return (retval);
} /* addlava */
#elif (defined _MSC_VER)
long addlava(int param)
{
__asm
{
mov ebx, param
mov al, byte ptr [ebx-133]
mov dl, byte ptr [ebx-1]
add al, byte ptr [ebx-132]
add dl, byte ptr [ebx+131]
add al, byte ptr [ebx-131]
add dl, byte ptr [ebx+132]
add al, byte ptr [ebx+1]
add al, dl
mov param, eax
} /* asm */
return(param);
} /* addlava */
#else
#error Please write Assembly code for your platform!
#endif
#else /* USE_I386_ASM */
long addlava(int param)
{
unsigned char al;
unsigned char *s = (unsigned char *)param;
unsigned char *t = (unsigned char *)(param-133);
al = t[0] + t[132] + t[1] + s[131] + t[2] + s[132] + s[1];
return((param&0xffffff00)|al);
} /* addlava */
#endif
void movelava(char *dapic)
{
long i, j, x, y, z, zz, dalavadropsiz, dadropsizlookup;
long dalavax, dalavay, *ptr, *ptr2;
for(z=min(LAVAMAXDROPS-lavanumdrops-1,3);z>=0;z--)
{
lavadropx[lavanumdrops] = (rand()&(LAVASIZ-1));
lavadropy[lavanumdrops] = (rand()&(LAVASIZ-1));
lavadropsiz[lavanumdrops] = 1;
lavanumdrops++;
}
for(z=lavanumdrops-1;z>=0;z--)
{
dadropsizlookup = lavadropsizlookup[lavadropsiz[z]]*(((z&1)<<1)-1);
dalavadropsiz = lavadropsiz[z];
dalavax = lavadropx[z]; dalavay = lavadropy[z];
for(zz=lavaradcnt[lavadropsiz[z]]-1;zz>=0;zz--)
{
i = (((lavaradx[dalavadropsiz][zz]+dalavax)&(LAVASIZ-1))<<LAVALOGSIZ);
i += ((lavarady[dalavadropsiz][zz]+dalavay)&(LAVASIZ-1));
dapic[i] += dadropsizlookup;
if (dapic[i] < 192) dapic[i] = 192;
}
lavadropsiz[z]++;
if (lavadropsiz[z] > 10)
{
lavanumdrops--;
lavadropx[z] = lavadropx[lavanumdrops];
lavadropy[z] = lavadropy[lavanumdrops];
lavadropsiz[z] = lavadropsiz[lavanumdrops];
}
}
/* Back up dapic with 1 pixel extra on each boundary */
/* (to prevent anding for wrap-around) */
ptr = (long *)dapic;
ptr2 = (long *)((LAVASIZ+4)+1+((long)lavabakpic));
for(x=0;x<LAVASIZ;x++)
{
for(y=(LAVASIZ>>2);y>0;y--) *ptr2++ = ((*ptr++)&0x1f1f1f1f);
ptr2++;
}
for(y=0;y<LAVASIZ;y++)
{
lavabakpic[y+1] = (dapic[y+((LAVASIZ-1)<<LAVALOGSIZ)]&31);
lavabakpic[y+1+(LAVASIZ+1)*(LAVASIZ+4)] = (dapic[y]&31);
}
for(x=0;x<LAVASIZ;x++)
{
lavabakpic[(x+1)*(LAVASIZ+4)] = (dapic[(x<<LAVALOGSIZ)+(LAVASIZ-1)]&31);
lavabakpic[(x+1)*(LAVASIZ+4)+(LAVASIZ+1)] = (dapic[x<<LAVALOGSIZ]&31);
}
lavabakpic[0] = (dapic[LAVASIZ*LAVASIZ-1]&31);
lavabakpic[LAVASIZ+1] = (dapic[LAVASIZ*(LAVASIZ-1)]&31);
lavabakpic[(LAVASIZ+4)*(LAVASIZ+1)] = (dapic[LAVASIZ-1]&31);
lavabakpic[(LAVASIZ+4)*(LAVASIZ+2)-1] = (dapic[0]&31);
ptr = (long *)dapic;
for(x=0;x<LAVASIZ;x++)
{
i = (long)&lavabakpic[(x+1)*(LAVASIZ+4)+1];
j = i+LAVASIZ;
for(y=i;y<j;y+=4)
{
*ptr++ = ((addlava(y+0)&0xf8)>>3)+
((addlava(y+1)&0xf8)<<5)+
((addlava(y+2)&0xf8)<<13)+
((addlava(y+3)&0xf8)<<21)+
0xc2c2c2c2;
}
}
lavanumframes++;
}
void drawtilebackground (long thex, long they, short tilenum,
signed char shade, long cx1, long cy1,
long cx2, long cy2, char dapalnum)
{
long x, y, xsiz, ysiz, tx1, ty1, tx2, ty2;
xsiz = tilesizx[tilenum]; tx1 = cx1/xsiz; tx2 = cx2/xsiz;
ysiz = tilesizy[tilenum]; ty1 = cy1/ysiz; ty2 = cy2/ysiz;
for(x=tx1;x<=tx2;x++)
for(y=ty1;y<=ty2;y++)
rotatesprite(x*xsiz<<16,y*ysiz<<16,65536L,0,tilenum,shade,dapalnum,8+16+64+128,cx1,cy1,cx2,cy2);
}
void printext(long x, long y, char *buffer, short tilenum, char invisiblecol)
{
long i;
char ch;
for(i=0;buffer[i]!=0;i++)
{
ch = buffer[i];
rotatesprite((x-((8&15)<<3))<<16,(y-((8>>4)<<3))<<16,65536L,0,tilenum,0,0,8+16+64+128,x,y,x+7,y+7);
rotatesprite((x-((ch&15)<<3))<<16,(y-((ch>>4)<<3))<<16,65536L,0,tilenum,0,0,8+16+128,x,y,x+7,y+7);
x += 8;
}
}
static long ostatusflytime = 0x80000000;
void drawstatusflytime(short snum) { /* Andy did this */
long nstatusflytime;
if ((snum == screenpeek) && (screensize <= xdim)) {
nstatusflytime = (((flytime[snum] + 119) - lockclock) / 120);
if (nstatusflytime > 1000) nstatusflytime = 1000;
else if (nstatusflytime < 0) nstatusflytime = 0;
if (nstatusflytime != ostatusflytime) {
if (nstatusflytime > 999) sprintf((char*)&tempbuf,"FT:BIG");
else sprintf((char*)&tempbuf,"FT:%3ld",nstatusflytime);
printext((xdim - 56L),(ydim - 20L),tempbuf,ALPHABET,80);
ostatusflytime = nstatusflytime;
}
}
}
void drawstatusbar(short snum) { /* Andy did this */
long nstatusflytime;
if ((snum == screenpeek) && (screensize <= xdim)) {
sprintf((char*)&tempbuf,"Deaths:%d",deaths[snum]);
printext((xdim>>1)-(strlen(tempbuf)<<2),ydim-16,tempbuf,ALPHABET,80);
sprintf((char*)&tempbuf,"Health:%3ld",health[snum]);
printext((xdim>>1)-(strlen(tempbuf)<<2),ydim-24,tempbuf,ALPHABET,80);
sprintf((char*)&tempbuf,"B:%3d",numbombs[snum]);
printext(8L,(ydim - 28L),tempbuf,ALPHABET,80);
sprintf((char*)&tempbuf,"M:%3d",nummissiles[snum]);
printext(8L,(ydim - 20L),tempbuf,ALPHABET,80);
sprintf((char*)&tempbuf,"G:%3d",numgrabbers[snum]);
printext(8L,(ydim - 12L),tempbuf,ALPHABET,80);
nstatusflytime = (((flytime[snum] + 119) - lockclock) / 120);
if (nstatusflytime < 0) {
sprintf((char*)&tempbuf,"FT: 0");
ostatusflytime = 0;
}
else if (nstatusflytime > 999) {
sprintf((char*)&tempbuf,"FT:BIG");
ostatusflytime = 999;
}
else {
sprintf((char*)&tempbuf,"FT:%3ld",nstatusflytime);
ostatusflytime = nstatusflytime;
}
printext((xdim - 56L),(ydim - 20L),tempbuf,ALPHABET,80);
}
}
void setup3dscreen(void)
{
long i, dax, day, dax2, day2;
i = setgamemode(option[0],vesares[option[6]&15][0],vesares[option[6]&15][1]);
if (i < 0)
{
printf("VESA driver for (%ld * %ld) not found/supported.\n",xdim,ydim);
printf(" Press ENTER to play in NORMAL mode instead\n");
printf(" Press ESC to quit to DOS\n");
keystatus[1] = keystatus[0x1c] = keystatus[0x9c] = 0;
while (!keystatus[1])
if (keystatus[0x1c]|keystatus[0x9c])
{ option[0] = vidoption = 2; i = setgamemode(option[0],vesares[option[6]&15][0],vesares[option[6]&15][1]); break; }
}
if (i < 0)
{
sendlogoff();
musicoff();
uninitmultiplayers();
uninittimer();
uninitkeys();
uninitengine();
uninitsb();
uninitgroupfile();
exit(0);
}
/* Make that ugly pink into black in case it ever shows up! */
i = 0L;
VBE_setPalette(255,1,(char *)&i);
/*outp(0x3c8,255); outp(0x3c9,0); outp(0x3c9,0); outp(0x3c9,0);*/
screensize = xdim;
if (screensize > xdim)
{
dax = 0; day = 0;
dax2 = xdim-1; day2 = ydim-1;
}
else
{
dax = ((xdim-screensize)>>1);
dax2 = dax+screensize-1;
day = (((ydim-32)-scale(screensize,ydim-32,xdim))>>1);
day2 = day + scale(screensize,ydim-32,xdim)-1;
setview(dax,day,dax2,day2);
}
flushperms();
if (screensize < xdim)
drawtilebackground(0L,0L,BACKGROUND,8,0L,0L,xdim-1L,ydim-1L,0); /* Draw background */
if (screensize <= xdim)
{
rotatesprite((xdim-320)<<15,(ydim-32)<<16,65536L,0,STATUSBAR,0,0,8+16+64+128,0L,0L,xdim-1L,ydim-1L);
i = ((xdim-320)>>1);
while (i >= 8) i -= 8, rotatesprite(i<<16,(ydim-32)<<16,65536L,0,STATUSBARFILL8,0,0,8+16+64+128,0L,0L,xdim-1L,ydim-1L);
if (i >= 4) i -= 4, rotatesprite(i<<16,(ydim-32)<<16,65536L,0,STATUSBARFILL4,0,0,8+16+64+128,0L,0L,xdim-1L,ydim-1L);
i = ((xdim-320)>>1)+320;
while (i <= xdim-8) rotatesprite(i<<16,(ydim-32)<<16,65536L,0,STATUSBARFILL8,0,0,8+16+64+128,0L,0L,xdim-1L,ydim-1L), i += 8;
if (i <= xdim-4) rotatesprite(i<<16,(ydim-32)<<16,65536L,0,STATUSBARFILL4,0,0,8+16+64+128,0L,0L,xdim-1L,ydim-1L), i += 4;
drawstatusbar(screenpeek); /* Andy did this */
}
}
void setinterpolation(long *posptr)
{
long i;
if (numinterpolations >= MAXINTERPOLATIONS) return;
for(i=numinterpolations-1;i>=0;i--)
if (curipos[i] == posptr) return;
curipos[numinterpolations] = posptr;
oldipos[numinterpolations] = *posptr;
numinterpolations++;
}
void stopinterpolation(long *posptr)
{
long i;
for(i=numinterpolations-1;i>=startofdynamicinterpolations;i--)
if (curipos[i] == posptr)
{
numinterpolations--;
oldipos[i] = oldipos[numinterpolations];
bakipos[i] = bakipos[numinterpolations];
curipos[i] = curipos[numinterpolations];
}
}
void updateinterpolations() /* Stick at beginning of domovethings */
{
long i;
for(i=numinterpolations-1;i>=0;i--) oldipos[i] = *curipos[i];
}
static void dointerpolations() /* Stick at beginning of drawscreen */
{
long i, j, odelta, ndelta;
ndelta = 0; j = 0;
for(i=numinterpolations-1;i>=0;i--)
{
bakipos[i] = *curipos[i];
odelta = ndelta; ndelta = (*curipos[i])-oldipos[i];
if (odelta != ndelta) j = mulscale16(ndelta,smoothratio);
*curipos[i] = oldipos[i]+j;
}
}
void restoreinterpolations() /* Stick at end of drawscreen */
{
long i;
for(i=numinterpolations-1;i>=0;i--) *curipos[i] = bakipos[i];
}
void searchmap(short startsector)
{
long i, j, dasect, splc, send, startwall, endwall;
short dapic;
walltype *wal;
if ((startsector < 0) || (startsector >= numsectors)) return;
for(i=0;i<(MAXSECTORS>>3);i++) show2dsector[i] = 0;
for(i=0;i<(MAXWALLS>>3);i++) show2dwall[i] = 0;
for(i=0;i<(MAXSPRITES>>3);i++) show2dsprite[i] = 0;
automapping = 0;
/* Search your area recursively & set all show2dsector/show2dwalls */
tempshort[0] = startsector;
show2dsector[startsector>>3] |= (1<<(startsector&7));
dapic = sector[startsector].ceilingpicnum;
if (waloff[dapic] == 0) loadtile(dapic);
dapic = sector[startsector].floorpicnum;
if (waloff[dapic] == 0) loadtile(dapic);
for(splc=0,send=1;splc<send;splc++)
{
dasect = tempshort[splc];
startwall = sector[dasect].wallptr;
endwall = startwall + sector[dasect].wallnum;
for(i=startwall,wal=&wall[startwall];i<endwall;i++,wal++)
{
show2dwall[i>>3] |= (1<<(i&7));
dapic = wall[i].picnum;
if (waloff[dapic] == 0) loadtile(dapic);
dapic = wall[i].overpicnum;
if (((dapic&0xfffff000) == 0) && (waloff[dapic] == 0)) loadtile(dapic);
j = wal->nextsector;
if ((j >= 0) && ((show2dsector[j>>3]&(1<<(j&7))) == 0))
{
show2dsector[j>>3] |= (1<<(j&7));
dapic = sector[j].ceilingpicnum;
if (waloff[dapic] == 0) loadtile(dapic);
dapic = sector[j].floorpicnum;
if (waloff[dapic] == 0) loadtile(dapic);
tempshort[send++] = (short)j;
}
}
for(i=headspritesect[dasect];i>=0;i=nextspritesect[i])
{
show2dsprite[i>>3] |= (1<<(i&7));
dapic = sprite[i].picnum;
if (waloff[dapic] == 0) loadtile(dapic);
}
}
}
void prepareboard(char *daboardfilename)
{
short startwall, endwall, dasector;
/*long i, j, k, s, dax, day, daz, dax2, day2;*/
long i, j, k=0, s, dax, day, dax2, day2;
getmessageleng = 0;
typemessageleng = 0;
randomseed = 17L;
/* Clear (do)animation's list */
animatecnt = 0;
typemode = 0;
locselectedgun = 0;
locselectedgun2 = 0;
if (loadboard(daboardfilename,&posx[0],&posy[0],&posz[0],&ang[0],&cursectnum[0]) == -1)
{
musicoff();
uninitmultiplayers();
uninittimer();
uninitkeys();
uninitengine();
uninitsb();
uninitgroupfile();
setvmode(0x3); /* Set back to text mode */
printf("Board not found\n");
exit(0);
}
setup3dscreen();
for(i=0;i<MAXPLAYERS;i++)
{
posx[i] = posx[0];