2016-03-01 15:47:10 +00:00
|
|
|
// Emacs style mode select -*- C++ -*-
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// $Id:$
|
|
|
|
//
|
|
|
|
// Copyright (C) 1993-1996 by id Software, Inc.
|
|
|
|
//
|
|
|
|
// This source is available for distribution and/or modification
|
|
|
|
// only under the terms of the DOOM Source Code License as
|
|
|
|
// published by id Software. All rights reserved.
|
|
|
|
//
|
|
|
|
// The source is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
|
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
// $Log:$
|
|
|
|
//
|
|
|
|
// DESCRIPTION:
|
|
|
|
// Handle Sector base lighting effects.
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
#include "templates.h"
|
|
|
|
#include "m_random.h"
|
|
|
|
|
|
|
|
#include "doomdef.h"
|
|
|
|
#include "p_local.h"
|
|
|
|
#include "p_spec.h"
|
|
|
|
|
|
|
|
#include "p_lnspec.h"
|
|
|
|
#include "doomstat.h"
|
2016-12-20 17:26:33 +00:00
|
|
|
#include "p_maputl.h"
|
2017-01-08 17:45:30 +00:00
|
|
|
#include "g_levellocals.h"
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
// State.
|
|
|
|
#include "r_state.h"
|
|
|
|
#include "statnums.h"
|
2016-09-19 17:14:30 +00:00
|
|
|
#include "serializer.h"
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
static FRandom pr_flicker ("Flicker");
|
|
|
|
static FRandom pr_lightflash ("LightFlash");
|
|
|
|
static FRandom pr_strobeflash ("StrobeFlash");
|
|
|
|
static FRandom pr_fireflicker ("FireFlicker");
|
|
|
|
|
2016-04-10 16:29:23 +00:00
|
|
|
|
|
|
|
class DFireFlicker : public DLighting
|
|
|
|
{
|
|
|
|
DECLARE_CLASS(DFireFlicker, DLighting)
|
|
|
|
public:
|
|
|
|
DFireFlicker(sector_t *sector);
|
|
|
|
DFireFlicker(sector_t *sector, int upper, int lower);
|
2016-09-19 17:14:30 +00:00
|
|
|
void Serialize(FSerializer &arc);
|
2016-04-10 16:29:23 +00:00
|
|
|
void Tick();
|
|
|
|
protected:
|
|
|
|
int m_Count;
|
|
|
|
int m_MaxLight;
|
|
|
|
int m_MinLight;
|
|
|
|
private:
|
|
|
|
DFireFlicker();
|
|
|
|
};
|
|
|
|
|
|
|
|
class DFlicker : public DLighting
|
|
|
|
{
|
|
|
|
DECLARE_CLASS(DFlicker, DLighting)
|
|
|
|
public:
|
|
|
|
DFlicker(sector_t *sector, int upper, int lower);
|
2016-09-19 17:14:30 +00:00
|
|
|
void Serialize(FSerializer &arc);
|
2016-04-10 16:29:23 +00:00
|
|
|
void Tick();
|
|
|
|
protected:
|
|
|
|
int m_Count;
|
|
|
|
int m_MaxLight;
|
|
|
|
int m_MinLight;
|
|
|
|
private:
|
|
|
|
DFlicker();
|
|
|
|
};
|
|
|
|
|
|
|
|
class DLightFlash : public DLighting
|
|
|
|
{
|
|
|
|
DECLARE_CLASS(DLightFlash, DLighting)
|
|
|
|
public:
|
|
|
|
DLightFlash(sector_t *sector);
|
|
|
|
DLightFlash(sector_t *sector, int min, int max);
|
2016-09-19 17:14:30 +00:00
|
|
|
void Serialize(FSerializer &arc);
|
2016-04-10 16:29:23 +00:00
|
|
|
void Tick();
|
|
|
|
protected:
|
|
|
|
int m_Count;
|
|
|
|
int m_MaxLight;
|
|
|
|
int m_MinLight;
|
|
|
|
int m_MaxTime;
|
|
|
|
int m_MinTime;
|
|
|
|
private:
|
|
|
|
DLightFlash();
|
|
|
|
};
|
|
|
|
|
|
|
|
class DStrobe : public DLighting
|
|
|
|
{
|
|
|
|
DECLARE_CLASS(DStrobe, DLighting)
|
|
|
|
public:
|
|
|
|
DStrobe(sector_t *sector, int utics, int ltics, bool inSync);
|
|
|
|
DStrobe(sector_t *sector, int upper, int lower, int utics, int ltics);
|
2016-09-19 17:14:30 +00:00
|
|
|
void Serialize(FSerializer &arc);
|
2016-04-10 16:29:23 +00:00
|
|
|
void Tick();
|
|
|
|
protected:
|
|
|
|
int m_Count;
|
|
|
|
int m_MinLight;
|
|
|
|
int m_MaxLight;
|
|
|
|
int m_DarkTime;
|
|
|
|
int m_BrightTime;
|
|
|
|
private:
|
|
|
|
DStrobe();
|
|
|
|
};
|
|
|
|
|
|
|
|
class DGlow : public DLighting
|
|
|
|
{
|
|
|
|
DECLARE_CLASS(DGlow, DLighting)
|
|
|
|
public:
|
|
|
|
DGlow(sector_t *sector);
|
2016-09-19 17:14:30 +00:00
|
|
|
void Serialize(FSerializer &arc);
|
2016-04-10 16:29:23 +00:00
|
|
|
void Tick();
|
|
|
|
protected:
|
|
|
|
int m_MinLight;
|
|
|
|
int m_MaxLight;
|
|
|
|
int m_Direction;
|
|
|
|
private:
|
|
|
|
DGlow();
|
|
|
|
};
|
|
|
|
|
|
|
|
// [RH] Glow from Light_Glow and Light_Fade specials
|
|
|
|
class DGlow2 : public DLighting
|
|
|
|
{
|
|
|
|
DECLARE_CLASS(DGlow2, DLighting)
|
|
|
|
public:
|
|
|
|
DGlow2(sector_t *sector, int start, int end, int tics, bool oneshot);
|
2016-09-19 17:14:30 +00:00
|
|
|
void Serialize(FSerializer &arc);
|
2016-04-10 16:29:23 +00:00
|
|
|
void Tick();
|
|
|
|
protected:
|
|
|
|
int m_Start;
|
|
|
|
int m_End;
|
|
|
|
int m_MaxTics;
|
|
|
|
int m_Tics;
|
|
|
|
bool m_OneShot;
|
|
|
|
private:
|
|
|
|
DGlow2();
|
|
|
|
};
|
|
|
|
|
|
|
|
// [RH] Phased light thinker
|
|
|
|
class DPhased : public DLighting
|
|
|
|
{
|
|
|
|
DECLARE_CLASS(DPhased, DLighting)
|
|
|
|
public:
|
|
|
|
DPhased(sector_t *sector);
|
|
|
|
DPhased(sector_t *sector, int baselevel, int phase);
|
2016-09-19 17:14:30 +00:00
|
|
|
void Serialize(FSerializer &arc);
|
2016-04-10 16:29:23 +00:00
|
|
|
void Tick();
|
|
|
|
protected:
|
|
|
|
BYTE m_BaseLevel;
|
|
|
|
BYTE m_Phase;
|
|
|
|
private:
|
|
|
|
DPhased();
|
|
|
|
DPhased(sector_t *sector, int baselevel);
|
|
|
|
int PhaseHelper(sector_t *sector, int index, int light, sector_t *prev);
|
|
|
|
};
|
|
|
|
|
|
|
|
#define GLOWSPEED 8
|
|
|
|
#define STROBEBRIGHT 5
|
|
|
|
#define FASTDARK 15
|
|
|
|
#define SLOWDARK TICRATE
|
|
|
|
|
|
|
|
|
2016-03-01 15:47:10 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-11-24 20:36:02 +00:00
|
|
|
IMPLEMENT_CLASS(DLighting, false, false)
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
DLighting::DLighting ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
DLighting::DLighting (sector_t *sector)
|
|
|
|
: DSectorEffect (sector)
|
|
|
|
{
|
|
|
|
ChangeStatNum (STAT_LIGHT);
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// FIRELIGHT FLICKER
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-11-24 20:36:02 +00:00
|
|
|
IMPLEMENT_CLASS(DFireFlicker, false, false)
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
DFireFlicker::DFireFlicker ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-09-19 17:14:30 +00:00
|
|
|
void DFireFlicker::Serialize(FSerializer &arc)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
Super::Serialize (arc);
|
2016-09-19 17:14:30 +00:00
|
|
|
arc("count", m_Count)
|
|
|
|
("maxlight", m_MaxLight)
|
|
|
|
("minlight", m_MinLight);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// T_FireFlicker
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void DFireFlicker::Tick ()
|
|
|
|
{
|
|
|
|
int amount;
|
|
|
|
|
|
|
|
if (--m_Count == 0)
|
|
|
|
{
|
|
|
|
amount = (pr_fireflicker() & 3) << 4;
|
|
|
|
|
|
|
|
// [RH] Shouldn't this be (m_MaxLight - amount < m_MinLight)?
|
|
|
|
if (m_Sector->lightlevel - amount < m_MinLight)
|
|
|
|
m_Sector->SetLightLevel(m_MinLight);
|
|
|
|
else
|
|
|
|
m_Sector->SetLightLevel(m_MaxLight - amount);
|
|
|
|
|
|
|
|
m_Count = 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// P_SpawnFireFlicker
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
DFireFlicker::DFireFlicker (sector_t *sector)
|
|
|
|
: DLighting (sector)
|
|
|
|
{
|
|
|
|
m_MaxLight = sector->lightlevel;
|
|
|
|
m_MinLight = sector_t::ClampLight(sector->FindMinSurroundingLight(sector->lightlevel) + 16);
|
|
|
|
m_Count = 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
DFireFlicker::DFireFlicker (sector_t *sector, int upper, int lower)
|
|
|
|
: DLighting (sector)
|
|
|
|
{
|
|
|
|
m_MaxLight = sector_t::ClampLight(upper);
|
|
|
|
m_MinLight = sector_t::ClampLight(lower);
|
|
|
|
m_Count = 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// [RH] flickering light like Hexen's
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-11-24 20:36:02 +00:00
|
|
|
IMPLEMENT_CLASS(DFlicker, false, false)
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
DFlicker::DFlicker ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-09-19 17:14:30 +00:00
|
|
|
void DFlicker::Serialize(FSerializer &arc)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
Super::Serialize (arc);
|
2016-09-19 17:14:30 +00:00
|
|
|
arc("count", m_Count)
|
|
|
|
("maxlight", m_MaxLight)
|
|
|
|
("minlight", m_MinLight);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void DFlicker::Tick ()
|
|
|
|
{
|
|
|
|
if (m_Count)
|
|
|
|
{
|
|
|
|
m_Count--;
|
|
|
|
}
|
|
|
|
else if (m_Sector->lightlevel == m_MaxLight)
|
|
|
|
{
|
|
|
|
m_Sector->SetLightLevel(m_MinLight);
|
|
|
|
m_Count = (pr_flicker()&7)+1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_Sector->SetLightLevel(m_MaxLight);
|
|
|
|
m_Count = (pr_flicker()&31)+1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
DFlicker::DFlicker (sector_t *sector, int upper, int lower)
|
|
|
|
: DLighting (sector)
|
|
|
|
{
|
2016-05-04 18:33:17 +00:00
|
|
|
m_MaxLight = sector_t::ClampLight(upper);
|
|
|
|
m_MinLight = sector_t::ClampLight(lower);
|
|
|
|
sector->lightlevel = m_MaxLight;
|
2016-03-01 15:47:10 +00:00
|
|
|
m_Count = (pr_flicker()&64)+1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void EV_StartLightFlickering (int tag, int upper, int lower)
|
|
|
|
{
|
|
|
|
int secnum;
|
|
|
|
FSectorTagIterator it(tag);
|
|
|
|
while ((secnum = it.Next()) >= 0)
|
|
|
|
{
|
2017-01-07 18:32:24 +00:00
|
|
|
new DFlicker (&level.sectors[secnum], upper, lower);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// BROKEN LIGHT FLASHING
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-11-24 20:36:02 +00:00
|
|
|
IMPLEMENT_CLASS(DLightFlash, false, false)
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
DLightFlash::DLightFlash ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-09-19 17:14:30 +00:00
|
|
|
void DLightFlash::Serialize(FSerializer &arc)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
Super::Serialize (arc);
|
2016-09-19 17:14:30 +00:00
|
|
|
arc("count", m_Count)
|
|
|
|
("maxlight", m_MaxLight)
|
|
|
|
("minlight", m_MinLight)
|
|
|
|
("maxtime", m_MaxTime)
|
|
|
|
("mintime", m_MinTime);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// T_LightFlash
|
|
|
|
// Do flashing lights.
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void DLightFlash::Tick ()
|
|
|
|
{
|
|
|
|
if (--m_Count == 0)
|
|
|
|
{
|
|
|
|
if (m_Sector->lightlevel == m_MaxLight)
|
|
|
|
{
|
|
|
|
m_Sector->SetLightLevel(m_MinLight);
|
|
|
|
m_Count = (pr_lightflash() & m_MinTime) + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_Sector->SetLightLevel(m_MaxLight);
|
|
|
|
m_Count = (pr_lightflash() & m_MaxTime) + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// P_SpawnLightFlash
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
DLightFlash::DLightFlash (sector_t *sector)
|
|
|
|
: DLighting (sector)
|
|
|
|
{
|
|
|
|
// Find light levels like Doom.
|
|
|
|
m_MaxLight = sector->lightlevel;
|
|
|
|
m_MinLight = sector->FindMinSurroundingLight (sector->lightlevel);
|
|
|
|
m_MaxTime = 64;
|
|
|
|
m_MinTime = 7;
|
|
|
|
m_Count = (pr_lightflash() & m_MaxTime) + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
DLightFlash::DLightFlash (sector_t *sector, int min, int max)
|
|
|
|
: DLighting (sector)
|
|
|
|
{
|
|
|
|
// Use specified light levels.
|
|
|
|
m_MaxLight = sector_t::ClampLight(max);
|
|
|
|
m_MinLight = sector_t::ClampLight(min);
|
|
|
|
m_MaxTime = 64;
|
|
|
|
m_MinTime = 7;
|
|
|
|
m_Count = (pr_lightflash() & m_MaxTime) + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// STROBE LIGHT FLASHING
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-11-24 20:36:02 +00:00
|
|
|
IMPLEMENT_CLASS(DStrobe, false, false)
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
DStrobe::DStrobe ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-09-19 17:14:30 +00:00
|
|
|
void DStrobe::Serialize(FSerializer &arc)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
Super::Serialize (arc);
|
2016-09-19 17:14:30 +00:00
|
|
|
arc("count", m_Count)
|
|
|
|
("maxlight", m_MaxLight)
|
|
|
|
("minlight", m_MinLight)
|
|
|
|
("darktime", m_DarkTime)
|
|
|
|
("brighttime", m_BrightTime);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// T_StrobeFlash
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void DStrobe::Tick ()
|
|
|
|
{
|
|
|
|
if (--m_Count == 0)
|
|
|
|
{
|
|
|
|
if (m_Sector->lightlevel == m_MinLight)
|
|
|
|
{
|
|
|
|
m_Sector->SetLightLevel(m_MaxLight);
|
|
|
|
m_Count = m_BrightTime;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_Sector->SetLightLevel(m_MinLight);
|
|
|
|
m_Count = m_DarkTime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Hexen-style constructor
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
DStrobe::DStrobe (sector_t *sector, int upper, int lower, int utics, int ltics)
|
|
|
|
: DLighting (sector)
|
|
|
|
{
|
|
|
|
m_DarkTime = ltics;
|
|
|
|
m_BrightTime = utics;
|
|
|
|
m_MaxLight = sector_t::ClampLight(upper);
|
|
|
|
m_MinLight = sector_t::ClampLight(lower);
|
|
|
|
m_Count = 1; // Hexen-style is always in sync
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Doom-style constructor
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
DStrobe::DStrobe (sector_t *sector, int utics, int ltics, bool inSync)
|
|
|
|
: DLighting (sector)
|
|
|
|
{
|
|
|
|
m_DarkTime = ltics;
|
|
|
|
m_BrightTime = utics;
|
|
|
|
|
|
|
|
m_MaxLight = sector->lightlevel;
|
|
|
|
m_MinLight = sector->FindMinSurroundingLight (sector->lightlevel);
|
|
|
|
|
|
|
|
if (m_MinLight == m_MaxLight)
|
|
|
|
m_MinLight = 0;
|
|
|
|
|
|
|
|
m_Count = inSync ? 1 : (pr_strobeflash() & 7) + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Start strobing lights (usually from a trigger)
|
|
|
|
// [RH] Made it more configurable.
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void EV_StartLightStrobing (int tag, int upper, int lower, int utics, int ltics)
|
|
|
|
{
|
|
|
|
int secnum;
|
|
|
|
FSectorTagIterator it(tag);
|
|
|
|
while ((secnum = it.Next()) >= 0)
|
|
|
|
{
|
2017-01-07 18:32:24 +00:00
|
|
|
sector_t *sec = &level.sectors[secnum];
|
2016-03-01 15:47:10 +00:00
|
|
|
if (sec->lightingdata)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
new DStrobe (sec, upper, lower, utics, ltics);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EV_StartLightStrobing (int tag, int utics, int ltics)
|
|
|
|
{
|
|
|
|
int secnum;
|
|
|
|
FSectorTagIterator it(tag);
|
|
|
|
while ((secnum = it.Next()) >= 0)
|
|
|
|
{
|
2017-01-07 18:32:24 +00:00
|
|
|
sector_t *sec = &level.sectors[secnum];
|
2016-03-01 15:47:10 +00:00
|
|
|
if (sec->lightingdata)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
new DStrobe (sec, utics, ltics, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TURN LINE'S TAG LIGHTS OFF
|
|
|
|
// [RH] Takes a tag instead of a line
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void EV_TurnTagLightsOff (int tag)
|
|
|
|
{
|
|
|
|
int secnum;
|
|
|
|
FSectorTagIterator it(tag);
|
|
|
|
while ((secnum = it.Next()) >= 0)
|
|
|
|
{
|
2017-01-07 18:32:24 +00:00
|
|
|
sector_t *sector = &level.sectors[secnum];
|
2016-03-01 15:47:10 +00:00
|
|
|
int min = sector->lightlevel;
|
|
|
|
|
2017-01-02 20:40:52 +00:00
|
|
|
for (auto ln : sector->Lines)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2017-01-02 20:40:52 +00:00
|
|
|
sector_t *tsec = getNextSector (ln, sector);
|
2016-03-01 15:47:10 +00:00
|
|
|
if (!tsec)
|
|
|
|
continue;
|
|
|
|
if (tsec->lightlevel < min)
|
|
|
|
min = tsec->lightlevel;
|
|
|
|
}
|
|
|
|
sector->SetLightLevel(min);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TURN LINE'S TAG LIGHTS ON
|
|
|
|
// [RH] Takes a tag instead of a line
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void EV_LightTurnOn (int tag, int bright)
|
|
|
|
{
|
|
|
|
int secnum;
|
|
|
|
FSectorTagIterator it(tag);
|
|
|
|
while ((secnum = it.Next()) >= 0)
|
|
|
|
{
|
2017-01-07 18:32:24 +00:00
|
|
|
sector_t *sector = &level.sectors[secnum];
|
2016-03-01 15:47:10 +00:00
|
|
|
int tbright = bright; //jff 5/17/98 search for maximum PER sector
|
|
|
|
|
|
|
|
// bright = -1 means to search ([RH] Not 0)
|
|
|
|
// for highest light level
|
|
|
|
// surrounding sector
|
|
|
|
if (bright < 0)
|
|
|
|
{
|
2017-01-02 20:40:52 +00:00
|
|
|
for (auto ln : sector->Lines)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2017-01-02 20:40:52 +00:00
|
|
|
sector_t *temp = getNextSector(ln, sector);
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
if (!temp)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (temp->lightlevel > tbright)
|
|
|
|
tbright = temp->lightlevel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sector->SetLightLevel(tbright);
|
|
|
|
|
|
|
|
//jff 5/17/98 unless compatibility optioned
|
|
|
|
//then maximum near ANY tagged sector
|
|
|
|
if (i_compatflags & COMPATF_LIGHT)
|
|
|
|
{
|
|
|
|
bright = tbright;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// killough 10/98
|
|
|
|
//
|
|
|
|
// EV_LightTurnOnPartway
|
|
|
|
//
|
|
|
|
// Turn sectors tagged to line lights on to specified or max neighbor level
|
|
|
|
//
|
|
|
|
// Passed the tag of sector(s) to light and a light level fraction between 0 and 1.
|
|
|
|
// Sets the light to min on 0, max on 1, and interpolates in-between.
|
|
|
|
// Used for doors with gradual lighting effects.
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-03-26 22:19:38 +00:00
|
|
|
void EV_LightTurnOnPartway (int tag, double frac)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2016-03-26 22:19:38 +00:00
|
|
|
frac = clamp(frac, 0., 1.);
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
// Search all sectors for ones with same tag as activating line
|
|
|
|
int secnum;
|
|
|
|
FSectorTagIterator it(tag);
|
|
|
|
while ((secnum = it.Next()) >= 0)
|
|
|
|
{
|
2017-01-07 18:32:24 +00:00
|
|
|
sector_t *temp, *sector = &level.sectors[secnum];
|
2017-01-02 20:40:52 +00:00
|
|
|
int bright = 0, min = sector->lightlevel;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2017-01-02 20:40:52 +00:00
|
|
|
for (auto ln : sector->Lines)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2017-01-02 20:40:52 +00:00
|
|
|
if ((temp = getNextSector (ln, sector)) != nullptr)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
if (temp->lightlevel > bright)
|
|
|
|
{
|
|
|
|
bright = temp->lightlevel;
|
|
|
|
}
|
|
|
|
if (temp->lightlevel < min)
|
|
|
|
{
|
|
|
|
min = temp->lightlevel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-03-26 22:19:38 +00:00
|
|
|
sector->SetLightLevel(int(frac * bright + (1 - frac) * min));
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// [RH] New function to adjust tagged sectors' light levels
|
|
|
|
// by a relative amount. Light levels are clipped to
|
|
|
|
// be within range for sector_t::lightlevel.
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void EV_LightChange (int tag, int value)
|
|
|
|
{
|
|
|
|
int secnum;
|
|
|
|
FSectorTagIterator it(tag);
|
|
|
|
while ((secnum = it.Next()) >= 0)
|
|
|
|
{
|
2017-01-07 18:32:24 +00:00
|
|
|
level.sectors[secnum].SetLightLevel(level.sectors[secnum].lightlevel + value);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Spawn glowing light
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-11-24 20:36:02 +00:00
|
|
|
IMPLEMENT_CLASS(DGlow, false, false)
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
DGlow::DGlow ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-09-19 17:14:30 +00:00
|
|
|
void DGlow::Serialize(FSerializer &arc)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
Super::Serialize (arc);
|
2016-09-19 17:14:30 +00:00
|
|
|
arc("direction", m_Direction)
|
|
|
|
("maxlight", m_MaxLight)
|
|
|
|
("minlight", m_MinLight);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void DGlow::Tick ()
|
|
|
|
{
|
|
|
|
int newlight = m_Sector->lightlevel;
|
|
|
|
|
|
|
|
switch (m_Direction)
|
|
|
|
{
|
|
|
|
case -1:
|
|
|
|
// DOWN
|
|
|
|
newlight -= GLOWSPEED;
|
|
|
|
if (newlight <= m_MinLight)
|
|
|
|
{
|
|
|
|
newlight += GLOWSPEED;
|
|
|
|
m_Direction = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
// UP
|
|
|
|
newlight += GLOWSPEED;
|
|
|
|
if (newlight >= m_MaxLight)
|
|
|
|
{
|
|
|
|
newlight -= GLOWSPEED;
|
|
|
|
m_Direction = -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
m_Sector->SetLightLevel(newlight);
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
DGlow::DGlow (sector_t *sector)
|
|
|
|
: DLighting (sector)
|
|
|
|
{
|
|
|
|
m_MinLight = sector->FindMinSurroundingLight (sector->lightlevel);
|
|
|
|
m_MaxLight = sector->lightlevel;
|
|
|
|
m_Direction = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// [RH] More glowing light, this time appropriate for Hexen-ish uses.
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-11-24 20:36:02 +00:00
|
|
|
IMPLEMENT_CLASS(DGlow2, false, false)
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
DGlow2::DGlow2 ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-09-19 17:14:30 +00:00
|
|
|
void DGlow2::Serialize(FSerializer &arc)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
Super::Serialize (arc);
|
2016-09-19 17:14:30 +00:00
|
|
|
arc("end", m_End)
|
|
|
|
("maxtics", m_MaxTics)
|
|
|
|
("oneshot", m_OneShot)
|
|
|
|
("start", m_Start)
|
|
|
|
("tics", m_Tics);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void DGlow2::Tick ()
|
|
|
|
{
|
|
|
|
if (m_Tics++ >= m_MaxTics)
|
|
|
|
{
|
|
|
|
if (m_OneShot)
|
|
|
|
{
|
|
|
|
m_Sector->SetLightLevel(m_End);
|
|
|
|
Destroy ();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int temp = m_Start;
|
|
|
|
m_Start = m_End;
|
|
|
|
m_End = temp;
|
|
|
|
m_Tics -= m_MaxTics;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_Sector->SetLightLevel(((m_End - m_Start) * m_Tics) / m_MaxTics + m_Start);
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
DGlow2::DGlow2 (sector_t *sector, int start, int end, int tics, bool oneshot)
|
|
|
|
: DLighting (sector)
|
|
|
|
{
|
|
|
|
m_Start = sector_t::ClampLight(start);
|
|
|
|
m_End = sector_t::ClampLight(end);
|
|
|
|
m_MaxTics = tics;
|
|
|
|
m_Tics = -1;
|
|
|
|
m_OneShot = oneshot;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void EV_StartLightGlowing (int tag, int upper, int lower, int tics)
|
|
|
|
{
|
|
|
|
int secnum;
|
|
|
|
|
|
|
|
// If tics is non-positive, then we can't really do anything.
|
|
|
|
if (tics <= 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (upper < lower)
|
|
|
|
{
|
|
|
|
int temp = upper;
|
|
|
|
upper = lower;
|
|
|
|
lower = temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
FSectorTagIterator it(tag);
|
|
|
|
while ((secnum = it.Next()) >= 0)
|
|
|
|
{
|
2017-01-07 18:32:24 +00:00
|
|
|
sector_t *sec = &level.sectors[secnum];
|
2016-03-01 15:47:10 +00:00
|
|
|
if (sec->lightingdata)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
new DGlow2 (sec, upper, lower, tics, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void EV_StartLightFading (int tag, int value, int tics)
|
|
|
|
{
|
|
|
|
int secnum;
|
|
|
|
FSectorTagIterator it(tag);
|
|
|
|
while ((secnum = it.Next()) >= 0)
|
|
|
|
{
|
2017-01-07 18:32:24 +00:00
|
|
|
sector_t *sec = &level.sectors[secnum];
|
2016-03-01 15:47:10 +00:00
|
|
|
if (sec->lightingdata)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (tics <= 0)
|
|
|
|
{
|
|
|
|
sec->SetLightLevel(value);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// No need to fade if lightlevel is already at desired value.
|
|
|
|
if (sec->lightlevel == value)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
new DGlow2 (sec, sec->lightlevel, value, tics, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// [RH] Phased lighting ala Hexen, but implemented without the help of the Hexen source
|
|
|
|
// The effect is a little different, but close enough, I feel.
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-11-24 20:36:02 +00:00
|
|
|
IMPLEMENT_CLASS(DPhased, false, false)
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
DPhased::DPhased ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-09-19 17:14:30 +00:00
|
|
|
void DPhased::Serialize(FSerializer &arc)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
Super::Serialize (arc);
|
2016-09-19 17:14:30 +00:00
|
|
|
arc("baselevel", m_BaseLevel)
|
|
|
|
("phase", m_Phase);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void DPhased::Tick ()
|
|
|
|
{
|
|
|
|
const int steps = 12;
|
|
|
|
|
|
|
|
if (m_Phase < steps)
|
|
|
|
m_Sector->SetLightLevel( ((255 - m_BaseLevel) * m_Phase) / steps + m_BaseLevel);
|
|
|
|
else if (m_Phase < 2*steps)
|
|
|
|
m_Sector->SetLightLevel( ((255 - m_BaseLevel) * (2*steps - m_Phase - 1) / steps
|
|
|
|
+ m_BaseLevel));
|
|
|
|
else
|
|
|
|
m_Sector->SetLightLevel(m_BaseLevel);
|
|
|
|
|
|
|
|
if (m_Phase == 0)
|
|
|
|
m_Phase = 63;
|
|
|
|
else
|
|
|
|
m_Phase--;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
int DPhased::PhaseHelper (sector_t *sector, int index, int light, sector_t *prev)
|
|
|
|
{
|
2016-12-20 17:26:33 +00:00
|
|
|
if (!sector || sector->validcount == validcount)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DPhased *l;
|
|
|
|
int baselevel = sector->lightlevel ? sector->lightlevel : light;
|
2016-12-20 17:26:33 +00:00
|
|
|
sector->validcount = validcount;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
if (index == 0)
|
|
|
|
{
|
|
|
|
l = this;
|
|
|
|
m_BaseLevel = baselevel;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
l = new DPhased (sector, baselevel);
|
|
|
|
|
|
|
|
int numsteps = PhaseHelper (sector->NextSpecialSector (
|
|
|
|
sector->special == LightSequenceSpecial1 ?
|
|
|
|
LightSequenceSpecial2 : LightSequenceSpecial1, prev),
|
|
|
|
index + 1, l->m_BaseLevel, sector);
|
|
|
|
l->m_Phase = ((numsteps - index - 1) * 64) / numsteps;
|
|
|
|
|
|
|
|
sector->special = 0;
|
|
|
|
|
|
|
|
return numsteps;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
DPhased::DPhased (sector_t *sector, int baselevel)
|
|
|
|
: DLighting (sector)
|
|
|
|
{
|
|
|
|
m_BaseLevel = baselevel;
|
|
|
|
}
|
|
|
|
|
|
|
|
DPhased::DPhased (sector_t *sector)
|
|
|
|
: DLighting (sector)
|
|
|
|
{
|
2016-12-20 17:26:33 +00:00
|
|
|
validcount++;
|
2016-03-01 15:47:10 +00:00
|
|
|
PhaseHelper (sector, 0, 0, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
DPhased::DPhased (sector_t *sector, int baselevel, int phase)
|
|
|
|
: DLighting (sector)
|
|
|
|
{
|
|
|
|
m_BaseLevel = baselevel;
|
|
|
|
m_Phase = phase;
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
//
|
|
|
|
// EV_StopLightEffect
|
|
|
|
//
|
|
|
|
// Stops a lighting effect that is currently running in a sector.
|
|
|
|
//
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
void EV_StopLightEffect (int tag)
|
|
|
|
{
|
|
|
|
TThinkerIterator<DLighting> iterator;
|
|
|
|
DLighting *effect;
|
|
|
|
|
|
|
|
while ((effect = iterator.Next()) != NULL)
|
|
|
|
{
|
|
|
|
if (tagManager.SectorHasTag(effect->GetSector(), tag))
|
|
|
|
{
|
|
|
|
effect->Destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-04-10 16:29:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
void P_SpawnLights(sector_t *sector)
|
|
|
|
{
|
|
|
|
switch (sector->special)
|
|
|
|
{
|
|
|
|
case Light_Phased:
|
|
|
|
new DPhased(sector, 48, 63 - (sector->lightlevel & 63));
|
|
|
|
break;
|
|
|
|
|
|
|
|
// [RH] Hexen-like phased lighting
|
|
|
|
case LightSequenceStart:
|
|
|
|
new DPhased(sector);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case dLight_Flicker:
|
|
|
|
new DLightFlash(sector);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case dLight_StrobeFast:
|
|
|
|
new DStrobe(sector, STROBEBRIGHT, FASTDARK, false);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case dLight_StrobeSlow:
|
|
|
|
new DStrobe(sector, STROBEBRIGHT, SLOWDARK, false);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case dLight_Strobe_Hurt:
|
|
|
|
new DStrobe(sector, STROBEBRIGHT, FASTDARK, false);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case dLight_Glow:
|
|
|
|
new DGlow(sector);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case dLight_StrobeSlowSync:
|
|
|
|
new DStrobe(sector, STROBEBRIGHT, SLOWDARK, true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case dLight_StrobeFastSync:
|
|
|
|
new DStrobe(sector, STROBEBRIGHT, FASTDARK, true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case dLight_FireFlicker:
|
|
|
|
new DFireFlicker(sector);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case dScroll_EastLavaDamage:
|
|
|
|
new DStrobe(sector, STROBEBRIGHT, FASTDARK, false);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case sLight_Strobe_Hurt:
|
|
|
|
new DStrobe(sector, STROBEBRIGHT, FASTDARK, false);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|