1 //-------------------------------------------------------------------------
2 /*
3 Copyright (C) 1996, 2003 - 3D Realms Entertainment
4 Copyright (C) 2017-2019 Nuke.YKT
5
6 This file is part of Duke Nukem 3D version 1.5 - Atomic Edition
7
8 Duke Nukem 3D is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
17 See the GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
23 Original Source: 1996 - Todd Replogle
24 Prepared for public release: 03/21/2003 - Charlie Wiederhold, 3D Realms
25 */
26 //-------------------------------------------------------------------------
27 #include "duke3d.h"
28
29 short torchcnt;
30 short jaildoorcnt;
31 short minecartcnt;
32
33 extern char _wp1,_wp2,_wp3,_wp4,_wp5,_wp6;
34
35 short torchsector[64];
36 short torchsectorshade[64];
37 short torchtype[64];
38
39 short lightnincnt;
40
41 short jaildoorsound[32];
42 long jaildoordrag[32];
43 long jaildoorspeed[32];
44 short jaildoorsecthtag[32];
45 long jaildoordist[32];
46 short jaildoordir[32];
47 short jaildooropen[32];
48 short jaildoorsect[32];
49
50 short minecartdir[16];
51 long minecartspeed[16];
52 short minecartchildsect[16];
53 short minecartsound[16];
54 long minecartdist[16];
55 long minecartdrag[16];
56 short minecartopen[16];
57 short minecartsect[16];
58
59 short lightninsector[64];
60 short lightninsectorshade[64];
61
dotorch(void)62 void dotorch(void)
63 {
64 int ds;
65 short j, i;
66 short startwall, endwall;
67 char shade;
68 ds = TRAND&8;
69 for (i = 0; i < torchcnt; i++)
70 {
71 shade = torchsectorshade[i] - ds;
72 switch (torchtype[i])
73 {
74 case 0:
75 sector[torchsector[i]].floorshade = shade;
76 sector[torchsector[i]].ceilingshade = shade;
77 break;
78 case 1:
79 sector[torchsector[i]].ceilingshade = shade;
80 break;
81 case 2:
82 sector[torchsector[i]].floorshade = shade;
83 break;
84 case 4:
85 sector[torchsector[i]].ceilingshade = shade;
86 break;
87 case 5:
88 sector[torchsector[i]].floorshade = shade;
89 break;
90 }
91 startwall = sector[torchsector[i]].wallptr;
92 endwall = startwall + sector[torchsector[i]].wallnum;
93 for (j = startwall; j < endwall; j++)
94 {
95 if (wall[j].lotag != 1)
96 {
97 switch (torchtype[i])
98 {
99 case 0:
100 wall[j].shade = shade;
101 break;
102 case 1:
103 wall[j].shade = shade;
104 break;
105 case 2:
106 wall[j].shade = shade;
107 break;
108 case 3:
109 wall[j].shade = shade;
110 break;
111 }
112 }
113 }
114 }
115 }
116
dojaildoor(void)117 void dojaildoor(void)
118 {
119 short i, j;
120 short startwall, endwall;
121 long x, y;
122 long speed;
123 for (i = 0; i < jaildoorcnt; i++)
124 {
125 if (numplayers > 2)
126 speed = jaildoorspeed[i];
127 else
128 speed = jaildoorspeed[i];
129 if (speed < 2)
130 speed = 2;
131 if (jaildooropen[i] == 1)
132 {
133 jaildoordrag[i] -= speed;
134 if (jaildoordrag[i] <= 0)
135 {
136 jaildoordrag[i] = 0;
137 jaildooropen[i] = 2;
138 switch (jaildoordir[i])
139 {
140 case 10:
141 jaildoordir[i] = 30;
142 break;
143 case 20:
144 jaildoordir[i] = 40;
145 break;
146 case 30:
147 jaildoordir[i] = 10;
148 break;
149 case 40:
150 jaildoordir[i] = 20;
151 break;
152 }
153 }
154 else
155 {
156 startwall = sector[jaildoorsect[i]].wallptr;
157 endwall = startwall + sector[jaildoorsect[i]].wallnum;
158 for (j = startwall; j < endwall; j++)
159 {
160 switch (jaildoordir[i])
161 {
162 case 10:
163 x = wall[j].x;
164 y = wall[j].y + speed;
165 break;
166 case 20:
167 x = wall[j].x - speed;
168 y = wall[j].y;
169 break;
170 case 30:
171 x = wall[j].x;
172 y = wall[j].y - speed;
173 break;
174 case 40:
175 x = wall[j].x + speed;
176 y = wall[j].y;
177 break;
178 }
179 dragpoint(j,x,y);
180 }
181 }
182 }
183 if (jaildooropen[i] == 3)
184 {
185 jaildoordrag[i] -= speed;
186 if (jaildoordrag[i] <= 0)
187 {
188 jaildoordrag[i] = 0;
189 jaildooropen[i] = 0;
190 switch (jaildoordir[i])
191 {
192 case 10:
193 jaildoordir[i] = 30;
194 break;
195 case 20:
196 jaildoordir[i] = 40;
197 break;
198 case 30:
199 jaildoordir[i] = 10;
200 break;
201 case 40:
202 jaildoordir[i] = 20;
203 break;
204 }
205 }
206 else
207 {
208 startwall = sector[jaildoorsect[i]].wallptr;
209 endwall = startwall + sector[jaildoorsect[i]].wallnum;
210 for (j = startwall; j < endwall; j++)
211 {
212 switch (jaildoordir[i])
213 {
214 case 10:
215 x = wall[j].x;
216 y = wall[j].y + speed;
217 break;
218 case 20:
219 x = wall[j].x - speed;
220 y = wall[j].y;
221 break;
222 case 30:
223 x = wall[j].x;
224 y = wall[j].y - speed;
225 break;
226 case 40:
227 x = wall[j].x + speed;
228 y = wall[j].y;
229 break;
230 }
231 dragpoint(j,x,y);
232 }
233 }
234 }
235 }
236 }
237
moveminecart(void)238 void moveminecart(void)
239 {
240 short i;
241 short j;
242 short csect;
243 short startwall;
244 short endwall;
245 long speed;
246 long y;
247 long x;
248 short nextj;
249 long cx;
250 long cy;
251 long unk;
252 long max_x;
253 long min_y;
254 long max_y;
255 long min_x;
256 for (i = 0; i < minecartcnt; i++)
257 {
258 speed = minecartspeed[i];
259 if (speed < 2)
260 speed = 2;
261
262 if (minecartopen[i] == 1)
263 {
264 minecartdrag[i] -= speed;
265 if (minecartdrag[i] <= 0)
266 {
267 minecartdrag[i] = minecartdist[i];
268 minecartopen[i] = 2;
269 switch (minecartdir[i])
270 {
271 case 10:
272 minecartdir[i] = 30;
273 break;
274 case 20:
275 minecartdir[i] = 40;
276 break;
277 case 30:
278 minecartdir[i] = 10;
279 break;
280 case 40:
281 minecartdir[i] = 20;
282 break;
283 }
284 }
285 else
286 {
287 startwall = sector[minecartsect[i]].wallptr;
288 endwall = startwall + sector[minecartsect[i]].wallnum;
289 for (j = startwall; j < endwall; j++)
290 {
291 switch (minecartdir[i])
292 {
293 case 10:
294 x = wall[j].x;
295 y = wall[j].y + speed;
296 break;
297 case 20:
298 x = wall[j].x - speed;
299 y = wall[j].y;
300 break;
301 case 30:
302 x = wall[j].x;
303 y = wall[j].y - speed;
304 break;
305 case 40:
306 x = wall[j].x + speed;
307 y = wall[j].y;
308 break;
309 }
310 dragpoint(j,x,y);
311 }
312 }
313 }
314 if (minecartopen[i] == 2)
315 {
316 minecartdrag[i] -= speed;
317 if (minecartdrag[i] <= 0)
318 {
319 minecartdrag[i] = minecartdist[i];
320 minecartopen[i] = 1;
321 switch (minecartdir[i])
322 {
323 case 10:
324 minecartdir[i] = 30;
325 break;
326 case 20:
327 minecartdir[i] = 40;
328 break;
329 case 30:
330 minecartdir[i] = 10;
331 break;
332 case 40:
333 minecartdir[i] = 20;
334 break;
335 }
336 }
337 else
338 {
339 startwall = sector[minecartsect[i]].wallptr;
340 endwall = startwall + sector[minecartsect[i]].wallnum;
341 for (j = startwall; j < endwall; j++)
342 {
343 switch (minecartdir[i])
344 {
345 case 10:
346 x = wall[j].x;
347 y = wall[j].y + speed;
348 break;
349 case 20:
350 x = wall[j].x - speed;
351 y = wall[j].y;
352 break;
353 case 30:
354 x = wall[j].x;
355 y = wall[j].y - speed;
356 break;
357 case 40:
358 x = wall[j].x + speed;
359 y = wall[j].y;
360 break;
361 }
362 dragpoint(j,x,y);
363 }
364 }
365 }
366 csect = minecartchildsect[i];
367 startwall = sector[csect].wallptr;
368 endwall = startwall + sector[csect].wallnum;
369 max_x = max_y = -0x20000;
370 min_x = min_y = 0x20000;
371 for (j = startwall; j < endwall; j++)
372 {
373 x = wall[j].x;
374 y = wall[j].y;
375 if (x > max_x)
376 max_x = x;
377 if (y > max_y)
378 max_y = y;
379 if (x < min_x)
380 min_x = x;
381 if (y < min_y)
382 min_y = y;
383 }
384 cx = (max_x + min_x) >> 1;
385 cy = (max_y + min_y) >> 1;
386 j = headspritesect[csect];
387 while (j != -1)
388 {
389 nextj = nextspritesect[j];
390 if (badguy(&sprite[j]))
391 setsprite(j,cx,cy,sprite[j].z);
392 j = nextj;
393 }
394 }
395 }
396