djcev.com

//

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

Last update to this file was on 2024-06-15 at 19:50.

Show shadow.qc

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

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

#ifdef SSQC
const float SHADOWCONTROLLER_STARTOFF = 1;
#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;

// was self.fading
/*
if (self.state >= 0)
self.state = -1;
*/

/*
dprint (ftos(self.count));
dprint ("\n");
*/

lightstyle (self.switchshadstyle,
lightstyle_fade_lookup(self.count));
self.count = self.count + self.dmg;
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;

// was self.fading
/*
if (self.state <= 0)
self.state = 1;
*/

/*
dprint (ftos(self.count));
dprint ("\n");
*/

lightstyle (self.switchshadstyle,
lightstyle_fade_lookup(self.count));
self.count = self.count - self.dmg;
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.dmg -> step size
if (speed >= 0.24)
{
sc.delay = (speed / 12);
sc.dmg = 1;
}
else if (speed >= 0.12)
{
sc.delay = (speed / 6);
sc.dmg = 2;
}
else if (speed >= 0.06)
{
sc.delay = (speed / 3);
sc.dmg = 4;
}
else if (speed >= 0.04)
{
sc.delay = (speed / 2);
sc.dmg = 6;
}
else
{
sc.delay = 0;
sc.dmg = 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);

// 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;
}

// was self.fading
/*
e.state = 0;
*/

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

if (e.spawnflags & 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 =
{
// new spawnflags for all entities -- iw
if (SUB_Inhibit())
return;

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 = "";
};

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

func_shadow_init (self);
};
#endif
// };

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

Log shadow.qc

Date Commit Message Author + -
2024-06-15 Major update, committing as-is, will have bugs cev +12  
2024-03-24 2nd pass refactor, rework QC class structure cev +155 -119
2024-01-31 Class based monster refactor & start projectiles cev +4 -3
2024-01-09 Continue OO / Class-based refactor cev +209 -150
2023-12-09 Start OO / class-based refactor, work on items cev +2  
2023-11-27 Code reorg, minor movement changes, misc cev +194  

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