DayZ 1.28
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено

◆ Update()

void ActionTargets::Update ( )
inlineprivate

clear state

camera & ray properties

if the cursor target is a proxy

ignores attachments on player

Need to do this surface detection here as the current RaycastRVResult might not contain the correct surface info

Check current surface player is looking at

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)

См. определение в файле ActionTargets.c строка 224

225 {
226 int i;
227
229 m_VicinityObjects.ClearVicinityObjects();
230 Clear();
231
232 Object cursorTarget = null;
233 EntityAI cursorTargetEntity = null;
234 array<Object> vicinityObjects = new array<Object>;
235
237 int hitComponentIndex;
238 vector playerPos = m_Player.GetPosition();
239 vector headingDirection = MiscGameplayFunctions.GetHeadingVector(m_Player);
240
243
244 RaycastRVParams rayInput = new RaycastRVParams(m_RayStart, m_RayEnd, m_Player);
245 rayInput.flags = CollisionFlags.ALLOBJECTS;
246 //rayInput.sorted = true;
247 array<ref RaycastRVResult> results = new array<ref RaycastRVResult>;
248
249 if ( DayZPhysics.RaycastRVProxy(rayInput, results) )
250 {
251 if ( results.Count() > 0 )
252 {
253 array<float> distance_helper = new array<float>;
254 array<float> distance_helper_unsorted = new array<float>;
255 float distance;
256
257 for (i = 0; i < results.Count(); i++)
258 {
259 distance = vector.DistanceSq(results[i].pos, m_RayStart);
260 distance_helper.Insert(distance);
261 //Print("#" + i + " " + results.Get(i).obj);
262 }
263 //Print("--------------");
264 distance_helper_unsorted.Copy(distance_helper);
265 distance_helper.Sort();
266
267 RaycastRVResult res;
268
269 for (i = 0; i < results.Count(); i++)
270 {
271 res = results.Get(distance_helper_unsorted.Find(distance_helper[i])); //closest object
272
273 cursorTarget = res.obj;
274 Class.CastTo(cursorTargetEntity,cursorTarget);
275 if (cursorTarget && !cursorTarget.CanBeActionTarget())
276 continue;
278 if (res.hierLevel > 0)
279 {
281 if (!res.parent.IsMan())
282 {
283 m_VicinityObjects.StoreVicinityObject(res.obj, res.parent);
284 //Print("storing, 1st pass (hier > 0): " + res.obj);
285 }
286 else
287 continue;
288 }
289 else
290 {
291 m_VicinityObjects.StoreVicinityObject(res.obj, null);
292 //Print("storing, 1st pass: " + res.obj);
293 }
294
295 m_HitPos = res.pos;
296 hitComponentIndex = res.component;
297
298 if (res.surface && res.surface.GetSurfaceType() != "")
299 {
301 }
302 else
303 {
305 SurfaceDetectionParameters surfaceParams = new SurfaceDetectionParameters();
306 surfaceParams.type = SurfaceDetectionType.Roadway;
307 surfaceParams.position = m_HitPos;
308 surfaceParams.includeWater = true;
309 surfaceParams.syncMode = UseObjectsMode.NoWait;
310 surfaceParams.rsd = RoadSurfaceDetection.ABOVE;
311
313 SurfaceDetectionResult surfaceResult = new SurfaceDetectionResult();
314 if (g_Game.GetSurface(surfaceParams, surfaceResult))
315 {
316 if (surfaceResult && surfaceResult.surface)
317 {
318 m_SurfaceInfo = surfaceResult.surface;
319 }
320 }
321 }
322 break;
323 }
324 }
325 //else
326 //Print("NO RESULTS FOUND!");
327 }
328 else
329 {
330 //Print("CAST UNSUCCESFUL");
331 cursorTarget = null;
332 m_HitPos = vector.Zero;
333 m_SurfaceInfo = null;
334 hitComponentIndex = -1;
335 }
336
337 //Print(cursorTarget);
338
340 DayZPlayerCamera camera = m_Player.GetCurrentCamera();
341 if (camera && camera.GetCurrentPitch() <= -45) // Spatial search is a contributor to very heavy searching, limit it to when we are at least looking down
342 DayZPlayerUtils.GetEntitiesInCone(playerPos, headingDirection, c_ConeAngle, c_MaxTargetDistance, c_ConeHeightMin, c_ConeHeightMax, vicinityObjects);
343
345 vicinityObjects.RemoveItem(m_Player);
346
348 //Print("m_VicinityObjects before" + m_VicinityObjects.Count());
349 m_VicinityObjects.TransformToVicinityObjects(vicinityObjects);
350 //Print("m_VicinityObjects after" + m_VicinityObjects.Count());
351
353 FilterObstructedObjectsEx(cursorTarget, vicinityObjects);
354
356 for (i = 0; i < m_VicinityObjects.Count(); i++)
357 {
358 Object object = m_VicinityObjects.GetObject(i);
359 Object parent = m_VicinityObjects.GetParent(i);
360
361 float utility = ComputeUtility(object, m_RayStart, m_RayEnd, cursorTarget, m_HitPos, m_SurfaceInfo);
362 if (utility > 0)
363 {
364 int targetComponent = -1;
365 targetComponent = hitComponentIndex;
366
367 string surfaceName;
368 if (m_SurfaceInfo && m_SurfaceInfo.GetEntryName() != "")
369 surfaceName = m_SurfaceInfo.GetEntryName();
370
371 ActionTarget at = new ActionTarget(object, parent, targetComponent, m_HitPos, utility, surfaceName);
372 StoreTarget(at);
373 }
374 /*else
375 Print("utility < 0; object: " + object + " | parent: " + parent);*/
376 }
377
379 if (m_HitPos == vector.Zero)
380 {
381 vector contact_pos, contact_dir, hitNormal;
382 int contactComponent;
383 float hitFraction;
384 Object hitObject;
385
387
388 PhxInteractionLayers collisionLayerMask = PhxInteractionLayers.ROADWAY|PhxInteractionLayers.TERRAIN|PhxInteractionLayers.WATERLAYER;
389 DayZPhysics.RayCastBullet(m_RayStart,m_RayEnd,collisionLayerMask,null,hitObject,contact_pos,hitNormal,hitFraction);
390 m_HitPos = contact_pos;
391 }
392
393 m_Targets.Insert(new ActionTarget(null, null, -1, m_HitPos, 0));
394
395#ifdef DIAG_DEVELOPER
396 if (DiagMenu.GetBool(DiagMenuIDs.MISC_ACTION_TARGETS_DEBUG))
397 {
398 ShowDebugActionTargets(true);
399 DrawDebugActionTargets(true);
400 DrawDebugCone(true);
401 DrawDebugRay(true);
402 DrawSelectionPos(DiagMenu.GetBool(DiagMenuIDs.MISC_ACTION_TARGETS_SELPOS_DEBUG));
403 }
404 else
405 {
406 ShowDebugActionTargets(false);
407 DrawDebugActionTargets(false);
408 DrawDebugCone(false);
409 DrawDebugRay(false);
410 DrawSelectionPos(false);
411 }
412#endif
413 //Print("--------------");
414 }
class LogManager EntityAI
void ActionTarget(Object object, Object parent, int componentIndex, vector cursorHitPos, float utility, string surfaceName="")
Определения ActionTargets.c:121
DayZGame g_Game
Определения DayZGame.c:3868
PhxInteractionLayers
Определения DayZPhysics.c:2
void DayZPlayerUtils()
cannot be instantiated
Определения DayZPlayerUtils.c:465
DiagMenuIDs
Определения EDiagMenuIDs.c:2
SurfaceDetectionType
Определения SurfaceInfo.c:66
UseObjectsMode
Определения SurfaceInfo.c:54
SurfaceInfo m_SurfaceInfo
Определения ActionTargets.c:788
const float c_MaxTargetDistance
Определения ActionTargets.c:795
vector m_RayEnd
Определения ActionTargets.c:785
float ComputeUtility(Object pTarget, vector pRayStart, vector pRayEnd, Object cursorTarget, vector hitPos, SurfaceInfo surfaceInfo)
computes utility of target
Определения ActionTargets.c:465
const float c_ConeAngle
Определения ActionTargets.c:797
vector m_HitPos
Определения ActionTargets.c:786
void StoreTarget(ActionTarget pActionTarget)
inserts action into sorted array based on utility
Определения ActionTargets.c:436
const float c_RayDistance
searching properties
Определения ActionTargets.c:794
PlayerBase m_Player
player owner
Определения ActionTargets.c:774
void FilterObstructedObjectsEx(Object cursor_target, array< Object > vicinityObjects)
Определения ActionTargets.c:531
void Clear()
Определения ActionTargets.c:219
vector m_RayStart
objects in vicinity
Определения ActionTargets.c:784
ref array< ref ActionTarget > m_Targets
selected & sorted targets by utility function
Определения ActionTargets.c:777
const float c_ConeHeightMax
Определения ActionTargets.c:799
const float c_ConeHeightMin
Определения ActionTargets.c:798
proto native vector GetCurrentCameraPosition()
proto native vector GetCurrentCameraDirection()
CollisionFlags flags
Определения DayZPhysics.c:63
Object obj
object,that we collide with (NULL if none), If hierLevel > 0 object is the proxy object
Определения DayZPhysics.c:100
int component
index of component in corresponding geometry level
Определения DayZPhysics.c:107
int hierLevel
which hierarchy level is the collision detected at, == 0 = objects in landscape, > 0 = proxy
Определения DayZPhysics.c:106
SurfaceInfo surface
surface material info handle
Определения DayZPhysics.c:109
vector pos
position of collision (in world coord)
Определения DayZPhysics.c:103
Object parent
if hierLevel > 0 most parent of the proxy object
Определения DayZPhysics.c:101
bool includeWater
Include water in the surface detection, will return the water if it is higher than the surface.
Определения SurfaceInfo.c:83
SurfaceDetectionType type
Type of surface to detect.
Определения SurfaceInfo.c:77
RoadSurfaceDetection rsd
See RoadSurfaceDetection, SurfaceTraceType.Roadway only.
Определения SurfaceInfo.c:92
vector position
3D position to trace the surface from
Определения SurfaceInfo.c:80
UseObjectsMode syncMode
See UseObjectsMode, SurfaceTraceType.Roadway only.
Определения SurfaceInfo.c:86
SurfaceInfo surface
Returned SurfaceInfo, plain pointer.
Определения SurfaceInfo.c:114
proto string GetSurfaceType()
class DayZPlayerCameraResult DayZPlayerCamera(DayZPlayer pPlayer, HumanInputController pInput)
Определения dayzplayer.c:56
class LOD Object
proto native CGame GetGame()
CollisionFlags
Определения EnDebug.c:141

Перекрестные ссылки ActionTarget(), c_ConeAngle, c_ConeHeightMax, c_ConeHeightMin, c_MaxTargetDistance, c_RayDistance, Class::CastTo(), Clear(), RaycastRVResult::component, ComputeUtility(), DayZPlayerCamera(), DayZPlayerUtils(), vector::DistanceSq(), FilterObstructedObjectsEx(), RaycastRVParams::flags, g_Game, DiagMenu::GetBool(), CGame::GetCurrentCameraDirection(), CGame::GetCurrentCameraPosition(), GetGame(), SurfaceInfo::GetSurfaceType(), RaycastRVResult::hierLevel, SurfaceDetectionParameters::includeWater, m_HitPos, m_Player, m_RayEnd, m_RayStart, m_SurfaceInfo, m_Targets, RaycastRVResult::obj, RaycastRVResult::parent, RaycastRVResult::pos, SurfaceDetectionParameters::position, DayZPhysics::RayCastBullet(), DayZPhysics::RaycastRVProxy(), SurfaceDetectionParameters::rsd, StoreTarget(), RaycastRVResult::surface, SurfaceDetectionResult::surface, SurfaceDetectionParameters::syncMode, SurfaceDetectionParameters::type и vector::Zero.