DayZ 1.24
Loading...
Searching...
No Matches
VicinityItemManager.c
Go to the documentation of this file.
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;
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 return;
44
46 return;
47
49 {
50 if (!FreeDebugCamera.GetInstance() || FreeDebugCamera.GetInstance().IsActive() == false)
51 return;
52 }
53
54 m_VicinityItems.Insert(entity);
55 }
56
61
63 {
64 if (m_VicinityCargos.Find(object) == INDEX_NOT_FOUND)
65 m_VicinityCargos.Insert(object);
66 }
67
69 {
71 }
72
73 void Update(float delta_time)
74 {
76
78 {
81 }
82 }
83
85 {
88 return true;
89
91 if (entity == player)
92 return true;
93 if (entity.IsParticle())
94 return true;
95 if (entity.IsScriptedLight())
96 return true;
97 if (entity.IsBeingPlaced())
98 return true;
99 if (entity.IsHologram())
100 return true;
101 if (entity.IsMan() || entity.IsZombie() || entity.IsZombieMilitary())
102 {
103 //visibility cone check
104 vector entityPosition = entity.GetPosition();
105
106 if (entity && entity.IsMan())
107 {
109 if (vicinityPlayer)
110 entityPosition = vicinityPlayer.GetBonePositionWS(vicinityPlayer.GetBoneIndexByName("spine3"));
111 }
112 else if (entity && (entity.IsZombie() || entity.IsZombieMilitary()))
113 {
115 if (zombie)
116 entityPosition = zombie.GetBonePositionWS(zombie.GetBoneIndexByName("spine3"));
117 }
118
120 if (FreeDebugCamera.GetInstance() && FreeDebugCamera.GetInstance().IsActive())
121 return false;
122
124 entityDirection.Normalize();
125 entityDirection[1] = 0; //ignore height
126
128 playerDirection.Normalize();
129 playerDirection[1] = 0; //ignore height
130
132 if (dotRadians > -0.5)
133 return true;
134 }
135
136 return false;
137 }
138
140 {
142
144 return true;
145 if (entity == PlayerBase.Cast(GetGame().GetPlayer()))
146 return true;
147 if (entity.IsParticle())
148 return true;
149 if (entity.IsScriptedLight())
150 return true;
151 if (entity.IsBeingPlaced())
152 return true;
153 if (entity.IsHologram())
154 return true;
155
158 return true;
159 if (!item.IsTakeable())
160 return true;
161
162 return false;
163 }
164
166 {
169
170 //Print("---object in cone: " + object_in_cone);
172 return true;
173 if (entity == player)
174 return true;
175 if (entity.IsParticle())
176 return true;
177 if (entity.IsScriptedLight())
178 return true;
179 if (entity.IsBeingPlaced())
180 return true;
181 if (entity.IsHologram())
182 return true;
183
186 return true;
187 if (item && !item.IsTakeable())
188 return true;
189
190 return false;
191 }
192
194 {
195 return MiscGameplayFunctions.CanIgnoreDistanceCheck(entity_ai);
196 }
197
198 //per frame call
200 {
202
207 vector playerPosition = player.GetPosition();
211
213 bool cameraActive = FreeDebugCamera.GetInstance() && FreeDebugCamera.GetInstance().IsActive();
214 if (cameraActive)
215 {
216 playerPosition = FreeDebugCamera.GetInstance().GetPosition();
218
219 float headingAngle = FreeDebugCamera.GetInstance().GetOrientation()[0] * Math.DEG2RAD;
220
222 headingDirection[1] = 0;
224 headingDirection.Normalize();
225 }
226
227 if (m_VicinityItems)
228 m_VicinityItems.Clear();
229
231 m_VicinityCargos.Clear();
232
233 //1. GetAll actors in VICINITY_ACTOR_DISTANCE
234 //DebugActorsSphereDraw(VICINITY_ACTOR_DISTANCE);
236
237 // no filtering for cargo (initial implementation)
240
241 //filter unnecessary and duplicate objects beforehand
243 {
246
248 continue;
249
252 }
253
255 objectsInVicinity.Clear();
256
257 //2. GetAll Objects in VICINITY_DISTANCE
259 //DebugObjectsSphereDraw(VICINITY_DISTANCE);
260
261 //filter unnecessary and duplicate objects beforehand
263 {
266
268 continue;
269
272 }
273
275 objectsInVicinity.Clear();
276
277 //3. Add objects from GetEntitiesInCone
279 //DebugConeDraw(playerPosition, VICINITY_CONE_ANGLE);
280
283 //filter unnecessary and duplicate objects beforehand
285 {
288
290 continue;
291
293 {
294 //Test distance to closest component first
296 rayInput.flags = CollisionFlags.NEARESTCONTACT;
298 rayInput.radius = 0.1;
300
302 {
304 continue;
305
306 if (result.hierLevel > 0 && result.parent == objectInCone)
308 else if (result.hierLevel == 0 && result.obj == objectInCone)
310 }
311 }
312 }
313
314 //4. Add large objects - particularly buildings and BaseBuildingBase
320 };
321
322 params.SetParams(playerPosition, headingDirection.VectorToAngles(), boxEdgeLength * 2, ObjIntersect.View, ObjIntersect.Fire, true);
324 if (GetGame().IsBoxCollidingGeometryProxy(params, {player}, results))
325 {
327 {
328 if (bResult.obj && (bResult.obj.CanObstruct() || bResult.obj.CanProxyObstruct()))
329 {
330 if (allFoundObjects.Find(bResult.obj) == INDEX_NOT_FOUND)
331 allFoundObjects.Insert(bResult.obj);
332 }
333
334 if (bResult.parent && (bResult.parent.CanObstruct() || bResult.parent.CanProxyObstruct()))
335 {
336 if (allFoundObjects.Find(bResult.parent) == INDEX_NOT_FOUND)
337 allFoundObjects.Insert(bResult.parent);
338 }
339 }
340 }
341
342 //5. Filter filtered objects with RayCast from the player ( head bone )
345
347 if (obstructingObjects.Count() > 0 && !cameraActive)
348 {
349 if (filteredObjects.Count() > 10)
350 {
352 MiscGameplayFunctions.GetHeadBonePos(player, rayStart);
353
356
357 foreach (Object object: filteredObjectsGrouped)
358 AddVicinityItems(object);
359 }
360 else
361 {
363 {
366
367 //distance check
369 {
371 continue;
372 }
373
376 }
377 }
378 }
379 else
380 {
383 }
384 }
385
387 {
388 return MiscGameplayFunctions.IsObjectObstructed(filtered_object);
389 }
390
391#ifdef DIAG_DEVELOPER
392 //Debug functions
393
395
396 private void DebugActorsSphereDraw(float radius)
397 {
398 CleanupDebugShapes(rayShapes);
399
400 rayShapes.Insert(Debug.DrawSphere(GetGame().GetPlayer().GetPosition(), radius, COLOR_GREEN, ShapeFlags.TRANSP | ShapeFlags.WIREFRAME));
401 }
402
403 private void DebugObjectsSphereDraw(float radius)
404 {
405 rayShapes.Insert(Debug.DrawSphere(GetGame().GetPlayer().GetPosition(), radius, COLOR_GREEN, ShapeFlags.TRANSP | ShapeFlags.WIREFRAME));
406 }
407
408 private void DebugRaycastDraw(vector start, vector end)
409 {
411 }
412
413 private void DebugConeDraw(vector start, float cone_angle)
414 {
416 float playerAngle;
417 float xL, xR, zL, zR;
418
419 playerAngle = MiscGameplayFunctions.GetHeadingAngle(PlayerBase.Cast(GetGame().GetPlayer()));
420
421 endL = start;
422 endR = start;
427 endL[0] = endL[0] + xL;
428 endL[2] = endL[2] + zL;
429 endR[0] = endR[0] + xR;
430 endR[2] = endR[2] + zR;
431
435 }
436
437 private void CleanupDebugShapes(array<Shape> shapesArr)
438 {
439 foreach (Shape shape : shapesArr)
440 Debug.RemoveShape(shape);
441
442 shapesArr.Clear();
443 }
444#endif
445}
void DayZPlayerUtils()
cannot be instantiated
PlayerBase GetPlayer()
class JsonUndergroundAreaTriggerData GetPosition
Class that holds parameters to feed into CGame.IsBoxCollidingGeometryProxy.
represents base for cargo storage for entities
Definition Cargo.c:7
Super root of all classes in Enforce script.
Definition EnScript.c:11
static proto bool RaycastRVProxy(notnull RaycastRVParams in, out notnull array< ref RaycastRVResult > results, array< Object > excluded=null)
Definition Debug.c:14
static Shape DrawSphere(vector pos, float size=1, int color=0x1fff7f7f, ShapeFlags flags=ShapeFlags.TRANSP|ShapeFlags.NOOUTLINE)
Definition Debug.c:434
static Shape DrawArrow(vector from, vector to, float size=0.5, int color=0xFFFFFFFF, int flags=0)
Definition Debug.c:511
static Shape DrawLine(vector from, vector to, int color=0xFFFFFFFF, int flags=0)
Definition Debug.c:489
script counterpart to engine's class Inventory
Definition Inventory.c:79
static proto native bool CheckManipulatedObjectsDistances(notnull EntityAI e0, notnull EntityAI e1, float radius)
Definition EnMath.c:7
bool IsObstructed(Object filtered_object)
const float VICINITY_CONE_DISTANCE
const float VICINITY_CONE_REACH_DISTANCE
void AddVicinityCargos(CargoBase object)
array< EntityAI > GetVicinityItems()
const float VICINITY_ACTOR_DISTANCE
void Update(float delta_time)
bool ExcludeFromContainer_Phase3(Object object_in_cone)
bool ExcludeFromContainer_Phase1(Object actor_in_radius)
static ref VicinityItemManager s_Instance
array< CargoBase > GetVicinityCargos()
const float VICINITY_LARGE_ACTOR_DISTANCE
static VicinityItemManager GetInstance()
void AddVicinityItems(Object object)
const float VICINITY_CONE_RADIANS
const float VICINITY_CONE_ANGLE
ref array< EntityAI > m_VicinityItems
bool ExcludeFromContainer_Phase2(Object object_in_radius)
bool CanIgnoreDistanceCheck(EntityAI entity_ai)
ref array< CargoBase > m_VicinityCargos
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.
Definition EnConvert.c:271
const int INDEX_NOT_FOUND
Definition gameplay.c:13
proto native CGame GetGame()
const int COLOR_GREEN
Definition constants.c:65
const int COLOR_YELLOW
Definition constants.c:67
CollisionFlags
Definition EnDebug.c:141
ShapeFlags
Definition 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.
static const float PI_HALF
Definition EnMath.c:14
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
Definition EnMath.c:17