From bc3a83936662b71f11d09b709165f1206b89178c Mon Sep 17 00:00:00 2001 From: ScriptedSnark <51358194+ScriptedSnark@users.noreply.github.com> Date: Tue, 12 Mar 2024 19:04:17 +0500 Subject: [PATCH] Add "Need for Speed" effect --- GSChaos/CChaos.cpp | 1 + GSChaos/CFeatureNeedForSpeed.cpp | 87 ++++++++++++++++++++++++++++++++ GSChaos/CFeatureNeedForSpeed.h | 47 +++++++++++++++++ GSChaos/GSChaos.vcxproj | 2 + GSChaos/GSChaos.vcxproj.filters | 6 +++ GSChaos/includes.h | 1 + README.md | 1 + 7 files changed, 145 insertions(+) create mode 100644 GSChaos/CFeatureNeedForSpeed.cpp create mode 100644 GSChaos/CFeatureNeedForSpeed.h diff --git a/GSChaos/CChaos.cpp b/GSChaos/CChaos.cpp index b2dd9708..c118cc24 100644 --- a/GSChaos/CChaos.cpp +++ b/GSChaos/CChaos.cpp @@ -95,6 +95,7 @@ void CChaos::FeatureInit() RegisterChaosFeature(); RegisterChaosFeature(); RegisterChaosFeature(); + RegisterChaosFeature(); RegisterChaosFeature(); // must be last!!! diff --git a/GSChaos/CFeatureNeedForSpeed.cpp b/GSChaos/CFeatureNeedForSpeed.cpp new file mode 100644 index 00000000..9bdae76f --- /dev/null +++ b/GSChaos/CFeatureNeedForSpeed.cpp @@ -0,0 +1,87 @@ +#include "includes.h" + +void CFeatureNeedForSpeed::Init() +{ + CChaosFeature::Init(); +} + +void CFeatureNeedForSpeed::ActivateFeature() +{ + CChaosFeature::ActivateFeature(); + m_bActivated = true; + + m_flTimeToFail = gChaos.GetGlobalTime() + NFS_INIT_FAIL_TIME; +} + +void CFeatureNeedForSpeed::DeactivateFeature() +{ + CChaosFeature::DeactivateFeature(); + m_bActivated = false; +} + +void CFeatureNeedForSpeed::OnFrame(double time) +{ + if (!m_bActivated) + return; + + Vector velocity = (*sv_player)->v.velocity; + if (velocity.Length2D() < NFS_REQUIRED_SPEED) + { + if (gChaos.GetGlobalTime() > m_flTimeToFail) + { + Explode(); + m_bActivated = false; + } + } + else + m_flTimeToFail = gChaos.GetGlobalTime() + NFS_FAIL_TIME; +} + +void CFeatureNeedForSpeed::Draw() +{ + if (!m_bActivated) + return; + + char buffer[64]; + snprintf(buffer, sizeof(buffer), "%.01f | STAY ABOVE 500 UPS!", (*sv_player)->v.velocity.Length2D()); + + ImGui::PushFont(gChaos.m_fontTrebuchet); + + ImVec2 pos = ImVec2((ImGui::GetIO().DisplaySize.x * 0.5f) - (ImGui::CalcTextSize(buffer).x * 0.5f), ImGui::GetIO().DisplaySize.y * 0.1f); + ImGui::GetForegroundDrawList()->AddText(ImVec2(pos.x + 2, pos.y + 2), ImGui::GetColorU32(ImVec4(0.0f, 0.0f, 0.0f, 1.0f)), buffer); + ImGui::GetForegroundDrawList()->AddText(pos, ImGui::GetColorU32(ImVec4(1.0f, 0.627f, 0.0f, 1.0f)), buffer); + + ImGui::PopFont(); +} + +void CFeatureNeedForSpeed::Explode() // TODO: make this thing public for every class (move to Utils.cpp) +{ + if (!m_bActivated) + return; + + // create explosion + edict_t* pent = CREATE_NAMED_ENTITY(MAKE_STRING("rpg_rocket")); + if (!pent) + { + // heart attack :DDD + (*sv_player)->v.health = -20; + return; + } + + gEntityInterface->pfnSpawn(pent); + gEntityInterface->pfnThink(pent); + + pent->v.origin = (*sv_player)->v.origin; + pent->v.angles = (*sv_player)->v.angles; + pent->v.dmg = 1000; + pent->v.dmgtime = 1.0f; + pent->v.nextthink = gpGlobals->time + 0.1f; + + gEntityInterface->pfnTouch((*sv_player), pent); + gEntityInterface->pfnTouch(pent, (*sv_player)); +} + +const char* CFeatureNeedForSpeed::GetFeatureName() +{ + return "Need for Speed"; +} \ No newline at end of file diff --git a/GSChaos/CFeatureNeedForSpeed.h b/GSChaos/CFeatureNeedForSpeed.h new file mode 100644 index 00000000..44ced598 --- /dev/null +++ b/GSChaos/CFeatureNeedForSpeed.h @@ -0,0 +1,47 @@ +/** + * Copyright - ScriptedSnark, 2024. + * CFeatureNeedForSpeed.h + * + * Project (GSChaos) header file + * Authors: ScriptedSnark. + * Do not delete this comment block. Respect others' work! + */ + +#ifdef CFEATURENEEDFORSPEED_H_RECURSE_GUARD +#error Recursive header files inclusion detected in CFeatureNeedForSpeed.h +#else //CFEATURENEEDFORSPEED_H_RECURSE_GUARD + +#define CFEATURENEEDFORSPEED_H_RECURSE_GUARD + +#ifndef CFEATURENEEDFORSPEED_H_GUARD +#define CFEATURENEEDFORSPEED_H_GUARD +#pragma once + +#ifdef __cplusplus + +#define NFS_REQUIRED_SPEED 500.0f +#define NFS_INIT_FAIL_TIME 1.5 +#define NFS_FAIL_TIME 0.35 + +class CFeatureNeedForSpeed : public CChaosFeature +{ + void Init() override; + void ActivateFeature() override; + void DeactivateFeature() override; + void OnFrame(double time) override; + void Draw() override; + void Explode(); + const char* GetFeatureName() override; +private: + bool m_bActivated; + double m_flTimeToFail; +}; + +#else //!__cplusplus +#error C++ compiler required to compile CFeatureNeedForSpeed.h +#endif //__cplusplus + +#endif //CFEATURENEEDFORSPEED_H_GUARD + +#undef CFEATURENEEDFORSPEED_H_RECURSE_GUARD +#endif //CFEATURENEEDFORSPEED_H_RECURSE_GUARD \ No newline at end of file diff --git a/GSChaos/GSChaos.vcxproj b/GSChaos/GSChaos.vcxproj index 82ffbe13..e4696bab 100644 --- a/GSChaos/GSChaos.vcxproj +++ b/GSChaos/GSChaos.vcxproj @@ -139,6 +139,7 @@ + @@ -214,6 +215,7 @@ + diff --git a/GSChaos/GSChaos.vcxproj.filters b/GSChaos/GSChaos.vcxproj.filters index ec919402..116bf36c 100644 --- a/GSChaos/GSChaos.vcxproj.filters +++ b/GSChaos/GSChaos.vcxproj.filters @@ -173,6 +173,9 @@ Effects + + Effects + @@ -404,6 +407,9 @@ Effects + + Effects + diff --git a/GSChaos/includes.h b/GSChaos/includes.h index ec270032..c526e202 100644 --- a/GSChaos/includes.h +++ b/GSChaos/includes.h @@ -130,6 +130,7 @@ extern bool g_bEncrypted; #include "CFeatureGravityField.h" #include "CFeatureIceSkating.h" #include "CFeatureInvertVelocity.h" +#include "CFeatureNeedForSpeed.h" #include "CFeatureCombineEffects.h" //======================== diff --git a/README.md b/README.md index df9783db..18e918ee 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,7 @@ Additional info: > Hyper Gravity Field > Ice Skating > Invert Velocity +> Need for Speed (500 ups curse) > Combine Effects ( 3 in 1 ) ```