-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScores.pas
250 lines (187 loc) · 7.02 KB
/
Scores.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
(*
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','LIBRTL','SMGRTL')]Module High_Score;
Var
ScoreDisplay: Unsigned;
Roster: [External]Roster_Type;
Pasteboard: [External]Unsigned;
ClassName: [External]Array [Class_Type] of Varying [13] of char;
(******************************************************************************)
[External]Function XP_Needed (Class: Class_Type; Level: Integer): Real;external;
[External]Function Alive (Character: Character_Type): Boolean;external;
[External]Function String(Num: Integer; Len: Integer:=0):Line;external;
[External]Function Get_Response (Time_Out: Integer:=-1; Time_Out_Char: Char:=' '):[Volatile]Char;External;
[External]Function Read_Score_List: High_Score_List;External;
[External]Procedure Write_Score_List (Score_List: High_Score_List);External;
(******************************************************************************)
Procedure Insert (Character: Character_Type; Var Temp: Combined_List; Username: Line);
Var
Pos,X: Integer;
Found: Boolean;
Begin { TODO: Add a unique id to each character so we don't have to do this guesswork to identify the same character }
If Character.Previous_Lvl>0 then
Character.Experience:=Character.Experience + XP_Needed (Character.PreviousClass,Character.Previous_Lvl);
If Not Alive(Character) then Character.Experience:=0;
Pos:=0; X:=0;
Found:=False;
Repeat
Begin
X:=X + 1;
If (Character.Name=Temp[X].Name) and (Username=Temp[X].User_Name) then
Found:=True;
End;
Until (X=40) or Found;
{ Look for the same character so that we can update it }
If Not Found then { If we didn't find character, search for any empty slot. }
Begin
Pos:=0; X:=0;
Found:=False;
Repeat
Begin
X:=X + 1;
If (Temp[X].Lvl1=0) or (Temp[X].Experience=0) then
Found:=True;
End;
Until (X=40) or (Found);
End;
{ In either case, X should equal the spot to insert }
Pos:=X;
With Temp[Pos] do
Begin
Name:=Character.Name;
User_Name:=Username;
Lvl1:=Character.Level;
Lvl2:=Character.Previous_Lvl;
Class1:=Character.Class;
Class2:=Character.PreviousClass;
Experience:=Character.Experience;
Defeated_Barrat:=Character.Scenarios_Won[0];
End;
End;
(******************************************************************************)
Function Make_Combined_Score_List (Score_List: High_Score_List; Username: Line): Combined_List;
Var
X: Integer;
Temp: Combined_List;
Character: Character_Type;
Begin
{ Copy the current high scores to the first 20 slots }
For X:=1 to 20 do Temp[X]:=Score_List[X];
{ Initialize t he last twenty slots }
For X:=21 to 40 do Temp[X]:=Zero;
{ Now insert all the new characters }
For X:=1 to 20 do
Begin
Character:=Roster[X];
Insert(Character,Temp,Username);
End;
Make_Combined_Score_List:=Temp;
End;
(******************************************************************************)
Procedure Swap (Var Combined_Score_List: Combined_List; I,J: Integer);
Var
Save: Score;
Begin
Save:=Combined_Score_List[I];
Combined_Score_List[I]:=Combined_Score_List[J];
Combined_Score_List[J]:=Save;
End;
(******************************************************************************)
Procedure Sort_Combined_List (Var Combined_Score_List: Combined_List; First: Integer:=1; Last: Integer:=40);
Var
I: Integer;
Done: Boolean;
Begin
Repeat
Begin
Done:=True;
For I:=First to Last-1 do
If Combined_Score_List[I].experience<Combined_Score_List[I + 1].experience then
Begin
Swap (Combined_Score_List, I, I + 1);
Done:=False;
End;
End;
Until Done;
End;
(******************************************************************************)
Function Top_Twenty (Combined_Score_List: Combined_List): High_Score_List;
Var
Temp: High_Score_List;
X: Integer;
Begin
For X:=1 to 20 do
Temp[X]:=Combined_Score_List[X];
Top_Twenty:=Temp;
End;
(******************************************************************************)
[Global]Procedure Update_High_Scores (UserName: Line);
Var
Combined_Score_List: Combined_List;
Score_List: High_Score_List;
Begin
Score_List := Read_Score_List;
Combined_Score_List:=Make_Combined_Score_List (Score_List, Username);
Sort_Combined_List (Combined_Score_List);
Write_Score_List (Top_Twenty(Combined_Score_List));
{ TODO: Is code missing? }
End;
(*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*)
Procedure Initialize;
Const
High_Score_Title = 'Character Name Username Level Class Experience';
Begin
SMG$Create_Virtual_Display (22,78,ScoreDisplay,1);
SMG$Label_Border (ScoreDisplay,'-=*> High Scores <*=-',SMG$K_TOP);
SMG$Erase_Display (ScoreDisplay);
SMG$Put_Line (ScoreDisplay, High_Score_Title);
End;
(******************************************************************************)
Procedure Print_List (Score_List: High_Score_List);
Var
Rendition: Unsigned;
X: Integer;
T: Line;
C1,C2: Line;
Begin
For X:=1 to 19 do
If (Score_List[X].Lvl1>0) and (Score_List[X].Experience>0) then
Begin
T:=Pad(Score_List[X].Name,' ',21)+Pad(Score_List[X].USer_Name,' ',16);
C1:=String(Score_List[X].Lvl1);
If Score_List[X].Lvl2>0 then C1:=C1+'/'+String(Score_List[X].Lvl2);
If C1.Length<8 then T:=T + Pad(C1,' ',8)
Else T:=T + C1;
C1:=ClassName[Score_List[X].Class1];
C2:=ClassName[Score_List[X].Class2];
if Score_List[X].Class2<>NoClass then C1:=C1+'/'+C2;
If C1.Length<18 then T:=T + Pad(C1,' ',18)
Else T:=T + SubStr(C1,1,18);
T:=T + String(Trunc(Score_List[X].Experience),12);
Rendition:=0;
If Score_List[X].Defeated_Barrat then Rendition:=SMG$M_Bold; { T:=T+'*' }
SMG$Put_Line (ScoreDisplay,T,,Rendition);
End;
SMG$Put_Chars (ScoreDisplay,'Characters in ',21,7);
SMG$Put_Chars (ScoreDisplay,'Boldface',,,,SMG$M_Bold);
SMG$Put_Chars (ScoreDisplay,' have completed ');
SMG$Put_Chars (ScoreDisplay,'the Quest of the Stone',,,,SMG$M_Underline + SMG$M_Reverse);
SMG$Put_Chars (ScoreDisplay,'Press any key',22,32);
SMG$Paste_Virtual_Display (ScoreDisplay,Pasteboard,2,2);
Get_Response;
SMG$Unpaste_Virtual_Display (ScoreDisplay,Pasteboard);
SMG$Delete_Virtual_Display (ScoreDisplay);
End;
(******************************************************************************)
[Global]Procedure Print_Scores;
Var
Score_List: High_Score_List;
Begin { Print Scores }
Initialize;
Score_List := Read_Score_List;
Print_List (Score_List);
End; { Print Scores }
End. { High Score }