-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonindex.pas
145 lines (129 loc) · 3.6 KB
/
monindex.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
[INHERIT ('monconst','montype')]
MODULE MonIndex(OUTPUT);
%include 'headers.txt'
[GLOBAL]
FUNCTION ChangeTopIndex(Number : INTEGER; FileSlot : INTEGER;
MaxValue :INTEGER) : BYTE_BOOL;
(* Number is the number of allocated slots taht should be put it *)
(* FileSlot should have the form I_xxxxx; where I_xxxxx is one of the defined
constants in monconst.pas *)
(* MaxValue, should be a constant, such as MaxRoom or MaxIndex or MaxSpell.. *)
VAR
Index : IndexRec;
BEGIN
IF GetIndex(FileSlot, Index) THEN
BEGIN
IF Index.Top + Number <= MaxValue THEN
Index.Top := Index.Top + Number
ELSE
BEGIN
Writeln('Insufficient space. Adding ',MaxValue-Index.Top:3,' slots.');
Index.Top := MaxValue;
END;
ChangeTopIndex := SaveIndex(FileSlot, Index);
END
ELSE
ChangeTopIndex := FALSE;
END;
(* -------------------------------------------------------------------------- *)
[GLOBAL]
FUNCTION FindFreeIndexSlot(IndexNum : INTEGER; VAR Slot : INTEGER) : BYTE_BOOL;
VAR
Indx : IndexRec;
Found : BYTE_BOOL;
BEGIN
Found := FALSE;
Slot := 0;
IF GetIndex(IndexNum, Indx) THEN
WHILE Not(Found) AND (Slot < Indx.Top) DO
BEGIN
Slot := Slot + 1;
Found := Indx.Free[Slot];
END;
FindFreeIndexSlot := Found;
END;
(* -------------------------------------------------------------------------- *)
[GLOBAL]
PROCEDURE ResetIndex(IndexNum : INTEGER; MaxValue : INTEGER);
VAR
Indx : IndexRec;
Loop : INTEGER;
BEGIN
Indx := ZERO;
FOR Loop := 1 TO MaxValue DO
Indx.Free[Loop] := TRUE;
Indx.InUse := 0;
Indx.Top := MaxValue;
IF SaveIndex(IndexNum, Indx) THEN
END;
[GLOBAL]
PROCEDURE FixIndex;
VAR
Loop2, Loop : INTEGER;
Ind : IndexRec;
lnam1, lnam2 : longnamerec;
snam1 : shortnamerec;
rsnm1 : realshortnamerec;
HDesc : RoomDesc;
Obj : ObjectRec;
Class : ClassRec;
Spell : SpellRec;
BEGIN
For Loop := 1 TO I_MAX DO
BEGIN
IF GetIndex(Loop, Ind) THEN
BEGIN
CASE Loop OF
I_ROOM : BEGIN
GetLongName(l_na_roomnam, lnam1);
GetLongName(l_na_roomown, lnam2);
END;
I_OBJECT : GetShortName(s_na_objnam, snam1);
I_CLASS : GetRealShortName(rsnr_class, rsnm1);
I_SPELL : GetShortName(s_na_spell, snam1);
END;
FOR Loop2 := 1 TO Ind.top DO
BEGIN
IF not Ind.free[loop2] THEN
BEGIN
CASE Loop OF
I_ROOM : BEGIN
IF GetRoomDesc(Loop2, HDesc) THEN
BEGIN
lnam1.Idents[Loop2] := HDesc.NiceName;
lnam2.Idents[Loop2] := HDesc.Owner;
END;
END;
I_OBJECT : BEGIN
IF GetObj(Loop2, Obj) THEN
snam1.idents[Loop2] := Obj.ObjName
ELSE
ind.free[loop] := true;
END;
I_CLASS :
IF GetClass(Loop2, Class) THEN
rsnm1.idents[loop2] := class.name
ELSE
Ind.free[loop] := true;
I_SPELL :
IF GetSpell(Loop2, Spell) THEN
snam1.idents[loop2] := spell.name
ELSE
Ind.free[loop] := true;
END;
END; (* if inuse *)
END; (* for loop2 *)
SaveIndex(Loop, Ind);
CASE Loop OF
I_ROOM : BEGIN
SaveLongName(l_na_roomnam, lnam1);
SaveLongName(l_na_roomown, lnam2);
END;
I_OBJECT : SaveShortName(s_na_objnam, snam1);
I_CLASS : SaveRealShortName(rsnr_class, rsnm1);
I_SPELL : SaveShortName(s_na_spell, snam1);
END;
END; (* get index *)
END;
END;
END.