-
Notifications
You must be signed in to change notification settings - Fork 37
/
OLDCAT.C
1211 lines (1001 loc) · 27.9 KB
/
OLDCAT.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
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
/* The Catacomb Source Code
* Copyright (C) 1993-2014 Flat Rock Software
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/*
** Catacomb II -- The C translation...
*/
#include "PCRLIB.H"
#define maxpics 2047
#define numtiles 24*24-1 /*number of tiles displayed on screen*/
#define numlevels 30
#define maxobj 400 /*maximum possible active objects*/
#define solidwall 129
#define blankfloor 128
#define leftoff 11
#define topoff 11
#define tile2s 256 /*tile number where the 2*2 pictures start*/
#define tile3s tile2s+64*4
#define tile4s tile3s+19*9
#define tile5s tile4s+19*16
#define lasttile tile5s+19*25
typedef enum {nosnd,blockedsnd,itemsnd,treasuresnd,bigshotsnd,shotsnd,
tagwallsnd,tagmonsnd,tagplayersnd,killmonsnd,killplayersnd,opendoorsnd,
potionsnd,spellsnd,noitemsnd,gameoversnd,highscoresnd,leveldonesnd,
foundsnd} soundenum;
typedef enum {playercmd,gargcmd,dragoncmd,ramstraight,ramdiag,straight,idle,
fade,explode} thinktype;
typedef enum {benign,monster,pshot,mshot,nukeshot} tagtype;
typedef enum {nothing,player,goblin,skeleton,ogre,gargoyle,dragon,wallhit,
shot,bigshot,rock,dead1,dead2,dead3,dead4,dead5,dead6,teleporter,
torch,lastclass} classtype;
typedef struct {
boolean active; /*if false, the object has not seen the player yet*/
classtype class;
byte x,y, /*location of upper left corner in world*/
stage, /*animation frame being drawn*/
delay; /*number of frames to pause without doing anything*/
dirtype dir; /*direction facing*/
byte hp, /*hit points*/
oldx,oldy; /*position where it was last drawn*/
int oldtile; /*origin tile when last drawn*/
char filler[1]; /*pad to 16 bytes*/
} activeobj;
typedef struct { /*holds a copy of ActiveObj, and its class info*/
boolean active; /*if false, the object has not seen the player yet*/
classtype class;
byte x,y, /*location of upper left corner in world*/
stage, /*animation frame being drawn*/
delay; /*number of frames to pause without doing anything*/
dirtype dir; /*direction facing*/
byte hp, /*hit points*/
oldx,oldy; /*position where it was last drawn*/
int oldtile; /*origin tile when last drawn*/
char filler[1]; /*pad to 16 bytes*/
thinktype think;
tagtype contact;
boolean solid;
word firstchar;
byte size;
byte stages;
byte dirmask;
word speed;
byte hitpoints;
byte damage;
word points;
char filler2[1]; /*pad to 32 bytes*/
} objdesc;
/*=================*/
/* */
/* typed constants */
/* */
/*=================*/
char altmeters[14][13] = {
{0,0,0,0,0,0,0,0,0,0,0,0,0},
{190,0,0,0,0,0,0,0,0,0,0,0,0},
{190,192,0,0,0,0,0,0,0,0,0,0,0},
{190,191,192,0,0,0,0,0,0,0,0,0,0},
{190,191,191,192,0,0,0,0,0,0,0,0,0},
{190,191,191,191,192,0,0,0,0,0,0,0,0},
{190,191,191,191,191,192,0,0,0,0,0,0,0},
{190,191,191,191,191,191,192,0,0,0,0,0,0},
{190,191,191,191,191,191,191,192,0,0,0,0,0},
{190,191,191,191,191,191,191,191,192,0,0,0,0},
{190,191,191,191,191,191,191,191,191,192,0,0,0},
{190,191,191,191,191,191,191,191,191,191,192,0,0},
{190,191,191,191,191,191,191,191,191,191,191,192,0},
{190,191,191,191,191,191,191,191,191,191,191,191,193} };
char meters[14][13] = {
{0,0,0,0,0,0,0,0,0,0,0,0,0},
{194,0,0,0,0,0,0,0,0,0,0,0,0},
{194,196,0,0,0,0,0,0,0,0,0,0,0},
{194,195,196,0,0,0,0,0,0,0,0,0,0},
{194,195,195,196,0,0,0,0,0,0,0,0,0},
{194,195,195,195,196,0,0,0,0,0,0,0,0},
{194,195,195,195,195,196,0,0,0,0,0,0,0},
{194,195,195,195,195,195,196,0,0,0,0,0,0},
{194,195,195,195,195,195,195,196,0,0,0,0,0},
{194,195,195,195,195,195,195,195,196,0,0,0,0},
{194,195,195,195,195,195,195,195,195,196,0,0,0},
{194,195,195,195,195,195,195,195,195,195,196,0,0},
{194,195,195,195,195,195,195,195,195,195,195,196,0},
{194,195,195,195,195,195,195,195,195,195,195,195,193} };
dirtype opposite[9] =
{south,west,north,east,southwest,northwest,northeast,southeast,nodir};
/*==================*/
/* */
/* global variables */
/* */
/*==================*/
enum {game,demogame,demosave,editor} playmode;
enum {quited,killed,reseted,victorious} gamexit; /*determines what to do after playloop*/
int oldtiles [numtiles]; /*tile displayed last refresh*/
int background[87][86]; /*base map*/
int view[87][86]; /*base map with objects drawn in*/
int originx, originy; /*current world location of UL corn*/
byte priority [maxpics+1]; /*tile draw overlap priorities*/
int items[6];
int shotpower; /*0-13 characters in power meter*/
int side; /*which side shots come from*/
int boltsleft; /*number of shots left in a bolt*/
activeobj o[maxobj+1]; /*everything that moves is here*/
objdesc obj , altobj; /*total info about objecton and alt*/
int altnum; /*o[#] of altobj*/
int numobj,objecton; /*number of objects in O now*/
struct {
thinktype think; /*some of these sizes are for the*/
tagtype contact; /*convenience of the assembly routines*/
boolean solid;
word firstchar;
byte size;
byte stages;
byte dirmask;
word speed;
byte hitpoints;
byte damage;
word points;
byte filler[2];
} ObjDef [lastclass];
int i,j,k,x,y,z;
boolean playdone, leveldone;
boolean tempb;
char far *tempp;
int chkx,chky,chkspot; /*spot being checked by WALK*/
word frameon;
char far *grmem;
classtype clvar;
/****************************************************************************/
//////////////////////////////////
//
// function prototypes
//
//////////////////////////////////
void extern DrawObj (void);
void extern EraseObj (void);
void extern DoAll (void);
void extern EGAmove (void);
void extern CGArefresh (void);
void extern EGArefresh (void);
/*==============================*/
/* */
/* xxxREFRESH */
/* Refresh the changed areas of */
/* the tiles map in the various */
/* graphics modes. */
/* */
/*==============================*/
char demowin [5][16] = {
{14,15,15,15,15,15,15,15,15,15,15,15,15,15,15,16},
{17,' ','-','-','-',' ','D','E','M','O',' ','-','-','-',' ',18},
{17,'S','P','A','C','E',' ','T','O',' ','S','T','A','R','T',18},
{17,'F','1',' ','T','O',' ','G','E','T',' ','H','E','L','P',18},
{19,20,20,20,20,20,20,20,20,20,20,20,20,20,20,21} };
void refresh (void)
{
int x,y,basex,basey;
word underwin [5][16];
basex=originx+4;
basey=originy+17;
if (playmode==demogame)
for (y=0; x<=4; y++)
for (x=0; x<=15; x++)
{
underwin[y][x]=view[y+basey][x+basex];
view[y+basey][x+basex]=demowin[y][x+1];
};
WaitVBL ();
if (grmode==CGAgr)
CGArefresh();
else
EGArefresh();
if (playmode==demogame)
for (y=0; x<=4; y++)
for (x=0; x<=15; x++)
view[y+basey][x+basex]=underwin[y][x];
WaitVBL ();
}
void simplerefresh(void)
{
WaitVBL ();
if (grmode==CGAgr)
CGArefresh();
else
EGArefresh();
}
/*======================================*/
/* */
/* RESTORE */
/* Redraws every tile on the tiled area */
/* by setting oldtiles to -1. Used to */
/* erase any temporary windows. */
/* */
/*======================================*/
void clearold (void)
{
memset (&oldtiles,0xff,sizeof(oldtiles)); /*clear all oldtiles*/
};
void restore (void)
{
clearold ();
SimpleRefresh ();
};
/* */
/* Help */
/* */
boolean wantmore (void)
{
sx=2;
sy=20;
Print ("(SPACE for more/ESC)");
sx=12;
sy=21;
ch = get ();
if (ch==chr(27))
return false;
return true;
};
/* */
/* charpic */
/* */
void charpic(int x,int y, classtype c, dirtype dir, int stage)
{
int xx,yy,size,tilenum;
size=ObjDef[c].size;
tilenum=ObjDef[c].firstchar+size*size
* ((integer(dir) & ObjDef[c].dirmask)*ObjDef[c].stages+stage);
for (yy=y;yy<=y+size-1;yy++)
for (xx=x;xx<=x+size-1;xx++)
{
charout (xx,yy,tilenum);
inc(tilenum);
};
};
void help (void)
{
int x,y;
CenterWindow (20,20);
Print (" C A T A C O M B \n");
Print (" - - - - - - - \n");
Print (" By John Carmack & \n");
Print (" PC Arcade \n");
Print ("\n");
Print ("F1 = Help \n");
Print ("F2 = Sound on / off \n");
Print ("F3 = Controls \n");
Print ("F4 = Game reset \n");
Print ("F9 = Pause \n");
Print ("F10= Quit \n");
Print ("\n");
Print ("Watch the demo for \n");
Print ("a play example. \n");
Print ("\n");
Print ("Hit fire at the demo\n");
Print ("to begin playing. \n");
if (!Wantmore())
return;
CenterWindow (20,20);
Print ("\nKeyboard controls: \n\n");
Print ("Move : Arrows \n");
Print ("Button1 : Ctrl \n");
Print ("Button2 : Alt \n");
Print ("\nTo switch to mouse \n");
Print ("or joystick control,\n");
Print ("hit F3. \n");
if (!Wantmore())
return;
CenterWindow (20,20);
Print ("Button 1 / CTRL key:\n");
Print ("Builds shot power. \n");
Print ("If the shot power \n");
Print ("meter is full when \n");
Print ("the button is \n");
Print ("released, a super \n");
Print ("shot will be \n");
Print ("launched. \n");
Print ("\n");
for (y=11; y<=18; y++)
for (x=3; x<=20; x++)
Charout (x,y,128);
charpic (4,14,player,east,2);
charpic (19,15,shot,east,1);
charpic (17,14,shot,east,0);
charpic (15,15,shot,east,1);
charpic (8,14,bigshot,east,0);
if (!Wantmore())
return;
CenterWindow (20,20);
Print ("Button 2 / ALT key:\n");
Print ("Allows you to move \n");
Print ("without changing the\n");
Print ("direction you are \n");
Print ("facing. Good for \n");
Print ("searching walls and \n");
Print ("fighting retreats. \n");
for (y=11; y<=18; y++)
for (x=3; x<=20; x++)
if (y==15)
charout (x,y,129);
else if (y==16)
charout (x,y,131);
else
charout (x,y,128);
charpic (6,13,player,south,2);
sx=6;
sy=15;
print ("\35\35\36\36\37\37");
if (!Wantmore())
return;
CenterWindow (20,20);
Print (""P"" or ""SPACE"" will \n");
Print ("take a healing \n");
Print ("potion if you have \n");
Print ("one. This restores \n");
Print ("the body meter to \n");
Print ("full strength. Keep\n");
Print ("a sharp eye on the \n");
Print ("meter, because when \n");
Print ("it runs out, you are\n");
Print ("dead! \n\n");
Print ("""B"" will cast a bolt\n");
Print ("spell if you have \n");
Print ("any. You can mow \n");
Print ("down a lot of \n");
Print ("monsters with a bit \n");
Print ("of skill. \n");
if (!Wantmore())
return;
CenterWindow (20,20);
Print ("""N"" or ""ENTER"" will \n");
Print ("cast a nuke spell. \n");
Print ("This usually wipes \n");
Print ("out all the monsters\n");
Print ("near you. Consider \n");
Print ("it a panic button \n");
Print ("when you are being \n");
Print ("mobbed by monsters! \n\n");
Print (" \200\200\200\n");
Print ("Potions: \200\242\200\n");
Print (" \200\200\200\n");
Print ("Scrolls: \200\243\200\n");
Print (" (bolts/nukes) \200\200\200\n");
Print ("Treasure: \200\247\200\n");
Print (" (points) \200\200\200\n");
Print (" \200\200\200\n");
Wantmore();
};
/* */
/* Reset */
/* */
void reset(void)
{
CenterWindow (18,1);
Print ("Reset game (Y/N)?");
ch= get ();
if (ch=='Y')
{
gamexit=killed;
playdone=true;
};
};
/*===========================*/
/* */
/* CHECKKEYS */
/* If a key has been pressed */
/* it will be assigned to CH/*/
/* altkey, and if it is an F */
/* key, it will be processed.*/
/* */
/*===========================*/
void checkkeys (void)
{
};
/*=========================================================================*/
/*==============================*/
/* */
/* LOADLEVEL / SAVELEVEL */
/* Loads map LEVEL into memory, */
/* and sets everything up. */
/* */
/*==============================*/
void loadlevel(void)
{
classtype tokens[256-230] =
{player,teleporter,goblin,skeleton,ogre,gargoyle,dragon,nothing,
nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,
nothing,nothing,nothing,nothing,nothing,nothing,nothing,nothing,
nothing,nothing};
char filename[64],st[64];
int x,y,xx,yy,recs, btile;
char sm[4096];
strcpy (filename,"LEVEL");
itoa (level,st,10);
strcat (filename,level);
LoadFile (filename,sm);
numobj=0;
o[0].x=13; /*just defaults if no player token is found*/
o[0].y=13;
o[0].stage=0;
o[0].delay=0;
o[0].dir=east;
o[0].oldx=0;
o[0].oldy=0;
o[0].oldtile=-1;
for (yy=0; yy<64; yy++)
for (xx=0; xx<64; xx++)
{
btile=sm[yy*64+xx];
if (btile<230)
background[yy+topoff][xx+leftoff]=btile;
else
{
/*hit a monster token*/
background[yy+topoff][xx+leftoff]=blankfloor;
if (tokens[btile-230]==player)
/*the player token determines where you start in level*/
{
o[0].x=xx+topoff;
o[0].y=yy+leftoff;
}
else
/*monster tokens add to the object list*/
{
numobj++;
o[numobj].active=false;
o[numobj].class=tokens[btile-230];
o[numobj].x=xx+leftoff;
o[numobj].y=yy+topoff;
o[numobj].stage=0;
o[numobj].delay=0;
o[numobj].dir=(dirtype)(rndt()/64); /*random 0-3*/
o[numobj].hp=ObjDef[o[numobj].class].hitpoints;
o[numobj].oldx=x;
o[numobj].oldy=y;
o[numobj].oldtile=-1;
};
};
};
originx = o[0].x-11;
originy = o[0].y-11;
shotpower=0;
for (y=topoff-1; y<65+topoff; y++)
for (x=leftoff-1; x<64+leftoff; x++)
view[y][x]=background[y][x];
sx=33; /*print the new level number on the right window*/
sy=1;
printint (level);
Print (" "); /*in case it went from double to single digit*/
restore();
};
/*==========================================================================*/
#include "cat_play.c"
#include "objects.c"
/*========================================*/
/* */
/* Finished */
/* SHows the } page... */
/* */
/*========================================*/
void finished()
{
playsound (treasuresnd);
WaitEndSound();
playsound (treasuresnd);
WaitEndSound();
playsound (treasuresnd);
WaitEndSound();
playsound (treasuresnd);
WaitEndSound();
sx=20;
sy=24;
get ();
};
/*================================*/
/* */
/* PLAYSETUP */
/* Set up all data for a new game */
/* Does NOT start it playing */
/* */
/*================================*/
void playsetup()
{
int i;
score=0;
shotpower=0;
level=1;
if (keydown [0x2E] || keydown [0x14]) /*hold down 'C' and 'T' to CheaT!*/
{
CenterWindow (16,2);
Print ("Warp to which\nlevel (1-99)?");
inputint (level);
if (level<1)
level=1;
if (level>30)
level=30;
restore();
};
for (i=1; i<6; i++)
items[i]=0;
o[0].active = true;
o[0].class = player;
o[0].hp = 13;
o[0].dir=west;
o[0].stage=0;
o[0].delay=0;
DrawWindow (24,0,38,23); /*draw the right side window*/
Print (" Level\n\nScore:\n\nTop :\n\nK:\nP:\nB:\nN:\n\n\n");
Print (" Shot Power\n\n\n Body\n\n\n");
printhighscore();
printbody();
printshotpower();
/*give them a few items to start with*/
givenuke();
givenuke();
givebolt();
givebolt();
givebolt();
givepotion();
givepotion();
givepotion();
};
/*================================*/
/* */
/* GAMEOVER */
/* Do a game over bit, check */
/* for a high score, return */
/* to demo. */
/* */
/*================================*/
void gameover()
{
int place,i,j;
char st[64];
WaitEndSound();
simplerefresh();
};
/****************************************************************************/
#if 0
/*====================*/
/* */
/* EDITORLOOP */
/* The editor mode... */
/* */
/*====================*/
void editorloop()
Label
cmdover;
const
samplepics : array[1..12] of string[13] =
("\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80",
"\x80\x80\x81\x81\x87\x80\x80\x80\x87\x87\xb1\x80\x80",
"\x80\x81\x81\x81\x81\x87\x80\x87\x87\x87\x87\xb1\x80",
"\x80\x81\x81\x81\x81\x82\x80\x87\xb2\xb3\xb4\xac\x80",
"\x80\x86\x81\x81\x85\x84\x80\xb0\x87\x87\xaf\xae\x80",
"\x80\x80\x86\x83\x84\x80\x80\x80\xb0\xad\xae\x80\x80",
"\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80",
"\x80\xa2\x80\xa3\x80\xa4\x80\xa7\x80\xa5\x80\xa6\x80",
"\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80",
"\x80\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\x80",
"\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80",
"\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80");
var
drawtile:integer;
ltx,lty,ltt,x,y,i:integer;
dor: dirtype;
b1,b2: boolean;
/*$i-*/
/* */
/* */
/* LOADLEVEL */
/* Loads map LEVEL into memory, */
/* nothing more */
/* */
/* */
Procedure LoadLevel;
label
tryopen,fileread;
Var
filename : string;
st: string[3];
x,y,xx,yy,recs, btile : Integer;
iofile: file;
tile: byte;
sm : array [0..4095] of byte;
{
str(level:1,st);
filename=concat ('LEVEL',st,'.CAT');
tryopen:
Assign (iofile,filename);
Reset (iofile,1);
If ioresult<>0
/*create a blank level for the editor*/
{
for x=0 to 63 do
for y=0 to 63 do
background[y+topoff,x+leftoff]=blankfloor;
for x=0 to 63 do
{
background[topoff,x]=131; /*perspective north wall*/
background[topoff+63,x]=129; /*solid south wall*/
background[x,leftoff]=130; /*perspective west wall*/
background[x,leftoff+63]=129; /*solid east wall*/
};
background [topoff,leftoff]=133; /*perspective NW corner*/
goto fileread;
}
else
BlockRead (iofile,sm,4096,recs);
Close (iofile);
numobj=0;
for yy=0 to 63 do
for xx=0 to 63 do
{
tile=sm[yy*64+xx];
/*if tile is an exploding block, change it to a special icon for editor*/
if (tile>=136) and (tile<=145)
tile=tile+35;
background[yy+topoff,xx+leftoff]=tile;
};
fileread:
for y=topoff to 63+topoff do
for x=leftoff to 63+leftoff do
view[y,x]=background[y,x];
sx=33; /*print the new level number on the right window*/
sy=1;
shortnum (level);
Print (' '); /*in case it went from double to single digit*/
restore;
};
/* */
/* Save Level */
/* */
Procedure Saveit;
Var
iofile : file;
filename : string;
x,y,recs : Integer;
tile: byte;
st: string[3];
sm : array [0..4095] of byte;
{
CenterWindow (9,1);
Print ('Saving...');
For y=0 to 63 do
for x=0 to 63 do
{
tile=background[y+topoff,x+leftoff] and $00FF;
/*if the tile was an exploding block, change back to undetectable*/
if (tile>=171) and (tile<=180)
tile=tile-35;
sm[y*64+x]=tile;
};
str(level:1,st);
filename=concat ('LEVEL',st,'.CAT');
Assign (iofile,filename);
Rewrite (iofile,1);
BlockWrite (iofile,sm,4096,recs);
Close (iofile);
restore;
};
/* */
/* Select Level */
/* */
function SelectLevel:boolean;
Var
err:integer;
lv:string;
{
selectlevel=false; /*editor won't reload a level if false*/
CenterWindow (16,2);
Print ('Edit which level](1-99):');
input (lv,2);
if lv[1]=chr(27) /*allow ESC to quit editor mode*/
{
leveldone=true;
playdone=true;
};
val (lv,level,err);
If level>=1
selectlevel=true;
restore;
};
/* */
/* Toggle Block */
/* */
Procedure ToggleBlock;
Var
x,y,block:integer;
{
x=originx+topoff;
y=originy+leftoff;
block=background [y,x];
If block=blankfloor
block=solidwall
else
block=blankfloor;
background [y,x]=block;
view [y,x]=block;
};
/* */
/* Print map */
/* */
Procedure PrintMap;
var
x,y,block:integer;
ch: char;
{
writeln (lst);
Writeln (lst,'CATACOMB level ',level);
for y=0 to 65 do
{
for x=0 to 65 do
{
block=background[topoff-1+y,leftoff-1+x];
case block of
0..127: ch=chr(block); /*ASCII*/
128: ch=' '; /*floor*/
129..135: ch='#'; /*walls*/
171..177: ch='*'; /*exploding*/
178..180: ch='!'; /*hidden stuff*/
162: ch='p'; /*potion*/
163: ch='s'; /*scroll*/
164: ch='k'; /*key*/
165: ch='|'; /*door*/
166: ch='-'; /*door*/
167: ch='$'; /*treasure*/
230..238: ch=chr(ord('0')+block-229); /*tokens*/
else ch='?';
};
write (lst,ch);
};
writeln (lst);
};
writeln (lst,chr(12));
};
/*==================================*/
{
regs.ax=0;
intr($33,regs); /*show the mouse cursor*/
DrawWindow (24,0,38,23); /*draw the right side window*/
Print (' Level]] Map editor]]F4=exit]F7=Load]F8=Save]^P=Print');
sx=25;
leftedge=sx;
sy=10;
for i=1 to 12 do
Print (samplepics[i]+']');
drawtile=solidwall;
ltx=28;
lty=13;
ltt=solidwall;
xormask=$FFFF;
charout (ltx,lty,ltt); /*highlight the new block*/
xormask=0;
level=1;
playdone=false;
Repeat
leveldone=false;
originx=0;
originy=0;
If selectlevel /*let them choose which level to edit*/
loadlevel
else
goto cmdover; /*so if they pressed ESC, they can leave*/
repeat
SimpleRefresh;
regs.ax=1;
intr($33,regs); /*show the mouse cursor*/
waitvbl; /*make sure it gets seen*/
waitvbl;
Repeat
regs.ax=3;
intr($33,regs); /*mouse status*/
Until keypressed or (regs.bx and 3>0);
sx=regs.cx div 16; /*tile on screen mouse is over*/
sy=regs.dx div 8;
regs.ax=2;
intr($33,regs); /*hide the mouse cursor*/
Checkkeys; /*handles F keys and returns a keypress*/
ch=chr(0);
altkey=false;
if keypressed
{
ch=upcase(readkey);
if ch=chr(0)
{
altkey=true;
ch=readkey;
}
};
if (sx<24) and (sy<24)
/*buttons pressed in tile map*/
{
x=originx+sx;
y=originy+sy;
if (x>=leftoff) and (x<leftoff+64) and
(y>=topoff) and (y<topoff+64)
{