djcev.com

//

Git Repos / fte_dogmode / qc / misc / lights.qc

Last update to this file was on 2024-03-24 at 02:40.

Show lights.qc

//==============================================================================
// lights.qc taken from c0burn's Slipgate mod -- dumptruck_ds
//==============================================================================

//======================================================================
// constants
//======================================================================

const float LIGHT_START_OFF = 1;
const float LIGHT_FADE_IN_OUT = 2;
const float LIGHT_SILENT_TORCH = 4; // for silent torch -- dumptruck_ds

const float LIGHT_THINK_FADE_IN = 1;
const float LIGHT_THINK_FADE_OUT = 2;

//======================================================================
// forward declarations
//======================================================================

string(float num) lightstyle_lookup;
void() setup_lightstyles;
string(float num) lightstyle_fade_lookup;

// base_light
void() base_light_think_fade_in;
void() base_light_think_fade_out;
void() base_light_use;
void(entity e) base_light_init;
strip void() base_light;

// light
void(entity e) light_init;
void() light;

// light_fluoro
void(entity e) light_fluoro_init;
void() light_fluoro;

// light_fluorospark
void(entity e) light_fluorospark_init;
void() light_fluorospark;

// light_globe
void(entity e) light_globe_init;
void() light_globe;

// light_torch_small_walltorch
void(entity e) light_torch_small_walltorch_init;
void() light_torch_small_walltorch;

// light_flame_large_yellow
void(entity e) light_flame_large_yellow_init;
void() light_flame_large_yellow;

// light_flame_small_yellow
void(entity e) light_flame_small_yellow_init;
void() light_flame_small_yellow;

// light_flame_small_white
void(entity e) light_flame_small_white_init;
void() light_flame_small_white;

// light_sprite_flame
void(entity e) light_sprite_flame_init;
void() light_sprite_flame;

//------------------------------------------------------------------------------

//----------------------------------------------------------------------
// lightstyle_lookup
//----------------------------------------------------------------------
string(float num) lightstyle_lookup =
{
switch (num)
{
case 0:
// 0 normal
return "m";
case 1:
// 1 FLICKER (first variety)
return "mmnmmommommnonmmonqnmmo";
case 2:
// 2 SLOW STRONG PULSE
return "abcdefghijklmnopqrstuvwxyz"
"yxwvutsrqponmlkjihgfedcba";
case 3:
// 3 CANDLE (first variety)
return "mmmmmaaaaammmmmaaaaaabcdefgabcdefg";
case 4:
// 4 FAST STROBE
return "mamamamamama";
case 5:
// 5 GENTLE PULSE 1
return "jklmnopqrstuvwxyzyxwvutsrqponmlkj";
case 6:
// 6 FLICKER (second variety)
return "nmonqnmomnmomomno";
case 7:
// 7 CANDLE (second variety)
return "mmmaaaabcdefgmmmmaaaammmaamm";
case 8:
// 8 CANDLE (third variety)
return "mmmaaammmaaammmabcdefaaaammmmabcdefmmmaaaa";
case 9:
// 9 SLOW STROBE (fourth variety)
return "aaaaaaaazzzzzzzz";
case 10:
// 10 FLUORESCENT FLICKER
return "mmamammmmammamamaaamammma";
case 11:
// 11 SLOW PULSE NOT FADE TO BLACK
return "abcdefghijklmnopqrrqponmlkjihgfedcba";
case 12:
// 12 BLINK OFF / ON (can be synced with animated
// textures, e.g. +0light and +1light)
// textures animate at 5fps but lights are
// 10fps...
return "aamm";
default:
// DEFAULT
return "a";
}
};

//----------------------------------------------------------------------
// setup_lightstyles
// Setup light animation tables. 'a' is total darkness, 'z' is maxbright.
// Styles 32+ are assigned by the light program for switchable lights.
//----------------------------------------------------------------------
void() setup_lightstyles =
{
for (float i = 0; i <= 12; i++)
{
lightstyle (i, lightstyle_lookup(i));
}
};

//----------------------------------------------------------------------
// lightstyle_fade_lookup
//----------------------------------------------------------------------
string(float num) lightstyle_fade_lookup =
{
switch (num)
{
case 0:
return "a";
case 1:
return "b";
case 2:
return "c";
case 3:
return "d";
case 4:
return "e";
case 5:
return "f";
case 6:
return "g";
case 7:
return "h";
case 8:
return "i";
case 9:
return "j";
case 10:
return "k";
case 11:
return "l";
case 12:
return "m";
default:
error ("count out of range\n");
break;
}
};

//----------------------------------------------------------------------
// class base_light: base_mapentity
// {
//--------------------------------------------------------------
void() base_light_think_fade_in =
{
if (self.count < 0)
self.count = 0;
if (self.count > 12)
self.count = 12;

lightstyle (self.style, lightstyle_fade_lookup(self.count));

self.count = self.count + 1;
if (self.count > 12)
return;

self.think = base_light_think_fade_in;
self.nextthink = time + self.speed;
};

//--------------------------------------------------------------
void() base_light_think_fade_out =
{
// light_fade_out
if (self.count < 0)
self.count = 0;
if (self.count > 12)
self.count = 12;

lightstyle (self.style, lightstyle_fade_lookup(self.count));

self.count = self.count - 1;
if (self.count < 0)
return;

self.think = base_light_think_fade_out;
self.nextthink = time + self.speed;
};

//--------------------------------------------------------------
// light_use -- using a light will turn it on and off
//--------------------------------------------------------------
void() base_light_use =
{
if (self.spawnflags & LIGHT_START_OFF)
{
self.spawnflags = self.spawnflags - LIGHT_START_OFF;

if (self.spawnflags & LIGHT_FADE_IN_OUT && !self.style2)
base_light_think_fade_in ();
else
lightstyle (self.style,
lightstyle_lookup(self.style2));
}
else
{
self.spawnflags = self.spawnflags + LIGHT_START_OFF;

if (self.spawnflags & LIGHT_FADE_IN_OUT && !self.style2)
base_light_think_fade_out ();
else
lightstyle (self.style, "a");
}
};

//--------------------------------------------------------------
void(entity e) base_light_init =
{
base_mapentity_init (e);

// default speed for fading in/out
if (e.speed <= 0)
e.speed = 0.1;

// non-switchable light
if (!e.targetname)
{
remove (e);
return;
}

if (e.style < 32)
// return now if this is not a switchable light
// removes one level of indentation below -- CEV
return;

// switchable light
e.use = base_light_use;
if (e.spawnflags & LIGHT_START_OFF)
{
e.count = 0;
lightstyle (e.style, "a");
}
else
{
e.count = 12;
lightstyle (e.style, lightstyle_lookup(e.style2));
}
};

//--------------------------------------------------------------
strip void() base_light =
{
base_light_init (self);
};
// };

/*QUAKED light (0 1 0) (-8 -8 -8) (8 8 8) LIGHT_START_OFF LIGHT_FADE_IN_OUT X X X X X X NOT_ON_EASY NOT_ON_NORMAL NOT_ON_HARD_OR_NIGHTMARE NOT_IN_DEATHMATCH NOT_IN_COOP NOT_IN_SINGLEPLAYER X NOT_ON_HARD_ONLY NOT_ON_NIGHTMARE_ONLY

Light

==========
Spawnflags
==========
LIGHT_START_OFF - switchable lights only - light is off by default
LIGHT_FADE_IN_OUT - switchable lights only - light fades in and out. can't be combined with animated lights.

==========
Keys
==========
"light" "n"
Set the light intensity. Negative values are also allowed and will cause the entity to subtract light cast by other entities. Default 300.

"wait" "n"
Scale the fade distance of the light by "n". Values of n > 1 make the light fade more quickly with distance, and values < 1 make the light fade more slowly (and thus reach further). Default 1.

"delay" "n"
Select an attenuation formaula for the light:
0 => Linear attenuation (default)
1 => 1/x attenuation
2 => 1/(x^2) attenuation
3 => No attenuation (same brightness at any distance)
4 => "local minlight" - No attenuation and like minlight,
it won't raise the lighting above it's light value.
Unlike minlight, it will only affect surfaces within
line of sight of the entity.
5 => 1/(x^2) attenuation, but slightly more attenuated and
without the extra bright effect that "delay 2" has
near the source.

"_falloff" "n"
Sets the distance at which the light drops to 0, in map units.
In this mode, "wait" is ignored and "light" only controls the brightness at the center of the light, and no longer affects the falloff distance.
Only supported on linear attenuation (delay 0) lights currently.

"_color" "r g b"
Specify red(r), green(g) and blue(b) components for the colour of the light. RGB component values are between 0 and 255 (between 0 and 1 is also accepted). Default is white light ("255 255 255").

"target" "name"
Turns the light into a spotlight, with the direction of light being towards another entity with it�s "targetname" key set to "name".
"mangle" "yaw pitch roll"
Turns the light into a spotlight and specifies the direction of light using yaw, pitch and roll in degrees. Yaw specifies the angle around the Z-axis from 0 to 359 degrees and pitch specifies the angle from 90 (straight up) to -90 (straight down). Roll has no effect, so use any value (e.g. 0). Often easier than the "target" method.

"angle" "n"
Specifies the angle in degrees for a spotlight cone. Default 40.

"_softangle" "n"
Specifies the angle in degrees for an inner spotlight cone (must be less than the "angle" cone. Creates a softer transition between the full brightness of the inner cone to the edge of the outer cone. Default 0 (disabled).

"targetname" "name"
Turns the light into a switchable light, toggled by another entity targeting it�s name.

"speed" "n"
If the light is switchable and LIGHT_FADE_IN_OUT is set, the speed at which the light transitions. Default 0.1.

"style" "n"
Set the animated light style. Default 0.

"style2" "n"
Set the animated light style for a switchable light, because style will be overriden if a targetname is set. Default 0.

"_anglescale" "n" | "_anglesense" "n"
Sets a scaling factor for how much influence the angle of incidence of light on a surface has on the brightness of the surface. n must be between 0.0 and 1.0. Smaller values mean less attenuation, with zero meaning that angle of incidence has no effect at all on the brightness. Default 0.5.

"_dirtscale" "n" | "_dirtgain" "n"
Override the global "_dirtscale" or "_dirtgain" settings to change how this light is affected by dirtmapping (ambient occlusion). See descriptions of these keys in the worldspawn section.

"_dirt" "n"
Overrides the worldspawn setting of "_dirt" for this particular light. -1 to disable dirtmapping (ambient occlusion) for this light, making it illuminate the dirtmapping shadows. 1 to enable ambient occlusion for this light. Default is to defer to the worldspawn setting.

"_deviance" "n"
Split up the light into a sphere of randomly positioned lights within radius "n" (in world units). Useful to give shadows a wider penumbra. "_samples" specifies the number of lights in the sphere. The "light" value is automatically scaled down for most lighting formulas (except linear and non-additive minlight) to attempt to keep the brightness equal. Default is 0, do not split up lights.

"_samples" "n"
Number of lights to use for "_deviance". Default 16 (only used if "_deviance" is set).

"_surface" "texturename"
Makes surfaces with the given texture name emit light, by using this light as a template which is copied across those surfaces. Lights are spaced about 128 units (though possibly closer due to bsp splitting) apart and positioned 2 units above the surfaces.

"_surface_offset" "n"
Controls the offset lights are placed above surfaces for "_surface". Default 2.

"_surface_spotlight" "n"
For a surface light template (i.e. a light with "_surface" set), setting this to "1" makes each instance into a spotlight, with the direction of light pointing along the surface normal. In other words, it automatically sets "mangle" on each of the generated lights.

"_project_texture" "texture"
Specifies that a light should project this texture. The texture must be used in the map somewhere.

"_project_mangle" "yaw pitch roll"
Specifies the yaw/pitch/roll angles for a texture projection (overriding mangle).

"_project_fov" "n"
Specifies the fov angle for a texture projection. Default 90.

"_bouncescale" "n"
Scales the amount of light that is contributed by bounces. Default is 1.0, 0.0 disables bounce lighting for this light.

"_sun" "n"
Set to 1 to make this entity a sun, as an alternative to using the sunlight worldspawn keys. If the light targets an info_null entity, the direction towards that entity sets sun direction. The light itself is disabled, so it can be placed anywhere in the map.

The following light properties correspond to these sunlight settings:
light => _sunlight
mangle => _sunlight_mangle
deviance => _sunlight_penumbra
_color => _sunlight_color
_dirt => _sunlight_dirt
_anglescale => _anglescale
*/
//----------------------------------------------------------------------
// class light: base_light
// {
//--------------------------------------------------------------
void(entity e) light_init =
{
e.classname = "light";
e.classtype = CT_LIGHT;
base_light_init (e);
};

//--------------------------------------------------------------
void() light =
{
// new spawnflags for all entities -- iw
if (SUB_Inhibit())
return;

light_init (self);
};
// };

/*QUAKED light_fluoro (0 1 0) (-8 -8 -8) (8 8 8) LIGHT_START_OFF LIGHT_FADE_IN_OUT X X X X X X NOT_ON_EASY NOT_ON_NORMAL NOT_ON_HARD_OR_NIGHTMARE NOT_IN_DEATHMATCH NOT_IN_COOP NOT_IN_SINGLEPLAYER X NOT_ON_HARD_ONLY NOT_ON_NIGHTMARE_ONLY

Non-displayed light.
Makes steady fluorescent humming sound.
See the "light" entity for a full description.
*/
//----------------------------------------------------------------------
// class light_fluoro: base_light
// {
//--------------------------------------------------------------
void(entity e) light_fluoro_init =
{
e.classname = "light_fluoro";
e.classtype = CT_LIGHT_FLUORO;
ambient_sound_lbuzz (e.origin);
base_light_init (e);
};

//--------------------------------------------------------------
void() light_fluoro =
{
// new spawnflags for all entities -- iw
if (SUB_Inhibit())
return;

light_fluoro_init (self);
};
// };

/*QUAKED light_fluorospark (0 1 0) (-8 -8 -8) (8 8 8) LIGHT_START_OFF LIGHT_FADE_IN_OUT X X X X X X NOT_ON_EASY NOT_ON_NORMAL NOT_ON_HARD_OR_NIGHTMARE NOT_IN_DEATHMATCH NOT_IN_COOP NOT_IN_SINGLEPLAYER X NOT_ON_HARD_ONLY NOT_ON_NIGHTMARE_ONLY

Non-displayed light.
Makes sparking, broken fluorescent sound.
Can't be toggled.
Default style is 10.
See the "light" entity for a full description.
*/
//----------------------------------------------------------------------
// class light_fluorospark: base_ambient_sound
// {
//--------------------------------------------------------------
void(entity e) light_fluorospark_init =
{
e.classname = "light_fluorospark";
e.classtype = CT_LIGHT_FLUOROSPARK;
base_mapentity_init (e);

if (!e.style)
e.style = 10;
ambient_sound_fbuzz (e.origin);
remove (e);
};

//--------------------------------------------------------------
void() light_fluorospark =
{
// new spawnflags for all entities -- iw
if (SUB_Inhibit())
return;

light_fluorospark_init (self);
};
// };

/*QUAKED light_globe (0 1 0) (-8 -8 -8) (8 8 8) X X X X X X X X NOT_ON_EASY NOT_ON_NORMAL NOT_ON_HARD_OR_NIGHTMARE NOT_IN_DEATHMATCH NOT_IN_COOP NOT_IN_SINGLEPLAYER X NOT_ON_HARD_ONLY NOT_ON_NIGHTMARE_ONLY
Sphere globe light.
Can't be toggled.
See the "light" entity for a full description.
*/
//----------------------------------------------------------------------
// class light_globe: base_light
// {
//--------------------------------------------------------------
void(entity e) light_globe_init =
{
e.classname = "light_globe";
e.classtype = CT_LIGHT_GLOBE;
base_mapentity_init (e);

precache_model ("progs/s_light.spr");
setmodel (e, "progs/s_light.spr");
makestatic (e);
};

//--------------------------------------------------------------
void() light_globe =
{
// new spawnflags for all entities -- iw
if (SUB_Inhibit())
return;

light_globe_init (self);
};
// };

/*QUAKED light_torch_small_walltorch (0 .5 0) (-10 -10 -20) (10 10 20) X X X X X X X X NOT_ON_EASY NOT_ON_NORMAL NOT_ON_HARD_OR_NIGHTMARE NOT_IN_DEATHMATCH NOT_IN_COOP NOT_IN_SINGLEPLAYER X NOT_ON_HARD_ONLY NOT_ON_NIGHTMARE_ONLY
{ model ("progs/flame.mdl"); }
Short wall torch
See the "light" entity for a full description.
*/
//----------------------------------------------------------------------
// class light_torch_small_walltorch: base_ambient_sound
// {
//--------------------------------------------------------------
void(entity e) light_torch_small_walltorch_init =
{
e.classname = "light_torch_small_walltorch";
e.classtype = CT_LIGHT_TORCH_SMALL_WALLTORCH;
base_mapentity_init (e);

// precache_model ("progs/flame.mdl");
precache_body_model (e, "progs/flame.mdl");
// setmodel (e, "progs/flame.mdl");
body_model (e, "progs/flame.mdl");
// for silent torch -- dumptruck_ds
if !(e.spawnflags && LIGHT_SILENT_TORCH)
ambient_sound_fire (e.origin);
makestatic (e);
};

//--------------------------------------------------------------
void() light_torch_small_walltorch =
{
// new spawnflags for all entities -- iw
if (SUB_Inhibit())
return;

light_torch_small_walltorch_init (self);
};
// };

/*QUAKED light_flame_large_yellow (0 1 0) (-10 -10 -12) (12 12 18) X X X X X X X X NOT_ON_EASY NOT_ON_NORMAL NOT_ON_HARD_OR_NIGHTMARE NOT_IN_DEATHMATCH NOT_IN_COOP NOT_IN_SINGLEPLAYER X NOT_ON_HARD_ONLY NOT_ON_NIGHTMARE_ONLY
{ model ( { "path" : "progs/flame2.mdl", "frame" : 1 } ); }
Large yellow flame
See the "light" entity for a full description.
*/
//----------------------------------------------------------------------
// class light_flame_large_yellow: base_ambient_sound
// {
//--------------------------------------------------------------
void(entity e) light_flame_large_yellow_init =
{
e.classname = "light_flame_large_yellow";
e.classtype = CT_LIGHT_FLAME_LARGE_YELLOW;
base_mapentity_init (e);

precache_model ("progs/flame2.mdl");
setmodel (e, "progs/flame2.mdl");
e.frame = 1;
ambient_sound_fire (e.origin);
makestatic (e);
};

//--------------------------------------------------------------
void() light_flame_large_yellow =
{
// new spawnflags for all entities -- iw
if (SUB_Inhibit())
return;

light_flame_large_yellow_init (self);
};
// };

/*QUAKED light_flame_small_yellow (0 1 0) (-8 -8 -8) (8 8 8) X X X X X X X X NOT_ON_EASY NOT_ON_NORMAL NOT_ON_HARD_OR_NIGHTMARE NOT_IN_DEATHMATCH NOT_IN_COOP NOT_IN_SINGLEPLAYER X NOT_ON_HARD_ONLY NOT_ON_NIGHTMARE_ONLY
{ model ("progs/flame2.mdl"); }
Small yellow flame
See the "light" entity for a full description.
*/
//----------------------------------------------------------------------
// class light_flame_small_yellow: base_ambient_sound
// {
//--------------------------------------------------------------
void(entity e) light_flame_small_yellow_init =
{
e.classname = "light_flame_small_yellow";
e.classtype = CT_LIGHT_FLAME_SMALL_YELLOW;
base_mapentity_init (e);

precache_model ("progs/flame2.mdl");
setmodel (e, "progs/flame2.mdl");
ambient_sound_fire (e.origin);
makestatic (e);
};

//--------------------------------------------------------------
void() light_flame_small_yellow =
{
// new spawnflags for all entities -- iw
if (SUB_Inhibit())
return;

light_flame_small_yellow_init (self);
};
// };

/*QUAKED light_flame_small_white (0 1 0) (-8 -8 -8) (8 8 8) X X X X X X X X NOT_ON_EASY NOT_ON_NORMAL NOT_ON_HARD_OR_NIGHTMARE NOT_IN_DEATHMATCH NOT_IN_COOP NOT_IN_SINGLEPLAYER X NOT_ON_HARD_ONLY NOT_ON_NIGHTMARE_ONLY
{ model ("progs/flame2.mdl"); }
Left for compatability
Identical to "light_flame_small_yellow"
*/
//----------------------------------------------------------------------
// class light_flame_small_white: light_flame_small_yellow
// {
//--------------------------------------------------------------
void(entity e) light_flame_small_white_init =
{
e.classname = "light_flame_small_white";
e.classtype = CT_LIGHT_FLAME_SMALL_WHITE;
base_mapentity_init (e);

// same as small_yellow -- CEV
precache_model ("progs/flame2.mdl");
setmodel (e, "progs/flame2.mdl");
ambient_sound_fire (e.origin);
makestatic (e);
};

//--------------------------------------------------------------
void() light_flame_small_white =
{
// new spawnflags for all entities -- iw
if (SUB_Inhibit())
return;

light_flame_small_white_init (self);
};
// };

/*QUAKED light_sprite_flame (0 1 0) (-8 -8 -8) (8 8 8) X X X X X X X X NOT_ON_EASY NOT_ON_NORMAL NOT_ON_HARD_OR_NIGHTMARE NOT_IN_DEATHMATCH NOT_IN_COOP NOT_IN_SINGLEPLAYER X NOT_ON_HARD_ONLY NOT_ON_NIGHTMARE_ONLY
{ model ("progs/s_flame.spr"); }
Large flame spite*/
//----------------------------------------------------------------------
// class light_sprite_flame: base_misc_model
// {
//--------------------------------------------------------------
void(entity e) light_sprite_flame_init =
{
e.classname = "light_sprite_flame";
e.classtype = CT_LIGHT_SPRITE_FLAME;
base_misc_model_init (e);

precache_model ("progs/s_flame.spr");
setmodel (e, "progs/s_flame.spr");
ambient_sound_fire (e.origin);

e.frame = rint (random() * 13);
e.first_frame = 0;
e.last_frame = 13;
e.speed = 0.05;
e.think = base_misc_model_think;
e.nextthink = time + 0.1;
};

//--------------------------------------------------------------
void() light_sprite_flame =
{
// new spawnflags for all entities -- iw
if (SUB_Inhibit())
return;

light_sprite_flame_init (self);
};
// };

Return to the top of this page or return to the overview of this repo.

Log lights.qc

Date Commit Message Author + -
2024-03-24 2nd pass refactor, rework QC class structure cev +286 -165
2024-01-31 Class based monster refactor & start projectiles cev +23 -4
2024-01-09 Continue OO / Class-based refactor cev +111 -93
2023-12-09 Start OO / class-based refactor, work on items cev +227 -196
2023-12-02 More refactoring & moving, begin adding mdls & snd cev +492  

Return to the top of this page or return to the overview of this repo.