-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmon.pas
9942 lines (8377 loc) · 218 KB
/
mon.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
{
This is Monster, a multiuser adventure game system
where the players create the universe.
Written by Rich Skrenta at Northwestern University, 1988.
}
program monster(input,output);
const
%include 'privusers.pas'
veryshortlen = 12; { very short string length for userid's etc }
shortlen = 20; { ordinary short string }
maxobjs = 15; { max objects allow on floor in a room }
maxpeople = 10; { max people allowed in a room }
maxplayers = 300; { max log entries to make for players }
maxcmds = 75; { top value for cmd keyword slots }
maxshow = 50; { top value for set/show keywords }
maxexit = 6; { 6 exits from each loc: NSEWUD }
maxroom = 1000; { Total maximum ever possible }
maxdetail = 5; { max num of detail keys/descriptions per room }
maxevent = 15; { event slots per event block }
maxindex = 10000; { top value for bitmap allocation }
maxhold = 6; { max # of things a player can be holding }
maxerr = 15; { # of consecutive record collisions before the
the deadlock error message is printed }
numevnts = 10; { # of different event records to be maintained }
numpunches = 12; { # of different kinds of punches there are }
maxparm = 20; { parms for object USEs }
maxspells = 50; { total number of spells available }
descmax = 10; { lines per description block }
DEFAULT_LINE = 32000; { A virtual one liner record number that
really means "use the default one liner
description instead of reading one from
the file" }
{ Mnemonics for directions }
north = 1;
south = 2;
east = 3;
west = 4;
up = 5;
down = 6;
{ Index record mnemonics }
I_BLOCK = 1; { True if description block is not used }
I_LINE = 2; { True if line slot is not used }
I_ROOM = 3; { True if room slot is not in use }
I_PLAYER = 4; { True if slot is not occupied by a player }
I_ASLEEP = 5; { True if player is not playing }
I_OBJECT = 6; { True if object record is not being used }
I_INT = 7; { True if int record is not being used }
{ Integer record mnemonics }
N_LOCATION = 1; { Player's location }
N_NUMROOMS = 2; { How many rooms they've made }
N_ALLOW = 3; { How many rooms they're allowed to make }
N_ACCEPT = 4; { Number of open accept exits they have }
N_EXPERIENCE = 5; { How "good" they are }
N_SELF = 6; { player's self descriptions }
{ object kind mnemonics }
O_BLAND = 0; { bland object, good for keys }
O_WEAPON = 1;
O_ARMOR = 2;
O_THRUSTER = 3; { use puts player through an exit }
O_CLOAK = 4;
O_BAG = 100;
O_CRYSTAL = 101;
O_WAND = 102;
O_HAND = 103;
{ Command Mnemonics }
error = 0;
setnam = 1;
help = 2;
quest = 3;
quit = 4;
look = 5;
go = 6;
form = 7;
link = 8;
unlink = 9;
c_whisper = 10;
poof = 11;
desc = 12;
dbg = 14;
say = 15;
c_rooms = 17;
c_system = 18;
c_disown = 19;
c_claim = 20;
c_create = 21;
c_public = 22;
c_accept = 23;
c_refuse = 24;
c_zap = 25;
c_hide = 26;
c_l = 27;
c_north = 28;
c_south = 29;
c_east = 30;
c_west = 31;
c_up = 32;
c_down = 33;
c_n = 34;
c_s = 35;
c_e = 36;
c_w = 37;
c_u = 38;
c_d = 39;
c_custom = 40;
c_who = 41;
c_players = 42;
c_search = 43;
c_unhide = 44;
c_punch = 45;
c_ping = 46;
c_health = 47;
c_get = 48;
c_drop = 49;
c_inv = 50;
c_i = 51;
c_self = 52;
c_whois = 53;
c_duplicate = 54;
c_version = 56;
c_objects = 57;
c_use = 58;
c_wield = 59;
c_brief = 60;
c_wear = 61;
c_relink = 62;
c_unmake = 63;
c_destroy = 64;
c_show = 65;
c_set = 66;
e_detail = 100; { pseudo command for log_action of desc exit }
e_custroom = 101; { customizing this room }
e_program = 102; { customizing (programming) an object }
e_usecrystal = 103; { using a crystal ball }
{ Show Mnemonics }
s_exits = 1;
s_object = 2;
s_quest = 3;
s_details = 4;
{ Set Mnemonics }
y_quest = 1;
y_altmsg = 2;
y_group1 = 3;
y_group2 = 4;
{ Event Mnemonics }
E_EXIT = 1; { player left room }
E_ENTER = 2; { player entered room }
E_BEGIN = 3; { player joined game here }
E_QUIT = 4; { player here quit game }
E_SAY = 5; { someone said something }
E_SETNAM = 6; { player set his personal name }
E_POOFIN = 8; { someone poofed into this room }
E_POOFOUT = 9; { someone poofed out of this room }
E_DETACH = 10; { a link has been destroyed }
E_EDITDONE = 11; { someone is finished editing a desc }
E_NEWEXIT = 12; { someone made an exit here }
E_BOUNCEDIN = 13; { an object "bounced" into the room }
E_EXAMINE = 14; { someone is examining something }
E_CUSTDONE = 15; { someone is done customizing an exit }
E_FOUND = 16; { player found something }
E_SEARCH = 17; { player is searching room }
E_DONEDET = 18; { done adding details to a room }
E_HIDOBJ = 19; { someone hid an object here }
E_UNHIDE = 20; { voluntarily revealed themself }
E_FOUNDYOU = 21; { someone found someone else hiding }
E_PUNCH = 22; { someone has punched someone else }
E_MADEOBJ = 23; { someone made an object here }
E_GET = 24; { someone picked up an object }
E_DROP = 25; { someone dropped an object }
E_DROPALL = 26; { quit & dropped stuff on way out }
E_IHID = 27; { tell others that I have hidden (!) }
E_NOISES = 28; { strange noises from hidden people }
E_PING = 29; { send a ping to a potential zombie }
E_PONG = 30; { ping answered }
E_HIDEPUNCH = 31; { someone hidden is attacking }
E_SLIPPED = 32; { attack caused obj to drop unwillingly }
E_ROOMDONE = 33; { done customizing this room }
E_OBJDONE = 34; { done programming an object }
E_HPOOFOUT = 35; { someone hiding poofed out }
E_FAILGO = 36; { a player failed to go through an exit }
E_HPOOFIN = 37; { someone poofed into a room hidden }
E_TRYPUNCH = 38; { someone failed to punch someone else }
E_PINGONE = 39; { someone was pinged away . . . }
E_CLAIM = 40; { someone claimed this room }
E_DISOWN = 41; { owner of this room has disowned it }
E_WEAKER = 42; { person is weaker from battle }
E_OBJCLAIM = 43; { someone claimed an object }
E_OBJDISOWN = 44; { someone disowned an object }
E_SELFDONE = 45; { done editing self description }
E_WHISPER = 46; { someone whispers to someone else }
E_WIELD = 47; { player wields a weapon }
E_UNWIELD = 48; { player puts a weapon away }
E_DONECRYSTALUSE = 49; { done using the crystal ball }
E_WEAR = 50; { someone has put on something }
E_UNWEAR = 51; { someone has taken off something }
E_DESTROY = 52; { someone has destroyed an object }
E_HIDESAY = 53; { anonymous say }
E_OBJPUBLIC = 54; { someone made an object public }
E_SYSDONE = 55; { done with system maint. mode }
E_UNMAKE = 56; { remove typedef for object }
E_LOOKDETAIL = 57; { looking at a detail of this room }
E_ACCEPT = 58; { made an "accept" exit here }
E_REFUSE = 59; { got rid of an "accept" exit here }
E_DIED = 60; { someone died and evaporated }
E_LOOKYOU = 61; { someone is looking at you }
E_FAILGET = 62; { someone can't get something }
E_FAILUSE = 63; { someone can't use something }
E_CHILL = 64; { someone scrys you }
E_NOISE2 = 65; { say while in crystal ball }
E_LOOKSELF = 66; { someone looks at themself }
E_INVENT = 67; { someone takes inventory }
E_POOFYOU = 68; { MM poofs someone away . . . . }
E_WHO = 69; { someone does a who }
E_PLAYERS = 70; { someone does a players }
E_VIEWSELF = 71; { someone views a self description }
E_REALNOISE = 72; { make the real noises message print }
E_ALTNOISE = 73; { alternate mystery message }
E_MIDNIGHT = 74; { it's midnight now, tell everyone }
E_ACTION = 100; { base command action event }
{ Misc. }
GOODHEALTH = 7;
type
string = varying[80] of char;
veryshortstring = varying[veryshortlen] of char;
shortstring = varying[shortlen] of char;
{ This is a list of description block numbers;
If a number is zero, there is no text for that block }
{ exit kinds:
0: no way - blocked exit
1: open passageway
2: object required
6: exit only exists if player is holding the key
}
exit = record
toloc: integer; { location exit goes to }
kind: integer; { type of the exit }
slot: integer; { exit slot of toloc target }
exitdesc, { one liner description of exit }
closed, { desc of a closed door }
fail, { description if can't go thru }
success, { desc while going thru exit }
goin, { what others see when you go into the exit }
{ ofail, }
comeout: { what others see when you come out of the exit }
integer; { all refer to the liner file }
{ if zero defaults will be printed }
hidden: integer; { **** about to change this **** }
objreq: integer; { object required to pass this exit }
alias: veryshortstring; { alias for the exit dir, a keyword }
reqverb: boolean; { require alias as a verb to work }
reqalias: boolean; { require alias only (no direction) to
pass through the exit }
autolook: boolean; { do a look when user comes out of exit }
end;
{ index record # 1 is block index }
{ index record # 2 is line index }
{ index record # 3 is room index }
{ index record # 4 is player alloc index }
{ index record # 5 is player awake (in game) index }
indexrec = record
indexnum: integer; { validation number }
free: packed array[1..maxindex] of boolean;
top: integer; { max records available }
inuse: integer; { record #s in use }
end;
{ names are record #1 }
{ owners are record # 2 }
{ player pers_names are record # 3 }
{ userids are record # 4 }
{ object names are record # 5 }
{ object creators are record # 6 }
{ date of last play is # 7 }
{ time of last play is # 8 }
namrec = record
validate: integer;
loctop: integer;
idents: array[1..maxroom] of shortstring;
end;
objectrec = record
objnum: integer; { allocation number for the object }
onum: integer; { number index to objnam/objown }
oname: shortstring; { duplicate of name of object }
kind: integer; { what kind of object this is }
linedesc: integer; { liner desc of object Here }
home: integer; { if object at home, then print the }
homedesc: integer; { home description }
actindx: integer; { action index -- programs for the future }
examine: integer; { desc block for close inspection }
worth: integer; { how much it cost to make (in gold) }
numexist: integer; { number in existence }
sticky: boolean; { can they ever get it? }
getobjreq: integer; { object required to get this object }
getfail: integer; { fail-to-get description }
getsuccess: integer; { successful picked up description }
useobjreq: integer; { object require to use this object }
uselocreq: integer; { place have to be to use this object }
usefail: integer; { fail-to-use description }
usesuccess: integer; { successful use of object description }
usealias: veryshortstring;
reqalias: boolean;
reqverb: boolean;
particle: integer; { a,an,some, etc... "particle" is not
be right, but hey, it's in the code }
parms: array[1..maxparm] of integer;
d1: integer; { extra description # 1 }
d2: integer; { extra description # 2 }
exp3,exp4,exp5,exp6: integer;
end;
anevent = record
sender, { slot of sender }
action, { what event this is, E_something }
target, { opt target of action }
parm: integer; { expansion parm }
msg: string; { string for SAY and other cmds }
loc: integer; { room that event is targeted for }
end;
eventrec = record
validat: integer; { validation number for record locking }
evnt: array[1..maxevent] of anevent;
point: integer; { circular buffer pointer }
end;
peoplerec = record
kind: integer; { 0=none,1=player,2=npc }
parm: integer; { index to npc controller (object?) }
username: veryshortstring; { actual userid of person }
name: shortstring; { chosen name of person }
hiding: integer; { degree to which they're hiding }
act,targ: integer; { last thing that this person did }
holding: array[1..maxhold] of integer; { objects being held }
experience: integer;
wearing: integer; { object that they're wearing }
wielding: integer; { weapon they're wielding }
health: integer; { how healthy they are }
self: integer; { self description }
ex1,ex2,ex3,ex4,ex5: integer;
end;
spellrec = record
recnum: integer;
level: array[1..maxspells] of integer;
end;
descrec = record
descrinum: integer;
lines: array[1..descmax] of string;
desclen: integer; { number used in this block }
end;
linerec = record
linenum: integer;
theline: string;
end;
room = record
valid: integer; { validation number for record locking }
locnum: integer;
owner: veryshortstring; { who owns the room: userid if private
'' if public
'*' if disowned }
nicename: string; { pretty name for location }
nameprint: integer; { code for printing name:
0: don't print it
1: You're in
2: You're at
}
primary: integer; { room descriptions }
secondary: integer;
which: integer; { 0 = only print primary room desc.
1 = only print secondary room desc.
2 = print both
3 = print primary then secondary
if has magic object }
magicobj: integer; { special object for this room }
effects: integer;
parm: integer;
exits: array[1..maxexit] of exit;
pile: integer; { if more than maxobjs objects here }
objs: array[1..maxobjs] of integer; { refs to object file }
objhide: array[1..maxobjs] of integer; { how much each object
is hidden }
{ see hidden on exitrec
above }
objdrop: integer; { where objects go when they're dropped }
objdesc: integer; { what it says when they're dropped }
objdest: integer; { what it says in target room when
"bounced" object comes in }
people: array[1..maxpeople] of peoplerec;
grploc1,grploc2: integer;
grpnam1,grpnam2: shortstring;
detail: array[1..maxdetail] of veryshortstring;
detaildesc: array[1..maxdetail] of integer;
trapto: integer; { where the "trapdoor" goes }
trapchance: integer; { how often the trapdoor works }
rndmsg: integer; { message that randomly prints }
xmsg2: integer; { another random block }
exp2,exp3,exp4: integer;
exitfail: integer; { default fail description for exits }
ofail: integer; { what other's see when you fail, default }
end;
intrec = record
intnum: integer;
int: array[1..maxplayers] of integer;
end;
var
old_prompt: [external] string;
line: [external] string;
oldcmd: string; { string for '.' command to do last command }
inmem: boolean; { Is this rooms roomrec (here....) in memory?
We call gethere many times to make sure
here is current. However, we only want to
actually do a getroom if the roomrec has been
modified }
brief: boolean := FALSE; { brief/verbose descriptions }
rndcycle: integer; { integer for rnd_event }
debug: boolean;
ping_answered: boolean; { flag for ping answers }
hiding : boolean := FALSE; { is player hiding? }
midnight_notyet: boolean := TRUE; { hasn't been midnight yet }
first_puttoken: boolean := TRUE; { flag for first place into world }
logged_act : boolean := FALSE; { flag to indicate that a log_action
has been called, and the next call
to clear_command needs to clear the
action parms in the here roomrec }
roomfile : file of room;
eventfile: file of eventrec;
namfile: file of namrec;
descfile: file of descrec;
linefile: file of linerec;
indexfile: file of indexrec;
intfile: file of intrec;
objfile: file of objectrec;
spellfile: file of spellrec;
cmds: array[1..maxcmds] of shortstring := (
'name', { setnam = 1 }
'help', { help = 2 }
'?', { quest = 3 }
'quit', { quit = 4 }
'look', { look = 5 }
'go', { go = 6 }
'form', { form = 7 }
'link', { link = 8 }
'unlink', { unlink = 9 }
'whisper', { c_whisper = 10}
'poof', { poof = 11 }
'describe', { desc = 12 }
'',
'debug', { dbg = 14 }
'say', { say = 15 }
'', { }
'rooms', { c_rooms = 17 }
'system', { c_system = 18 }
'disown', { c_disown = 19 }
'claim', { c_claim = 20 }
'make', { c_create = 21 }
'public', { c_public = 22 }
'accept', { c_accept = 23 }
'refuse', { c_refuse = 24 }
'zap', { c_zap = 25 }
'hide', { c_hide = 26 }
'l', { c_l = 27 }
'north', { c_north = 28 }
'south', { c_south = 29 }
'east', { c_east = 30 }
'west', { c_west = 31 }
'up', { c_up = 32 }
'down', { c_down = 33 }
'n', { c_n = 34 }
's', { c_s = 35 }
'e', { c_e = 36 }
'w', { c_w = 37 }
'u', { c_u = 38 }
'd', { c_d = 39 }
'customize', { c_custom = 40 }
'who', { c_who = 41 }
'players', { c_players = 42}
'search', { c_search = 43 }
'reveal', { c_unhide = 44 }
'punch', { c_punch = 45 }
'ping', { c_ping = 46 }
'health', { c_health = 47 }
'get', { c_get = 48 }
'drop', { c_drop = 49 }
'inventory', { c_inv = 50 }
'i', { c_i = 51 }
'self', { c_self = 52 }
'whois', { c_whois = 53 }
'duplicate', { c_duplicate = 54 }
'',
'version', { c_version = 56}
'objects', { c_objects = 57}
'use', { c_use = 58 }
'wield', { c_wield = 59 }
'brief', { c_brief = 60 }
'wear', { c_wear = 61 }
'relink', { c_relink = 62 }
'unmake', { c_unmake = 63 }
'destroy', { c_destroy = 64}
'show', { c_show = 65 }
'set', { c_set = 66 }
'',
'',
'',
'',
'',
'',
'',
'',
''
);
numcmds: integer; { number of main level commands there are }
show: array[1..maxshow] of shortstring;
numshow: integer;
setkey: array[1..maxshow] of shortstring;
numset: integer;
direct: array[1..maxexit] of shortstring :=
('north','south','east','west','up','down');
spells: array[1..maxspells] of string; { names of spells }
numspells: integer; { number of spells there actually are }
done: boolean; { flag for QUIT }
userid: veryshortstring; { userid of this player }
location: integer; { current place number }
hold_kind: array[1..maxhold] of integer; { kinds of the objects i'm
holding }
myslot: integer := 1; { here.people[myslot]... is this player }
myname: shortstring; { personal name this player chose (setname) }
myevent: integer; { which point in event buffer we are at }
found_exit: array[1..maxexit] of boolean;
{ has exit i been found by the player? }
mylog: integer; { which log entry this player is }
mywear: integer; { what I'm wearing }
mywield: integer; { weapon I'm wielding }
myhealth: integer; { how well I'm feeling }
myexperience: integer; { how experienced I am }
myself: integer; { self description block }
healthcycle: integer; { used in rnd_event to control how quickly a
player heals }
here: room; { current room record }
event: eventrec;
privd: boolean;
objnam, { object names }
objown, { object owners }
nam, { record 1 is room names }
own, { rec 2 is room owners }
pers, { 3 is player personal names }
user, { 4 is player userid }
adate, { 5 is date of last play }
atime { 6 is time of last play }
: namrec;
anint: intrec; { info about game players }
obj: objectrec;
spell: spellrec;
block: descrec; { a text block of descmax lines }
indx: indexrec; { an record allocation record }
oneliner: linerec; { a line record }
heredsc: descrec;
[external]
procedure wait(seconds: real); { system SLEEP call }
external;
[external]
function random:real; { system random number generator }
external;
[external]
function rnd100: integer; { returns a random # between 0-100 }
external;
[external]
procedure setup_guts; { disables ctrl-Y/ctrl-C }
{ necessary to prevent ZOMBIES in the world }
extern;
[external]
procedure finish_guts; { re-enables ctrl-Y/ctrl-C }
extern;
[external] function get_userid:string;
external;
[external] function trim(s: string): string;
external;
[external]
procedure grab_line(prompt: string; var s:string; echo:boolean := true);
{ Input routine. Gets a line of text from user which checking
for async events }
external;
[external]
procedure putchars(s: string);
extern;
procedure xpoof(loc: integer);
forward;
procedure do_exit(exit_slot: integer);
forward;
function put_token(room: integer;var aslot:integer;hidelev:integer := 0):boolean;
forward;
procedure take_token(aslot, roomno: integer);
forward;
procedure maybe_drop;
forward;
procedure do_program(objnam: string);
forward;
function drop_everything(pslot: integer := 0): boolean;
forward;
procedure collision_wait;
var
wait_time: real;
begin
wait_time := random;
if wait_time < 0.001 then
wait_time := 0.001;
wait(wait_time);
end;
{ increment err; if err is too high, suspect deadlock }
{ this is called by all getX procedures to ease deadlock checking }
procedure deadcheck(var err: integer; s:string);
begin
err := err + 1;
if err > maxerr then begin
writeln('%warning- ',s,' seems to be deadlocked; notify the Monster Manager');
finish_guts;
halt;
err := 0;
end;
end;
{ first procedure of form getX
attempts to get given room record
resolves record access conflicts, checks for deadlocks
Locks record; use freeroom immediately after getroom if data is
for read-only
}
procedure getroom(n: integer:= 0);
var
err: integer;
begin
if n = 0 then
n := location;
roomfile^.valid := 0;
err := 0;
if debug then
writeln('%getroom(',n:1,')');
find(roomfile,n,error := continue);
while roomfile^.valid <> n do begin
deadcheck(err,'getroom');
collision_wait;
find(roomfile,n,error := continue);
end;
here := roomfile^;
inmem := false;
{ since this getroom could be doing anything, we will
assume that it is bozoing the correct here record for
this room. If this getroom called by gethere, then
gethere will correct inmem immediately. Otherwise
the next gethere will restore the correct here record. }
end;
procedure putroom;
begin
locate(roomfile,here.valid);
roomfile^ := here;
put(roomfile);
end;
procedure freeroom; { unlock the record if you're not going to write it }
begin
unlock(roomfile);
end;
procedure gethere(n: integer := 0);
begin
if (n = 0) or (n = location) then begin
if not(inmem) then begin
getroom; { getroom(n) okay here also }
freeroom;
inmem := true;
end else if debug then
writeln('%gethere - here already in memory');
end else begin
getroom(n);
freeroom;
end;
end;
procedure getown;
var
err: integer;
begin
namfile^.validate := 0;
err := 0;
find(namfile,2,error := continue);
while namfile^.validate <> 2 do begin
deadcheck(err,'getown');
collision_wait;
find(namfile,2,error := continue);
end;
own := namfile^;
end;
procedure getnam;
var
err: integer;
begin
namfile^.validate := 0;
err := 0;
find(namfile,1,error := continue);
while namfile^.validate <> 1 do begin
deadcheck(err,'getnam');
collision_wait;
find(namfile,1,error := continue);
end;
nam := namfile^;
end;
procedure freenam;
begin
unlock(namfile);
end;
procedure freeown;
begin
unlock(namfile);
end;
procedure putnam;
begin
locate(namfile,1);
namfile^:= nam;
put(namfile);
end;
procedure putown;
begin
locate(namfile,2);
namfile^:= own;
put(namfile);
end;
procedure getobj(n: integer);
var
err: integer;
begin
if n = 0 then
n := location;
objfile^.objnum := 0;
err := 0;
find(objfile,n,error := continue);
while objfile^.objnum <> n do begin
deadcheck(err,'getobj');
collision_wait;
find(objfile,n,error := continue);
end;
obj := objfile^;
end;
procedure putobj;
begin
locate(objfile,obj.objnum);
objfile^ := obj;
put(objfile);
end;
procedure freeobj; { unlock the record if you're not going to write it }
begin
unlock(objfile);
end;
procedure getint(n: integer);
var
err: integer;
begin
intfile^.intnum := 0;
err := 0;
find(intfile,n,error := continue);
while intfile^.intnum <> n do begin
deadcheck(err,'getint');
collision_wait;
find(intfile,n,error := continue);
end;
anint := intfile^;
end;
procedure freeint;
begin
unlock(intfile);
end;
procedure putint;
var
n: integer;
begin
n := anint.intnum;
locate(intfile,n);
intfile^:= anint;
put(intfile);
end;
procedure getspell(n: integer := 0);
var
err: integer;
begin
if n = 0 then
n := mylog;
spellfile^.recnum := 0;
err := 0;
find(spellfile,n,error := continue);
while spellfile^.recnum <> n do begin
deadcheck(err,'getspell');
collision_wait;
find(spellfile,n,error := continue);
end;
spell := spellfile^;
end;
procedure freespell;
begin
unlock(spellfile);
end;
procedure putspell;
var
n: integer;
begin
n := spell.recnum;
locate(spellfile,n);
spellfile^:= spell;
put(spellfile);
end;
procedure getuser; { get log rec with everyone's userids in it }
var
err: integer;
begin
namfile^.validate := 0;
err := 0;
find(namfile,4,error := continue);
while namfile^.validate <> 4 do begin
deadcheck(err,'getuser');
collision_wait;