-
Notifications
You must be signed in to change notification settings - Fork 37
/
CATED.C
430 lines (361 loc) · 9.38 KB
/
CATED.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
/* 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.
*/
#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;
printint (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]=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=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='0'+block-229; /*tokens*/
else ch='?';
};
write (lst,ch);
};
writeln (lst);
};
writeln (lst,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;
drawchar (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=0;
altkey=false;
if keypressed
{
ch=upcase(readkey);
if ch=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)
{
if (regs.bx and 1>0)
/*left button places/deletes a drawtile*/
{
background[y,x]=drawtile;
view[y,x]=drawtile;
};
if (regs.bx and 2>0) /*right button places a blankfloor*/
{
background[y,x]=blankfloor;
view[y,x]=blankfloor;
};
if (not altkey) and ((ch>='a') and (ch<='z')
or ((ch>='0') and (ch<='9') ) )
{
if (ch>='0') and (ch<='9')
background[y,x]=ord(ch)+161 /*map numbers are later*/
else
background[y,x]=ord(ch)+32; /*map letters are lowercase*/
view[y,x]=background[y,x];
regs.ax=4;
regs.cx=regs.cx+16;
intr ($33,regs); /*move the mouse over*/
};
if (not altkey) and (ch=' ') /*space makes a solidwall*/
{
background[y,x]=solidwall;
view[y,x]=solidwall;
regs.ax=4;
regs.cx=regs.cx+16;
intr ($33,regs); /*move the mouse over*/
};
};
};
x=sx-24;
y=sy-9;
if (regs.bx and 1>0) and (x>0) and (x<14) and (y>0) and (y<13)and
(samplepics[y][x]<>#128)
/*button pressed in samplepics*/
{
drawchar (ltx,lty,ltt); /*unhighlight the old drawtile*/
drawtile=ord(samplepics[y][x]);
ltx=sx;
lty=sy;
ltt=drawtile;
xormask=$ffff;
drawchar (ltx,lty,ltt); /*highlight the new block*/
xormask=0;
};
rd_keyboard (dir,b1,b2);
case dir of
north: if originy>0
originy=originy-1
else
PlaySound (blockedsnd);
west: if originx>0
originx=originx-1
else
PlaySound(blockedsnd);
east: if originx<51+leftoff
originx=originx+1
else
PlaySound(blockedsnd);
south: if originy<51+topoff
originy=originy+1
else
PlaySound(blockedsnd);
};
if keydown[$19] and keydown[$1d] /*control-p*/
printmap;
if keydown[$42]
{
keydown[$42]=false;
saveit;
};
if keydown[$41]
{
keydown[$41]=false;
leveldone=true; /*so selectlevel will be called*/
};
cmdover:
until leveldone or playdone;
until playdone;
};
#endif