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))
173 if (!item.IsTakeable())
179 bool ExcludeFromContainer_Phase3(
Object object_in_cone)
185 if (!
Class.CastTo(entity, object_in_cone))
187 if (entity == player)
189 if (entity.IsParticle())
191 if (entity.IsScriptedLight())
193 if (entity.IsBeingPlaced())
195 if (entity.IsHologram())
199 if (!
Class.CastTo(item, object_in_cone) && !object_in_cone.IsTransport() && !
PASBroadcaster.Cast(object_in_cone))
201 if (item && !item.IsTakeable())
207 bool CanIgnoreDistanceCheck(
EntityAI entity_ai)
209 return MiscGameplayFunctions.CanIgnoreDistanceCheck(entity_ai);
213 void RefreshVicinityItems()
221 vector playerPosition = player.GetPosition();
222 vector playerHeadPositionFixed = playerPosition;
223 playerHeadPositionFixed[1] = playerPosition[1] + 1.6;
224 vector headingDirection = MiscGameplayFunctions.GetHeadingVector(player);
227 bool cameraActive = FreeDebugCamera.GetInstance() && FreeDebugCamera.GetInstance().IsActive();
230 playerPosition = FreeDebugCamera.GetInstance().GetPosition();
231 playerHeadPositionFixed = playerPosition;
233 float headingAngle = FreeDebugCamera.GetInstance().GetOrientation()[0] *
Math.DEG2RAD;
235 headingDirection[0] =
Math.Cos(headingAngle);
236 headingDirection[1] = 0;
237 headingDirection[2] =
Math.Sin(headingAngle);
238 headingDirection.Normalize();
242 m_VicinityItems.Clear();
244 if (m_VicinityCargos)
245 m_VicinityCargos.Clear();
249 GetGame().GetObjectsAtPosition3D(playerPosition, VICINITY_ACTOR_DISTANCE, objectsInVicinity, proxyCargos);
252 foreach (
CargoBase cargoObject : proxyCargos)
253 AddVicinityCargos(cargoObject);
256 foreach (
Object actorInRadius : objectsInVicinity)
259 allFoundObjects.Insert(actorInRadius);
261 if (ExcludeFromContainer_Phase1(actorInRadius))
265 filteredObjects.Insert(actorInRadius);
268 if (objectsInVicinity)
269 objectsInVicinity.Clear();
272 GetGame().GetObjectsAtPosition3D(playerPosition, VICINITY_DISTANCE, objectsInVicinity, proxyCargos);
276 foreach (
Object objectInRadius : objectsInVicinity)
279 allFoundObjects.Insert(objectInRadius);
281 if (ExcludeFromContainer_Phase2(objectInRadius))
285 filteredObjects.Insert(objectInRadius);
288 if (objectsInVicinity)
289 objectsInVicinity.Clear();
292 DayZPlayerUtils.GetEntitiesInCone(playerPosition, headingDirection, VICINITY_CONE_ANGLE, VICINITY_CONE_REACH_DISTANCE, CONE_HEIGHT_MIN, CONE_HEIGHT_MAX, objectsInVicinity);
298 foreach (
Object objectInCone : objectsInVicinity)
301 allFoundObjects.Insert(objectInCone);
303 if (ExcludeFromContainer_Phase3(objectInCone))
309 rayInput =
new RaycastRVParams(playerHeadPositionFixed, objectInCone.GetPosition());
311 rayInput.type = ObjIntersectView;
312 rayInput.radius = 0.1;
313 DayZPhysics.RaycastRVProxy(rayInput, raycastResults, {player});
317 if (
vector.DistanceSq(result.pos, playerHeadPositionFixed) > VICINITY_CONE_REACH_DISTANCE * VICINITY_CONE_REACH_DISTANCE)
320 if (result.hierLevel > 0 && result.parent == objectInCone)
321 filteredObjects.Insert(objectInCone);
322 else if (result.hierLevel == 0 && result.obj == objectInCone)
323 filteredObjects.Insert(objectInCone);
331 VICINITY_LARGE_ACTOR_DISTANCE,
332 VICINITY_LARGE_ACTOR_DISTANCE,
333 VICINITY_LARGE_ACTOR_DISTANCE
336 params.SetParams(playerPosition, headingDirection.VectorToAngles(), boxEdgeLength * 2, ObjIntersect.View, ObjIntersect.Fire,
true);
338 if (
GetGame().IsBoxCollidingGeometryProxy(params, {player}, results))
340 foreach (BoxCollidingResult bResult : results)
342 if (bResult.obj && (bResult.obj.CanObstruct() || bResult.obj.CanProxyObstruct()))
346 allFoundObjects.Insert(bResult.obj);
350 if (bResult.parent && (bResult.parent.CanObstruct() || bResult.parent.CanProxyObstruct()))
354 allFoundObjects.Insert(bResult.parent);
362 MiscGameplayFunctions.FilterObstructingObjects(allFoundObjects, obstructingObjects);
365 if (obstructingObjects.Count() > 0 && !cameraActive)
367 if (filteredObjects.Count() > 10)
370 MiscGameplayFunctions.GetHeadBonePos(player, rayStart);
373 MiscGameplayFunctions.FilterObstructedObjectsByGrouping(rayStart, VICINITY_CONE_DISTANCE, 0.3, filteredObjects, obstructingObjects, filteredObjectsGrouped,
true,
true, VICINITY_CONE_REACH_DISTANCE);
375 foreach (
Object object: filteredObjectsGrouped)
376 AddVicinityItems(
object);
380 foreach (
Object filteredObjectClose: filteredObjects)
383 Class.CastTo(entity, filteredObjectClose);
386 if (
vector.DistanceSq(playerPosition, entity.GetPosition()) > VICINITY_CONE_REACH_DISTANCE * VICINITY_CONE_REACH_DISTANCE)
388 if (!CanIgnoreDistanceCheck(entity))
394 if (!IsObstructed(filteredObjectClose))
396 AddVicinityItems(filteredObjectClose);
403 foreach (
Object filteredObject: filteredObjects)
404 AddVicinityItems(filteredObject);
408 bool IsObstructed(
Object filtered_object)
410 return MiscGameplayFunctions.IsObjectObstructed(filtered_object);
413 #ifdef DIAG_DEVELOPER
418 private void DebugActorsSphereDraw(
float radius)
420 CleanupDebugShapes(rayShapes);
425 private void DebugObjectsSphereDraw(
float radius)
435 private void DebugConeDraw(
vector start,
float cone_angle)
445 xL = VICINITY_CONE_REACH_DISTANCE *
Math.Cos( playerAngle +
Math.PI_HALF + cone_angle *
Math.DEG2RAD );
446 zL = VICINITY_CONE_REACH_DISTANCE *
Math.Sin( playerAngle +
Math.PI_HALF + cone_angle *
Math.DEG2RAD );
447 xR = VICINITY_CONE_REACH_DISTANCE *
Math.Cos( playerAngle +
Math.PI_HALF - cone_angle *
Math.DEG2RAD );
448 zR = VICINITY_CONE_REACH_DISTANCE *
Math.Sin( playerAngle +
Math.PI_HALF - cone_angle *
Math.DEG2RAD );
449 endL[0] = endL[0] + xL;
450 endL[2] = endL[2] + zL;
451 endR[0] = endR[0] + xR;
452 endR[2] = endR[2] + zR;
461 foreach (
Shape shape : shapesArr)
462 Debug.RemoveShape(shape);