-
Notifications
You must be signed in to change notification settings - Fork 20
Ghost Boundary #1271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
DESTROYGIRL
merged 3 commits into
NeotokyoRebuild:master
from
DESTROYGIRL:ghost_boundry
Aug 16, 2025
Merged
Ghost Boundary #1271
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| #include "neo_ghost_boundary.h" | ||
| #include "neo_gamerules.h" | ||
| #include "weapon_ghost.h" | ||
|
|
||
| #define THINK_INTERVAL 0.05f | ||
| #define GHOST_ANGLES QAngle(15, 0, 270) // Angles the ghost will reset to (laid on its back) | ||
|
|
||
| //############################## | ||
| // Trigger Weapon | ||
| //############################## | ||
|
|
||
| LINK_ENTITY_TO_CLASS(neo_trigger_weapon, CNEO_TriggerWeapon); | ||
|
|
||
| BEGIN_DATADESC(CNEO_TriggerWeapon) | ||
| DEFINE_THINKFUNC(Think), | ||
| END_DATADESC() | ||
|
|
||
| void CNEO_TriggerWeapon::Spawn() | ||
| { | ||
| BaseClass::Spawn(); | ||
| InitTrigger(); | ||
|
|
||
| SetNextThink(gpGlobals->curtime + THINK_INTERVAL); | ||
| } | ||
|
|
||
| void CNEO_TriggerWeapon::Think() | ||
| { | ||
| CheckForWeapon(); | ||
| SetNextThink(gpGlobals->curtime + THINK_INTERVAL); | ||
| } | ||
|
|
||
| // Weapons have the FSOLID_TRIGGER solidflag which is why they can't be used in triggers. | ||
| // If we remove it weapons can't be picked up by walking over them. | ||
|
|
||
| // NEO TODO DG: When there is a use for it improve this so it functions as expected- like other triggers. | ||
| // What's here is fine for the ghost boundary but using this trigger for weapons will spam StartTouch every think | ||
| void CNEO_TriggerWeapon::CheckForWeapon() | ||
| { | ||
| Vector mins, maxs; | ||
| CollisionProp()->WorldSpaceAABB(&mins, &maxs); | ||
|
|
||
| CBaseEntity* pEntList[128]; | ||
| int count = UTIL_EntitiesInBox(pEntList, ARRAYSIZE(pEntList), mins, maxs, 0); // Low accuracy | ||
|
|
||
| for (int i = 0; i < count; ++i) | ||
| { | ||
| CBaseEntity* pEnt = pEntList[i]; | ||
|
|
||
| if (!pEnt->IsBaseCombatWeapon()) | ||
| { | ||
| continue; | ||
| } | ||
|
|
||
| if (pEnt->GetOwnerEntity()) | ||
| { | ||
| continue; | ||
| } | ||
|
|
||
| if (IsEntityInside(pEnt)) // High(er) accuracy | ||
| { | ||
| StartTouch(pEnt); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| bool CNEO_TriggerWeapon::IsEntityInside(CBaseEntity* pEnt) | ||
| { | ||
| trace_t tr; | ||
| Vector point = pEnt->WorldSpaceCenter(); | ||
| UTIL_TraceModel(point, point, pEnt->CollisionProp()->OBBMins(), pEnt->CollisionProp()->OBBMaxs(), this, COLLISION_GROUP_NONE, &tr); | ||
|
|
||
| return tr.startsolid; // If the trace started inside the trigger or not | ||
| } | ||
|
|
||
|
|
||
| //############################## | ||
| // Ghost Boundary | ||
| //############################## | ||
|
|
||
| LINK_ENTITY_TO_CLASS(neo_ghost_boundary, CNEO_GhostBoundary); | ||
|
|
||
| BEGIN_DATADESC(CNEO_GhostBoundary) | ||
| DEFINE_THINKFUNC(Think), | ||
| END_DATADESC() | ||
|
|
||
| void CNEO_GhostBoundary::Think() | ||
| { | ||
| BaseClass::Think(); | ||
|
|
||
| if (!NEORules()->GhostExists()) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| int iGhosterIndex = NEORules()->GetGhosterPlayer(); | ||
| if (iGhosterIndex == 0) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| CBasePlayer* pPlayer = UTIL_PlayerByIndex(iGhosterIndex); | ||
| if (pPlayer->GetFlags() & FL_ONGROUND) | ||
| { | ||
| m_vecLastGhosterPos = pPlayer->GetAbsOrigin(); | ||
| } | ||
| } | ||
|
|
||
| void CNEO_GhostBoundary::StartTouch(CBaseEntity *pOther) | ||
| { | ||
| BaseClass::StartTouch(pOther); | ||
|
|
||
| Vector vecGhostSpawn = NEORules()->m_vecPreviousGhostSpawn; | ||
| if ((vecGhostSpawn == vec3_origin) && (m_vecLastGhosterPos == vec3_origin)) | ||
| { | ||
| return; // Don't bother teleporting if there's no ghost spawn and no ghoster pos | ||
| } | ||
|
|
||
| auto pDroppedGhost = (pOther && pOther->IsBaseCombatWeapon() && static_cast<CNEOBaseCombatWeapon*>(pOther)->IsGhost()) | ||
| ? static_cast<CWeaponGhost*>(pOther) : nullptr; | ||
| if (pDroppedGhost) | ||
| { | ||
| if (m_vecLastGhosterPos == vec3_origin) | ||
| { | ||
| pDroppedGhost->VPhysicsGetObject()->SetPosition(vecGhostSpawn, GHOST_ANGLES, true); | ||
| // Don't freeze it, ghosts aren't frozen when they spawn | ||
| } | ||
| else | ||
| { | ||
| pDroppedGhost->VPhysicsGetObject()->SetPosition(m_vecLastGhosterPos, GHOST_ANGLES, true); | ||
| pDroppedGhost->VPhysicsGetObject()->EnableMotion(false); | ||
| } | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| CNEO_Player *pNEOPlayer = ToNEOPlayer(pOther); | ||
| if (pNEOPlayer && pNEOPlayer->IsCarryingGhost()) | ||
| { | ||
| CBaseCombatWeapon* pHeldGhost = pNEOPlayer->Weapon_OwnsThisType("weapon_ghost"); | ||
| pNEOPlayer->Weapon_Drop(pHeldGhost); | ||
|
|
||
| pHeldGhost->VPhysicsGetObject()->SetPosition(m_vecLastGhosterPos, GHOST_ANGLES, true); | ||
| pHeldGhost->VPhysicsGetObject()->EnableMotion(false); | ||
|
|
||
| return; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| #pragma once | ||
| #include "cbase.h" | ||
| #include "triggers.h" | ||
|
|
||
| class CNEO_TriggerWeapon : public CBaseTrigger | ||
| { | ||
| public: | ||
| DECLARE_CLASS(CNEO_TriggerWeapon, CBaseTrigger); | ||
| DECLARE_DATADESC(); | ||
|
|
||
| virtual void Spawn() override; | ||
| virtual void Think() override; | ||
|
|
||
| private: | ||
| void CheckForWeapon(); | ||
| bool IsEntityInside(CBaseEntity* pEnt); | ||
| }; | ||
|
|
||
| class CNEO_GhostBoundary : public CNEO_TriggerWeapon | ||
| { | ||
| public: | ||
| DECLARE_CLASS(CNEO_GhostBoundary, CNEO_TriggerWeapon); | ||
| DECLARE_DATADESC(); | ||
|
|
||
| virtual void Think() override; | ||
| virtual void StartTouch(CBaseEntity *pOther) override; | ||
|
|
||
| private: | ||
| Vector m_vecLastGhosterPos = vec3_origin; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.