3 private const float UPDATE_FREQUENCY = 0.25;
4 private const float VICINITY_DISTANCE = 0.5;
5 private const float VICINITY_ACTOR_DISTANCE = 2.0;
6 private const float VICINITY_LARGE_ACTOR_DISTANCE = 3.0;
7 private const float VICINITY_CONE_DISTANCE = 2.0;
8 private const float VICINITY_CONE_REACH_DISTANCE = 2.0;
9 private const float VICINITY_CONE_ANGLE = 30;
10 private const float VICINITY_CONE_RADIANS = 0.5;
11 private const string CE_CENTER =
"ce_center";
12 private const float HEIGHT_OFFSET = 0.2;
13 private const int OBJECT_OBSTRUCTION_WEIGHT = 10000;
14 private const float CONE_HEIGHT_MIN = -0.5;
15 private const float CONE_HEIGHT_MAX = 3.0;
19 private float m_RefreshCounter;
36 return m_VicinityItems;
39 void AddVicinityItems(
Object object)
54 if (!FreeDebugCamera.GetInstance() || FreeDebugCamera.GetInstance().IsActive() ==
false)
60 m_VicinityItems.Insert(entity);
65 return m_VicinityCargos;
72 m_VicinityCargos.Insert(
object);
76 void ResetRefreshCounter()
81 void Update(
float delta_time)
83 m_RefreshCounter += delta_time;
85 if (m_RefreshCounter >= UPDATE_FREQUENCY)
87 RefreshVicinityItems();
92 bool ExcludeFromContainer_Phase1(
Object actor_in_radius)
95 if (!
Class.CastTo(entity, actor_in_radius))
101 if (entity.IsParticle())
103 if (entity.IsScriptedLight())
105 if (entity.IsBeingPlaced())
107 if (entity.IsHologram())
109 if (entity.IsMan() || entity.IsZombie() || entity.IsZombieMilitary())
112 vector entityPosition = entity.GetPosition();
114 if (entity && entity.IsMan())
119 entityPosition = vicinityPlayer.GetBonePositionWS(vicinityPlayer.GetBoneIndexByName(
"spine3"));
122 else if (entity && (entity.IsZombie() || entity.IsZombieMilitary()))
127 entityPosition = zombie.GetBonePositionWS(zombie.GetBoneIndexByName(
"spine3"));
132 if (FreeDebugCamera.GetInstance() && FreeDebugCamera.GetInstance().IsActive())
137 vector entityDirection = player.GetPosition() - entityPosition;
138 entityDirection.Normalize();
139 entityDirection[1] = 0;
141 vector playerDirection = MiscGameplayFunctions.GetHeadingVector(player);
142 playerDirection.Normalize();
143 playerDirection[1] = 0;
145 float dotRadians =
vector.Dot(playerDirection, entityDirection);
146 if (dotRadians > -0.5)
153 bool ExcludeFromContainer_Phase2(
Object object_in_radius)
157 if (!
Class.CastTo(entity, object_in_radius))
161 if (entity.IsParticle())
163 if (entity.IsScriptedLight())
165 if (entity.IsBeingPlaced())
167 if (entity.IsHologram())
171 if (!
Class.CastTo(item, object_in_radius))
177 bool ExcludeFromContainer_Phase3(
Object object_in_cone)
183 if (!
Class.CastTo(entity, object_in_cone))
185 if (entity == player)
187 if (entity.IsParticle())
189 if (entity.IsScriptedLight())
191 if (entity.IsBeingPlaced())
193 if (entity.IsHologram())
197 if (!
Class.CastTo(item, object_in_cone) && !object_in_cone.IsTransport() && !
PASBroadcaster.Cast(object_in_cone))
203 bool CanIgnoreDistanceCheck(
EntityAI entity_ai)
205 return MiscGameplayFunctions.CanIgnoreDistanceCheck(entity_ai);
209 void RefreshVicinityItems()
217 vector playerPosition = player.GetPosition();
218 vector playerHeadPositionFixed = playerPosition;
220 vector headingDirection = MiscGameplayFunctions.GetHeadingVector(player);
223 bool cameraActive = FreeDebugCamera.GetInstance() && FreeDebugCamera.GetInstance().IsActive();
226 playerPosition = FreeDebugCamera.GetInstance().GetPosition();
227 playerHeadPositionFixed = playerPosition;
229 float headingAngle = FreeDebugCamera.GetInstance().GetOrientation()[0] *
Math.DEG2RAD;
231 headingDirection[0] =
Math.Cos(headingAngle);
232 headingDirection[1] = 0;
233 headingDirection[2] =
Math.Sin(headingAngle);
234 headingDirection.Normalize();
238 m_VicinityItems.Clear();
240 if (m_VicinityCargos)
241 m_VicinityCargos.Clear();
245 GetGame().GetObjectsAtPosition3D(playerPosition, VICINITY_ACTOR_DISTANCE, objectsInVicinity, proxyCargos);
248 foreach (
CargoBase cargoObject : proxyCargos)
249 AddVicinityCargos(cargoObject);
252 foreach (
Object actorInRadius : objectsInVicinity)
255 allFoundObjects.Insert(actorInRadius);
257 if (ExcludeFromContainer_Phase1(actorInRadius))
261 filteredObjects.Insert(actorInRadius);
264 if (objectsInVicinity)
265 objectsInVicinity.Clear();
268 GetGame().GetObjectsAtPosition3D(playerPosition, VICINITY_DISTANCE, objectsInVicinity, proxyCargos);
272 foreach (
Object objectInRadius : objectsInVicinity)
275 allFoundObjects.Insert(objectInRadius);
277 if (ExcludeFromContainer_Phase2(objectInRadius))
281 filteredObjects.Insert(objectInRadius);
284 if (objectsInVicinity)
285 objectsInVicinity.Clear();
288 DayZPlayerUtils.GetEntitiesInCone(playerPosition, headingDirection, VICINITY_CONE_ANGLE, VICINITY_CONE_REACH_DISTANCE, CONE_HEIGHT_MIN, CONE_HEIGHT_MAX, objectsInVicinity);
294 foreach (
Object objectInCone : objectsInVicinity)
297 allFoundObjects.Insert(objectInCone);
299 if (ExcludeFromContainer_Phase3(objectInCone))
304 rayInput =
new RaycastRVParams(playerHeadPositionFixed, objectInCone.GetPosition());
306 rayInput.type = ObjIntersectView;
307 rayInput.radius = 0.1;
308 DayZPhysics.RaycastRVProxy(rayInput, raycastResults, {player});
313 if (
vector.DistanceSq(result.pos, playerPosition) > VICINITY_CONE_REACH_DISTANCE * VICINITY_CONE_REACH_DISTANCE)
316 if (result.hierLevel > 0)
318 if (result.parent.CanProxyObstruct())
321 if (result.parent == objectInCone)
323 filteredObjects.Insert(objectInCone);
329 if (result.obj == objectInCone)
331 filteredObjects.Insert(objectInCone);
342 VICINITY_LARGE_ACTOR_DISTANCE,
343 VICINITY_LARGE_ACTOR_DISTANCE,
344 VICINITY_LARGE_ACTOR_DISTANCE
347 params.SetParams(playerPosition, headingDirection.VectorToAngles(), boxEdgeLength * 2, ObjIntersect.View, ObjIntersect.Fire,
true);
349 if (
GetGame().IsBoxCollidingGeometryProxy(params, {player}, results))
351 foreach (BoxCollidingResult bResult : results)
353 if (bResult.obj && (bResult.obj.CanObstruct() || bResult.obj.CanProxyObstruct()))
356 allFoundObjects.Insert(bResult.obj);
359 if (bResult.parent && (bResult.parent.CanObstruct() || bResult.parent.CanProxyObstruct()))
362 allFoundObjects.Insert(bResult.parent);
369 MiscGameplayFunctions.FilterObstructingObjects(allFoundObjects, obstructingObjects);
372 if (obstructingObjects.Count() > 0 && !cameraActive)
375 if (filteredObjects.Count() > 10)
378 MiscGameplayFunctions.FilterObstructedObjectsByGrouping(playerHeadPositionFixed, VICINITY_CONE_DISTANCE, 0.3, filteredObjects, obstructingObjects, filteredObjectsGrouped,
true,
true, VICINITY_CONE_REACH_DISTANCE);
380 foreach (
Object object: filteredObjectsGrouped)
381 AddVicinityItems(
object);
385 foreach (
Object filteredObjectClose: filteredObjects)
388 Class.CastTo(entity, filteredObjectClose);
391 if (
vector.DistanceSq(playerPosition, entity.GetPosition()) > VICINITY_CONE_REACH_DISTANCE * VICINITY_CONE_REACH_DISTANCE)
393 if (!CanIgnoreDistanceCheck(entity))
401 AddVicinityItems(filteredObjectClose);
408 foreach (
Object filteredObject: filteredObjects)
409 AddVicinityItems(filteredObject);
427 return MiscGameplayFunctions.IsObjectObstructed(filtered_object);
435 private void DebugActorsSphereDraw(
float radius)
437 CleanupDebugShapes(rayShapes);
442 private void DebugObjectsSphereDraw(
float radius)
452 private void DebugConeDraw(
vector start,
float cone_angle)
462 xL = VICINITY_CONE_REACH_DISTANCE *
Math.Cos( playerAngle +
Math.PI_HALF + cone_angle *
Math.DEG2RAD );
463 zL = VICINITY_CONE_REACH_DISTANCE *
Math.Sin( playerAngle +
Math.PI_HALF + cone_angle *
Math.DEG2RAD );
464 xR = VICINITY_CONE_REACH_DISTANCE *
Math.Cos( playerAngle +
Math.PI_HALF - cone_angle *
Math.DEG2RAD );
465 zR = VICINITY_CONE_REACH_DISTANCE *
Math.Sin( playerAngle +
Math.PI_HALF - cone_angle *
Math.DEG2RAD );
466 endL[0] = endL[0] + xL;
467 endL[2] = endL[2] + zL;
468 endR[0] = endR[0] + xR;
469 endR[2] = endR[2] + zR;
478 foreach (
Shape shape : shapesArr)
479 Debug.RemoveShape(shape);