Skip to content

Commit

Permalink
Add "Gravity Field" effect
Browse files Browse the repository at this point in the history
  • Loading branch information
ScriptedSnark committed Mar 11, 2024
1 parent 8456c6c commit 1634608
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 0 deletions.
1 change: 1 addition & 0 deletions GSChaos/CChaos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ void CChaos::FeatureInit()
RegisterChaosFeature<CFeatureUpsideDown>();
RegisterChaosFeature<CFeatureNPCExplode>();
RegisterChaosFeature<CFeatureJeepy>();
RegisterChaosFeature<CFeatureGravityField>();

RegisterChaosFeature<CFeatureCombineEffects>(); // must be last!!!

Expand Down
68 changes: 68 additions & 0 deletions GSChaos/CFeatureGravityField.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#include "includes.h"

// From engine's mathlib.c
float Length(const vec3_t v)
{
int i;
float length;

length = 0;
for (i = 0; i < 3; i++)
length += v[i] * v[i];
length = static_cast<float>(sqrt(length)); // FIXME

return length;
}

void CFeatureGravityField::Init()
{
CChaosFeature::Init();
}

void CFeatureGravityField::ActivateFeature()
{
CChaosFeature::ActivateFeature();
m_bActivated = true;
}

void CFeatureGravityField::DeactivateFeature()
{
CChaosFeature::DeactivateFeature();
m_bActivated = false;
}

void CFeatureGravityField::OnFrame(double time)
{
if (!m_bActivated)
return;

if (CLWrapper::GetPausedState())
return;

// point of no return
edict_t* e;
for (int i = 1; i < sv->num_edicts; i++)
{
e = ORIG_EDICT_NUM(i);
if (e && !e->free)
{
if (e->v.flags & FL_CLIENT)
continue;

(*sv_player)->v.flags |= FL_GODMODE; // this effect is too crazy for player's health :DDD

Vector target = (*sv_player)->v.origin - e->v.origin;

float distance = Length(target);
Vector direction = target / distance;
Vector velocity = direction * MAGNET_SPEED;

e->v.velocity = velocity;
}
}
}

const char* CFeatureGravityField::GetFeatureName()
{
return "Hyper Gravity Field";
}
42 changes: 42 additions & 0 deletions GSChaos/CFeatureGravityField.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Copyright - ScriptedSnark, 2024.
* CFeatureGravityField.h
*
* Project (GSChaos) header file
* Authors: ScriptedSnark.
* Do not delete this comment block. Respect others' work!
*/

#ifdef CFEATUREGRAVITYFIELD_H_RECURSE_GUARD
#error Recursive header files inclusion detected in CFeatureGravityField.h
#else //CFEATUREGRAVITYFIELD_H_RECURSE_GUARD

#define CFEATUREGRAVITYFIELD_H_RECURSE_GUARD

#ifndef CFEATUREGRAVITYFIELD_H_GUARD
#define CFEATUREGRAVITYFIELD_H_GUARD
#pragma once

#ifdef __cplusplus

#define MAGNET_SPEED 1500.0f

class CFeatureGravityField : public CChaosFeature
{
void Init() override;
void ActivateFeature() override;
void DeactivateFeature() override;
void OnFrame(double time) override;
const char* GetFeatureName() override;
private:
bool m_bActivated;
};

#else //!__cplusplus
#error C++ compiler required to compile CFeatureGravityField.h
#endif //__cplusplus

#endif //CFEATUREGRAVITYFIELD_H_GUARD

#undef CFEATUREGRAVITYFIELD_H_RECURSE_GUARD
#endif //CFEATUREGRAVITYFIELD_H_RECURSE_GUARD
2 changes: 2 additions & 0 deletions GSChaos/GSChaos.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
<ClCompile Include="CFeatureGiveGauss.cpp" />
<ClCompile Include="CFeatureGlobalGodMode.cpp" />
<ClCompile Include="CFeatureGodMode.cpp" />
<ClCompile Include="CFeatureGravityField.cpp" />
<ClCompile Include="CFeatureGrieferShephard.cpp" />
<ClCompile Include="CFeatureGruntAmbush.cpp" />
<ClCompile Include="CFeatureGTA2Camera.cpp" />
Expand Down Expand Up @@ -199,6 +200,7 @@
<ClInclude Include="CFeatureGiveGauss.h" />
<ClInclude Include="CFeatureGlobalGodMode.h" />
<ClInclude Include="CFeatureGodMode.h" />
<ClInclude Include="CFeatureGravityField.h" />
<ClInclude Include="CFeatureGrieferShephard.h" />
<ClInclude Include="CFeatureGruntAmbush.h" />
<ClInclude Include="CFeatureGTA2Camera.h" />
Expand Down
6 changes: 6 additions & 0 deletions GSChaos/GSChaos.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@
<ClCompile Include="..\external\imgui\backends\imgui_impl_opengl3.cpp">
<Filter>ImGUI</Filter>
</ClCompile>
<ClCompile Include="CFeatureGravityField.cpp">
<Filter>Effects</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="includes.h" />
Expand Down Expand Up @@ -386,6 +389,9 @@
<ClInclude Include="..\external\imgui\backends\imgui_impl_opengl3.h">
<Filter>ImGUI</Filter>
</ClInclude>
<ClInclude Include="CFeatureGravityField.h">
<Filter>Effects</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="Hooking">
Expand Down
1 change: 1 addition & 0 deletions GSChaos/includes.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ extern bool g_bEncrypted;
#include "CFeatureUpsideDown.h"
#include "CFeatureNPCExplode.h"
#include "CFeatureJeepy.h"
#include "CFeatureGravityField.h"

#include "CFeatureCombineEffects.h"
//========================
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Additional info:
> Upside Down
> Every NPC explodes
> Let's see Jeepy's lasagna
> Hyper Gravity Field
> Combine Effects ( 3 in 1 )
```

Expand Down

0 comments on commit 1634608

Please sign in to comment.