# move iconv's headers and libs out of the main developer directory, so that it isn...
[AROS-Contrib.git] / Games / Doom / p_lights.c
blob306e977d35f18a512d0a9bc8e55fa2ad6aa776a4
1 // Emacs style mode select -*- C++ -*-
2 //-----------------------------------------------------------------------------
3 //
4 // $Id$
5 //
6 // Copyright (C) 1993-1996 by id Software, Inc.
7 //
8 // This source is available for distribution and/or modification
9 // only under the terms of the DOOM Source Code License as
10 // published by id Software. All rights reserved.
12 // The source is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
15 // for more details.
17 // $Log$
18 // Revision 1.1 2000/02/29 18:21:04 stegerg
19 // Doom port based on ADoomPPC. Read README.AROS!
22 // DESCRIPTION:
23 // Handle Sector base lighting effects.
24 // Muzzle flash?
26 //-----------------------------------------------------------------------------
28 static const char
29 rcsid[] = "$Id$";
32 #include "z_zone.h"
33 #include "m_random.h"
35 #include "doomdef.h"
36 #include "p_local.h"
39 // State.
40 #include "r_state.h"
43 // FIRELIGHT FLICKER
47 // T_FireFlicker
49 void T_FireFlicker (fireflicker_t* flick)
51 int amount;
53 if (--flick->count)
54 return;
56 amount = (P_Random()&3)*16;
58 if (flick->sector->lightlevel - amount < flick->minlight)
59 flick->sector->lightlevel = flick->minlight;
60 else
61 flick->sector->lightlevel = flick->maxlight - amount;
63 flick->count = 4;
69 // P_SpawnFireFlicker
71 void P_SpawnFireFlicker (sector_t* sector)
73 fireflicker_t* flick;
75 // Note that we are resetting sector attributes.
76 // Nothing special about it during gameplay.
77 sector->special = 0;
79 flick = Z_Malloc ( sizeof(*flick), PU_LEVSPEC, 0);
81 P_AddThinker (&flick->thinker);
83 flick->thinker.function.acp1 = (actionf_p1) T_FireFlicker;
84 flick->sector = sector;
85 flick->maxlight = sector->lightlevel;
86 flick->minlight = P_FindMinSurroundingLight(sector,sector->lightlevel)+16;
87 flick->count = 4;
93 // BROKEN LIGHT FLASHING
98 // T_LightFlash
99 // Do flashing lights.
101 void T_LightFlash (lightflash_t* flash)
103 if (--flash->count)
104 return;
106 if (flash->sector->lightlevel == flash->maxlight)
108 flash-> sector->lightlevel = flash->minlight;
109 flash->count = (P_Random()&flash->mintime)+1;
111 else
113 flash-> sector->lightlevel = flash->maxlight;
114 flash->count = (P_Random()&flash->maxtime)+1;
123 // P_SpawnLightFlash
124 // After the map has been loaded, scan each sector
125 // for specials that spawn thinkers
127 void P_SpawnLightFlash (sector_t* sector)
129 lightflash_t* flash;
131 // nothing special about it during gameplay
132 sector->special = 0;
134 flash = Z_Malloc ( sizeof(*flash), PU_LEVSPEC, 0);
136 P_AddThinker (&flash->thinker);
138 flash->thinker.function.acp1 = (actionf_p1) T_LightFlash;
139 flash->sector = sector;
140 flash->maxlight = sector->lightlevel;
142 flash->minlight = P_FindMinSurroundingLight(sector,sector->lightlevel);
143 flash->maxtime = 64;
144 flash->mintime = 7;
145 flash->count = (P_Random()&flash->maxtime)+1;
151 // STROBE LIGHT FLASHING
156 // T_StrobeFlash
158 void T_StrobeFlash (strobe_t* flash)
160 if (--flash->count)
161 return;
163 if (flash->sector->lightlevel == flash->minlight)
165 flash-> sector->lightlevel = flash->maxlight;
166 flash->count = flash->brighttime;
168 else
170 flash-> sector->lightlevel = flash->minlight;
171 flash->count =flash->darktime;
179 // P_SpawnStrobeFlash
180 // After the map has been loaded, scan each sector
181 // for specials that spawn thinkers
183 void
184 P_SpawnStrobeFlash
185 ( sector_t* sector,
186 int fastOrSlow,
187 int inSync )
189 strobe_t* flash;
191 flash = Z_Malloc ( sizeof(*flash), PU_LEVSPEC, 0);
193 P_AddThinker (&flash->thinker);
195 flash->sector = sector;
196 flash->darktime = fastOrSlow;
197 flash->brighttime = STROBEBRIGHT;
198 flash->thinker.function.acp1 = (actionf_p1) T_StrobeFlash;
199 flash->maxlight = sector->lightlevel;
200 flash->minlight = P_FindMinSurroundingLight(sector, sector->lightlevel);
202 if (flash->minlight == flash->maxlight)
203 flash->minlight = 0;
205 // nothing special about it during gameplay
206 sector->special = 0;
208 if (!inSync)
209 flash->count = (P_Random()&7)+1;
210 else
211 flash->count = 1;
216 // Start strobing lights (usually from a trigger)
218 void EV_StartLightStrobing(line_t* line)
220 int secnum;
221 sector_t* sec;
223 secnum = -1;
224 while ((secnum = P_FindSectorFromLineTag(line,secnum)) >= 0)
226 sec = &sectors[secnum];
227 if (sec->specialdata)
228 continue;
230 P_SpawnStrobeFlash (sec,SLOWDARK, 0);
237 // TURN LINE'S TAG LIGHTS OFF
239 void EV_TurnTagLightsOff(line_t* line)
241 int i;
242 int j;
243 int min;
244 sector_t* sector;
245 sector_t* tsec;
246 line_t* templine;
248 sector = sectors;
250 for (j = 0;j < numsectors; j++, sector++)
252 if (sector->tag == line->tag)
254 min = sector->lightlevel;
255 for (i = 0;i < sector->linecount; i++)
257 templine = sector->lines[i];
258 tsec = getNextSector(templine,sector);
259 if (!tsec)
260 continue;
261 if (tsec->lightlevel < min)
262 min = tsec->lightlevel;
264 sector->lightlevel = min;
271 // TURN LINE'S TAG LIGHTS ON
273 void
274 EV_LightTurnOn
275 ( line_t* line,
276 int bright )
278 int i;
279 int j;
280 sector_t* sector;
281 sector_t* temp;
282 line_t* templine;
284 sector = sectors;
286 for (i=0;i<numsectors;i++, sector++)
288 if (sector->tag == line->tag)
290 // bright = 0 means to search
291 // for highest light level
292 // surrounding sector
293 if (!bright)
295 for (j = 0;j < sector->linecount; j++)
297 templine = sector->lines[j];
298 temp = getNextSector(templine,sector);
300 if (!temp)
301 continue;
303 if (temp->lightlevel > bright)
304 bright = temp->lightlevel;
307 sector-> lightlevel = bright;
314 // Spawn glowing light
317 void T_Glow(glow_t* g)
319 switch(g->direction)
321 case -1:
322 // DOWN
323 g->sector->lightlevel -= GLOWSPEED;
324 if (g->sector->lightlevel <= g->minlight)
326 g->sector->lightlevel += GLOWSPEED;
327 g->direction = 1;
329 break;
331 case 1:
332 // UP
333 g->sector->lightlevel += GLOWSPEED;
334 if (g->sector->lightlevel >= g->maxlight)
336 g->sector->lightlevel -= GLOWSPEED;
337 g->direction = -1;
339 break;
344 void P_SpawnGlowingLight(sector_t* sector)
346 glow_t* g;
348 g = Z_Malloc( sizeof(*g), PU_LEVSPEC, 0);
350 P_AddThinker(&g->thinker);
352 g->sector = sector;
353 g->minlight = P_FindMinSurroundingLight(sector,sector->lightlevel);
354 g->maxlight = sector->lightlevel;
355 g->thinker.function.acp1 = (actionf_p1) T_Glow;
356 g->direction = -1;
358 sector->special = 0;