Reset entity on start round for env_spark, env_laser, env_beam

This commit is contained in:
s1lent 2018-01-28 21:42:22 +07:00
parent a5eadb6cb2
commit a7bdaa011a
No known key found for this signature in database
GPG Key ID: 0FE401DC73916B5C
6 changed files with 160 additions and 10 deletions

View File

@ -1160,10 +1160,14 @@ void CEnvSpark::Spawn()
SetUse(&CEnvSpark::SparkStop); SetUse(&CEnvSpark::SparkStop);
} }
else else
{
SetUse(&CEnvSpark::SparkStart); SetUse(&CEnvSpark::SparkStart);
} }
}
else else
{
SetThink(&CEnvSpark::SparkThink); SetThink(&CEnvSpark::SparkThink);
}
pev->nextthink = gpGlobals->time + (0.1f + RANDOM_FLOAT(0.0f, 1.5f)); pev->nextthink = gpGlobals->time + (0.1f + RANDOM_FLOAT(0.0f, 1.5f));
@ -1175,6 +1179,43 @@ void CEnvSpark::Spawn()
Precache(); 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() void CEnvSpark::Precache()
{ {
PRECACHE_SOUND("buttons/spark1.wav"); PRECACHE_SOUND("buttons/spark1.wav");

View File

@ -126,6 +126,10 @@ public:
virtual int Save(CSave &save); virtual int Save(CSave &save);
virtual int Restore(CRestore &restore); virtual int Restore(CRestore &restore);
#ifdef REGAMEDLL_FIXES
virtual void Restart();
#endif
public: public:
void EXPORT SparkThink(); void EXPORT SparkThink();
void EXPORT SparkStart(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value); void EXPORT SparkStart(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value);

View File

@ -340,27 +340,32 @@ void CLightning::Spawn()
SetThink(&CLightning::DamageThink); SetThink(&CLightning::DamageThink);
pev->nextthink = gpGlobals->time + 0.1f; pev->nextthink = gpGlobals->time + 0.1f;
} }
if (pev->targetname) if (pev->targetname)
{ {
if (!(pev->spawnflags & SF_BEAM_STARTON)) if (!(pev->spawnflags & SF_BEAM_STARTON))
{ {
m_active = FALSE;
pev->effects = EF_NODRAW; pev->effects = EF_NODRAW;
m_active = 0;
pev->nextthink = 0; pev->nextthink = 0;
} }
else else
m_active = 1; {
m_active = TRUE;
}
SetUse(&CLightning::ToggleUse); SetUse(&CLightning::ToggleUse);
} }
} }
else else
{ {
m_active = 0; m_active = FALSE;
if (!FStringNull(pev->targetname)) if (!FStringNull(pev->targetname))
{ {
SetUse(&CLightning::StrikeUse); SetUse(&CLightning::StrikeUse);
} }
if (FStringNull(pev->targetname) || (pev->spawnflags & SF_BEAM_STARTON)) if (FStringNull(pev->targetname) || (pev->spawnflags & SF_BEAM_STARTON))
{ {
SetThink(&CLightning::StrikeThink); SetThink(&CLightning::StrikeThink);
@ -369,6 +374,62 @@ void CLightning::Spawn()
} }
} }
#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 = 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() void CLightning::Precache()
{ {
m_spriteTexture = PRECACHE_MODEL((char *)STRING(m_iszSpriteName)); m_spriteTexture = PRECACHE_MODEL((char *)STRING(m_iszSpriteName));
@ -378,7 +439,9 @@ void CLightning::Precache()
void CLightning::Activate() void CLightning::Activate()
{ {
if (ServerSide()) if (ServerSide())
{
BeamUpdateVars(); BeamUpdateVars();
}
} }
void CLightning::KeyValue(KeyValueData *pkvd) void CLightning::KeyValue(KeyValueData *pkvd)
@ -451,13 +514,13 @@ void CLightning::ToggleUse(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TY
if (m_active) if (m_active)
{ {
m_active = 0; m_active = FALSE;
pev->effects |= EF_NODRAW; pev->effects |= EF_NODRAW;
pev->nextthink = 0; pev->nextthink = 0;
} }
else else
{ {
m_active = 1; m_active = TRUE;
pev->effects &= ~EF_NODRAW; pev->effects &= ~EF_NODRAW;
DoSparks(GetStartPos(), GetEndPos()); DoSparks(GetStartPos(), GetEndPos());
@ -476,7 +539,7 @@ void CLightning::StrikeUse(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TY
if (m_active) if (m_active)
{ {
m_active = 0; m_active = FALSE;
SetThink(nullptr); SetThink(nullptr);
} }
else else
@ -512,7 +575,7 @@ void CLightning::StrikeThink()
pev->nextthink = gpGlobals->time + m_life + m_restrike; pev->nextthink = gpGlobals->time + m_life + m_restrike;
} }
m_active = 1; m_active = TRUE;
if (FStringNull(m_iszEndEntity)) if (FStringNull(m_iszEndEntity))
{ {
@ -842,7 +905,11 @@ void CLaser::Spawn()
if (!m_pSprite && m_iszSpriteName) if (!m_pSprite && m_iszSpriteName)
m_pSprite = CSprite::SpriteCreate(STRING(m_iszSpriteName), pev->origin, TRUE); m_pSprite = CSprite::SpriteCreate(STRING(m_iszSpriteName), pev->origin, TRUE);
else else
{
// TODO: Call CLaser::Spawn more than once may cause to a memory leaks,
// since env_sprite will be not released.
m_pSprite = nullptr; m_pSprite = nullptr;
}
if (m_pSprite) if (m_pSprite)
m_pSprite->SetTransparency(kRenderGlow, pev->rendercolor.x, pev->rendercolor.y, pev->rendercolor.z, pev->renderamt, pev->renderfx); m_pSprite->SetTransparency(kRenderGlow, pev->rendercolor.x, pev->rendercolor.y, pev->rendercolor.z, pev->renderamt, pev->renderfx);
@ -853,6 +920,33 @@ void CLaser::Spawn()
TurnOn(); 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() void CLaser::Precache()
{ {
pev->modelindex = PRECACHE_MODEL((char *)STRING(pev->model)); pev->modelindex = PRECACHE_MODEL((char *)STRING(pev->model));

View File

@ -202,6 +202,10 @@ public:
virtual int Restore(CRestore &restore); virtual int Restore(CRestore &restore);
virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value); virtual void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value);
#ifdef REGAMEDLL_FIXES
virtual void Restart();
#endif
public: public:
void TurnOn(); void TurnOn();
void TurnOff(); void TurnOff();
@ -253,6 +257,10 @@ public:
virtual int Restore(CRestore &restore); virtual int Restore(CRestore &restore);
virtual void Activate(); virtual void Activate();
#ifdef REGAMEDLL_FIXES
virtual void Restart();
#endif
public: public:
void EXPORT StrikeThink(); void EXPORT StrikeThink();
void EXPORT DamageThink(); void EXPORT DamageThink();
@ -274,7 +282,7 @@ public:
public: public:
static TYPEDESCRIPTION m_SaveData[]; static TYPEDESCRIPTION m_SaveData[];
int m_active; BOOL m_active;
int m_iszStartEntity; int m_iszStartEntity;
int m_iszEndEntity; int m_iszEndEntity;
float m_life; float m_life;

View File

@ -138,7 +138,7 @@ void Broadcast(const char *sentence)
MESSAGE_BEGIN(MSG_BROADCAST, gmsgSendAudio); MESSAGE_BEGIN(MSG_BROADCAST, gmsgSendAudio);
WRITE_BYTE(0); WRITE_BYTE(0);
WRITE_STRING(text); WRITE_STRING(text);
WRITE_SHORT(100); WRITE_SHORT(PITCH_NORM);
MESSAGE_END(); MESSAGE_END();
} }
@ -575,6 +575,7 @@ void EXT_FUNC CHalfLifeMultiplay::__API_HOOK(CleanUpMap)()
UTIL_RestartOther("func_button"); UTIL_RestartOther("func_button");
UTIL_RestartOther("func_rot_button"); UTIL_RestartOther("func_rot_button");
UTIL_RestartOther("env_render"); UTIL_RestartOther("env_render");
UTIL_RestartOther("env_spark");
UTIL_RestartOther("trigger_push"); UTIL_RestartOther("trigger_push");
#endif #endif
@ -590,7 +591,10 @@ void EXT_FUNC CHalfLifeMultiplay::__API_HOOK(CleanUpMap)()
#ifdef REGAMEDLL_FIXES #ifdef REGAMEDLL_FIXES
UTIL_RestartOther("trigger_once"); UTIL_RestartOther("trigger_once");
UTIL_RestartOther("func_wall_toggle"); UTIL_RestartOther("func_wall_toggle");
UTIL_RestartOther("trigger_hurt");
UTIL_RestartOther("multisource"); UTIL_RestartOther("multisource");
UTIL_RestartOther("env_beam");
UTIL_RestartOther("env_laser");
UTIL_RestartOther("trigger_auto"); UTIL_RestartOther("trigger_auto");
#endif #endif

View File

@ -221,7 +221,6 @@ public:
#ifdef REGAMEDLL_FIXES #ifdef REGAMEDLL_FIXES
virtual void Restart(); virtual void Restart();
virtual int ObjectCaps() { return (CBaseTrigger::ObjectCaps() | FCAP_MUST_RESET); }
#endif #endif
void EXPORT RadiationThink(); void EXPORT RadiationThink();