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

◆ RefreshVicinityItems()

void VicinityItemManager::RefreshVicinityItems ( )
inlineprivate

If in free camera, override the position that the inventory gets generated from

If in free camera, don't worry about obstructed objects if there are any

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

209 {
210 PlayerBase player = PlayerBase.Cast(g_Game.GetPlayer());
211
212 array<Object> objectsInVicinity = new array<Object>();
213 array<CargoBase> proxyCargos = new array<CargoBase>();
214 array<Object> filteredObjects = new array<Object>();
215 array<Object> allFoundObjects = new array<Object>();
216 vector playerPosition = player.GetPosition();
217 vector playerHeadPositionFixed = MiscGameplayFunctions.GetPlayerHeadPosition(player);
218 vector headingDirection = MiscGameplayFunctions.GetHeadingVector(player);
219
221 bool cameraActive = FreeDebugCamera.GetInstance() && FreeDebugCamera.GetInstance().IsActive();
222 if (cameraActive)
223 {
224 playerPosition = FreeDebugCamera.GetInstance().GetPosition();
225 playerHeadPositionFixed = playerPosition;
226
227 float headingAngle = FreeDebugCamera.GetInstance().GetOrientation()[0] * Math.DEG2RAD;
228
229 headingDirection[0] = Math.Cos(headingAngle);
230 headingDirection[1] = 0;
231 headingDirection[2] = Math.Sin(headingAngle);
232 headingDirection.Normalize();
233 }
234
235 if (m_VicinityItems)
236 m_VicinityItems.Clear();
237
239 m_VicinityCargos.Clear();
240
241 //1. GetAll actors in VICINITY_ACTOR_DISTANCE
242 //DebugActorsSphereDraw(VICINITY_ACTOR_DISTANCE);
243 g_Game.GetObjectsAtPosition3D(playerPosition, VICINITY_ACTOR_DISTANCE, objectsInVicinity, proxyCargos);
244
245 // no filtering for cargo (initial implementation)
246 foreach (CargoBase cargoObject : proxyCargos)
247 AddVicinityCargos(cargoObject);
248
249 //filter unnecessary and duplicate objects beforehand
250 foreach (Object actorInRadius : objectsInVicinity)
251 {
252 if (allFoundObjects.Find(actorInRadius) == INDEX_NOT_FOUND)
253 allFoundObjects.Insert(actorInRadius);
254
255 if (ExcludeFromContainer_Phase1(actorInRadius))
256 continue;
257
258 if (filteredObjects.Find(actorInRadius) == INDEX_NOT_FOUND)
259 filteredObjects.Insert(actorInRadius);
260 }
261
262 if (objectsInVicinity)
263 objectsInVicinity.Clear();
264
265 //2. GetAll Objects in VICINITY_DISTANCE
266 g_Game.GetObjectsAtPosition3D(playerPosition, VICINITY_DISTANCE, objectsInVicinity, proxyCargos);
267 //DebugObjectsSphereDraw(VICINITY_DISTANCE);
268
269 //filter unnecessary and duplicate objects beforehand
270 foreach (Object objectInRadius : objectsInVicinity)
271 {
272 if (allFoundObjects.Find(objectInRadius) == INDEX_NOT_FOUND)
273 allFoundObjects.Insert(objectInRadius);
274
275 if (ExcludeFromContainer_Phase2(objectInRadius))
276 continue;
277
278 if (filteredObjects.Find(objectInRadius) == INDEX_NOT_FOUND)
279 filteredObjects.Insert(objectInRadius);
280 }
281
282 if (objectsInVicinity)
283 objectsInVicinity.Clear();
284
285 //3. Add objects from GetEntitiesInCone
286 DayZPlayerUtils.GetEntitiesInCone(playerPosition, headingDirection, VICINITY_CONE_ANGLE, VICINITY_CONE_REACH_DISTANCE, CONE_HEIGHT_MIN, CONE_HEIGHT_MAX, objectsInVicinity);
287 //DebugConeDraw(playerPosition, VICINITY_CONE_ANGLE);
288
289 RaycastRVParams rayInput;
290 array<ref RaycastRVResult> raycastResults = new array<ref RaycastRVResult>();
291 //filter unnecessary and duplicate objects beforehand
292 foreach (Object objectInCone : objectsInVicinity)
293 {
294 if (allFoundObjects.Find(objectInCone) == INDEX_NOT_FOUND)
295 allFoundObjects.Insert(objectInCone);
296
297 if (ExcludeFromContainer_Phase3(objectInCone))
298 continue;
299
300 if (filteredObjects.Find(objectInCone) == INDEX_NOT_FOUND)
301 {
302 //if (objectInCone.IsBuilding()) //TODO: redo, buildings will show only some attachment groups, similar to cars or BBB objects
303 EntityAI ent;
304 if (Class.CastTo(ent,objectInCone) && ent.GetInventory())
305 {
306 //Print(ent.GetModelName());
307 filteredObjects.Insert(objectInCone);
308 continue;
309 }
310
311 rayInput = new RaycastRVParams(playerHeadPositionFixed, objectInCone.GetPosition());
312 rayInput.flags = CollisionFlags.ALLOBJECTS;
313 rayInput.type = ObjIntersectView;
314 rayInput.radius = 0.1;
315 DayZPhysics.RaycastRVProxy(rayInput, raycastResults, {player});
316 //Debug.DrawLine(playerHeadPositionFixed,objectInCone.GetPosition(),COLOR_WHITE,ShapeFlags.ONCE);
317
318 foreach (RaycastRVResult result : raycastResults)
319 {
320 if (vector.DistanceSq(result.pos, playerPosition) > VICINITY_CONE_REACH_DISTANCE * VICINITY_CONE_REACH_DISTANCE)
321 continue;
322
323 if (result.hierLevel > 0)
324 {
325 if (result.parent.CanProxyObstruct())
326 break;
327
328 if (result.parent == objectInCone)
329 {
330 filteredObjects.Insert(objectInCone);
331 break;
332 }
333 }
334 else
335 {
336 if (result.obj == objectInCone)
337 {
338 filteredObjects.Insert(objectInCone);
339 break;
340 }
341 }
342 }
343 }
344 }
345
346 //4. Add large objects - particularly buildings and BaseBuildingBase
347 BoxCollidingParams params = new BoxCollidingParams();
348 vector boxEdgeLength = {
352 };
353
354 params.SetParams(playerPosition, headingDirection.VectorToAngles(), boxEdgeLength * 2, ObjIntersect.View, ObjIntersect.Fire, true);
355 array<ref BoxCollidingResult> results = new array<ref BoxCollidingResult>();
356 if (g_Game.IsBoxCollidingGeometryProxy(params, {player}, results))
357 {
358 foreach (BoxCollidingResult bResult : results)
359 {
360 if (bResult.obj && (bResult.obj.CanObstruct() || bResult.obj.CanProxyObstruct()))
361 {
362 if (allFoundObjects.Find(bResult.obj) == INDEX_NOT_FOUND)
363 allFoundObjects.Insert(bResult.obj);
364 }
365
366 if (bResult.parent && (bResult.parent.CanObstruct() || bResult.parent.CanProxyObstruct()))
367 {
368 if (allFoundObjects.Find(bResult.parent) == INDEX_NOT_FOUND)
369 allFoundObjects.Insert(bResult.parent);
370 }
371 }
372 }
373
374 //5. Filter filtered objects with RayCast from the player ( head bone )
375 array<Object> obstructingObjects = new array<Object>();
376 MiscGameplayFunctions.FilterObstructingObjects(allFoundObjects, obstructingObjects);
377
379 if (obstructingObjects.Count() > 0 && !cameraActive)
380 {
381 //obstructingObjects.Debug();
382 if (filteredObjects.Count() > 10)
383 {
384 array<Object> filteredObjectsGrouped = new array<Object>();
385 MiscGameplayFunctions.FilterObstructedObjectsByGrouping(playerHeadPositionFixed, VICINITY_CONE_DISTANCE, 0.3, filteredObjects, obstructingObjects, filteredObjectsGrouped, true, true, VICINITY_CONE_REACH_DISTANCE);
386
387 foreach (Object object: filteredObjectsGrouped)
388 AddVicinityItems(object);
389 }
390 else
391 {
392 foreach (Object filteredObjectClose: filteredObjects)
393 {
394 EntityAI entity;
395 Class.CastTo(entity, filteredObjectClose);
396
397 //distance check
398 if (vector.DistanceSq(playerPosition, entity.GetPosition()) > VICINITY_CONE_REACH_DISTANCE * VICINITY_CONE_REACH_DISTANCE)
399 {
400 if (!CanIgnoreDistanceCheck(entity))
401 {
402 continue;
403 }
404 }
405
406 if (!IsObstructed(filteredObjectClose))
407 {
408 AddVicinityItems(filteredObjectClose);
409 }
410 }
411 }
412 }
413 else
414 {
415 foreach (Object filteredObject: filteredObjects)
416 AddVicinityItems(filteredObject);
417 }
418 }
class LogManager EntityAI
DayZGame g_Game
Определения DayZGame.c:4074
void DayZPlayerUtils()
cannot be instantiated
Определения DayZPlayerUtils.c:465
proto native void SetParams(vector center, vector orientation, vector edgeLength, ObjIntersect primaryType, ObjIntersect secondaryType, bool fullComponentInfo)
Set the parameters.
float radius
radius along the ray tested
Определения DayZPhysics.c:57
int type
Определения DayZPhysics.c:73
CollisionFlags flags
Определения DayZPhysics.c:63
bool IsObstructed(Object filtered_object)
Определения VicinityItemManager.c:420
const float VICINITY_CONE_DISTANCE
Определения VicinityItemManager.c:7
const float VICINITY_CONE_REACH_DISTANCE
Определения VicinityItemManager.c:8
void AddVicinityCargos(CargoBase object)
Определения VicinityItemManager.c:68
const float VICINITY_ACTOR_DISTANCE
Определения VicinityItemManager.c:5
const float CONE_HEIGHT_MIN
Определения VicinityItemManager.c:14
bool ExcludeFromContainer_Phase3(Object object_in_cone)
Определения VicinityItemManager.c:177
bool ExcludeFromContainer_Phase1(Object actor_in_radius)
Определения VicinityItemManager.c:92
const float CONE_HEIGHT_MAX
Определения VicinityItemManager.c:15
const float VICINITY_LARGE_ACTOR_DISTANCE
Определения VicinityItemManager.c:6
void AddVicinityItems(Object object)
Определения VicinityItemManager.c:39
const float VICINITY_CONE_ANGLE
Определения VicinityItemManager.c:9
ref array< EntityAI > m_VicinityItems
Определения VicinityItemManager.c:17
const float VICINITY_DISTANCE
Определения VicinityItemManager.c:4
bool ExcludeFromContainer_Phase2(Object object_in_radius)
Определения VicinityItemManager.c:153
bool CanIgnoreDistanceCheck(EntityAI entity_ai)
Определения VicinityItemManager.c:202
ref array< CargoBase > m_VicinityCargos
Определения VicinityItemManager.c:18
proto float Normalize()
Normalizes vector. Returns length.
proto vector VectorToAngles()
Converts vector to spherical coordinates with radius = 1.
const int INDEX_NOT_FOUND
Определения gameplay.c:13
class LOD Object
CollisionFlags
Определения EnDebug.c:141

Перекрестные ссылки AddVicinityCargos(), AddVicinityItems(), CanIgnoreDistanceCheck(), Class::CastTo(), CONE_HEIGHT_MAX, CONE_HEIGHT_MIN, Math::Cos(), DayZPlayerUtils(), Math::DEG2RAD, vector::DistanceSq(), ExcludeFromContainer_Phase1(), ExcludeFromContainer_Phase2(), ExcludeFromContainer_Phase3(), RaycastRVParams::flags, g_Game, INDEX_NOT_FOUND, IsObstructed(), m_VicinityCargos, m_VicinityItems, vector::Normalize(), RaycastRVParams::radius, DayZPhysics::RaycastRVProxy(), BoxCollidingParams::SetParams(), Math::Sin(), RaycastRVParams::type, vector::VectorToAngles(), VICINITY_ACTOR_DISTANCE, VICINITY_CONE_ANGLE, VICINITY_CONE_DISTANCE, VICINITY_CONE_REACH_DISTANCE, VICINITY_DISTANCE и VICINITY_LARGE_ACTOR_DISTANCE.

Используется в OnShow() и Update().