-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStonequest.pas
1361 lines (1033 loc) · 52.4 KB
/
Stonequest.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('TYPES', 'SYS$LIBRARY:STARLET','LIBRTL','SMGRTL','STRRTL')]
Program Stonequest (Input,Output,Char_File,Item_File,Monster_File,Message_File,TreasFile,
MazeFile,SaveFile,PicFile,AmountFile,
ScoresFile,LogFile,HoursFile,PrintMazeFile);
{
Adding two types of comments next to each Var parameter.
If the data pointed to by the var parameter is modified, the comment will be "VAR$OBJECT".
If the pointer itself is reassigned, the comment will be "VAR$REASSIGNED".
}
{ This is Stonequest, a game. But it's not just any game - far from it! This
game was originally based on the Sir-Tech game, "Wizardry", for the Apple II
computer. At the time, "Wizardry" was the best. I wrote "Stonequest" just
to see if it could be done. It could. (But it ain't easy, let me tell you!)
But then I was inspired by other games that were becoming legends, such as
"The Bard's Tale" by Electronic Arts, and Moria, a public domain game. I
attempted to capture the best of these games within the framework of
"Wizardry". The result is a game that I feel is the best fantasy/simulation
around, and the biggest source of plagerized material in the world! I feel
that this game contains the best of all three of the above games, plus all
the other little odds and ends I threw in on a warped whim.
I apologize for the sorry lack of documentation in this game. When I first
started there was none; I've tried to add some since then. I've also tried
to make my variable and procedure names more self-explanatory. I wish the
best of luck to all those who try to modify it!
This game is dedicated to the memory of my late grandmother, Jenny Mayer on this day, 10/13/1988 }
Const
Owner_Account = 'SYSTEM';
Up_Arrow = CHR(18); Down_Arrow = CHR(19);
Left_Arrow = CHR(20); Right_Arrow = CHR(21);
ZeroOrd=ORD('0'); AOrd=ORD('A');
Cler_Spell = 1; Wiz_Spell = 2;
Type
AST_Arg_Type = Record
Pasteboard: [Long]Unsigned;
Argument: [Long]Unsigned;
Control_Key: [Byte]0..255;
End;
Spell_List = Packed Array [1..9] of Set of Spell_Name;
Signed_Word = [Word]-32767..32767;
Unsigned_Word = [Word]0..65535;
Time_Type = Packed Array [1..11] of char;
Party_File_Type = File of Name_Type;
SpName_Type = Cler_Spell..Wiz_Spell;
Var
{*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Files~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*}
PrintMazeFile: [Global]Text; { A pictoral representation of a level of levels }
HoursFile: [Global]Text; { The stonequest schedule }
TreasFile: [Global]Treas_File; { Treasure Types }
Monster_File: [Global]Monst_File; { Monster records }
Item_File: [Global]Equip_File; { Item records }
Char_File: [Global]Character_File; { Character records }
Message_File: [Global]Text; { Game text }
MazeFile: [Global]LevelFile; { The maze }
PartyFile: [Global]Party_File_Type; { Save party file }
SaveFile: [Global]Save_File_Type; { Save game file }
PicFile: [Global]Picture_File_Type; { Pictures }
AmountFile: [Global]Number_File; { Item amounts }
ScoresFile: [Global]Score_File; { High scores }
LogFile: [Global]Packed file of Line; { Player log }
{*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Tables~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*}
Roster: [Global]Roster_Type; { All characters }
Treasure: [Global]List_of_Treasures; { All treasure types }
Item_List: [Global]List_of_Items; { All items }
Pics: [Global]Pic_List; { Graphic Images }
{*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Text~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*}
TrapName: [External]Array [Trap_Type] of Varying[20] of Char;
Item_Name: [External]Array [Item_Type] of Varying[7] of char;
Spell: [External]Array [Spell_Name] of Varying[4] of Char;
Long_Spell: [External]Array [Spell_Name] of Varying [25] of Char;
StatusName: [External]Array [Status_Type] of Varying [14] of char;
ClassName: [External]Array [Class_Type] of Varying [13] of char;
AlignName: [External]Array [Align_Type] of Packed Array [1..7] of char;
RaceName: [External]Array [Race_Type] of Packed Array [1..12] of char;
SexName: [External]Array [Sex_Type] of Packed Array [1..11] of char;
AbilName: [External]Array [1..7] of Packed Array [1..12] of char;
WizSpells,ClerSpells: [External]Spell_List;
{*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Virtual Devices for SMG$~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*}
ViewDisplay,MonsterDisplay,SpellsDisplay,TextDisplay,CampDisplay,MessageDisplay,CommandsDisplay : [Global]Unsigned;
CharacterDisplay,TopDisplay,BottomDisplay,OptionsDisplay,GraveDisplay,ScenarioDisplay,WinDisplay : [Global]Unsigned;
SpellListDisplay,ScreenDisplay,FightDisplay,ShellDisplay,HelpDisplay,Pasteboard,Keyboard : [Global]Unsigned;
{*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~General~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*}
Experience_Needed: [Global]Array [Class_Type,1..50] of Real;
Trap_Authorized_Error: [Global]Boolean;
Main_Menu,In_Utilities: [Global]Boolean;
DataModified: [Global]Boolean;
ShowHours: Boolean;
Keypresses: [Global]Integer;
Print_Queue: [Global,Volatile]Line;
Minutes_Left: [Global]Integer;
Start_Priority: Unsigned; { The priority at which Stonequest was run }
Location: [Global]Place_Type; { Which module we're in }
Seed: [Global,Volatile]Unsigned; { Seed for random number }
Answer: Char; { User input from main program }
Cursor_Mode: [Global,Volatile]Boolean; { Is the cursor on or off? }
Broadcast_On: [Global,Volatile]Boolean; { Is the broadcast on ? }
Bells_On: [Global,Volatile]Boolean; { Are the bells on? }
Authorized: [Global]Boolean; { Can current user use Utilities? }
Game_Saved: [Global]Boolean; { Is there a previous game saved? }
{*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Game Loading and Saving Variables~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*}
Auto_Load: [Global]Boolean; { Auto-load in progress }
Auto_Save: [Global]Boolean; { Auto-save in progress }
{*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Externally Used Variables~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*}
Delay_Constant: [Global]Real;
Leave_Maze: [Global]Boolean; { Is there a forced leave maze? }
Maze: [Global]Level; { The current level the party's on }
Direction: [Global]Direction_Type; { The direction the party's facing }
Position: [Global]Level;
Minute_Counter: [Global]Real; { Minutes since last CAMP in Maze }
Rounds_Left: [Global]Array [Spell_Name] of Unsigned; { spell's time left }
PosX,PosY,PosZ: [Global,Byte]0..20; { Global position in maze }
{*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Used for Encounter Module~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*}
Party_Spell,Person_Spell,Caster_Spell,All_Monsters_Spell,Group_Spell,Area_Spell: [External]Set of Spell_Name;
Version_Number: [Global]Line;
Logging: [Global]Boolean; { Should users and errors be logged? }
Value
Logging:=True;
Version_Number:='V2.0'; { Current revision number }
Trap_Authorized_Error:=True; { Don't trap errors is user is authorized }
DataModified:=False; { Initially, data has not been modified }
Keypresses:=0; { No keypresses yet }
Minutes_Left:=60; { For use with hour-warnings }
Authorized:=False; { The user is not authorized by default! }
Print_Queue:='SYS$PRINT'; { Where should print screen print to? }
Main_Menu:=True; { We start at the main menu }
{*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~External DEClarations~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*}
{ 2023-09-21 JHG: Located the missing definition at https://github.com/dungeons-of-moria/vms-moria/blob/55058f595a810fb8576f898e76a4eb2937fa362c/source/moria.pas#L26 }
[Asynchronous,External]Function Oh_No (Var SA: Array [$u1..$u2:Integer] of Integer; Var MA: Array [$u3..$u4:Integer] of [Unsafe]Integer):[Unsafe]Integer;external;
[External]Procedure No_Controly;External;
[External]Procedure Controly;External;
[External]Function String(Num: Integer; Len: Integer:=0):Line;external;
[External]Procedure Player_Utilities(Var Pasteboard: Unsigned);External;
[External]Function Make_Choice (Choices: Char_Set; Time_Out: Integer:=-1; Time_Out_Char: Char:=' '): Char;External;
[External]Procedure Wait_Key (Time_Out: Integer:=-1);External;
[External]Function Roll_Die (Die_Type: Integer): [Volatile]Integer;External;
[External]Function Get_Seed: [Volatile]Integer;External;
{**********************************************************************************************************************************}
[Asynchronous]Procedure Print_Pasteboard (Var Arguments: AST_Arg_Type; Pasteboard: Unsigned);
[Asynchronous,External]Procedure Printing_Message;External;
begin { Print Pasteboard }
{ 2023-09-22 JHG - Couldn't get al the volatile params working. Not worth it.
SMG$PRINT_PASTEBOARD (Pasteboard,Print_Queue);
Printing_Message; }
End; { Print Pasteboard }
{**********************************************************************************************************************************}
[Global]Procedure Special_Keys (Key_Code: Unsigned_Word);
[External]Procedure Help;external;
[External]Procedure Shell_Out;External;
Begin { Special Keys }
If (Key_Code=SMG$K_TRM_CTRLU) and Not (Main_Menu or In_Utilities) then Player_Utilities(Pasteboard);
If (Key_Code=SMG$K_TRM_HELP) then Help;
If (Key_Code=SMG$K_TRM_DO) then Shell_Out;
End; { Special Keys }
{**********************************************************************************************************************************}
[Global]Procedure Ring_Bell (Display_Id: Unsigned; Number_of_Times: Integer:=1);
Begin { Ring Bell }
If Bells_On then SMG$Ring_Bell (Display_ID,Number_of_Times);
End; { Ring Bell }
{**********************************************************************************************************************************}
[Global]Procedure Cursor;
{ This procedure will turn the cursor on, and set CURSOR_MODE, the cursor's flag, to be true }
Begin { Cursor }
Cursor_Mode:=True; { Set the cursor flag }
SMG$Set_Cursor_Mode(Pasteboard, 0) { Turn on the cursor }
End; { Cursor }
{**********************************************************************************************************************************}
[Global]Procedure No_Cursor;
{ This procedure will turn the cursor off, and set CURSOR_MODE, the cursor's flag, to be false }
Begin { No Cursor }
Cursor_Mode:=False; { Clear the cursor flag }
SMG$Set_Cursor_Mode(Pasteboard, 1) { Turn off the cursor }
End; { No Cursor }
{**********************************************************************************************************************************}
[Global]Function User_Name: Line;
{ This function will return the USERNAME of the person using the game. The
code was provided by Denis Haskin, a great hacker, but a poor documenter,
not unlike myself. ( *wink* ) }
Type
Items= record
Buffer_Length,Item_Code: Unsigned_word;
Buffer_Address,Return_Length_Address: integer;
End;
Item_List_Type= Record
Item: Array [0..0] of Items;
Terminator: Integer;
End;
Buffer_type = Array [0..0] of Line;
Var
Item_list : item_list_type;
Buffer : buffer_type;
PID : unsigned;
Begin { User Name }
Buffer[0]:='';
With Item_List.Item[0] do
Begin
Buffer_length:=12;
Item_Code:=JPI$_Username; { Specify that we want the username }
Buffer_Address:=Iaddress(Buffer[0].Body); { Send it the string buffer }
Return_Length_Address:=IAddress(Buffer[0].Length) { And the length }
End;
Item_List.Terminator:=0; { Indicate no more items }
pid:=0; { Indicate the current process }
$getjpi(pidadr:=%ref pid,itmlst:=%ref item_list);
{ Return current username in Buffer[0] }
User_Name:=Buffer[0];
End; { User Name }
{**********************************************************************************************************************************}
Procedure Delete_All_Displays;
{ This procedure deletes all (?) of the virtual displays created by the game }
Begin { Delete All Displays }
SMG$Delete_Virtual_Display(ScreenDisplay);
SMG$Delete_Virtual_Display(HelpDisplay);
SMG$Delete_Virtual_Display(ShellDisplay);
SMG$Delete_Virtual_Display(CharacterDisplay);
SMG$Delete_Virtual_Display(MonsterDisplay);
SMG$Delete_Virtual_Display(CommandsDisplay);
SMG$Delete_Virtual_Display(SpellsDisplay);
SMG$Delete_Virtual_Display(OptionsDisplay);
SMG$Delete_Virtual_Display(TextDisplay);
SMG$Delete_Virtual_Display(ViewDisplay);
SMG$Delete_Virtual_Display(FightDisplay);
SMG$Delete_Virtual_Display(MessageDisplay);
SMG$Delete_Virtual_Display(CampDisplay);
SMG$Delete_Virtual_Display(ScenarioDisplay);
SMG$Delete_Virtual_Display(GraveDisplay);
SMG$Delete_Virtual_Display(TopDisplay);
SMG$Delete_Virtual_Display(BottomDisplay);
End; { Delete All Displays }
{**********************************************************************************************************************************}
Procedure Delete_Virtual_Devices;
{ This procedure deletes all of the virtual devices created by SMG$ }
Begin { Delete Virtual Devices }
SMG$Disable_Broadcast_Trapping (Pasteboard); { Stop trapping }
Cursor; { Restore the cursor to the on position }
SMG$Delete_Virtual_Keyboard (Keyboard); { Delete the keyboard }
Delete_All_Displays; { Delete the displays created in Stonequest }
SMG$Delete_Pasteboard (Pasteboard, 1); { Delete the pasteboard }
End; { Delete Virtual Devices }
{**********************************************************************************************************************************}
[Global]Procedure Extend_LogFile (Out_Message: Line);
{ This procedure writes the supplied line to the logfile }
Begin { Extend LogFile }
Repeat
Open (LogFile,'Stone_Data:Stone_Log.Dat',History:=Unknown,Sharing:=READONLY,Error:=CONTINUE);
Until (Status(LogFile)<>PAS$K_FILALROPE);
Extend (LogFile,Error:=Continue);
Write (LogFile,Out_Message,Error:=Continue);
Close (LogFile,Error:=Continue);
End; { Extend LogFile }
{**********************************************************************************************************************************}
[Global]Procedure Read_Error_Window (FileType: Line; Code: Integer:=0);
{ This procedure prints an error message and then exits Stonequest. }
[External]Procedure Exit (XStatus: Integer:=1);External;
Var
BroadcastDisplay: Unsigned; { Virtual keyboard and Broadcast }
Msg: Line;
{ THIS CODE IS MISSING IN THE PRINT OUT. IT WILL NEED TO BE RECREATED. -- JHG 2023-09-15 }
Begin
{ THIS CODE IS MISSING IN THE PRINT OUT. IT WILL NEED TO BE RECREATED. -- JHG 2023-09-15 }
End;
{**********************************************************************************************************************************}
{[Global]?}
Procedure Message_Trap (Code: Integer; FileType: Line);
{ THIS CODE IS MISSING IN THE PRINT OUT. IT WILL NEED TO BE RECREATED. -- JHG 2023-09-15 }
[External]Procedure Exit (XStatus: Integer:=1);External;
Var
Msg: Line;
BroadcastDisplay: Unsigned;
Begin { Message Trap }
Msg:='* * * Error reading '+FileType+' file!';
If Code<>0 then msg:=msg+' Error #'+String(code);
Msg:=Msg+' * * *';
If Logging then Extend_LogFile (Msg);
SMG$Create_Virtual_Display (5,78,BroadcastDisplay,1);
SMG$Erase_Display (BroadcastDisplay);
SMG$Label_Border (BroadcastDisplay, '> Yikes! <', SMG$K_TOP);
{ Print the message to the display }
SMG$Put_Chars (BroadcastDisplay,Msg,2,39-(Pas_Errors[Code].Length div 2));
If (Code>-2) and (Code<129) then
SMG$Put_Chars (BroadcastDisplay,Pas_Errors[Code],3,39-(Pas_Errors[Code].Length div 2));
{ Paste it onto the pasteboard }
SMG$Paste_Virtual_Display (BroadcastDisplay,Pasteboard,2,2);
{ Wait and then delete all created virtual devices }
LIB$WAIT (3);
SMG$Unpaste_Virtual_Display (BroadcastDisplay,Pasteboard);
SMG$Delete_Virtual_Display (BroadcastDisplay);
Delete_Virtual_Devices;
Exit; { Leave the game. (sorry! ) }
End; { Message Trap }
{**********************************************************************************************************************************}
[Global]Function Load_Saved_Game: [Volatile]Save_Record;
{ This function returns the saved game, if there was one. This function is not defined if the file doesn't exist so the checking
must be performed before this. }
Var
Temp: Save_Record;
Begin { Load Saved Game }
With Temp do
Begin { Make a dummy save record }
PosX:=1; PosY:=1; PosZ:=0;
Direction:=North;
Party_Size:=1;
Current_Size:=0;
End;
{ Open the file, and if there's data, read it }
Open (SaveFile, 'SYS$LOGIN:STONE_SAVE.DAT',History:=OLD,Error:=CONTINUE);
If Status(SaveFile)=PAS$K_SUCCESS then
Begin
Reset (SaveFile,Error:=Continue);
If Not EOF (SaveFile) then Read (SaveFile, Temp)
Else Read_Error_Window ('save',Status(SaveFile));
Close (SaveFile,Error:=Continue);
End
Else
Read_Error_Window ('save',Status(SaveFile));
{ Return the data }
Load_Saved_Game:=Temp;
End; { Load Saved Game }
{**********************************************************************************************************************************}
[Global]Procedure Change_Score (Var Character: Character_Type; Score_Num, Inc: Integer);
{ This procedure changes an ability score of a character }
Begin { Change Score }
If ((Character.Abilities[Score_Num]>3) and (Inc<0)) or
((Character.Abilities[Score_Num]<25) and (Inc>0)) then
Character.Abilities[Score_Num]:=Character.Abilities[Score_Num]+Inc;
End; { Change Score }
{**********************************************************************************************************************************}
[Global]Procedure Special_Occurance (Var Character: Character_Type; Number: Integer);
[External]Function XP_Needed (Class: Class_Type; Level: Integer): Real;external;
[External]Function Made_Roll (Needed: Integer): [Volatile]Boolean;external;
{ This procedure implements the "special occurances" (kinda like Daka's special dinners) for an item or whatever. All it does it
something hard-coded for each particular item }
Var
X: Integer;
Begin { Special Occurance }
Case Number of
1: If Made_Roll (65) then
If Not Made_Roll(Character.Level) then
Begin { Raise Character's level }
Character.Level:=Character.Level + 1;
Character.Experience:=XP_Needed (Character.Class,Character.Level);
End; { Raise Character's Level }
2: Begin { Lower character's level }
Character.Level:=Character.Level-1;
If Character.Level<1 then
Begin
Character.Level:=1;
Character.Curr_HP:=0;
Character.Max_HP:=0;
Character.Status:=Deleted;
End
Else
Character.Experience:=XP_Needed (Character.Class,Character.Level);
End; { Lower character's level }
3: Begin { Reduce a character's age 2-20 years }
Character.Age:=Character.Age-(Roll_Die(10)*2*365);
If Character.Age<(10*365) then Character.Age:=10*365;
End; { Increase a characters age }
{ Raise the ability scores }
4..10: Change_Score (Character,Number-3,Roll_Die(3));
{ Lower the ability scores }
11..17: Change_Score (Character,Number-10,Roll_Die(3)*(-1));
18: Begin
For X:=1 to 12 + Roll_Die(12) do
If Character.Class=Barbarian then
Character.Class:=Cleric
Else
Character.Class:=Succ(Character.Class);
If Character.Class=Character.PreviousClass then
If Character.Class=Barbarian then
Character.Class:=Cleric
Else
Character.Class:=Succ(Character.Class);
End;
19: Begin
Character.Alignment:=Evil;
Character.Abilities[1]:=Max(Character.Abilities[1], 17);
End;
Otherwise ;
End;
End; { Special Occurance }
{**********************************************************************************************************************************}
[Global]Procedure Show_Image (Number: Pic_Type; Var Display: Unsigned);
{ This procedure will copy the NUMBERth picture onto DISPLAY }
Var
X,Y: Integer;
Pic: Picture;
Image: Image_Type;
Begin { Show Image }
{ Get the appropriate image }
Pic:=Pics[Number];
Image:=Pic.Image;
{ Copy it onto the display }
SMG$Begin_Display_Update (Display);
For Y:=1 to 9 do
For X:=1 to 23 do
SMG$Put_Chars (Display,Image[X,Y],Y + 0,X + 0);
SMG$End_Display_Update (Display);
End; { Show Image }
{**********************************************************************************************************************************}
Function Time_And_Date_And_Name: [Volatile]Line;
{ This function returns the current time, date, and username of player }
Var
T: Line;
T1: Time_type;
Begin { Time and Date and Name }
T1:=''; Time(T1);
T:=User_Name+' '+T1;
Date(T1);
Time_and_Date_and_Name:=T+' '+T1+' '
End; { Time and Date and Name }
{**********************************************************************************************************************************}
Procedure Log_Player_In;
{ This procedure records the time and date the user logged into the logfile. }
Begin { Log Player In }
If Logging and (User_Name<>Owner_Account) then Extend_LogFile (Time_And_Date_And_name+'IN');
End; { Log Player In }
{**********************************************************************************************************************************}
Procedure Log_Player_Out;
{ See above? }
Begin { Log Player Out }
If Logging and (User_Name<>Owner_Account) then
Extend_LogFile (Time_And_Date_And_name+'OUT');
End; { Log Player Out }
{**********************************************************************************************************************************}
[External]Function Read_Items: List_of_Items;External;
[External]Function Read_Pictures: Pic_List;External;
[External]Function Read_Messages: Message_Group;external;
[External]Function Read_Roster: Roster_Type;external;
[External]Function Get_Maze_File_Name (levelCharacter: Char): Line;External;
[External]Function Read_Level_from_Maze_File(Var fileVar: LevelFile; levelNumber: Integer): Level;External;
[External]Function Read_Treasures: List_of_Treasures;external;
[External]Function Read_Monsters: List_of_monsters;External;
[External]Procedure Write_Roster (Roster: Roster_Type);External;
[External]Procedure Save_Pictures(Pics: Pic_List);External;
[External]Procedure Save_Monsters (Monster: List_of_monsters);external;
[External]Procedure Save_Items(Item_List: List_of_Items);external;
[External]Procedure Save_Treasure(Treasure: List_of_Treasures);external;
[External]Procedure Save_Messages (Messages: Message_Group);external;
{**********************************************************************************************************************************}
[Global]Procedure Error_Window (FileType: Line);
{ Print a error message window }
Var
BroadcastDisplay: Unsigned; { Virtual keyboard and Broadcast }
Msg: Line;
Begin { Error Window }
Msg:='* * * Error writing '+FileType+' file! * * *';
SMG$Create_Virtual_Display(5,78,BroadcastDisplay,1);
SMG$Erase_Display (BroadcastDisplay);
SMG$Label_Border (BroadcastDisplay,'> Yikes! <',SMG$K_TOP);
{ Print the message to the display }
SMG$Put_Chars (BroadcastDisplay,Msg,3,39-(Msg.Length div 2));
{ Paste it onto the pasteboard }
SMG$Paste_Virtual_Display (BroadcastDisplay,Pasteboard,2,2);
{ Delete all created virtual devices }
LIB$WAIT (3);
SMG$Unpaste_Virtual_Display (BroadcastDisplay,Pasteboard);
SMG$Delete_Virtual_Display (BroadcastDisplay);
End; { Error Window }
{**********************************************************************************************************************************}
Function Successful (Result_Code: Integer): Boolean;
Begin { Successful }
Successful:=(Result_Code=PAS$K_SUCCESS) or (Result_Code=PAS$K_EOF);
End; { Successful }
{**********************************************************************************************************************************}
[Global]Procedure Delay (Seconds: Real);
{ This procedure will wait SECONDS seconmds. This is good because the game
hibernates, saving CPU time. }
Begin { Delay }
Lib$Wait(Seconds);
End; { Delay }
{**********************************************************************************************************************************}
[Global]Procedure Print_Roster;
{ This procedure will print the roster of characters to SCREENDISPLAY }
Var
Slot: Integer;
T: Line;
Begin { Print Roster }
{ Erase and label the proper display }
SMG$Begin_Display_Update (ScreenDisplay);
SMG$Erase_Display (ScreenDisplay);
T:='Roster of Characters';
SMG$Set_Cursor_ABS (ScreenDisplay,1,40-(t.length div 2));
SMG$Put_Line (ScreenDisplay,T,1,1);
SMG$Put_Line (ScreenDisplay,
' #) Name Class Level Status',1,0);
{ Print all the characters }
For Slot:=1 to 20 do
If Roster[Slot].Status<>Deleted then { If the slot is used ... }
Begin { Print the occupant }
SMG$Put_Chars (ScreenDisplay,
String (Slot,2)
+') ');
SMG$Put_Chars (ScreenDisplay,Pad(Roster[Slot].Name,' ',21));
SMG$Put_Chars (ScreenDisplay,AlignName[Roster[Slot].Alignment][1]
+'-');
SMG$Put_Chars (ScreenDisplay,
Pad(ClassName[Roster[Slot].Class],' ',16));
SMG$Put_Chars (ScreenDisplay,String (Roster[Slot].Level,3));
SMG$Put_Line (ScreenDisplay,' '
+StatusName[Roster[Slot].Status]);
End { Print the occupant }
Else { Otherwise print a blank line }
SMG$Put_Line (ScreenDisplay,'');
SMG$End_Display_Update (ScreenDisplay);
End; { Print Roster }
{**********************************************************************************************************************************}
[Global]Procedure Plane_Difference (Var Plus: Integer; PosZ: Integer);
Var
Lower_Bound,Upper_Bound: Integer;
Begin { Plane Difference }
If PosZ>10 then
If Plus>0 then
Begin
Lower_Bound:=0;
Plus:=Plus-(PosZ-10);
If Plus<Lower_Bound then Plus:=Lower_Bound;
End
Else
If Plus<0 then
Begin
Upper_Bound:=0;
Plus:=Plus+(PosZ-10);
If Plus>Upper_Bound then Plus:=Upper_Bound;
End;
End; { Plane Difference }
{**********************************************************************************************************************************}
[Global]Function Screen_Line (LineWidth: Integer:=80): Line;
{ This function returns a line of the format:
+------------+
of width LINEWIDTH. This is used primarily for KYRN, but other uses may arise. }
Var
Temp: Line;
Loop: Integer;
Begin { Screen Line }
Temp:='+'; { Left '+' }
For Loop:=2 to (LineWidth-1) do
Temp:=Temp+'-'; { Intermediate '-'s }
Screen_Line:=Temp+'+'; { Right '+' }
End; { Screen Line }
{**********************************************************************************************************************************}
Procedure Initialize_Displays;
{ This procedure creates virtual displays for use with SMG$. If any displays, for example a command window, never changes, it is
initialized here with the proper text. }
Begin { Initialize Displays }
{ Create the displays }
SMG$Create_Virtual_Display (7,78,CharacterDisplay,1);
SMG$Create_Virtual_Display (4,54,MonsterDisplay,1);
SMG$Create_Virtual_Display (4,54,CommandsDisplay,1);
SMG$Create_Virtual_Display (4,54,SpellsDisplay,1);
SMG$Create_Virtual_Display (4,54,OptionsDisplay,1);
SMG$Create_Virtual_Display (4,54,TextDisplay,1);
SMG$Create_Virtual_Display (9,23,ViewDisplay,1);
SMG$Create_Virtual_Display (9,23,FightDisplay,1);
SMG$Create_Virtual_Display (4,78,MessageDisplay,1);
SMG$Create_Virtual_Display (22,78,CampDisplay,1);
SMG$Create_Virtual_Display (22,78,GraveDisplay,1);
SMG$Create_Virtual_Display (22,78,ScenarioDisplay,1);
SMG$Create_Virtual_Display (22,78,WinDisplay,1);
SMG$Create_Virtual_Display (24,80,HelpDisplay,0);
SMG$Create_Virtual_Display (24,80,ShellDisplay,0);
SMG$Create_Virtual_Display (10,78,TopDisplay,1);
SMG$Create_Virtual_Display (12,80,BottomDisplay);
{ Label the proper borders }
SMG$Label_Border(ScenarioDisplay,
'=*> The Quest of the Stone <*=',SMG$K_TOP);
SMG$Label_Border(WinDisplay,
'=*> The Quest of the Stone <*=',SMG$K_TOP);
SMG$Label_Border(GraveDisplay,
' Warrior''s Gate ',SMG$K_TOP);
SMG$Label_Border(CampDisplay,
' Camp ',SMG$K_TOP);
SMG$Label_Border(MonsterDisplay,
' Combat ',SMG$K_TOP);
SMG$Label_Border(TopDisplay,
'Kyrn',SMG$K_RIGHT);
SMG$Label_Border(ViewDisplay);
{ Initialize the proper borders }
SMG$Put_Chars(CommandsDisplay,
'F)orward C)amp S)tay 1 round',1,3);
SMG$Put_Chars(CommandsDisplay,
'L)eft T)ime Delay ^ ',2,3);
SMG$Put_Chars(CommandsDisplay,
'R)ight HELP | ',3,3);
SMG$Put_Chars(CommandsDisplay,
'K)ick DO <------+------>',4,3);
End; { Initialize Displays }
{**********************************************************************************************************************************}
Procedure Add_Dot (Var X: Integer);
{ This procedure adds a dot to the line of dots on the screen }
Begin { Add Dot }
SMG$Put_Chars (ScreenDisplay,'. ',11,X);
X:=X + 1;
End; { Add Dot }
{**********************************************************************************************************************************}
{ 2023-09-22 JHG - Couldn't get all the volatile parms working. [Asynchronous,Global]}Procedure Out_of_Band_AST (Var Arguments: AST_Arg_Type);
{ This procedure handles any control characters typed by the users during
the game }
Begin { Out of Band AST }
Case Arguments.Control_Key of
SMG$K_TRM_CTRLW,SMG$K_TRM_CTRLR: SMG$Repaint_Screen (Pasteboard); { 2023-09-22 JHG - Did not take Arguments as a parameter }
SMG$K_TRM_CTRLP: Print_Pasteboard (Arguments,Pasteboard);
Otherwise ;
End;
End; { Out of Band AST }
{**********************************************************************************************************************************}
[Global]Procedure Trap_Out_of_Bands;
{ This procedure enables the trapping of special keys }
Const { Trap these characters }
Trap = 2**SMG$K_TRM_CTRLW+
2**SMG$K_TRM_CTRLR+
2**SMG$K_TRM_CTRLP;
Begin { Trap Out of Bands }
SMG$Set_Out_Of_Band_ASTs (Pasteboard,Trap,AST_Routine:=%Immed OUT_OF_BAND_AST);
End; { Trap Out of Bands }
{**********************************************************************************************************************************}
[Global]Procedure Dont_Trap_Out_of_Bands;
Begin { Dont Trap Out of Bands }
SMG$Set_Out_Of_Band_ASTs (Pasteboard,0);
End; { Dont Trap Out of Bands }
{**********************************************************************************************************************************}
Procedure Create_Virtual_Devices;
{ This procedure creates two virtual devices for use with SMG$. The first is PASTEBOARD, which handles all screen output and is a
virtual screen. The display SCREENDISPLAY is pasted on it to start out with, but other displays may be pasted and removed during
the course of game play. The second device is the Virtual Keyboard, through which keys are read. }
[External,Unbound]Procedure Message_trap;external;
Begin { Create Virtual Devices }
{ Create the virtual terminal and keyboard }
SMG$Create_Pasteboard (Pasteboard);
SMG$Create_Virtual_Keyboard(keyboard);
{ Turn off the cursor }
No_Cursor;
{ Enable message trapping }
SMG$Set_Broadcast_Trapping (pasteboard,%Immed Message_Trap,0);
{ Enable screen repainting on ^W }
Trap_Out_of_Bands;
{ Create and clear the primary screen display }
SMG$Create_Virtual_Display (24, 80,ScreenDisplay,0);
SMG$Erase_Display (ScreenDisplay);
{ Print the initialization message to the display }
SMG$Put_Chars (ScreenDisplay, 'Initializing Game',10,33,,1);
SMG$Put_Chars (ScreenDisplay, 'Please Wait. ',11,35);
{ Paste the display onto the pasteboard }
SMG$Paste_Virtual_Display (ScreenDisplay,Pasteboard,1,1);
End; { Create Virtual Devices }
{**********************************************************************************************************************************}
[Global]Function Saved_Game: [Volatile]Boolean;
{ This function returns TRUE is there is a previous game saved, and FALSE otherwise. }
Var
Temp: Boolean;
Begin { Saved Game }
{ Open the save file }
Open (SaveFile,'SYS$LOGIN:STONE_SAVE.DAT',History:=OLD,Error:=CONTINUE,Sharing:=NONE);
{ No data in the file => No saved game }
Temp:=NOT(Status(SaveFile)=PAS$K_FILNOTFOU);
Saved_Game:=Temp;
{ Close the save file }
If Temp then Close (SaveFile);
End; { Saved Game }
{**********************************************************************************************************************************}
Procedure Initialize_Globals;
{ This procedure initializes all globals and externally used variables. This is so that when a call is mode to, say,
Print_Character, MAZE is defined even though it may not be used. }
Begin { Initialize Globals }
Experience_Needed:=Zero;
{ We're not leaving the maze when we haven't entered it... }
Leave_Maze:=False;
{ The current "level" has no contents... }
Maze.Room:=Zero;
{ The backup level is the same... }
Position:=Maze;
{ We're arbitrarily facing North... }
Direction:=North;
{ We've spent zero minutes in the maze... }
Minute_Counter:=0;
{ We've casted no spells }
Rounds_Left:=Zero;
{ ... and we're at maze coordinates (0,0,0) }
PosX:=0; PosY:=0; PosZ:=0;
End; { Initialize Globals }
{**********************************************************************************************************************************}
Procedure Initialize;
{ This procedure initializes the game. Initialized are virtual devices, string constants, and virtual displays. Information from
the disk is brought in at this point. }
Var
X: Integer;
Begin { Initialize }
If Not (Authorized or (User_name=Owner_Account)) then $SETPRI (Pri:=4,PrvPri:=Start_Priority);
Log_Player_In;
X:=47; { Initialize X for ADD_DOT }
Cursor_Mode:=True; { The cursor is on at the moment }
Create_Virtual_Devices; Add_Dot(X); { Create pasteboard and keyboard }
Pics:=Read_Pictures; Add_Dot(X); { Read in the picture images }
Roster:=Read_Roster; Add_Dot(X); { Read in the characters }
Treasure:=Read_Treasures;Add_Dot(X); { Read in the treasure types }
Item_List := Read_Items; Add_Dot(X); { Read in items }
Initialize_Displays; Add_Dot(X); { Create and initialize displays }
Initialize_Globals; Add_Dot(X); { Initialize external variables }
Broadcast_On:=True; Add_Dot(X);
Bells_On:=True; Add_Dot(X);
Game_Saved:=Saved_Game; Add_Dot(X); { Is there a saved game? }
Auto_Load:=False; Add_Dot(X);
Auto_Save:=False; Add_Dot(X);
Seed:=Get_Seed; Add_Dot(X); { Get a seed for the rand. #s }
End; { Initialize }
{**********************************************************************************************************************************}
[Global]Function Rendition_Set (Var T: Line): Unsigned;
{ This function scans T for special characters, and then returns the renditionset for SMG$ to print out T with the right
renditions }
Var
New_Line: Line;
Position: Integer;
Blinking,Bold,Inverse,Underline: Boolean;
Temp: Unsigned;
Begin { Rendition_Set }
New_Line:='';
Bold:=False; Inverse:=False; Underline:=False; Blinking:=False;
For Position:=1 to T.Length do
Case T[Position] of
'^': Bold:=True;
'_': Underline:=True;
'`': Inverse:=True;
'{': Blinking:=True;
Otherwise New_Line:=New_Line + T[Position];
End;
T:=New_Line; Temp:=SMG$M_NORMAL;
If Bold then Temp:=Temp + SMG$M_BOLD;
If Inverse then Temp:=Temp + SMG$M_REVERSE;
If Blinking then Temp:=Temp + SMG$M_BLINK;
If Underline then Temp:=Temp + SMG$M_UNDERLINE;
Rendition_Set:=Temp;
End; { Rendition Set }
{**********************************************************************************************************************************}
Procedure View_Scenario;
{ This procedure prints the scenario to a bordered display }
Const
Length=21; { Maximum number of lines allowed }
Var
LineCount: Integer;
L,Msg: Line;
Rendition: Unsigned; { Rendition set for line }