Skip to content

Commit

Permalink
Add team based blocking and options to turn blocking on
Browse files Browse the repository at this point in the history
* New convar: neo_sv_collision
    * 0 (default) - No blocking at all
    * 1 - Team-based blocking
    * 2 - All players blocking
  • Loading branch information
nullsystem committed Oct 7, 2024
1 parent 7f8390b commit c6bd62a
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
29 changes: 29 additions & 0 deletions mp/src/game/shared/neo/neo_gamerules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,17 @@ ConVar neo_sv_suicide_prevent_cap_punish("neo_sv_suicide_prevent_cap_punish", "1
true, 0.0f, true, 1.0f);
#endif

enum ENeoCollision
{
NEOCOLLISION_NONE = 0,
NEOCOLLISION_TEAM,
NEOCOLLISION_ALL,

NEOCOLLISION__TOTAL,
};

ConVar neo_sv_collision("neo_sv_collision", "0", FCVAR_REPLICATED, "0 = No collision (default), 1 = Team-based collision, 2 = All player collision", true, 0.0f, true, NEOCOLLISION__TOTAL - 1);

REGISTER_GAMERULES_CLASS( CNEORules );

BEGIN_NETWORK_TABLE_NOBASE( CNEORules, DT_NEORules )
Expand Down Expand Up @@ -438,6 +449,23 @@ int CNEORules::DefaultFOV(void)
#endif
}

bool CNEORules::ShouldCollide(const CBaseEntity *ent0, const CBaseEntity *ent1) const
{
const int ent0Group = ent0->GetCollisionGroup();
const int ent1Group = ent1->GetCollisionGroup();
const int iNeoCol = neo_sv_collision.GetInt();
if (iNeoCol != NEOCOLLISION_ALL &&
(ent0Group == COLLISION_GROUP_PLAYER || ent0Group == COLLISION_GROUP_PLAYER_MOVEMENT) &&
(ent1Group == COLLISION_GROUP_PLAYER || ent1Group == COLLISION_GROUP_PLAYER_MOVEMENT))
{
auto *ent0Player = static_cast<const CNEO_Player *>(ent0);
auto *ent1Player = static_cast<const CNEO_Player *>(ent1);
return (iNeoCol == NEOCOLLISION_TEAM) ? (ent0Player->GetTeamNumber() != ent1Player->GetTeamNumber()) : false;
}
return const_cast<CNEORules *>(this)->CTeamplayRules::ShouldCollide(ent0Group, ent1Group);
}

#if 0
bool CNEORules::ShouldCollide(int collisionGroup0, int collisionGroup1)
{
if (collisionGroup0 > collisionGroup1)
Expand All @@ -455,6 +483,7 @@ bool CNEORules::ShouldCollide(int collisionGroup0, int collisionGroup1)

return CTeamplayRules::ShouldCollide(collisionGroup0, collisionGroup1);
}
#endif

extern ConVar mp_chattime;

Expand Down
3 changes: 2 additions & 1 deletion mp/src/game/shared/neo/neo_gamerules.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ class CNEORules : public CHL2MPRules, public CGameEventListener

virtual void ClientDisconnected(edict_t* pClient) OVERRIDE;
#endif
virtual bool ShouldCollide( int collisionGroup0, int collisionGroup1 ) OVERRIDE;
bool ShouldCollide(const CBaseEntity *ent0, const CBaseEntity *ent1) const;
//virtual bool ShouldCollide( int collisionGroup0, int collisionGroup1 ) OVERRIDE;

virtual const char* GetGameName() { return NEO_GAME_NAME; }

Expand Down
20 changes: 20 additions & 0 deletions mp/src/game/shared/util_shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
bool NPC_CheckBrushExclude( CBaseEntity *pEntity, CBaseEntity *pBrush );
#endif

#ifdef NEO
#include "neo_gamerules.h"
#endif


// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
Expand Down Expand Up @@ -301,8 +305,24 @@ bool CTraceFilterSimple::ShouldHitEntity( IHandleEntity *pHandleEntity, int cont
return false;
if ( !pEntity->ShouldCollide( m_collisionGroup, contentsMask ) )
return false;
#ifdef NEO
if (m_pPassEnt)
{
const CBaseEntity *pThisEntity = EntityFromEntityHandle(m_pPassEnt);
if (pEntity && pThisEntity && !static_cast<CNEORules *>(g_pGameRules)->ShouldCollide(pThisEntity, pEntity))
{
return false;
}
}
else
{
if ( pEntity && !g_pGameRules->ShouldCollide( m_collisionGroup, pEntity->GetCollisionGroup() ) )
return false;
}
#else
if ( pEntity && !g_pGameRules->ShouldCollide( m_collisionGroup, pEntity->GetCollisionGroup() ) )
return false;
#endif
if ( m_pExtraShouldHitCheckFunction &&
(! ( m_pExtraShouldHitCheckFunction( pHandleEntity, contentsMask ) ) ) )
return false;
Expand Down

0 comments on commit c6bd62a

Please sign in to comment.