| 1 |
/* Emacs style mode select -*- C -*- |
| 2 |
*----------------------------------------------------------------------------- |
| 3 |
* |
| 4 |
* |
| 5 |
* PrBoom: a Doom port merged with LxDoom and LSDLDoom |
| 6 |
* based on BOOM, a modified and improved DOOM engine |
| 7 |
* Copyright (C) 1999 by |
| 8 |
* id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman |
| 9 |
* Copyright (C) 1999-2000 by |
| 10 |
* Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze |
| 11 |
* Copyright 2005, 2006 by |
| 12 |
* Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko |
| 13 |
* |
| 14 |
* This program is free software; you can redistribute it and/or |
| 15 |
* modify it under the terms of the GNU General Public License |
| 16 |
* as published by the Free Software Foundation; either version 2 |
| 17 |
* of the License, or (at your option) any later version. |
| 18 |
* |
| 19 |
* This program is distributed in the hope that it will be useful, |
| 20 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 |
* GNU General Public License for more details. |
| 23 |
* |
| 24 |
* You should have received a copy of the GNU General Public License |
| 25 |
* along with this program; if not, write to the Free Software |
| 26 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 27 |
* 02111-1307, USA. |
| 28 |
* |
| 29 |
* DESCRIPTION: |
| 30 |
* Action routines for lighting thinkers |
| 31 |
* Spawn sector based lighting effects. |
| 32 |
* Handle lighting linedef types |
| 33 |
* |
| 34 |
*-----------------------------------------------------------------------------*/ |
| 35 |
|
| 36 |
#include "doomstat.h" //jff 5/18/98 |
| 37 |
#include "doomdef.h" |
| 38 |
#include "m_random.h" |
| 39 |
#include "r_main.h" |
| 40 |
#include "p_spec.h" |
| 41 |
#include "p_tick.h" |
| 42 |
|
| 43 |
#include "dsda/id_list.h" |
| 44 |
|
| 45 |
////////////////////////////////////////////////////////// |
| 46 |
// |
| 47 |
// Lighting action routines, called once per tick |
| 48 |
// |
| 49 |
////////////////////////////////////////////////////////// |
| 50 |
|
| 51 |
// |
| 52 |
// T_FireFlicker() |
| 53 |
// |
| 54 |
// Firelight flicker action routine, called once per tick |
| 55 |
// |
| 56 |
// Passed a fireflicker_t structure containing light levels and timing |
| 57 |
// Returns nothing |
| 58 |
// |
| 59 |
void T_FireFlicker (fireflicker_t* flick) |
| 60 |
{ |
| 61 |
int amount; |
| 62 |
|
| 63 |
if (--flick->count) |
| 64 |
return; |
| 65 |
|
| 66 |
amount = (P_Random(pr_lights)&3)*16; |
| 67 |
|
| 68 |
if (flick->sector->lightlevel - amount < flick->minlight) |
| 69 |
flick->sector->lightlevel = flick->minlight; |
| 70 |
else |
| 71 |
flick->sector->lightlevel = flick->maxlight - amount; |
| 72 |
|
| 73 |
flick->count = 4; |
| 74 |
} |
| 75 |
|
| 76 |
// |
| 77 |
// T_LightFlash() |
| 78 |
// |
| 79 |
// Broken light flashing action routine, called once per tick |
| 80 |
// |
| 81 |
// Passed a lightflash_t structure containing light levels and timing |
| 82 |
// Returns nothing |
| 83 |
// |
| 84 |
void T_LightFlash (lightflash_t* flash) |
| 85 |
{ |
| 86 |
if (--flash->count) |
| 87 |
return; |
| 88 |
|
| 89 |
if (flash->sector->lightlevel == flash->maxlight) |
| 90 |
{ |
| 91 |
flash-> sector->lightlevel = flash->minlight; |
| 92 |
flash->count = (P_Random(pr_lights)&flash->mintime)+1; |
| 93 |
} |
| 94 |
else |
| 95 |
{ |
| 96 |
flash-> sector->lightlevel = flash->maxlight; |
| 97 |
flash->count = (P_Random(pr_lights)&flash->maxtime)+1; |
| 98 |
} |
| 99 |
|
| 100 |
} |
| 101 |
|
| 102 |
// |
| 103 |
// T_StrobeFlash() |
| 104 |
// |
| 105 |
// Strobe light flashing action routine, called once per tick |
| 106 |
// |
| 107 |
// Passed a strobe_t structure containing light levels and timing |
| 108 |
// Returns nothing |
| 109 |
// |
| 110 |
void T_StrobeFlash (strobe_t* flash) |
| 111 |
{ |
| 112 |
if (--flash->count) |
| 113 |
return; |
| 114 |
|
| 115 |
if (flash->sector->lightlevel == flash->minlight) |
| 116 |
{ |
| 117 |
flash-> sector->lightlevel = flash->maxlight; |
| 118 |
flash->count = flash->brighttime; |
| 119 |
} |
| 120 |
else |
| 121 |
{ |
| 122 |
flash-> sector->lightlevel = flash->minlight; |
| 123 |
flash->count =flash->darktime; |
| 124 |
} |
| 125 |
} |
| 126 |
|
| 127 |
// |
| 128 |
// T_Glow() |
| 129 |
// |
| 130 |
// Glowing light action routine, called once per tick |
| 131 |
// |
| 132 |
// Passed a glow_t structure containing light levels and timing |
| 133 |
// Returns nothing |
| 134 |
// |
| 135 |
|
| 136 |
void T_Glow(glow_t* g) |
| 137 |
{ |
| 138 |
switch(g->direction) |
| 139 |
{ |
| 140 |
case -1: |
| 141 |
// light dims |
| 142 |
g->sector->lightlevel -= GLOWSPEED; |
| 143 |
if (g->sector->lightlevel <= g->minlight) |
| 144 |
{ |
| 145 |
g->sector->lightlevel += GLOWSPEED; |
| 146 |
g->direction = 1; |
| 147 |
} |
| 148 |
break; |
| 149 |
|
| 150 |
case 1: |
| 151 |
// light brightens |
| 152 |
g->sector->lightlevel += GLOWSPEED; |
| 153 |
if (g->sector->lightlevel >= g->maxlight) |
| 154 |
{ |
| 155 |
g->sector->lightlevel -= GLOWSPEED; |
| 156 |
g->direction = -1; |
| 157 |
} |
| 158 |
break; |
| 159 |
} |
| 160 |
} |
| 161 |
|
| 162 |
////////////////////////////////////////////////////////// |
| 163 |
// |
| 164 |
// Sector lighting type spawners |
| 165 |
// |
| 166 |
// After the map has been loaded, each sector is scanned |
| 167 |
// for specials that spawn thinkers |
| 168 |
// |
| 169 |
////////////////////////////////////////////////////////// |
| 170 |
|
| 171 |
// |
| 172 |
// P_SpawnFireFlicker() |
| 173 |
// |
| 174 |
// Spawns a fire flicker lighting thinker |
| 175 |
// |
| 176 |
// Passed the sector that spawned the thinker |
| 177 |
// Returns nothing |
| 178 |
// |
| 179 |
void P_SpawnFireFlicker (sector_t* sector) |
| 180 |
{ |
| 181 |
fireflicker_t* flick; |
| 182 |
|
| 183 |
P_ClearNonGeneralizedSectorSpecial(sector); |
| 184 |
|
| 185 |
flick = Z_MallocLevel ( sizeof(*flick)); |
| 186 |
|
| 187 |
memset(flick, 0, sizeof(*flick)); |
| 188 |
P_AddThinker (&flick->thinker); |
| 189 |
|
| 190 |
flick->thinker.function = T_FireFlicker; |
| 191 |
flick->sector = sector; |
| 192 |
sector->lightingdata = flick; |
| 193 |
flick->maxlight = sector->lightlevel; |
| 194 |
flick->minlight = P_FindMinSurroundingLight(sector,sector->lightlevel)+16; |
| 195 |
flick->count = 4; |
| 196 |
} |
| 197 |
|
| 198 |
// |
| 199 |
// P_SpawnLightFlash() |
| 200 |
// |
| 201 |
// Spawns a broken light flash lighting thinker |
| 202 |
// |
| 203 |
// Passed the sector that spawned the thinker |
| 204 |
// Returns nothing |
| 205 |
// |
| 206 |
void P_SpawnLightFlash (sector_t* sector) |
| 207 |
{ |
| 208 |
lightflash_t* flash; |
| 209 |
|
| 210 |
P_ClearNonGeneralizedSectorSpecial(sector); |
| 211 |
|
| 212 |
flash = Z_MallocLevel ( sizeof(*flash)); |
| 213 |
|
| 214 |
memset(flash, 0, sizeof(*flash)); |
| 215 |
P_AddThinker (&flash->thinker); |
| 216 |
|
| 217 |
flash->thinker.function = T_LightFlash; |
| 218 |
flash->sector = sector; |
| 219 |
sector->lightingdata = flash; |
| 220 |
flash->maxlight = sector->lightlevel; |
| 221 |
|
| 222 |
flash->minlight = P_FindMinSurroundingLight(sector,sector->lightlevel); |
| 223 |
flash->maxtime = 64; |
| 224 |
flash->mintime = 7; |
| 225 |
flash->count = (P_Random(pr_lights)&flash->maxtime)+1; |
| 226 |
} |
| 227 |
|
| 228 |
// |
| 229 |
// P_SpawnStrobeFlash |
| 230 |
// |
| 231 |
// Spawns a blinking light thinker |
| 232 |
// |
| 233 |
// Passed the sector that spawned the thinker, speed of blinking |
| 234 |
// and whether blinking is to by syncrhonous with other sectors |
| 235 |
// |
| 236 |
// Returns nothing |
| 237 |
// |
| 238 |
void P_SpawnStrobeFlash |
| 239 |
( sector_t* sector, |
| 240 |
int fastOrSlow, |
| 241 |
int inSync ) |
| 242 |
{ |
| 243 |
strobe_t* flash; |
| 244 |
|
| 245 |
flash = Z_MallocLevel ( sizeof(*flash)); |
| 246 |
|
| 247 |
memset(flash, 0, sizeof(*flash)); |
| 248 |
P_AddThinker (&flash->thinker); |
| 249 |
|
| 250 |
flash->sector = sector; |
| 251 |
sector->lightingdata = flash; |
| 252 |
flash->darktime = fastOrSlow; |
| 253 |
flash->brighttime = STROBEBRIGHT; |
| 254 |
flash->thinker.function = T_StrobeFlash; |
| 255 |
flash->maxlight = sector->lightlevel; |
| 256 |
flash->minlight = P_FindMinSurroundingLight(sector, sector->lightlevel); |
| 257 |
|
| 258 |
if (flash->minlight == flash->maxlight) |
| 259 |
flash->minlight = 0; |
| 260 |
|
| 261 |
P_ClearNonGeneralizedSectorSpecial(sector); |
| 262 |
|
| 263 |
if (!inSync) |
| 264 |
flash->count = (P_Random(pr_lights)&7)+1; |
| 265 |
else |
| 266 |
flash->count = 1; |
| 267 |
} |
| 268 |
|
| 269 |
// |
| 270 |
// P_SpawnGlowingLight() |
| 271 |
// |
| 272 |
// Spawns a glowing light (smooth oscillation from min to max) thinker |
| 273 |
// |
| 274 |
// Passed the sector that spawned the thinker |
| 275 |
// Returns nothing |
| 276 |
// |
| 277 |
void P_SpawnGlowingLight(sector_t* sector) |
| 278 |
{ |
| 279 |
glow_t* g; |
| 280 |
|
| 281 |
g = Z_MallocLevel( sizeof(*g)); |
| 282 |
|
| 283 |
memset(g, 0, sizeof(*g)); |
| 284 |
P_AddThinker(&g->thinker); |
| 285 |
|
| 286 |
g->sector = sector; |
| 287 |
sector->lightingdata = g; |
| 288 |
g->minlight = P_FindMinSurroundingLight(sector,sector->lightlevel); |
| 289 |
g->maxlight = sector->lightlevel; |
| 290 |
g->thinker.function = T_Glow; |
| 291 |
g->direction = -1; |
| 292 |
|
| 293 |
P_ClearNonGeneralizedSectorSpecial(sector); |
| 294 |
} |
| 295 |
|
| 296 |
////////////////////////////////////////////////////////// |
| 297 |
// |
| 298 |
// Linedef lighting function handlers |
| 299 |
// |
| 300 |
////////////////////////////////////////////////////////// |
| 301 |
|
| 302 |
// |
| 303 |
// EV_StartLightStrobing() |
| 304 |
// |
| 305 |
// Start strobing lights (usually from a trigger) |
| 306 |
// |
| 307 |
// Passed the line that activated the strobing |
| 308 |
// Returns true |
| 309 |
// |
| 310 |
// jff 2/12/98 added int return value, fixed return |
| 311 |
// |
| 312 |
int EV_StartLightStrobing(line_t* line) |
| 313 |
{ |
| 314 |
const int *id_p; |
| 315 |
sector_t* sec; |
| 316 |
|
| 317 |
// start lights strobing in all sectors tagged same as line |
| 318 |
FIND_SECTORS(id_p, line->tag) |
| 319 |
{ |
| 320 |
sec = §ors[*id_p]; |
| 321 |
|
| 322 |
// Original code never stored lighting data, |
| 323 |
// so this only stops a light appearing in old complevels, |
| 324 |
// and only when there is a floor or ceiling thinker. |
| 325 |
if (demo_compatibility && P_PlaneActive(sec)) |
| 326 |
continue; |
| 327 |
|
| 328 |
P_SpawnStrobeFlash (sec,SLOWDARK, 0); |
| 329 |
} |
| 330 |
return 1; |
| 331 |
} |
| 332 |
|
| 333 |
// |
| 334 |
// EV_TurnTagLightsOff() |
| 335 |
// |
| 336 |
// Turn line's tagged sector's lights to min adjacent neighbor level |
| 337 |
// |
| 338 |
// Passed the line that activated the lights being turned off |
| 339 |
// Returns true |
| 340 |
// |
| 341 |
// jff 2/12/98 added int return value, fixed return |
| 342 |
// |
| 343 |
int EV_TurnTagLightsOff(line_t* line) |
| 344 |
{ |
| 345 |
const int *id_p; |
| 346 |
|
| 347 |
// search sectors for those with same tag as activating line |
| 348 |
|
| 349 |
// killough 10/98: replaced inefficient search with fast search |
| 350 |
FIND_SECTORS(id_p, line->tag) |
| 351 |
{ |
| 352 |
sector_t *sector = sectors + *id_p, *tsec; |
| 353 |
int i, min = sector->lightlevel; |
| 354 |
// find min neighbor light level |
| 355 |
for (i = 0;i < sector->linecount; i++) |
| 356 |
if ((tsec = getNextSector(sector->lines[i], sector)) && |
| 357 |
tsec->lightlevel < min) |
| 358 |
min = tsec->lightlevel; |
| 359 |
sector->lightlevel = min; |
| 360 |
} |
| 361 |
return 1; |
| 362 |
} |
| 363 |
|
| 364 |
// |
| 365 |
// EV_LightTurnOn() |
| 366 |
// |
| 367 |
// Turn sectors tagged to line lights on to specified or max neighbor level |
| 368 |
// |
| 369 |
// Passed the activating line, and a level to set the light to |
| 370 |
// If level passed is 0, the maximum neighbor lighting is used |
| 371 |
// Returns true |
| 372 |
// |
| 373 |
// jff 2/12/98 added int return value, fixed return |
| 374 |
// |
| 375 |
int EV_LightTurnOn(line_t *line, int bright) |
| 376 |
{ |
| 377 |
const int *id_p; |
| 378 |
|
| 379 |
// search all sectors for ones with same tag as activating line |
| 380 |
|
| 381 |
// killough 10/98: replace inefficient search with fast search |
| 382 |
FIND_SECTORS(id_p, line->tag) |
| 383 |
{ |
| 384 |
sector_t *temp, *sector = sectors+*id_p; |
| 385 |
int j, tbright = bright; //jff 5/17/98 search for maximum PER sector |
| 386 |
|
| 387 |
// bright = 0 means to search for highest light level surrounding sector |
| 388 |
|
| 389 |
if (!bright) |
| 390 |
for (j = 0;j < sector->linecount; j++) |
| 391 |
if ((temp = getNextSector(sector->lines[j],sector)) && |
| 392 |
temp->lightlevel > tbright) |
| 393 |
tbright = temp->lightlevel; |
| 394 |
|
| 395 |
sector->lightlevel = tbright; |
| 396 |
|
| 397 |
//jff 5/17/98 unless compatibility optioned |
| 398 |
//then maximum near ANY tagged sector |
| 399 |
if (comp[comp_model]) |
| 400 |
bright = tbright; |
| 401 |
} |
| 402 |
return 1; |
| 403 |
} |
| 404 |
|
| 405 |
/* killough 10/98: |
| 406 |
* |
| 407 |
* EV_LightTurnOnPartway() |
| 408 |
* |
| 409 |
* Turn sectors tagged to line lights on to specified or max neighbor level |
| 410 |
* |
| 411 |
* Passed the activating line, and a light level fraction between 0 and 1. |
| 412 |
* Sets the light to min on 0, max on 1, and interpolates in-between. |
| 413 |
* Used for doors with gradual lighting effects. |
| 414 |
* |
| 415 |
* Returns true |
| 416 |
*/ |
| 417 |
|
| 418 |
int EV_LightTurnOnPartway(line_t *line, fixed_t level) |
| 419 |
{ |
| 420 |
const int *id_p; |
| 421 |
|
| 422 |
if (level < 0) // clip at extremes |
| 423 |
level = 0; |
| 424 |
if (level > FRACUNIT) |
| 425 |
level = FRACUNIT; |
| 426 |
|
| 427 |
// search all sectors for ones with same tag as activating line |
| 428 |
FIND_SECTORS(id_p, line->tag) |
| 429 |
{ |
| 430 |
sector_t *temp, *sector = sectors+*id_p; |
| 431 |
int j, bright = 0, min = sector->lightlevel; |
| 432 |
|
| 433 |
for (j = 0; j < sector->linecount; j++) |
| 434 |
if ((temp = getNextSector(sector->lines[j],sector))) |
| 435 |
{ |
| 436 |
if (temp->lightlevel > bright) |
| 437 |
bright = temp->lightlevel; |
| 438 |
if (temp->lightlevel < min) |
| 439 |
min = temp->lightlevel; |
| 440 |
} |
| 441 |
|
| 442 |
sector->lightlevel = // Set level in-between extremes |
| 443 |
(level * bright + (FRACUNIT-level) * min) >> FRACBITS; |
| 444 |
} |
| 445 |
return 1; |
| 446 |
} |
| 447 |
|
| 448 |
void EV_LightChange(int tag, short change) |
| 449 |
{ |
| 450 |
const int *id_p; |
| 451 |
|
| 452 |
FIND_SECTORS(id_p, tag) |
| 453 |
sectors[*id_p].lightlevel += change; |
| 454 |
} |
| 455 |
|
| 456 |
void EV_LightSet(int tag, short level) |
| 457 |
{ |
| 458 |
const int *id_p; |
| 459 |
|
| 460 |
FIND_SECTORS(id_p, tag) |
| 461 |
sectors[*id_p].lightlevel = level; |
| 462 |
} |
| 463 |
|
| 464 |
void EV_LightSetMinNeighbor(int tag) |
| 465 |
{ |
| 466 |
const int *id_p; |
| 467 |
|
| 468 |
FIND_SECTORS(id_p, tag) |
| 469 |
{ |
| 470 |
int i; |
| 471 |
short level; |
| 472 |
sector_t *temp, *sector; |
| 473 |
|
| 474 |
sector = §ors[*id_p]; |
| 475 |
level = sector->lightlevel; |
| 476 |
|
| 477 |
for (i = 0; i < sector->linecount; i++) |
| 478 |
if ((temp = getNextSector(sector->lines[i], sector)) && temp->lightlevel < level) |
| 479 |
level = temp->lightlevel; |
| 480 |
|
| 481 |
sector->lightlevel = level; |
| 482 |
} |
| 483 |
} |
| 484 |
|
| 485 |
void EV_LightSetMaxNeighbor(int tag) |
| 486 |
{ |
| 487 |
const int *id_p; |
| 488 |
|
| 489 |
FIND_SECTORS(id_p, tag) |
| 490 |
{ |
| 491 |
int i; |
| 492 |
short level; |
| 493 |
sector_t *temp, *sector; |
| 494 |
|
| 495 |
sector = §ors[*id_p]; |
| 496 |
level = 0; |
| 497 |
|
| 498 |
for (i = 0; i < sector->linecount; i++) |
| 499 |
if ((temp = getNextSector(sector->lines[i], sector)) && temp->lightlevel > level) |
| 500 |
level = temp->lightlevel; |
| 501 |
|
| 502 |
sector->lightlevel = level; |
| 503 |
} |
| 504 |
} |
| 505 |
|
| 506 |
void T_ZDoom_Glow(zdoom_glow_t *g) |
| 507 |
{ |
| 508 |
if (g->tics++ >= g->maxtics) |
| 509 |
{ |
| 510 |
if (g->oneshot) |
| 511 |
{ |
| 512 |
g->sector->lightlevel = g->endlevel; |
| 513 |
g->sector->lightingdata = NULL; |
| 514 |
P_RemoveThinker(&g->thinker); |
| 515 |
return; |
| 516 |
} |
| 517 |
else |
| 518 |
{ |
| 519 |
short temp = g->startlevel; |
| 520 |
g->startlevel = g->endlevel; |
| 521 |
g->endlevel = temp; |
| 522 |
g->tics -= g->maxtics; |
| 523 |
} |
| 524 |
} |
| 525 |
|
| 526 |
g->sector->lightlevel = g->tics * (g->endlevel - g->startlevel) / g->maxtics + g->startlevel; |
| 527 |
} |
| 528 |
|
| 529 |
static void P_SpawnZDoomLightGlow(sector_t *sec, short startlevel, short endlevel, |
| 530 |
short maxtics, dboolean oneshot) |
| 531 |
{ |
| 532 |
zdoom_glow_t *g; |
| 533 |
|
| 534 |
g = Z_MallocLevel(sizeof(*g)); |
| 535 |
|
| 536 |
memset(g, 0, sizeof(*g)); |
| 537 |
P_AddThinker(&g->thinker); |
| 538 |
g->thinker.function = T_ZDoom_Glow; |
| 539 |
|
| 540 |
g->sector = sec; |
| 541 |
sec->lightingdata = g; |
| 542 |
g->startlevel = startlevel; |
| 543 |
g->endlevel = endlevel; |
| 544 |
g->tics = -1; |
| 545 |
g->maxtics = maxtics; |
| 546 |
g->oneshot = oneshot; |
| 547 |
} |
| 548 |
|
| 549 |
void EV_StartLightFading(int tag, short level, short tics) |
| 550 |
{ |
| 551 |
const int *id_p; |
| 552 |
|
| 553 |
FIND_SECTORS(id_p, tag) |
| 554 |
{ |
| 555 |
sector_t *sec = §ors[*id_p]; |
| 556 |
|
| 557 |
if (sec->lightingdata || sec->lightlevel == level) |
| 558 |
continue; |
| 559 |
|
| 560 |
if (tics) |
| 561 |
{ |
| 562 |
P_SpawnZDoomLightGlow(sec, sec->lightlevel, level, tics, true); |
| 563 |
} |
| 564 |
else |
| 565 |
{ |
| 566 |
sec->lightlevel = level; |
| 567 |
} |
| 568 |
} |
| 569 |
} |
| 570 |
|
| 571 |
void EV_StartLightGlowing(int tag, short upper, short lower, short tics) |
| 572 |
{ |
| 573 |
const int *id_p; |
| 574 |
|
| 575 |
if (tics == 0) |
| 576 |
return; |
| 577 |
|
| 578 |
if (upper < lower) |
| 579 |
{ |
| 580 |
short temp = upper; |
| 581 |
upper = lower; |
| 582 |
lower = temp; |
| 583 |
} |
| 584 |
|
| 585 |
FIND_SECTORS(id_p, tag) |
| 586 |
{ |
| 587 |
sector_t *sec = §ors[*id_p]; |
| 588 |
|
| 589 |
if (sec->lightingdata) |
| 590 |
continue; |
| 591 |
|
| 592 |
P_SpawnZDoomLightGlow(sec, upper, lower, tics, false); |
| 593 |
} |
| 594 |
} |
| 595 |
|
| 596 |
void T_ZDoom_Flicker(zdoom_flicker_t *g) |
| 597 |
{ |
| 598 |
if (g->count) |
| 599 |
{ |
| 600 |
g->count--; |
| 601 |
} |
| 602 |
else if (g->sector->lightlevel == g->upper) |
| 603 |
{ |
| 604 |
g->sector->lightlevel = g->lower; |
| 605 |
g->count = (P_Random(pr_lights) & 7) + 1; |
| 606 |
} |
| 607 |
else |
| 608 |
{ |
| 609 |
g->sector->lightlevel = g->upper; |
| 610 |
g->count = (P_Random(pr_lights) & 31) + 1; |
| 611 |
} |
| 612 |
} |
| 613 |
|
| 614 |
static void P_SpawnZDoomLightFlicker(sector_t *sec, short upper, short lower) |
| 615 |
{ |
| 616 |
zdoom_flicker_t *g; |
| 617 |
|
| 618 |
g = Z_MallocLevel(sizeof(*g)); |
| 619 |
|
| 620 |
memset(g, 0, sizeof(*g)); |
| 621 |
P_AddThinker(&g->thinker); |
| 622 |
g->thinker.function = T_ZDoom_Flicker; |
| 623 |
|
| 624 |
g->sector = sec; |
| 625 |
sec->lightingdata = g; |
| 626 |
g->upper = upper; |
| 627 |
g->lower = lower; |
| 628 |
g->count = (P_Random(pr_lights) & 64) + 1; |
| 629 |
} |
| 630 |
|
| 631 |
void EV_StartLightFlickering(int tag, short upper, short lower) |
| 632 |
{ |
| 633 |
const int *id_p; |
| 634 |
|
| 635 |
FIND_SECTORS(id_p, tag) |
| 636 |
{ |
| 637 |
sector_t *sec = §ors[*id_p]; |
| 638 |
|
| 639 |
if (sec->lightingdata) |
| 640 |
continue; |
| 641 |
|
| 642 |
P_SpawnZDoomLightFlicker(sec, upper, lower); |
| 643 |
} |
| 644 |
} |
| 645 |
|
| 646 |
static void P_SpawnZDoomLightStrobe(sector_t *sector, int upper, int lower, |
| 647 |
int brighttime, int darktime, int count) |
| 648 |
{ |
| 649 |
strobe_t* g; |
| 650 |
|
| 651 |
g = Z_MallocLevel ( sizeof(*g)); |
| 652 |
|
| 653 |
memset(g, 0, sizeof(*g)); |
| 654 |
P_AddThinker (&g->thinker); |
| 655 |
|
| 656 |
g->sector = sector; |
| 657 |
sector->lightingdata = g; |
| 658 |
g->darktime = darktime; |
| 659 |
g->brighttime = brighttime; |
| 660 |
g->thinker.function = T_StrobeFlash; |
| 661 |
g->maxlight = upper; |
| 662 |
g->minlight = lower; |
| 663 |
|
| 664 |
if (g->minlight == g->maxlight) |
| 665 |
g->minlight = 0; |
| 666 |
|
| 667 |
g->count = count; |
| 668 |
} |
| 669 |
|
| 670 |
static void P_SpawnZDoomLightStrobeDoom(sector_t* sector, int brighttime, int darktime) |
| 671 |
{ |
| 672 |
int count = (P_Random(pr_lights) & 7) + 1; |
| 673 |
|
| 674 |
P_SpawnZDoomLightStrobe( |
| 675 |
sector, sector->lightlevel, P_FindMinSurroundingLight(sector, sector->lightlevel), |
| 676 |
brighttime, darktime, count |
| 677 |
); |
| 678 |
} |
| 679 |
|
| 680 |
void EV_StartZDoomLightStrobing(int tag, int upper, int lower, int brighttime, int darktime) |
| 681 |
{ |
| 682 |
const int *id_p; |
| 683 |
|
| 684 |
FIND_SECTORS(id_p, tag) |
| 685 |
{ |
| 686 |
sector_t *sec = §ors[*id_p]; |
| 687 |
|
| 688 |
if (sec->lightingdata) |
| 689 |
continue; |
| 690 |
|
| 691 |
P_SpawnZDoomLightStrobe(sec, upper, lower, brighttime, darktime, 1); |
| 692 |
} |
| 693 |
} |
| 694 |
|
| 695 |
void EV_StartZDoomLightStrobingDoom(int tag, int brighttime, int darktime) |
| 696 |
{ |
| 697 |
const int *id_p; |
| 698 |
|
| 699 |
FIND_SECTORS(id_p, tag) |
| 700 |
{ |
| 701 |
sector_t *sec = §ors[*id_p]; |
| 702 |
|
| 703 |
if (sec->lightingdata) |
| 704 |
continue; |
| 705 |
|
| 706 |
P_SpawnZDoomLightStrobeDoom(sec, brighttime, darktime); |
| 707 |
} |
| 708 |
} |
| 709 |
|
| 710 |
void EV_StopLightEffect(int tag) |
| 711 |
{ |
| 712 |
const int *id_p; |
| 713 |
|
| 714 |
FIND_SECTORS(id_p, tag) |
| 715 |
{ |
| 716 |
sector_t *sec = §ors[*id_p]; |
| 717 |
|
| 718 |
if (sec->lightingdata) |
| 719 |
{ |
| 720 |
P_RemoveThinker((thinker_t *) sec->lightingdata); |
| 721 |
sec->lightingdata = NULL; |
| 722 |
} |
| 723 |
} |
| 724 |
} |
| 725 |
|
| 726 |
// hexen |
| 727 |
|
| 728 |
void T_Light(light_t * light) |
| 729 |
{ |
| 730 |
if (light->count) |
| 731 |
{ |
| 732 |
light->count--; |
| 733 |
return; |
| 734 |
} |
| 735 |
switch (light->type) |
| 736 |
{ |
| 737 |
case LITE_FADE: |
| 738 |
light->sector->lightlevel = |
| 739 |
((light->sector->lightlevel << FRACBITS) + |
| 740 |
light->value2) >> FRACBITS; |
| 741 |
if (light->tics2 == 1) |
| 742 |
{ |
| 743 |
if (light->sector->lightlevel >= light->value1) |
| 744 |
{ |
| 745 |
light->sector->lightlevel = light->value1; |
| 746 |
P_RemoveThinker(&light->thinker); |
| 747 |
} |
| 748 |
} |
| 749 |
else if (light->sector->lightlevel <= light->value1) |
| 750 |
{ |
| 751 |
light->sector->lightlevel = light->value1; |
| 752 |
P_RemoveThinker(&light->thinker); |
| 753 |
} |
| 754 |
break; |
| 755 |
case LITE_GLOW: |
| 756 |
light->sector->lightlevel = |
| 757 |
((light->sector->lightlevel << FRACBITS) + |
| 758 |
light->tics1) >> FRACBITS; |
| 759 |
if (light->tics2 == 1) |
| 760 |
{ |
| 761 |
if (light->sector->lightlevel >= light->value1) |
| 762 |
{ |
| 763 |
light->sector->lightlevel = light->value1; |
| 764 |
light->tics1 = -light->tics1; |
| 765 |
light->tics2 = -1; // reverse direction |
| 766 |
} |
| 767 |
} |
| 768 |
else if (light->sector->lightlevel <= light->value2) |
| 769 |
{ |
| 770 |
light->sector->lightlevel = light->value2; |
| 771 |
light->tics1 = -light->tics1; |
| 772 |
light->tics2 = 1; // reverse direction |
| 773 |
} |
| 774 |
break; |
| 775 |
case LITE_FLICKER: |
| 776 |
if (light->sector->lightlevel == light->value1) |
| 777 |
{ |
| 778 |
light->sector->lightlevel = light->value2; |
| 779 |
light->count = (P_Random(pr_hexen) & 7) + 1; |
| 780 |
} |
| 781 |
else |
| 782 |
{ |
| 783 |
light->sector->lightlevel = light->value1; |
| 784 |
light->count = (P_Random(pr_hexen) & 31) + 1; |
| 785 |
} |
| 786 |
break; |
| 787 |
case LITE_STROBE: |
| 788 |
if (light->sector->lightlevel == light->value1) |
| 789 |
{ |
| 790 |
light->sector->lightlevel = light->value2; |
| 791 |
light->count = light->tics2; |
| 792 |
} |
| 793 |
else |
| 794 |
{ |
| 795 |
light->sector->lightlevel = light->value1; |
| 796 |
light->count = light->tics1; |
| 797 |
} |
| 798 |
break; |
| 799 |
default: |
| 800 |
break; |
| 801 |
} |
| 802 |
} |
| 803 |
|
| 804 |
dboolean EV_SpawnLight(line_t * line, byte * arg, lighttype_t type) |
| 805 |
{ |
| 806 |
light_t *light; |
| 807 |
sector_t *sec; |
| 808 |
const int *id_p; |
| 809 |
int arg1, arg2, arg3, arg4; |
| 810 |
dboolean think; |
| 811 |
dboolean rtn; |
| 812 |
|
| 813 |
arg1 = arg[1]; |
| 814 |
arg2 = arg[2]; |
| 815 |
arg3 = arg[3]; |
| 816 |
arg4 = arg[4]; |
| 817 |
|
| 818 |
rtn = false; |
| 819 |
FIND_SECTORS(id_p, arg[0]) |
| 820 |
{ |
| 821 |
think = false; |
| 822 |
sec = §ors[*id_p]; |
| 823 |
|
| 824 |
light = (light_t *) Z_MallocLevel(sizeof(light_t)); |
| 825 |
light->type = type; |
| 826 |
light->sector = sec; |
| 827 |
light->count = 0; |
| 828 |
rtn = true; |
| 829 |
switch (type) |
| 830 |
{ |
| 831 |
case LITE_RAISEBYVALUE: |
| 832 |
sec->lightlevel += arg1; |
| 833 |
if (sec->lightlevel > 255) |
| 834 |
{ |
| 835 |
sec->lightlevel = 255; |
| 836 |
} |
| 837 |
break; |
| 838 |
case LITE_LOWERBYVALUE: |
| 839 |
sec->lightlevel -= arg1; |
| 840 |
if (sec->lightlevel < 0) |
| 841 |
{ |
| 842 |
sec->lightlevel = 0; |
| 843 |
} |
| 844 |
break; |
| 845 |
case LITE_CHANGETOVALUE: |
| 846 |
sec->lightlevel = arg1; |
| 847 |
if (sec->lightlevel < 0) |
| 848 |
{ |
| 849 |
sec->lightlevel = 0; |
| 850 |
} |
| 851 |
else if (sec->lightlevel > 255) |
| 852 |
{ |
| 853 |
sec->lightlevel = 255; |
| 854 |
} |
| 855 |
break; |
| 856 |
case LITE_FADE: |
| 857 |
think = true; |
| 858 |
light->value1 = arg1; // destination lightlevel |
| 859 |
light->value2 = FixedDiv((arg1 - sec->lightlevel) << FRACBITS, arg2 << FRACBITS); // delta lightlevel |
| 860 |
if (sec->lightlevel <= arg1) |
| 861 |
{ |
| 862 |
light->tics2 = 1; // get brighter |
| 863 |
} |
| 864 |
else |
| 865 |
{ |
| 866 |
light->tics2 = -1; |
| 867 |
} |
| 868 |
break; |
| 869 |
case LITE_GLOW: |
| 870 |
think = true; |
| 871 |
light->value1 = arg1; // upper lightlevel |
| 872 |
light->value2 = arg2; // lower lightlevel |
| 873 |
light->tics1 = FixedDiv((arg1 - sec->lightlevel) << FRACBITS, arg3 << FRACBITS); // lightlevel delta |
| 874 |
if (sec->lightlevel <= arg1) |
| 875 |
{ |
| 876 |
light->tics2 = 1; // get brighter |
| 877 |
} |
| 878 |
else |
| 879 |
{ |
| 880 |
light->tics2 = -1; |
| 881 |
} |
| 882 |
break; |
| 883 |
case LITE_FLICKER: |
| 884 |
think = true; |
| 885 |
light->value1 = arg1; // upper lightlevel |
| 886 |
light->value2 = arg2; // lower lightlevel |
| 887 |
sec->lightlevel = light->value1; |
| 888 |
light->count = (P_Random(pr_hexen) & 64) + 1; |
| 889 |
break; |
| 890 |
case LITE_STROBE: |
| 891 |
think = true; |
| 892 |
light->value1 = arg1; // upper lightlevel |
| 893 |
light->value2 = arg2; // lower lightlevel |
| 894 |
light->tics1 = arg3; // upper tics |
| 895 |
light->tics2 = arg4; // lower tics |
| 896 |
light->count = arg3; |
| 897 |
sec->lightlevel = light->value1; |
| 898 |
break; |
| 899 |
default: |
| 900 |
rtn = false; |
| 901 |
break; |
| 902 |
} |
| 903 |
if (think) |
| 904 |
{ |
| 905 |
P_AddThinker(&light->thinker); |
| 906 |
light->thinker.function = T_Light; |
| 907 |
} |
| 908 |
else |
| 909 |
{ |
| 910 |
Z_Free(light); |
| 911 |
} |
| 912 |
} |
| 913 |
return rtn; |
| 914 |
} |
| 915 |
|
| 916 |
static int PhaseTable[64] = { |
| 917 |
128, 112, 96, 80, 64, 48, 32, 32, |
| 918 |
16, 16, 16, 0, 0, 0, 0, 0, |
| 919 |
0, 0, 0, 0, 0, 0, 0, 0, |
| 920 |
0, 0, 0, 0, 0, 0, 0, 0, |
| 921 |
0, 0, 0, 0, 0, 0, 0, 0, |
| 922 |
0, 0, 0, 0, 0, 0, 0, 0, |
| 923 |
0, 0, 0, 0, 0, 16, 16, 16, |
| 924 |
32, 32, 48, 64, 80, 96, 112, 128 |
| 925 |
}; |
| 926 |
|
| 927 |
void T_Phase(phase_t * phase) |
| 928 |
{ |
| 929 |
phase->index = (phase->index + 1) & 63; |
| 930 |
phase->sector->lightlevel = phase->base + PhaseTable[phase->index]; |
| 931 |
} |
| 932 |
|
| 933 |
void P_SpawnPhasedLight(sector_t * sector, int base, int index) |
| 934 |
{ |
| 935 |
phase_t *phase; |
| 936 |
|
| 937 |
phase = Z_MallocLevel(sizeof(*phase)); |
| 938 |
P_AddThinker(&phase->thinker); |
| 939 |
phase->sector = sector; |
| 940 |
sector->lightingdata = phase; |
| 941 |
if (index == -1) |
| 942 |
{ // sector->lightlevel as the index |
| 943 |
phase->index = sector->lightlevel & 63; |
| 944 |
} |
| 945 |
else |
| 946 |
{ |
| 947 |
phase->index = index & 63; |
| 948 |
} |
| 949 |
phase->base = base & 255; |
| 950 |
sector->lightlevel = phase->base + PhaseTable[phase->index]; |
| 951 |
phase->thinker.function = T_Phase; |
| 952 |
|
| 953 |
P_ClearNonGeneralizedSectorSpecial(sector); |
| 954 |
} |
| 955 |
|
| 956 |
void P_SpawnLightSequence(sector_t * sector, int indexStep) |
| 957 |
{ |
| 958 |
sector_t *sec; |
| 959 |
sector_t *nextSec; |
| 960 |
sector_t *tempSec; |
| 961 |
int seqSpecial; |
| 962 |
int i; |
| 963 |
int count; |
| 964 |
fixed_t index; |
| 965 |
fixed_t indexDelta; |
| 966 |
int base; |
| 967 |
|
| 968 |
seqSpecial = LIGHT_SEQUENCE; // look for Light_Sequence, first |
| 969 |
sec = sector; |
| 970 |
count = 1; |
| 971 |
do |
| 972 |
{ |
| 973 |
nextSec = NULL; |
| 974 |
sec->special = LIGHT_SEQUENCE_START; // make sure that the search doesn't back up. |
| 975 |
for (i = 0; i < sec->linecount; i++) |
| 976 |
{ |
| 977 |
tempSec = getNextSector(sec->lines[i], sec); |
| 978 |
if (!tempSec) |
| 979 |
{ |
| 980 |
continue; |
| 981 |
} |
| 982 |
if (tempSec->special == seqSpecial) |
| 983 |
{ |
| 984 |
if (seqSpecial == LIGHT_SEQUENCE) |
| 985 |
{ |
| 986 |
seqSpecial = LIGHT_SEQUENCE_ALT; |
| 987 |
} |
| 988 |
else |
| 989 |
{ |
| 990 |
seqSpecial = LIGHT_SEQUENCE; |
| 991 |
} |
| 992 |
nextSec = tempSec; |
| 993 |
count++; |
| 994 |
} |
| 995 |
} |
| 996 |
sec = nextSec; |
| 997 |
} |
| 998 |
while (sec); |
| 999 |
|
| 1000 |
sec = sector; |
| 1001 |
count *= indexStep; |
| 1002 |
index = 0; |
| 1003 |
indexDelta = FixedDiv(64 * FRACUNIT, count * FRACUNIT); |
| 1004 |
base = sector->lightlevel; |
| 1005 |
do |
| 1006 |
{ |
| 1007 |
nextSec = NULL; |
| 1008 |
if (sec->lightlevel) |
| 1009 |
{ |
| 1010 |
base = sec->lightlevel; |
| 1011 |
} |
| 1012 |
P_SpawnPhasedLight(sec, base, index >> FRACBITS); |
| 1013 |
index += indexDelta; |
| 1014 |
for (i = 0; i < sec->linecount; i++) |
| 1015 |
{ |
| 1016 |
tempSec = getNextSector(sec->lines[i], sec); |
| 1017 |
if (!tempSec) |
| 1018 |
{ |
| 1019 |
continue; |
| 1020 |
} |
| 1021 |
if (tempSec->special == LIGHT_SEQUENCE_START) |
| 1022 |
{ |
| 1023 |
nextSec = tempSec; |
| 1024 |
} |
| 1025 |
} |
| 1026 |
sec = nextSec; |
| 1027 |
} |
| 1028 |
while (sec); |
| 1029 |
} |