env_spark: Fix spawnflag START_ON not implying TOGGLE, add Input() method and implement more stuff.

This commit is contained in:
Marco Cawthorne 2024-02-23 13:57:28 -08:00
parent ca318e29f9
commit cb4ba0c201
Signed by: eukara
GPG Key ID: CE2032F0A2882A22
2 changed files with 98 additions and 27 deletions

View File

@ -22,10 +22,13 @@ enumflags
EVSPARK_UNUSED4, EVSPARK_UNUSED4,
EVSPARK_UNUSED5, EVSPARK_UNUSED5,
EVSPARK_TOGGLE, EVSPARK_TOGGLE,
EVSPARK_STARTON EVSPARK_STARTON,
EVSPARK_UNUSED6,
EVSPARK_SILENT,
EVSPARK_DIRECTIONAL
}; };
/*!QUAKED env_spark (1 .5 0) (-8 -8 -8) (8 8 8) x x x x x EVSPARK_TOGGLE EVSPARK_STARTON /*!QUAKED env_spark (1 .5 0) (-8 -8 -8) (8 8 8) x x x x x TOGGLE START_ON
# OVERVIEW # OVERVIEW
Creates a series (or just one) spark effect with sound when triggered. Creates a series (or just one) spark effect with sound when triggered.
@ -36,13 +39,21 @@ Creates a series (or just one) spark effect with sound when triggered.
- "angles" : Sets the pitch, yaw and roll angles of the spark. - "angles" : Sets the pitch, yaw and roll angles of the spark.
- "MaxDelay" : Delay between sparks when start-on (or toggle) is set - "MaxDelay" : Delay between sparks when start-on (or toggle) is set
# INPUTS
- "StartSpark" : Enables a continous spark emitter.
- "StopSpark" : Stops the ongoing spark emitter.
- "ToggleSpark" : Toggles the state of the spark emitter.
- "SparkOnce" : Creates a single spark effect, once.
# SPAWNFLAGS # SPAWNFLAGS
- EVSPARK_TOGGLE (32) : When triggered, it'll spark continously with "MaxDelay" dictating the interval. - TOGGLE (32) : When triggered, it'll spark continously with "MaxDelay" dictating the interval.
- EVSPARK_STARTON (64) : Start sparking upon spawning, at least waiting til "MaxDelay" seconds has passed. - START_ON (64) : Start sparking upon spawning, at least waiting til "MaxDelay" seconds has passed.
- SILENT (256) : Do not play a sound.
- DIRECTIONAL (512) : Angles are respected to direct the spark.
# NOTES # NOTES
The spawnflags EVSPARK_TOGGLE and EVSPARK_STARTON are often used together. The spawnflag START_ON (32) automatically enables the TOGGLE (64) flag
Without them set, it'll of course only spark once whenever it's triggered. as well.
# TRIVIA # TRIVIA
This entity was introduced in Half-Life (1998). This entity was introduced in Half-Life (1998).
@ -59,17 +70,24 @@ public:
virtual void Spawned(void); virtual void Spawned(void);
virtual void Respawn(void); virtual void Respawn(void);
virtual void Trigger(entity, triggermode_t); virtual void Trigger(entity, triggermode_t);
nonvirtual void CreateSpark(void); virtual void Input(entity, string, string);
nonvirtual void TimedSpark(void); nonvirtual void _TimedSpark(void);
nonvirtual void StartSpark(void);
nonvirtual void StopSpark(void);
nonvirtual void ToggleSpark(void);
nonvirtual void SparkOnce(void);
private: private:
float m_flMaxDelay; float m_flMaxDelay;
int _m_iSparkParticle;
}; };
void void
env_spark::env_spark(void) env_spark::env_spark(void)
{ {
m_flMaxDelay = 0.0f; m_flMaxDelay = 0.0f;
_m_iSparkParticle = 0i;
} }
void void
@ -77,6 +95,7 @@ env_spark::Save(float handle)
{ {
super::Save(handle); super::Save(handle);
SaveFloat(handle, "m_flMaxDelay", m_flMaxDelay); SaveFloat(handle, "m_flMaxDelay", m_flMaxDelay);
SaveInt(handle, "_m_iSparkParticle", _m_iSparkParticle);
} }
void void
@ -86,6 +105,9 @@ env_spark::Restore(string strKey, string strValue)
case "m_flMaxDelay": case "m_flMaxDelay":
m_flMaxDelay = ReadFloat(strValue); m_flMaxDelay = ReadFloat(strValue);
break; break;
case "_m_iSparkParticle":
_m_iSparkParticle = ReadInt(strValue);
break;
default: default:
super::Restore(strKey, strValue); super::Restore(strKey, strValue);
} }
@ -108,55 +130,104 @@ env_spark::Spawned(void)
{ {
super::Spawned(); super::Spawned();
Sound_Precache("env_spark.sfx"); Sound_Precache("fx.spark");
_m_iSparkParticle = particleeffectnum("fx_spark.main");
} }
void void
env_spark::Respawn(void) env_spark::Respawn(void)
{ {
InitPointTrigger();
if (m_flMaxDelay <= 0) { if (m_flMaxDelay <= 0) {
m_flMaxDelay = 1.0f; m_flMaxDelay = 1.0f;
} }
if (HasSpawnFlags(EVSPARK_STARTON)) { if (HasSpawnFlags(EVSPARK_STARTON)) {
Trigger(this, TRIG_ON); StartSpark();
} }
if (HasSpawnFlags(EVSPARK_DIRECTIONAL) == false) {
SetAngles([0,0,0]);
}
}
void
env_spark::StartSpark(void)
{
ScheduleThink(_TimedSpark, (random() * m_flMaxDelay));
}
void
env_spark::StopSpark(void)
{
ReleaseThink();
}
void
env_spark::ToggleSpark(void)
{
if (IsThinking() == true) {
StopSpark();
} else {
StartSpark();
}
}
void
env_spark::SparkOnce(void)
{
if (HasSpawnFlags(EVSPARK_SILENT) == false) {
StartSoundDef("fx.spark", CHAN_AUTO, true);
}
pointparticles(_m_iSparkParticle, origin, angles, 1);
} }
void void
env_spark::Trigger(entity act, triggermode_t state) env_spark::Trigger(entity act, triggermode_t state)
{ {
if (!HasSpawnFlags(EVSPARK_TOGGLE)) { if (!HasSpawnFlags(EVSPARK_TOGGLE) && !HasSpawnFlags(EVSPARK_STARTON)) {
CreateSpark(); SparkOnce();
return; return;
} }
switch (state) { switch (state) {
case TRIG_OFF: case TRIG_OFF:
ReleaseThink(); StopSpark();
break; break;
case TRIG_ON: case TRIG_ON:
ScheduleThink(CreateSpark, (random() * m_flMaxDelay)); StartSpark();
break; break;
default: default:
if (IsThinking() == true) { ToggleSpark();
Trigger(act, TRIG_OFF);
} else {
Trigger(act, TRIG_ON);
}
} }
} }
void void
env_spark::CreateSpark(void) env_spark::Input(entity theActivator, string inputName, string dataField)
{ {
Sound_Play(this, CHAN_AUTO, "env_spark.sfx"); switch (inputName) {
pointparticles(particleeffectnum("platform.spark"), origin, angles, 1); case "StartSpark":
StartSpark();
break;
case "StopSpark":
StopSpark();
break;
case "ToggleSpark":
ToggleSpark();
break;
case "SparkOnce":
SparkOnce();
break;
default:
super::Input(theActivator, inputName, dataField);
}
} }
void void
env_spark::TimedSpark(void) env_spark::_TimedSpark(void)
{ {
CreateSpark(); SparkOnce();
ScheduleThink(CreateSpark, (random() * m_flMaxDelay)); ScheduleThink(_TimedSpark, (random() * m_flMaxDelay));
} }

View File

@ -394,14 +394,14 @@ env_laser::predraw(void)
if (m_iBeamFlags & (LASER_STARTSPARKS)) { if (m_iBeamFlags & (LASER_STARTSPARKS)) {
vector dir = vectoangles(origin - m_vecEndPos); vector dir = vectoangles(origin - m_vecEndPos);
makevectors(dir); makevectors(dir);
pointparticles(particleeffectnum("platform.spark"), origin, -v_forward, 1); pointparticles(particleeffectnum("fx.spark"), origin, -v_forward, 1);
} }
if (m_iBeamFlags & (LASER_ENDSPARKS)) { if (m_iBeamFlags & (LASER_ENDSPARKS)) {
vector dir2 = vectoangles(m_vecEndPos - origin); vector dir2 = vectoangles(m_vecEndPos - origin);
makevectors(dir2); makevectors(dir2);
pointparticles(particleeffectnum("platform.spark"), m_vecEndPos, -v_forward, 1); pointparticles(particleeffectnum("fx.spark"), m_vecEndPos, -v_forward, 1);
} }
m_flSparkTime = time + 0.25f; m_flSparkTime = time + 0.25f;