-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathO_PLAY0.PAS
More file actions
3307 lines (2805 loc) · 78.1 KB
/
Copy pathO_PLAY0.PAS
File metadata and controls
3307 lines (2805 loc) · 78.1 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
{$O+}
{$F+}
unit o_play0;
{This unit contains just about everything that should always be in memory.}
{NOT an overlay, but it's closely related to them.}
interface
uses u_sound,u_help,u_io,u_vars,
graph,u_graph,u_adv,crt2,dos,u_fonts,u_graps,u_delay2;
const BLANK=' '; {39 chars}
R150=1000;
DECOGRP=244;
type
{windowbuffertype=array[1..176,1..64] of byte;}
{ screenbank=array[1..64000] of byte; }
screenstriparray=array[1..20,1..320] of byte;
swapinfo_rec = record
execfile:string[12];
execparam:string[40];
data:array[1..10] of byte; {@}
end;
bmpimage=array[0..0] of byte;
var
bmptemp:^bmpimage;
entrancemacro:byte;
starth:byte;
lastmov:byte;
bmpskinname:string[12];
thisportal:byte;
oldhour:byte;
aggro:byte;
resurrect:boolean;
macrosuccess:byte;
oops_i_missed,newwmapload,brandnewgame:boolean;
starting_up_clearscreen:boolean;
swapinfo:^swapinfo_rec;
modified:array[1..99] of boolean;
next_queued_action,queued_actions:byte;
queued_action:array[1..16,1..2] of byte;
encumberance:byte;
arcade:boolean;
crc:^crcarray;
{wbuffer:^windowbuffertype;}
printer:text;
a_weap_org_x,a_weap_org_y,action_weap,a_weap_type:byte;
timestepsec:byte;
timephase:byte;
oldtimepic,timepic:byte;
teleport_room:byte;
{ qtile:array[1..12] of word; }
var pal1:array[0..255,0..2] of byte;
{ dpal:array[0..255,0..2] of byte; }
{$I I_MSTREC.PAS}
{$I I_CRCREC.PAS}
{$I I_WANDC1.PAS}
var i,i1:integer;
{ bank1:^screenbank; }
screenstrip:^screenstriparray;
s,ss:string;
quittime:boolean;
curricon:byte;
erasebottom:byte;
readkey_time:word;
readkey_default:char;
readkey_0default:char;
pass_message,block_message:byte;
creaturemoved:array[1..RCMAX] of byte;
sounded:boolean;
keybuffer:boolean;
nextanim: longint;
var doublepass:boolean; {should it put off parsing until character moves?}
dp_tmresult,dp_tmspot,dp_tmdata,dp_room,dp_x,dp_y:byte;
do_all,bumpnoise,stepnoise:boolean;
macroloaded:byte;
const
LOCNTMAX=6400;
OOPS=10;
type chunkprec = array[1..3,1..3] of byte;
locrec = record
o,d:byte;
end;
chunkrec = array[1..16,1..16] of locrec;
type vehrec = array[1..255] of
record
obj,objcode:byte;
xchunk,ychunk:byte;
used:boolean;
howmany:byte;
end;
var xinloc,yinloc:byte;
xchunkloc,ychunkloc:integer;
macro_teleport:boolean;
global_xloc,global_yloc,global_xchunk,global_ychunk,
global_room,global_region:byte;
veh:vehrec;
Ack:masterrec;
thisregion:byte;
chunk:chunkprec;
gotolocation,chunksave:boolean;
locntsize:word;
roomwide,roomtall:byte;
map:array[1..3,1..3] of chunkrec;
mapcolors:array[0..255] of byte;
type anim_rec = record
t1,t2,t3,t4:byte;
tb4,tb:boolean;
lit:byte;
under:byte;
aggro:boolean;
end;
var animate:boolean;
anim_screen:array[0..17,0..12] of anim_rec;
anim_wide,anim_tall:byte;
anim_phase_one:boolean;
key_report:boolean;
type
macrorec = record
cmd:byte;
data:Array[1..6,1..3] of byte;
next:word;
end;
macroarray=array[0..0] of macrorec;
var
macro:^macroarray;
procedure flopitem(wxloc,wyloc,inv,invn:byte);
procedure show_shortmsg;
procedure showmosaic;
function loadmosaic(n:byte):boolean;
procedure load_longmsgfile(mn:byte);
procedure show_longmsg;
procedure longmessage(n:byte);
procedure shortmessage(n:byte);
procedure writelog(n:integer; s:string);
procedure writelog2(n1,n2,n3,n4:word;n5,n6,n7:longint);
procedure calculate_weight;
{from i_msgply}
procedure clear_keyboard_buffer;
procedure bottomsay(y:byte;s:string);
procedure clearbottom;
procedure waitkey;
procedure adjacent_error;
procedure showbmp(n:word;transp:boolean);
procedure picturemessage(n:word);
{end i_msgply}
procedure soundeffect(snd:word; channel:byte);
procedure graphHP;
procedure playerdeath;
{from i_ply2:}
function distance(x1,y1,x2,y2:integer):byte;
{from i_ply3:}
procedure loadconfig;
procedure saveconfig;
procedure loadcreatures;
procedure loadobjs;
procedure savestrip;
procedure restorestrip;
procedure savepage;
procedure restorepage;
procedure titlebars;
procedure showplayerstatus;
procedure boxx(x1,y1,x2,y2:byte);
procedure savewmap;
procedure loadwmap;
procedure savemap;
procedure loadmap(n:byte);
{end i_ply3}
{from i_ply1:}
function selectinventory(cats:byte;comment:string):byte;
procedure animation;
procedure anim_toggle;
procedure run_macro(n:byte);
procedure bytecopy(fn1,fn2:string);
function bytecopybunch(ext,newext:char):word;
function countfiles(ext:string2):word;
procedure deletebunch(ext:string4);
procedure fullgamesave;
procedure cycletime;
procedure menuskinbmp;
procedure showtimepic;
procedure mutesoundmenu;
procedure levelup;
procedure passtime(settimestep:byte);
implementation
var starting_h:byte;
procedure flopitem(wxloc,wyloc,inv,invn:byte);
var dropcount:integer;
begin
{drop items}
dropcount:=1;
repeat
if (veh[dropcount].used) then inc(dropcount) else inc(dropcount,1000);
until dropcount>255;
if dropcount>300 then
begin
{write item}
dec(dropcount,1000);
veh[dropcount].used:=true;
veh[dropcount].obj:=
map[wxloc DIV 16+1,wyloc DIV 16+1,
wxloc MOD 16+1,wyloc MOD 16+1].o;
veh[dropcount].objcode:=
map[wxloc DIV 16+1,wyloc DIV 16+1,
wxloc MOD 16+1,wyloc MOD 16+1].d;
veh[dropcount].howmany:=invn;
veh[dropcount].xchunk:=xchunkloc+(wxloc DIV 16)-1;
veh[dropcount].ychunk:=ychunkloc+(wyloc DIV 16)-1;
map[wxloc DIV 16+1,wyloc DIV 16+1,
wxloc MOD 16+1,wyloc MOD 16+1].o:=inv;
map[wxloc DIV 16+1,wyloc DIV 16+1,
wxloc MOD 16+1,wyloc MOD 16+1].d:=dropcount;
end;
writelog(dropcount,'flopitem: '+strnum(invn)+' of '+strnum(inv)+' at '+strnum(wxloc)+','+strnum(wyloc));
end;
procedure loadmapcolors;
var cf:file of byte;
i:byte;
begin
assign(cf,ADVNAME+'.MCO');
{$I-} reset(cf); {$I+}
if ioresult<>0 then
begin
for i:=0 to 255 do mapcolors[i]:=i;
end else
begin
for i:=0 to 255 do read(cf,mapcolors[i]);
close(cf);
end;
end;
procedure show_shortmsg;
var i:integer;
begin
{ thickln(261,170,262,190,0);}
drawh(10,170,309,lo(TEXTC0));
drawh(10,189,309,lo(TEXTC0));
drawv(10,170,189,lo(TEXTC0));
drawv(309,170,189,lo(TEXTC0));
drawh(11,171,308,hi(TEXTC0));
drawh(11,188,308,hi(TEXTC0));
drawv(11,171,188,hi(TEXTC0));
drawv(308,171,188,hi(TEXTC0));
for i:=1 to 37 do
begin
putletter(i*2+1,171,ord(shortmsg.chars[1,i]),shortmsg.attrs[1,i]);
putletter(i*2+1,179,ord(shortmsg.chars[2,i]),shortmsg.attrs[2,i]);
end;
end;
procedure showmosaic;
var x,y:byte;
begin
for x:=1 to 16 do for y:=1 to 11 do
putgrap(x*4-3,y*16-14,mosaic[x,y]);
end;
procedure transparent_mosaic;
var x,y:byte;
begin
for x:=1 to 16 do for y:=1 to 11 do
if (mosaic[x,y]<>240) and (mosaic[x,y]<>0) then putgrap(x*4-3,y*16-14,mosaic[x,y]);
end;
function loadmosaic(n:byte):boolean;
var mf:file of mosaicrec;
begin
writelog(n,'Loading mosaic');
assign(mf,ADVNAME+MOSAICFILE);
{$I-} reset(mf); {$I+}
if ioresult<>0 then
begin
loadmosaic:=false;exit;
end;
if n>filesize(mf)+1 then
begin
loadmosaic:=false;exit;
end;
seek(mf,n-1);
read(mf,mosaic);
close(mf);
end;
procedure load_longmsgfile(mn:byte);
var f:file of longmsgrec;
begin
writelog(mn,'Loading long message');
if mn=0 then exit;
assign(f,ADVNAME+LONGMSGFILE);
{$I-} reset(f); {$I+}
if ioresult<>0 then exit;
if filesize(f)>=mn then seek(f,mn-1);
read(f,longmsg);
close(f);
end;
procedure show_longmsg;
var i,i1:integer;
begin
{for i:=1 to 177 do fillchar(mem[$a000:scrnh[i]+4],256,lo(TEXTC0));}
for i1:=1 to 22 do
for i:=1 to 32 do
putletter(i*2-1,2+(i1-1)*8,ord(longmsg.chars[i1,i]),longmsg.attrs[i1,i]);
end;
procedure longmessage(n:byte);
var i,i1,ii:byte;
cs,ty,ty2,bb:byte;
begin
load_longmsgfile(n);
show_longmsg;
(*
if PALETTE=16 then begin;show_longmsg;exit;end;
for i1:=1 to 22 do
for i:=1 to 32 do
begin
cs:=longmsg.attrs[i1,i];
case cs of
1,4:ty:=85;
2,5:ty:=170;
else ty:=255;
end;
if cs<4 then ty2:=0 else ty2:=255;
bb:=byte(longmsg.chars[i1,i]);
{ putletter(i*2-1,2+(i1-1)*8,ord(longmsg.chars[i1,i]),longmsg.attrs[i1,i]);}
for ii:=1 to 8 do
begin
move(block^[bb,ii],wbuffer^[i1*8-(8-ii),i*2-1],2);
if cs>0 then
begin { analyze and change the bx bytes }
wbuffer^[i1*8-(8-ii),i*2-1]:=(wbuffer^[i1*8-(8-ii),i*2-1] XOR ty2) AND ty;
wbuffer^[i1*8-(8-ii),i*2]:=(wbuffer^[i1*8-(8-ii),i*2] XOR ty2) AND ty;
end;
end;
end;
for i:=1 to 176 do
move(wbuffer^[i,1],mem[scrnl:1+scrnh[i+2]],64);
*)
clearbottom;
waitkey;
end;
procedure internal_shortmsg;
begin
(*
savestrip;
clearbottom;
thickln(261,170,262,190,0);
drawh(10,170,309,0);
drawh(10,189,309,0);
drawh(11,171,308,3);
drawh(11,188,308,3);
drawv(10,170,189,0);
drawv(11,171,188,3);
drawv(309,170,189,0);
drawv(308,171,188,3);
say(3,171,0,ack.shortmessage1);
say(3,179,0,ack.shortmessage2);
bottomsay(2,'PRESS A KEY TO CONTINUE.');
if readkey=#0 then if readkey=#59 then help;
bottomsay(2,' ');
restorestrip;
*)
end;
procedure internal_bmsg;
begin
{ bottomsay(1,ack.shortmessage1);
bottomsay(2,ack.shortmessage2);}
end;
procedure shortmessage(n:byte);
var j:char;
begin
if n=0 then
begin
internal_shortmsg;
exit;
end;
load_shortmsgfile(n);
clearbottom;
savestrip;
show_shortmsg;
bottomsay(2,'PRESS A KEY TO CONTINUE.');
if readkey=#0 then if readkey=#59 then help;
bottomsay(2,' ');
restorestrip;
end;
procedure invertscr;
var b:byte; b2:word;
begin
for b:=5 to 177 do for b2:=1 to 31 do
begin
meml[$a000:scrnh[b]+(b2*8)]:=meml[$a000:scrnh[b]+(b2*8)] XOR $0F0F0F0F;
meml[$a000:scrnh[b]+(b2*8)+4]:=meml[$a000:scrnh[b]+(b2*8)+4] XOR $0F0F0F0F;
end;
end;
procedure writelog(n:integer; s:string);
var logfile:text;
begin
if ack.cheat<>123 then exit;
assign(logfile,ADVNAME+'.LOG');
{$I-} append(logfile); {$I+}
if ioresult<>0 then rewrite(logfile);
writeln(logfile,n,' '+s);
close(logfile);
end;
procedure writelog2(n1,n2,n3,n4:word;n5,n6,n7:longint);
var logfile:text;
begin
if ack.cheat<>123 then exit;
assign(logfile,'TIMER.LOG');
{$I-} append(logfile); {$I+}
if ioresult<>0 then rewrite(logfile);
writeln(logfile,n1,' ',n2,' ',n3,' ',n4,' ',n5,' ',n6,' ',n7);
close(logfile);
end;
procedure calculate_weight;
var i:integer;t:longint;max:longint;w:word;
begin
i:=1;
t:=ack.pcash*(obj^[i].d[9]*256+obj^[i].d[10]);
for i:=2 to 254 do if ack.pinv[i]<>0 then
if (obj^[i].t>5) and (obj^[i].t<10) then
begin
w:=obj^[i].d[9]*256+obj^[i].d[10];
if w<=30000 then
t:=t+ack.pinv[i]*w;
end;
if ack.plvehicle<>0 then
max:=obj^[ack.plvehicle].d[9]*256+obj^[ack.plvehicle].d[10] else
max:=ack.strength[0]*5;
if max<10 then max:=10;
encumberance:=t DIV max;
end;
procedure clear_keyboard_buffer;
var regs:registers;
begin
regs.ah:=$0c;regs.al:=$00;
intr($21,regs);
end;
procedure fixpalette;
begin
loadbmppalette(ack.ackversion,ADVNAME,bgi_dir);
{ greg.ax:=$1012;
greg.bx:=0;
greg.cx:=256;
greg.es:=seg(dpal[0,0]);
greg.dx:=ofs(dpal[0,0]);
intr($10,greg); }
end;
var macrolines:byte;
procedure loadmacro(n:byte);
var df:file of macrorec;
macbuff:macrorec;
i:integer;
begin
writelog(n,'Loading macro');
assign(df,ADVNAME+MACROFILE);
{$I-} reset(df); {$I+}
if ioresult<>0 then exit;
seek(df,n);
read(df,macbuff);
i:=1;
macro^[i]:=macbuff;
i:=2;
while (macbuff.next<>0) and (i<100) do
begin
seek(df,macbuff.next);
read(df,macbuff);
macro^[i]:=macbuff;
inc(i);
end;
{macrolines:=i-1;}
macro^[i].cmd:=22; {implied "stop" at the end}
macrolines:=i;
close(df);
macroloaded:=n;
end;
procedure bottomsay(y:byte;s:string);
begin
case y of
0:y:=184;
1:y:=180;
2:y:=188;
end;
say(2,y,0,s);
end;
procedure clearbottom;
begin
say(1,180,0,BLANK);
say(1,188,0,BLANK);
end;
procedure waitkey;
var j:char;
done:boolean;
begin
clear_keyboard_buffer;
bottomsay(2,'PRESS A KEY TO CONTINUE.');
done:=false;
repeat
j:=readkey;
if j=#0 then j:=readkey else done:=true;
until done;
bottomsay(2,' ');
end;
procedure adjacent_error;
begin
clearbottom;bottomsay(1,'RANGED WEAPONS CAN''T ATTACK ADJACENT');
bottomsay(2,'SPACES. PRESS A KEY TO CONTINUE...');
if readkey=#0 then if readkey=#59 then help;
clearbottom;
end;
{$I I_SNDEFF.PAS} {procedure soundeffect}
procedure showbmp(n:word;transp:boolean);
var bmpf:file; bmph:file of byte;
i,i2:integer;
b,t:byte;
pal2:array[0..255,0..2] of byte;
name:string;
header:Array[1..54] of byte;
headersize:word;
count:word;
j:char;
begin
{first 54 bytes: header}
{next 1024- bytes: pal in B-G-R-0}
{next 64000 bytes: bitmap itself}
{clear screen}
{load new palette}
if n=65530 then
begin
name:=file_exists(bmpskinname);
end else
if n=65529 then
begin
name:=file_exists('ABOUT.BMP');
end else
begin
writelog(n,'Displaying BMP');
name:=custom_content_exists(n,'BMP');
end;
if name<>'' then
begin
assign(bmph,name);
reset(bmph);
if ioresult=0 then
begin
seek(bmph,46);
read(bmph,b);
i2:=b;
if i2=0 then i2:=256;
headersize:=54+(i2*4);
close(bmph);
writelog(100,strnum(64000+headersize));
assign(bmpf,name);
{$I-}
reset(bmpf,64000+headersize);
blockread(bmpf,bmptemp^[0],1);
close(bmpf);
{$I+}
{load and discard header}
for i:=0 to i2-1 do
begin
pal2[i,2]:=bmptemp^[54+(i*4)];
pal2[i,1]:=bmptemp^[54+(i*4)+1];
pal2[i,0]:=bmptemp^[54+(i*4)+2];
end;
{load palette off disk}
{load and display picture}
if not transp then
begin
{load new palette into pal2}
for i:=0 to 255 do for i2:=0 to 2 do
pal2[i,i2]:=pal2[i,i2] SHR 2;
{ clearscreen;}
{load current palette into pal1}
greg.ax:=$1017;
greg.bx:=0;
greg.cx:=256;
greg.es:=seg(pal1[0,0]);
greg.dx:=ofs(pal1[0,0]);
intr($10,greg);
if (pal1[0,1]<>pal2[0,1]) or
(pal1[10,2]<>pal2[10,2]) or
(pal1[20,1]<>pal2[20,1]) or
(pal1[30,2]<>pal2[30,2]) or
(pal1[40,1]<>pal2[40,1])
then
begin
i:=-1;
repeat
inc(i);
i2:=pal1[i,0]+pal1[i,1]+pal1[i,2];
until (i=255) or (i2<6);
fillchar(mem[$a000:0000],64000,i);
end;
begin
{load palette}
greg.ax:=$1012;
greg.bx:=0;
greg.cx:=256;
greg.es:=seg(pal2[0,0]);
greg.dx:=ofs(pal2[0,0]);
intr($10,greg);
end;
{
for i:=199 downto 0 do
begin
BlockRead(bmpf,mem[$A000:i*320],320);
end;
}
for i:=199 downto 0 do
begin
move(bmptemp^[((199-i)*320)+headersize],mem[$A000:i*320],320);
end;
end
else
begin
count:=headersize;
t:=bmptemp^[count]; inc(count);
b:=t;
for i:=199 downto 0 do
for i2:=0 to 319 do
begin
if b<>t then mem[$A000:i*320 + i2]:=b;
b:=bmptemp^[count]; inc(count);
end;
end;
end; {if ioresult=0}
end;
end;
procedure picturemessage(n:word);
var j:char;pausemouse2:boolean;
begin
hidemouse;
showbmp(n,false);
if readkey=#0 then j:=readkey;
clearscreen;
fixpalette;
showmouse;
end;
procedure fadeoutpal(speed:byte);
var pal2:array[0..255,0..2] of byte;
i0,i,i1,i2:byte;
begin
writelog(0,'Fading palette');
greg.ax:=$1017;
greg.bx:=0;
greg.cx:=256;
greg.es:=seg(pal1[0,0]);
greg.dx:=ofs(pal1[0,0]);
intr($10,greg);
move(pal1[0,0],pal2[0,0],256*3);
i2:=63;
for i0:=1 to 5 do
begin
for i:=0 to 255 do for i1:=0 to 2 do
pal2[i,i1]:=round(pal1[i,i1] - (pal1[i,i1] * (i0/5)));
if speed<>0 then delay2(speed*10);
greg.ax:=$1012;
greg.bx:=0;
greg.cx:=256;
greg.es:=seg(pal2[0,0]);
greg.dx:=ofs(pal2[0,0]);
intr($10,greg);
end;
end;
{var shownHP,shownMP:boolean;}
procedure graphHP;
{ var ycou:byte;
xcou:byte; }
var s:string[8]; b:byte;
begin
if ack.hpmax[0]>1 then
begin
s:=strnum(ack.HP[0]);
while length(s)<3 do s:=' '+s;
if ack.poison>0 then s:=s+'Û2P';
say(71,140,0,s);
end;
if ack.mpmax[0]>0 then
begin
s:=strnum(ack.MP[0]);
while length(s)<3 do s:=' '+s;
say(71,149,0,s);
end;
(*
if ack.HP[0]<>ack.HPmax[0] then
begin
say(67,170,0,'H');
for ycou:=1 to 40 do
begin
if ((40-ycou)/40)*ack.HPmax[0]>ack.HP[0] then
meml[scrnl:(70*4)+scrnh[168+ycou]]:=$04040404 else
meml[scrnl:(70*4)+scrnh[168+ycou]]:=$0a0a0a0a;
end;
shownHP:=true;
end else
if shownHP then begin
say(67,170,0,' ');
for ycou:=1 to 10 do
for xcou:=0 to 3 do
meml[scrnl:xcou+(70*4)+scrnh[168+ycou]]:=lo(TEXTC0);
{blank it out}
shownHP:=false;
end;
if ack.MP[0]<>ack.MPmax[0] then
begin
say(74,170,0,'E');
for ycou:=1 to 10 do
if ((11-ycou)/10)*ack.MPmax[0]>ack.MP[0] then
meml[scrnl:(77*4)+scrnh[168+ycou]]:=$08080808 else
meml[scrnl:(77*4)+scrnh[168+ycou]]:=$09090909;
shownMP:=true;
end else
if shownMP then begin
say(74,170,0,' ');
for ycou:=1 to 10 do
for xcou:=0 to 3 do
meml[scrnl:xcou+(77*4)+scrnh[168+ycou]]:=lo(TEXTC0);
{blank it out}
shownMP:=false;
end;
*)
end;
procedure playerdeath;
begin
stopsound(0);
ack.hp[0]:=0;
graphHP;
writelog(0,'Player death');
if ack.deathmacro=0 then
begin
delay2(3000);
fadeoutpal(10);
clearscreen;
fixpalette;
say(30,80,0,'THE END.');
delay2(3000);
bottomsay(0,'PRESS A KEY TO QUIT.');
clear_keyboard_buffer;
repeat until keypressed;clear_keyboard_buffer;
halt;
end else
run_macro(ack.deathmacro);
resurrect:=true;
end;
var thingtaken:array[1..4] of byte;
procedure takething(xx,yy:byte);
var i:integer;
begin
yy:=yy*4;
for i:=yy+1 to yy+4 do
thingtaken[i-yy]:=mem[scrnl:xx+scrnh[i]];
end;
procedure replacething(xx,yy:byte);
var i:integer;
begin
yy:=yy*4;
for i:=yy+1 to yy+4 do mem[scrnl:xx+scrnh[i]]:=thingtaken[i-yy];
end;
function distance(x1,y1,x2,y2:integer):byte;
var dd:integer;
begin
x2:=x2-x1;x2:=abs(x2);
y2:=y2-y1;y2:=abs(y2);
if x2>50 then x2:=50;
if y2>50 then y2:=50;
dd:=round(sqrt( sqr(x2) + sqr(y2) ));
if dd>255 then dd:=255;
if dd<0 then dd:=255;
distance:=dd;
end;
procedure loadconfig;
var ackf:file of masterrec;i:byte;
begin
loadmapcolors;
writelog(0,'Loading config '+ADVNAME+MASTERFILE);
assign(ackf,ADVNAME+MASTERFILE);
{$I-} reset(ackf); {$I+}
if ioresult<>0 then
begin;say(1,1,0,'FILE NOT FOUND: '+ADVNAME+MASTERFILE);readln;halt;end;
read(ackf,ack);
close(ackf);
for i:=2 to 254 do
if ack.pinv[i]>0 then
case obj^[i].t of
6,7,8,9,11:begin end;
else ack.pinv[i]:=0;
end;
if ack.ackversion<25 then
begin
ack.invisible:=0;
ack.poison:=0;
ack.fly:=false; ack.nomove_n:=false;
ack.nomove_s:=false; ack.nomove_e:=false;
ack.nomove_w:=false; ack.unused:=false;
ack.splituse:=1;
for i:=8 to 26 do ack.variableshi[i]:=0;
ack.minviewdistance:=1;
ack.torchduration:=0;
ack.showclock:=0;
ack.misssound:=97;
ack.hitsound:=98;
for i:=1 to 12 do ack.qtile[i]:=0;
ack.hourmacro:=0;
ack.music:=0;
ack.darkforeground:=17;ack.darkbackground:=0;
end;
end;
procedure saveconfig;
var ackf:file of masterrec;
begin
writelog(0,'Saving config '+ADVNAME+MASTERFILE);
assign(ackf,ADVNAME+MASTERFILE);
{$I-} rewrite(ackf); {$I+}
if ioresult<>0 then exit;
write(ackf,ack);
close(ackf);
end;
procedure loadcreatures;
var cf:file of creaturerec;
csf:file of word;
i:byte;
begin
writelog(0,'Loading creatures');