-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathitems.inc
165 lines (149 loc) · 3.16 KB
/
items.inc
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
{ Item generation }
Procedure GenerateLight(I: Integer);
Var
P: Real;
DU, DL: Integer;
Begin
P := Random;
If P > 0.95 Then
Begin
DL := 9;
DU := 10;
End
Else If P > 0.9 Then
Begin
DL := 7;
DU := 9;
End
Else If P > 0.8 Then
Begin
DL := 4;
DU := 8;
End
Else If P > 0.6 Then
Begin
DL := 2;
DU := 5;
End
Else
Begin
DL := 1;
DU := 3;
End;
{ light will become less effective per level }
With Items[I] Do
Begin
IType := 1; { light }
Taken := False;
L := (Random(DU - DL) + DL) * 16 div Min(DC + 1, 16);
T := 0;
D1 := Random(DU - DL) + DL;
D2 := Random(10);
End;
End;
Procedure GenerateTreasure(I: Integer);
Begin
With Items[I] Do
Begin
IType := 2; { treasure }
Taken := False;
L := 0;
T := 1; { all treasure equal val }
D1 := Random(10) + 10;
D2 := Random(10) + 10;
End;
DT := DT + 1;
End;
{ check for collisions with items }
Function HitItem(X1, Y1: Integer): Integer;
Var
I: Integer;
Found: Boolean;
Begin
Found := False;
I := 1;
If ItemI > 0 Then
Repeat
Begin
With Items[I] Do
Begin
If (X = X1) And (Y = Y1) And (Not Taken) Then
Found := True
Else
I := I + 1;
End;
End;
Until (I > ItemI) Or Found;
If Found Then HitItem := I
Else HitItem := -1;
End;
{ Generate upto 3 items per room }
Procedure GenerateItems;
Var
I, J: Integer;
P: Real;
Valid: Boolean;
Begin
CLight := -1;
CTreasure := -1;
{ player is given 1st light }
GenerateLight(0);
ItemI := 0;
T := 0;
DT := 0;
CT := 0;
For I := 0 To RoomI Do
Begin
For J := 0 To 4 Do
Begin
Repeat
Begin
Valid := True;
P := Random;
If P > 0.4 Then
Begin { we can adjust this as a difficulty }
With Items[ItemI + 1], Rooms[I] Do
Begin
Redraw := True;
X := Random(X2 - X1 - 2) + X1 + 1;
Y := Random(Y2 - Y1 - 2) + Y1 + 1;
Room := I;
Valid := HitItem(X, Y) = -1;
If Valid Then
Begin
If P > 0.8 Then GenerateTreasure(ItemI + 1)
Else GenerateLight(ItemI + 1);
ItemI := ItemI + 1;
End
End;
End
End;
Until Valid;
End;
End;
End;
{ set all items for redraw }
Procedure SetAllRedraw;
Var
I : Integer;
Begin
For I := 1 To ItemI Do Items[I].Redraw := True;
End;
{ take the item, apply side effects to globals }
Procedure TakeItem(I: Integer);
Begin
Items[I].Taken := True;
Items[I].Redraw := True;
If Items[I].L > 0 Then
Begin
SetAllRedraw;
L := Items[I].L;
CLight := I;
End;
If Items[I].T > 0 Then
Begin
T := T + Items[I].T;
CTreasure := I;
CT := 3;
End;
End;