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;
111 arg1 = arg[1] > 255 ? 255 : arg[1];
112 arg1 = arg1 < 0 ? 0 : arg1;
113 arg2 = arg[2] > 255 ? 255 : arg[2];
114 arg2 = arg2 < 0 ? 0 : arg2;
115 arg3 = arg[3] > 255 ? 255 : arg[3];
116 arg3 = arg3 < 0 ? 0 : arg3;
117 arg4 = arg[4] > 255 ? 255 : arg[4];
118 arg4 = arg4 < 0 ? 0 : arg4;
123 while((secNum = P_FindSectorFromTag(arg[0], secNum)) >= 0)
126 sec = §ors[secNum];
128 light = (light_t *)Z_Malloc(sizeof(light_t), PU_LEVSPEC, 0);
135 case LITE_RAISEBYVALUE:
136 sec->lightlevel += arg1;
137 if(sec->lightlevel > 255)
139 sec->lightlevel = 255;
142 case LITE_LOWERBYVALUE:
143 sec->lightlevel -= arg1;
144 if(sec->lightlevel < 0)
149 case LITE_CHANGETOVALUE:
150 sec->lightlevel = arg1;
151 if(sec->lightlevel < 0)
155 else if(sec->lightlevel > 255)
157 sec->lightlevel = 255;
162 light->value1 = arg1; // destination lightlevel
163 light->value2 = FixedDiv((arg1-sec->lightlevel)<<FRACBITS,
164 arg2<<FRACBITS); // delta lightlevel
165 if(sec->lightlevel <= arg1)
167 light->tics2 = 1; // get brighter
176 light->value1 = arg1; // upper lightlevel
177 light->value2 = arg2; // lower lightlevel
178 light->tics1 = FixedDiv((arg1-sec->lightlevel)<<FRACBITS,
179 arg3<<FRACBITS); // lightlevel delta
180 if(sec->lightlevel <= arg1)
182 light->tics2 = 1; // get brighter
191 light->value1 = arg1; // upper lightlevel
192 light->value2 = arg2; // lower lightlevel
193 sec->lightlevel = light->value1;
194 light->count = (P_Random()&64)+1;
198 light->value1 = arg1; // upper lightlevel
199 light->value2 = arg2; // lower lightlevel
200 light->tics1 = arg3; // upper tics
201 light->tics2 = arg4; // lower tics
203 sec->lightlevel = light->value1;
211 P_AddThinker(&light->thinker);
212 light->thinker.function = T_Light;
222 //============================================================================
226 //============================================================================
230 128, 112, 96, 80, 64, 48, 32, 32,
231 16, 16, 16, 0, 0, 0, 0, 0,
232 0, 0, 0, 0, 0, 0, 0, 0,
233 0, 0, 0, 0, 0, 0, 0, 0,
234 0, 0, 0, 0, 0, 0, 0, 0,
235 0, 0, 0, 0, 0, 0, 0, 0,
236 0, 0, 0, 0, 0, 16, 16, 16,
237 32, 32, 48, 64, 80, 96, 112, 128
240 void T_Phase(phase_t *phase)
242 phase->index = (phase->index+1)&63;
243 phase->sector->lightlevel = phase->base+PhaseTable[phase->index];
246 //==========================================================================
248 // P_SpawnPhasedLight
250 //==========================================================================
252 void P_SpawnPhasedLight(sector_t *sector, int base, int index)
256 phase = Z_Malloc(sizeof(*phase), PU_LEVSPEC, 0);
257 P_AddThinker(&phase->thinker);
258 phase->sector = sector;
260 { // sector->lightlevel as the index
261 phase->index = sector->lightlevel&63;
265 phase->index = index&63;
267 phase->base = base&255;
268 sector->lightlevel = phase->base+PhaseTable[phase->index];
269 phase->thinker.function = T_Phase;
274 //==========================================================================
276 // P_SpawnLightSequence
278 //==========================================================================
280 void P_SpawnLightSequence(sector_t *sector, int indexStep)
292 seqSpecial = LIGHT_SEQUENCE; // look for Light_Sequence, first
298 sec->special = LIGHT_SEQUENCE_START; // make sure that the search doesn't back up.
299 for(i = 0; i < sec->linecount; i++)
301 tempSec = getNextSector(sec->lines[i], sec);
306 if(tempSec->special == seqSpecial)
308 if(seqSpecial == LIGHT_SEQUENCE)
310 seqSpecial = LIGHT_SEQUENCE_ALT;
314 seqSpecial = LIGHT_SEQUENCE;
326 indexDelta = FixedDiv(64*FRACUNIT, count*FRACUNIT);
327 base = sector->lightlevel;
333 base = sec->lightlevel;
335 P_SpawnPhasedLight(sec, base, index>>FRACBITS);
337 for(i = 0; i < sec->linecount; i++)
339 tempSec = getNextSector(sec->lines[i], sec);
344 if(tempSec->special == LIGHT_SEQUENCE_START)