12 void StoreVicinityObject(
Object object,
Object parent = null)
16 if (ib && (ib.IsBeingPlaced() || ib.IsHologram()))
26 if ( !m_VicinityObjects.Contains(
object) )
29 m_VicinityObjects.Set(
object, parent);
36 for (
int i = 0; i < objects.Count(); i++)
40 StoreVicinityObject(objects[i]);
46 void ClearVicinityObjects()
48 m_VicinityObjects.Clear();
55 for (
int i = 0; i < m_VicinityObjects.Count(); i++)
62 vicinityObjects.Insert(GetObject(i));
65 return vicinityObjects;
72 for (
int i = 0; i < m_VicinityObjects.Count(); i++)
74 vicinityObjects.Insert(GetObject(i));
77 return vicinityObjects;
83 return m_VicinityObjects.GetKey(i);
89 return m_VicinityObjects.GetElement(i);
94 return m_VicinityObjects.Count();
99 m_VicinityObjects.Remove(
object);
104 for (
int i = 0; i < objects.Count(); i++)
106 m_VicinityObjects.Remove(objects[i]);
116 private vector m_CursorHitPos;
117 private float m_Utility;
118 private string m_SurfaceName;
121 void ActionTarget(
Object object,
Object parent,
int componentIndex,
vector cursorHitPos,
float utility,
string surfaceName =
"")
126 m_CursorHitPos = cursorHitPos;
129 m_SurfaceName = surfaceName;
130 if (m_SurfaceName !=
"")
167 return m_CursorHitPos;
170 void SetCursorHitPos(
vector cursor_position)
172 m_CursorHitPos = cursor_position;
175 string GetSurfaceName()
177 return m_SurfaceName;
180 int GetSurfaceLiquidType()
182 return m_SurfaceLiquidType;
185 void DbgPrintTargetDump()
192 string res =
"ActionTarget dump = {";
196 res = res +
"; m_CursorHitPos: " + m_CursorHitPos.ToString();
197 res = res +
"; m_Utility: " + m_Utility.ToString();
216 return m_VicinityObjects.GetVicinityObjects();
229 m_VicinityObjects.ClearVicinityObjects();
232 Object cursorTarget = null;
237 int hitComponentIndex;
238 vector playerPos = m_Player.GetPosition();
239 vector headingDirection = MiscGameplayFunctions.GetHeadingVector(m_Player);
241 m_RayStart =
GetGame().GetCurrentCameraPosition();
242 m_RayEnd = m_RayStart +
GetGame().GetCurrentCameraDirection() * c_RayDistance;
249 if (
DayZPhysics.RaycastRVProxy(rayInput, results) )
251 if ( results.Count() > 0 )
257 for (i = 0; i < results.Count(); i++)
259 distance =
vector.DistanceSq(results[i].pos, m_RayStart);
260 distance_helper.Insert(distance);
264 distance_helper_unsorted.Copy(distance_helper);
265 distance_helper.Sort();
269 for (i = 0; i < results.Count(); i++)
271 res = results.Get(distance_helper_unsorted.Find(distance_helper[i]));
273 cursorTarget = res.obj;
274 Class.CastTo(cursorTargetEntity,cursorTarget);
275 if (cursorTarget && !cursorTarget.CanBeActionTarget())
278 if (res.hierLevel > 0)
281 if (!res.parent.IsMan())
283 m_VicinityObjects.StoreVicinityObject(res.obj, res.parent);
291 m_VicinityObjects.StoreVicinityObject(res.obj, null);
296 hitComponentIndex = res.component;
300 m_SurfaceInfo = res.surface;
307 surfaceParams.position = m_HitPos;
308 surfaceParams.includeWater =
true;
310 surfaceParams.rsd = RoadSurfaceDetection.ABOVE;
314 if (
g_Game.GetSurface(surfaceParams, surfaceResult))
316 if (surfaceResult && surfaceResult.surface)
318 m_SurfaceInfo = surfaceResult.surface;
333 m_SurfaceInfo = null;
334 hitComponentIndex = -1;
341 if (camera && camera.GetCurrentPitch() <= -45)
342 DayZPlayerUtils.GetEntitiesInCone(playerPos, headingDirection, c_ConeAngle, c_MaxTargetDistance, c_ConeHeightMin, c_ConeHeightMax, vicinityObjects);
345 vicinityObjects.RemoveItem(m_Player);
349 m_VicinityObjects.TransformToVicinityObjects(vicinityObjects);
353 FilterObstructedObjectsEx(cursorTarget, vicinityObjects);
356 for (i = 0; i < m_VicinityObjects.Count(); i++)
358 Object object = m_VicinityObjects.GetObject(i);
359 Object parent = m_VicinityObjects.GetParent(i);
361 float utility = ComputeUtility(
object, m_RayStart, m_RayEnd, cursorTarget, m_HitPos, m_SurfaceInfo);
364 int targetComponent = -1;
365 targetComponent = hitComponentIndex;
368 if (m_SurfaceInfo && m_SurfaceInfo.
GetEntryName() !=
"")
371 ActionTarget at =
new ActionTarget(
object, parent, targetComponent, m_HitPos, utility, surfaceName);
379 if (m_HitPos ==
vector.Zero)
381 vector contact_pos, contact_dir, hitNormal;
382 int contactComponent;
386 m_RayEnd = m_RayStart +
GetGame().GetCurrentCameraDirection() * c_RayDistance * 3;
389 DayZPhysics.RayCastBullet(m_RayStart,m_RayEnd,collisionLayerMask,null,hitObject,contact_pos,hitNormal,hitFraction);
390 m_HitPos = contact_pos;
393 m_Targets.Insert(
new ActionTarget(null, null, -1, m_HitPos, 0));
398 ShowDebugActionTargets(
true);
399 DrawDebugActionTargets(
true);
406 ShowDebugActionTargets(
false);
407 DrawDebugActionTargets(
false);
408 DrawDebugCone(
false);
410 DrawSelectionPos(
false);
416 private bool IsObstructed(
Object object)
419 return IsObstructedEx(
object, cache);
424 return MiscGameplayFunctions.IsObjectObstructedEx(
object, cache);
428 int GetTargetsCount()
429 {
return m_Targets.Count(); }
432 ActionTarget GetTarget(
int index)
433 {
return m_Targets.Get(index); }
436 private void StoreTarget(ActionTarget pActionTarget)
438 int index = FindIndexForStoring(pActionTarget.GetUtility());
439 m_Targets.InsertAt(pActionTarget, index);
444 private int FindIndexForStoring(
float value)
447 int right = m_Targets.Count() - 1;
448 while ( left <= right )
450 int middle = (left + right) / 2;
451 float middleValue = m_Targets.Get(middle).GetUtility();
453 if ( middleValue == value )
455 else if ( middleValue < value )
468 if (
vector.DistanceSq(hitPos, m_Player.GetPosition()) > c_MaxTargetDistance * c_MaxTargetDistance)
473 if (pTarget == cursorTarget)
476 if (pTarget.GetType() ==
string.Empty)
479 if (pTarget.IsBuilding())
482 if (pTarget.IsTransport())
486 if (pTarget.CanUseConstruction())
489 if (pTarget.IsWell())
492 vector playerPosXZ = m_Player.GetPosition();
496 if (
vector.DistanceSq(playerPosXZ, hitPosXZ) <= c_MaxTargetDistance * c_MaxTargetDistance)
497 return c_UtilityMaxValue;
503 float distSqr = DistSqrPoint2Line(pTarget.GetPosition(), pRayStart, pRayEnd);
504 return (c_UtilityMaxDistFromRaySqr - distSqr) / c_UtilityMaxDistFromRaySqr;
520 float c1 =
vector.Dot(w,v);
521 float c2 =
vector.Dot(v,v);
523 if ( c1 <= 0 || c2 == 0 )
524 return vector.DistanceSq(pPoint, pL1);
527 vector nearestPoint = pL1 + (v * b);
528 return vector.DistanceSq(pPoint, nearestPoint);
531 private void FilterObstructedObjectsEx(
Object cursor_target,
array<Object> vicinityObjects)
533 #ifdef DIAG_DEVELOPER
535 CleanupDebugShapes(obstruction);
539 MiscGameplayFunctions.FilterObstructingObjects(vicinityObjects, obstructingObjects);
541 if ( obstructingObjects.Count() > 0 )
545 int numObstructed = 0;
546 int mCount = m_VicinityObjects.Count();
548 if (mCount > GROUPING_COUNT_THRESHOLD)
551 MiscGameplayFunctions.FilterObstructedObjectsByGrouping(m_RayStart, c_MaxTargetDistance, c_DistanceDelta, m_VicinityObjects.GetRawVicinityObjects(), vicinityObjects, filteredObjects);
552 m_VicinityObjects.ClearVicinityObjects();
553 m_VicinityObjects.TransformToVicinityObjects(filteredObjects);
557 FilterObstructedObjects(cursor_target);
562 private void FilterObstructedObjects(
Object cursor_target)
564 int numObstructed = 0;
565 int mCount = m_VicinityObjects.Count();
570 for (
int i = mCount; i >= 0; --i )
572 Object object = m_VicinityObjects.GetObject(i);
573 Object parent = m_VicinityObjects.GetParent(i);
576 if (
object && !parent)
580 if (numObstructed > OBSTRUCTED_COUNT_THRESHOLD &&
object != cursor_target)
582 m_VicinityObjects.Remove(
object);
587 if (
object != cursor_target && IsObstructedEx(
object, cache))
589 m_VicinityObjects.Remove(
object);
605 void ShowDebugActionTargets(
bool enabled)
612 DbgUI.BeginCleanupScope();
616 for (
int i = 0; i < GetTargetsCount(); i++ )
618 obj = m_Targets.Get(i).GetObject();
621 float util = m_Targets.Get(i).GetUtility();
622 int compIdx = m_Targets.Get(i).GetComponentIndex();
625 compName = obj.GetActionComponentName(compIdx);
626 obj.GetActionComponentNameList(compIdx, compNames);
628 if ( compNames.Count() > 0 )
630 for (
int c = 0; c < compNames.Count(); c++ )
632 DbgUI.Text(obj.GetDisplayName() +
" :: " + obj +
" | util: " + util +
" | compIdx: " + compIdx +
" | compName: " + compNames[c] +
"| wPos: " + obj.GetWorldPosition() );
637 DbgUI.Text(obj.GetDisplayName() +
" :: " + obj +
" | util: " + util +
" | compIdx: " + compIdx +
" | compName: " + compName +
"| wPos: " + obj.GetWorldPosition() );
645 DbgUI.EndCleanupScope();
648 void DrawDebugActionTargets(
bool enabled)
658 CleanupDebugShapes(shapes);
660 for (
int i = 0; i < GetTargetsCount(); i++ )
662 obj = m_Targets.Get(i).GetObject();
665 w_pos = obj.GetPosition();
668 w_pos_sphr[1] = w_pos_sphr[1] + 0.5;
671 w_pos_lend[1] = w_pos_lend[1] + 0.5;
687 CleanupDebugShapes(shapes);
690 private void DrawDebugCone(
bool enabled)
693 vector start, end, endL, endR;
699 CleanupDebugShapes(dbgConeShapes);
701 start = m_Player.GetPosition();
702 playerAngle = MiscGameplayFunctions.GetHeadingAngle(m_Player);
705 start[1] = start[1] + 0.2;
709 xL = c_MaxTargetDistance *
Math.Cos(playerAngle +
Math.PI_HALF + c_ConeAngle *
Math.DEG2RAD);
710 zL = c_MaxTargetDistance *
Math.Sin(playerAngle +
Math.PI_HALF + c_ConeAngle *
Math.DEG2RAD);
711 xR = c_MaxTargetDistance *
Math.Cos(playerAngle +
Math.PI_HALF - c_ConeAngle *
Math.DEG2RAD);
712 zR = c_MaxTargetDistance *
Math.Sin(playerAngle +
Math.PI_HALF - c_ConeAngle *
Math.DEG2RAD);
713 endL[0] = endL[0] + xL;
714 endL[2] = endL[2] + zL;
715 endR[0] = endR[0] + xR;
716 endR[2] = endR[2] + zR;
723 CleanupDebugShapes(dbgConeShapes);
726 private void DrawSelectionPos(
bool enabled)
730 CleanupDebugShapes(dbgPosShapes);
731 if (GetTargetsCount() > 0 && GetTarget(0).GetUtility() > -1 )
733 ActionTarget at = GetTarget(0);
736 string compName = at.GetObject().GetActionComponentName(at.GetComponentIndex());
737 vector modelPos = at.GetObject().GetSelectionPositionMS(compName);
738 vector worldPos = at.GetObject().ModelToWorld(modelPos);
744 CleanupDebugShapes(dbgPosShapes);
747 private void DrawDebugRay(
bool enabled)
751 CleanupDebugShapes(rayShapes);
756 CleanupDebugShapes(rayShapes);
761 for (
int it = 0; it < shapesArr.Count(); ++it )
763 Debug.RemoveShape( shapesArr[it] );
784 private vector m_RayStart;
794 private const float c_RayDistance = 5.0;
795 private const float c_MaxTargetDistance = 3.0;
797 private const float c_ConeAngle = 30.0;
798 private const float c_ConeHeightMin = -0.5;
799 private const float c_ConeHeightMax = 2.0;
800 private const float c_DistanceDelta = 0.3;
803 private const float c_UtilityMaxValue = 10000;
804 private const float c_UtilityMaxDistFromRaySqr = 0.8 * 0.8;
807 private const string CE_CENTER =
"ce_center";
808 private const float HEIGHT_OFFSET = 0.2;
811 private const int OBSTRUCTED_COUNT_THRESHOLD = 3;
812 private const int GROUPING_COUNT_THRESHOLD = 10;
815 vector CalculateRayStart();
eBleedingSourceType GetType()
Super root of all classes in Enforce script.
override bool IsTakeable()
proto int GetLiquidType()
See 'LiquidTypes' in 'constants.c'.
static proto SurfaceInfo GetByFile(string name)
proto string GetSurfaceType()
proto string GetEntryName()
objects in vicinity - extended with secondary object which is parent of that Object
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
proto native int GetComponentIndex()
class DayZPlayerCameraResult DayZPlayerCamera(DayZPlayer pPlayer, HumanInputController pInput)
proto native CGame GetGame()
proto void Print(void var)
Prints content of variable to console/log.
proto native vobject GetObject(string name)
Loads object from data, or gets it from cache. Object must be released when not used.
void IsObjectObstructedCache(vector rayCastStart, int totalObjects)
class PresenceNotifierNoiseEvents windowPosX
dbgUI settings
override bool CanBeActionTarget()