djcev.com

//

Git Repos / fte_dogmode / qc / misc / sparks.qc

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

Show sparks.qc

//==============================================================================
// misc_sparks -- selections from Rubicon 2 qc by john fitzgibbons
//==============================================================================

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

#ifdef SSQC
//----------------------------------------------------------------------
// misc_sparks spawnflags -- CEV
//----------------------------------------------------------------------
typedef enumflags
{
SPAWNFLAG_MISC_SPARKS_START_OFF = 1,
SPAWNFLAG_MISC_SPARKS_BLUE = 2,
SPAWNFLAG_MISC_SPARKS_PALE = 4
// 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_sparks_spawnflags;
#endif

#ifdef SSQC
//----------------------------------------------------------------------
typedef enum
{
TEMP_SPARK_FADE1, // animation states for temp_spark
TEMP_SPARK_FADE2, // stored in .aflag even though
TEMP_SPARK_FADE3, // these aren't flags -- CEV
TEMP_SPARK_FADE4,
TEMP_SPARK_REMOVE
} temp_spark_flags;
#endif

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

#ifdef SSQC
// temp_spark
void() temp_spark_think;
entity(entity own, vector org, float sflags) spawn_temp_spark;
void(entity e) temp_spark_init;
strip void() temp_spark;
#endif

#ifdef SSQC
// misc_sparks
void() misc_sparks_think_make;
void() misc_sparks_think_turnofflight;
void() misc_sparks_use;
void(entity e) misc_sparks_init;
void() misc_sparks;
#endif

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

//----------------------------------------------------------------------
// temp_spark - an individual spark - from Rubicon2, refactored by CEV
//----------------------------------------------------------------------
// class temp_spark: base_tempentity
// {
#ifdef SSQC
//--------------------------------------------------------------
void() temp_spark_think =
{
if (self.aflag == TEMP_SPARK_REMOVE)
{
remove (self);
return;
}

self.alpha -= 0.2;
self.aflag += 1;
self.nextthink = time + 0.05;
};

//--------------------------------------------------------------
entity(entity own, vector org, float sflags) spawn_temp_spark =
{
local entity e = spawn ();
e.owner = own;
e.origin = org;
e.spawnflags = sflags;
temp_spark_init (e);
return e;
};

//--------------------------------------------------------------
void(entity e) temp_spark_init =
{
e.classname = "spark";
e.classtype = CT_TEMP_SPARK;
// TODO CEV set classgroup directly to save a function call
// base_tempentity_init (e);
e.classgroup |= CG_TEMPENTITY;

e.movetype = MOVETYPE_BOUNCE;
e.solid = SOLID_TRIGGER;
e.alpha = 1.0;
e.gravity = 0.3;
e.velocity_x = -40 + random() * 80;
e.velocity_y = -40 + random() * 80;
e.velocity_z = -40 + random() * 80;
e.avelocity = '3000 3000 3000';

if (random() < 0.33)
e.skin = 0;
else if (random() < 0.5)
e.skin = 1;
else
e.skin = 2;

if (e.spawnflags & SPAWNFLAG_MISC_SPARKS_PALE)
e.skin = e.skin + 6;
else if (e.spawnflags & SPAWNFLAG_MISC_SPARKS_BLUE)
e.skin = e.skin + 3;

setmodel (e, "progs/spark.mdl");
setorigin (e, e.origin);
setsize (e, '0 0 0', '0 0 0');

e.aflag = TEMP_SPARK_FADE1;
e.think = temp_spark_think;
e.nextthink = time + 0.5 + 1.5 * random();
};

//--------------------------------------------------------------
strip void() temp_spark =
{
temp_spark_init (self);
};
#endif
// };

/*QUAKED misc_sparks (0 .5 .8) (-8 -8 -8) (8 8 8) START_OFF SPARKS_BLUE SPARKS_PALE 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

Produces a burst of yellow sparks at random intervals. If targeted, it will toggle between on or off. If it targets a light, that light will flash allong with each burst of sparks. Note: targeted lights should be set to START_OFF.

SPARKS_BLUE: sparks are blue in color

SPARKS_PALE: sparks are pale yellow in color

Keys:

"wait" is the average delay between bursts (variance is 1/2 wait). Default is 2.

"cnt" is the average number of sparks in a burst (variance is 1/4 cnt). Default is 15.

"sounds"
0) no sound
1) sparks
*/
//----------------------------------------------------------------------
// class misc_sparks: base_mapentity
// {
#ifdef SSQC
//--------------------------------------------------------------
void() misc_sparks_think_make =
{
if (self.spawnflags & SPAWNFLAG_MISC_SPARKS_START_OFF)
{
self.think = misc_sparks_think_make;
self.nextthink = time + 0.1;
return;
}

local float i;
i = -0.25 * self.cnt + random() * 0.5 * self.cnt;
while (i < self.cnt)
{
spawn_temp_spark (self, self.origin, self.spawnflags);
i++;
}

if (self.sounds == 1)
{
if (self.noise != __NULL__ && self.noise != "")
{
sound (self, CHAN_AUTO, self.noise,
VOL_HIGH, ATTN_STATIC);
}
else
{
SOUND (self, snd_misc_spark)
}
}

sub_usetargets ();
self.think = misc_sparks_think_turnofflight;
self.nextthink = time + 0.1 + random() * 0.1;
};

//--------------------------------------------------------------
void() misc_sparks_think_turnofflight =
{
sub_usetargets ();
self.think = misc_sparks_think_make;
self.nextthink = time + (random() + 0.5) * self.wait - 0.15;
};

//--------------------------------------------------------------
void() misc_sparks_use =
{

if (self.spawnflags & SPAWNFLAG_MISC_SPARKS_START_OFF)
self.spawnflags &= ~SPAWNFLAG_MISC_SPARKS_START_OFF;
else
self.spawnflags |= SPAWNFLAG_MISC_SPARKS_START_OFF;
};

//--------------------------------------------------------------
void(entity e) misc_sparks_init =
{
e.classname = "misc_sparks";
e.classtype = CT_MISC_SPARKS;
base_mapentity_init (e);

precache_model ("progs/spark.mdl");

if (!e.noise)
precache_sound (snd_misc_spark.wav);
else
precache_sound (e.noise);

if (!e.movedir)
e.movedir = '0 0 -30';

if (!e.wait)
e.wait = 2;

if (!e.cnt)
e.cnt = 15;

e.use = misc_sparks_use;
e.think = misc_sparks_think_make;
e.nextthink = time + random() * 0.1;
};

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

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

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

Log sparks.qc

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