Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AIUpdateTargetSuppressionData.c
Go to the documentation of this file.
2{
3 // Inputs
4 protected static const string PORT_SUPPRESSION_VOLUME = "SuppressionVolume";
5
6 // Outputs
7 protected static const string PORT_VISIBLE = "Visible";
8 protected static const string PORT_TIME_LAST_SEEN = "TimeLastSeen_ms";
9 protected static const string PORT_FIRE_TREE_ID = "FireTreeId";
10
11 // These IDs must match to actual trees in the tree
12 protected const int FIRE_TREE_INVALID = -1; // No aiming or firing is allowed at all
13 protected const int FIRE_TREE_LOOK = 0; // Looking at target without firing
14 protected const int FIRE_TREE_SUPPRESSIVE = 1;
15
16 // Related to visibility check
17 protected float m_fVisibilityCheckTimer = VISIBILITY_CHECK_INTERVAL_S; // We need the vision check to run right on start. This data is required by movement logic.
18 protected bool m_bTargetVisible = false;
19 protected float m_fTargetLastSeenTime_ms = 0; // World time
20 protected ref TraceParam m_TraceParam;
21 protected ref array<IEntity> m_TraceParamExcludeArray;
22 protected const float VISIBILITY_CHECK_INTERVAL_S = 0.75;
23 protected const float VISIBILITY_CHECK_TRACE_RESULT_THRESHOLD = 0.5;
24
25 // Other
26 protected SCR_AIUtilityComponent m_UtilityComponent;
27 protected PerceptionComponent m_PerceptionComponent;
28
29 #ifdef WORKBENCH
30 protected ref array<ref Shape> m_aDebugShapes = {};
31 #endif
32
33 //---------------------------------------------------------------------------
34 override void OnInit(AIAgent owner)
35 {
36 m_UtilityComponent = SCR_AIUtilityComponent.Cast(owner.FindComponent(SCR_AIUtilityComponent));
37 IEntity myEntity = owner.GetControlledEntity();
38 if (myEntity)
39 m_PerceptionComponent = PerceptionComponent.Cast(myEntity.FindComponent(PerceptionComponent));
40 }
41
42 //---------------------------------------------------------------------------
43 override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
44 {
45 SCR_AISuppressionVolumeBase suppressionVolume;
46 if (!GetVariableIn(PORT_SUPPRESSION_VOLUME, suppressionVolume) || !suppressionVolume)
47 return ENodeResult.FAIL;
48
49 IEntity myEntity = owner.GetControlledEntity();
50 if (!myEntity || !m_UtilityComponent || !m_PerceptionComponent)
51 return ENodeResult.FAIL;
52
55 {
56 m_bTargetVisible = CheckTargetVisibility(myEntity, suppressionVolume);
57
59 m_fTargetLastSeenTime_ms = GetGame().GetWorld().GetWorldTime();
60
62 }
63
64 int fireTreeid = ResolveFireTree(m_bTargetVisible);
65
66 // Write data to ports
70
71 return ENodeResult.SUCCESS;
72 }
73
74 //---------------------------------------------------------------------------
75 bool CheckTargetVisibility(notnull IEntity myEntity, notnull SCR_AISuppressionVolumeBase suppressionVolume)
76 {
77 // Init trace params
78 if (!m_TraceParam)
79 {
81 m_TraceParam.TargetLayers = EPhysicsLayerDefs.FireGeometry;
82 m_TraceParam.Flags = TraceFlags.ENTS | TraceFlags.OCEAN | TraceFlags.WORLD | TraceFlags.ANY_CONTACT;
85 }
86
87 // Update entity exclude array
89 m_TraceParamExcludeArray.Insert(myEntity);
90 IEntity myEntityParent = myEntity.GetParent();
91 if (myEntityParent)
92 {
93 m_TraceParamExcludeArray.Insert(myEntityParent);
94 IEntity myEntityParentParent = myEntityParent.GetParent();
95 if (myEntityParentParent)
96 m_TraceParamExcludeArray.Insert(myEntityParentParent);
97 }
98
99 // Update start and end pos
100 // If we were to trace from start to end, and trace fraction in result is above VISIBILITY_CHECK_TRACE_RESULT_THRESHOLD,
101 // then we treat it as good visibility to target.
102 // But it means that we don't need to trace whole length anyway, but only fraction of it.
103 // That's why actual trace end is lerped.
104 ChimeraCharacter myCharacter = ChimeraCharacter.Cast(myEntity);
105 if (myCharacter)
106 m_TraceParam.Start = myCharacter.EyePosition();
107 else
108 m_TraceParam.Start = myEntity.GetOrigin();
109 vector traceEndPosIdeal = suppressionVolume.GetCenterPosition() + Vector(0, 2, 0); // Raise it a few meters up, to help around slopes
110 m_TraceParam.End = vector.Lerp(m_TraceParam.Start, traceEndPosIdeal, VISIBILITY_CHECK_TRACE_RESULT_THRESHOLD);
111
112 float traceResult = GetGame().GetWorld().TraceMove(m_TraceParam, null);
113
114 bool visible = traceResult == 1.0;
115
116 #ifdef WORKBENCH
117 if (DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_AI_SHOW_DEBUG_SHAPES))
118 {
119 m_aDebugShapes.Clear();
120
121 int lineColor;
122 if (visible)
123 lineColor = Color.GREEN;
124 else
125 lineColor = Color.RED;
126
127 vector lineVerts[2];
128 lineVerts[0] = m_TraceParam.Start;
129 lineVerts[1] = m_TraceParam.End;
130 Shape lineShape = Shape.CreateLines(lineColor, ShapeFlags.DEFAULT, lineVerts, 2);
131 m_aDebugShapes.Insert(lineShape);
132
133 if (traceResult != 1.0)
134 {
135 vector hitPos = m_TraceParam.Start + traceResult * (m_TraceParam.End - m_TraceParam.Start);
136 Shape sphereShape = Shape.CreateSphere(Color.RED, ShapeFlags.DEFAULT, hitPos, 0.2);
137 m_aDebugShapes.Insert(sphereShape);
138 }
139 }
140 #endif
141
142 return visible;
143 }
144
145 //---------------------------------------------------------------------------
146 int ResolveFireTree(bool targetVisible)
147 {
148 // Is aiming forbidden by combat move?
149 SCR_AIBehaviorBase executedBehavior = SCR_AIBehaviorBase.Cast(m_UtilityComponent.GetExecutedAction());
150 if (executedBehavior && executedBehavior.m_bUseCombatMove && !m_UtilityComponent.m_CombatMoveState.m_bAimAtTarget)
151 return FIRE_TREE_INVALID;
152
153 // Friendly in aim?
154 if (m_PerceptionComponent.GetFriendlyInLineOfFire())
155 return FIRE_TREE_LOOK;
156
157 if (targetVisible)
159
160 return FIRE_TREE_LOOK;
161 }
162
163 //---------------------------------------------------------------------------
165 override TStringArray GetVariablesIn() { return s_aVarsIn; }
166
169
170 static override bool VisibleInPalette() { return true; }
171}
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition DebugMenuID.c:4
ArmaReforgerScripted GetGame()
Definition game.c:1398
void SCR_AIBehaviorBase(SCR_AIUtilityComponent utility, SCR_AIActivityBase groupActivity)
Definition Color.c:13
Diagnostic and developer menu system.
Definition DiagMenu.c:18
proto external Managed FindComponent(typename typeName)
proto external IEntity GetParent()
proto void SetVariableOut(string name, void val)
proto bool GetVariableIn(string name, out void val)
bool CheckTargetVisibility(notnull IEntity myEntity, notnull SCR_AISuppressionVolumeBase suppressionVolume)
override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
Instance of created debug visualizer.
Definition Shape.c:14
ENodeResult
Definition ENodeResult.c:13
ShapeFlags
Definition ShapeFlags.c:13
array< string > TStringArray
Definition Types.c:385
proto native vector Vector(float x, float y, float z)
TraceFlags
Definition TraceFlags.c:13