Arma Reforger Explorer
1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Toggle main menu visibility
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
8
class
SCR_AIMovementDetector
9
{
10
protected
vector
m_vPrevPos
;
11
protected
vector
m_vPosStopped
;
12
protected
IEntity
m_OwnerEntity
;
13
protected
WorldTimestamp
m_TimeLastStopped
;
14
protected
WorldTimestamp
m_TimeLastMoved
;
15
protected
WorldTimestamp
m_TimeLastUpdate
;
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
//-------------------------------------------------------------------------------------------------
33
void
SCR_AIMovementDetector
(
IEntity
myEntity)
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
}
GetGame
ArmaReforgerScripted GetGame()
Definition
game.c:1398
Color
Definition
Color.c:13
IEntity
Definition
IEntity.c:13
SCR_AIMovementDetector::TIME_MOVING_S
static const float TIME_MOVING_S
Definition
SCR_AIMovementDetector.c:28
SCR_AIMovementDetector::m_TimeLastMoved
WorldTimestamp m_TimeLastMoved
Definition
SCR_AIMovementDetector.c:14
SCR_AIMovementDetector::m_bMoving
bool m_bMoving
Definition
SCR_AIMovementDetector.c:16
SCR_AIMovementDetector::STOPPED_RADIUS_SQ
static const float STOPPED_RADIUS_SQ
Definition
SCR_AIMovementDetector.c:25
SCR_AIMovementDetector::GetMoving
bool GetMoving()
Returns current state, and updates it in lazy manner, not more often than once per UPDATE_INTERVAL_S.
Definition
SCR_AIMovementDetector.c:90
SCR_AIMovementDetector::m_TimeLastStopped
WorldTimestamp m_TimeLastStopped
Definition
SCR_AIMovementDetector.c:13
SCR_AIMovementDetector::SCR_AIMovementDetector
void SCR_AIMovementDetector(IEntity myEntity)
Definition
SCR_AIMovementDetector.c:33
SCR_AIMovementDetector::m_TimeLastUpdate
WorldTimestamp m_TimeLastUpdate
Definition
SCR_AIMovementDetector.c:15
SCR_AIMovementDetector::TIME_STOPPED_S
static const float TIME_STOPPED_S
Definition
SCR_AIMovementDetector.c:27
SCR_AIMovementDetector::m_vPosStopped
vector m_vPosStopped
Definition
SCR_AIMovementDetector.c:11
SCR_AIMovementDetector::m_vPrevPos
vector m_vPrevPos
Definition
SCR_AIMovementDetector.c:10
SCR_AIMovementDetector::m_OwnerEntity
IEntity m_OwnerEntity
Definition
SCR_AIMovementDetector.c:12
SCR_AIMovementDetector::STOPPED_RADIUS
static const float STOPPED_RADIUS
Definition
SCR_AIMovementDetector.c:24
SCR_AIMovementDetector::Update
void Update(WorldTimestamp worldTime)
Definition
SCR_AIMovementDetector.c:39
SCR_AIMovementDetector::UPDATE_INTERVAL_S
static const float UPDATE_INTERVAL_S
Definition
SCR_AIMovementDetector.c:30
Shape
Instance of created debug visualizer.
Definition
Shape.c:14
WorldTimestamp
Definition
WorldTimestamp.c:26
vector
Definition
vector.c:13
ShapeFlags
ShapeFlags
Definition
ShapeFlags.c:13
Update
@ Update
Definition
SndComponentCallbacks.c:14
scripts
Game
AI
Components
SCR_AIMovementDetector.c
Generated by
1.17.0