Skip to content

Commit

Permalink
Reset entity on start round for env_spark, env_laser, env_beam
Browse files Browse the repository at this point in the history
  • Loading branch information
s1lentq committed Jan 28, 2018
1 parent a5eadb6 commit a7bdaa0
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 10 deletions.
41 changes: 41 additions & 0 deletions regamedll/dlls/buttons.cpp
Expand Up @@ -1160,10 +1160,14 @@ void CEnvSpark::Spawn()
SetUse(&CEnvSpark::SparkStop);
}
else
{
SetUse(&CEnvSpark::SparkStart);
}
}
else
{
SetThink(&CEnvSpark::SparkThink);
}

pev->nextthink = gpGlobals->time + (0.1f + RANDOM_FLOAT(0.0f, 1.5f));

Expand All @@ -1175,6 +1179,43 @@ void CEnvSpark::Spawn()
Precache();
}

#ifdef REGAMEDLL_FIXES
void CEnvSpark::Restart()
{
SetThink(nullptr);
SetUse(nullptr);

// Use for on/off
if (pev->spawnflags & SF_SPARK_TOOGLE)
{
// Start on
if (pev->spawnflags & SF_SPARK_IF_OFF)
{
// start sparking
SetThink(&CEnvSpark::SparkThink);

// set up +USE to stop sparking
SetUse(&CEnvSpark::SparkStop);
}
else
{
SetUse(&CEnvSpark::SparkStart);
}
}
else
{
SetThink(&CEnvSpark::SparkThink);
}

pev->nextthink = gpGlobals->time + (0.1f + RANDOM_FLOAT(0.0f, 1.5f));

if (m_flDelay <= 0.0f)
{
m_flDelay = 1.5f;
}
}
#endif

void CEnvSpark::Precache()
{
PRECACHE_SOUND("buttons/spark1.wav");
Expand Down
4 changes: 4 additions & 0 deletions regamedll/dlls/buttons.h
Expand Up @@ -126,6 +126,10 @@ class CEnvSpark: public CBaseEntity
virtual int Save(CSave &save);
virtual int Restore(CRestore &restore);

#ifdef REGAMEDLL_FIXES
virtual void Restart();
#endif

public:
void EXPORT SparkThink();
void EXPORT SparkStart(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value);
Expand Down
108 changes: 101 additions & 7 deletions regamedll/dlls/effects.cpp
Expand Up @@ -340,34 +340,95 @@ void CLightning::Spawn()
SetThink(&CLightning::DamageThink);
pev->nextthink = gpGlobals->time + 0.1f;
}

if (pev->targetname)
{
if (!(pev->spawnflags & SF_BEAM_STARTON))
{
m_active = FALSE;
pev->effects = EF_NODRAW;
m_active = 0;
pev->nextthink = 0;
}
else
m_active = 1;
{
m_active = TRUE;
}

SetUse(&CLightning::ToggleUse);
}
}
else
{
m_active = FALSE;

if (!FStringNull(pev->targetname))
{
SetUse(&CLightning::StrikeUse);
}

if (FStringNull(pev->targetname) || (pev->spawnflags & SF_BEAM_STARTON))
{
SetThink(&CLightning::StrikeThink);
pev->nextthink = gpGlobals->time + 1.0f;
}
}
}

#ifdef REGAMEDLL_FIXES
void CLightning::Restart()
{
if (FStringNull(m_iszSpriteName))
{
SetThink(&CLightning::SUB_Remove);
return;
}

// Remove model & collisions
pev->solid = SOLID_NOT;
pev->dmgtime = gpGlobals->time;

if (ServerSide())
{
SetThink(nullptr);
if (pev->dmg > 0)
{
SetThink(&CLightning::DamageThink);
pev->nextthink = gpGlobals->time + 0.1f;
}

if (pev->targetname)
{
if (!(pev->spawnflags & SF_BEAM_STARTON))
{
m_active = FALSE;
pev->effects |= EF_NODRAW;
pev->nextthink = 0;
}
else
{
m_active = TRUE;
}

SetUse(&CLightning::ToggleUse);
}
}
else
{
m_active = 0;
m_active = FALSE;

if (!FStringNull(pev->targetname))
{
SetUse(&CLightning::StrikeUse);
}

if (FStringNull(pev->targetname) || (pev->spawnflags & SF_BEAM_STARTON))
{
SetThink(&CLightning::StrikeThink);
pev->nextthink = gpGlobals->time + 1.0f;
}
}
}
#endif

void CLightning::Precache()
{
Expand All @@ -378,7 +439,9 @@ void CLightning::Precache()
void CLightning::Activate()
{
if (ServerSide())
{
BeamUpdateVars();
}
}

void CLightning::KeyValue(KeyValueData *pkvd)
Expand Down Expand Up @@ -451,13 +514,13 @@ void CLightning::ToggleUse(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TY

if (m_active)
{
m_active = 0;
m_active = FALSE;
pev->effects |= EF_NODRAW;
pev->nextthink = 0;
}
else
{
m_active = 1;
m_active = TRUE;
pev->effects &= ~EF_NODRAW;
DoSparks(GetStartPos(), GetEndPos());

Expand All @@ -476,7 +539,7 @@ void CLightning::StrikeUse(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TY

if (m_active)
{
m_active = 0;
m_active = FALSE;
SetThink(nullptr);
}
else
Expand Down Expand Up @@ -512,7 +575,7 @@ void CLightning::StrikeThink()
pev->nextthink = gpGlobals->time + m_life + m_restrike;
}

m_active = 1;
m_active = TRUE;

if (FStringNull(m_iszEndEntity))
{
Expand Down Expand Up @@ -842,7 +905,11 @@ void CLaser::Spawn()
if (!m_pSprite && m_iszSpriteName)
m_pSprite = CSprite::SpriteCreate(STRING(m_iszSpriteName), pev->origin, TRUE);
else
{
// TODO: Call CLaser::Spawn more than once may cause to a memory leaks,
// since env_sprite will be not released.
m_pSprite = nullptr;
}

if (m_pSprite)
m_pSprite->SetTransparency(kRenderGlow, pev->rendercolor.x, pev->rendercolor.y, pev->rendercolor.z, pev->renderamt, pev->renderfx);
Expand All @@ -853,6 +920,33 @@ void CLaser::Spawn()
TurnOn();
}

#ifdef REGAMEDLL_FIXES
void CLaser::Restart()
{
if (FStringNull(pev->model))
{
SetThink(&CLaser::SUB_Remove);
return;
}

// Remove model & collisions
pev->solid = SOLID_NOT;
pev->flags |= FL_CUSTOMENTITY;

SetThink(&CLaser::StrikeThink);

if (m_pSprite)
{
m_pSprite->SetTransparency(kRenderGlow, pev->rendercolor.x, pev->rendercolor.y, pev->rendercolor.z, pev->renderamt, pev->renderfx);
}

if (pev->targetname && !(pev->spawnflags & SF_BEAM_STARTON))
TurnOff();
else
TurnOn();
}
#endif

void CLaser::Precache()
{
pev->modelindex = PRECACHE_MODEL((char *)STRING(pev->model));
Expand Down
10 changes: 9 additions & 1 deletion regamedll/dlls/effects.h
Expand Up @@ -202,6 +202,10 @@ class CLaser: public CBeam
virtual int Restore(CRestore &restore);
virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value);

#ifdef REGAMEDLL_FIXES
virtual void Restart();
#endif

public:
void TurnOn();
void TurnOff();
Expand Down Expand Up @@ -253,6 +257,10 @@ class CLightning: public CBeam
virtual int Restore(CRestore &restore);
virtual void Activate();

#ifdef REGAMEDLL_FIXES
virtual void Restart();
#endif

public:
void EXPORT StrikeThink();
void EXPORT DamageThink();
Expand All @@ -274,7 +282,7 @@ class CLightning: public CBeam
public:
static TYPEDESCRIPTION m_SaveData[];

int m_active;
BOOL m_active;
int m_iszStartEntity;
int m_iszEndEntity;
float m_life;
Expand Down
6 changes: 5 additions & 1 deletion regamedll/dlls/multiplay_gamerules.cpp
Expand Up @@ -138,7 +138,7 @@ void Broadcast(const char *sentence)
MESSAGE_BEGIN(MSG_BROADCAST, gmsgSendAudio);
WRITE_BYTE(0);
WRITE_STRING(text);
WRITE_SHORT(100);
WRITE_SHORT(PITCH_NORM);
MESSAGE_END();
}

Expand Down Expand Up @@ -575,6 +575,7 @@ void EXT_FUNC CHalfLifeMultiplay::__API_HOOK(CleanUpMap)()
UTIL_RestartOther("func_button");
UTIL_RestartOther("func_rot_button");
UTIL_RestartOther("env_render");
UTIL_RestartOther("env_spark");
UTIL_RestartOther("trigger_push");
#endif

Expand All @@ -590,7 +591,10 @@ void EXT_FUNC CHalfLifeMultiplay::__API_HOOK(CleanUpMap)()
#ifdef REGAMEDLL_FIXES
UTIL_RestartOther("trigger_once");
UTIL_RestartOther("func_wall_toggle");
UTIL_RestartOther("trigger_hurt");
UTIL_RestartOther("multisource");
UTIL_RestartOther("env_beam");
UTIL_RestartOther("env_laser");
UTIL_RestartOther("trigger_auto");
#endif

Expand Down
1 change: 0 additions & 1 deletion regamedll/dlls/triggers.h
Expand Up @@ -221,7 +221,6 @@ class CTriggerHurt: public CBaseTrigger

#ifdef REGAMEDLL_FIXES
virtual void Restart();
virtual int ObjectCaps() { return (CBaseTrigger::ObjectCaps() | FCAP_MUST_RESET); }
#endif

void EXPORT RadiationThink();
Expand Down

0 comments on commit a7bdaa0

Please sign in to comment.