Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AILookAtThreatSystemLogic.c
Go to the documentation of this file.
1
5{
6 // Outputs
7 protected static const string PORT_CURRENT_POSITION = "CurrentPos"; // Position where we currently want to look at (major or minor threat)
8 protected static const string PORT_RESET_LOOK = "ResetLook";
9 protected static const string PORT_ACTIVE = "Active";
10 protected static const string PORT_RAISE_WEAPON = "RaiseWeapon";
11 protected static const string PORT_USE_OPTICS = "UseOptics";
12
13 protected static const int STATE_IDLE = 0; // Nothing to look at, although this shouldn't be possible.
14 protected static const int STATE_OBSERVING_MAJOR = 1; // Looking at major sector (most dangerous)
15 protected static const int STATE_OBSERVING_MINOR = 2; // Looking at minor sector
16 protected static const int STATE_INTERMISSION = 3; // A pause after looking
17
18 protected static const float DANGER_THRESHOLD_RAISE_WEAPON = 0.5; // Danger of sector beyond which we raise weapon
19 protected static const float DISTANCE_USE_OPTICS_SQ = 200*200;
20
23 protected int m_iSectorMajor;
24 protected int m_iSectorMinor;
25
26 protected int m_iState;
28 protected float m_fTimer;
29 protected float m_fTimerThreshold;
30
32
33 [Attribute("1", UIWidgets.EditBox)]
34 protected float m_fLookDurationMajor;
35
36 [Attribute("1", UIWidgets.EditBox)]
37 protected float m_fLookDurationMinor;
38
39 [Attribute("0", UIWidgets.EditBox, "Duration of waiting after looking")]
40 protected float m_fIntermissionDuration;
41
42 [Attribute("1", UIWidgets.EditBox, "Timers will be randomized between 1.0 and this value")]
44
45 [Attribute("0", UIWidgets.ComboBox, "Evaluate if we should raise weapon, and use optics?")]
47
48 //---------------------------------------------------------------------------
49 override void OnInit(AIAgent owner)
50 {
51 SCR_AIUtilityComponent utility = SCR_AIUtilityComponent.Cast(owner.FindComponent(SCR_AIUtilityComponent));
52 m_ThreatFilter = utility.m_SectorThreatFilter;
53 m_MyEntity = utility.m_OwnerEntity;
54
55 Reset();
56 }
57
58 //---------------------------------------------------------------------------
59 override void OnAbort(AIAgent owner, Node nodeCausingAbort)
60 {
61 Reset();
62 }
63
64 //---------------------------------------------------------------------------
65 protected void Reset()
66 {
67 m_iSectorMajor = -1;
68 m_iSectorMinor = -1;
70 m_fTimer = 0;
72 }
73
74 //---------------------------------------------------------------------------
75 override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
76 {
77 if (!m_ThreatFilter)
78 return ENodeResult.FAIL;
79
80 // Update timestamp, calculate timeSlice
81 WorldTimestamp worldTimestamp = GetGame().GetWorld().GetTimestamp();
82 float timeSlice_s = worldTimestamp.DiffSeconds(m_TimestampLastUpdate);
83 m_TimestampLastUpdate = worldTimestamp;
84
85 bool resetLook = false; // We reset it whenever we alternate sectors
86 int prevState = m_iState;
87
88 //-------------------------------------------------
89 /*
90 The logic of the state machine:
91 Alternate looking at major sector, and then at minor sector, with different duration.
92 If major sector from threat system changes, switch to looking at it.
93 */
94
95 int sectorMajor, sectorMinor;
96 m_ThreatFilter.GetActiveSectors(sectorMajor, sectorMinor);
97
98 switch (m_iState)
99 {
100 // Nothing to look at right now
101 case STATE_IDLE:
102 {
103 if (sectorMajor != -1) // There is now something to look at
105 break;
106 }
107
109 {
110 m_fTimer += timeSlice_s;
111
112 if (sectorMajor == -1)
113 SwitchState_Idle(); // Nothing to look at any more
114 else if (sectorMajor != m_iSectorMajor)
115 {
116 // Major sector changed, so something important has happened
117 // Reset the looking in BT, restart the timer
118 resetLook = true;
120 }
121 else if (m_fTimer > m_fTimerThreshold)
122 {
123 // Looked at it too much
126 else if (sectorMinor != -1)
128 }
129
130 break;
131 }
132
134 {
135 m_fTimer += timeSlice_s;
136
137 if (sectorMajor != m_iSectorMajor && sectorMajor != -1)
138 {
139 // Major sector changed, so something important has happened
140 // Start looking at major threat sector again
141 resetLook = true;
143 }
144 else if (sectorMinor == -1) // Minor sector is no longer relevant
145 {
146 if (sectorMajor != -1)
148 else
150 }
151 else if (m_fTimer > m_fTimerThreshold)
152 {
155 else if (sectorMajor != -1)
157 else
159 }
160
161 break;
162 }
163
165 {
166 m_fTimer += timeSlice_s;
167
168 if (sectorMajor != m_iSectorMajor && sectorMajor != -1)
169 {
170 // Major sector changed, so something important has happened
171 // Start looking at major threat sector again
172 resetLook = true;
174 }
175 else if (m_fTimer > m_fTimerThreshold)
176 {
177 // After pause is over, look at the next sector, if it's valid
179 {
180 if (sectorMajor != -1)
182 else
184 }
185 else
186 {
187 if (sectorMinor != -1)
189 else if (sectorMajor != -1)
191 else
193 }
194 }
195
196 break;
197 }
198 }
199
200 m_iSectorMajor = sectorMajor;
201 m_iSectorMinor = sectorMinor;
202
203
204 //-------------------------------------------------
205 // Propagate data to outputs
206
207 // Reset
208 if (m_iState != prevState) // Also reset if state changed
209 resetLook = true;
210 if (resetLook)
212
213 // Active
216
217 // Position and Radius
218 if (active)
219 {
220 int sectorId;
222 sectorId = m_iSectorMajor;
223 else
224 sectorId = m_iSectorMinor;
225
226 vector threatPos = m_ThreatFilter.GetSectorPos(sectorId);
228 }
229
230 // Optional: Evaluate if we should raise weapon, and use optics
232 {
233 bool raiseWeapon = false;
234 bool useOptics = false;
235 if (m_iSectorMajor != -1)
236 {
237 float dangerValue = m_ThreatFilter.GetSectorDanger(m_iSectorMajor);
238 raiseWeapon = dangerValue > DANGER_THRESHOLD_RAISE_WEAPON;
239 float distanceSq = vector.DistanceSq(m_ThreatFilter.GetSectorPos(m_iSectorMajor), m_MyEntity.GetOrigin());
240 useOptics = distanceSq > DISTANCE_USE_OPTICS_SQ;
241 }
242
243 // Raise weapon
244 SetVariableOut(PORT_RAISE_WEAPON, raiseWeapon);
246 }
247
248 return ENodeResult.SUCCESS;
249 }
250
258
266
267 protected void SwitchState_Idle()
268 {
270 m_fTimer = 0;
271 }
272
281
282 //---------------------------------------------------------------------------
285
286 override static bool VisibleInPalette() { return true; }
287}
ArmaReforgerScripted GetGame()
Definition game.c:1398
Definition Math.c:13
Definition Node.c:13
proto void SetVariableOut(string name, void val)
override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
void SwitchState_Intermission(int stateAfterIntermission)
override void OnAbort(AIAgent owner, Node nodeCausingAbort)
ENodeResult
Definition ENodeResult.c:13
SCR_FieldOfViewSettings Attribute
array< string > TStringArray
Definition Types.c:385