@@ -61,61 +61,8 @@ bool CASW_Radiation_Volume::IsValidRadTarget( CBaseEntity *pOther )
6161 return pOther->IsNPC ();
6262}
6363
64- void CASW_Radiation_Volume::RadTouch ( CBaseEntity* pOther )
65- {
66- // if other is a valid entity to radiate, add it to our list
67- if ( !IsValidRadTarget ( pOther ) )
68- return ;
69-
70- // m_flBoxWidth used as radius:
71- const float flRadius = m_flBoxWidth;
72- const float flRadiusSqr = flRadius * flRadius;
73-
74- const Vector vecCenter = GetAbsOrigin ();
75- CCollisionProperty* pOtherColl = pOther->CollisionProp (); // cache
76- CCollisionProperty* pVolColl = CollisionProp (); // cache
77- if ( !pVolColl )
78- return ;
79-
80- // compute the nearest point on the other entity to our center (robust for large NPCs)
81- Vector vecNearest;
82- if ( pOtherColl )
83- pOtherColl->CalcNearestPoint ( vecCenter, &vecNearest );
84- else
85- vecNearest = pOther->WorldSpaceCenter ();
86-
87- // If other is a marine, use CYLINDER test:
88- // - horizontal (XY) distance < radius
89- // - AND the nearest point must be within our cuboid bounds (so Z is constrained by the volume)
90- if ( pOther->Classify () == CLASS_ASW_MARINE )
91- {
92- // must be within our cuboid in Z (IsPointInBounds) and within horizontal radius
93- if ( pVolColl->IsPointInBounds ( vecNearest ) )
94- {
95- // horizontal delta (XY)
96- Vector vecDelta = vecNearest - vecCenter;
97- // horizontal distance squared check (circle)
98- if ( ( vecDelta.x * vecDelta.x + vecDelta.y * vecDelta.y ) >= flRadiusSqr )
99- return ;
100- }
101- }
102- else
103- {
104- // aliens: full cuboid check only
105- if ( !pVolColl->IsPointInBounds ( vecNearest ) )
106- return ;
107- }
108-
109- // avoid duplicates
110- if ( m_hRadTouching.Find ( pOther ) == m_hRadTouching.InvalidIndex () )
111- {
112- m_hRadTouching.AddToTail ( pOther );
113- if ( GetNextThink () == TICK_NEVER_THINK )
114- SetNextThink ( gpGlobals->curtime );
115- }
116- }
117-
118- bool CASW_Radiation_Volume::RadTouching ( CBaseEntity* pEnt )
64+ // Helper centralizing detection logic used by RadTouch and RadTouching
65+ bool CASW_Radiation_Volume::IsInRadiationVolume ( CBaseEntity *pEnt )
11966{
12067 if ( !pEnt )
12168 return false ;
@@ -125,8 +72,8 @@ bool CASW_Radiation_Volume::RadTouching( CBaseEntity* pEnt )
12572 const float flRadiusSqr = flRadius * flRadius;
12673
12774 const Vector vecCenter = GetAbsOrigin ();
128- CCollisionProperty* pEntColl = pEnt->CollisionProp (); // cache
129- CCollisionProperty* pVolColl = CollisionProp (); // cache
75+ CCollisionProperty* pEntColl = pEnt->CollisionProp ();
76+ CCollisionProperty* pVolColl = CollisionProp ();
13077 if ( !pVolColl )
13178 return false ;
13279
@@ -158,6 +105,25 @@ bool CASW_Radiation_Volume::RadTouching( CBaseEntity* pEnt )
158105 return pVolColl->IsPointInBounds ( vecNearest );
159106}
160107
108+ void CASW_Radiation_Volume::RadTouch ( CBaseEntity* pOther )
109+ {
110+ // if other is a valid entity to radiate, add it to our list
111+ if ( !IsValidRadTarget ( pOther )
112+ || m_hRadTouching.Find ( pOther ) != m_hRadTouching.InvalidIndex () // avoid duplicates
113+ || !IsInRadiationVolume ( pOther ) )
114+ return ;
115+
116+ m_hRadTouching.AddToTail ( pOther );
117+ if ( GetNextThink () == TICK_NEVER_THINK )
118+ SetNextThink ( gpGlobals->curtime );
119+ }
120+
121+ bool CASW_Radiation_Volume::RadTouching ( CBaseEntity* pEnt )
122+ {
123+ // simply reuse centralized detection
124+ return IsInRadiationVolume ( pEnt );
125+ }
126+
161127void CASW_Radiation_Volume::RadHurt (CBaseEntity *pEnt)
162128{
163129 if (!pEnt)
@@ -166,7 +132,7 @@ void CASW_Radiation_Volume::RadHurt(CBaseEntity *pEnt)
166132 int iDamageType = DMG_RADIATION;
167133
168134 CBaseEntity *pAttacker = this ;
169- if (m_hCreator.Get () && pEnt->Classify () != CLASS_ASW_MARINE) // don't deal friendly fire damage from rad barrels
135+ if (m_hCreator.Get () && pEnt->Classify () != CLASS_ASW_MARINE) // don't deal friendly fire damage from rad barrels
170136 pAttacker = m_hCreator.Get ();
171137
172138 CBaseEntity *pWeapon = NULL ;
0 commit comments