DayZ 1.27
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

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 строка 194

195 {
196 int i;
197
199 m_VicinityObjects.ClearVicinityObjects();
200 Clear();
201
202 Object cursorTarget = null;
203 EntityAI cursorTargetEntity = null;
204 array<Object> vicinityObjects = new array<Object>;
205
207 int hitComponentIndex;
208 vector playerPos = m_Player.GetPosition();
209 vector headingDirection = MiscGameplayFunctions.GetHeadingVector(m_Player);
210
213
214 RaycastRVParams rayInput = new RaycastRVParams(m_RayStart, m_RayEnd, m_Player);
215 rayInput.flags = CollisionFlags.ALLOBJECTS;
216 //rayInput.sorted = true;
217 array<ref RaycastRVResult> results = new array<ref RaycastRVResult>;
218
219 if ( DayZPhysics.RaycastRVProxy(rayInput, results) )
220 {
221 if ( results.Count() > 0 )
222 {
223 array<float> distance_helper = new array<float>;
224 array<float> distance_helper_unsorted = new array<float>;
225 float distance;
226
227 for (i = 0; i < results.Count(); i++)
228 {
229 distance = vector.DistanceSq(results[i].pos, m_RayStart);
230 distance_helper.Insert(distance);
231 //Print("#" + i + " " + results.Get(i).obj);
232 }
233 //Print("--------------");
234 distance_helper_unsorted.Copy(distance_helper);
235 distance_helper.Sort();
236
237 RaycastRVResult res;
238
239
240 for ( i = 0; i < results.Count(); i++)
241 {
242 res = results.Get(distance_helper_unsorted.Find(distance_helper[i])); //closest object
243
244 cursorTarget = res.obj;
245 Class.CastTo(cursorTargetEntity,cursorTarget);
246 if (cursorTarget && !cursorTarget.CanBeActionTarget())
247 continue;
249 if ( res.hierLevel > 0 )
250 {
252 if ( !res.parent.IsMan() )
253 {
254 m_VicinityObjects.StoreVicinityObject(res.obj, res.parent);
255 //Print("storing, 1st pass (hier > 0): " + res.obj);
256 }
257 else
258 continue;
259 }
260 else
261 {
262 m_VicinityObjects.StoreVicinityObject(res.obj, null);
263 //Print("storing, 1st pass: " + res.obj);
264 }
265
266 m_HitPos = res.pos;
267 hitComponentIndex = res.component;
268 break;
269 }
270 }
271 //else
272 //Print("NO RESULTS FOUND!");
273 }
274 else
275 {
276 //Print("CAST UNSUCCESFUL");
277 cursorTarget = null;
278 m_HitPos = vector.Zero;
279 hitComponentIndex = -1;
280 }
281
282 //Print(cursorTarget);
283
285 DayZPlayerCamera camera = m_Player.GetCurrentCamera();
286 if (camera && camera.GetCurrentPitch() <= -45) // Spatial search is a contributor to very heavy searching, limit it to when we are at least looking down
287 DayZPlayerUtils.GetEntitiesInCone(playerPos, headingDirection, c_ConeAngle, c_MaxTargetDistance, c_ConeHeightMin, c_ConeHeightMax, vicinityObjects);
288
290 vicinityObjects.RemoveItem(m_Player);
291
293 //Print("m_VicinityObjects before" + m_VicinityObjects.Count());
294 m_VicinityObjects.TransformToVicinityObjects(vicinityObjects);
295 //Print("m_VicinityObjects after" + m_VicinityObjects.Count());
296
298 FilterObstructedObjectsEx(cursorTarget, vicinityObjects);
299
301 for ( i = 0; i < m_VicinityObjects.Count(); i++ )
302 {
303 Object object = m_VicinityObjects.GetObject(i);
304 Object parent = m_VicinityObjects.GetParent(i);
305
306 float utility = ComputeUtility(object, m_RayStart, m_RayEnd, cursorTarget, m_HitPos);
307 if ( utility > 0 )
308 {
309 int targetComponent = -1;
310 targetComponent = hitComponentIndex;
311
312 ActionTarget at = new ActionTarget(object, parent, targetComponent, m_HitPos, utility);
313 StoreTarget(at);
314 }
315 /*else
316 Print("utility < 0; object: " + object + " | parent: " + parent);*/
317 }
318
320 if (m_HitPos == vector.Zero)
321 {
322 vector contact_pos, contact_dir, hitNormal;
323 int contactComponent;
324 float hitFraction;
325 Object hitObject;
326
328
329 PhxInteractionLayers collisionLayerMask = PhxInteractionLayers.ROADWAY|PhxInteractionLayers.TERRAIN|PhxInteractionLayers.WATERLAYER;
330 DayZPhysics.RayCastBullet(m_RayStart,m_RayEnd,collisionLayerMask,null,hitObject,contact_pos,hitNormal,hitFraction);
331 m_HitPos = contact_pos;
332 }
333
334 m_Targets.Insert(new ActionTarget(null, null, -1, m_HitPos, 0));
335
336#ifdef DIAG_DEVELOPER
337 if (DiagMenu.GetBool(DiagMenuIDs.MISC_ACTION_TARGETS_DEBUG))
338 {
339 ShowDebugActionTargets(true);
340 DrawDebugActionTargets(true);
341 DrawDebugCone(true);
342 DrawDebugRay(true);
343 DrawSelectionPos(DiagMenu.GetBool(DiagMenuIDs.MISC_ACTION_TARGETS_SELPOS_DEBUG));
344 }
345 else
346 {
347 ShowDebugActionTargets(false);
348 DrawDebugActionTargets(false);
349 DrawDebugCone(false);
350 DrawDebugRay(false);
351 DrawSelectionPos(false);
352 }
353#endif
354 //Print("--------------");
355 }
class LogManager EntityAI
class ActionTargets ActionTarget
ref map< Object, Object > m_VicinityObjects
Определения ActionTargets.c:114
PhxInteractionLayers
Определения DayZPhysics.c:2
void DayZPlayerUtils()
cannot be instantiated
Определения DayZPlayerUtils.c:465
DiagMenuIDs
Определения EDiagMenuIDs.c:2
const float c_MaxTargetDistance
Определения ActionTargets.c:730
vector m_RayEnd
Определения ActionTargets.c:722
const float c_ConeAngle
Определения ActionTargets.c:732
vector m_HitPos
Определения ActionTargets.c:723
void StoreTarget(ActionTarget pActionTarget)
inserts action into sorted array based on utility
Определения ActionTargets.c:377
const float c_RayDistance
searching properties
Определения ActionTargets.c:729
PlayerBase m_Player
player owner
Определения ActionTargets.c:711
void FilterObstructedObjectsEx(Object cursor_target, array< Object > vicinityObjects)
Определения ActionTargets.c:468
void Clear()
Определения ActionTargets.c:189
vector m_RayStart
objects in vicinity
Определения ActionTargets.c:721
ref array< ref ActionTarget > m_Targets
selected & sorted targets by utility function
Определения ActionTargets.c:714
float ComputeUtility(Object pTarget, vector pRayStart, vector pRayEnd, Object cursorTarget, vector hitPos)
computes utility of target
Определения ActionTargets.c:406
const float c_ConeHeightMax
Определения ActionTargets.c:734
const float c_ConeHeightMin
Определения ActionTargets.c:733
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
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
class DayZPlayerCameraResult DayZPlayerCamera(DayZPlayer pPlayer, HumanInputController pInput)
Определения dayzplayer.c:56
class LOD Object
proto native CGame GetGame()
CollisionFlags
Определения EnDebug.c:141