DayZ 1.27
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(GetGame().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(GetGame().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(GetGame().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 ItemBase item;
197 if (!Class.CastTo(item, object_in_cone) && !object_in_cone.IsTransport() && !PASBroadcaster.Cast(object_in_cone))
198 return true;
199
200 return false;
201 }
202
204 {
205 return MiscGameplayFunctions.CanIgnoreDistanceCheck(entity_ai);
206 }
207
208 //per frame call
210 {
211 PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
212
213 array<Object> objectsInVicinity = new array<Object>();
214 array<CargoBase> proxyCargos = new array<CargoBase>();
215 array<Object> filteredObjects = new array<Object>();
216 array<Object> allFoundObjects = new array<Object>();
217 vector playerPosition = player.GetPosition();
218 vector playerHeadPositionFixed = playerPosition;
219 playerHeadPositionFixed[1] = playerHeadPositionFixed[1] + GetFixedHeadHeightAdjustment(player);
220 vector headingDirection = MiscGameplayFunctions.GetHeadingVector(player);
221
223 bool cameraActive = FreeDebugCamera.GetInstance() && FreeDebugCamera.GetInstance().IsActive();
224 if (cameraActive)
225 {
226 playerPosition = FreeDebugCamera.GetInstance().GetPosition();
227 playerHeadPositionFixed = playerPosition;
228
229 float headingAngle = FreeDebugCamera.GetInstance().GetOrientation()[0] * Math.DEG2RAD;
230
231 headingDirection[0] = Math.Cos(headingAngle);
232 headingDirection[1] = 0;
233 headingDirection[2] = Math.Sin(headingAngle);
234 headingDirection.Normalize();
235 }
236
237 if (m_VicinityItems)
238 m_VicinityItems.Clear();
239
241 m_VicinityCargos.Clear();
242
243 //1. GetAll actors in VICINITY_ACTOR_DISTANCE
244 //DebugActorsSphereDraw(VICINITY_ACTOR_DISTANCE);
245 GetGame().GetObjectsAtPosition3D(playerPosition, VICINITY_ACTOR_DISTANCE, objectsInVicinity, proxyCargos);
246
247 // no filtering for cargo (initial implementation)
248 foreach (CargoBase cargoObject : proxyCargos)
249 AddVicinityCargos(cargoObject);
250
251 //filter unnecessary and duplicate objects beforehand
252 foreach (Object actorInRadius : objectsInVicinity)
253 {
254 if (allFoundObjects.Find(actorInRadius) == INDEX_NOT_FOUND)
255 allFoundObjects.Insert(actorInRadius);
256
257 if (ExcludeFromContainer_Phase1(actorInRadius))
258 continue;
259
260 if (filteredObjects.Find(actorInRadius) == INDEX_NOT_FOUND)
261 filteredObjects.Insert(actorInRadius);
262 }
263
264 if (objectsInVicinity)
265 objectsInVicinity.Clear();
266
267 //2. GetAll Objects in VICINITY_DISTANCE
268 GetGame().GetObjectsAtPosition3D(playerPosition, VICINITY_DISTANCE, objectsInVicinity, proxyCargos);
269 //DebugObjectsSphereDraw(VICINITY_DISTANCE);
270
271 //filter unnecessary and duplicate objects beforehand
272 foreach (Object objectInRadius : objectsInVicinity)
273 {
274 if (allFoundObjects.Find(objectInRadius) == INDEX_NOT_FOUND)
275 allFoundObjects.Insert(objectInRadius);
276
277 if (ExcludeFromContainer_Phase2(objectInRadius))
278 continue;
279
280 if (filteredObjects.Find(objectInRadius) == INDEX_NOT_FOUND)
281 filteredObjects.Insert(objectInRadius);
282 }
283
284 if (objectsInVicinity)
285 objectsInVicinity.Clear();
286
287 //3. Add objects from GetEntitiesInCone
288 DayZPlayerUtils.GetEntitiesInCone(playerPosition, headingDirection, VICINITY_CONE_ANGLE, VICINITY_CONE_REACH_DISTANCE, CONE_HEIGHT_MIN, CONE_HEIGHT_MAX, objectsInVicinity);
289 //DebugConeDraw(playerPosition, VICINITY_CONE_ANGLE);
290
291 RaycastRVParams rayInput;
293 //filter unnecessary and duplicate objects beforehand
294 foreach (Object objectInCone : objectsInVicinity)
295 {
296 if (allFoundObjects.Find(objectInCone) == INDEX_NOT_FOUND)
297 allFoundObjects.Insert(objectInCone);
298
299 if (ExcludeFromContainer_Phase3(objectInCone))
300 continue;
301
302 if (filteredObjects.Find(objectInCone) == INDEX_NOT_FOUND)
303 {
304 rayInput = new RaycastRVParams(playerHeadPositionFixed, objectInCone.GetPosition());
305 rayInput.flags = CollisionFlags.ALLOBJECTS;
306 rayInput.type = ObjIntersectView;
307 rayInput.radius = 0.1;
308 DayZPhysics.RaycastRVProxy(rayInput, raycastResults, {player});
309 //Debug.DrawLine(playerHeadPositionFixed,objectInCone.GetPosition(),COLOR_WHITE,ShapeFlags.ONCE);
310
311 foreach (RaycastRVResult result : raycastResults)
312 {
314 continue;
315
316 if (result.hierLevel > 0)
317 {
318 if (result.parent.CanProxyObstruct())
319 break;
320
321 if (result.parent == objectInCone)
322 {
323 filteredObjects.Insert(objectInCone);
324 break;
325 }
326 }
327 else
328 {
329 if (result.obj == objectInCone)
330 {
331 filteredObjects.Insert(objectInCone);
332 break;
333 }
334 }
335 }
336 }
337 }
338
339 //4. Add large objects - particularly buildings and BaseBuildingBase
341 vector boxEdgeLength = {
345 };
346
347 params.SetParams(playerPosition, headingDirection.VectorToAngles(), boxEdgeLength * 2, ObjIntersect.View, ObjIntersect.Fire, true);
349 if (GetGame().IsBoxCollidingGeometryProxy(params, {player}, results))
350 {
351 foreach (BoxCollidingResult bResult : results)
352 {
353 if (bResult.obj && (bResult.obj.CanObstruct() || bResult.obj.CanProxyObstruct()))
354 {
355 if (allFoundObjects.Find(bResult.obj) == INDEX_NOT_FOUND)
356 allFoundObjects.Insert(bResult.obj);
357 }
358
359 if (bResult.parent && (bResult.parent.CanObstruct() || bResult.parent.CanProxyObstruct()))
360 {
361 if (allFoundObjects.Find(bResult.parent) == INDEX_NOT_FOUND)
362 allFoundObjects.Insert(bResult.parent);
363 }
364 }
365 }
366
367 //5. Filter filtered objects with RayCast from the player ( head bone )
368 array<Object> obstructingObjects = new array<Object>();
369 MiscGameplayFunctions.FilterObstructingObjects(allFoundObjects, obstructingObjects);
370
372 if (obstructingObjects.Count() > 0 && !cameraActive)
373 {
374 //obstructingObjects.Debug();
375 if (filteredObjects.Count() > 10)
376 {
377 array<Object> filteredObjectsGrouped = new array<Object>();
378 MiscGameplayFunctions.FilterObstructedObjectsByGrouping(playerHeadPositionFixed, VICINITY_CONE_DISTANCE, 0.3, filteredObjects, obstructingObjects, filteredObjectsGrouped, true, true, VICINITY_CONE_REACH_DISTANCE);
379
380 foreach (Object object: filteredObjectsGrouped)
381 AddVicinityItems(object);
382 }
383 else
384 {
385 foreach (Object filteredObjectClose: filteredObjects)
386 {
387 EntityAI entity;
388 Class.CastTo(entity, filteredObjectClose);
389
390 //distance check
391 if (vector.DistanceSq(playerPosition, entity.GetPosition()) > VICINITY_CONE_REACH_DISTANCE * VICINITY_CONE_REACH_DISTANCE)
392 {
393 if (!CanIgnoreDistanceCheck(entity))
394 {
395 continue;
396 }
397 }
398
399 if (!IsObstructed(filteredObjectClose))
400 {
401 AddVicinityItems(filteredObjectClose);
402 }
403 }
404 }
405 }
406 else
407 {
408 foreach (Object filteredObject: filteredObjects)
409 AddVicinityItems(filteredObject);
410 }
411 }
412
414 {
415 if (player.IsPlayerInStance(DayZPlayerConstants.STANCEMASK_ERECT|DayZPlayerConstants.STANCEMASK_RAISEDERECT))
417 if (player.IsPlayerInStance(DayZPlayerConstants.STANCEMASK_CROUCH|DayZPlayerConstants.STANCEMASK_RAISEDCROUCH))
419 if (player.IsPlayerInStance(DayZPlayerConstants.STANCEMASK_PRONE|DayZPlayerConstants.STANCEMASK_RAISEDPRONE))
421
423 }
424
425 bool IsObstructed(Object filtered_object)
426 {
427 return MiscGameplayFunctions.IsObjectObstructed(filtered_object);
428 }
429
430#ifdef DIAG_DEVELOPER
431 //Debug functions
432
433 ref array<Shape> rayShapes = new array<Shape>();
434
435 private void DebugActorsSphereDraw(float radius)
436 {
437 CleanupDebugShapes(rayShapes);
438
439 rayShapes.Insert(Debug.DrawSphere( GetGame().GetPlayer().GetPosition(), radius, COLOR_GREEN, ShapeFlags.TRANSP|ShapeFlags.WIREFRAME));
440 }
441
442 private void DebugObjectsSphereDraw(float radius)
443 {
444 rayShapes.Insert(Debug.DrawSphere(GetGame().GetPlayer().GetPosition(), radius, COLOR_GREEN, ShapeFlags.TRANSP|ShapeFlags.WIREFRAME));
445 }
446
447 private void DebugRaycastDraw(vector start, vector end)
448 {
449 rayShapes.Insert(Debug.DrawArrow(start, end, 0.5, COLOR_YELLOW));
450 }
451
452 private void DebugConeDraw(vector start, float cone_angle)
453 {
454 vector endL, endR;
455 float playerAngle;
456 float xL,xR,zL,zR;
457
458 playerAngle = MiscGameplayFunctions.GetHeadingAngle(PlayerBase.Cast(GetGame().GetPlayer()));
459
460 endL = start;
461 endR = start;
462 xL = VICINITY_CONE_REACH_DISTANCE * Math.Cos( playerAngle + Math.PI_HALF + cone_angle * Math.DEG2RAD ); // x
463 zL = VICINITY_CONE_REACH_DISTANCE * Math.Sin( playerAngle + Math.PI_HALF + cone_angle * Math.DEG2RAD ); // z
464 xR = VICINITY_CONE_REACH_DISTANCE * Math.Cos( playerAngle + Math.PI_HALF - cone_angle * Math.DEG2RAD ); // x
465 zR = VICINITY_CONE_REACH_DISTANCE * Math.Sin( playerAngle + Math.PI_HALF - cone_angle * Math.DEG2RAD ); // z
466 endL[0] = endL[0] + xL;
467 endL[2] = endL[2] + zL;
468 endR[0] = endR[0] + xR;
469 endR[2] = endR[2] + zR;
470
471 rayShapes.Insert(Debug.DrawLine(start, endL, COLOR_GREEN));
472 rayShapes.Insert(Debug.DrawLine(start, endR, COLOR_GREEN)) ;
473 rayShapes.Insert(Debug.DrawLine(endL, endR, COLOR_GREEN));
474 }
475
476 private void CleanupDebugShapes(array<Shape> shapesArr)
477 {
478 foreach (Shape shape : shapesArr)
479 Debug.RemoveShape(shape);
480
481 shapesArr.Clear();
482 }
483#endif
484}
void DayZPlayerUtils()
cannot be instantiated
Определения DayZPlayerUtils.c:465
PlayerBase GetPlayer()
Определения ModifierBase.c:51
void Debug()
Определения UniversalTemperatureSource.c:349
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.
proto native void GetObjectsAtPosition3D(vector pos, float radius, out array< Object > objects, out array< CargoBase > proxyCargos)
Returns list of all objects in sphere "radius" around position "pos".
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)
Определения Debug.c:319
Определения Debug.c:2
override bool IsMan()
Определения Man.c:44
Определения Building.c:6
static proto native bool CheckManipulatedObjectsDistances(notnull EntityAI e0, notnull EntityAI e1, float radius)
script counterpart to engine's class Inventory
Определения Inventory.c:79
Определения InventoryItem.c:731
Определения EnMath.c:7
Определения ObjectTyped.c:2
Определения PlayerBaseClient.c:2
static const float HEAD_HEIGHT_CROUCH
Определения PlayerConstants.c:13
static const float HEAD_HEIGHT_ERECT
[seconds]
Определения PlayerConstants.c:12
static const float HEAD_HEIGHT_PRONE
Определения PlayerConstants.c:14
Определения PlayerConstants.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:425
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:413
const float CONE_HEIGHT_MAX
Определения VicinityItemManager.c:15
void RefreshVicinityItems()
Определения VicinityItemManager.c:209
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:203
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:271
proto float Normalize()
Normalizes vector. Returns length.
proto vector VectorToAngles()
Converts vector to spherical coordinates with radius = 1.
Определения EnConvert.c:106
DayZPlayerConstants
defined in C++
Определения dayzplayer.c:602
const int INDEX_NOT_FOUND
Определения gameplay.c:13
proto native CGame GetGame()
const int COLOR_GREEN
Определения constants.c:65
const int COLOR_YELLOW
Определения 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.
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
class JsonUndergroundAreaTriggerData GetPosition
Определения UndergroundAreaLoader.c:9