-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEncounter.pas
3256 lines (2602 loc) · 108 KB
/
Encounter.pas
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
(*
Copyright (C) 2024 Jeffrey Getzin.
Licensed under the GNU General Public License v3.0 with additional terms.
See the LICENSE file in the repository root for details.
*)
[Inherit ('SYS$LIBRARY:STARLET','Types','SMGRTL','StrRtl','PriorityQueue')]Module Encounter;
{ This is the main module for combat. It handles all phases of combat,
including treasure and fleeing. }
Const
MonY = 2; MonX = 26;
SpellsY = 7; SpellsX = 26;
ViewY = 2; ViewX = 2;
ZeroOrd = Ord ('0');
Cler_Spell = 1; Wiz_Spell = 2;
Type
Place_Ptr = ^Place_Node;
Place_Node = Record
PosX: Horizontal_Type;
PosY: Horizontal_Type;
PosZ: Vertical_Type;
Next: Place_Ptr;
End;
Place_Stack = Record
Front: Place_Ptr;
Length: Integer;
End;
ClassSet = Set of Item_Type;
Spell_List = Packed Array [1..9] of Set of Spell_Name;
Var
Bool_String : Array [Boolean] of Line;
Show_Messages : Boolean;
Keyboard,Pasteboard,FightDisplay,CharacterDisplay : [External]Unsigned;
MonsterDisplay,CommandsDisplay,ViewDisplay : [External]Unsigned;
MessageDisplay,SpellsDisplay : [External]Unsigned;
SpellListDisplay,OptionsDisplay : [External]Unsigned;
WizSpells,ClerSpells : [External]Spell_List;
Spell : [External]Array [Spell_Name] of Varying [4] of Char;
Maze : [External]Level;
PosX,PosY : [External]Horizontal_Type;
PosZ : [External]Vertical_Type;
Leave_Maze : [External]Boolean;
Delay_Constant : [External]Real;
Party_Spell,Person_Spell,Caster_Spell,All_Monsters_Spell,Group_Spell,Area_Spell: [External]Set of Spell_Name;
Item_List : [External]List_of_Items;
Pics : [External]Pic_List;
Places : [External]Place_Stack;
Time_Stop_Monsters,Time_Stop_Players : [Global]Boolean;
Encounter_Spells : Set of Spell_Name;
Silenced,Can_Attack : [Global]Party_Flag;
NotSurprised,Yikes,NoMagic : [Global]Boolean;
Bells_On : [External,Volatile]Boolean;
Value
Bool_String[True]:='On'; Bool_String[False]:='Off';
(******************************************************************************)
[External]Function Get_Num (Display: Unsigned): Integer;External;
[External]Procedure Cursor;External;
[External]Procedure No_Cursor;External;
[External]Function Make_Choice (Choices: Char_Set; Time_Out: Integer:=-1;
Time_Out_Char: Char:=' '): Char;External;
[External]Function Yes_or_No (Time_Out: Integer:=-1;
Time_Out_Char: Char:=' '): [Volatile]Char;External;
[External]Function Zero_Through_Six (Var Number: Integer; Time_Out: Integer:=-1; Time_Out_Char: Char:='0'): Char;External;
[External]Function Pick_Character_Number (Party_Size: Integer; Current_Party_Size: Integer:=0;
Time_Out: Integer:=-1; Time_Out_Char: Char:='0'): [Volatile]Integer;External;
[External]Procedure Ring_Bell (Display_Id: Unsigned; Number_of_Times: Integer:=1);External;
[External]Function Roll_Die (Die_Type: Integer): [Volatile]Integer;External;
[External]Function Random_Number (Die: Die_Type): [Volatile]Integer;External;
[External]Function Regenerates (Character: Character_Type; PosZ: Integer:=0): Integer;external;
[External]Function Alive (Character: Character_Type): Boolean;external;
[External]Function Made_Roll (Needed: Integer): [Volatile]Boolean;external;
[External]Procedure Delay (Seconds: Real);External;
[External]Function String(Num: Integer; Len: Integer:=0):Line;External;
[External]Function Compute_Party_Size (Member: Party_Type; Party_Size: Integer): Integer;External;
[External]Procedure Print_Party_Line (Member: Party_Type; Party_Size,Position: Integer);External;
[External]Procedure Time_Effects (Position: Integer; Var Member: Party_Type; Party_Size: Integer);External;
[External]Procedure Dead_Character (Position: Integer; Var Member: Party_Type; Party_Size: Integer);External;
[External]Function Empty (A: PriorityQueue): Boolean;External;
[External]Procedure MakeNull (Var A: PriorityQueue);External;
[External]Function P (A: AttackerType): Integer;External;
[External]Procedure Insert (X: AttackerType; Var A: PriorityQueue);External;
[External]Function DeleteMin (Var A: PriorityQueue): AttackerType;External;
[External]Function Read_Items: [Volatile]List_of_Items;External;
(******************************************************************************)
Function Insane_Leader (Party: Party_Type; Var Name: Line): Boolean;
Begin { Insane Leader }
If Party[1].Status=Insane then
Begin
Name:=Party[1].Name;
Insane_Leader:=True;
End
Else
Insane_Leader:=False;
End; { Insane Leader }
(******************************************************************************)
Function Party_Dead (Party: Party_type; Size: Integer): Boolean;
{ This function will return TRUE if every member in the party is dead, and FALSE otherwise }
Var
Temp: Boolean;
Index: Integer;
Begin { Party Dead }
Temp:=False;
Index:=0;
{ Repeat until all members checked or one living found }
Repeat
Begin
Index:=Index + 1;
Temp:=Temp or Alive (Party[Index]);
End;
Until Temp or (Index=6);
Party_Dead:=Not Temp;
End; { Party Dead }
(******************************************************************************)
[Global]Function Monster_Name (Monster: Monster_Record; Number: Integer; Identified: Boolean): Monster_Name_Type;
{ This function returns the name of the monster as influenced by whether or not the monsters have been identified, and whether there
is just one, or many. }
Begin { Monster Name }
If Identified then { If the monster is known... }
If Number>1 then { and there's more than one.... }
Monster_Name:=Monster.Real_Plural { Use the correct plural name }
Else
Monster_Name:=Monster.Real_Name { Otherwise use the correct singular name }
Else { Otherwise, if it isn't known... }
If Number>1 then { and there's more than one.... }
Monster_Name:=Monster.Plural { Use the unidentified plural name }
Else
Monster_Name:=Monster.Name; { Otherwise use the unidentified singular name }
End; { Monster Name }
(******************************************************************************)
[Global]Procedure Slay_Character (Var Character: Character_Type; Var Can_Attack: Flag);
{ This procedure kills CHARACTER, if he or she is not already dead }
Begin { Slay Character }
If Not (Character.Status in [Dead,Ashes,Deleted]) then
Begin
Character.Regenerates:=0; Character.Armor_Class:=12; Character.Status:=Dead; Character.Curr_HP:=0;
Can_Attack:=False;
SMG$Put_Line (MessageDisplay,
Character.Name
+' is slain!',0,1);
Ring_Bell (MessageDisplay,3);
End;
End; { Slay Character }
(******************************************************************************)
Function Update_Can_Attacks (Member: Party_Type; Party_Size: Integer): Party_Flag;
{ This procedure will determine who in the party can still attack }
Var
Individual: Integer;
Can_Attack: Party_Flag;
Begin { Update Can Attacks }
For Individual:=1 to Party_Size do
Can_Attack[Individual]:=(Member[Individual].Status in [Healthy,Poisoned,Zombie]);
Update_Can_Attacks:=Can_Attack;
End; { Update Can Attacks }
(******************************************************************************)
Procedure Combat_Message;
{ Print "An encounter..." on the screen }
Begin { Combat Message }
SMG$Begin_Display_Update (MessageDisplay);
SMG$Erase_Display (MessageDisplay);
SMG$Put_Chars (MessageDisplay, 'An encounter...',2,1,,1);
SMG$End_Display_Update (MessageDisplay);
Delay (2);
End; { Combat Message }
(******************************************************************************)
Procedure Compute_AC_And_Regenerates (Var Character: Character_Type);
[External]Function Compute_AC (Character: Character_Type; PosZ: Integer:=0): Integer;external;
Begin { Compute AC and Regenerates }
Character.Armor_Class:=Compute_AC(Character,PosZ);
Character.Regenerates:=Regenerates(Character,PosZ);
End; { Compute AC and Regenerates }
(******************************************************************************)
Procedure Initialize_Character (Var Character: Character_Type; Position: Integer);
Begin { Initialize Character }
Compute_AC_And_Regenerates (Character);
Character.Attack.Berserk:=False;
Silenced[Position]:=False
End; { Initialize Character }
(******************************************************************************)
Procedure Initialize (Var Member: Party_Type; Var Current_Party_Size: Party_Size_Type; Party_Size: Integer;
Var Can_Attack: Party_Flag; Var Alarm_Off: Boolean; Time_Delay: Integer);
{ This procedure initializes the encounter module. }
Var
Character: Integer;
Begin { Initialize }
Combat_Message;
Show_Messages:=True;
{ Establish the delay constant for pacing messages }
Delay_Constant:=Time_Delay/500;
{ Initialize some displays }
SMG$Create_Virtual_Display (22,78,SpellListDisplay,1);
SMG$Erase_Display (SpellListDisplay);
Encounter_Spells := Party_Spell + Person_Spell + Caster_Spell + All_Monsters_Spell + Group_Spell + Area_Spell;
Can_Attack:=Update_Can_Attacks (Member,Party_Size);
Time_Stop_Monsters:=False; Time_Stop_Players:=False;
For Character:=1 to Current_Party_Size do
Initialize_Character(Member[Character],Character);
Alarm_Off:=False; NotSurprised:=False;
Yikes:=False;
End; { Initialize }
(******************************************************************************)
Procedure Switch_Characters (Character1,Character2: Integer; Var Member: Party_Type; Var Can_Attack: Party_Flag);
{ This function switches the positions of two characters in the party. Notice that, in case of a silenced person, it is
not the person that is silenced, but the area occupied by the person. Therefore, if a non-silenced person person switches with
a silenced person, the non-silenced person becomes silenced and visa versa. }
Var
Temp: Character_Type;
Temp1: Boolean;
Begin { Switch Characters }
Temp:=Member[Character1];
Member[Character1]:=Member[Character2];
Member[Character2]:=Temp;
Temp1:=Can_Attack[Character1];
Can_Attack[Character1]:=Can_Attack[Character2];
Can_Attack[Character2]:=Temp1;
End; { Switch Character }
(******************************************************************************)
Procedure Berserk_Characters (Var Member: Party_Type; Current_Party_Size: Party_Size_Type; Var Can_Attack: Party_Flag);
{ This procedure will advance a berserk character in the ranks }
Var
Loop: Integer;
Begin { Berserk Characters }
For Loop:=2 to Current_Party_Size do
If (Member[Loop].Status in [Healthy,Poisoned]) and Member[Loop].Attack.Berserk then
Switch_Characters (Loop,Loop-1,Member,Can_Attack);
End; { Berserk Characters }
(******************************************************************************)
Function Need_to_Switch_Characters (Character2,Character1: Status_Type):Boolean;
Var
Temp: Boolean;
Begin { Need to Switch Characters }
Temp:=False;
Case Character2 of
Healthy,Poisoned,Zombie: Temp:=Not (Character1 in [Insane,Healthy,Poisoned,Zombie]);
Asleep: Temp:=Not(Character1 in [Zombie,Insane,Healthy,Poisoned,Asleep]);
Petrified,Paralyzed: Temp:=Character1 in [Dead,Ashes,Deleted];
Dead,Ashes,Deleted: Temp:=False;
Insane: Temp:=True;
Afraid: Temp:=Not (Character1 in [Zombie,Insane,Healthy,Poisoned,Afraid,Paralyzed,Petrified]);
Otherwise Temp:=False;
End;
Need_To_Switch_Characters:=Temp;
End; { Need to Switch Characters }
(******************************************************************************)
[Global]Procedure Dead_Characters (Var Member: Party_Type; Var Current_Party_Size: Party_Size_Type; Party_Size: Integer;
Var Can_Attack: Party_Flag);
{ This procedure will move dead characters and/or inactive characters to the back of the party. The algorithm is basically a
bubblesort, which is O(n^2), but since there are most six slots, the time is negligable. }
Var
Done: Boolean;
Loop: Integer;
Begin { Dead Characters }
Can_Attack:=Update_Can_Attacks (Member,Party_Size);
Repeat
Begin
Done:=True;
For Loop:=Party_Size downto 2 do
If Need_to_Switch_Characters (Member[Loop].Status,Member[Loop-1].Status) then
Begin
Switch_Characters (Loop,Loop-1,Member,Can_Attack);
Done:=False;
End;
End;
Until Done;
Current_Party_Size:=Compute_Party_Size (Member,Party_Size);
End; { Dead Characters }
(******************************************************************************)
Function Index_of_Living_Aux (Group: Monster_Group): Integer;
{ This function returns the slot of the first living monster in GROUP }
Var
Index: Integer;
Begin { Index of Living Aux }
Index:=1;
While (Index<=Group.Curr_Group_Size) and (Group.Status[Index]=Dead) do
Index:=Index + 1;
If Index>Group.Curr_Group_Size then
Index_of_Living_Aux:=0
Else
Index_of_Living_Aux:=Index;
End; { Index of Living Aux }
(******************************************************************************)
[Global]Function Index_of_Living (Group: Monster_Group): [Volatile]Integer;
Var
Person: Integer;
Begin { Index of Living }
If Index_of_Living_Aux (Group)=0 then
Index_of_Living:=0
Else
Begin
Repeat
Person:=Roll_Die(Group.Curr_Group_Size)
Until Group.Status[Person]<>Dead;
Index_of_Living:=Person;
End;
End; { Index of Living }
(******************************************************************************)
Function Number_Active (Group: Monster_Group): Integer;
{ This function determines how many monsters can attack in GROUP }
Var
Temp: Integer;
Loop: Integer;
Begin { Number Active }
Temp:=0;
For Loop:=1 to Group.Curr_Group_Size do
If Group.Status[Loop] in [Healthy,Poisoned,Afraid,Zombie] then
Temp:=Temp + 1;
Number_Active:=Temp;
End; { Number Active }
(******************************************************************************)
Procedure Print_Monster_Line (Group_Number: Integer; Group: Monster_Group);
{ This procedure will print out the GROUP_NUMBERth group's status line }
Var
Name: Line;
Begin
Name:='';
If Group.Curr_Group_Size>0 then
Begin
Name:=Monster_Name (Group.Monster,Group.Curr_Group_Size,Group.Identified);
SMG$Put_Chars (MonsterDisplay,
CHR(Group_Number + ZeroOrd)
+' '
+String(Group.Curr_Group_Size),Group_Number,1,1);
SMG$Put_Chars (MonsterDisplay,' '
+Name
+' ('
+String(Number_Active (Group))
+')');
End
Else
SMG$Put_Chars (MonsterDisplay,
'',Group_Number,1,1);
End;
(******************************************************************************)
Procedure Switch_Monsters (Var Group: Monster_Group; One,Two: Integer);
{ This procedure switches the position of two monsters in GROUP }
Var
TempStat: Status_Type;
TempMax: Integer;
TempCurr: Integer;
Begin
TempStat:=Group.Status[One];
TempMax:=Group.Max_HP[One];
TempCurr:=Group.Curr_HP[One];
Group.Status[One]:=Group.Status[Two];
Group.Max_HP[One]:=Group.Max_HP[Two];
Group.Curr_HP[One]:=Group.Curr_HP[Two];
Group.Status[Two]:=TempStat;
Group.Max_HP[Two]:=TempMax;
Group.Curr_HP[Two]:=TempCurr;
End;
(******************************************************************************)
Function Need_to_Swap (Group: Monster_Group; Pos1,Pos2: Integer): Boolean;
{ This function determines whether or not two monsters need to be switched in the marching order }
Var
Temp: Boolean;
Begin
Temp:=(Group.Status[Pos1]=Dead);
Temp:=Temp and (Group.Status[Pos2]<>Dead);
Need_to_Swap:=Temp;
End;
(******************************************************************************)
Procedure Update_Monster_Group (Var Group: Monster_Group);
{ This procedure will update the current monster group. Updated are the positions of the monsters, and the current group size }
Var
Slot: Integer;
Done: Boolean;
Begin
If Group.Orig_Group_Size>1 then
Repeat
Begin
Done:=True;
For Slot:=Group.Orig_Group_Size downto 2 do
If Need_to_Swap (Group,Slot-1,Slot) then
Begin
Switch_Monsters (Group,Slot-1,Slot);
Done:=False;
End;
End;
Until Done;
Group.Curr_Group_Size:=0; Slot:=1;
While (Group.Status[Slot]<>Dead) and (Slot<=Group.Orig_Group_Size) do
Begin
Group.Curr_Group_Size:=Group.Curr_Group_Size + 1;
Slot:=Slot + 1;
End
End;
(******************************************************************************)
Procedure Print_Monsters (Var Group: Encounter_Group);
{ This procedure will print the monster status lines to the monster display }
Var
Num: Integer;
Begin
SMG$Begin_Display_Update (MonsterDisplay);
SMG$Erase_Display (MonsterDisplay);
For Num:=4 downto 1 do
Begin
Group[Num].Identified:=Group[Num].Identified or Made_Roll (15); { TODO: Make method taking past encounters into consideration }
Update_Monster_Group (Group[Num]);
Print_Monster_Line (Num,Group[Num]);
End;
SMG$End_Display_Update (MonsterDisplay);
End;
(******************************************************************************)
[Global]Procedure Show_Monster_Image (Number: Pic_Type; Var Display: Unsigned);
Var
Pic: Picture;
[External]Procedure Show_Image (Number: Pic_Type; Var Display: Unsigned);External;
Begin
SMG$Begin_Display_Update (Display);
Show_Image (Number, Display);
Pic:=Pics[Number];
If Yikes then
Begin
If (Pic.Right_Eye.X>0) and (Pic.Right_Eye.Y>0) then
SMG$Put_Chars (Display,Pic.Eye_Type+'',Pic.Right_Eye.Y + 0,Pic.Right_Eye.X + 0);
If (Pic.Left_Eye.X>0) and (Pic.Left_Eye.Y>0) then
SMG$Put_Chars (Display,Pic.Eye_Type+'',Pic.Left_Eye.Y + 0,Pic.Left_Eye.X + 0);
End;
SMG$End_Display_Update (Display);
End;
(******************************************************************************)
Procedure They_Advance (Name: Monster_Name_Type);
Begin
SMG$Begin_Display_Update (MessageDisplay);
SMG$Erase_Display (MessageDisplay);
SMG$Put_Line (MessageDisplay, 'The ' + Name + ' advance!');
SMG$End_Display_Update (MessageDisplay);
Ring_Bell (MessageDisplay, 2);
Delay (2*Delay_Constant);
End;
(******************************************************************************)
Procedure Swap_Groups (Var Group: Encounter_Group; Group1, Group2: Integer; Var Advance: Boolean;
Var Name: Monster_Name_Type);
Var
Temp: Monster_Group;
Begin
Advance:=False;
If Group[Group1].Curr_Group_Size>0 then
Begin
Name:=Monster_Name(Group[Group2].Monster,2,Group[Group2].Identified);
Advance:=True;
End;
Temp:=Group[Group1];
Group[Group1]:=Group[Group2];
Group[Group2]:=Temp;
End;
(******************************************************************************)
Function Want_to_Pass (Group: Encounter_Group; Pos1,Pos2: Integer): [Volatile]Boolean;
Begin
{ TODO: This looks wrong. }
Want_to_Pass:=(Group[Pos1].Curr_Group_Size=Group[Pos2].Curr_Group_Size) and (Group[Pos2].Curr_Group_Size<>0) and Made_Roll(15);
End;
(******************************************************************************)
Procedure Update_Monster_Box (Var Group: Encounter_Group);
{ This procedure will allow monsters groups to switch positions for more favorable attack advantages }
Var
i: Integer;
j: Integer;
Name: Monster_Name_Type;
Advance: Boolean;
Begin
Print_Monsters (Group);
For i:=1 to 3 do
For j:=4 downto i + 1 do
If (Group[j-1].Curr_Group_Size<Group[j].Curr_Group_Size) or Want_to_Pass (Group,j-1,j) then
Begin
Swap_Groups (Group,j-1,j,Advance,Name);
SMG$Begin_Display_Update (MonsterDisplay);
Print_Monster_Line (j-1,Group[j-1]);
Print_Monster_Line (j,Group[j]);
SMG$End_Display_Update (MonsterDisplay);
If Advance then
They_Advance (Name);
If Group[1].Curr_Group_Size>0 then
Show_Monster_Image (Group[1].Monster.Picture_Number,FightDisplay);
End;
End;
(******************************************************************************)
[Global]Procedure Update_Character_Box (Member: Party_Type; Party_Size: Integer; Var Can_Attack: Party_Flag);
Var
Num: Integer;
Begin
Can_Attack:=Update_Can_Attacks (Member,Party_Size);
SMG$Begin_Display_Update (CharacterDisplay);
For Num:=1 to Party_size do
Print_Party_Line (Member,Party_Size,Num);
SMG$End_Display_Update (CharacterDisplay);
End;
(******************************************************************************)
Function Item_Attacker_Level (Attacker: Character_Type): Integer;
Var
Critical_Flag: Boolean;
Item_Num: Integer;
Begin
Critical_Flag:=False;
For Item_Num:=1 to Attacker.No_of_Items do
If Attacker.Item[Item_num].isEquipped then
If Item_List[Attacker.Item[Item_Num].Item_Num].autoKill then { TODO: Make the items stack so multiple items equals better chance of critical }
Critical_Flag:=True;
If Critical_Flag then Item_Attacker_Level:=Max(Attacker.Level,Attacker.Previous_Lvl)
Else Item_Attacker_Level:=0;
End;
(******************************************************************************)
Function Class_Attacker_Level (Attacker: Character_Type): Integer;
Var
Attacker_Level: Integer;
Begin
Attacker_Level:=0;
If Attacker.Class in [Monk, Ninja, Assassin] then
If Attacker.PreviousClass in [Monk, Ninja, Assassin] then
Class_Attacker_Level:=Max(Attacker.Level,Attacker.Previous_Lvl)
Else
Class_Attacker_Level:=Attacker.Level
Else if Attacker.PreviousClass in [Monk, Ninja, Assassin] then
Class_Attacker_Level:=Attacker.Previous_Lvl
Else
Class_Attacker_Level:=0;
End;
(******************************************************************************)
[Global]Function Critical_hit (Attacker: Character_Type; Defender_Level: Integer): [Volatile]Boolean;
Var
Base: Integer;
Attacker_Level: Integer;
Begin
Attacker_Level:=Max(Class_Attacker_Level(Attacker),Item_Attacker_Level(Attacker));
If Attacker_Level>0 then
Begin
Base:=10+ (5* ((Attacker_Level-Defender_Level) div 2));
Critical_Hit:=Made_Roll(Base);
End
Else
Critical_Hit:=False;
End;
(******************************************************************************)
Function Luck_Adjustment (Luck: Integer): Integer;
Begin
Case Luck of
3: Luck_Adjustment:=-3;
4: Luck_Adjustment:=-2;
5: Luck_Adjustment:=-1;
6..15: Luck_Adjustment:=0;
16: Luck_Adjustment:=1;
17: Luck_Adjustment:=2;
18,19,20: Luck_Adjustment:=3;
21,22,23: Luck_Adjustment:=4;
24,25: Luck_Adjustment:=5;
Otherwise Luck_Adjustment:=0;
End;
End;
(******************************************************************************)
Function Natural_Adjustment (Character: Character_Type; Attack: Attack_Type): Integer;
Var
Constitution: Integer;
Luck: Integer;
Race: Race_Type;
Temp: Integer;
Begin
Temp:=0; Race:=Character.Race; Constitution:=Character.Abilities[5]; Luck:=Character.Abilities[7];
If Attack=Poison then
If Race in [LizardMan,HfOgre,Dwarven,Hobbit] then
Temp:=Temp + Trunc (Constitution / 3.5)
Else
If (Constitution>18) then
Temp:=Temp+(Constitution-18);
If (Race in [Dwarven,Hobbit]) and (Attack in [Magic,Death,CauseFear]) then
Temp:=Temp + Trunc (Constitution / 3.5);
Temp:=Temp + Luck_Adjustment (Luck);
Natural_Adjustment:=Temp;
End;
(******************************************************************************)
Function Magical_Adjustment (Character: Character_Type; Attack: Attack_Type): Integer;
Var
Temp: Integer;
Item_No: Integer;
Begin
Temp:=0;
If Character.No_of_Items>0 then
For Item_No:=1 to Character.No_of_Items do
If Character.Item[Item_No].isEquipped then
If (Attack in Item_List[Character.Item[Item_No].Item_Num].Resists) or
((Attack in [Stoning,LvlDrain]) and (Magic in Item_List[Character.Item[Item_No].Item_Num].Resists)) then
Temp:=Temp + 1;
Magical_Adjustment:=Temp;
End;
(******************************************************************************)
Function Class_Save (Class: Class_Type; Level: Integer): Integer;
Var
Temp: Integer;
Begin
Case Class of
Cleric,Monk: Temp:=10 - (((Level - 1) div 3));
Fighter,Ranger,Samurai,Paladin,AntiPaladin: Temp:=10 - (((Level - 1) div 2));
Wizard: Temp:=11 - (((Level - 1) div 5));
Thief,Ninja,Assassin,Bard: Temp:=11 - (((Level - 1) div 4));
Otherwise Temp:=12 - (((Level - 1) div 5));
End;
Class_Save:=Temp;
End;
(******************************************************************************)
Function Base_Save (Character: Character_Type): Integer;
Var
Temp1,Temp2: Integer;
Begin
Temp1:=Class_Save (Character.Class,Character.Level);
Temp2:=Class_Save (Character.PreviousClass,Character.Previous_Lvl);
Base_Save:=Min (Temp1,Temp2);
End;
(******************************************************************************)
Function Class_Adjustment (Class: Class_Type; Attack: Attack_Type): Integer;
Begin
Class_Adjustment:=0;
Case Attack of
Poison: If Class=Assassin then
Class_Adjustment:=1;
Magic: If Class=Wizard then
Class_Adjustment:=1;
Death: If Class=AntiPaladin then
Class_Adjustment:=1;
CauseFear: If Class=AntiPaladin then
Class_Adjustment:=-3
Else If Class=Barbarian then
Class_Adjustment:=5;
Aging,Sleep: If Class=Monk then
Class_Adjustment:=1;
End;
End;
(******************************************************************************)
Function Saving_Throw (Character: Character_Type; Attack: Attack_Type): Integer;
Var
Roll_Needed: Integer;
Begin
Roll_Needed:=Base_Save (Character);
Roll_Needed:=Roll_Needed
- Natural_Adjustment (Character,Attack)
- Magical_Adjustment (Character,Attack)
- Class_Adjustment (Character.Class,Attack)
- Class_Adjustment (Character.PreviousClass,Attack);
Saving_Throw:=Max(Roll_Needed,2);
End;
(******************************************************************************)
[Global]Function Made_Save (Character: Character_Type; Attack: Attack_Type): [Volatile]Boolean;
Var
Temp_Save: Boolean;
Begin
Temp_Save:=(Roll_Die(20)>=Saving_Throw(Character,Attack));
If Attack=Charming then
If Character.Race in [Elven,Drow] then
Temp_Save:=Temp_Save or Made_Roll (90)
Else
If Character.Race=HfElf then
Temp_Save:=Temp_Save or Made_Roll(30);
Made_Save:=Temp_Save;
End;
(******************************************************************************)
[Global]Function Monster_Save (Monster: Monster_Record; Attack: Attack_Type): [Volatile]Boolean;
Var
Temp: Integer;
Begin
Temp:=10-(((Monster.Hit_Points.X-1) div 2));
If Attack in Monster.Resists then
Temp:=Temp-4;
Monster_Save:=(Roll_Die(20)>Temp);
End;
(******************************************************************************)
Function Class_Base_Chance (Class: Class_Type; Level: Integer): Integer;
Begin
Case Class of
Cleric: Class_Base_Chance:=10 - (2 * ((level - 1) div 3));
Fighter,Ranger,Monk,Samurai,Barbarian,Paladin,AntiPaladin: Class_Base_Chance:=10 - (2 * ((level - 1) div 2));
Wizard: Class_Base_Chance:=11 - (2 * ((level - 1) div 5));
Thief,Assassin,Bard: Class_Base_Chance:=11 - (2 * ((level - 1) div 4));
Otherwise Class_Base_Chance:= 0;
End;
End;
(******************************************************************************)
Function Weapon_Plus_To_Hit (Character: Character_Type; Kind: Monster_Type; PosZ: Integer): Integer;
Var
Temp_Item: Item_Record;
Weapon_Plus: Integer;
Item_No: Integer;
Plus: Integer;
[External]Procedure Plane_Difference (Var Plus: Integer; PosZ: Integer);External; { TODO: Make this a function. }
Begin
Weapon_Plus:=0;
If Character.No_of_Items>0 then
For Item_No:=1 to Character.No_of_Items do
If Character.Item[Item_No].isEquipped then
Begin
Temp_Item:=Item_List[Character.Item[Item_No].Item_Num];
Plus:=Temp_Item.Plus_To_Hit;
If Kind in Temp_Item.Versus then
Plus:=Plus + (4 * Plus);
Plane_Difference (Plus,PosZ);
Weapon_Plus:=Weapon_Plus + Plus;
End;
Weapon_Plus_to_Hit:=Weapon_Plus;
End;
(******************************************************************************)
Function Strength_Plus_to_Hit (Strength: Integer): Integer;
Begin
Case Strength of
3: Strength_Plus_to_Hit:=-3;
4,5: Strength_Plus_to_Hit:=-2;
6,7: Strength_Plus_to_Hit:=-1;
8..14: Strength_Plus_to_Hit:=0;
15: Strength_Plus_to_Hit:=1;
16,17: Strength_Plus_to_Hit:=2;
18: Strength_Plus_to_Hit:=3;
19: Strength_Plus_to_Hit:=4;
20: Strength_Plus_to_Hit:=5;
21: Strength_Plus_to_Hit:=6;
22: Strength_Plus_to_Hit:=7;
23,24: Strength_Plus_to_Hit:=8;
25: Strength_Plus_to_Hit:=9;
Otherwise Strength_Plus_to_Hit:=0;
End;
End;
(******************************************************************************)
[Global]Function To_hit_Roll (Character: Character_Type; AC: Integer; Monster: Monster_Record): Integer;
Var
Weapon_Plus: Integer;
Temp: Integer;
Cant_Hit: Boolean;
Begin
Weapon_Plus:=Weapon_Plus_to_Hit (Character,Monster.Kind,PosZ);
Cant_Hit:=(Weapon_Plus<Monster.Weapon_Plus_Needed);
If Cant_Hit then
Temp:=MaxInt div 2
Else
Begin
Temp:=Min(Class_Base_Chance(Character.Class,Character.Level),
Class_Base_Chance(Character.PreviousClass,Character.Previous_Lvl));
If Character.Attack.Berserk then Temp:=Temp-4;
If Character.Status=Zombie then Temp:=Class_Base_Chance (Fighter,Character.Level);
Temp:=Temp-(AC-10);
Temp:=Temp-Strength_plus_to_Hit (Character.Abilities[1]);
Temp:=Temp-Weapon_Plus;
If Temp>20 then Temp:=20
Else if Temp<2 then Temp:=2;
End;
To_Hit_Roll:=Temp;
End;
(******************************************************************************)
Function Surprised (Monster: Monster_Record; Member: Party_Type): [Volatile]Surprise_Type;
Var
Die: Integer;
Surprise,Be_Surprised: Set of 1..12;
Begin
Be_Surprised:=[11,12];
Surprise:=[1,2];
If ([Member[1].Class,Member[1].PreviousClass]*[Samurai,Monk,Ranger]<>[])
or (Member[1].Race in [Elven,Drow]) then
Begin
Surprise:=[1];
Be_Surprised:=[9,10,11,12];
End;
If (Member[1].Abilities[7]>15) then Be_Surprised:=Be_Surprised-[1];
If (Member[1].Abilities[7]>17) then Surprise:=Surprise+[10];
Case Monster.Kind of
Karateka,Demon: Be_Surprised:=Be_Surprised+[3,4];
Dragon: Surprise:=Surprise+[6];
Insect: Surprise:=[];
Otherwise ;
End;
If Not (CanBeSurprised in Monster.Properties) then Surprise:=[];
Die:=Roll_Die(12);
If Die in Be_Surprised then
Surprised:=PartySurprised
Else
If Die in Surprise then
Surprised:=MonsterSurprised
Else
Surprised:=NoSurprise;
End;
(******************************************************************************)
[Global]Function Know_Monster (Monster_Number: Integer; Member: Party_Type; Current_Party_Size: Party_Size_Type): [Volatile]Boolean;
Var
Chance: Integer;
CharNo: Integer;
In_Partys_Set: Boolean;