diff --git a/regamedll/dlls/buttons.cpp b/regamedll/dlls/buttons.cpp index 0e19bc41..cecdd6ae 100644 --- a/regamedll/dlls/buttons.cpp +++ b/regamedll/dlls/buttons.cpp @@ -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)); @@ -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"); diff --git a/regamedll/dlls/buttons.h b/regamedll/dlls/buttons.h index 7638d62a..62ae7a38 100644 --- a/regamedll/dlls/buttons.h +++ b/regamedll/dlls/buttons.h @@ -126,6 +126,10 @@ public: 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); diff --git a/regamedll/dlls/effects.cpp b/regamedll/dlls/effects.cpp index b5db0755..947a74aa 100644 --- a/regamedll/dlls/effects.cpp +++ b/regamedll/dlls/effects.cpp @@ -340,27 +340,32 @@ 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 = 0; + m_active = FALSE; + if (!FStringNull(pev->targetname)) { SetUse(&CLightning::StrikeUse); } + if (FStringNull(pev->targetname) || (pev->spawnflags & SF_BEAM_STARTON)) { 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() { m_spriteTexture = PRECACHE_MODEL((char *)STRING(m_iszSpriteName)); @@ -378,7 +439,9 @@ void CLightning::Precache() void CLightning::Activate() { if (ServerSide()) + { BeamUpdateVars(); + } } void CLightning::KeyValue(KeyValueData *pkvd) @@ -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()); @@ -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 @@ -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)) { @@ -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); @@ -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)); diff --git a/regamedll/dlls/effects.h b/regamedll/dlls/effects.h index c63d46f4..17a17ef8 100644 --- a/regamedll/dlls/effects.h +++ b/regamedll/dlls/effects.h @@ -202,6 +202,10 @@ public: 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(); @@ -253,6 +257,10 @@ public: virtual int Restore(CRestore &restore); virtual void Activate(); +#ifdef REGAMEDLL_FIXES + virtual void Restart(); +#endif + public: void EXPORT StrikeThink(); void EXPORT DamageThink(); @@ -274,7 +282,7 @@ public: public: static TYPEDESCRIPTION m_SaveData[]; - int m_active; + BOOL m_active; int m_iszStartEntity; int m_iszEndEntity; float m_life; diff --git a/regamedll/dlls/multiplay_gamerules.cpp b/regamedll/dlls/multiplay_gamerules.cpp index 481814d8..ecb94ee1 100644 --- a/regamedll/dlls/multiplay_gamerules.cpp +++ b/regamedll/dlls/multiplay_gamerules.cpp @@ -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(); } @@ -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 @@ -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 diff --git a/regamedll/dlls/triggers.h b/regamedll/dlls/triggers.h index 86f85aa1..eee9a25a 100644 --- a/regamedll/dlls/triggers.h +++ b/regamedll/dlls/triggers.h @@ -221,7 +221,6 @@ public: #ifdef REGAMEDLL_FIXES virtual void Restart(); - virtual int ObjectCaps() { return (CBaseTrigger::ObjectCaps() | FCAP_MUST_RESET); } #endif void EXPORT RadiationThink();