Skip to content

Commit ddc62cf

Browse files
committed
Fixes: Weapons: Revised radiation volume.
1 parent 087e155 commit ddc62cf

1 file changed

Lines changed: 35 additions & 8 deletions

File tree

src/game/server/swarm/asw_radiation_volume.cpp

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void CASW_Radiation_Volume::Spawn( void )
4444
AddEffects(EF_NODRAW);
4545
SetSolid( SOLID_BBOX );
4646
float boxWidth = m_flBoxWidth;
47-
UTIL_SetSize(this, Vector(-boxWidth,-boxWidth,0),Vector(boxWidth,boxWidth,boxWidth * 2));
47+
UTIL_SetSize( this, Vector( -boxWidth, -boxWidth, 0 ), Vector( boxWidth, boxWidth, boxWidth ) );
4848
SetCollisionGroup(ASW_COLLISION_GROUP_PASSABLE);
4949
AddSolidFlags(FSOLID_TRIGGER | FSOLID_NOT_SOLID);
5050
SetTouch( &CASW_Radiation_Volume::RadTouch );
@@ -61,25 +61,52 @@ bool CASW_Radiation_Volume::IsValidRadTarget( CBaseEntity *pOther )
6161
return pOther->IsNPC();
6262
}
6363

64-
void CASW_Radiation_Volume::RadTouch( CBaseEntity *pOther )
64+
void CASW_Radiation_Volume::RadTouch( CBaseEntity* pOther )
6565
{
6666
// if other is a valid entity to radiate, add it to our list
67-
if (IsValidRadTarget(pOther) && m_hRadTouching.Find(pOther) == m_hRadTouching.InvalidIndex())
67+
if ( !IsValidRadTarget( pOther ) )
68+
return;
69+
70+
// Treat m_flBoxWidth as radius:
71+
float flRadius = m_flBoxWidth;
72+
73+
// If entity has a collision prop, compute nearest point and test 3D distance (sphere)
74+
if ( pOther->CollisionProp() )
75+
{
76+
Vector vecNearest;
77+
pOther->CollisionProp()->CalcNearestPoint( GetAbsOrigin(), &vecNearest );
78+
79+
Vector vecDelta = vecNearest - GetAbsOrigin();
80+
if ( vecDelta.Length() > flRadius )
81+
return; // outside the sphere
82+
}
83+
84+
if ( m_hRadTouching.Find( pOther ) == m_hRadTouching.InvalidIndex() )
6885
{
69-
m_hRadTouching.AddToTail(pOther);
70-
if (GetNextThink() == TICK_NEVER_THINK)
86+
m_hRadTouching.AddToTail( pOther );
87+
if ( GetNextThink() == TICK_NEVER_THINK )
7188
SetNextThink( gpGlobals->curtime );
7289
}
7390
}
7491

75-
bool CASW_Radiation_Volume::RadTouching(CBaseEntity *pEnt)
92+
bool CASW_Radiation_Volume::RadTouching( CBaseEntity* pEnt )
7693
{
77-
if (!pEnt || !pEnt->CollisionProp() || !CollisionProp())
94+
if ( !pEnt || !pEnt->CollisionProp() )
7895
return false;
7996

97+
// Treat m_flBoxWidth as radius:
98+
float flRadius = m_flBoxWidth;
99+
100+
// nearest point on the entity to our center
80101
Vector vecNearest;
81102
pEnt->CollisionProp()->CalcNearestPoint( GetAbsOrigin(), &vecNearest );
82-
return CollisionProp()->IsPointInBounds(vecNearest);
103+
104+
// Sphere test (3D)
105+
Vector vecDelta = vecNearest - GetAbsOrigin();
106+
if ( vecDelta.Length() > flRadius )
107+
return false; // outside the sphere
108+
109+
return true;
83110
}
84111

85112
void CASW_Radiation_Volume::RadHurt(CBaseEntity *pEnt)

0 commit comments

Comments
 (0)