-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplotbase.pp
More file actions
446 lines (383 loc) · 10.6 KB
/
plotbase.pp
File metadata and controls
446 lines (383 loc) · 10.6 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
unit plotbase;
{This unit defines the Plot Arc type, and provides several}
{procedures for dealing with it.}
{ PLOTBASE MARK II - technology marches on and DeadCold with it. }
{ I have replaced the original PlotBase/PlotLine stuff with the }
{ considerably more elegant GearHead Arena Script code. }
interface
uses texutil;
const
NAG_ScriptVar = 0;
NAG_MonsterMemory = 1;
Type
SAttPtr = ^SAtt;
SAtt = Record {*** STRING ATTRIBUTE ***}
info: String;
next: SAttPtr;
end;
NAttPtr = ^NAtt;
NAtt = Record {*** NUMERICAL ATTRIBUTE ***}
G,S: Integer; {General, Specific, Value}
V: LongInt;
next: NAttPtr;
end;
Function CreateSAtt(var LList: SAttPtr): SAttPtr;
Procedure DisposeSAtt(var LList: SAttPtr);
Procedure RemoveSAtt(var LList,LMember: SAttPtr);
Function FindSAtt(LList: SAttPtr; Code: String): SAttPtr;
Function SetSAtt(var LList: SAttPtr; Info: String): SAttPtr;
Function StoreSAtt(var LList: SAttPtr; Info: String): SAttPtr;
Function SAttValue(LList: SAttPtr; Code: String): String;
Function CreateNAtt(var LList: NAttPtr): NAttPtr;
Procedure DisposeNAtt(var LList: NAttPtr);
Procedure RemoveNAtt(var LList,LMember: NAttPtr);
Function FindNAtt(LList: NAttPtr; G,S: Integer): NAttPtr;
Function SetNAtt(var LList: NAttPtr; G,S: Integer; V: LongInt): NAttPtr;
Function AddNAtt(var LList: NAttPtr; G,S: Integer; V: LongInt): NAttPtr;
Function NAttValue(LList: NAttPtr; G,S: Integer): LongInt;
Procedure WriteNAtt( NA: NAttPtr; var F: Text );
Procedure WriteSAtt( SA: SAttPtr; var F: Text );
Function ReadNAtt( var F: Text ): NAttPtr;
Function ReadSAtt( var F: Text ): SAttPtr;
implementation
const
SaveFileContinue = 0;
SaveFileSentinel = -1;
Function CreateSAtt(var LList: SAttPtr): SAttPtr;
{Add a new element to the head of LList.}
var
it: SAttPtr;
begin
{Allocate memory for our new element.}
New(it);
if it = Nil then exit;
{Attach IT to the list.}
it^.Next := LList;
LList := it;
{Return a pointer to the new element.}
CreateSAtt := it;
end;
Procedure DisposeSAtt(var LList: SAttPtr);
{Dispose of the list, freeing all associated system resources.}
var
LTemp: SAttPtr;
begin
while LList <> Nil do begin
LTemp := LList^.Next;
Dispose(LList);
LList := LTemp;
end;
end;
Procedure RemoveSAtt(var LList,LMember: SAttPtr);
{Locate and extract member LMember from list LList.}
{Then, dispose of LMember.}
var
a,b: SAttPtr;
begin
{Initialize A and B}
B := LList;
A := Nil;
{Locate LMember in the list. A will thereafter be either Nil,}
{if LMember if first in the list, or it will be equal to the}
{element directly preceding LMember.}
while (B <> LMember) and (B <> Nil) do begin
A := B;
B := B^.next;
end;
if B = Nil then begin
{Major FUBAR. The member we were trying to remove can't}
{be found in the list.}
writeln('ERROR- RemoveSAtt asked to remove a link that doesnt exist.');
end
else if A = Nil then begin
{There's no element before the one we want to remove,}
{i.e. it's the first one in the list.}
LList := B^.Next;
Dispose(B);
B := Nil;
end
else begin
{We found the attribute we want to delete and have another}
{one standing before it in line. Go to work.}
A^.next := B^.next;
Dispose(B);
B := Nil;
end;
end;
Function FindSAtt(LList: SAttPtr; Code: String): SAttPtr;
{Search through the list looking for a String Attribute}
{whose code matches CODE and return its address.}
{Return Nil if no such SAtt can be found.}
var
it: SAttPtr;
S: STring;
begin
{Initialize IT to Nil.}
it := Nil;
Code := UpCase(Code);
{Check through all the SAtts looking for the SATT in question.}
while LList <> Nil do begin
S := LList^.info;
S := UpCase(ExtractWord(S));
if S = Code then it := LList;
LList := LList^.Next;
end;
FindSAtt := it;
end;
Function SetSAtt(var LList: SAttPtr; Info: String): SAttPtr;
{Add string attribute Info to the list. However, a gear}
{may not have two string attributes with the same name.}
{So, check to see whether or not the list already contains}
{a string attribute of this type; if so, just replace the}
{INFO field. If not, create a new SAtt and fill it in.}
var
it: SAttPtr;
code: String;
begin
{Determine the CODE of the string.}
code := Info;
code := ExtractWord(code);
{See if that code already exists in the list,}
{if not create a new entry for it.}
it := FindSAtt(LList,code);
{Plug in the value.}
if RetrieveAString( Info ) = '' then begin
if it <> Nil then RemoveSAtt( LList , it );
end else begin
if it = Nil then it := CreateSAtt(LList);
it^.info := Info;
end;
{Return a pointer to the new attribute.}
SetSAtt := it;
end;
Function StoreSAtt(var LList: SAttPtr; Info: String): SAttPtr;
{ Add string attribute Info to the list. This procedure }
{ doesn't check to make sure this attribute isn't duplicated. }
var
it: SAttPtr;
begin
it := CreateSAtt(LList);
it^.info := Info;
{Return a pointer to the new attribute.}
StoreSAtt := it;
end;
Function SAttValue(LList: SAttPtr; Code: String): String;
{Find a String Attribute which corresponds to Code, then}
{return its embedded alligator string.}
var
it: SAttPtr;
begin
it := FindSAtt(LList,Code);
if it = Nil then Exit('');
SAttValue := RetrieveAString(it^.info);
end;
Function CreateNAtt(var LList: NAttPtr): NAttPtr;
{Add a new element to the head of LList.}
var
it: NAttPtr;
begin
{Allocate memory for our new element.}
New(it);
if it = Nil then exit;
{Initialize values.}
it^.Next := LList;
LList := it;
{Return a pointer to the new element.}
CreateNAtt := it;
end;
Procedure DisposeNAtt(var LList: NAttPtr);
{Dispose of the list, freeing all associated system resources.}
var
LTemp: NAttPtr;
begin
while LList <> Nil do begin
LTemp := LList^.Next;
Dispose(LList);
LList := LTemp;
end;
end;
Procedure RemoveNAtt(var LList,LMember: NAttPtr);
{Locate and extract member LMember from list LList.}
{Then, dispose of LMember.}
var
a,b: NAttPtr;
begin
{Initialize A and B}
B := LList;
A := Nil;
{Locate LMember in the list. A will thereafter be either Nil,}
{if LMember if first in the list, or it will be equal to the}
{element directly preceding LMember.}
while (B <> LMember) and (B <> Nil) do begin
A := B;
B := B^.next;
end;
if B = Nil then begin
{Major FUBAR. The member we were trying to remove can't}
{be found in the list.}
writeln('ERROR- RemoveLink asked to remove a link that doesnt exist.');
end
else if A = Nil then begin
{There's no element before the one we want to remove,}
{i.e. it's the first one in the list.}
LList := B^.Next;
Dispose(B);
B := Nil;
end
else begin
{We found the attribute we want to delete and have another}
{one standing before it in line. Go to work.}
A^.next := B^.next;
Dispose(B);
B := Nil;
end;
end;
Function FindNAtt(LList: NAttPtr; G,S: Integer): NAttPtr;
{Locate the numerical attribute described by G,S and}
{return a pointer to it. If no such attribute exists}
{in the list, return Nil.}
var
it: NAttPtr;
begin
{Initialize it to Nil.}
it := Nil;
{Loop through all the elements.}
while LList <> Nil do begin
if (LList^.G = G) and (LList^.S = S) then it := LList;
LList := LList^.Next;
end;
{Return the value.}
FindNatt := it;
end;
Function SetNAtt(var LList: NAttPtr; G,S: Integer; V: LongInt ): NAttPtr;
{Set the Numerical Attribute described by G,S to value V.}
{If the attribute already exists, change its value. If not,}
{create the attribute.}
var
it: NAttPtr;
begin
it := FindNAtt(LList,G,S);
if it = Nil then begin
{The attribute doesn't currently exist. Create it.}
it := CreateNAtt(LList);
it^.G := G;
it^.S := S;
it^.V := V;
end else begin
{The attribute is already posessed. Just change}
{its Value field.}
it^.V := V;
end;
SetNAtt := it;
end;
Function AddNAtt(var LList: NAttPtr; G,S: Integer; V: LongInt ): NAttPtr;
{Add value V to the value field of the Numerical Attribute}
{described by G,S. If the attribute does not exist, create}
{it and set its value to V.}
{If, as a result of this operation, V drops below 0,}
{the numerical attribute will be removed and Nil will}
{be returned.}
var
it: NAttPtr;
begin
it := FindNAtt(LList,G,S);
if it = Nil then begin
{The attribute doesn't currently exist. Create it.}
it := CreateNAtt(LList);
it^.G := G;
it^.S := S;
it^.V := V;
end else begin
it^.V := it^.V + V;
end;
if it^.V < 0 then RemoveNAtt(LList,it);
AddNAtt := it;
end;
Function NAttValue(LList: NAttPtr; G,S: Integer): LongInt;
{Return the value of Numeric Attribute G,S. If this}
{attribute is not posessed, return 0.}
var
it: LongInt;
begin
it := 0;
while LList <> Nil do begin
if (LList^.G = G) and (LList^.S = S) then it := LList^.V;
LList := LList^.Next;
end;
NAttValue := it;
end;
Procedure WriteNAtt( NA: NAttPtr; var F: Text );
{ Output the provided list of string attributes. }
var
msg: String;
begin
{ Export Numeric Attributes }
while NA <> Nil do begin
msg := BStr( SaveFileContinue ) + ' ' + BStr( NA^.G ) + ' ' + BStr( NA^.S ) + ' ' + BStr( NA^.V );
writeln( F , msg );
NA := NA^.Next;
end;
{ Write the sentinel line here. }
writeln( F , SaveFileSentinel );
end;
Procedure WriteSAtt( SA: SAttPtr; var F: Text );
{ Output the provided list of string attributes. }
begin
{ Export String Attributes }
while SA <> Nil do begin
{ Error check- only output valid string attributes. }
if Pos('<',SA^.Info) > 0 then writeln( F , SA^.Info );
SA := SA^.Next;
end;
{ Write the sentinel line here. }
writeln( F , 'Z' );
end;
Function ReadNAtt( var F: Text ): NAttPtr;
{ Read some numeric attributes from the file. }
var
N,G,S: Integer;
V: LongInt;
it: NAttPtr;
TheLine: String;
begin
{ Initialize the list to Nil. }
it := Nil;
{ Keep processing this file until either the sentinel }
{ is encountered or we run out of data. }
repeat
{ read the next line of the file. }
readln( F , TheLine );
{ Extract the action code. }
N := ExtractValue( TheLine );
{ If this action code implies that there's a gear }
{ to load, get to work. }
if N = SaveFileContinue then begin
{ Read the specific values of this NAtt. }
G := ExtractValue( TheLine );
S := ExtractValue( TheLine );
V := ExtractValue( TheLine );
SetNAtt( it , G , S , V );
end;
until ( N = SaveFileSentinel ) or EoF( F );
ReadNAtt := it;
end;
Function ReadSAtt( var F: Text ): SAttPtr;
{ Read some string attributes from the file. }
var
it: SAttPtr;
TheLine: String;
begin
it := Nil;
{ Keep processing this file until either the sentinel }
{ is encountered or we run out of data. }
repeat
{ read the next line of the file. }
readln( F , TheLine );
{ If this is a valid string attribute, file it. }
if Pos('<',TheLine) > 0 then begin
StoreSAtt( it , TheLine );
end;
until ( Pos('<',TheLine) = 0 ) or EoF( F );
ReadSAtt := it;
end;
end.