DayZ 1.30
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
VicinityItemManager.c
См. документацию.
2{
3 private const float UPDATE_FREQUENCY = 0.25;
4 private const float VICINITY_DISTANCE = 0.5;
5 private const float VICINITY_ACTOR_DISTANCE = 2.0;
6 private const float VICINITY_LARGE_ACTOR_DISTANCE = 3.0;
7 private const float VICINITY_CONE_DISTANCE = 2.0;
8 private const float VICINITY_CONE_REACH_DISTANCE = 2.0;
9 private const float VICINITY_CONE_ANGLE = 30;
10 private const float VICINITY_CONE_RADIANS = 0.5;
11 private const string CE_CENTER = "ce_center";
12 private const float HEIGHT_OFFSET = 0.2;
13 private const int OBJECT_OBSTRUCTION_WEIGHT = 10000; //in grams
14 private const float CONE_HEIGHT_MIN = -0.5;
15 private const float CONE_HEIGHT_MAX = 3.0;
16
19 private float m_RefreshCounter;
20 private static ref VicinityItemManager s_Instance;
21
23 {
24 if (!s_Instance)
26
27 return s_Instance;
28 }
29
30 void Init()
31 {
32 }
33
38
40 {
41 EntityAI entity = EntityAI.Cast(object);
42 if (!entity)
43 {
44 return;
45 }
46
47 if (m_VicinityItems.Find(entity) != INDEX_NOT_FOUND)
48 {
49 return;
50 }
51
53 {
54 if (!FreeDebugCamera.GetInstance() || FreeDebugCamera.GetInstance().IsActive() == false)
55 {
56 return;
57 }
58 }
59
60 m_VicinityItems.Insert(entity);
61 }
62
67
69 {
70 if (m_VicinityCargos.Find(object) == INDEX_NOT_FOUND)
71 {
72 m_VicinityCargos.Insert(object);
73 }
74 }
75
77 {
79 }
80
81 void Update(float delta_time)
82 {
83 m_RefreshCounter += delta_time;
84
86 {
89 }
90 }
91
92 bool ExcludeFromContainer_Phase1(Object actor_in_radius)
93 {
94 EntityAI entity;
95 if (!Class.CastTo(entity, actor_in_radius))
96 return true;
97
98 PlayerBase player = PlayerBase.Cast(g_Game.GetPlayer());
99 if (entity == player)
100 return true;
101 if (entity.IsParticle())
102 return true;
103 if (entity.IsScriptedLight())
104 return true;
105 if (entity.IsBeingPlaced())
106 return true;
107 if (entity.IsHologram())
108 return true;
109 if (entity.IsMan() || entity.IsZombie() || entity.IsZombieMilitary())
110 {
111 //visibility cone check
112 vector entityPosition = entity.GetPosition();
113
114 if (entity && entity.IsMan())
115 {
116 PlayerBase vicinityPlayer = PlayerBase.Cast(entity);
117 if (vicinityPlayer)
118 {
119 entityPosition = vicinityPlayer.GetBonePositionWS(vicinityPlayer.GetBoneIndexByName("spine3"));
120 }
121 }
122 else if (entity && (entity.IsZombie() || entity.IsZombieMilitary()))
123 {
124 ZombieBase zombie = ZombieBase.Cast(entity);
125 if (zombie)
126 {
127 entityPosition = zombie.GetBonePositionWS(zombie.GetBoneIndexByName("spine3"));
128 }
129 }
130
132 if (FreeDebugCamera.GetInstance() && FreeDebugCamera.GetInstance().IsActive())
133 {
134 return false;
135 }
136
137 vector entityDirection = player.GetPosition() - entityPosition;
138 entityDirection.Normalize();
139 entityDirection[1] = 0; //ignore height
140
141 vector playerDirection = MiscGameplayFunctions.GetHeadingVector(player);
142 playerDirection.Normalize();
143 playerDirection[1] = 0; //ignore height
144
145 float dotRadians = vector.Dot(playerDirection, entityDirection);
146 if (dotRadians > -0.5)
147 return true;
148 }
149
150 return false;
151 }
152
153 bool ExcludeFromContainer_Phase2(Object object_in_radius)
154 {
155 EntityAI entity;
156
157 if (!Class.CastTo(entity, object_in_radius))
158 return true;
159 if (entity == PlayerBase.Cast(g_Game.GetPlayer()))
160 return true;
161 if (entity.IsParticle())
162 return true;
163 if (entity.IsScriptedLight())
164 return true;
165 if (entity.IsBeingPlaced())
166 return true;
167 if (entity.IsHologram())
168 return true;
169
170 ItemBase item;
171 if (!Class.CastTo(item, object_in_radius))
172 return true;
173
174 return false;
175 }
176
178 {
179 EntityAI entity;
180 PlayerBase player = PlayerBase.Cast(g_Game.GetPlayer());
181
182 //Print("---object in cone: " + object_in_cone);
183 if (!Class.CastTo(entity, object_in_cone))
184 return true;
185 if (entity == player)
186 return true;
187 if (entity.IsParticle())
188 return true;
189 if (entity.IsScriptedLight())
190 return true;
191 if (entity.IsBeingPlaced())
192 return true;
193 if (entity.IsHologram())
194 return true;
195
196 if (!entity.IsDetectableByVicinityCone())
197 return true;
198
199 return false;
200 }
201
203 {
204 return MiscGameplayFunctions.CanIgnoreDistanceCheck(entity_ai) || entity_ai.IsBuilding(); //TODO: IsBuilding will be replaced by 'CanUseConstruction', already in MiscGameplayFunctions fn
205 }
206
207 //per frame call
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;
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 {
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
348 vector boxEdgeLength = {
352 };
353
354 params.SetParams(playerPosition, headingDirection.VectorToAngles(), boxEdgeLength * 2, ObjIntersect.View, ObjIntersect.Fire, true);
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 }
419
420 bool IsObstructed(Object filtered_object)
421 {
422 return MiscGameplayFunctions.IsObjectObstructed(filtered_object);
423 }
424
425#ifdef DIAG_DEVELOPER
426 //Debug functions
427
428 ref array<Shape> rayShapes = new array<Shape>();
429
430 private void DebugActorsSphereDraw(float radius)
431 {
432 CleanupDebugShapes(rayShapes);
433
434 rayShapes.Insert(Debug.DrawSphere( g_Game.GetPlayer().GetPosition(), radius, COLOR_GREEN, ShapeFlags.TRANSP|ShapeFlags.WIREFRAME));
435 }
436
437 private void DebugObjectsSphereDraw(float radius)
438 {
439 rayShapes.Insert(Debug.DrawSphere(g_Game.GetPlayer().GetPosition(), radius, COLOR_GREEN, ShapeFlags.TRANSP|ShapeFlags.WIREFRAME));
440 }
441
442 private void DebugRaycastDraw(vector start, vector end)
443 {
444 rayShapes.Insert(Debug.DrawArrow(start, end, 0.5, COLOR_YELLOW));
445 }
446
447 private void DebugConeDraw(vector start, float cone_angle)
448 {
449 vector endL, endR;
450 float playerAngle;
451 float xL,xR,zL,zR;
452
453 playerAngle = MiscGameplayFunctions.GetHeadingAngle(PlayerBase.Cast(g_Game.GetPlayer()));
454
455 endL = start;
456 endR = start;
457 xL = VICINITY_CONE_REACH_DISTANCE * Math.Cos( playerAngle + Math.PI_HALF + cone_angle * Math.DEG2RAD ); // x
458 zL = VICINITY_CONE_REACH_DISTANCE * Math.Sin( playerAngle + Math.PI_HALF + cone_angle * Math.DEG2RAD ); // z
459 xR = VICINITY_CONE_REACH_DISTANCE * Math.Cos( playerAngle + Math.PI_HALF - cone_angle * Math.DEG2RAD ); // x
460 zR = VICINITY_CONE_REACH_DISTANCE * Math.Sin( playerAngle + Math.PI_HALF - cone_angle * Math.DEG2RAD ); // z
461 endL[0] = endL[0] + xL;
462 endL[2] = endL[2] + zL;
463 endR[0] = endR[0] + xR;
464 endR[2] = endR[2] + zR;
465
466 rayShapes.Insert(Debug.DrawLine(start, endL, COLOR_GREEN));
467 rayShapes.Insert(Debug.DrawLine(start, endR, COLOR_GREEN)) ;
468 rayShapes.Insert(Debug.DrawLine(endL, endR, COLOR_GREEN));
469 }
470
471 private void CleanupDebugShapes(array<Shape> shapesArr)
472 {
473 foreach (Shape shape : shapesArr)
474 Debug.RemoveShape(shape);
475
476 shapesArr.Clear();
477 }
478#endif
479
480 [Obsolete("use MiscGameplayFunctions.GetPlayerHeadHeight instead")]
482 {
483 return MiscGameplayFunctions.GetPlayerHeadHeight(player);
484 }
485}
string Debug()
Определения CachedEquipmentStorageBase.c:26
DayZGame g_Game
Определения DayZGame.c:4074
void DayZPlayerUtils()
cannot be instantiated
Определения DayZPlayerUtils.c:465
void CleanupDebugShapes(array< Shape > shapesArr)
DEPRECATED.
Определения DynamicMusicPlayer.c:1038
proto native void SetParams(vector center, vector orientation, vector edgeLength, ObjIntersect primaryType, ObjIntersect secondaryType, bool fullComponentInfo)
Set the parameters.
Class that holds parameters to feed into CGame.IsBoxCollidingGeometryProxy.
represents base for cargo storage for entities
Определения Cargo.c:7
Super root of all classes in Enforce script.
Определения EnScript.c:11
static proto bool RaycastRVProxy(notnull RaycastRVParams in, out notnull array< ref RaycastRVResult > results, array< Object > excluded=null)
Определения DayZPhysics.c:124
static Shape DrawSphere(vector pos, float size=1, int color=0x1fff7f7f, ShapeFlags flags=ShapeFlags.TRANSP|ShapeFlags.NOOUTLINE)
Определения 3_Game/DayZ/tools/Debug.c:395
Определения 3_Game/DayZ/tools/Debug.c:2
override bool IsMan()
Определения 3_Game/DayZ/Entities/Man.c:48
static proto native bool CheckManipulatedObjectsDistances(notnull EntityAI e0, notnull EntityAI e1, float radius)
script counterpart to engine's class Inventory
Определения EnMath.c:7
Определения ObjectTyped.c:2
Определения PlayerBaseClient.c:2
float radius
radius along the ray tested
Определения DayZPhysics.c:57
int type
Определения DayZPhysics.c:73
CollisionFlags flags
Определения DayZPhysics.c:63
Определения DayZPhysics.c:50
Определения DayZPhysics.c:99
bool IsObstructed(Object filtered_object)
Определения VicinityItemManager.c:420
const string CE_CENTER
Определения VicinityItemManager.c:11
const float VICINITY_CONE_DISTANCE
Определения VicinityItemManager.c:7
void ResetRefreshCounter()
Определения VicinityItemManager.c:76
const float VICINITY_CONE_REACH_DISTANCE
Определения VicinityItemManager.c:8
void AddVicinityCargos(CargoBase object)
Определения VicinityItemManager.c:68
array< EntityAI > GetVicinityItems()
Определения VicinityItemManager.c:34
const float VICINITY_ACTOR_DISTANCE
Определения VicinityItemManager.c:5
void Update(float delta_time)
Определения VicinityItemManager.c:81
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
void Init()
Определения VicinityItemManager.c:30
static ref VicinityItemManager s_Instance
Определения VicinityItemManager.c:20
array< CargoBase > GetVicinityCargos()
Определения VicinityItemManager.c:63
float GetFixedHeadHeightAdjustment(PlayerBase player)
Определения VicinityItemManager.c:481
const float CONE_HEIGHT_MAX
Определения VicinityItemManager.c:15
void RefreshVicinityItems()
Определения VicinityItemManager.c:208
const float VICINITY_LARGE_ACTOR_DISTANCE
Определения VicinityItemManager.c:6
static VicinityItemManager GetInstance()
Определения VicinityItemManager.c:22
const int OBJECT_OBSTRUCTION_WEIGHT
Определения VicinityItemManager.c:13
void AddVicinityItems(Object object)
Определения VicinityItemManager.c:39
const float VICINITY_CONE_RADIANS
Определения VicinityItemManager.c:10
float m_RefreshCounter
Определения VicinityItemManager.c:19
const float VICINITY_CONE_ANGLE
Определения VicinityItemManager.c:9
const float HEIGHT_OFFSET
Определения VicinityItemManager.c:12
ref array< EntityAI > m_VicinityItems
Определения VicinityItemManager.c:17
const float UPDATE_FREQUENCY
Определения VicinityItemManager.c:3
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
Определения ZombieFemaleBase.c:2
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
static proto native float DistanceSq(vector v1, vector v2)
Returns the square distance between tips of two 3D vectors.
static float Dot(vector v1, vector v2)
Returns Dot product of vector v1 and vector v2.
Определения EnConvert.c:305
proto float Normalize()
Normalizes vector. Returns length.
proto vector VectorToAngles()
Converts vector to spherical coordinates with radius = 1.
Определения EnConvert.c:119
const int INDEX_NOT_FOUND
Определения gameplay.c:13
const int COLOR_GREEN
Определения 1_Core/DayZ/constants.c:65
const int COLOR_YELLOW
Определения 1_Core/DayZ/constants.c:67
CollisionFlags
Определения EnDebug.c:141
ShapeFlags
Определения EnDebug.c:126
class DiagMenu Shape
don't call destructor directly. Use Destroy() instead
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
void Obsolete(string msg="")
Определения EnScript.c:371
static proto float Cos(float angle)
Returns cosinus of angle in radians.
static proto float Sin(float angle)
Returns sinus of angle in radians.
static const float DEG2RAD
Определения EnMath.c:17