DayZ 1.24
Loading...
Searching...
No Matches
ActionTargets Class Reference
Collaboration diagram for ActionTargets:
[legend]

Private Member Functions

void ActionTargets (PlayerBase player)
 
void Clear ()
 
void Update ()
 
bool IsObstructed (Object object)
 
bool IsObstructedEx (Object object, IsObjectObstructedCache cache)
 
int GetTargetsCount ()
 returns count of founded targets
 
ActionTarget GetTarget (int index)
 returns action target at index
 
void StoreTarget (ActionTarget pActionTarget)
 inserts action into sorted array based on utility
 
int FindIndexForStoring (float value)
 binary search algorithm
 
float ComputeUtility (Object pTarget, vector pRayStart, vector pRayEnd, Object cursorTarget, vector hitPos)
 computes utility of target
 
float DistSqrPoint2Line (vector pPoint, vector pL1, vector pL2)
 distance between point and line
 
void FilterObstructedObjectsEx (Object cursor_target, array< Object > vicinityObjects)
 
void FilterObstructedObjects (Object cursor_target)
 
vector CalculateRayStart ()
 DEPRECATED.
 

Static Private Member Functions

static array< ObjectGetVicinityObjects ()
 

Private Attributes

PlayerBase m_Player
 player owner
 
ref array< ref ActionTargetm_Targets
 selected & sorted targets by utility function
 
vector m_RayEnd
 
vector m_HitPos
 
const float c_RayDistance = 5.0
 searching properties
 
const float c_MaxTargetDistance = 3.0
 
const float c_MaxActionDistance = UAMaxDistances.DEFAULT
 
const float c_ConeAngle = 30.0
 
const float c_ConeHeightMin = -0.5
 
const float c_ConeHeightMax = 2.0
 
const float c_DistanceDelta = 0.3
 
const float c_UtilityMaxValue = 10000
 utility constants
 
const float c_UtilityMaxDistFromRaySqr = 0.8 * 0.8
 
const string CE_CENTER = "ce_center"
 p3d
 
const float HEIGHT_OFFSET = 0.2
 
const int OBSTRUCTED_COUNT_THRESHOLD = 3
 misc
 
const int GROUPING_COUNT_THRESHOLD = 10
 

Static Private Attributes

vector m_RayStart
 objects in vicinity
 

Detailed Description

Definition at line 169 of file ActionTargets.c.

Constructor & Destructor Documentation

◆ ActionTargets()

void ActionTargets::ActionTargets ( PlayerBase player)
inlineprivate

Definition at line 171 of file ActionTargets.c.

172 {
176
177 m_Debug = false;
178 }
ref map< Object, Object > m_VicinityObjects
void VicinityObjects()
PlayerBase m_Player
player owner
ref array< ref ActionTarget > m_Targets
selected & sorted targets by utility function

References m_Player, m_VicinityObjects, and VicinityObjects().

Member Function Documentation

◆ CalculateRayStart()

vector ActionTargets::CalculateRayStart ( )
private

DEPRECATED.

◆ Clear()

void ActionTargets::Clear ( )
inlineprivate

Definition at line 185 of file ActionTargets.c.

186 {
187 m_Targets.Clear();
188 }

References m_Targets.

◆ ComputeUtility()

float ActionTargets::ComputeUtility ( Object pTarget,
vector pRayStart,
vector pRayEnd,
Object cursorTarget,
vector hitPos )
inlineprivate

computes utility of target

out of reach

ground and static objects

basebuilding objects

Definition at line 402 of file ActionTargets.c.

403 {
406 return -1;
407
408 if (pTarget)
409 {
410 if (pTarget == cursorTarget)
411 {
413 if (pTarget.GetType() == string.Empty)
414 return 0.01;
415
416 if (pTarget.IsBuilding())
417 return 0.25;
418
419 if (pTarget.IsTransport())
420 return 0.25;
421
423 if (pTarget.CanUseConstruction())
424 return 0.85;
425
426 if (pTarget.IsWell())
427 return 0.9;
428
429 vector playerPosXZ = m_Player.GetPosition();
431 playerPosXZ[1] = 0;
432 hitPosXZ[1] = 0;
434 return c_UtilityMaxValue;
435 }
436
437 float distSqr = DistSqrPoint2Line(pTarget.GetPosition(), pRayStart, pRayEnd);
439 }
440
441 return -1;
442 }
const float c_UtilityMaxDistFromRaySqr
const float c_MaxTargetDistance
float DistSqrPoint2Line(vector pPoint, vector pL1, vector pL2)
distance between point and line
const float c_UtilityMaxValue
utility constants
static proto native float DistanceSq(vector v1, vector v2)
Returns the square distance between tips of two 3D vectors.

References c_MaxTargetDistance, c_UtilityMaxDistFromRaySqr, c_UtilityMaxValue, vector::DistanceSq(), DistSqrPoint2Line(), and m_Player.

◆ DistSqrPoint2Line()

float ActionTargets::DistSqrPoint2Line ( vector pPoint,
vector pL1,
vector pL2 )
inlineprivate

distance between point and line

Definition at line 445 of file ActionTargets.c.

446 {
447 vector v = pL2 - pL1;
448 vector w = pPoint - pL1;
449
450 float c1 = vector.Dot(w, v);
451 float c2 = vector.Dot(v, v);
452
453 if (c1 <= 0 || c2 == 0)
454 return vector.DistanceSq(pPoint, pL1);
455
456 float b = c1 / c2;
457 vector nearestPoint = pL1 + (v * b);
459 }
static float Dot(vector v1, vector v2)
Returns Dot product of vector v1 and vector v2.
Definition EnConvert.c:271

References vector::DistanceSq(), and vector::Dot().

Referenced by ComputeUtility().

◆ FilterObstructedObjects()

void ActionTargets::FilterObstructedObjects ( Object cursor_target)
inlineprivate

check if targets are not obstructed (eg.: wall)

check for object obstruction(if the object is not a proxy - has no parent)

when the number of obstructed items is higher than OBSTRUCTED_COUNT_THRESHOLD remove do no run obstruction check and skip these items

obstruction check

Definition at line 490 of file ActionTargets.c.

491 {
492 int numObstructed = 0;
493 int mCount = m_VicinityObjects.Count();
495 mCount--;
496
498 for (int i = mCount; i >= 0; --i)
499 {
500 Object object = m_VicinityObjects.GetObject(i);
501 Object parent = m_VicinityObjects.GetParent(i);
502
504 if (object && !parent)
505 {
509 {
510 m_VicinityObjects.Remove(object);
511 continue;
512 }
513
515 if (object != cursor_target && IsObstructedEx(object, cache))
516 {
517 m_VicinityObjects.Remove(object);
519 }
520
521 cache.ClearCache();
522 }
523 }
524 }
void IsObjectObstructedCache(vector rayCastStart, int totalObjects)
const int OBSTRUCTED_COUNT_THRESHOLD
misc
bool IsObstructedEx(Object object, IsObjectObstructedCache cache)
vector m_RayStart
objects in vicinity

References IsObjectObstructedCache(), IsObstructedEx(), m_RayStart, m_VicinityObjects, and OBSTRUCTED_COUNT_THRESHOLD.

Referenced by FilterObstructedObjectsEx().

◆ FilterObstructedObjectsEx()

void ActionTargets::FilterObstructedObjectsEx ( Object cursor_target,
array< Object > vicinityObjects )
inlineprivate

Definition at line 461 of file ActionTargets.c.

462 {
463#ifdef DIAG_DEVELOPER
464 if (DiagMenu.GetBool(DiagMenuIDs.MISC_ACTION_TARGETS_DEBUG))
465 CleanupDebugShapes(obstruction);
466#endif
467
470
471 if (obstructingObjects.Count() > 0)
472 {
473 PlayerBase player = PlayerBase.Cast(g_Game.GetPlayer());
474
475 int numObstructed = 0;
476 int mCount = m_VicinityObjects.Count();
477
479 {
481 MiscGameplayFunctions.FilterObstructedObjectsByGrouping(m_RayStart, c_MaxTargetDistance, c_DistanceDelta, m_VicinityObjects.GetRawVicinityObjects(), vicinityObjects, filteredObjects);
482 m_VicinityObjects.ClearVicinityObjects();
483 m_VicinityObjects.TransformToVicinityObjects(filteredObjects);
484 }
485 else
487 }
488 }
DayZGame g_Game
Definition DayZGame.c:3528
DiagMenuIDs
Definition EDiagMenuIDs.c:2
const float c_DistanceDelta
void FilterObstructedObjects(Object cursor_target)
const int GROUPING_COUNT_THRESHOLD
static proto bool GetBool(int id, bool reverse=false)
Get value as bool from the given script id.

References c_DistanceDelta, c_MaxTargetDistance, FilterObstructedObjects(), g_Game, DiagMenu::GetBool(), GROUPING_COUNT_THRESHOLD, m_RayStart, and m_VicinityObjects.

◆ FindIndexForStoring()

int ActionTargets::FindIndexForStoring ( float value)
inlineprivate

binary search algorithm

Definition at line 381 of file ActionTargets.c.

382 {
383 int left = 0;
384 int right = m_Targets.Count() - 1;
385 while (left <= right)
386 {
387 int middle = (left + right) / 2;
388 float middleValue = m_Targets.Get(middle).GetUtility();
389
390 if (middleValue == value)
391 return middle;
392 else if (middleValue < value)
393 right = middle - 1;
394 else
395 left = middle + 1;
396 }
397
398 return left;
399 }

References m_Targets.

Referenced by StoreTarget().

◆ GetTarget()

ActionTarget ActionTargets::GetTarget ( int index)
inlineprivate

returns action target at index

Definition at line 369 of file ActionTargets.c.

370 { return m_Targets.Get(index); }

References m_Targets.

◆ GetTargetsCount()

int ActionTargets::GetTargetsCount ( )
inlineprivate

returns count of founded targets

Definition at line 365 of file ActionTargets.c.

366 { return m_Targets.Count(); }

References m_Targets.

◆ GetVicinityObjects()

static array< Object > ActionTargets::GetVicinityObjects ( )
inlinestaticprivate

Definition at line 180 of file ActionTargets.c.

181 {
182 return m_VicinityObjects.GetVicinityObjects();
183 }

References m_VicinityObjects.

◆ IsObstructed()

bool ActionTargets::IsObstructed ( Object object)
inlineprivate

Definition at line 353 of file ActionTargets.c.

354 {
356 return IsObstructedEx(object, cache);
357 }

References IsObjectObstructedCache(), IsObstructedEx(), and m_RayStart.

◆ IsObstructedEx()

bool ActionTargets::IsObstructedEx ( Object object,
IsObjectObstructedCache cache )
inlineprivate

Definition at line 359 of file ActionTargets.c.

360 {
361 return MiscGameplayFunctions.IsObjectObstructedEx(object, cache);
362 }

Referenced by FilterObstructedObjects(), and IsObstructed().

◆ StoreTarget()

void ActionTargets::StoreTarget ( ActionTarget pActionTarget)
inlineprivate

inserts action into sorted array based on utility

Definition at line 373 of file ActionTargets.c.

374 {
375 int index = FindIndexForStoring(pActionTarget.GetUtility());
376 m_Targets.InsertAt(pActionTarget, index);
377 //Print("StoreTarget; object: " + pActionTarget.GetObject() + " | parent: " + pActionTarget.GetParent() + " | idx: " + index);
378 }
int FindIndexForStoring(float value)
binary search algorithm

References FindIndexForStoring(), and m_Targets.

◆ Update()

void ActionTargets::Update ( )
inlineprivate

clear state

camera & ray properties

if the cursor target is a proxy

ignores attachments on player

spacial search

removes player from the vicinity

transformation of array of Objects to hashmap (VicinityObjects)

removes Vicinity objects that are not directly visible from player position

select & sort targets based on utility function

action target for surface actions (lowest utility)

Definition at line 190 of file ActionTargets.c.

191 {
192 int i;
193
195 m_VicinityObjects.ClearVicinityObjects();
196 Clear();
197
201
204 vector playerPos = m_Player.GetPosition();
206
207 m_RayStart = GetGame().GetCurrentCameraPosition();
208 m_RayEnd = m_RayStart + GetGame().GetCurrentCameraDirection() * c_RayDistance;
209
211 rayInput.flags = CollisionFlags.ALLOBJECTS;
212 //rayInput.sorted = true;
214
216 {
217 if (results.Count() > 0)
218 {
221 float distance;
222
223 for (i = 0; i < results.Count(); i++)
224 {
227 //Print("#" + i + " " + results.Get(i).obj);
228 }
229 //Print("--------------");
231 distance_helper.Sort();
232
234
235
236 for (i = 0; i < results.Count(); i++)
237 {
238 res = results.Get(distance_helper_unsorted.Find(distance_helper[i])); //closest object
239
240 cursorTarget = res.obj;
242 if (cursorTarget && !cursorTarget.CanBeActionTarget())
243 continue;
245 if (res.hierLevel > 0)
246 {
248 if (!res.parent.IsMan())
249 {
250 m_VicinityObjects.StoreVicinityObject(res.obj, res.parent);
251 //Print("storing, 1st pass (hier > 0): " + res.obj);
252 }
253 else
254 continue;
255 }
256 else
257 {
258 m_VicinityObjects.StoreVicinityObject(res.obj, null);
259 //Print("storing, 1st pass: " + res.obj);
260 }
261
262 m_HitPos = res.pos;
263 hitComponentIndex = res.component;
264 break;
265 }
266 }
267 //else
268 //Print("NO RESULTS FOUND!");
269 }
270 else
271 {
272 //Print("CAST UNSUCCESFUL");
276 }
277
278 //Print(cursorTarget);
279
281 DayZPlayerCamera camera = m_Player.GetCurrentCamera();
282 if (camera && camera.GetCurrentPitch() <= -45) // Spatial search is a contributor to very heavy searching, limit it to when we are at least looking down
284
286 vicinityObjects.RemoveItem(m_Player);
287
289 //Print("m_VicinityObjects before" + m_VicinityObjects.Count());
290 m_VicinityObjects.TransformToVicinityObjects(vicinityObjects);
291 //Print("m_VicinityObjects after" + m_VicinityObjects.Count());
292
295
297 for (i = 0; i < m_VicinityObjects.Count(); i++)
298 {
299 Object object = m_VicinityObjects.GetObject(i);
300 Object parent = m_VicinityObjects.GetParent(i);
301
303 if (utility > 0)
304 {
305 int targetComponent = -1;
307
308 ActionTarget at = new ActionTarget(object, parent, targetComponent, m_HitPos, utility);
310 }
311 /*else
312 Print("utility < 0; object: " + object + " | parent: " + parent);*/
313 }
314
316 if (m_HitPos == vector.Zero)
317 {
320 float hitFraction;
322
323 m_RayEnd = m_RayStart + GetGame().GetCurrentCameraDirection() * c_RayDistance * 3;
324
328 }
329
330 m_Targets.Insert(new ActionTarget(null, null, -1, m_HitPos, 0));
331
332#ifdef DIAG_DEVELOPER
333 if (DiagMenu.GetBool(DiagMenuIDs.MISC_ACTION_TARGETS_DEBUG))
334 {
337 DrawDebugCone(true);
338 DrawDebugRay(true);
339 DrawSelectionPos(DiagMenu.GetBool(DiagMenuIDs.MISC_ACTION_TARGETS_SELPOS_DEBUG));
340 }
341 else
342 {
345 DrawDebugCone(false);
346 DrawDebugRay(false);
347 DrawSelectionPos(false);
348 }
349#endif
350 //Print("--------------");
351 }
class ActionTargets ActionTarget
PhxInteractionLayers
Definition DayZPhysics.c:2
void DayZPlayerUtils()
cannot be instantiated
const float c_ConeAngle
void StoreTarget(ActionTarget pActionTarget)
inserts action into sorted array based on utility
const float c_RayDistance
searching properties
void FilterObstructedObjectsEx(Object cursor_target, array< Object > vicinityObjects)
float ComputeUtility(Object pTarget, vector pRayStart, vector pRayEnd, Object cursorTarget, vector hitPos)
computes utility of target
const float c_ConeHeightMax
const float c_ConeHeightMin
Super root of all classes in Enforce script.
Definition EnScript.c:11
static proto bool RayCastBullet(vector begPos, vector endPos, PhxInteractionLayers layerMask, Object ignoreObj, out Object hitObject, out vector hitPosition, out vector hitNormal, out float hitFraction)
static proto bool RaycastRVProxy(notnull RaycastRVParams in, out notnull array< ref RaycastRVResult > results, array< Object > excluded=null)
static const vector Zero
Definition EnConvert.c:110
class DayZPlayerCameraResult DayZPlayerCamera(DayZPlayer pPlayer, HumanInputController pInput)
Definition dayzplayer.c:56
proto native CGame GetGame()
CollisionFlags
Definition EnDebug.c:141
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.

Member Data Documentation

◆ c_ConeAngle

const float ActionTargets::c_ConeAngle = 30.0
private

Definition at line 717 of file ActionTargets.c.

◆ c_ConeHeightMax

const float ActionTargets::c_ConeHeightMax = 2.0
private

Definition at line 719 of file ActionTargets.c.

◆ c_ConeHeightMin

const float ActionTargets::c_ConeHeightMin = -0.5
private

Definition at line 718 of file ActionTargets.c.

◆ c_DistanceDelta

const float ActionTargets::c_DistanceDelta = 0.3
private

Definition at line 720 of file ActionTargets.c.

Referenced by FilterObstructedObjectsEx().

◆ c_MaxActionDistance

const float ActionTargets::c_MaxActionDistance = UAMaxDistances.DEFAULT
private

Definition at line 716 of file ActionTargets.c.

◆ c_MaxTargetDistance

const float ActionTargets::c_MaxTargetDistance = 3.0
private

Definition at line 715 of file ActionTargets.c.

Referenced by ComputeUtility(), and FilterObstructedObjectsEx().

◆ c_RayDistance

const float ActionTargets::c_RayDistance = 5.0
private

searching properties

Definition at line 714 of file ActionTargets.c.

◆ c_UtilityMaxDistFromRaySqr

const float ActionTargets::c_UtilityMaxDistFromRaySqr = 0.8 * 0.8
private

Definition at line 724 of file ActionTargets.c.

Referenced by ComputeUtility().

◆ c_UtilityMaxValue

const float ActionTargets::c_UtilityMaxValue = 10000
private

utility constants

Definition at line 723 of file ActionTargets.c.

Referenced by ComputeUtility().

◆ CE_CENTER

const string ActionTargets::CE_CENTER = "ce_center"
private

p3d

Definition at line 727 of file ActionTargets.c.

◆ GROUPING_COUNT_THRESHOLD

const int ActionTargets::GROUPING_COUNT_THRESHOLD = 10
private

Definition at line 732 of file ActionTargets.c.

Referenced by FilterObstructedObjectsEx().

◆ HEIGHT_OFFSET

const float ActionTargets::HEIGHT_OFFSET = 0.2
private

Definition at line 728 of file ActionTargets.c.

◆ m_HitPos

vector ActionTargets::m_HitPos
private

Definition at line 708 of file ActionTargets.c.

◆ m_Player

PlayerBase ActionTargets::m_Player
private

player owner

Definition at line 696 of file ActionTargets.c.

Referenced by ActionTargets(), and ComputeUtility().

◆ m_RayEnd

vector ActionTargets::m_RayEnd
private

Definition at line 707 of file ActionTargets.c.

◆ m_RayStart

vector ActionTargets::m_RayStart
staticprivate

objects in vicinity

Definition at line 706 of file ActionTargets.c.

Referenced by FilterObstructedObjects(), FilterObstructedObjectsEx(), and IsObstructed().

◆ m_Targets

ref array<ref ActionTarget> ActionTargets::m_Targets
private

selected & sorted targets by utility function

Definition at line 699 of file ActionTargets.c.

Referenced by Clear(), FindIndexForStoring(), GetTarget(), GetTargetsCount(), and StoreTarget().

◆ OBSTRUCTED_COUNT_THRESHOLD

const int ActionTargets::OBSTRUCTED_COUNT_THRESHOLD = 3
private

misc

Definition at line 731 of file ActionTargets.c.

Referenced by FilterObstructedObjects().


The documentation for this class was generated from the following file: