-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathO_PLAY3.PAS
More file actions
2388 lines (2078 loc) · 70.9 KB
/
O_PLAY3.PAS
File metadata and controls
2388 lines (2078 loc) · 70.9 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+}
{.DEFINE DEBUG}
unit o_play3;
{Room-region procedures are in this overlay.}
interface
uses xms,u_sound,u_help,u_io,u_vars,
graph,u_graph,u_adv,crt2,dos,u_fonts,u_graps,o_play0,o_play0a,o_play1,u_delay2;
procedure getroom(n:byte);
function rtrymove(therex,therey,herex,herey,room:Byte):Byte;
procedure walkroom(var rgn,room,ydummy,x,y:byte);
implementation
var obj8,dp8:byte;
roomunder:array[1..16,1..11] of byte;
procedure getroom(n:byte);
var c1,c2:byte;
b1,b2:byte;
point,nextpoint:locpointer;
donedigging:boolean;
begin
if n>region.rooms then exit;
with region.room do
begin
roomwide:=x2[n]-x1[n]+1;roomtall:=y2[n]-y1[n]+1;
for c1:=x1[n] to x2[n] do for c2:=y1[n] to y2[n] do
begin
roomunder[c1-x1[n]+1,c2-y1[n]+1]:=0;
point:=roomloc(n,c1-x1[n]+1,c2-y1[n]+1);
if point=0 then
begin
b1:=0;
end
else
begin
b1:=locnt^[point].obj;
b2:=locnt^[point].objcode;
if (b1=255) or (obj^[b1].t>5) then
begin
donedigging:=locnt^[point].p=0;
nextpoint:=point;
while not donedigging do
begin
nextpoint:=locnt^[nextpoint].p;
if locnt^[nextpoint].p=0 then donedigging:=true;
if (locnt^[nextpoint].obj<>0) and (locnt^[nextpoint].obj<>255)
then if obj^[locnt^[nextpoint].obj].t<6 then
begin; roomunder[c1-x1[n]+1,c2-y1[n]+1]:=locnt^[nextpoint].obj; donedigging:=true; end;
end;
{writelog(0,'digging result at '+strnum(c1-x1[n]+1)+','+
strnum(c2-y1[n]+1)+' was '+strnum(roomunder[c1-x1[n]+1,c2-y1[n]+1]));}
end;
end;
map[2,2,c1-x1[n]+1,c2-y1[n]+1].o:=b1;
map[2,2,c1-x1[n]+1,c2-y1[n]+1].d:=b2;
end;
end;
end;
procedure roomloadwandering(n:byte);
var i,addslot,addslotc:integer;
creatureslot,creatureslott,laycreature:byte;
begin
for i:=1 to WANDERMAX do if wander_index^[i].x=n then
if wander_index^[i].odds>random(100) then
if locnt^[roomloc(n,wander_index^[i].xin,wander_index^[i].yin)].obj<>255 then begin
addslot:=0;
for addslotc:=1 to locntsize do
if locnt^[addslotc].obj=0 then addslot:=addslotc;
if addslot=0 then if locntsize<LOCNTMAX then
begin;addslot:=locntsize+1;inc(locntsize);end;
if addslot<>0 then
begin
creatureslot:=0;creatureslott:=0;
repeat
inc(creatureslot);
if creatureslot>RCMAX then creatureslott:=255
else if rcrc^[creatureslot].used=false then
creatureslott:=creatureslot;
until creatureslott<>0;
if creatureslott<>255 then
begin {***}
laycreature:=wander_index^[i].creature;
if laycreature<>0 then
with rcrc^[creatureslott] do
begin {*****}
{ rcrc^[creatureslott].xchunk:=xchunkloc;
rcrc^[creatureslott].ychunk:=ychunkloc; }
used:=true;show:=true;
{ obj:=map[c1,c2,wander_index^[i].xin,wander_index^[i].yin].o;
objdata:=map[c1,c2,wander_index^[i].xin,wander_index^[i].yin].d; }
crcsource:=laycreature;
hp:=crc^[laycreature].hm;
mp:=crc^[laycreature].mm;
recurring:=false;odds:=100;
motive:=0;
anger:=0;
if crc^[laycreature].t=2 then anger:=1;
if crc^[laycreature].t=4 then anger:=6;
if crc^[laycreature].t=1 then anger:=2;
talk:=0;
locnt^[addslot].p:=
rmcnt^[wander_index^[i].xin+region.room.x1[n]-1,wander_index^[i].yin+region.room.y1[n]-1];
rmcnt^[wander_index^[i].xin+region.room.x1[n]-1,wander_index^[i].yin+region.room.y1[n]-1]:=addslot;
locnt^[addslot].obj:=255;
locnt^[addslot].objcode:=creatureslott;
end; {if creature}
end; {if creature slot}
end; {if room addslot}
end; {if odds}
end;
function rtrymove(therex,therey,herex,herey,room:Byte):Byte;
var
llp:locpointer;
tmresult:byte;
tmspot:byte;
tmdata:byte;
tmst:byte;
stepclick:boolean;
begin
readkey_time:=R150;
if arcade then readkey_default:=#255 else
readkey_default:=#1;
tmresult:=0; {assume okay}
tmspot:=map[2,2,therex,therey].o;
tmdata:=map[2,2,therex,therey].d;
if tmspot<>0 then if obj^[tmspot].t<6 then if obj^[tmspot].d[8]=3 then
begin
dp8:=0;
trypassable(dp8,obj^[tmspot].d[4],obj^[tmspot].d[5]);
if dp8<>0 then tmspot:=obj^[tmspot].d[12];
end;
if tmspot<>0 then
begin
tmst:=obj^[tmspot].t;
if tmst=10 then if ack.plvehicle<>0 then tmst:=3;
if (tmst>5) and (tmst<>10) then
begin {DIG}
llp:=locnt^[roomloc(room,therex,therey)].p;
repeat
tmst:=obj^[locnt^[llp].obj].t;
if tmst<6 then
begin
tmspot:=locnt^[llp].obj;
tmdata:=locnt^[llp].objcode;
end;
llp:=locnt^[llp].p;
until (llp=0) or (tmst<6);
end;
if (tmst=3) or (tmst=4) then
tmresult:=99; {99 means impassable}
if (tmst=5) then tmresult:=5;
if tmresult<99 then
if tmst<6 then trypassable(tmresult,obj^[tmspot].d[4],obj^[tmspot].d[5]);
if tmst<6 then block_message:=obj^[tmspot].d[7] else block_message:=0;
if (tmst=5) and (tmresult<99)
then pass_message:=obj^[tmspot].d[13] else pass_message:=0;
if pass_message<>0 then shortmessage(pass_message);
actionparser(tmresult,tmspot,tmdata,room,therex,therey,herex,herey);
end else
begin
tmresult:=0;if ack.stepsound<>0 then
if (herex<>therex) or (herey<>therey) then
soundeffect(ack.stepsound,1);
end;
rtrymove:=tmresult;
end;
procedure walkroom(var rgn,room,ydummy,x,y:byte);
var j2,j:char;
steal_llp:word;
done2,done:boolean;
putgrapc:byte;
tracer:boolean;
dropping2,dropping:byte; no_drop:boolean;
llp,addslot,addslotc:locpointer;
rtryval:byte;
xmod,ymod,xorx,xory:integer;
aimxloc,aimyloc,n,xloc,yloc,xlocold,ylocold:byte;
moved,arrowmoved:boolean;
dri,dri1:integer;
dropamount:word;
weapon1n,weapon1t,weapon2n,weapon2t,maxrange,wxloc,wyloc:byte;
registerattacks:array[1..16,1..8] of byte;
regattacknum:byte;
whoops:byte;
attacker_alignment,attacker_id:byte;
hitcrc_bugfix:array[1..16,1..4] of byte;
hitcrc_bugfix_counter:byte;
newroom:boolean;
vehcount:byte;
quasimap:array[1..16,1..11] of byte;
tmspot,tmdata:byte;
procedure checkadjacent(xl,yl,dir:byte);
var roomsearch:Byte; {dir is 0 up 1 dn 2 lf 3 rt}
begin
xl:=xl-1+region.room.x1[room];
yl:=yl-1+region.room.y1[room];
{search for another room that includes those two}
for roomsearch:=1 to region.rooms do
with region.room do begin
if (x1[roomsearch]<xl) and (x2[roomsearch]>xl) and
(y1[roomsearch]<yl) and (y2[roomsearch]>yl) then
begin
case dir of
0:begin;yloc:=y2[roomsearch]-y1[roomsearch]+1;
xloc:=x1[room]+ xloc -x1[roomsearch];newroom:=true;end;
1:begin;yloc:=1;
xloc:=x1[room]+ xloc -x1[roomsearch];newroom:=true;end;
2:begin;xloc:=x2[roomsearch]-x1[roomsearch]+1;
yloc:=y1[room]+ yloc -y1[roomsearch];newroom:=true;end;
3:begin;xloc:=1;
yloc:=y1[room]+ yloc -y1[roomsearch];newroom:=true;end;
end;
room:=roomsearch;
end;
end;
end;
procedure roomprojectile(px,py:byte; var x,y:byte; skill:byte);
var rise,run,xstep,ystep,herex,herey:integer;
done:boolean;
count:integer;
shootingover:byte;
begin
writelog(0,'roomprojectile begin: '+strnum(px)+','+strnum(py)+' - '+strnum(x)+','+strnum(y));
rise:=y-py; run:=x-px;
xstep:=abs(run); ystep:=abs(rise);
if xstep=0 then xstep:=1;if ystep=0 then ystep:=1;
if xstep>ystep then ystep:=xstep else xstep:=ystep;
herex:=px*xstep; herey:=py*ystep; done:=false;
count:=0;
writelog(0,'roomprojectile: herex:'+strnum(herex)+' herey:'+strnum(herey)+
' run:'+strnum(run)+' rise:'+strnum(rise)+' xstep:'+strnum(xstep)+' ystep:'+strnum(ystep));
repeat
if (round(herex/xstep)=x) AND (round(herey/ystep)=y) then
begin;done:=true;writelog(0,'roomprojectile: arrival');end {we've arrived}
else
begin
{look at what the projectile is passing over}
shootingover:=map[2,2,round(herex/xstep),round(herey/ystep)].o;
if ( herex<>xloc*xstep ) OR ( herey<>yloc*ystep ) {make sure we've actually left home}
then
begin
{check what we are shooting over}
if shootingover<>255 then {no friendly fire, the AI isn't nearly smart enough}
if (shootingover<>0) then
begin
{it is an object...}
case obj^[shootingover].t of
1,2,5:if obj^[shootingover].d[4]>127 then begin;writelog(0,'roomprojectile: hit opaque terrain');done:=true;end;
3,4:begin;done:=true;writelog(0,'roomprojectile: hit obstacle');end;
end; {case}
end; {object}
if done then begin;x:=round(herex/xstep);y:=round(herey/ystep);end;
end; {check}
end; {look}
inc(herex,run);inc(herey,rise);
inc(count);if count>300 then done:=true;
until done;
writelog(0,'roomprojectile end: '+strnum(px)+','+strnum(py)+' - '+strnum(x)+','+strnum(y));
end;
procedure shootterrain(weapon0t,weapon0n:byte);
begin
if map[2,2,wxloc,wyloc].o<>0 then
if (obj^[map[2,2,wxloc,wyloc].o].t<6)
and (obj^[map[2,2,wxloc,wyloc].o].d[9]=11) then
if (obj^[map[2,2,wxloc,wyloc].o].d[10]=0) or (obj^[map[2,2,wxloc,wyloc].o].d[10]=weapon0n) then
do_action(obj^[map[2,2,wxloc,wyloc].o].d[2],
obj^[map[2,2,wxloc,wyloc].o].d[3],0,0,map[2,2,wxloc,wyloc].o,
map[2,2,wxloc,wyloc].d,room,wxloc,wyloc);
if map[2,2,wxloc,wyloc].o<>0 then
if (obj^[weapon0n].d[4]>=obj^[map[2,2,wxloc,wyloc].o].d[11])
AND (obj^[map[2,2,wxloc,wyloc].o].t<6) AND
(obj^[map[2,2,wxloc,wyloc].o].d[11]<>0) then
begin
{process terrain destruction}
if obj^[map[2,2,wxloc,wyloc].o].d[8]>5 then begin
writelog(obj^[map[2,2,wxloc,wyloc].o].d[8]-5,'Running terrain death macro');
run_macro(obj^[map[2,2,wxloc,wyloc].o].d[8]-5);
end;
if obj^[map[2,2,wxloc,wyloc].o].d[12]=0 then
begin
llp:=roomloc(room,wxloc,wyloc);
locnt^[llp].obj:=0;
rmcnt^[wxloc+region.room.x1[room]-1,
wyloc+region.room.y1[room]-1]:=locnt^[llp].p;
if llp=locntsize then dec(locntsize);
getroom(room);moved:=true;
{eliminate}
end else
begin
llp:=roomloc(room,wxloc,wyloc);
locnt^[llp].obj:=obj^[map[2,2,wxloc,wyloc].o].d[12];
getroom(room);moved:=true;
{replace with...}
end;
end;
end;
function hitcreature(weapon0t,weapon0n,skill:byte):boolean;
var who:byte;
i:integer;
damage:integer;
dropcount:integer;
hitpoints:integer;
addslotc:integer;
begin
damage:=0;
{process weapon damage}
if weapon0n<>0 then hitpoints:=obj^[weapon0n].d[4] {base damage}
else hitpoints:=0;
i:=skill; {skill from 1-100 is chance of hitting for that damage}
i:=skill; {skill from 1-100 is chance of hitting for that damage}
if i>random(100) then damage:=random(hitpoints)+1;
{skill from 101-200 is chance of hitting for double damage}
if skill>100 then i:=skill-100 else i:=0;
if i>random(100) then damage:=damage*2;
{skill from 201+ is chance of hitting for quadruple damage}
if skill>200 then i:=skill-200 else i:=0;
if i>random(100) then damage:=damage*2;
hitcreature:=false;
if map[2,2,wxloc,wyloc].o=255 then
begin {target is a creature}
hitcreature:=true;
chunksave:=true;
who:=map[2,2,wxloc,wyloc].d;
if crc^[rcrc^[who].crcsource].hm=0 then exit;
if attacker_alignment=5 then
begin
if oops_i_missed then
begin {i missed}
if crc^[rcrc^[who].crcsource].t<>ack.alignment then
if random(2)=0 then rcrc^[who].anger:=5;
end else
begin {deliberate shot}
soundeffect(hi(crcsounds[rcrc^[who].crcsource]),1);
if crc^[rcrc^[who].crcsource].t=ack.alignment then
ack.criminal:=ack.alignment else rcrc^[who].anger:=5;
end; {if missed}
end {if attacker is player}
else
if ((rcrc^[who].anger=attacker_alignment) or (rcrc^[who].anger=0))
then
begin {not angry, or already angry}
rcrc^[who].anger:=attacker_alignment;
end else
if (random(4)=0) then {angry at someone else}
if crc^[rcrc^[who].crcsource].t<>1 then
rcrc^[who].anger:=attacker_alignment; {if not good, then maybe go berserk}
if random(4)=0 then
soundeffect(hi(crcsounds[rcrc^[who].crcsource]),1); {make attack sound}
{if creature has armor, process it}
if crc^[rcrc^[who].crcsource].ar<>0 then
with crc^[rcrc^[who].crcsource] do
if
( obj^[ar].d[6] > random(100) ) then
begin;damage:=damage-obj^[ar].d[5];if damage<0 then damage:=0;end;
{if creature is invulnerable, damage becomes zero}
if crc^[rcrc^[who].crcsource].hm=0 then damage:=0;
if rcrc^[who].hp>crc^[rcrc^[who].crcsource].hm then rcrc^[who].hp:=crc^[rcrc^[who].crcsource].hm;
{if damage has become zero, this is a miss; play the sound}
hitpoints:=rcrc^[who].hp-damage;
if attacker_alignment=5 then
begin {messages indicating you are the attacker}
if damage>0 then
begin
soundeffect(ack.hitsound,1);
scrollsay('YOU HIT '+crc^[rcrc^[who].crcsource].n+' FOR '+strnum(damage)+' DAMAGE!');
delay2(combatpacing*3);
if hitpoints<=0 then
begin
scrollsay(crc^[rcrc^[who].crcsource].n+' HAS BEEN KILLED!');
soundeffect(lo(crcsounds[rcrc^[who].crcsource]),1); {play death sound}
delay2(combatpacing*3);
end;
delay2(combatpacing*3);
end
else
begin
scrollsay('YOU ATTACK '+crc^[rcrc^[who].crcsource].n+', BUT MISS!');
soundeffect(ack.misssound,1);delay(500);
end;
end else
begin {messages indicating hot NPC on NPC action}
if damage>0 then
begin
soundeffect(ack.hitsound,1);
scrollsay(crc^[attacker_id].n+' HITS '+crc^[rcrc^[who].crcsource].n+' FOR '+strnum(damage)+' DMG');
delay2(combatpacing*5);
if hitpoints<=0 then
begin
scrollsay(crc^[rcrc^[who].crcsource].n+' HAS BEEN KILLED!');
soundeffect(lo(crcsounds[rcrc^[who].crcsource]),1); {play death sound}
delay2(combatpacing*5);
end;
end;
end;
if hitpoints<=0 then
begin
if ack.ackversion>24 then
{ if attacker_alignment=ack.alignment then }
with crc^[rcrc^[who].crcsource] do ack.experience:=ack.experience+ ((exphi-1)*256 + exp);
soundeffect(lo(crcsounds[rcrc^[who].crcsource]),1);
xmod:=wxloc;ymod:=wyloc;
rcrc^[who].show:=false;if not rcrc^[who].recurring then
rcrc^[who].used:=false;
{remove creature}
locnt^[rmcnt^[xmod+region.room.x1[room]-1,ymod+region.room.y1[room]-1]].obj:=0;
rmcnt^[xmod+region.room.x1[room]-1,ymod+region.room.y1[room]-1]:=
locnt^[rmcnt^[xmod+region.room.x1[room]-1,ymod+region.room.y1[room]-1]].p;
{drop inventory, if any}
for i:=3 downto 1 do if crc^[rcrc^[who].crcsource].inv[i]<>0 then
with crc^[rcrc^[who].crcsource] do
if (obj^[inv[i]].t<6) or (inv[i]=1) or ((random(100)<invn[i]) or (ack.ackversion<31)) then
{if terrain, or money, or random chance}
begin
dropping:=inv[i];
if (dropping<>1) and (obj^[dropping].t>5) then dri:=1 else dri:=invn[i];
addslot:=0;
if locntsize>5000 then
begin
{search for empty slot}
for addslotc:=1 to locntsize do
if locnt^[addslotc].obj=0 then addslot:=addslotc;
end;
if addslot=0 then if locntsize<LOCNTMAX then
begin;addslot:=locntsize+1;inc(locntsize);end;
if addslot<>0 then
begin
locnt^[addslot].p:=
rmcnt^[xmod+region.room.x1[room]-1,ymod+region.room.y1[room]-1];
rmcnt^[xmod+region.room.x1[room]-1,ymod+region.room.y1[room]-1]:=addslot;
locnt^[addslot].obj:=dropping;
locnt^[addslot].objcode:=dri;
end;
end;
{draw what's really there}
getroom(room);moved:=true;
if crc^[rcrc^[who].crcsource].deathm<>0 then
if ack.ackversion>11 then run_macro(crc^[rcrc^[who].crcsource].deathm);
end else rcrc^[who].hp:=hitpoints;
end else
if (wxloc=xloc) and (wyloc=yloc) then
begin {target is the player}
{process armor damage absorb}
for i:=1 to 7 do {for each slot}
if ack.parmor[i]<>0 then {if wearing armor}
if ack.countarmor[i]=0 then {and its not disabled}
if ( obj^[ack.parmor[i]].d[6] > random(100) ) then {and random coverage}
damage:=damage-obj^[ack.parmor[i]].d[5]; {then absorb damage}
if damage<0 then damage:=0;
hitpoints:=ack.hp[0]-damage; {inflict damage}
{sound effect}
if damage>0 then
begin
soundeffect(ack.hitsound,1);
scrollsay(crc^[attacker_id].n+' HITS YOU FOR '+strnum(damage)+' DAMAGE!');
if crc^[rcrc^[who].crcsource].touchm<>0 then
if weapon0t=7 then
if ack.ackversion>=30 then run_macro(crc^[rcrc^[who].crcsource].touchm);
delay2(combatpacing*5);
if hitpoints<=0 then scrollsay('YOU HAVE BEEN KILLED!');
end else
begin
scrollsay(crc^[attacker_id].n+' ATTACKS YOU AND MISSES!');
soundeffect(ack.misssound,1);delay(500);
end;
if hitpoints<=0 then hitpoints:=0;
ack.hp[0]:=hitpoints;
graphHP;
chunksave:=true;
hitcreature:=true;
end; {target is player}
erasebottom:=1;
end;
procedure resolve_rangedweapon(weapon0t,weapon0n,skill:byte);
var
Conecounter,old_wxloc,old_wyloc,wxloc2,wyloc2:byte;
wxlocc_begin,wxlocc_end,wylocc_begin,wylocc_end,wxlocc,wylocc:byte;
begin
old_wxloc:=wxloc;old_wyloc:=wyloc;
if weapon0t=8 then
if obj^[weapon0n].d[5] DIV 16<11 then
begin
wxloc2:=wxloc;wyloc2:=wyloc;
{ if (distance(aimxloc,aimyloc,wxloc,wyloc)>1) then}
for wxlocc:=wxloc2+10 to wxloc2+30 do
for wylocc:=wyloc2+10 to wyloc2+30 do
begin
wxloc:=wxlocc-20;wyloc:=wylocc-20;
if (wxloc>=1) and (wyloc>=1) and
(wxloc<=roomwide) and (wyloc<=roomtall) then
if distance(wxloc2,wyloc2,wxloc,wyloc)<=obj^[weapon0n].d[5] DIV 16
then begin
showweapon(weapon0t,weapon0n,aimxloc,aimyloc,wxloc,wyloc,roomwide,roomtall);
if not hitcreature(weapon0t,weapon0n,skill)
then shootterrain(weapon0t,weapon0n);
{process ranged weapon 1}
end;
end; { else if attacker_alignment=5 then adjacent_error;}
end else
if (xmod<>0) or (ymod<>0) then begin
wxloc:=aimxloc;wyloc:=aimyloc;
wxloc2:=wxloc;wyloc2:=wyloc;
wxlocc_begin:=20;
wxlocc_end:=20;
wylocc_begin:=20;
wylocc_end:=20;
for conecounter:=0 to obj^[weapon0n].d[5] MOD 16 do
begin
wxloc2:=aimxloc+(xmod*(conecounter+1));
wyloc2:=aimyloc+(ymod*(conecounter+1));
if obj^[weapon0n].d[5] DIV 16 = 12 then
begin
if ymod<>0 then
begin
wxlocc_begin:=20-conecounter;
wxlocc_end:=20+conecounter;
end;
if xmod<>0 then begin
wylocc_begin:=20-conecounter;
wylocc_end:=20+conecounter;
end;
end;
for wxlocc:=(wxlocc_begin) to (wxlocc_end) do
for wylocc:=(wylocc_begin) to (wylocc_end) do
begin
wxloc:=wxloc2+wxlocc-20;
wyloc:=wyloc2+wylocc-20;
if (wxloc>=1) and (wyloc>=1) and
(wxloc<=roomwide) and (wyloc<=roomtall) then
if distance(aimxloc,aimyloc,wxloc,wyloc)-1<=obj^[weapon0n].d[5] MOD 16 then
begin
roomprojectile(aimxloc,aimyloc,wxloc,wyloc,skill);
showweapon(weapon0t,weapon0n,aimxloc,aimyloc,wxloc,wyloc,roomwide,roomtall);
if not hitcreature(weapon0t,weapon0n,skill)
then shootterrain(weapon0t,weapon0n);
end;
end;
end;
wxloc:=old_wxloc;wyloc:=old_wyloc;
end;
sounded:=false;
delay2(combatpacing);
end;
procedure attacking(ttxloc,ttyloc,ttwxloc,ttwyloc,
ttweapon1n,ttweapon2n,skill:byte);
begin
aimxloc:=ttxloc;
aimyloc:=ttyloc;
wxloc:=ttwxloc;
wyloc:=ttwyloc;
weapon1n:=ttweapon1n;weapon2n:=ttweapon2n;
if weapon1n=0 then weapon1t:=0
else weapon1t:=obj^[weapon1n].t;
if weapon2n=0 then weapon2t:=0
else weapon2t:=obj^[weapon2n].t;
if (weapon1n=0) and (weapon2n=0) then exit;
sounded:=false;
roomprojectile(aimxloc,aimyloc,wxloc,wyloc,skill);
{process ranged weapons}
resolve_rangedweapon(weapon1t,weapon1n,skill);
sounded:=false;
aimxloc:=ttxloc;
aimyloc:=ttyloc;
wxloc:=ttwxloc;
wyloc:=ttwyloc;
weapon2n:=ttweapon2n;
if weapon2n=0 then weapon2t:=0
else weapon2t:=obj^[weapon2n].t;
roomprojectile(aimxloc,aimyloc,wxloc,wyloc,skill);
resolve_rangedweapon(weapon2t,weapon2n,skill);
if ((wxloc<>aimxloc) or (wyloc<>aimyloc)) then begin
if weapon1t=7 then
begin
aimxloc:=ttxloc;
aimyloc:=ttyloc;
wxloc:=ttwxloc;
wyloc:=ttwyloc;
weapon1n:=ttweapon1n;
if weapon1n=0 then weapon1t:=0
else weapon1t:=obj^[weapon1n].t;
showweapon(weapon1t,weapon1n,aimxloc,aimyloc,wxloc,wyloc,roomwide,roomtall);
inverttarget(wxloc,wyloc,roomwide,roomtall);
if not hitcreature(weapon1t,weapon1n,skill)
then shootterrain(weapon1t,weapon1n);
inverttarget(wxloc,wyloc,roomwide,roomtall);
{process melee weapon 1}
end;
if weapon2t=7 then
begin
aimxloc:=ttxloc;
aimyloc:=ttyloc;
wxloc:=ttwxloc;
wyloc:=ttwyloc;
weapon2n:=ttweapon2n;
if weapon2n=0 then weapon2t:=0
else weapon2t:=obj^[weapon2n].t;
showweapon(weapon2t,weapon2n,aimxloc,aimyloc,wxloc,wyloc,roomwide,roomtall);
inverttarget(wxloc,wyloc,roomwide,roomtall);
if not hitcreature(weapon2t,weapon2n,skill)
then shootterrain(weapon2t,weapon2n);
inverttarget(wxloc,wyloc,roomwide,roomtall);
{process melee weapon 2}
end;
end;
end;
procedure maponly(room,px,py:byte);
var putgrapc,x,y:byte;
shadowing:byte;
creatureslot:byte;
oldspot:byte;
rise,run,herex,herey,xystep:integer;
xstep,ystep:shortint;
done,opaque:boolean;
limit_found,two_found:boolean;
two_x,two_y:byte;
attacktaken:boolean;
shadowscan:Array[1..16,1..11] of byte;
var motionx,motiony,attacklocx,attacklocy:byte; {what it would like to do}
found,fight:boolean;
var movedindex:byte;
foundrange:integer;
longisbest:boolean;
function checkdest(xscc,yscc:integer;who:byte):boolean;
var
mapobj,mapobjdata,creaturevehicle:byte;
passable:boolean;
point,nextpoint:word;
donedigging:boolean;
{$I I_CHKDST.PAS} {the same code is used by wmap and room regions}
begin
mapobj:=map[2,2,xscc,yscc].o;
mapobjdata:=map[2,2,xscc,yscc].d;
creaturevehicle:=crc^[rcrc^[who].crcsource].veh;
if (mapobj=255) or (obj^[mapobj].t>5) then
begin
if mapobj<>255 then mapobj:=0;
point:=locnt^[roomloc(room,xscc,yscc)].p;
donedigging:=(locnt^[point].p=0);
nextpoint:=point;
while not donedigging do
begin
nextpoint:=locnt^[nextpoint].p;
if locnt^[nextpoint].p=0 then donedigging:=true;
if (locnt^[nextpoint].obj<>0) and (locnt^[nextpoint].obj<>255)
then if obj^[locnt^[nextpoint].obj].t<6 then
begin; mapobj:=locnt^[nextpoint].obj; donedigging:=true; end;
end;
end;
{perform the actual check... }
if (xscc>=roomwide) or (xscc<=1) or (yscc<=1) or (yscc>=roomtall) then passable:=false else
passable:=checkdest2(mapobj,creaturevehicle);
{one final check: make sure they're not trying to step on the player!}
if (xscc=xloc) and (yscc=yloc) then passable:=false;
{return the result}
checkdest:=passable;
end;
procedure movecreature(xsc,ysc,xscc,yscc:integer);
var cnum:byte;
addslotc:integer;
buffer_p:word;
begin
cnum:=map[2,2,xsc,ysc].d;
{$IFDEF DEBUG}
writeln(printer,'Moving creature: from ',xsc,',',ysc,' to ',xscc,',',yscc);
{$ENDIF}
if movedindex=creaturemoved[cnum] then exit;
CHUNKSAVE:=true;
creaturemoved[cnum]:=movedindex; {prevents double moves}
{restore footpad}
xmod:=xsc;ymod:=ysc;
{find inital pointer, store in buffer}
buffer_p:=rmcnt^[xmod+region.room.x1[room]-1,ymod+region.room.y1[room]-1];
{set inital pointer to what's under the creature}
rmcnt^[xmod+region.room.x1[room]-1,ymod+region.room.y1[room]-1]:=
locnt^[buffer_p].p;
{set creature's pointer to the new space's initial pointer}
locnt^[buffer_p].p:=
rmcnt^[xscc+region.room.x1[room]-1,yscc+region.room.y1[room]-1];
{set new space's initial pointer to the creature}
rmcnt^[xscc+region.room.x1[room]-1,yscc+region.room.y1[room]-1]:=
buffer_p;
moved:=true;getroom(room);
end;
procedure scanalign(anger,crcalign:byte;var ax,ay:byte;this_crcsource:byte);
var xloop,yloop:byte;
myx,myy:byte;
begin
{ you are xinloc+15, yinloc+15 }
writelog(0,'scanalign '+strnum(this_crcsource)+' anger: '+strnum(anger)+' crcalign: '+
strnum(crcalign)+' ack.align: '+strnum(ack.alignment)+' ack.crim: '+strnum(ack.criminal));
myx:=x;
myy:=y;
found:=false;
foundrange:=32760;
if anger=0 then exit;
if (anger>4) or (anger=ack.alignment) or (ack.criminal=crcalign) then
if (ack.hp[0]>0) and (ack.invisible=0) and (resurrect=false) then
begin
{if random(6)<4 then
soundeffect(hi(crcsounds[rcrc^[this_crcsource].crcsource]));}
found:=true;
ax:=xloc;
ay:=yloc;
foundrange:=round(1000*sqrt(sqr(ax-myx)+sqr(ay-myy)));
end;
{$IFDEF DEBUG}
write(printer,'Scanning. MyLoc=',myx,',',myy,'. YourLoc=',xloc,',',yloc,
' Anger=',anger,'. ');
{$ENDIF}
for xloop:=1 to roomwide do
for yloop:=1 to roomtall do
if (map[2,2,xloop,yloop].o=255) then
if (round(1000*sqrt(sqr(xloop-myx)+sqr(yloop-myy)))<foundrange)
and (((myx=xloop) and (myy=yloop))=false) then
begin
if (crc^[rcrc^[map[2,2,xloop,yloop].d].crcsource].t=anger)
or (anger=6) and
(rcrc^[map[2,2,xloop,yloop].d].crcsource<>this_crcsource)
then
begin
found:=true;
ax:=xloop;
ay:=yloop;
foundrange:=round(1000*sqrt(sqr(xloop-myx)+sqr(yloop-myy)));
end;
{check creature}
end;
end;
var xmotion,ymotion:integer;
nowviewdistance,xlit,ylit:byte;
begin
aggro:=0;
anim_tall:=roomtall;anim_wide:=roomwide;
shadowing:=region.shadow;
movedindex:=random(256);
regattacknum:=1;
for x:=1 to roomwide do for y:=1 to roomtall do anim_screen[x,y].aggro:=false;
for x:=1 to roomwide do for y:=1 to roomtall do
if map[2,2,x,y].o=255
{************}
then with rcrc^[map[2,2,x,y].d] do
begin
scanalign(anger,crc^[crcsource].t,attacklocx,attacklocy,crcsource);
{$IFDEF DEBUG}
if not found then writeln(printer,'Nothing found.') else
writeln(printer,'Target at ',attacklocx,',',attacklocy,'.');
{$ENDIF}
if found then
with crc^[crcsource] do begin
anim_screen[x,y].aggro:=true;
writelog(199,'processing aggro for '+n+' (#'+strnum(crcsource)+') at range '+strnum(foundrange));
attacker_alignment:=t;
attacker_id:=crcsource;
inc(aggro);
{enemy found. determine action}
fight:=false;
if (motive=2) or (motive=130) {oops, old bug fix}
then fight:=true {stop: hammer time. can't move. try firing}
else
begin
if (fw<>0) and (fr<>0) then
if u_vars.obj^[fw].d[4]>u_vars.obj^[fr].d[4] then
longisbest:=false else longisbest:=true;
if random(3)=1 then longisbest:=true;
if random(4)=1 then longisbest:=false;
if fr=0 then longisbest:=false;
if fw=0 then longisbest:=true;
if ((u_vars.obj^[fr].d[5] MOD 16)+1)*1000 < foundrange then longisbest:=false; {fix for NPCs ignoring range}
if ( (foundrange<=1000) and (not longisbest) ) or
( (foundrange>1) and (longisbest) ) then fight:=true;
{consider motion. if not moving, set fight:=true.}
end;
if creaturemoved[map[2,2,x,y].d]=movedindex
then fight:=false;
if not fight then
begin
writelog(199,'creature is moving');
xmotion:=0;ymotion:=0;
if x>xloc then xmotion:=-1;
if x<xloc then xmotion:=1;
if y>yloc then ymotion:=-1;
if y<yloc then ymotion:=1;
if (longisbest) and (foundrange<3000) then
begin;xmotion:=-xmotion;ymotion:=-ymotion;end;
if (ymotion<>0) and (xmotion<>0) then
if random(2)=1 then ymotion:=0 else xmotion:=0;
if checkdest(x+xmotion,y+ymotion,map[2,2,x,y].d) then
movecreature(x,y,x+xmotion,y+ymotion)
else begin;fight:=true;writelog(0,'cannot move, will try fighting');end;
{do motion}
end;
if fight then
begin
writelog(199,'creature is fighting');
if ((foundrange>1) AND (fr<>0)) or ((foundrange<=1000) AND (fw<>0)) then
begin
if foundrange>1000 then whoops:=rws else whoops:=ws; if fw=0 then whoops:=rws;
(* if random(whoops)<OOPS then
case random(4) of
0:dec(attacklocx);
1:dec(attacklocy);
2:inc(attacklocx);
3:inc(attacklocy);
end; {whoops} *)
registerattacks[regattacknum,8]:=crcsource;
registerattacks[regattacknum,1]:=x;
registerattacks[regattacknum,2]:=y;
registerattacks[regattacknum,3]:=attacklocx;
registerattacks[regattacknum,4]:=attacklocy;
if (foundrange<=1000) and (fw<>0) then
registerattacks[regattacknum,5]:=fw else
registerattacks[regattacknum,5]:=0;
if (foundrange>1000) or (fw=0) then
registerattacks[regattacknum,6]:=fr else
registerattacks[regattacknum,6]:=0;
registerattacks[regattacknum,7]:=whoops;
if regattacknum<16 then inc(regattacknum);
creaturemoved[map[2,2,x,y].d]:=movedindex;
{fire weapon}
end;
end;
end {determine} else
if motive=0 then
case random(8) of
1:if checkdest(x-1,y,map[2,2,x,y].d) then movecreature(x,y,x-1,y);
2:if checkdest(x+1,y,map[2,2,x,y].d) then movecreature(x,y,x+1,y);
3:if checkdest(x,y-1,map[2,2,x,y].d) then movecreature(x,y,x,y-1);
4:if checkdest(x,y+1,map[2,2,x,y].d) then movecreature(x,y,x,y+1);
end; {rnd8 case}