1 // Emacs style mode select -*- C++ -*-
2 //-----------------------------------------------------------------------------
6 // Copyright (C) 1993-1996 by id Software, Inc.
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
20 // Handle Sector base lighting effects.
23 //-----------------------------------------------------------------------------
26 rcsid[] = "$Id: p_lights.c,v 1.5 1997/02/03 22:45:11 b1 Exp $";
46 void T_FireFlicker (void *_flick, void*)
48 fireflicker_t *flick = (fireflicker_t*)_flick;
54 amount = (P_Random()&3)*16;
56 if (flick->sector->lightlevel - amount < flick->minlight)
57 flick->sector->lightlevel = flick->minlight;
59 flick->sector->lightlevel = flick->maxlight - amount;
69 void P_SpawnFireFlicker (sector_t* sector)
73 // Note that we are resetting sector attributes.
74 // Nothing special about it during gameplay.
77 flick = Z_Malloc ( sizeof(*flick), PU_LEVSPEC, 0);
79 P_AddThinker (&flick->thinker);
81 flick->thinker.function = T_FireFlicker;
82 flick->sector = sector;
83 flick->maxlight = sector->lightlevel;
84 flick->minlight = P_FindMinSurroundingLight(sector,sector->lightlevel)+16;
91 // BROKEN LIGHT FLASHING
97 // Do flashing lights.
99 void T_LightFlash (void* _flash, void*)
101 lightflash_t *flash = (lightflash_t*)_flash;
105 if (flash->sector->lightlevel == flash->maxlight)
107 flash-> sector->lightlevel = flash->minlight;
108 flash->count = (P_Random()&flash->mintime)+1;
112 flash-> sector->lightlevel = flash->maxlight;
113 flash->count = (P_Random()&flash->maxtime)+1;
123 // After the map has been loaded, scan each sector
124 // for specials that spawn thinkers
126 void P_SpawnLightFlash (sector_t* sector)
130 // nothing special about it during gameplay
133 flash = Z_Malloc ( sizeof(*flash), PU_LEVSPEC, 0);
135 P_AddThinker (&flash->thinker);
137 flash->thinker.function = T_LightFlash;
138 flash->sector = sector;
139 flash->maxlight = sector->lightlevel;
141 flash->minlight = P_FindMinSurroundingLight(sector,sector->lightlevel);
144 flash->count = (P_Random()&flash->maxtime)+1;
150 // STROBE LIGHT FLASHING
157 void T_StrobeFlash (void *_flash, void*)
159 strobe_t *flash = (strobe_t*)_flash;
163 if (flash->sector->lightlevel == flash->minlight)
165 flash-> sector->lightlevel = flash->maxlight;
166 flash->count = flash->brighttime;
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
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 = T_StrobeFlash;
199 flash->maxlight = sector->lightlevel;
200 flash->minlight = P_FindMinSurroundingLight(sector, sector->lightlevel);
202 if (flash->minlight == flash->maxlight)
205 // nothing special about it during gameplay
209 flash->count = (P_Random()&7)+1;
216 // Start strobing lights (usually from a trigger)
218 void EV_StartLightStrobing(line_t* line)
224 while ((secnum = P_FindSectorFromLineTag(line,secnum)) >= 0)
226 sec = §ors[secnum];
227 if (sec->specialdata)
230 P_SpawnStrobeFlash (sec,SLOWDARK, 0);
237 // TURN LINE'S TAG LIGHTS OFF
239 void EV_TurnTagLightsOff(line_t* line)
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);
261 if (tsec->lightlevel < min)
262 min = tsec->lightlevel;
264 sector->lightlevel = min;
271 // TURN LINE'S TAG LIGHTS ON
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
295 for (j = 0;j < sector->linecount; j++)
297 templine = sector->lines[j];
298 temp = getNextSector(templine,sector);
303 if (temp->lightlevel > bright)
304 bright = temp->lightlevel;
307 sector-> lightlevel = bright;
314 // Spawn glowing light
317 void T_Glow(void* _g, void*)
319 glow_t *g = (glow_t*)_g;
324 g->sector->lightlevel -= GLOWSPEED;
325 if (g->sector->lightlevel <= g->minlight)
327 g->sector->lightlevel += GLOWSPEED;
334 g->sector->lightlevel += GLOWSPEED;
335 if (g->sector->lightlevel >= g->maxlight)
337 g->sector->lightlevel -= GLOWSPEED;
345 void P_SpawnGlowingLight(sector_t* sector)
349 g = Z_Malloc( sizeof(*g), PU_LEVSPEC, 0);
351 P_AddThinker(&g->thinker);
354 g->minlight = P_FindMinSurroundingLight(sector,sector->lightlevel);
355 g->maxlight = sector->lightlevel;
356 g->thinker.function = T_Glow;