djcev.com

//

Git Repos / fte_dogmode / qc / func / shadow.qc

Last update to this file was on 2025-08-13 at 05:20.

Show shadow.qc

//==============================================================================
// func_shadow -- An invisible bmodel that can be used to only cast shadows.
//==============================================================================

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

#ifdef SSQC
//----------------------------------------------------------------------
// misc_shadowcontroller spawnflags -- CEV
//----------------------------------------------------------------------
typedef enumflags
{
SPAWNFLAG_MISC_SHADOWCONTROLLER_STARTOFF = 1
// SPAWNFLAG_NOT_ON_EASY = 256, // see base_entities.qc -- CEV
// SPAWNFLAG_NOT_ON_NORMAL = 512,
// SPAWNFLAG_NOT_ON_HARD_OR_NIGHTMARE = 1024,
// SPAWNFLAG_NOT_IN_DEATHMATCH = 2048,
// SPAWNFLAG_NOT_IN_COOP = 4096,
// SPAWNFLAG_NOT_IN_SP = 8192,
// SPAWNFLAG_NOT_ON_SKILL2 = 32768, // see base_entities.qc -- CEV
// SPAWNFLAG_NOT_ON_SKILL3 = 65536, // see base_entities.qc -- CEV
// SPAWNFLAG_CENTERPRINTALL = 131072 // see base_entities.qc -- CEV
} misc_shadowcontroller_spawnflags;
#endif

//======================================================================
// fields
//======================================================================

#ifdef SSQC
.float switchshadstyle;
.float shadowoff;
.entity shadowcontroller;
#endif

//======================================================================
// forward declaration
//======================================================================

// misc_shadowcontroller
#ifdef SSQC
void() misc_shadowcontroller_fade_out;
void() misc_shadowcontroller_fade_in;
void(entity sc, float speed) misc_shadowcontroller_setsteps;
void() misc_shadowcontroller_use;
entity(entity own, float sss, float spd, float sflags)
spawn_misc_shadowcontroller;
void(entity e) misc_shadowcontroller_init;
void() misc_shadowcontroller;
#endif

// func_shadow
#ifdef SSQC
void(entity e) func_shadow_init;
void() func_shadow;
#endif

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

//----------------------------------------------------------------------
// misc_shadowcontroller
//
// Controls switchable shadows on any bmodel entity (except doors).
// Target entity must have set _switchableshadow set to 1.
//
// speed: Controls the time in seconds it takes to fade the shadow in.
// Default is 0.5, and setting it to -1 disables fading.
// speed2: Same as 'speed' but for the fade out animation. If unset it's
// the same value as 'speed'.
// spawnflag 1: target shadow starts as disabled
//----------------------------------------------------------------------
// class misc_shadowcontroller: base_mapentity
// {
#ifdef SSQC
//--------------------------------------------------------------
void() misc_shadowcontroller_fade_out =
{
if (self.count < 0)
self.count = 0;
if (self.count > 12)
self.count = 12;

lightstyle (self.switchshadstyle,
lightstyle_fade_lookup(self.count));
self.count = self.count + self.aflag;
if (self.count > 12)
return;

self.think = misc_shadowcontroller_fade_out;
self.nextthink = time + self.delay;
};

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

lightstyle (self.switchshadstyle,
lightstyle_fade_lookup(self.count));
self.count = self.count - self.aflag;
if (self.count < 0)
return;

self.think = misc_shadowcontroller_fade_in;
self.nextthink = time + self.delay;
};

//--------------------------------------------------------------
void(entity sc, float speed) misc_shadowcontroller_setsteps =
{
// sc.delay -> time between steps
// sc.aflag -> step size
if (speed >= 0.24)
{
sc.delay = (speed / 12);
sc.aflag = 1;
}
else if (speed >= 0.12)
{
sc.delay = (speed / 6);
sc.aflag = 2;
}
else if (speed >= 0.06)
{
sc.delay = (speed / 3);
sc.aflag = 4;
}
else if (speed >= 0.04)
{
sc.delay = (speed / 2);
sc.aflag = 6;
}
else
{
sc.delay = 0;
sc.aflag = 12;
}
};

//--------------------------------------------------------------
void() misc_shadowcontroller_use =
{
if (self.shadowoff)
{
/*
dprint ("Fade in:\n");
*/
misc_shadowcontroller_setsteps (self, self.speed);
misc_shadowcontroller_fade_in ();
self.shadowoff = 0;
}
else
{
/*
dprint ("Fade out:\n");
*/
misc_shadowcontroller_setsteps (self, self.speed2);
misc_shadowcontroller_fade_out ();
self.shadowoff = 1;
}
};

//--------------------------------------------------------------
entity(entity own, float sss, float spd, float sflags)
spawn_misc_shadowcontroller =
{
local entity e = spawn ();
e.owner = own;
e.switchshadstyle = sss;
e.speed = spd;
e.spawnflags = sflags;
misc_shadowcontroller_init (e);
return e;
};

//--------------------------------------------------------------
void(entity e) misc_shadowcontroller_init =
{
entity t1;

e.classname = "misc_shadowcontroller";
e.classtype = CT_MISC_SHADOWCONTROLLER;
base_mapentity_init (e);

// don't transmit this entity to the client -- CEV
// e.SendEntity = base_entity_netsend_null;

// doesn't search for a target if switchshadstyle is already set
// used for built-in shadow controllers
if (!e.switchshadstyle)
{
// we need to find only the first target entity with
// switchable shadows set, since shadow lightstyles
// are bound by targetname
t1 = find (world, targetname2, e.target);

while (t1 != world && !t1.switchshadstyle)
{
t1 = find (t1, targetname2, e.target);
}

if (t1 == world)
{
t1 = find (world, targetname, e.target);

while (t1 != world && !t1.switchshadstyle)
{
t1 = find (t1, targetname, e.target);
}
}

if (t1 == world)
{
dprint ("misc_shadowcontroller_init: "
"_switchableshadow not set in target ");
dprint (e.target);
dprint ("\n");
return;
}

e.switchshadstyle = t1.switchshadstyle;
}

if (!e.speed)
e.speed = 0.5;
if (!e.speed2)
e.speed2 = e.speed;

if (e.spawnflags & SPAWNFLAG_MISC_SHADOWCONTROLLER_STARTOFF)
{
lightstyle (e.switchshadstyle, "m");

e.shadowoff = 1;
e.count = 12;

misc_shadowcontroller_setsteps (e, e.speed2);
}
else
{
lightstyle (e.switchshadstyle, "a");
e.shadowoff = 0;
e.count = 0;
misc_shadowcontroller_setsteps (e, e.speed);
}

e.use = misc_shadowcontroller_use;
};

//--------------------------------------------------------------
void() misc_shadowcontroller =
{
BASE_FUNC_PREINIT (__NULL__)
misc_shadowcontroller_init (self);
};
#endif
// };

//----------------------------------------------------------------------
// class func_shadow: base_func
// {
#ifdef SSQC
//--------------------------------------------------------------
void(entity e) func_shadow_init =
{
e.classname = "func_shadow";
e.classtype = CT_FUNC_SHADOW;
base_func_init (e);

e.angles = '0 0 0';
e.movetype = MOVETYPE_NONE;
e.solid = SOLID_NOT;

e.modelindex = 0;
e.model = "";

// don't transmit this entity to the client -- CEV
// e.SendEntity = base_entity_netsend_null;
};

//--------------------------------------------------------------
void() func_shadow =
{
BASE_FUNC_PREINIT (__NULL__)
func_shadow_init (self);
};
#endif
// };

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

Log shadow.qc

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