Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AIMovementDetector.c
Go to the documentation of this file.
1#ifdef WORKBENCH
2//#define MOVEMENT_DETECTOR_DIAG
3#endif
4
9{
10 protected vector m_vPrevPos;
16 protected bool m_bMoving;
17
18 #ifdef MOVEMENT_DETECTOR_DIAG
19 protected ref Shape m_ShapeLeaderPos;
20 protected ref Shape m_ShapePosStopped;
21 #endif
22
23 // Constants
24 protected static const float STOPPED_RADIUS = 6;
25 protected static const float STOPPED_RADIUS_SQ = STOPPED_RADIUS * STOPPED_RADIUS;
26
27 protected static const float TIME_STOPPED_S = 0.7; // Switch to stopped state after not moving for this time
28 protected static const float TIME_MOVING_S = 0.17; // Switch to moving state after moving for this time
29
30 protected static const float UPDATE_INTERVAL_S = 0.2; // How often to update state
31
32 //-------------------------------------------------------------------------------------------------
34 {
35 m_OwnerEntity = myEntity;
36 }
37
38 //-------------------------------------------------------------------------------------------------
39 protected void Update(WorldTimestamp worldTime)
40 {
41 vector pos = m_OwnerEntity.GetOrigin();
42 bool movedSinceLastUpdate = vector.DistanceSq(pos, m_vPrevPos) > 0.01; // Even when standing, character jitters a bit
43 m_vPrevPos = pos;
44
45 if (m_bMoving)
46 {
47 if (movedSinceLastUpdate)
48 m_TimeLastMoved = worldTime;
49 else
50 {
51 if (worldTime.DiffSeconds(m_TimeLastMoved) > TIME_STOPPED_S)
52 {
53 m_TimeLastStopped = worldTime;
54 m_bMoving = false;
55 m_vPosStopped = pos;
56 }
57 }
58 }
59 else
60 {
61 if (movedSinceLastUpdate)
62 {
63 if (worldTime.DiffSeconds(m_TimeLastStopped) > TIME_MOVING_S)
64 {
65 if (vector.DistanceSq(pos, m_vPosStopped) > STOPPED_RADIUS_SQ)
66 {
67 m_TimeLastMoved = worldTime;
68 m_bMoving = true;
69 }
70 }
71 }
72 else
73 {
74 m_TimeLastStopped = worldTime;
75 m_vPosStopped = pos;
76 }
77 }
78
79 #ifdef MOVEMENT_DETECTOR_DIAG
80 int color = Color.RED;
81 if (m_bMoving)
82 color = Color.GREEN;
83 m_ShapeLeaderPos = Shape.CreateCylinder(color, ShapeFlags.DEFAULT, pos, 0.5, 1.0);
84 m_ShapePosStopped = Shape.CreateCylinder(Color.VIOLET, ShapeFlags.DEFAULT, m_vPosStopped, STOPPED_RADIUS, 0.3);
85 #endif
86 }
87
88 //-------------------------------------------------------------------------------------------------
90 bool GetMoving()
91 {
92 WorldTimestamp worldTime = GetGame().GetWorld().GetTimestamp();
93 if (worldTime.DiffSeconds(m_TimeLastUpdate) > UPDATE_INTERVAL_S)
94 {
95 Update(worldTime);
96 m_TimeLastUpdate = worldTime;
97 }
98 return m_bMoving;
99 }
100}
ArmaReforgerScripted GetGame()
Definition game.c:1398
Definition Color.c:13
static const float TIME_MOVING_S
static const float STOPPED_RADIUS_SQ
bool GetMoving()
Returns current state, and updates it in lazy manner, not more often than once per UPDATE_INTERVAL_S.
void SCR_AIMovementDetector(IEntity myEntity)
static const float TIME_STOPPED_S
static const float STOPPED_RADIUS
void Update(WorldTimestamp worldTime)
static const float UPDATE_INTERVAL_S
Instance of created debug visualizer.
Definition Shape.c:14
ShapeFlags
Definition ShapeFlags.c:13