2 //**************************************************************************
4 //** p_lights.c : Heretic 2 : Raven Software, Corp.
11 //**************************************************************************
16 //============================================================================
20 //============================================================================
22 void T_Light(light_t *light)
32 light->sector->lightlevel = ((light->sector->lightlevel<<FRACBITS)
33 +light->value2)>>FRACBITS;
36 if(light->sector->lightlevel >= light->value1)
38 light->sector->lightlevel = light->value1;
39 P_RemoveThinker(&light->thinker);
42 else if(light->sector->lightlevel <= light->value1)
44 light->sector->lightlevel = light->value1;
45 P_RemoveThinker(&light->thinker);
49 light->sector->lightlevel = ((light->sector->lightlevel<<FRACBITS)
50 +light->tics1)>>FRACBITS;
53 if(light->sector->lightlevel >= light->value1)
55 light->sector->lightlevel = light->value1;
56 light->tics1 = -light->tics1;
57 light->tics2 = -1; // reverse direction
60 else if(light->sector->lightlevel <= light->value2)
62 light->sector->lightlevel = light->value2;
63 light->tics1 = -light->tics1;
64 light->tics2 = 1; // reverse direction
68 if(light->sector->lightlevel == light->value1)
70 light->sector->lightlevel = light->value2;
71 light->count = (P_Random()&7)+1;
75 light->sector->lightlevel = light->value1;
76 light->count = (P_Random()&31)+1;
80 if(light->sector->lightlevel == light->value1)
82 light->sector->lightlevel = light->value2;
83 light->count = light->tics2;
87 light->sector->lightlevel = light->value1;
88 light->count = light->tics1;
96 //============================================================================
100 //============================================================================
102 boolean EV_SpawnLight(line_t *line, byte *arg, lighttype_t type)
107 int arg1, arg2, arg3, arg4;
119 while((secNum = P_FindSectorFromTag(arg[0], secNum)) >= 0)
122 sec = §ors[secNum];
124 light = (light_t *)Z_Malloc(sizeof(light_t), PU_LEVSPEC, 0);
131 case LITE_RAISEBYVALUE:
132 sec->lightlevel += arg1;
133 if(sec->lightlevel > 255)
135 sec->lightlevel = 255;
138 case LITE_LOWERBYVALUE:
139 sec->lightlevel -= arg1;
140 if(sec->lightlevel < 0)
145 case LITE_CHANGETOVALUE:
146 sec->lightlevel = arg1;
147 if(sec->lightlevel < 0)
151 else if(sec->lightlevel > 255)
153 sec->lightlevel = 255;
158 light->value1 = arg1; // destination lightlevel
159 light->value2 = FixedDiv((arg1-sec->lightlevel)<<FRACBITS,
160 arg2<<FRACBITS); // delta lightlevel
161 if(sec->lightlevel <= arg1)
163 light->tics2 = 1; // get brighter
172 light->value1 = arg1; // upper lightlevel
173 light->value2 = arg2; // lower lightlevel
174 light->tics1 = FixedDiv((arg1-sec->lightlevel)<<FRACBITS,
175 arg3<<FRACBITS); // lightlevel delta
176 if(sec->lightlevel <= arg1)
178 light->tics2 = 1; // get brighter
187 light->value1 = arg1; // upper lightlevel
188 light->value2 = arg2; // lower lightlevel
189 sec->lightlevel = light->value1;
190 light->count = (P_Random()&64)+1;
194 light->value1 = arg1; // upper lightlevel
195 light->value2 = arg2; // lower lightlevel
196 light->tics1 = arg3; // upper tics
197 light->tics2 = arg4; // lower tics
199 sec->lightlevel = light->value1;
207 P_AddThinker(&light->thinker);
208 light->thinker.function = T_Light;
218 //============================================================================
222 //============================================================================
226 128, 112, 96, 80, 64, 48, 32, 32,
227 16, 16, 16, 0, 0, 0, 0, 0,
228 0, 0, 0, 0, 0, 0, 0, 0,
229 0, 0, 0, 0, 0, 0, 0, 0,
230 0, 0, 0, 0, 0, 0, 0, 0,
231 0, 0, 0, 0, 0, 0, 0, 0,
232 0, 0, 0, 0, 0, 16, 16, 16,
233 32, 32, 48, 64, 80, 96, 112, 128
236 void T_Phase(phase_t *phase)
238 phase->index = (phase->index+1)&63;
239 phase->sector->lightlevel = phase->base+PhaseTable[phase->index];
242 //==========================================================================
244 // P_SpawnPhasedLight
246 //==========================================================================
248 void P_SpawnPhasedLight(sector_t *sector, int base, int index)
252 phase = Z_Malloc(sizeof(*phase), PU_LEVSPEC, 0);
253 P_AddThinker(&phase->thinker);
254 phase->sector = sector;
256 { // sector->lightlevel as the index
257 phase->index = sector->lightlevel&63;
261 phase->index = index&63;
263 phase->base = base&255;
264 sector->lightlevel = phase->base+PhaseTable[phase->index];
265 phase->thinker.function = T_Phase;
270 //==========================================================================
272 // P_SpawnLightSequence
274 //==========================================================================
276 void P_SpawnLightSequence(sector_t *sector, int indexStep)
288 seqSpecial = LIGHT_SEQUENCE; // look for Light_Sequence, first
294 sec->special = LIGHT_SEQUENCE_START; // make sure that the search doesn't back up.
295 for(i = 0; i < sec->linecount; i++)
297 tempSec = getNextSector(sec->lines[i], sec);
302 if(tempSec->special == seqSpecial)
304 if(seqSpecial == LIGHT_SEQUENCE)
306 seqSpecial = LIGHT_SEQUENCE_ALT;
310 seqSpecial = LIGHT_SEQUENCE;
322 indexDelta = FixedDiv(64*FRACUNIT, count*FRACUNIT);
323 base = sector->lightlevel;
329 base = sec->lightlevel;
331 P_SpawnPhasedLight(sec, base, index>>FRACBITS);
333 for(i = 0; i < sec->linecount; i++)
335 tempSec = getNextSector(sec->lines[i], sec);
340 if(tempSec->special == LIGHT_SEQUENCE_START)