-
Notifications
You must be signed in to change notification settings - Fork 0
/
monlookup.pas
496 lines (435 loc) · 10.6 KB
/
monlookup.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
[INHERIT ('MONCONST','MONGLOBL','MONTYPE')]
MODULE MonLookup(OUTPUT);
%include 'headers.txt'
(* -------------------------------------------------------------------------- *)
[GLOBAL]
FUNCTION LookupDetail(VAR N : INTEGER; S : String) : BYTE_BOOL;
VAR
I, Poss, Maybe, Num : INTEGER;
P : String;
BEGIN
N := 0;
S := Lowcase(Trim(S));
I := 1;
Maybe := 0;
Num := 0;
FOR I := 1 TO MaxDetail DO
BEGIN
P := Lowcase(Trim(HereDesc.Detail[I]));
IF S = P THEN
Num := I
ELSE
IF Index(P, S) = 1 THEN
BEGIN
Maybe := Maybe + 1;
Poss := I;
END;
END;
IF Num <> 0 THEN
BEGIN
N := Num;
LookupDetail := TRUE;
END
ELSE
IF Maybe = 1 THEN
BEGIN
N := Poss;
LookupDetail := TRUE;
END
ELSE
IF Maybe > 1 THEN
LookupDetail := FALSE
ELSE
LookupDetail := FALSE;
END;
(* -------------------------------------------------------------------------- *)
[GLOBAL]
FUNCTION LookupAlias(VAR N : INTEGER; S : String) : BYTE_BOOL;
VAR
I : INTEGER;
BEGIN
N := 0;
FOR I := 1 TO MaxExit DO
IF HereDesc.Exits[I].Kind <> EK_PASSWORD THEN
IF Lowcase(Trim(S)) = Lowcase(Trim(HereDesc.Exits[I].Alias)) THEN
N := I;
IF N = 0 THEN
LookupAlias := FALSE
ELSE
LookupAlias := TRUE;
END;
(* ------------------------------------------------------------------------- *)
[GLOBAL]
FUNCTION LookupDir(VAR Dir : INTEGER; S : String) : BYTE_BOOL;
VAR
I, Poss, Maybe, Num : INTEGER;
BEGIN
S := LowCase(S);
I := 1;
Maybe := 0;
Num := 0;
FOR I := 1 TO MaxExit DO
BEGIN
IF S = Direct[I] THEN Num := i
ELSE
IF Index(Direct[I], S) = 1 THEN
BEGIN
Maybe := Maybe + 1;
poss := i;
END;
END;
IF Num <> 0 THEN
BEGIN
Dir := Num;
LookupDir := TRUE;
END
ELSE
IF Maybe = 1 THEN
BEGIN
Dir := Poss;
LookupDir := TRUE;
END
ELSE
IF Maybe > 1 THEN
LookupDir := FALSE
ELSE
LookupDir := FALSE;
END;
(* ------------------------------------------------------------------------- *)
[GLOBAL]
FUNCTION LookupCmd(S : String; Cmds : ARRAY[$l1..$l2:integer] of shortstring;
maxcmds : INTEGER) : INTEGER;
VAR
Loop, Poss, Maybe, Num : INTEGER;
BEGIN
S := LowCase(S);
Loop := 1;
Maybe := 0;
Num := 0;
FOR Loop := 1 TO MaxCmds DO
BEGIN
IF S = Cmds[Loop] THEN
Num := Loop
ELSE IF Index(Cmds[Loop],S) = 1 THEN
BEGIN
Maybe := Maybe + 1;
Poss := Loop;
END;
END;
IF Num <> 0 then LookupCmd := Num
ELSE IF Maybe = 1 then LookupCmd := Poss
ELSE IF Maybe > 1 then LookupCmd := C_Error
ELSE LookupCmd := C_Error;
END;
(* ------------------------------------------------------------------------- *)
[GLOBAL]
FUNCTION LookupAlign(S : String) : INTEGER;
VAR
Loop, Poss, Maybe, Num : INTEGER;
BEGIN
S := LowCase(S);
Loop := 1;
Maybe := 0;
Num := 0;
FOR Loop := 1 TO MaxAlign DO
BEGIN
IF S = Alignments[Loop] THEN
Num := Loop
ELSE IF Index(Alignments[Loop],S) = 1 THEN
BEGIN
Maybe := Maybe + 1;
Poss := Loop;
END;
END;
IF Num <> 0 then LookupAlign := Num
ELSE IF Maybe = 1 then LookupAlign := Poss
ELSE IF Maybe > 1 then LookupAlign := C_Error
ELSE LookupAlign := C_Error;
END;
(* -------------------------------------------------------------------------- *)
[GLOBAL]
FUNCTION LookupAtmosphere(S : String) : INTEGER;
VAR
Loop, Poss, Maybe, Num : INTEGER;
BEGIN
S := LowCase(S);
Maybe := 0;
Num := 0;
FOR Loop := 1 TO MaxAtmospheres DO
BEGIN
IF S = Atmosphere[Loop].Trigger THEN
Num := Loop
ELSE IF Index(Atmosphere[Loop].Trigger, S) = 1 THEN
BEGIN
Maybe := Maybe + 1;
Poss := Loop;
END;
END;
IF Num <> 0 THEN LookupAtmosphere := Num
ELSE IF Maybe = 1 THEN LookupAtmosphere := Poss
ELSE IF Maybe > 1 THEN LookupAtmosphere := C_Error
ELSE LookupAtmosphere := C_Error;
END;
(* -------------------------------------------------------------------------- *)
[GLOBAL]
FUNCTION LookupNameRaw(List : ARRAY [$l0..$l1:integer] of ShortString;
Ind : IndexRec; VAR Pnum : INTEGER; S : String;
Exact : byte_bool) : BYTE_BOOL;
VAR
Off, Top, Poss, Maybe, Loop : INTEGER;
Found : BYTE_BOOL;
Name : ShortString;
BEGIN
S := lowcase(S);
Maybe := 0;
Loop := $l0;
Off := 1 - loop;
Top := Loop - 1 + Ind.Top;
Found := FALSE;
While (Loop <= Top) AND Not(Found) DO
BEGIN
IF (NOT Ind.Free[Off+Loop]) THEN
BEGIN
Name := LowCase(list[loop]);
IF S = Name THEN
Found := TRUE
ELSE
IF Index(Trim(Name),S) = 1 THEN
BEGIN
Maybe := Maybe + 1;
Poss := Loop;
END;
END;
IF not(found) THEN Loop := Loop + 1;
END;
IF Found THEN
BEGIN
Pnum := Loop;
END ELSE IF (Maybe = 1) AND NOT Exact THEN
BEGIN
Pnum := Poss;
Found := TRUE;
END;
LookupNameRaw := found;
END;
(* -------------------------------------------------------------------------- *)
[GLOBAL]
FUNCTION LookupName(NameType : INTEGER; NameNum : INTEGER; VAR Pnum : INTEGER;
S : String; Exact : BYTE_BOOL := FALSE;
Silent : BYTE_BOOL := TRUE) : BYTE_BOOL;
VAR
IndexNum : INTEGER;
Found : BYTE_BOOL := FALSE;
Status : BYTE_BOOL;
RealShortName : RealShortNameRec;
Shortname : ShortNameRec;
SomeIndex : IndexRec;
Name : String;
BEGIN
CASE NameType OF
nt_RealShort : BEGIN
Case NameNum OF
RSNR_GroupName : IndexNum := I_GroupName;
RSNR_Class : IndexNum := I_Class;
END;
Status := GetRealShortName(NameNum, RealShortName);
IF Status THEN Status := GetIndex(IndexNum, SomeIndex);
Found := LookupNameRaw(RealShortName.idents, SomeIndex, Pnum,
S, exact);
END;
nt_Short : BEGIN
CASE NameNum OF
s_na_pers : IndexNum := I_Player;
s_na_user : IndexNum := I_Player;
s_na_objnam : IndexNum := I_Object;
s_na_rannam : IndexNum := I_Rand;
s_na_spell : IndexNum := I_Spell;
END;
Status := GetShortName(NameNum, ShortName);
IF Status THEN Status := GetIndex(IndexNum, SomeIndex);
Found := LookupNameRaw(ShortName.Idents, SomeIndex, Pnum, S,
exact);
END;
nt_long: halt;
END;
LookupName := Found;
IF (NOT Found) AND (NOT Silent) THEN
BEGIN
Write('I could not find that ');
CASE NameType OF
nt_realshort : CASE NameNum OF
RSNR_GroupName : Write('group');
RSNR_Class : Write('class');
END;
nt_short : CASE NameNum OF
s_na_pers : write('person');
s_na_user : write('user');
s_na_objnam : write('object');
s_na_rannam : write('random');
s_na_spell : write('spell');
END;
END;
Writeln(' ',S,'.');
END;
END;
(* -------------------------------------------------------------------------- *)
[GLOBAL]
FUNCTION ParseObjHere(VAR Objname : String) : INTEGER;
VAR
ObjNam : ShortNameRec;
Poss, ObjNum, Loop : INTEGER;
Done : BYTE_BOOL;
BEGIN
Poss := 0;
ParseObjHere := 0;
Loop := 1;
Done := FALSE;
While ((Loop<=MaxObjs) AND NOT(Done)) DO
BEGIN
ObjNum := Here.Objs[Loop] MOD 1000;
IF (ObjNum <> 0) THEN
BEGIN
IF (GlobalObjects[ObjNum].ObjName = ObjName) THEN
BEGIN
Poss := Loop;
Done := TRUE;
END
ELSE
BEGIN
IF (Index(GlobalObjects[ObjNum].ObjName, ObjName) = 1) THEN
IF Poss = 0 THEN Poss := Loop
ELSE
BEGIN
Done := TRUE;
Poss := -1;
END;
Loop := Loop + 1;
END;
END ELSE Loop := Loop + 1;
END;
IF Poss > 0 THEN
ObjName := GlobalObjects[Here.Objs[Poss] MOD 1000].ObjName;
ParseObjHere := Poss;
END;
(* -------------------------------------------------------------------------- *)
[GLOBAL]
FUNCTION ObjHere(ObjNum : INTEGER) : BYTE_BOOL;
VAR
Loop : INTEGER;
Found : BYTE_BOOL;
BEGIN
Loop := 1;
Found := FALSE;
WHILE (Loop <= MaxObjs) AND (NOT FOUND) DO
IF Here.Objs[Loop] MOD 1000 = ObjNum THEN
Found := TRUE
ELSE
Loop := Loop + 1;
ObjHere := Found;
END;
(* -------------------------------------------------------------------------- *)
[GLOBAL]
FUNCTION ObjHold(ObjNum : INTEGER; MyHold : HoldObj) : BYTE_BOOL;
VAR
Loop : INTEGER;
Found : BYTE_BOOL;
BEGIN
IF ObjNum = 0 THEN
Found := FALSE
ELSE
BEGIN
Loop := 1;
Found := FALSE;
WHILE (Loop <= MaxHold) AND (NOT Found) DO
BEGIN
IF MyHold.Holding[Loop] = ObjNum THEN
Found := TRUE
ELSE
Loop := Loop + 1;
END;
END;
ObjHold := Found;
END;
(* -------------------------------------------------------------------------- *)
[GLOBAL]
FUNCTION FindObj(ObjNum: INTEGER; RoomNum : INTEGER) : INTEGER;
VAR
Loop : INTEGER;
Status : BYTE_BOOL;
BEGIN
Loop := 1;
FindObj := 0;
IF GetRoom(RoomNum, Here) THEN
WHILE (Loop <= MaxObjs) DO
BEGIN
IF Here.objs[Loop] MOD 1000 = ObjNum THEN
FindObj := Loop;
Loop := Loop + 1;
END;
END;
(* -------------------------------------------------------------------------- *)
[GLOBAL]
FUNCTION ParseObj(VAR ObjNum : INTEGER; S : String;
MyHold : HoldObj) : BYTE_BOOL;
VAR
Slot: INTEGER;
BEGIN
IF LookUpname(nt_short, s_na_objnam,ObjNum,S) THEN
ParseObj := ObjHere(ObjNum) OR ObjHold(ObjNum, MyHold);
END;
(* -------------------------------------------------------------------------- *)
[GLOBAL]
FUNCTION ParsePers(VAR Pnum : INTEGER; VAR Log : INTEGER; S : String;
Echo : BYTE_BOOL := FALSE) : BYTE_BOOL;
VAR
Persnum, Loop, Poss : INTEGER;
Maybe : INTEGER := 0;
Num : INTEGER := 0;
Found : BYTE_BOOL := FALSE;
Status : BYTE_BOOL;
BEGIN
S := Lowcase(S);
Pnum := 0;
Log := 0;
IF Length(S) = 0 THEN
Loop := MaxPeople
ELSE
Loop := 0;
WHILE (Loop < MaxPeople ) AND NOT Found DO
BEGIN
Loop := Loop + 1;
IF ((Here.People[Loop].Hiding = 0) AND (Here.People[Loop].Kind <> 0)) THEN
BEGIN
IF S = LowCase(Here.People[Loop].Name) THEN
Found := TRUE
ELSE
IF Index(Lowcase(Here.People[Loop].Name), S) = 1 THEN
BEGIN
Maybe := Maybe + 1;
Poss := Loop;
END;
END;
END;
IF Found THEN
BEGIN
PNum := Loop;
Log := Here.People[Loop].Kind;
END
ELSE
IF Maybe = 1 THEN
BEGIN
PNum := Poss;
Found := TRUE;
Log := Here.People[PNum].Kind;
END
ELSE
BEGIN
Found := FALSE;
Log := 0;
END;
IF Echo AND (NOT Found) THEN
Writeln('That person cannot be seen in this room.');
ParsePers := Found;
END;
(* -------------------------------------------------------------------------- *)
END. (* Module monlookup *)