djcev.com

//

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

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

Show sparks.qc

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

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

const float MISC_SPARKS_START_OFF = 1;
const float MISC_SPARKS_BLUE = 2;
const float MISC_SPARKS_PALE = 4;

enum
{
TEMP_SPARK_FADE1, // animation states for temp_spark
TEMP_SPARK_FADE2,
TEMP_SPARK_FADE3,
TEMP_SPARK_FADE4,
TEMP_SPARK_REMOVE
};

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

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

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

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

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

self.alpha -= 0.2;
self.state += 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 & MISC_SPARKS_PALE)
e.skin = e.skin + 6;
else if (e.spawnflags & 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.state = TEMP_SPARK_FADE1;
e.think = temp_spark_think;
e.nextthink = time + 0.5 + 1.5 * random();
};

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

/*QUAKED misc_sparks (0 .5 .8) (-8 -8 -8) (8 8 8) MISC_SPARKS_START_OFF MISC_SPARKS_BLUE MISC_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
// {
//--------------------------------------------------------------
void() misc_sparks_think_make =
{
if (self.spawnflags & 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 != "")
sound (self, CHAN_AUTO, self.noise,
1, ATTN_STATIC);
else
sound (self, CHAN_AUTO, "enforcer/enfstop.wav",
1, ATTN_STATIC);

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 & MISC_SPARKS_START_OFF)
self.spawnflags &= ~MISC_SPARKS_START_OFF;
else
self.spawnflags |= 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 ("dump/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);
};
// };

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

Log sparks.qc

Date Commit Message Author + -
2024-03-24 2nd pass refactor, rework QC class structure cev +136 -110
2024-01-31 Class based monster refactor & start projectiles cev +2 -2
2024-01-09 Continue OO / Class-based refactor cev +132 -103
2023-12-09 Start OO / class-based refactor, work on items cev +138 -129
2023-11-27 Code reorg, minor movement changes, misc cev +160  

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