actiontargets.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753
  1. //! objects in vicinity - extended with secondary object which is parent of that Object
  2. class VicinityObjects
  3. {
  4. private ref map<Object, Object> m_VicinityObjects;
  5. void VicinityObjects()
  6. {
  7. m_VicinityObjects = new map<Object, Object>;
  8. }
  9. //! stores VicinityObject to Hashmap - for storing of parent/child relationship
  10. void StoreVicinityObject(Object object, Object parent = null)
  11. {
  12. //! completely remove items that are being placed or are holograms
  13. ItemBase ib = ItemBase.Cast(object);
  14. if (ib && (ib.IsBeingPlaced() || ib.IsHologram()))
  15. return;
  16. //! ignores plain objects
  17. /*if(object && object.IsPlainObject())
  18. {
  19. Print("ERROR: VicinityObjects | StoreVicinityObject | IsPlainObject check fail");
  20. return;
  21. }*/
  22. if ( !m_VicinityObjects.Contains(object) )
  23. {
  24. //! init of VicinityObjects - object, parent(if exists)
  25. m_VicinityObjects.Set(object, parent);
  26. }
  27. }
  28. //! transform simple array of Objects to VicinityObjects hashmap
  29. void TransformToVicinityObjects(array<Object> objects)
  30. {
  31. for (int i = 0; i < objects.Count(); i++)
  32. {
  33. if (objects[i].GetType() != "" && objects[i].CanBeActionTarget())
  34. {
  35. StoreVicinityObject(objects[i]);
  36. //Print("storing, 2nd pass: " + objects[i]);
  37. }
  38. }
  39. }
  40. void ClearVicinityObjects()
  41. {
  42. m_VicinityObjects.Clear();
  43. }
  44. //! return simple array of Objects in Vicinity
  45. array< Object > GetVicinityObjects()
  46. {
  47. ref array<Object> vicinityObjects = new array<Object>;
  48. for (int i = 0; i < m_VicinityObjects.Count(); i++)
  49. {
  50. //! filters out non-takeable items (won't be shown in vicinity)
  51. ItemBase ib = ItemBase.Cast(GetObject(i));
  52. if (ib && !ib.IsTakeable())
  53. continue;
  54. vicinityObjects.Insert(GetObject(i));
  55. }
  56. return vicinityObjects;
  57. }
  58. //! return simple array of Objects in Vicinity
  59. array< Object > GetRawVicinityObjects()
  60. {
  61. ref array<Object> vicinityObjects = new array<Object>;
  62. for (int i = 0; i < m_VicinityObjects.Count(); i++)
  63. {
  64. vicinityObjects.Insert(GetObject(i));
  65. }
  66. return vicinityObjects;
  67. }
  68. //! returns VicinityObjects Key
  69. Object GetObject(int i)
  70. {
  71. return m_VicinityObjects.GetKey(i);
  72. }
  73. //! returns VicinityObjects Element
  74. Object GetParent(int i)
  75. {
  76. return m_VicinityObjects.GetElement(i);
  77. }
  78. int Count()
  79. {
  80. return m_VicinityObjects.Count();
  81. }
  82. void Remove(Object object)
  83. {
  84. m_VicinityObjects.Remove(object);
  85. }
  86. void Remove(array<Object> objects)
  87. {
  88. for (int i = 0; i < objects.Count(); i++)
  89. {
  90. m_VicinityObjects.Remove(objects[i]);
  91. }
  92. }
  93. }
  94. class ActionTarget
  95. {
  96. void ActionTarget(Object object, Object parent, int componentIndex, vector cursorHitPos, float utility)
  97. {
  98. m_Object = object;
  99. m_Parent = parent;
  100. m_ComponentIndex = componentIndex;
  101. m_CursorHitPos = cursorHitPos;
  102. m_Utility = utility;
  103. }
  104. Object GetObject()
  105. { return m_Object; }
  106. Object GetParent()
  107. { return m_Parent; }
  108. bool IsProxy()
  109. {
  110. if (m_Parent)
  111. return true;
  112. return false;
  113. }
  114. int GetComponentIndex()
  115. { return m_ComponentIndex; }
  116. float GetUtility()
  117. { return m_Utility; }
  118. vector GetCursorHitPos()
  119. { return m_CursorHitPos; }
  120. void SetCursorHitPos(vector cursor_position)
  121. {
  122. m_CursorHitPos = cursor_position;
  123. }
  124. void DbgPrintTargetDump()
  125. {
  126. Print(DumpToString());
  127. }
  128. string DumpToString()
  129. {
  130. string res = "ActionTarget dump = {";
  131. res = res + "m_Object: " + Object.GetDebugName(m_Object);
  132. res = res + "; m_Parent: " + Object.GetDebugName(m_Parent);
  133. res = res + "; m_ComponentIndex: " + m_ComponentIndex.ToString();
  134. res = res + "; m_CursorHitPos: " + m_CursorHitPos.ToString();
  135. res = res + "; m_Utility: " + m_Utility.ToString();
  136. res = res + "}";
  137. return res;
  138. }
  139. private Object m_Object; // object itself
  140. private Object m_Parent; // null or parent of m_Object
  141. private int m_ComponentIndex; // p3d Component ID or -1
  142. private vector m_CursorHitPos;
  143. private float m_Utility;
  144. };
  145. class ActionTargets
  146. {
  147. void ActionTargets(PlayerBase player)
  148. {
  149. m_Player = player;
  150. m_VicinityObjects = new VicinityObjects;
  151. m_Targets = new array<ref ActionTarget>;
  152. m_Debug = false;
  153. }
  154. static array<Object> GetVicinityObjects()
  155. {
  156. return m_VicinityObjects.GetVicinityObjects();
  157. }
  158. void Clear()
  159. {
  160. m_Targets.Clear();
  161. }
  162. void Update()
  163. {
  164. int i;
  165. //! clear state
  166. m_VicinityObjects.ClearVicinityObjects();
  167. Clear();
  168. Object cursorTarget = null;
  169. EntityAI cursorTargetEntity = null;
  170. array<Object> vicinityObjects = new array<Object>;
  171. //! camera & ray properties
  172. int hitComponentIndex;
  173. vector playerPos = m_Player.GetPosition();
  174. vector headingDirection = MiscGameplayFunctions.GetHeadingVector(m_Player);
  175. m_RayStart = GetGame().GetCurrentCameraPosition();
  176. m_RayEnd = m_RayStart + GetGame().GetCurrentCameraDirection() * c_RayDistance;
  177. RaycastRVParams rayInput = new RaycastRVParams(m_RayStart, m_RayEnd, m_Player);
  178. rayInput.flags = CollisionFlags.ALLOBJECTS;
  179. //rayInput.sorted = true;
  180. array<ref RaycastRVResult> results = new array<ref RaycastRVResult>;
  181. if ( DayZPhysics.RaycastRVProxy(rayInput, results) )
  182. {
  183. if ( results.Count() > 0 )
  184. {
  185. array<float> distance_helper = new array<float>;
  186. array<float> distance_helper_unsorted = new array<float>;
  187. float distance;
  188. for (i = 0; i < results.Count(); i++)
  189. {
  190. distance = vector.DistanceSq(results[i].pos, m_RayStart);
  191. distance_helper.Insert(distance);
  192. //Print("#" + i + " " + results.Get(i).obj);
  193. }
  194. //Print("--------------");
  195. distance_helper_unsorted.Copy(distance_helper);
  196. distance_helper.Sort();
  197. RaycastRVResult res;
  198. for ( i = 0; i < results.Count(); i++)
  199. {
  200. res = results.Get(distance_helper_unsorted.Find(distance_helper[i])); //closest object
  201. cursorTarget = res.obj;
  202. Class.CastTo(cursorTargetEntity,cursorTarget);
  203. if (cursorTarget && !cursorTarget.CanBeActionTarget())
  204. continue;
  205. //! if the cursor target is a proxy
  206. if ( res.hierLevel > 0 )
  207. {
  208. //! ignores attachments on player
  209. if ( !res.parent.IsMan() )
  210. {
  211. m_VicinityObjects.StoreVicinityObject(res.obj, res.parent);
  212. //Print("storing, 1st pass (hier > 0): " + res.obj);
  213. }
  214. else
  215. continue;
  216. }
  217. else
  218. {
  219. m_VicinityObjects.StoreVicinityObject(res.obj, null);
  220. //Print("storing, 1st pass: " + res.obj);
  221. }
  222. m_HitPos = res.pos;
  223. hitComponentIndex = res.component;
  224. break;
  225. }
  226. }
  227. //else
  228. //Print("NO RESULTS FOUND!");
  229. }
  230. else
  231. {
  232. //Print("CAST UNSUCCESFUL");
  233. cursorTarget = null;
  234. m_HitPos = vector.Zero;
  235. hitComponentIndex = -1;
  236. }
  237. //Print(cursorTarget);
  238. //! spacial search
  239. DayZPlayerCamera camera = m_Player.GetCurrentCamera();
  240. if (camera && camera.GetCurrentPitch() <= -45) // Spatial search is a contributor to very heavy searching, limit it to when we are at least looking down
  241. DayZPlayerUtils.GetEntitiesInCone(playerPos, headingDirection, c_ConeAngle, c_MaxTargetDistance, c_ConeHeightMin, c_ConeHeightMax, vicinityObjects);
  242. //! removes player from the vicinity
  243. vicinityObjects.RemoveItem(m_Player);
  244. //! transformation of array of Objects to hashmap (VicinityObjects)
  245. //Print("m_VicinityObjects before" + m_VicinityObjects.Count());
  246. m_VicinityObjects.TransformToVicinityObjects(vicinityObjects);
  247. //Print("m_VicinityObjects after" + m_VicinityObjects.Count());
  248. //! removes Vicinity objects that are not directly visible from player position
  249. FilterObstructedObjectsEx(cursorTarget, vicinityObjects);
  250. //! select & sort targets based on utility function
  251. for ( i = 0; i < m_VicinityObjects.Count(); i++ )
  252. {
  253. Object object = m_VicinityObjects.GetObject(i);
  254. Object parent = m_VicinityObjects.GetParent(i);
  255. float utility = ComputeUtility(object, m_RayStart, m_RayEnd, cursorTarget, m_HitPos);
  256. if ( utility > 0 )
  257. {
  258. int targetComponent = -1;
  259. targetComponent = hitComponentIndex;
  260. ActionTarget at = new ActionTarget(object, parent, targetComponent, m_HitPos, utility);
  261. StoreTarget(at);
  262. }
  263. /*else
  264. Print("utility < 0; object: " + object + " | parent: " + parent);*/
  265. }
  266. //! action target for surface actions (lowest utility)
  267. if (m_HitPos == vector.Zero)
  268. {
  269. vector contact_pos, contact_dir, hitNormal;
  270. int contactComponent;
  271. float hitFraction;
  272. Object hitObject;
  273. m_RayEnd = m_RayStart + GetGame().GetCurrentCameraDirection() * c_RayDistance * 3;
  274. PhxInteractionLayers collisionLayerMask = PhxInteractionLayers.ROADWAY|PhxInteractionLayers.TERRAIN|PhxInteractionLayers.WATERLAYER;
  275. DayZPhysics.RayCastBullet(m_RayStart,m_RayEnd,collisionLayerMask,null,hitObject,contact_pos,hitNormal,hitFraction);
  276. m_HitPos = contact_pos;
  277. }
  278. m_Targets.Insert(new ActionTarget(null, null, -1, m_HitPos, 0));
  279. #ifdef DIAG_DEVELOPER
  280. if (DiagMenu.GetBool(DiagMenuIDs.MISC_ACTION_TARGETS_DEBUG))
  281. {
  282. ShowDebugActionTargets(true);
  283. DrawDebugActionTargets(true);
  284. DrawDebugCone(true);
  285. DrawDebugRay(true);
  286. DrawSelectionPos(DiagMenu.GetBool(DiagMenuIDs.MISC_ACTION_TARGETS_SELPOS_DEBUG));
  287. }
  288. else
  289. {
  290. ShowDebugActionTargets(false);
  291. DrawDebugActionTargets(false);
  292. DrawDebugCone(false);
  293. DrawDebugRay(false);
  294. DrawSelectionPos(false);
  295. }
  296. #endif
  297. //Print("--------------");
  298. }
  299. private bool IsObstructed(Object object)
  300. {
  301. IsObjectObstructedCache cache = new IsObjectObstructedCache(m_RayStart, 1);
  302. return IsObstructedEx(object, cache);
  303. }
  304. private bool IsObstructedEx(Object object, IsObjectObstructedCache cache)
  305. {
  306. return MiscGameplayFunctions.IsObjectObstructedEx(object, cache);
  307. }
  308. //! returns count of founded targets
  309. int GetTargetsCount()
  310. { return m_Targets.Count(); }
  311. //! returns action target at index
  312. ActionTarget GetTarget(int index)
  313. { return m_Targets.Get(index); }
  314. //! inserts action into sorted array based on utility
  315. private void StoreTarget(ActionTarget pActionTarget)
  316. {
  317. int index = FindIndexForStoring(pActionTarget.GetUtility());
  318. m_Targets.InsertAt(pActionTarget, index);
  319. //Print("StoreTarget; object: " + pActionTarget.GetObject() + " | parent: " + pActionTarget.GetParent() + " | idx: " + index);
  320. }
  321. //! binary search algorithm
  322. private int FindIndexForStoring(float value)
  323. {
  324. int left = 0;
  325. int right = m_Targets.Count() - 1;
  326. while ( left <= right )
  327. {
  328. int middle = (left + right) / 2;
  329. float middleValue = m_Targets.Get(middle).GetUtility();
  330. if ( middleValue == value )
  331. return middle;
  332. else if ( middleValue < value )
  333. right = middle - 1;
  334. else
  335. left = middle + 1;
  336. }
  337. return left;
  338. }
  339. //! computes utility of target
  340. private float ComputeUtility(Object pTarget, vector pRayStart, vector pRayEnd, Object cursorTarget, vector hitPos)
  341. {
  342. //! out of reach
  343. if (vector.DistanceSq(hitPos, m_Player.GetPosition()) > c_MaxTargetDistance * c_MaxTargetDistance)
  344. return -1;
  345. if (pTarget)
  346. {
  347. if ( pTarget == cursorTarget )
  348. {
  349. //! ground and static objects
  350. if ( pTarget.GetType() == string.Empty )
  351. return 0.01;
  352. if ( pTarget.IsBuilding() )
  353. return 0.25;
  354. if ( pTarget.IsTransport() )
  355. return 0.25;
  356. //!basebuilding objects
  357. if (pTarget.CanUseConstruction())
  358. return 0.85;
  359. if ( pTarget.IsWell() )
  360. return 0.9;
  361. vector playerPosXZ = m_Player.GetPosition();
  362. vector hitPosXZ = hitPos;
  363. playerPosXZ[1] = 0;
  364. hitPosXZ[1] = 0;
  365. if ( vector.DistanceSq(playerPosXZ, hitPosXZ) <= c_MaxTargetDistance * c_MaxTargetDistance )
  366. return c_UtilityMaxValue;
  367. }
  368. float distSqr = DistSqrPoint2Line(pTarget.GetPosition(), pRayStart, pRayEnd);
  369. return (c_UtilityMaxDistFromRaySqr - distSqr) / c_UtilityMaxDistFromRaySqr;
  370. }
  371. return -1;
  372. }
  373. //! distance between point and line
  374. private float DistSqrPoint2Line(vector pPoint, vector pL1, vector pL2)
  375. {
  376. vector v = pL2 - pL1;
  377. vector w = pPoint - pL1;
  378. float c1 = vector.Dot(w,v);
  379. float c2 = vector.Dot(v,v);
  380. if ( c1 <= 0 || c2 == 0 )
  381. return vector.DistanceSq(pPoint, pL1);
  382. float b = c1 / c2;
  383. vector nearestPoint = pL1 + (v * b);
  384. return vector.DistanceSq(pPoint, nearestPoint);
  385. }
  386. private void FilterObstructedObjectsEx(Object cursor_target, array<Object> vicinityObjects)
  387. {
  388. #ifdef DIAG_DEVELOPER
  389. if (DiagMenu.GetBool(DiagMenuIDs.MISC_ACTION_TARGETS_DEBUG))
  390. CleanupDebugShapes(obstruction);
  391. #endif
  392. array<Object> obstructingObjects = new array<Object>;
  393. MiscGameplayFunctions.FilterObstructingObjects(vicinityObjects, obstructingObjects);
  394. if ( obstructingObjects.Count() > 0 )
  395. {
  396. PlayerBase player = PlayerBase.Cast(g_Game.GetPlayer());
  397. int numObstructed = 0;
  398. int mCount = m_VicinityObjects.Count();
  399. if (mCount > GROUPING_COUNT_THRESHOLD)
  400. {
  401. array<Object> filteredObjects = new array<Object>;
  402. MiscGameplayFunctions.FilterObstructedObjectsByGrouping(m_RayStart, c_MaxTargetDistance, c_DistanceDelta, m_VicinityObjects.GetRawVicinityObjects(), vicinityObjects, filteredObjects);
  403. m_VicinityObjects.ClearVicinityObjects();
  404. m_VicinityObjects.TransformToVicinityObjects(filteredObjects);
  405. }
  406. else
  407. {
  408. FilterObstructedObjects(cursor_target);
  409. }
  410. }
  411. }
  412. private void FilterObstructedObjects(Object cursor_target)
  413. {
  414. int numObstructed = 0;
  415. int mCount = m_VicinityObjects.Count();
  416. IsObjectObstructedCache cache = new IsObjectObstructedCache(m_RayStart, mCount);
  417. mCount--;
  418. //! check if targets are not obstructed (eg.: wall)
  419. for ( int i = mCount; i >= 0; --i )
  420. {
  421. Object object = m_VicinityObjects.GetObject(i);
  422. Object parent = m_VicinityObjects.GetParent(i);
  423. //! check for object obstruction(if the object is not a proxy - has no parent)
  424. if (object && !parent)
  425. {
  426. //! when the number of obstructed items is higher than OBSTRUCTED_COUNT_THRESHOLD
  427. //! remove do no run obstruction check and skip these items
  428. if (numObstructed > OBSTRUCTED_COUNT_THRESHOLD && object != cursor_target)
  429. {
  430. m_VicinityObjects.Remove(object);
  431. continue;
  432. }
  433. //! obstruction check
  434. if (object != cursor_target && IsObstructedEx(object, cache))
  435. {
  436. m_VicinityObjects.Remove(object);
  437. numObstructed++;
  438. }
  439. cache.ClearCache();
  440. }
  441. }
  442. }
  443. #ifdef DIAG_DEVELOPER
  444. ref array<Shape> shapes = new array<Shape>();
  445. ref array<Shape> dbgConeShapes = new array<Shape>();
  446. ref array<Shape> rayShapes = new array<Shape>();
  447. ref array<Shape> obstruction = new array<Shape>();
  448. ref array<Shape> dbgPosShapes = new array<Shape>();
  449. void ShowDebugActionTargets(bool enabled)
  450. {
  451. int windowPosX = 0;
  452. int windowPosY = 50;
  453. Object obj;
  454. DbgUI.BeginCleanupScope();
  455. DbgUI.Begin("Action Targets", windowPosX, windowPosY);
  456. if ( enabled )
  457. {
  458. for ( int i = 0; i < GetTargetsCount(); i++ )
  459. {
  460. obj = m_Targets.Get(i).GetObject();
  461. if ( obj )
  462. {
  463. float util = m_Targets.Get(i).GetUtility();
  464. int compIdx = m_Targets.Get(i).GetComponentIndex();
  465. string compName;
  466. array<string> compNames = new array<string>;
  467. compName = obj.GetActionComponentName(compIdx);
  468. obj.GetActionComponentNameList(compIdx, compNames);
  469. if ( compNames.Count() > 0 )
  470. {
  471. for ( int c = 0; c < compNames.Count(); c++ )
  472. {
  473. DbgUI.Text(obj.GetDisplayName() + " :: " + obj + " | util: " + util + " | compIdx: " + compIdx + " | compName: " + compNames[c] + "| wPos: " + obj.GetWorldPosition() );
  474. }
  475. }
  476. else
  477. {
  478. DbgUI.Text(obj.GetDisplayName() + " :: " + obj + " | util: " + util + " | compIdx: " + compIdx + " | compName: " + compName + "| wPos: " + obj.GetWorldPosition() );
  479. }
  480. }
  481. else
  482. continue;
  483. }
  484. }
  485. DbgUI.End();
  486. DbgUI.EndCleanupScope();
  487. }
  488. void DrawDebugActionTargets(bool enabled)
  489. {
  490. int s_id;
  491. vector w_pos;
  492. vector w_pos_sphr;
  493. vector w_pos_lend;
  494. Object obj;
  495. if ( enabled )
  496. {
  497. CleanupDebugShapes(shapes);
  498. for ( int i = 0; i < GetTargetsCount(); i++ )
  499. {
  500. obj = m_Targets.Get(i).GetObject();
  501. if ( obj )
  502. {
  503. w_pos = obj.GetPosition();
  504. // sphere pos tweaks
  505. w_pos_sphr = w_pos;
  506. w_pos_sphr[1] = w_pos_sphr[1] + 0.5;
  507. // line pos tweaks
  508. w_pos_lend = w_pos;
  509. w_pos_lend[1] = w_pos_lend[1] + 0.5;
  510. if ( i == 0 )
  511. {
  512. shapes.Insert( Debug.DrawSphere(w_pos_sphr, 0.03, COLOR_RED) );
  513. shapes.Insert( Debug.DrawLine(w_pos, w_pos_lend, COLOR_RED) );
  514. }
  515. else
  516. {
  517. shapes.Insert( Debug.DrawSphere(w_pos_sphr, 0.03, COLOR_YELLOW) );
  518. shapes.Insert( Debug.DrawLine(w_pos, w_pos_lend, COLOR_YELLOW) );
  519. }
  520. }
  521. }
  522. }
  523. else
  524. CleanupDebugShapes(shapes);
  525. }
  526. private void DrawDebugCone(bool enabled)
  527. {
  528. // "cone" settings
  529. vector start, end, endL, endR;
  530. float playerAngle;
  531. float xL,xR,zL,zR;
  532. if (enabled)
  533. {
  534. CleanupDebugShapes(dbgConeShapes);
  535. start = m_Player.GetPosition();
  536. playerAngle = MiscGameplayFunctions.GetHeadingAngle(m_Player);
  537. // offset position of the shape in height
  538. start[1] = start[1] + 0.2;
  539. endL = start;
  540. endR = start;
  541. xL = c_MaxTargetDistance * Math.Cos(playerAngle + Math.PI_HALF + c_ConeAngle * Math.DEG2RAD); // x
  542. zL = c_MaxTargetDistance * Math.Sin(playerAngle + Math.PI_HALF + c_ConeAngle * Math.DEG2RAD); // z
  543. xR = c_MaxTargetDistance * Math.Cos(playerAngle + Math.PI_HALF - c_ConeAngle * Math.DEG2RAD); // x
  544. zR = c_MaxTargetDistance * Math.Sin(playerAngle + Math.PI_HALF - c_ConeAngle * Math.DEG2RAD); // z
  545. endL[0] = endL[0] + xL;
  546. endL[2] = endL[2] + zL;
  547. endR[0] = endR[0] + xR;
  548. endR[2] = endR[2] + zR;
  549. dbgConeShapes.Insert( Debug.DrawLine(start, endL, COLOR_BLUE) );
  550. dbgConeShapes.Insert( Debug.DrawLine(start, endR, COLOR_BLUE) ) ;
  551. dbgConeShapes.Insert( Debug.DrawLine(endL, endR, COLOR_BLUE) );
  552. }
  553. else
  554. CleanupDebugShapes(dbgConeShapes);
  555. }
  556. private void DrawSelectionPos(bool enabled)
  557. {
  558. if (enabled)
  559. {
  560. CleanupDebugShapes(dbgPosShapes);
  561. if (GetTargetsCount() > 0 && GetTarget(0).GetUtility() > -1 )
  562. {
  563. ActionTarget at = GetTarget(0);
  564. if (at.GetObject())
  565. {
  566. string compName = at.GetObject().GetActionComponentName(at.GetComponentIndex());
  567. vector modelPos = at.GetObject().GetSelectionPositionMS(compName);
  568. vector worldPos = at.GetObject().ModelToWorld(modelPos);
  569. dbgPosShapes.Insert( Debug.DrawSphere(worldPos, 0.25, Colors.PURPLE, ShapeFlags.NOZBUFFER) );
  570. }
  571. }
  572. }
  573. else
  574. CleanupDebugShapes(dbgPosShapes);
  575. }
  576. private void DrawDebugRay(bool enabled)
  577. {
  578. if (enabled)
  579. {
  580. CleanupDebugShapes(rayShapes);
  581. rayShapes.Insert( Debug.DrawSphere(m_HitPos, Math.Sqrt(c_UtilityMaxDistFromRaySqr), COLOR_BLUE_A, ShapeFlags.TRANSP) );
  582. rayShapes.Insert( Debug.DrawLine(m_RayStart, m_RayEnd, COLOR_BLUE) );
  583. }
  584. else
  585. CleanupDebugShapes(rayShapes);
  586. }
  587. private void CleanupDebugShapes(array<Shape> shapesArr)
  588. {
  589. for ( int it = 0; it < shapesArr.Count(); ++it )
  590. {
  591. Debug.RemoveShape( shapesArr[it] );
  592. }
  593. shapesArr.Clear();
  594. }
  595. #endif
  596. //--------------------------------------------------------
  597. // Members
  598. //--------------------------------------------------------
  599. //! player owner
  600. private PlayerBase m_Player;
  601. //! selected & sorted targets by utility function
  602. private ref array<ref ActionTarget> m_Targets;
  603. //! objects in vicinity
  604. static private ref VicinityObjects m_VicinityObjects
  605. private bool m_Debug
  606. private vector m_RayStart;
  607. private vector m_RayEnd;
  608. private vector m_HitPos;
  609. //--------------------------------------------------------
  610. // Constants
  611. //--------------------------------------------------------
  612. //! searching properties
  613. private const float c_RayDistance = 5.0;
  614. private const float c_MaxTargetDistance = 3.0;
  615. private const float c_MaxActionDistance = UAMaxDistances.DEFAULT;
  616. private const float c_ConeAngle = 30.0;
  617. private const float c_ConeHeightMin = -0.5;
  618. private const float c_ConeHeightMax = 2.0;
  619. private const float c_DistanceDelta = 0.3;
  620. //! utility constants
  621. private const float c_UtilityMaxValue = 10000;
  622. private const float c_UtilityMaxDistFromRaySqr = 0.8 * 0.8;
  623. //! p3d
  624. private const string CE_CENTER = "ce_center";
  625. private const float HEIGHT_OFFSET = 0.2;
  626. //! misc
  627. private const int OBSTRUCTED_COUNT_THRESHOLD = 3;
  628. private const int GROUPING_COUNT_THRESHOLD = 10;
  629. //! DEPRECATED
  630. vector CalculateRayStart();
  631. };
  632. class ObjectGroup
  633. {
  634. ref array<Object> Objects = new array<Object>;
  635. }