Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AIObserveUnknownFireBehavior.c
Go to the documentation of this file.
1
7
8[Obsolete("This behavior is no longer used and might be deleted in future. It is replaced by SCR_AIObserveThreatSystemBehavior.")]
10{
11 protected const float TIMEOUT_S = 16.0;
12 protected const float DURATION_MIN_S = 3.0; // Min duration of behavior
13 protected const float DIRECTION_SPAN_DEG = 32.0;
14 protected const float DURATION_S_PER_METER = 0.1; // How duration depends on distance
15 protected const float USE_BINOCULARS_DISTANCE_THRESHOLD = 70;
16
17 protected const float HIGH_PRIORITY_MAX_DISTANCE = 50; // Max distance at which we consider observing unknown fire a high priority
18
19 protected const float DELAY_MIN_S = 0.15; // Min delay before we start looking at the position
20 protected const float DELAY_S_PER_METER = 0.0015; // How the delay increases depending on distance
21
22 protected float m_fPriority;
23
24 ref SCR_BTParam<vector> m_vPosition = new SCR_BTParam<vector>("Position");
25 ref SCR_BTParam<float> m_fDuration = new SCR_BTParam<float>("Duration");
26 ref SCR_BTParam<float> m_fRadius = new SCR_BTParam<float>("Radius");
27 ref SCR_BTParam<bool> m_bUseBinoculars = new SCR_BTParam<bool>("UseBinoculars");
28 ref SCR_BTParam<float> m_fDelay = new SCR_BTParam<float>("Delay");
29 ref SCR_BTParam<bool> m_bUseMovement = new SCR_BTParam<bool>("UseMovement");
30 ref SCR_BTParam<bool> m_bLookedOnce = new SCR_BTParam<bool>("LookedOnce"); // We set it to true after we've looked at pos. once
31
32 protected float m_fDeleteActionTime_ms;
33
34 protected float m_fCombatMoveLogicTimeout = 0;
35
36 void SCR_AIObserveUnknownFireBehavior(SCR_AIUtilityComponent utility, SCR_AIActivityBase groupActivity, vector posWorld, bool useMovement, float priorityLevel = PRIORITY_LEVEL_NORMAL, float priority = PRIORITY_BEHAVIOR_OBSERVE_UNKNOWN_FIRE)
37 {
38 InitParameters(posWorld, useMovement);
39
40 if (!utility || !utility.GetAIAgent())
41 return;
42
43 m_sBehaviorTree = "{AD1A56AE2A7ADFE8}AI/BehaviorTrees/Chimera/Soldier/ObservePositionBehavior.bt";
44 m_bAllowLook = false; // Disable standard looking
45 m_bResetLook = true;
46 m_bUseCombatMove = useMovement;
47 SetIsUniqueInActionQueue(true);
48 m_fThreat = 1.01 * SCR_AIThreatSystem.VIGILANT_THRESHOLD;
49 m_fPriority = priority;
50 m_fPriorityLevel.m_Value = priorityLevel;
51
52 // Calculate duration depending on distance
53 IEntity controlledEntity = utility.GetAIAgent().GetControlledEntity();
54 float distance;
55 if (controlledEntity)
56 {
57 distance = vector.Distance(controlledEntity.GetOrigin(), posWorld);
58
60 m_fPriority = SCR_AIActionBase.PRIORITY_BEHAVIOR_OBSERVE_UNKNOWN_FIRE_HIGH_PRIORITY;
61 }
62
64
65 if (controlledEntity)
66 {
67 float radius = distance * Math.Tan(Math.DEG2RAD * DIRECTION_SPAN_DEG);
68 m_fRadius.m_Value = radius;
69 bool inVehicleOrTurret = utility.m_AIInfo.HasUnitState(EUnitState.IN_VEHICLE) || utility.m_AIInfo.HasUnitState(EUnitState.IN_TURRET);
70 m_bUseBinoculars.m_Value = !inVehicleOrTurret && distance > USE_BINOCULARS_DISTANCE_THRESHOLD;
71 }
72 }
73
74 //---------------------------------------------------------------------------------------------------------------------------------
75 override int GetCause()
76 {
77 return SCR_EAIBehaviorCause.COMBAT;
78 }
79
80 //---------------------------------------------------------------------------------------------------------------------------------
81 void InitParameters(vector position, bool useMovement)
82 {
83 m_vPosition.Init(this, position);
84 m_fDuration.Init(this, 0);
85 m_fRadius.Init(this, 0);
86 m_bUseBinoculars.Init(this, false);
87 m_fDelay.Init(this, 0.0);
88 m_bUseMovement.Init(this, useMovement);
89 m_bLookedOnce.Init(this, false);
90 }
91
92 //---------------------------------------------------------------------------------------------------------------------------------
93 void InitTiming(float distance)
94 {
95 float duration_s = Math.Max(DURATION_MIN_S, DURATION_S_PER_METER * distance); // Linearly increase with distance
96 duration_s = Math.RandomFloat(0.7*duration_s, 1.3*duration_s);
97 m_fDuration.m_Value = duration_s;
98
99 float timeout_s = Math.Max(TIMEOUT_S, duration_s); // Timeout is quite big, but it should be smaller than duration
100 InitTimeout(timeout_s);
101
102 float delay_s = Math.Max(DELAY_MIN_S, DELAY_S_PER_METER * distance); // Linearly increase with distance
103 delay_s = Math.RandomFloat(0.7*delay_s, 1.3*delay_s);
104 m_fDelay.m_Value = delay_s;
105 }
106
107 //---------------------------------------------------------------------------------------------------------------------------------
108 void InitTimeout(float timeout_s)
109 {
110 float currentTime_ms = GetGame().GetWorld().GetWorldTime(); // Milliseconds!
111 m_fDeleteActionTime_ms = currentTime_ms + 1000 * timeout_s;
112 }
113
114 //---------------------------------------------------------------------------------------------------------------------------------
115 void SetUseMovement(bool value)
116 {
117 m_bUseMovement.m_Value = value;
118 m_bUseCombatMove = value;
119 }
120
121 //---------------------------------------------------------------------------------------------------------------------------------
122 override void OnActionSelected()
123 {
124 super.OnActionSelected();
125
126 if (Math.RandomFloat01() < 0.2)
127 {
128 if (!m_Utility.m_CommsHandler.CanBypass())
129 {
130 SCR_AITalkRequest rq = new SCR_AITalkRequest(ECommunicationType.REPORT_UNDER_FIRE, null, vector.Zero, 0, false, true, SCR_EAITalkRequestPreset.IRRELEVANT);
131 m_Utility.m_CommsHandler.AddRequest(rq);
132 }
133 }
134
135 // If combat move is not used at all here, allow aiming immediately
136 // Because aiming is blocked by combat move aiming decorator
137 if (!m_bUseMovement.m_Value)
138 {
139 m_Utility.m_CombatMoveState.EnableAiming(true);
140 }
141 }
142
143 //---------------------------------------------------------------------------------------------------------------------------------
144 override float CustomEvaluate()
145 {
146 // Fail action if timeout has been reached
147 float currentTime_ms = GetGame().GetWorld().GetWorldTime();
148 if (currentTime_ms > m_fDeleteActionTime_ms)
149 {
150 Fail();
151 return 0;
152 }
153
154 // If we already looked at this once, lower the priority
155 if (m_bLookedOnce.m_Value)
156 return PRIORITY_BEHAVIOR_OBSERVE_LOW_PRIORITY;
157
158 return m_fPriority;
159 }
160
161 //---------------------------------------------------------------------------------------------------------------------------------
162 static bool IsNewPositionMoreRelevant(vector myWorldPos, vector oldWorldPos, vector newWorldPos)
163 {
164 vector vDirOld = vector.Direction(myWorldPos, oldWorldPos);
165 vector vDirNew = vector.Direction(myWorldPos, newWorldPos);
166 float cosAngle = vector.Dot(vDirOld, vDirNew);
167
168 return cosAngle < 0.707; // cos 45 deg
169 }
170};
171
173{
174 // Copied strings to avoid compilation warning about obsolete class
175 static ref TStringArray s_aVarsOut = {"Position", "Duration", "Radius", "UseBinoculars", "Delay", "UseMovement", "LookedOnce"};
176 override TStringArray GetVariablesOut() { return s_aVarsOut; }
177
178 static override bool VisibleInPalette() { return true; }
179};
180
182{
183 static ref TStringArray s_aVarsIn = {"Position", "Duration", "Radius", "UseBinoculars", "Delay", "UseMovement", "LookedOnce"};
184 override TStringArray GetVariablesIn() { return s_aVarsIn; }
185
186 static override bool VisibleInPalette() { return true; }
187}
ArmaReforgerScripted GetGame()
Definition game.c:1398
ref SCR_BTParam< float > m_fPriorityLevel
enum EAIActionFailReason PRIORITY_LEVEL_NORMAL
ResourceName m_sBehaviorTree
void Fail(bool doNotCompleteWaypoint)
void SCR_AIActivityBase(SCR_AIGroupUtilityComponent utility, AIWaypoint relatedWaypoint)
enum SCR_EAIActivityCause m_Utility
float m_fThreat
void SCR_AIBehaviorBase(SCR_AIUtilityComponent utility, SCR_AIActivityBase groupActivity)
bool m_bResetLook
bool m_bUseCombatMove
SCR_EAIBehaviorCause
bool m_bAllowLook
override TStringArray GetVariablesIn()
override TStringArray GetVariablesOut()
ECommunicationType
void SCR_AITalkRequest(ECommunicationType type, IEntity entity, vector pos, int enumSignal, bool transmitIfNoReceivers, bool transmitIfPassenger, SCR_EAITalkRequestPreset preset)
float distance
vector position
proto external vector GetOrigin()
Definition Math.c:13
bool VisibleInPalette()
static override bool VisibleInPalette()
void SCR_AIObserveUnknownFireBehavior(SCR_AIUtilityComponent utility, SCR_AIActivityBase groupActivity, vector posWorld, bool useMovement, float priorityLevel=PRIORITY_LEVEL_NORMAL, float priority=PRIORITY_BEHAVIOR_OBSERVE_UNKNOWN_FIRE)
static bool IsNewPositionMoreRelevant(vector myWorldPos, vector oldWorldPos, vector newWorldPos)
void InitParameters(vector position, bool useMovement)
array< string > TStringArray
Definition Types.c:385