Devilution
Diablo devolved - magic behind the 1996 computer game
lighting.cpp
Go to the documentation of this file.
1 
6 #include "all.h"
7 
9 
14 BYTE lightradius[16][128];
15 BOOL dovision;
17 char lightmax;
19 BYTE lightblock[64][16][16];
21 BYTE *pLightTbl;
22 BOOL lightflag;
23 
47 char CrawlTable[2749] = {
48  1,
49  0, 0,
50  4,
51  0, 1, 0, -1, -1, 0, 1, 0,
52  16,
53  0, 2, 0, -2, -1, 2, 1, 2,
54  -1, -2, 1, -2, -1, 1, 1, 1,
55  -1, -1, 1, -1, -2, 1, 2, 1,
56  -2, -1, 2, -1, -2, 0, 2, 0,
57  24,
58  0, 3, 0, -3, -1, 3, 1, 3,
59  -1, -3, 1, -3, -2, 3, 2, 3,
60  -2, -3, 2, -3, -2, 2, 2, 2,
61  -2, -2, 2, -2, -3, 2, 3, 2,
62  -3, -2, 3, -2, -3, 1, 3, 1,
63  -3, -1, 3, -1, -3, 0, 3, 0,
64  32,
65  0, 4, 0, -4, -1, 4, 1, 4,
66  -1, -4, 1, -4, -2, 4, 2, 4,
67  -2, -4, 2, -4, -3, 4, 3, 4,
68  -3, -4, 3, -4, -3, 3, 3, 3,
69  -3, -3, 3, -3, -4, 3, 4, 3,
70  -4, -3, 4, -3, -4, 2, 4, 2,
71  -4, -2, 4, -2, -4, 1, 4, 1,
72  -4, -1, 4, -1, -4, 0, 4, 0,
73  40,
74  0, 5, 0, -5, -1, 5, 1, 5,
75  -1, -5, 1, -5, -2, 5, 2, 5,
76  -2, -5, 2, -5, -3, 5, 3, 5,
77  -3, -5, 3, -5, -4, 5, 4, 5,
78  -4, -5, 4, -5, -4, 4, 4, 4,
79  -4, -4, 4, -4, -5, 4, 5, 4,
80  -5, -4, 5, -4, -5, 3, 5, 3,
81  -5, -3, 5, -3, -5, 2, 5, 2,
82  -5, -2, 5, -2, -5, 1, 5, 1,
83  -5, -1, 5, -1, -5, 0, 5, 0,
84  48,
85  0, 6, 0, -6, -1, 6, 1, 6,
86  -1, -6, 1, -6, -2, 6, 2, 6,
87  -2, -6, 2, -6, -3, 6, 3, 6,
88  -3, -6, 3, -6, -4, 6, 4, 6,
89  -4, -6, 4, -6, -5, 6, 5, 6,
90  -5, -6, 5, -6, -5, 5, 5, 5,
91  -5, -5, 5, -5, -6, 5, 6, 5,
92  -6, -5, 6, -5, -6, 4, 6, 4,
93  -6, -4, 6, -4, -6, 3, 6, 3,
94  -6, -3, 6, -3, -6, 2, 6, 2,
95  -6, -2, 6, -2, -6, 1, 6, 1,
96  -6, -1, 6, -1, -6, 0, 6, 0,
97  56,
98  0, 7, 0, -7, -1, 7, 1, 7,
99  -1, -7, 1, -7, -2, 7, 2, 7,
100  -2, -7, 2, -7, -3, 7, 3, 7,
101  -3, -7, 3, -7, -4, 7, 4, 7,
102  -4, -7, 4, -7, -5, 7, 5, 7,
103  -5, -7, 5, -7, -6, 7, 6, 7,
104  -6, -7, 6, -7, -6, 6, 6, 6,
105  -6, -6, 6, -6, -7, 6, 7, 6,
106  -7, -6, 7, -6, -7, 5, 7, 5,
107  -7, -5, 7, -5, -7, 4, 7, 4,
108  -7, -4, 7, -4, -7, 3, 7, 3,
109  -7, -3, 7, -3, -7, 2, 7, 2,
110  -7, -2, 7, -2, -7, 1, 7, 1,
111  -7, -1, 7, -1, -7, 0, 7, 0,
112  64,
113  0, 8, 0, -8, -1, 8, 1, 8,
114  -1, -8, 1, -8, -2, 8, 2, 8,
115  -2, -8, 2, -8, -3, 8, 3, 8,
116  -3, -8, 3, -8, -4, 8, 4, 8,
117  -4, -8, 4, -8, -5, 8, 5, 8,
118  -5, -8, 5, -8, -6, 8, 6, 8,
119  -6, -8, 6, -8, -7, 8, 7, 8,
120  -7, -8, 7, -8, -7, 7, 7, 7,
121  -7, -7, 7, -7, -8, 7, 8, 7,
122  -8, -7, 8, -7, -8, 6, 8, 6,
123  -8, -6, 8, -6, -8, 5, 8, 5,
124  -8, -5, 8, -5, -8, 4, 8, 4,
125  -8, -4, 8, -4, -8, 3, 8, 3,
126  -8, -3, 8, -3, -8, 2, 8, 2,
127  -8, -2, 8, -2, -8, 1, 8, 1,
128  -8, -1, 8, -1, -8, 0, 8, 0,
129  72,
130  0, 9, 0, -9, -1, 9, 1, 9,
131  -1, -9, 1, -9, -2, 9, 2, 9,
132  -2, -9, 2, -9, -3, 9, 3, 9,
133  -3, -9, 3, -9, -4, 9, 4, 9,
134  -4, -9, 4, -9, -5, 9, 5, 9,
135  -5, -9, 5, -9, -6, 9, 6, 9,
136  -6, -9, 6, -9, -7, 9, 7, 9,
137  -7, -9, 7, -9, -8, 9, 8, 9,
138  -8, -9, 8, -9, -8, 8, 8, 8,
139  -8, -8, 8, -8, -9, 8, 9, 8,
140  -9, -8, 9, -8, -9, 7, 9, 7,
141  -9, -7, 9, -7, -9, 6, 9, 6,
142  -9, -6, 9, -6, -9, 5, 9, 5,
143  -9, -5, 9, -5, -9, 4, 9, 4,
144  -9, -4, 9, -4, -9, 3, 9, 3,
145  -9, -3, 9, -3, -9, 2, 9, 2,
146  -9, -2, 9, -2, -9, 1, 9, 1,
147  -9, -1, 9, -1, -9, 0, 9, 0,
148  80,
149  0, 10, 0, -10, -1, 10, 1, 10,
150  -1, -10, 1, -10, -2, 10, 2, 10,
151  -2, -10, 2, -10, -3, 10, 3, 10,
152  -3, -10, 3, -10, -4, 10, 4, 10,
153  -4, -10, 4, -10, -5, 10, 5, 10,
154  -5, -10, 5, -10, -6, 10, 6, 10,
155  -6, -10, 6, -10, -7, 10, 7, 10,
156  -7, -10, 7, -10, -8, 10, 8, 10,
157  -8, -10, 8, -10, -9, 10, 9, 10,
158  -9, -10, 9, -10, -9, 9, 9, 9,
159  -9, -9, 9, -9, -10, 9, 10, 9,
160  -10, -9, 10, -9, -10, 8, 10, 8,
161  -10, -8, 10, -8, -10, 7, 10, 7,
162  -10, -7, 10, -7, -10, 6, 10, 6,
163  -10, -6, 10, -6, -10, 5, 10, 5,
164  -10, -5, 10, -5, -10, 4, 10, 4,
165  -10, -4, 10, -4, -10, 3, 10, 3,
166  -10, -3, 10, -3, -10, 2, 10, 2,
167  -10, -2, 10, -2, -10, 1, 10, 1,
168  -10, -1, 10, -1, -10, 0, 10, 0,
169  88,
170  0, 11, 0, -11, -1, 11, 1, 11,
171  -1, -11, 1, -11, -2, 11, 2, 11,
172  -2, -11, 2, -11, -3, 11, 3, 11,
173  -3, -11, 3, -11, -4, 11, 4, 11,
174  -4, -11, 4, -11, -5, 11, 5, 11,
175  -5, -11, 5, -11, -6, 11, 6, 11,
176  -6, -11, 6, -11, -7, 11, 7, 11,
177  -7, -11, 7, -11, -8, 11, 8, 11,
178  -8, -11, 8, -11, -9, 11, 9, 11,
179  -9, -11, 9, -11, -10, 11, 10, 11,
180  -10, -11, 10, -11, -10, 10, 10, 10,
181  -10, -10, 10, -10, -11, 10, 11, 10,
182  -11, -10, 11, -10, -11, 9, 11, 9,
183  -11, -9, 11, -9, -11, 8, 11, 8,
184  -11, -8, 11, -8, -11, 7, 11, 7,
185  -11, -7, 11, -7, -11, 6, 11, 6,
186  -11, -6, 11, -6, -11, 5, 11, 5,
187  -11, -5, 11, -5, -11, 4, 11, 4,
188  -11, -4, 11, -4, -11, 3, 11, 3,
189  -11, -3, 11, -3, -11, 2, 11, 2,
190  -11, -2, 11, -2, -11, 1, 11, 1,
191  -11, -1, 11, -1, -11, 0, 11, 0,
192  96,
193  0, 12, 0, -12, -1, 12, 1, 12,
194  -1, -12, 1, -12, -2, 12, 2, 12,
195  -2, -12, 2, -12, -3, 12, 3, 12,
196  -3, -12, 3, -12, -4, 12, 4, 12,
197  -4, -12, 4, -12, -5, 12, 5, 12,
198  -5, -12, 5, -12, -6, 12, 6, 12,
199  -6, -12, 6, -12, -7, 12, 7, 12,
200  -7, -12, 7, -12, -8, 12, 8, 12,
201  -8, -12, 8, -12, -9, 12, 9, 12,
202  -9, -12, 9, -12, -10, 12, 10, 12,
203  -10, -12, 10, -12, -11, 12, 11, 12,
204  -11, -12, 11, -12, -11, 11, 11, 11,
205  -11, -11, 11, -11, -12, 11, 12, 11,
206  -12, -11, 12, -11, -12, 10, 12, 10,
207  -12, -10, 12, -10, -12, 9, 12, 9,
208  -12, -9, 12, -9, -12, 8, 12, 8,
209  -12, -8, 12, -8, -12, 7, 12, 7,
210  -12, -7, 12, -7, -12, 6, 12, 6,
211  -12, -6, 12, -6, -12, 5, 12, 5,
212  -12, -5, 12, -5, -12, 4, 12, 4,
213  -12, -4, 12, -4, -12, 3, 12, 3,
214  -12, -3, 12, -3, -12, 2, 12, 2,
215  -12, -2, 12, -2, -12, 1, 12, 1,
216  -12, -1, 12, -1, -12, 0, 12, 0,
217  104,
218  0, 13, 0, -13, -1, 13, 1, 13,
219  -1, -13, 1, -13, -2, 13, 2, 13,
220  -2, -13, 2, -13, -3, 13, 3, 13,
221  -3, -13, 3, -13, -4, 13, 4, 13,
222  -4, -13, 4, -13, -5, 13, 5, 13,
223  -5, -13, 5, -13, -6, 13, 6, 13,
224  -6, -13, 6, -13, -7, 13, 7, 13,
225  -7, -13, 7, -13, -8, 13, 8, 13,
226  -8, -13, 8, -13, -9, 13, 9, 13,
227  -9, -13, 9, -13, -10, 13, 10, 13,
228  -10, -13, 10, -13, -11, 13, 11, 13,
229  -11, -13, 11, -13, -12, 13, 12, 13,
230  -12, -13, 12, -13, -12, 12, 12, 12,
231  -12, -12, 12, -12, -13, 12, 13, 12,
232  -13, -12, 13, -12, -13, 11, 13, 11,
233  -13, -11, 13, -11, -13, 10, 13, 10,
234  -13, -10, 13, -10, -13, 9, 13, 9,
235  -13, -9, 13, -9, -13, 8, 13, 8,
236  -13, -8, 13, -8, -13, 7, 13, 7,
237  -13, -7, 13, -7, -13, 6, 13, 6,
238  -13, -6, 13, -6, -13, 5, 13, 5,
239  -13, -5, 13, -5, -13, 4, 13, 4,
240  -13, -4, 13, -4, -13, 3, 13, 3,
241  -13, -3, 13, -3, -13, 2, 13, 2,
242  -13, -2, 13, -2, -13, 1, 13, 1,
243  -13, -1, 13, -1, -13, 0, 13, 0,
244  112,
245  0, 14, 0, -14, -1, 14, 1, 14,
246  -1, -14, 1, -14, -2, 14, 2, 14,
247  -2, -14, 2, -14, -3, 14, 3, 14,
248  -3, -14, 3, -14, -4, 14, 4, 14,
249  -4, -14, 4, -14, -5, 14, 5, 14,
250  -5, -14, 5, -14, -6, 14, 6, 14,
251  -6, -14, 6, -14, -7, 14, 7, 14,
252  -7, -14, 7, -14, -8, 14, 8, 14,
253  -8, -14, 8, -14, -9, 14, 9, 14,
254  -9, -14, 9, -14, -10, 14, 10, 14,
255  -10, -14, 10, -14, -11, 14, 11, 14,
256  -11, -14, 11, -14, -12, 14, 12, 14,
257  -12, -14, 12, -14, -13, 14, 13, 14,
258  -13, -14, 13, -14, -13, 13, 13, 13,
259  -13, -13, 13, -13, -14, 13, 14, 13,
260  -14, -13, 14, -13, -14, 12, 14, 12,
261  -14, -12, 14, -12, -14, 11, 14, 11,
262  -14, -11, 14, -11, -14, 10, 14, 10,
263  -14, -10, 14, -10, -14, 9, 14, 9,
264  -14, -9, 14, -9, -14, 8, 14, 8,
265  -14, -8, 14, -8, -14, 7, 14, 7,
266  -14, -7, 14, -7, -14, 6, 14, 6,
267  -14, -6, 14, -6, -14, 5, 14, 5,
268  -14, -5, 14, -5, -14, 4, 14, 4,
269  -14, -4, 14, -4, -14, 3, 14, 3,
270  -14, -3, 14, -3, -14, 2, 14, 2,
271  -14, -2, 14, -2, -14, 1, 14, 1,
272  -14, -1, 14, -1, -14, 0, 14, 0,
273  120,
274  0, 15, 0, -15, -1, 15, 1, 15,
275  -1, -15, 1, -15, -2, 15, 2, 15,
276  -2, -15, 2, -15, -3, 15, 3, 15,
277  -3, -15, 3, -15, -4, 15, 4, 15,
278  -4, -15, 4, -15, -5, 15, 5, 15,
279  -5, -15, 5, -15, -6, 15, 6, 15,
280  -6, -15, 6, -15, -7, 15, 7, 15,
281  -7, -15, 7, -15, -8, 15, 8, 15,
282  -8, -15, 8, -15, -9, 15, 9, 15,
283  -9, -15, 9, -15, -10, 15, 10, 15,
284  -10, -15, 10, -15, -11, 15, 11, 15,
285  -11, -15, 11, -15, -12, 15, 12, 15,
286  -12, -15, 12, -15, -13, 15, 13, 15,
287  -13, -15, 13, -15, -14, 15, 14, 15,
288  -14, -15, 14, -15, -14, 14, 14, 14,
289  -14, -14, 14, -14, -15, 14, 15, 14,
290  -15, -14, 15, -14, -15, 13, 15, 13,
291  -15, -13, 15, -13, -15, 12, 15, 12,
292  -15, -12, 15, -12, -15, 11, 15, 11,
293  -15, -11, 15, -11, -15, 10, 15, 10,
294  -15, -10, 15, -10, -15, 9, 15, 9,
295  -15, -9, 15, -9, -15, 8, 15, 8,
296  -15, -8, 15, -8, -15, 7, 15, 7,
297  -15, -7, 15, -7, -15, 6, 15, 6,
298  -15, -6, 15, -6, -15, 5, 15, 5,
299  -15, -5, 15, -5, -15, 4, 15, 4,
300  -15, -4, 15, -4, -15, 3, 15, 3,
301  -15, -3, 15, -3, -15, 2, 15, 2,
302  -15, -2, 15, -2, -15, 1, 15, 1,
303  -15, -1, 15, -1, -15, 0, 15, 0,
304  (char)128,
305  0, 16, 0, -16, -1, 16, 1, 16,
306  -1, -16, 1, -16, -2, 16, 2, 16,
307  -2, -16, 2, -16, -3, 16, 3, 16,
308  -3, -16, 3, -16, -4, 16, 4, 16,
309  -4, -16, 4, -16, -5, 16, 5, 16,
310  -5, -16, 5, -16, -6, 16, 6, 16,
311  -6, -16, 6, -16, -7, 16, 7, 16,
312  -7, -16, 7, -16, -8, 16, 8, 16,
313  -8, -16, 8, -16, -9, 16, 9, 16,
314  -9, -16, 9, -16, -10, 16, 10, 16,
315  -10, -16, 10, -16, -11, 16, 11, 16,
316  -11, -16, 11, -16, -12, 16, 12, 16,
317  -12, -16, 12, -16, -13, 16, 13, 16,
318  -13, -16, 13, -16, -14, 16, 14, 16,
319  -14, -16, 14, -16, -15, 16, 15, 16,
320  -15, -16, 15, -16, -15, 15, 15, 15,
321  -15, -15, 15, -15, -16, 15, 16, 15,
322  -16, -15, 16, -15, -16, 14, 16, 14,
323  -16, -14, 16, -14, -16, 13, 16, 13,
324  -16, -13, 16, -13, -16, 12, 16, 12,
325  -16, -12, 16, -12, -16, 11, 16, 11,
326  -16, -11, 16, -11, -16, 10, 16, 10,
327  -16, -10, 16, -10, -16, 9, 16, 9,
328  -16, -9, 16, -9, -16, 8, 16, 8,
329  -16, -8, 16, -8, -16, 7, 16, 7,
330  -16, -7, 16, -7, -16, 6, 16, 6,
331  -16, -6, 16, -6, -16, 5, 16, 5,
332  -16, -5, 16, -5, -16, 4, 16, 4,
333  -16, -4, 16, -4, -16, 3, 16, 3,
334  -16, -3, 16, -3, -16, 2, 16, 2,
335  -16, -2, 16, -2, -16, 1, 16, 1,
336  -16, -1, 16, -1, -16, 0, 16, 0,
337  (char)136,
338  0, 17, 0, -17, -1, 17, 1, 17,
339  -1, -17, 1, -17, -2, 17, 2, 17,
340  -2, -17, 2, -17, -3, 17, 3, 17,
341  -3, -17, 3, -17, -4, 17, 4, 17,
342  -4, -17, 4, -17, -5, 17, 5, 17,
343  -5, -17, 5, -17, -6, 17, 6, 17,
344  -6, -17, 6, -17, -7, 17, 7, 17,
345  -7, -17, 7, -17, -8, 17, 8, 17,
346  -8, -17, 8, -17, -9, 17, 9, 17,
347  -9, -17, 9, -17, -10, 17, 10, 17,
348  -10, -17, 10, -17, -11, 17, 11, 17,
349  -11, -17, 11, -17, -12, 17, 12, 17,
350  -12, -17, 12, -17, -13, 17, 13, 17,
351  -13, -17, 13, -17, -14, 17, 14, 17,
352  -14, -17, 14, -17, -15, 17, 15, 17,
353  -15, -17, 15, -17, -16, 17, 16, 17,
354  -16, -17, 16, -17, -16, 16, 16, 16,
355  -16, -16, 16, -16, -17, 16, 17, 16,
356  -17, -16, 17, -16, -17, 15, 17, 15,
357  -17, -15, 17, -15, -17, 14, 17, 14,
358  -17, -14, 17, -14, -17, 13, 17, 13,
359  -17, -13, 17, -13, -17, 12, 17, 12,
360  -17, -12, 17, -12, -17, 11, 17, 11,
361  -17, -11, 17, -11, -17, 10, 17, 10,
362  -17, -10, 17, -10, -17, 9, 17, 9,
363  -17, -9, 17, -9, -17, 8, 17, 8,
364  -17, -8, 17, -8, -17, 7, 17, 7,
365  -17, -7, 17, -7, -17, 6, 17, 6,
366  -17, -6, 17, -6, -17, 5, 17, 5,
367  -17, -5, 17, -5, -17, 4, 17, 4,
368  -17, -4, 17, -4, -17, 3, 17, 3,
369  -17, -3, 17, -3, -17, 2, 17, 2,
370  -17, -2, 17, -2, -17, 1, 17, 1,
371  -17, -1, 17, -1, -17, 0, 17, 0,
372  (char)144,
373  0, 18, 0, -18, -1, 18, 1, 18,
374  -1, -18, 1, -18, -2, 18, 2, 18,
375  -2, -18, 2, -18, -3, 18, 3, 18,
376  -3, -18, 3, -18, -4, 18, 4, 18,
377  -4, -18, 4, -18, -5, 18, 5, 18,
378  -5, -18, 5, -18, -6, 18, 6, 18,
379  -6, -18, 6, -18, -7, 18, 7, 18,
380  -7, -18, 7, -18, -8, 18, 8, 18,
381  -8, -18, 8, -18, -9, 18, 9, 18,
382  -9, -18, 9, -18, -10, 18, 10, 18,
383  -10, -18, 10, -18, -11, 18, 11, 18,
384  -11, -18, 11, -18, -12, 18, 12, 18,
385  -12, -18, 12, -18, -13, 18, 13, 18,
386  -13, -18, 13, -18, -14, 18, 14, 18,
387  -14, -18, 14, -18, -15, 18, 15, 18,
388  -15, -18, 15, -18, -16, 18, 16, 18,
389  -16, -18, 16, -18, -17, 18, 17, 18,
390  -17, -18, 17, -18, -17, 17, 17, 17,
391  -17, -17, 17, -17, -18, 17, 18, 17,
392  -18, -17, 18, -17, -18, 16, 18, 16,
393  -18, -16, 18, -16, -18, 15, 18, 15,
394  -18, -15, 18, -15, -18, 14, 18, 14,
395  -18, -14, 18, -14, -18, 13, 18, 13,
396  -18, -13, 18, -13, -18, 12, 18, 12,
397  -18, -12, 18, -12, -18, 11, 18, 11,
398  -18, -11, 18, -11, -18, 10, 18, 10,
399  -18, -10, 18, -10, -18, 9, 18, 9,
400  -18, -9, 18, -9, -18, 8, 18, 8,
401  -18, -8, 18, -8, -18, 7, 18, 7,
402  -18, -7, 18, -7, -18, 6, 18, 6,
403  -18, -6, 18, -6, -18, 5, 18, 5,
404  -18, -5, 18, -5, -18, 4, 18, 4,
405  -18, -4, 18, -4, -18, 3, 18, 3,
406  -18, -3, 18, -3, -18, 2, 18, 2,
407  -18, -2, 18, -2, -18, 1, 18, 1,
408  -18, -1, 18, -1, -18, 0, 18, 0
409 };
410 
412 char *pCrawlTable[19] = {
413  CrawlTable,
414  CrawlTable + 3,
415  CrawlTable + 12,
416  CrawlTable + 45,
417  CrawlTable + 94,
418  CrawlTable + 159,
419  CrawlTable + 240,
420  CrawlTable + 337,
421  CrawlTable + 450,
422  CrawlTable + 579,
423  CrawlTable + 724,
424  CrawlTable + 885,
425  CrawlTable + 1062,
426  CrawlTable + 1255,
427  CrawlTable + 1464,
428  CrawlTable + 1689,
429  CrawlTable + 1930,
430  CrawlTable + 2187,
431  CrawlTable + 2460
432 };
434 BYTE vCrawlTable[23][30] = {
435  { 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0 },
436  { 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 1, 9, 1, 10, 1, 11, 1, 12, 1, 13, 1, 14, 1, 15, 1 },
437  { 1, 0, 2, 0, 3, 0, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 11, 1, 12, 2, 13, 2, 14, 2, 15, 2 },
438  { 1, 0, 2, 0, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 2, 9, 2, 10, 2, 11, 2, 12, 2, 13, 3, 14, 3, 15, 3 },
439  { 1, 0, 2, 1, 3, 1, 4, 1, 5, 1, 6, 2, 7, 2, 8, 2, 9, 3, 10, 3, 11, 3, 12, 3, 13, 4, 14, 4, 0, 0 },
440  { 1, 0, 2, 1, 3, 1, 4, 1, 5, 2, 6, 2, 7, 3, 8, 3, 9, 3, 10, 4, 11, 4, 12, 4, 13, 5, 14, 5, 0, 0 },
441  { 1, 0, 2, 1, 3, 1, 4, 2, 5, 2, 6, 3, 7, 3, 8, 3, 9, 4, 10, 4, 11, 5, 12, 5, 13, 6, 14, 6, 0, 0 },
442  { 1, 1, 2, 1, 3, 2, 4, 2, 5, 3, 6, 3, 7, 4, 8, 4, 9, 5, 10, 5, 11, 6, 12, 6, 13, 7, 0, 0, 0, 0 },
443  { 1, 1, 2, 1, 3, 2, 4, 2, 5, 3, 6, 4, 7, 4, 8, 5, 9, 6, 10, 6, 11, 7, 12, 7, 12, 8, 13, 8, 0, 0 },
444  { 1, 1, 2, 2, 3, 2, 4, 3, 5, 4, 6, 5, 7, 5, 8, 6, 9, 7, 10, 7, 10, 8, 11, 8, 12, 9, 0, 0, 0, 0 },
445  { 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9, 11, 9, 11, 10, 0, 0, 0, 0, 0, 0 },
446  { 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 0, 0, 0, 0, 0, 0, 0, 0 },
447  { 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 9, 11, 10, 11, 0, 0, 0, 0, 0, 0 },
448  { 1, 1, 2, 2, 2, 3, 3, 4, 4, 5, 5, 6, 5, 7, 6, 8, 7, 9, 7, 10, 8, 10, 8, 11, 9, 12, 0, 0, 0, 0 },
449  { 1, 1, 1, 2, 2, 3, 2, 4, 3, 5, 4, 6, 4, 7, 5, 8, 6, 9, 6, 10, 7, 11, 7, 12, 8, 12, 8, 13, 0, 0 },
450  { 1, 1, 1, 2, 2, 3, 2, 4, 3, 5, 3, 6, 4, 7, 4, 8, 5, 9, 5, 10, 6, 11, 6, 12, 7, 13, 0, 0, 0, 0 },
451  { 0, 1, 1, 2, 1, 3, 2, 4, 2, 5, 3, 6, 3, 7, 3, 8, 4, 9, 4, 10, 5, 11, 5, 12, 6, 13, 6, 14, 0, 0 },
452  { 0, 1, 1, 2, 1, 3, 1, 4, 2, 5, 2, 6, 3, 7, 3, 8, 3, 9, 4, 10, 4, 11, 4, 12, 5, 13, 5, 14, 0, 0 },
453  { 0, 1, 1, 2, 1, 3, 1, 4, 1, 5, 2, 6, 2, 7, 2, 8, 3, 9, 3, 10, 3, 11, 3, 12, 4, 13, 4, 14, 0, 0 },
454  { 0, 1, 0, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 2, 8, 2, 9, 2, 10, 2, 11, 2, 12, 3, 13, 3, 14, 3, 15 },
455  { 0, 1, 0, 2, 0, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 11, 2, 12, 2, 13, 2, 14, 2, 15 },
456  { 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 1, 8, 1, 9, 1, 10, 1, 11, 1, 12, 1, 13, 1, 14, 1, 15 },
457  { 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15 }
458 };
460 BYTE byte_49463C[18][18] = {
461  { 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 },
462  { 0, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 },
463  { 0, 1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 },
464  { 0, 0, 1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 },
465  { 0, 0, 1, 1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 },
466  { 0, 0, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 },
467  { 0, 0, 0, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 },
468  { 0, 0, 0, 1, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 },
469  { 0, 0, 0, 0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3 },
470  { 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3 },
471  { 0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3 },
472  { 0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3 },
473  { 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3 },
474  { 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3 },
475  { 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3 },
476  { 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3 },
477  { 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3 },
478  { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2 }
479 };
480 
482 BYTE RadiusAdj[23] = { 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 4, 3, 2, 2, 2, 1, 1, 1, 0, 0, 0, 0 };
483 
484 void RotateRadius(int *x, int *y, int *dx, int *dy, int *lx, int *ly, int *bx, int *by)
485 {
486  int swap;
487 
488  *bx = 0;
489  *by = 0;
490 
491  swap = *dx;
492  *dx = 7 - *dy;
493  *dy = swap;
494  swap = *lx;
495  *lx = 7 - *ly;
496  *ly = swap;
497 
498  *x = *dx - *lx;
499  *y = *dy - *ly;
500 
501  if (*x < 0) {
502  *x += 8;
503  *bx = 1;
504  }
505  if (*y < 0) {
506  *y += 8;
507  *by = 1;
508  }
509 }
510 
511 void DoLighting(int nXPos, int nYPos, int nRadius, int Lnum)
512 {
513  int x, y, v, xoff, yoff, mult, radius_block;
514  int min_x, max_x, min_y, max_y;
515  int dist_x, dist_y, light_x, light_y, block_x, block_y, temp_x, temp_y;
516 
517  xoff = 0;
518  yoff = 0;
519  light_x = 0;
520  light_y = 0;
521  block_x = 0;
522  block_y = 0;
523 
524  if (Lnum >= 0) {
525  xoff = LightList[Lnum]._xoff;
526  yoff = LightList[Lnum]._yoff;
527  if (xoff < 0) {
528  xoff += 8;
529  nXPos--;
530  }
531  if (yoff < 0) {
532  yoff += 8;
533  nYPos--;
534  }
535  }
536 
537  dist_x = xoff;
538  dist_y = yoff;
539 
540  if (nXPos - 15 < 0) {
541  min_x = nXPos + 1;
542  } else {
543  min_x = 15;
544  }
545  if (nXPos + 15 > MAXDUNX) {
546  max_x = MAXDUNX - nXPos;
547  } else {
548  max_x = 15;
549  }
550  if (nYPos - 15 < 0) {
551  min_y = nYPos + 1;
552  } else {
553  min_y = 15;
554  }
555  if (nYPos + 15 > MAXDUNY) {
556  max_y = MAXDUNY - nYPos;
557  } else {
558  max_y = 15;
559  }
560 
561  if (nXPos >= 0 && nXPos < MAXDUNX && nYPos >= 0 && nYPos < MAXDUNY) {
562  dLight[nXPos][nYPos] = 0;
563  }
564 
565  mult = xoff + 8 * yoff;
566  for (y = 0; y < min_y; y++) {
567  for (x = 1; x < max_x; x++) {
568  radius_block = lightblock[mult][y][x];
569  if (radius_block < 128) {
570  temp_x = nXPos + x;
571  temp_y = nYPos + y;
572  v = lightradius[nRadius][radius_block];
573  if (temp_x >= 0 && temp_x < MAXDUNX && temp_y >= 0 && temp_y < MAXDUNY) {
574  if (v < dLight[temp_x][temp_y]) {
575  dLight[temp_x][temp_y] = v;
576  }
577  }
578  }
579  }
580  }
581  RotateRadius(&xoff, &yoff, &dist_x, &dist_y, &light_x, &light_y, &block_x, &block_y);
582  mult = xoff + 8 * yoff;
583  for (y = 0; y < max_y; y++) {
584  for (x = 1; x < max_x; x++) {
585  radius_block = lightblock[mult][y + block_y][x + block_x];
586  if (radius_block < 128) {
587  temp_x = nXPos + y;
588  temp_y = nYPos - x;
589  v = lightradius[nRadius][radius_block];
590  if (temp_x >= 0 && temp_x < MAXDUNX && temp_y >= 0 && temp_y < MAXDUNY) {
591  if (v < dLight[temp_x][temp_y]) {
592  dLight[temp_x][temp_y] = v;
593  }
594  }
595  }
596  }
597  }
598  RotateRadius(&xoff, &yoff, &dist_x, &dist_y, &light_x, &light_y, &block_x, &block_y);
599  mult = xoff + 8 * yoff;
600  for (y = 0; y < max_y; y++) {
601  for (x = 1; x < min_x; x++) {
602  radius_block = lightblock[mult][y + block_y][x + block_x];
603  if (radius_block < 128) {
604  temp_x = nXPos - x;
605  temp_y = nYPos - y;
606  v = lightradius[nRadius][radius_block];
607  if (temp_x >= 0 && temp_x < MAXDUNX && temp_y >= 0 && temp_y < MAXDUNY) {
608  if (v < dLight[temp_x][temp_y]) {
609  dLight[temp_x][temp_y] = v;
610  }
611  }
612  }
613  }
614  }
615  RotateRadius(&xoff, &yoff, &dist_x, &dist_y, &light_x, &light_y, &block_x, &block_y);
616  mult = xoff + 8 * yoff;
617  for (y = 0; y < min_y; y++) {
618  for (x = 1; x < min_x; x++) {
619  radius_block = lightblock[mult][y + block_y][x + block_x];
620  if (radius_block < 128) {
621  temp_x = nXPos - y;
622  temp_y = nYPos + x;
623  v = lightradius[nRadius][radius_block];
624  if (temp_x >= 0 && temp_x < MAXDUNX && temp_y >= 0 && temp_y < MAXDUNY) {
625  if (v < dLight[temp_x][temp_y]) {
626  dLight[temp_x][temp_y] = v;
627  }
628  }
629  }
630  }
631  }
632 }
633 
634 void DoUnLight(int nXPos, int nYPos, int nRadius)
635 {
636  int x, y, min_x, min_y, max_x, max_y;
637 
638  nRadius++;
639  min_y = nYPos - nRadius;
640  max_y = nYPos + nRadius;
641  min_x = nXPos - nRadius;
642  max_x = nXPos + nRadius;
643 
644  if (min_y < 0) {
645  min_y = 0;
646  }
647  if (max_y > MAXDUNY) {
648  max_y = MAXDUNY;
649  }
650  if (min_x < 0) {
651  min_x = 0;
652  }
653  if (max_x > MAXDUNX) {
654  max_x = MAXDUNX;
655  }
656 
657  for (y = min_y; y < max_y; y++) {
658  for (x = min_x; x < max_x; x++) {
659  if (x >= 0 && x < MAXDUNX && y >= 0 && y < MAXDUNY) {
660  dLight[x][y] = dPreLight[x][y];
661  }
662  }
663  }
664 }
665 
666 void DoUnVision(int nXPos, int nYPos, int nRadius)
667 {
668  int i, j, x1, y1, x2, y2;
669 
670  nRadius++;
671  y1 = nYPos - nRadius;
672  y2 = nYPos + nRadius;
673  x1 = nXPos - nRadius;
674  x2 = nXPos + nRadius;
675 
676  if (y1 < 0) {
677  y1 = 0;
678  }
679  if (y2 > MAXDUNY) {
680  y2 = MAXDUNY;
681  }
682  if (x1 < 0) {
683  x1 = 0;
684  }
685  if (x2 > MAXDUNX) {
686  x2 = MAXDUNX;
687  }
688 
689  for (i = x1; i < x2; i++) {
690  for (j = y1; j < y2; j++) {
691  dFlags[i][j] &= ~(BFLAG_VISIBLE | BFLAG_LIT);
692  }
693  }
694 }
695 
696 void DoVision(int nXPos, int nYPos, int nRadius, BOOL doautomap, BOOL visible)
697 {
698  BOOL nBlockerFlag;
699  int nCrawlX, nCrawlY, nLineLen, nTrans;
700  int j, k, v, x1adj, x2adj, y1adj, y2adj;
701 
702  if (nXPos >= 0 && nXPos <= MAXDUNX && nYPos >= 0 && nYPos <= MAXDUNY) {
703  if (doautomap) {
704  if (dFlags[nXPos][nYPos] >= 0) {
705  SetAutomapView(nXPos, nXPos);
706  }
707  dFlags[nXPos][nYPos] |= BFLAG_EXPLORED;
708  }
709  if (visible) {
710  dFlags[nXPos][nYPos] |= BFLAG_LIT;
711  }
712  dFlags[nXPos][nYPos] |= BFLAG_VISIBLE;
713  }
714 
715  for (v = 0; v < 4; v++) {
716  for (j = 0; j < 23; j++) {
717  nBlockerFlag = FALSE;
718  nLineLen = 2 * (nRadius - RadiusAdj[j]);
719  for (k = 0; k < nLineLen && !nBlockerFlag; k += 2) {
720  x1adj = 0;
721  x2adj = 0;
722  y1adj = 0;
723  y2adj = 0;
724  switch (v) {
725  case 0:
726  nCrawlX = nXPos + vCrawlTable[j][k];
727  nCrawlY = nYPos + vCrawlTable[j][k + 1];
728  if (vCrawlTable[j][k] > 0 && vCrawlTable[j][k + 1] > 0) {
729  x1adj = -1;
730  y2adj = -1;
731  }
732  break;
733  case 1:
734  nCrawlX = nXPos - vCrawlTable[j][k];
735  nCrawlY = nYPos - vCrawlTable[j][k + 1];
736  if (vCrawlTable[j][k] > 0 && vCrawlTable[j][k + 1] > 0) {
737  y1adj = 1;
738  x2adj = 1;
739  }
740  break;
741  case 2:
742  nCrawlX = nXPos + vCrawlTable[j][k];
743  nCrawlY = nYPos - vCrawlTable[j][k + 1];
744  if (vCrawlTable[j][k] > 0 && vCrawlTable[j][k + 1] > 0) {
745  x1adj = -1;
746  y2adj = 1;
747  }
748  break;
749  case 3:
750  nCrawlX = nXPos - vCrawlTable[j][k];
751  nCrawlY = nYPos + vCrawlTable[j][k + 1];
752  if (vCrawlTable[j][k] > 0 && vCrawlTable[j][k + 1] > 0) {
753  y1adj = -1;
754  x2adj = 1;
755  }
756  break;
757  }
758  if (nCrawlX >= 0 && nCrawlX < MAXDUNX && nCrawlY >= 0 && nCrawlY < MAXDUNY) {
759  nBlockerFlag = nBlockTable[dPiece[nCrawlX][nCrawlY]];
760  if ((x1adj + nCrawlX >= 0 && x1adj + nCrawlX < MAXDUNX && y1adj + nCrawlY >= 0 && y1adj + nCrawlY < MAXDUNY
761  && !nBlockTable[dPiece[x1adj + nCrawlX][y1adj + nCrawlY]])
762  || (x2adj + nCrawlX >= 0 && x2adj + nCrawlX < MAXDUNX && y2adj + nCrawlY >= 0 && y2adj + nCrawlY < MAXDUNY
763  && !nBlockTable[dPiece[x2adj + nCrawlX][y2adj + nCrawlY]])) {
764  if (doautomap) {
765  if (dFlags[nCrawlX][nCrawlY] >= 0) {
766  SetAutomapView(nCrawlX, nCrawlY);
767  }
768  dFlags[nCrawlX][nCrawlY] |= BFLAG_EXPLORED;
769  }
770  if (visible) {
771  dFlags[nCrawlX][nCrawlY] |= BFLAG_LIT;
772  }
773  dFlags[nCrawlX][nCrawlY] |= BFLAG_VISIBLE;
774  if (!nBlockerFlag) {
775  nTrans = dTransVal[nCrawlX][nCrawlY];
776  if (nTrans != 0) {
777  TransList[nTrans] = TRUE;
778  }
779  }
780  }
781  }
782  }
783  }
784  }
785 }
786 
788 {
790 }
791 
793 {
796 }
797 
799 {
800  int i, j, k, l, lights, shade, l1, l2, cnt, rem, div;
801  double fs, fa;
802  BYTE col, max;
803  BYTE *tbl, *trn;
804  BYTE blood[16];
805 
806  tbl = pLightTbl;
807  shade = 0;
808 
809  if (light4flag) {
810  lights = 3;
811  } else {
812  lights = 15;
813  }
814 
815  for (i = 0; i < lights; i++) {
816  *tbl++ = 0;
817  for (j = 0; j < 8; j++) {
818  col = 16 * j + shade;
819  max = 16 * j + 15;
820  for (k = 0; k < 16; k++) {
821  if (k != 0 || j != 0) {
822  *tbl++ = col;
823  }
824  if (col < max) {
825  col++;
826  } else {
827  max = 0;
828  col = 0;
829  }
830  }
831  }
832  for (j = 16; j < 20; j++) {
833  col = 8 * j + (shade >> 1);
834  max = 8 * j + 7;
835  for (k = 0; k < 8; k++) {
836  *tbl++ = col;
837  if (col < max) {
838  col++;
839  } else {
840  max = 0;
841  col = 0;
842  }
843  }
844  }
845  for (j = 10; j < 16; j++) {
846  col = 16 * j + shade;
847  max = 16 * j + 15;
848  for (k = 0; k < 16; k++) {
849  *tbl++ = col;
850  if (col < max) {
851  col++;
852  } else {
853  max = 0;
854  col = 0;
855  }
856  if (col == 255) {
857  max = 0;
858  col = 0;
859  }
860  }
861  }
862  if (light4flag) {
863  shade += 5;
864  } else {
865  shade++;
866  }
867  }
868 
869  for (i = 0; i < 256; i++) {
870  *tbl++ = 0;
871  }
872 
873  if (leveltype == DTYPE_HELL) {
874  tbl = pLightTbl;
875  for (i = 0; i < lights; i++) {
876  l1 = lights - i;
877  l2 = l1;
878  div = lights / l1;
879  rem = lights % l1;
880  cnt = 0;
881  blood[0] = 0;
882  col = 1;
883  for (j = 1; j < 16; j++) {
884  blood[j] = col;
885  l2 += rem;
886  if (l2 > l1 && j < 15) {
887  j++;
888  blood[j] = col;
889  l2 -= l1;
890  }
891  cnt++;
892  if (cnt == div) {
893  col++;
894  cnt = 0;
895  }
896  }
897  *tbl++ = 0;
898  for (j = 1; j <= 15; j++) {
899  *tbl++ = blood[j];
900  }
901  for (j = 15; j > 0; j--) {
902  *tbl++ = blood[j];
903  }
904  *tbl++ = 1;
905  tbl += 224;
906  }
907  *tbl++ = 0;
908  for (j = 0; j < 31; j++) {
909  *tbl++ = 1;
910  }
911  tbl += 224;
912  }
913 
914  trn = LoadFileInMem("PlrGFX\\Infra.TRN", NULL);
915  for (i = 0; i < 256; i++) {
916  *tbl++ = trn[i];
917  }
918  mem_free_dbg(trn);
919 
920  trn = LoadFileInMem("PlrGFX\\Stone.TRN", NULL);
921  for (i = 0; i < 256; i++) {
922  *tbl++ = trn[i];
923  }
924  mem_free_dbg(trn);
925 
926  for (i = 0; i < 8; i++) {
927  for (col = 226; col < 239; col++) {
928  if (i != 0 || col != 226) {
929  *tbl++ = col;
930  } else {
931  *tbl++ = 0;
932  }
933  }
934  *tbl++ = 0;
935  *tbl++ = 0;
936  *tbl++ = 0;
937  }
938  for (i = 0; i < 4; i++) {
939  col = 224;
940  for (j = 224; j < 239; j += 2) {
941  *tbl++ = col;
942  col += 2;
943  }
944  }
945  for (i = 0; i < 6; i++) {
946  for (col = 224; col < 239; col++) {
947  *tbl++ = col;
948  }
949  *tbl++ = 0;
950  }
951 
952  for (k = 0; k < 16; k++) {
953  for (l = 0; l < 128; l++) {
954  if (l > (k + 1) * 8) {
955  lightradius[k][l] = 15;
956  } else {
957  lightradius[k][l] = l * 15.0 / ((k + 1) * 8.0) + 0.5;
958  }
959  }
960  }
961 
962  for (i = 0; i < 8; i++) {
963  for (j = 0; j < 8; j++) {
964  for (k = 0; k < 16; k++) {
965  for (l = 0; l < 16; l++) {
966  fs = (BYTE)sqrt((8 * l - j) * (8 * l - j) + (8 * k - i) * (8 * k - i));
967  if (fs < 0.0) {
968  fa = -0.5;
969  } else {
970  fa = 0.5;
971  }
972  lightblock[i * 8 + j][k][l] = fs + fa;
973  }
974  }
975  }
976  }
977 }
978 
979 #ifdef _DEBUG
980 void ToggleLighting()
981 {
982  int i;
983 
984  lightflag ^= TRUE;
985 
986  if (lightflag) {
987  memset(dLight, 0, sizeof(dLight));
988  } else {
989  memcpy(dLight, dPreLight, sizeof(dLight));
990  for (i = 0; i < MAX_PLRS; i++) {
991  if (plr[i].plractive && plr[i].plrlevel == currlevel) {
992  DoLighting(plr[i].WorldX, plr[i].WorldY, plr[i]._pLightRad, -1);
993  }
994  }
995  }
996 }
997 #endif
998 
1000 {
1001  if (light4flag) {
1002  lightmax = 3;
1003  } else {
1004  lightmax = 15;
1005  }
1006 }
1007 
1009 {
1010  int i;
1011 
1012  numlights = 0;
1013  dolighting = FALSE;
1014  lightflag = FALSE;
1015 
1016  for (i = 0; i < MAXLIGHTS; i++) {
1017  lightactive[i] = i;
1018  }
1019 }
1020 
1021 int AddLight(int x, int y, int r)
1022 {
1023  int lid;
1024 
1025  if (lightflag) {
1026  return -1;
1027  }
1028 
1029  lid = -1;
1030 
1031  if (numlights < MAXLIGHTS) {
1032  lid = lightactive[numlights++];
1033  LightList[lid]._lx = x;
1034  LightList[lid]._ly = y;
1035  LightList[lid]._lradius = r;
1036  LightList[lid]._xoff = 0;
1037  LightList[lid]._yoff = 0;
1038  LightList[lid]._ldel = 0;
1039  LightList[lid]._lunflag = 0;
1040  dolighting = TRUE;
1041  }
1042 
1043  return lid;
1044 }
1045 
1046 void AddUnLight(int i)
1047 {
1048  if (lightflag || i == -1) {
1049  return;
1050  }
1051 
1052  LightList[i]._ldel = 1;
1053  dolighting = TRUE;
1054 }
1055 
1056 void ChangeLightRadius(int i, int r)
1057 {
1058  if (lightflag || i == -1) {
1059  return;
1060  }
1061 
1062  LightList[i]._lunflag = 1;
1063  LightList[i]._lunx = LightList[i]._lx;
1064  LightList[i]._luny = LightList[i]._ly;
1066  LightList[i]._lradius = r;
1067  dolighting = TRUE;
1068 }
1069 
1070 void ChangeLightXY(int i, int x, int y)
1071 {
1072  if (lightflag || i == -1) {
1073  return;
1074  }
1075 
1076  LightList[i]._lunflag = 1;
1077  LightList[i]._lunx = LightList[i]._lx;
1078  LightList[i]._luny = LightList[i]._ly;
1080  LightList[i]._lx = x;
1081  LightList[i]._ly = y;
1082  dolighting = TRUE;
1083 }
1084 
1085 void ChangeLightOff(int i, int x, int y)
1086 {
1087  if (lightflag || i == -1) {
1088  return;
1089  }
1090 
1091  LightList[i]._lunflag = 1;
1092  LightList[i]._lunx = LightList[i]._lx;
1093  LightList[i]._luny = LightList[i]._ly;
1095  LightList[i]._xoff = x;
1096  LightList[i]._yoff = y;
1097  dolighting = TRUE;
1098 }
1099 
1100 void ChangeLight(int i, int x, int y, int r)
1101 {
1102  if (lightflag || i == -1) {
1103  return;
1104  }
1105 
1106  LightList[i]._lunflag = 1;
1107  LightList[i]._lunx = LightList[i]._lx;
1108  LightList[i]._luny = LightList[i]._ly;
1110  LightList[i]._lx = x;
1111  LightList[i]._ly = y;
1112  LightList[i]._lradius = r;
1113  dolighting = TRUE;
1114 }
1115 
1117 {
1118  int i, j;
1119  BYTE temp;
1120 
1121  if (lightflag) {
1122  return;
1123  }
1124 
1125  if (dolighting) {
1126  for (i = 0; i < numlights; i++) {
1127  j = lightactive[i];
1128  if (LightList[j]._ldel) {
1129  DoUnLight(LightList[j]._lx, LightList[j]._ly, LightList[j]._lradius);
1130  }
1131  if (LightList[j]._lunflag) {
1132  DoUnLight(LightList[j]._lunx, LightList[j]._luny, LightList[j]._lunr);
1133  LightList[j]._lunflag = 0;
1134  }
1135  }
1136  for (i = 0; i < numlights; i++) {
1137  j = lightactive[i];
1138  if (!LightList[j]._ldel) {
1139  DoLighting(LightList[j]._lx, LightList[j]._ly, LightList[j]._lradius, j);
1140  }
1141  }
1142  i = 0;
1143  while (i < numlights) {
1144  if (LightList[lightactive[i]]._ldel) {
1145  numlights--;
1146  temp = lightactive[numlights];
1148  lightactive[i] = temp;
1149  } else {
1150  i++;
1151  }
1152  }
1153  }
1154 
1155  dolighting = FALSE;
1156 }
1157 
1159 {
1160  memcpy(dPreLight, dLight, sizeof(dPreLight));
1161 }
1162 
1164 {
1165  int i;
1166 
1167  numvision = 0;
1168  dovision = FALSE;
1169  visionid = 1;
1170 
1171  for (i = 0; i < TransVal; i++) {
1172  TransList[i] = FALSE;
1173  }
1174 }
1175 
1176 int AddVision(int x, int y, int r, BOOL mine)
1177 {
1178  int vid; // BUGFIX: if numvision >= MAXVISION behavior is undefined
1179 
1180  if (numvision < MAXVISION) {
1181  VisionList[numvision]._lx = x;
1182  VisionList[numvision]._ly = y;
1184  vid = visionid++;
1185  VisionList[numvision]._lid = vid;
1186  VisionList[numvision]._ldel = 0;
1188  VisionList[numvision]._lflags = mine != 0;
1189  numvision++;
1190  dovision = TRUE;
1191  }
1192 
1193  return vid;
1194 }
1195 
1196 void ChangeVisionRadius(int id, int r)
1197 {
1198  int i;
1199 
1200  for (i = 0; i < numvision; i++) {
1201  if (VisionList[i]._lid == id) {
1202  VisionList[i]._lunflag = 1;
1203  VisionList[i]._lunx = VisionList[i]._lx;
1204  VisionList[i]._luny = VisionList[i]._ly;
1206  VisionList[i]._lradius = r;
1207  dovision = TRUE;
1208  }
1209  }
1210 }
1211 
1212 void ChangeVisionXY(int id, int x, int y)
1213 {
1214  int i;
1215 
1216  for (i = 0; i < numvision; i++) {
1217  if (VisionList[i]._lid == id) {
1218  VisionList[i]._lunflag = 1;
1219  VisionList[i]._lunx = VisionList[i]._lx;
1220  VisionList[i]._luny = VisionList[i]._ly;
1222  VisionList[i]._lx = x;
1223  VisionList[i]._ly = y;
1224  dovision = TRUE;
1225  }
1226  }
1227 }
1228 
1230 {
1231  int i;
1232  BOOL delflag;
1233 
1234  if (dovision) {
1235  for (i = 0; i < numvision; i++) {
1236  if (VisionList[i]._ldel) {
1237  DoUnVision(VisionList[i]._lx, VisionList[i]._ly, VisionList[i]._lradius);
1238  }
1239  if (VisionList[i]._lunflag) {
1240  DoUnVision(VisionList[i]._lunx, VisionList[i]._luny, VisionList[i]._lunr);
1241  VisionList[i]._lunflag = 0;
1242  }
1243  }
1244  for (i = 0; i < TransVal; i++) {
1245  TransList[i] = FALSE;
1246  }
1247  for (i = 0; i < numvision; i++) {
1248  if (!VisionList[i]._ldel) {
1249  DoVision(
1250  VisionList[i]._lx,
1251  VisionList[i]._ly,
1252  VisionList[i]._lradius,
1253  VisionList[i]._lflags & 1,
1254  VisionList[i]._lflags & 1);
1255  }
1256  }
1257  do {
1258  delflag = FALSE;
1259  for (i = 0; i < numvision; i++) {
1260  if (VisionList[i]._ldel) {
1261  numvision--;
1262  if (numvision > 0 && i != numvision) {
1264  }
1265  delflag = TRUE;
1266  }
1267  }
1268  } while (delflag);
1269  }
1270 
1271  dovision = FALSE;
1272 }
1273 
1275 {
1276  int i, j, l;
1277  BYTE col;
1278  BYTE *tbl;
1279 
1280  l = light4flag ? 4 : 16;
1281 
1282  if (leveltype != DTYPE_HELL) {
1283  return;
1284  }
1285 
1286  tbl = pLightTbl;
1287 
1288  for (j = 0; j < l; j++) {
1289  tbl++;
1290  col = *tbl;
1291  for (i = 0; i < 30; i++) {
1292  tbl[0] = tbl[1];
1293  tbl++;
1294  }
1295  *tbl = col;
1296  tbl += 225;
1297  }
1298 }
1299 
RotateRadius
void RotateRadius(int *x, int *y, int *dx, int *dy, int *lx, int *ly, int *bx, int *by)
Definition: lighting.cpp:484
AddLight
int AddLight(int x, int y, int r)
Definition: lighting.cpp:1021
MakeLightTable
void MakeLightTable()
Definition: lighting.cpp:798
currlevel
BYTE currlevel
Definition: gendung.cpp:40
numlights
int numlights
Definition: lighting.cpp:13
MAX_PLRS
#define MAX_PLRS
Definition: defs.h:16
pLightTbl
BYTE * pLightTbl
Definition: lighting.cpp:21
DoLighting
void DoLighting(int nXPos, int nYPos, int nRadius, int Lnum)
Definition: lighting.cpp:511
ChangeLightOff
void ChangeLightOff(int i, int x, int y)
Definition: lighting.cpp:1085
numvision
int numvision
Definition: lighting.cpp:16
vCrawlTable
BYTE vCrawlTable[23][30]
vCrawlTable specifies the X- Y-coordinate offsets of lighting visions.
Definition: lighting.cpp:434
LightListStruct::_ly
int _ly
Definition: structs.h:1180
MAXDUNX
#define MAXDUNX
Definition: defs.h:25
ChangeLight
void ChangeLight(int i, int x, int y, int r)
Definition: lighting.cpp:1100
TransList
BOOLEAN TransList[256]
Definition: gendung.cpp:41
LightListStruct::_lunr
int _lunr
Definition: structs.h:1188
LightList
LightListStruct LightList[MAXLIGHTS]
Definition: lighting.cpp:12
MemFreeDbg
#define MemFreeDbg(p)
Definition: defs.h:157
ChangeLightXY
void ChangeLightXY(int i, int x, int y)
Definition: lighting.cpp:1070
dovision
BOOL dovision
Definition: lighting.cpp:15
visionid
int visionid
Definition: lighting.cpp:20
all.h
LightListStruct::_lflags
int _lflags
Definition: structs.h:1191
MAXVISION
#define MAXVISION
Definition: defs.h:39
MAXLIGHTS
#define MAXLIGHTS
Definition: defs.h:29
MAXDUNY
#define MAXDUNY
Definition: defs.h:26
BFLAG_LIT
@ BFLAG_LIT
Definition: enums.h:1883
dLight
char dLight[MAXDUNX][MAXDUNY]
Definition: gendung.cpp:27
LIGHTSIZE
#define LIGHTSIZE
Definition: defs.h:10
ChangeVisionXY
void ChangeVisionXY(int id, int x, int y)
Definition: lighting.cpp:1212
dPiece
int dPiece[MAXDUNX][MAXDUNY]
Definition: gendung.cpp:26
light4flag
BOOL light4flag
Definition: diablo.cpp:34
ProcessLightList
void ProcessLightList()
Definition: lighting.cpp:1116
LightListStruct::_lunflag
int _lunflag
Definition: structs.h:1184
lightblock
BYTE lightblock[64][16][16]
Definition: lighting.cpp:19
TransVal
char TransVal
Definition: gendung.cpp:23
dolighting
BOOL dolighting
Definition: lighting.cpp:18
DEVILUTION_END_NAMESPACE
#define DEVILUTION_END_NAMESPACE
Definition: types.h:10
AddUnLight
void AddUnLight(int i)
Definition: lighting.cpp:1046
LightListStruct::_yoff
int _yoff
Definition: structs.h:1190
LightListStruct::_lradius
int _lradius
Definition: structs.h:1181
RadiusAdj
BYTE RadiusAdj[23]
RadiusAdj maps from vCrawlTable index to lighting vision radius adjustment.
Definition: lighting.cpp:482
LoadFileInMem
BYTE * LoadFileInMem(char *pszName, DWORD *pdwFileLen)
Load a file in to a buffer.
Definition: engine.cpp:801
pCrawlTable
char * pCrawlTable[19]
pCrawlTable maps from circle radius to the X- and Y-coordinate deltas from the center of a circle.
Definition: lighting.cpp:412
lightradius
BYTE lightradius[16][128]
Definition: lighting.cpp:14
LightListStruct::_ldel
int _ldel
Definition: structs.h:1183
AddVision
int AddVision(int x, int y, int r, BOOL mine)
Definition: lighting.cpp:1176
ChangeLightRadius
void ChangeLightRadius(int i, int r)
Definition: lighting.cpp:1056
lightflag
BOOL lightflag
Definition: lighting.cpp:22
ChangeVisionRadius
void ChangeVisionRadius(int id, int r)
Definition: lighting.cpp:1196
VisionList
DEVILUTION_BEGIN_NAMESPACE LightListStruct VisionList[MAXVISION]
Definition: lighting.cpp:10
InitLighting
void InitLighting()
Definition: lighting.cpp:1008
FreeLightTable
void FreeLightTable()
Definition: lighting.cpp:787
LightListStruct::_lunx
int _lunx
Definition: structs.h:1186
DTYPE_HELL
@ DTYPE_HELL
Definition: enums.h:1872
InitLightMax
void InitLightMax()
Definition: lighting.cpp:999
DoVision
void DoVision(int nXPos, int nYPos, int nRadius, BOOL doautomap, BOOL visible)
Definition: lighting.cpp:696
ProcessVisionList
void ProcessVisionList()
Definition: lighting.cpp:1229
dPreLight
char dPreLight[MAXDUNX][MAXDUNY]
Definition: gendung.cpp:22
DiabloAllocPtr
BYTE * DiabloAllocPtr(DWORD dwBytes)
Multithreaded safe malloc.
Definition: engine.cpp:765
dTransVal
char dTransVal[MAXDUNX][MAXDUNY]
Definition: gendung.cpp:37
lightactive
BYTE lightactive[MAXLIGHTS]
Definition: lighting.cpp:11
mem_free_dbg
void mem_free_dbg(void *p)
Multithreaded safe memfree.
Definition: engine.cpp:786
LightListStruct::_lx
int _lx
Definition: structs.h:1179
byte_49463C
BYTE byte_49463C[18][18]
unused
Definition: lighting.cpp:460
LightListStruct::_xoff
int _xoff
Definition: structs.h:1189
DEVILUTION_BEGIN_NAMESPACE
Definition: sha.cpp:10
InitLightTable
void InitLightTable()
Definition: lighting.cpp:792
SavePreLighting
void SavePreLighting()
Definition: lighting.cpp:1158
SetAutomapView
void SetAutomapView(int x, int y)
Definition: automap.cpp:581
LightListStruct
Definition: structs.h:1178
InitVision
void InitVision()
Definition: lighting.cpp:1163
dFlags
char dFlags[MAXDUNX][MAXDUNY]
Definition: gendung.cpp:56
LightListStruct::_lid
int _lid
Definition: structs.h:1182
LightListStruct::_luny
int _luny
Definition: structs.h:1187
BFLAG_EXPLORED
@ BFLAG_EXPLORED
Definition: enums.h:1884
leveltype
BYTE leveltype
Definition: gendung.cpp:39
CrawlTable
char CrawlTable[2749]
CrawlTable specifies X- and Y-coordinate deltas from a missile target coordinate.
Definition: lighting.cpp:47
plr
PlayerStruct plr[MAX_PLRS]
Definition: player.cpp:10
BFLAG_VISIBLE
@ BFLAG_VISIBLE
Definition: enums.h:1878
lighting_color_cycling
void lighting_color_cycling()
Definition: lighting.cpp:1274
DoUnLight
void DoUnLight(int nXPos, int nYPos, int nRadius)
Definition: lighting.cpp:634
lightmax
char lightmax
Definition: lighting.cpp:17
nBlockTable
BOOLEAN nBlockTable[2049]
List of light blocking dPieces.
Definition: gendung.cpp:54
DoUnVision
void DoUnVision(int nXPos, int nYPos, int nRadius)
Definition: lighting.cpp:666