-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonalloc.pas
253 lines (219 loc) · 5.66 KB
/
monalloc.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
[inherit('monconst','montype','monglobl')]
MODULE MonAlloc(Input, Output);
%include 'headers.txt'
[GLOBAL]
FUNCTION CountRooms(S:ShortString; VAR NumRooms : INTEGER) : BYTE_BOOL;
var
RoomOwners : LongNameRec;
RoomIndex : IndexRec;
Loop : integer;
Status : BYTE_BOOL;
BEGIN
NumRooms := 0;
Status := GetLongName(L_NA_RoomOwn, RoomOwners);
IF Status THEN
BEGIN
Status := GetIndex(I_Room, RoomIndex);
IF Status THEN
BEGIN
FOR Loop := 1 to RoomIndex.Top DO
IF NOT(RoomIndex.Free[Loop]) THEN
IF (RoomOwners.Idents[Loop] = S) THEN
NumRooms := NumRooms + 1;
END;
END;
CountRooms := Status;
END;
(* -------------------------------------------------------------------------- *)
[GLOBAL]
FUNCTION CountObjects(S:ShortString; VAR NumObjects : INTEGER) : BYTE_BOOL;
VAR
Loop : INTEGER;
Status : BYTE_BOOL;
ObjectOwners : ShortNameRec;
ObjectIndex : IndexRec;
BEGIN
Status := GetShortName(S_NA_ObjOwn, ObjectOwners);
IF Status THEN
BEGIN
Status := GetIndex(I_Object, ObjectIndex);
IF Status THEN
BEGIN
NumObjects := 0;
FOR Loop := 1 to ObjectIndex.Top DO
BEGIN
IF NOT(ObjectIndex.Free[Loop]) THEN
IF (ObjectOwners.Idents[Loop] = S) THEN
NumObjects := NumObjects + 1;
END;
END;
END;
CountObjects := Status;
end;
(* -------------------------------------------------------------------------- *)
[GLOBAL]
FUNCTION AllowRoomOwnership(MyLog : INTEGER;
Userid : VeryShortString) : BYTE_BOOL;
VAR
Character : CharRec;
NumbRooms : INTEGER;
BEGIN
IF GetChar(MyLog, Character) THEN
IF CountRooms(UserId,NumbRooms) THEN
AllowRoomOwnership := (Character.maxrooms > NumbRooms)
ELSE
BEGIN
AllowRoomOwnership := FALSE;
Writeln('Error counting number of rooms - AllowRoomOwnership.');
END
ELSE
BEGIN
Writeln('Error reading character record - AllowRoomOwnership');
AllowRoomOwnership := FALSE;
END;
END;
(* -------------------------------------------------------------------------- *)
[GLOBAL]
FUNCTION AllowObjectOwnership(MyLog : INTEGER;
Userid : VeryShortString) : BYTE_BOOL;
VAR
Character : CharRec;
NumbObjects : INTEGER;
BEGIN
IF GetChar(MyLog, Character) THEN
IF CountObjects(UserId,NumbObjects) THEN
AllowObjectOwnership := (Character.MaxObjs > NumbObjects)
ELSE
BEGIN
AllowObjectOwnership := FALSE;
Writeln('Error counting number of rooms - AllowObjectOwnership.');
END
ELSE
BEGIN
Writeln('Error reading character record - AllowObjectOwnership');
AllowObjectOwnership := FALSE;
END;
END;
(* -------------------------------------------------------------------------- *)
[GLOBAL]
FUNCTION AllocDetail(VAR Index : INTEGER; S : String;
ThisRoom : INTEGER): BYTE_BOOL;
VAR
Found : BYTE_BOOL;
Status : BYTE_BOOL;
Here : RoomDesc;
BEGIN
Index := 1;
Found := FALSE;
Status := GetRoomDesc(ThisRoom, Here);
IF Status THEN
BEGIN
WHILE (Index <= MaxDetail) AND (NOT Found) DO
BEGIN
IF (Here.DetailDesc[Index] = 0) OR
(Here.DetailDesc[Index] = DEFAULT_DESC) THEN
Found := TRUE
ELSE
Index := Index + 1;
END;
IF Found THEN
BEGIN
Status := GetRoomDesc(ThisRoom, Here);
IF Status THEN
BEGIN
Here.Detail[Index] := LowCase(S);
Status := SaveRoomDesc(ThisRoom, Here);
IF Status THEN
LogEvent(0, 0, E_READ_ROOMDESC, 0, 0, 0, 0, '', ThisRoom);
END
ELSE
Writeln('Error reading in from room file - AllocDetail.');
END
ELSE
Writeln('Could not find a blank slot.');
END
ELSE
Writeln('Error reading in from room file - AllocDetail.');
AllocDetail := Status AND Found
END;
(* -------------------------------------------------------------------------- *)
[GLOBAL]
FUNCTION Allocate(IndexNum : INTEGER; VAR Slot : INTEGER) : BYTE_BOOL;
VAR
Index : IndexRec;
Found : BYTE_BOOL;
Status : BYTE_BOOL;
BEGIN
IF FindFreeIndexSlot(IndexNum, Slot) THEN
BEGIN
IF GetIndex(IndexNum, Index) THEN
BEGIN
Index.Free[Slot] := FALSE;
Index.InUse := Index.InUse + 1;
Status := SaveIndex(IndexNum, Index);
END
ELSE
Status := FALSE;
Allocate := Status;
IF Status THEN
Writeln('Space allocated.')
ELSE
Writeln('Space not allocated.');
END
ELSE
BEGIN
Writeln('There is no more space available.');
Allocate := FALSE;
END;
END;
(* -------------------------------------------------------------------------- *)
[GLOBAL]
FUNCTION DeAllocate(Indexnum : INTEGER; Slot : INTEGER) : BYTE_BOOL;
VAR
Index : IndexRec;
Status : BYTE_BOOL := TRUE;
BEGIN
IF GetIndex(IndexNum, Index) THEN
BEGIN
Index.InUse := Index.InUse - 1;
Index.Free[Slot] := TRUE;
Status := SaveIndex(IndexNum, Index);
END
ELSE
Status := FALSE;
DeAllocate := Status;
END;
(* -------------------------------------------------------------------------- *)
[GLOBAL]
FUNCTION DeAllocateDesc(Slot : INTEGER) : BYTE_BOOL;
VAR
Index : IndexRec;
Status : BYTE_BOOL := TRUE;
IndexNum : INTEGER := 0;
BEGIN
IF Slot < 0 THEN
BEGIN
IndexNum := I_LINE;
Slot := -Slot;
END
ELSE
IF (Slot > 0) THEN
IF (Slot <> DEFAULT_DESC) THEN
IndexNum := I_BLOCK;
IF (IndexNum <> 0) THEN
BEGIN
IF (Slot <> DEFAULT_DESC) THEN
BEGIN
IF GetIndex(IndexNum, Index) THEN
BEGIN
Index.InUse := Index.InUse - 1;
Index.Free[Slot] := TRUE;
Status := SaveIndex(IndexNum, Index);
END
ELSE
Status := FALSE;
END;
END;
DeAllocateDesc := Status;
END;
END.