Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/game/server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1368,6 +1368,8 @@ target_sources_grouped(
neo/neo_detpack.h
neo/neo_game_config.cpp
neo/neo_game_config.h
neo/neo_ghost_boundary.cpp
neo/neo_ghost_boundary.h
neo/neo_ghost_spawn_point.cpp
neo/neo_ghost_spawn_point.h
neo/neo_grenade.cpp
Expand Down
147 changes: 147 additions & 0 deletions src/game/server/neo/neo_ghost_boundary.cpp
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;
}
}
30 changes: 30 additions & 0 deletions src/game/server/neo/neo_ghost_boundary.h
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;
};
1 change: 1 addition & 0 deletions src/game/shared/neo/neo_gamerules.h
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ class CNEORules : public CHL2MPRules, public CGameEventListener
int m_iEntPrevCapSize = 0;
int m_iPrintHelpCounter = 0;
bool m_bGamemodeTypeBeenInitialized = false;
friend class CNEO_GhostBoundary;
Vector m_vecPreviousGhostSpawn = vec3_origin;
#endif
CNetworkVar(int, m_nRoundStatus);
Expand Down
Loading