Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
298 serge 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.
11
//
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.
16
//
17
// $Log:$
18
//
19
// DESCRIPTION:
20
//	Handle Sector base lighting effects.
21
//	Muzzle flash?
22
//
23
//-----------------------------------------------------------------------------
24
 
25
static const char
26
rcsid[] = "$Id: p_lights.c,v 1.5 1997/02/03 22:45:11 b1 Exp $";
27
 
28
 
29
#include "z_zone.h"
30
#include "m_random.h"
31
 
32
#include "doomdef.h"
33
#include "p_local.h"
34
 
35
 
36
// State.
37
#include "r_state.h"
38
 
39
//
40
// FIRELIGHT FLICKER
41
//
42
 
43
//
44
// T_FireFlicker
45
//
46
void T_FireFlicker (fireflicker_t* flick)
47
{
48
    int	amount;
49
 
50
    if (--flick->count)
51
	return;
52
 
53
    amount = (P_Random()&3)*16;
54
 
55
    if (flick->sector->lightlevel - amount < flick->minlight)
56
	flick->sector->lightlevel = flick->minlight;
57
    else
58
	flick->sector->lightlevel = flick->maxlight - amount;
59
 
60
    flick->count = 4;
61
}
62
 
63
 
64
 
65
//
66
// P_SpawnFireFlicker
67
//
68
void P_SpawnFireFlicker (sector_t*	sector)
69
{
70
    fireflicker_t*	flick;
71
 
72
    // Note that we are resetting sector attributes.
73
    // Nothing special about it during gameplay.
74
    sector->special = 0;
75
 
76
    flick = Z_Malloc ( sizeof(*flick), PU_LEVSPEC, 0);
77
 
78
    P_AddThinker (&flick->thinker);
79
 
80
    flick->thinker.function.acp1 = (actionf_p1) T_FireFlicker;
81
    flick->sector = sector;
82
    flick->maxlight = sector->lightlevel;
83
    flick->minlight = P_FindMinSurroundingLight(sector,sector->lightlevel)+16;
84
    flick->count = 4;
85
}
86
 
87
 
88
 
89
//
90
// BROKEN LIGHT FLASHING
91
//
92
 
93
 
94
//
95
// T_LightFlash
96
// Do flashing lights.
97
//
98
void T_LightFlash (lightflash_t* flash)
99
{
100
    if (--flash->count)
101
	return;
102
 
103
    if (flash->sector->lightlevel == flash->maxlight)
104
    {
105
	flash-> sector->lightlevel = flash->minlight;
106
	flash->count = (P_Random()&flash->mintime)+1;
107
    }
108
    else
109
    {
110
	flash-> sector->lightlevel = flash->maxlight;
111
	flash->count = (P_Random()&flash->maxtime)+1;
112
    }
113
 
114
}
115
 
116
 
117
 
118
 
119
//
120
// P_SpawnLightFlash
121
// After the map has been loaded, scan each sector
122
// for specials that spawn thinkers
123
//
124
void P_SpawnLightFlash (sector_t*	sector)
125
{
126
    lightflash_t*	flash;
127
 
128
    // nothing special about it during gameplay
129
    sector->special = 0;
130
 
131
    flash = Z_Malloc ( sizeof(*flash), PU_LEVSPEC, 0);
132
 
133
    P_AddThinker (&flash->thinker);
134
 
135
    flash->thinker.function.acp1 = (actionf_p1) T_LightFlash;
136
    flash->sector = sector;
137
    flash->maxlight = sector->lightlevel;
138
 
139
    flash->minlight = P_FindMinSurroundingLight(sector,sector->lightlevel);
140
    flash->maxtime = 64;
141
    flash->mintime = 7;
142
    flash->count = (P_Random()&flash->maxtime)+1;
143
}
144
 
145
 
146
 
147
//
148
// STROBE LIGHT FLASHING
149
//
150
 
151
 
152
//
153
// T_StrobeFlash
154
//
155
void T_StrobeFlash (strobe_t*		flash)
156
{
157
    if (--flash->count)
158
	return;
159
 
160
    if (flash->sector->lightlevel == flash->minlight)
161
    {
162
	flash-> sector->lightlevel = flash->maxlight;
163
	flash->count = flash->brighttime;
164
    }
165
    else
166
    {
167
	flash-> sector->lightlevel = flash->minlight;
168
	flash->count =flash->darktime;
169
    }
170
 
171
}
172
 
173
 
174
 
175
//
176
// P_SpawnStrobeFlash
177
// After the map has been loaded, scan each sector
178
// for specials that spawn thinkers
179
//
180
void
181
P_SpawnStrobeFlash
182
( sector_t*	sector,
183
  int		fastOrSlow,
184
  int		inSync )
185
{
186
    strobe_t*	flash;
187
 
188
    flash = Z_Malloc ( sizeof(*flash), PU_LEVSPEC, 0);
189
 
190
    P_AddThinker (&flash->thinker);
191
 
192
    flash->sector = sector;
193
    flash->darktime = fastOrSlow;
194
    flash->brighttime = STROBEBRIGHT;
195
    flash->thinker.function.acp1 = (actionf_p1) T_StrobeFlash;
196
    flash->maxlight = sector->lightlevel;
197
    flash->minlight = P_FindMinSurroundingLight(sector, sector->lightlevel);
198
 
199
    if (flash->minlight == flash->maxlight)
200
	flash->minlight = 0;
201
 
202
    // nothing special about it during gameplay
203
    sector->special = 0;
204
 
205
    if (!inSync)
206
	flash->count = (P_Random()&7)+1;
207
    else
208
	flash->count = 1;
209
}
210
 
211
 
212
//
213
// Start strobing lights (usually from a trigger)
214
//
215
void EV_StartLightStrobing(line_t*	line)
216
{
217
    int		secnum;
218
    sector_t*	sec;
219
 
220
    secnum = -1;
221
    while ((secnum = P_FindSectorFromLineTag(line,secnum)) >= 0)
222
    {
223
	sec = §ors[secnum];
224
	if (sec->specialdata)
225
	    continue;
226
 
227
	P_SpawnStrobeFlash (sec,SLOWDARK, 0);
228
    }
229
}
230
 
231
 
232
 
233
//
234
// TURN LINE'S TAG LIGHTS OFF
235
//
236
void EV_TurnTagLightsOff(line_t* line)
237
{
238
    int			i;
239
    int			j;
240
    int			min;
241
    sector_t*		sector;
242
    sector_t*		tsec;
243
    line_t*		templine;
244
 
245
    sector = sectors;
246
 
247
    for (j = 0;j < numsectors; j++, sector++)
248
    {
249
	if (sector->tag == line->tag)
250
	{
251
	    min = sector->lightlevel;
252
	    for (i = 0;i < sector->linecount; i++)
253
	    {
254
		templine = sector->lines[i];
255
		tsec = getNextSector(templine,sector);
256
		if (!tsec)
257
		    continue;
258
		if (tsec->lightlevel < min)
259
		    min = tsec->lightlevel;
260
	    }
261
	    sector->lightlevel = min;
262
	}
263
    }
264
}
265
 
266
 
267
//
268
// TURN LINE'S TAG LIGHTS ON
269
//
270
void
271
EV_LightTurnOn
272
( line_t*	line,
273
  int		bright )
274
{
275
    int		i;
276
    int		j;
277
    sector_t*	sector;
278
    sector_t*	temp;
279
    line_t*	templine;
280
 
281
    sector = sectors;
282
 
283
    for (i=0;i
284
    {
285
	if (sector->tag == line->tag)
286
	{
287
	    // bright = 0 means to search
288
	    // for highest light level
289
	    // surrounding sector
290
	    if (!bright)
291
	    {
292
		for (j = 0;j < sector->linecount; j++)
293
		{
294
		    templine = sector->lines[j];
295
		    temp = getNextSector(templine,sector);
296
 
297
		    if (!temp)
298
			continue;
299
 
300
		    if (temp->lightlevel > bright)
301
			bright = temp->lightlevel;
302
		}
303
	    }
304
	    sector-> lightlevel = bright;
305
	}
306
    }
307
}
308
 
309
 
310
//
311
// Spawn glowing light
312
//
313
 
314
void T_Glow(glow_t*	g)
315
{
316
    switch(g->direction)
317
    {
318
      case -1:
319
	// DOWN
320
	g->sector->lightlevel -= GLOWSPEED;
321
	if (g->sector->lightlevel <= g->minlight)
322
	{
323
	    g->sector->lightlevel += GLOWSPEED;
324
	    g->direction = 1;
325
	}
326
	break;
327
 
328
      case 1:
329
	// UP
330
	g->sector->lightlevel += GLOWSPEED;
331
	if (g->sector->lightlevel >= g->maxlight)
332
	{
333
	    g->sector->lightlevel -= GLOWSPEED;
334
	    g->direction = -1;
335
	}
336
	break;
337
    }
338
}
339
 
340
 
341
void P_SpawnGlowingLight(sector_t*	sector)
342
{
343
    glow_t*	g;
344
 
345
    g = Z_Malloc( sizeof(*g), PU_LEVSPEC, 0);
346
 
347
    P_AddThinker(&g->thinker);
348
 
349
    g->sector = sector;
350
    g->minlight = P_FindMinSurroundingLight(sector,sector->lightlevel);
351
    g->maxlight = sector->lightlevel;
352
    g->thinker.function.acp1 = (actionf_p1) T_Glow;
353
    g->direction = -1;
354
 
355
    sector->special = 0;
356
}
357