Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AIObserveUnknownFireBehavior.c
Go to the documentation of this file.
1 
9 {
10  protected const float TIMEOUT_S = 16.0;
11  protected const float DURATION_MIN_S = 3.0; // Min duration of behavior
12  protected const float DIRECTION_SPAN_DEG = 32.0;
13  protected const float DURATION_S_PER_METER = 0.1; // How duration depends on distance
14  protected const float USE_BINOCULARS_DISTANCE_THRESHOLD = 70;
15 
16  protected const float HIGH_PRIORITY_MAX_DISTANCE = 50; // Max distance at which we consider observing unknown fire a high priority
17 
18  protected const float DELAY_MIN_S = 0.15; // Min delay before we start looking at the position
19  protected const float DELAY_S_PER_METER = 0.0015; // How the delay increases depending on distance
20 
21  protected float m_fPriority;
22 
23  ref SCR_BTParam<vector> m_vPosition = new SCR_BTParam<vector>("Position");
24  ref SCR_BTParam<float> m_fDuration = new SCR_BTParam<float>("Duration");
25  ref SCR_BTParam<float> m_fRadius = new SCR_BTParam<float>("Radius");
26  ref SCR_BTParam<bool> m_bUseBinoculars = new SCR_BTParam<bool>("UseBinoculars");
27  ref SCR_BTParam<float> m_fDelay = new SCR_BTParam<float>("Delay");
28  ref SCR_BTParam<bool> m_bUseMovement = new SCR_BTParam<bool>("UseMovement");
29 
30  protected float m_fDeleteActionTime_ms;
31 
32  protected float m_fCombatMoveLogicTimeout = 0;
33 
34  void SCR_AIObserveUnknownFireBehavior(SCR_AIUtilityComponent utility, SCR_AIActivityBase groupActivity, vector posWorld, bool useMovement, float priorityLevel = PRIORITY_LEVEL_NORMAL)
35  {
36  InitParameters(posWorld, useMovement);
37 
38  if (!utility || !utility.GetAIAgent())
39  return;
40 
41  m_sBehaviorTree = "{AD1A56AE2A7ADFE8}AI/BehaviorTrees/Chimera/Soldier/ObservePositionBehavior.bt";
42  m_bAllowLook = false; // Disable standard looking
43  m_bResetLook = true;
44  m_bUseCombatMove = useMovement;
45  SetIsUniqueInActionQueue(true);
46  m_fThreat = 1.01 * SCR_AIThreatSystem.VIGILANT_THRESHOLD;
47  m_fPriority = SCR_AIActionBase.PRIORITY_BEHAVIOR_OBSERVE_UNKNOWN_FIRE;
48  m_fPriorityLevel.m_Value = priorityLevel;
49 
50  // Calculate duration depending on distance
51  IEntity controlledEntity = utility.GetAIAgent().GetControlledEntity();
52  float distance;
53  if (controlledEntity)
54  {
55  distance = vector.Distance(controlledEntity.GetOrigin(), posWorld);
56 
57  if (distance <= HIGH_PRIORITY_MAX_DISTANCE)
58  m_fPriority = SCR_AIActionBase.PRIORITY_BEHAVIOR_OBSERVE_UNKNOWN_FIRE_HIGH_PRIORITY;
59  }
60 
61  InitTiming(distance);
62 
63  if (controlledEntity)
64  {
65  float radius = distance * Math.Tan(Math.DEG2RAD * DIRECTION_SPAN_DEG);
66  m_fRadius.m_Value = radius;
67  m_bUseBinoculars.m_Value = distance > USE_BINOCULARS_DISTANCE_THRESHOLD;
68  }
69  }
70 
71  void InitParameters(vector position, bool useMovement)
72  {
73  m_vPosition.Init(this, position);
74  m_fDuration.Init(this, 0);
75  m_fRadius.Init(this, 0);
76  m_bUseBinoculars.Init(this, false);
77  m_fDelay.Init(this, 0.0);
78  m_bUseMovement.Init(this, useMovement);
79  }
80 
81  void InitTiming(float distance)
82  {
83  float duration_s = Math.Max(DURATION_MIN_S, DURATION_S_PER_METER * distance); // Linearly increase with distance
84  duration_s = Math.RandomFloat(0.7*duration_s, 1.3*duration_s);
85  m_fDuration.m_Value = duration_s;
86 
87  float timeout_s = Math.Max(TIMEOUT_S, duration_s); // Timeout is quite big, but it should be smaller than duration
88  InitTimeout(timeout_s);
89 
90  float delay_s = Math.Max(DELAY_MIN_S, DELAY_S_PER_METER * distance); // Linearly increase with distance
91  delay_s = Math.RandomFloat(0.7*delay_s, 1.3*delay_s);
92  m_fDelay.m_Value = delay_s;
93  }
94 
95  void InitTimeout(float timeout_s)
96  {
97  float currentTime_ms = GetGame().GetWorld().GetWorldTime(); // Milliseconds!
98  m_fDeleteActionTime_ms = currentTime_ms + 1000 * timeout_s;
99  }
100 
101  void SetUseMovement(bool value)
102  {
103  m_bUseMovement.m_Value = value;
104  m_bUseCombatMove = value;
105  }
106 
107  override void OnActionSelected()
108  {
109  super.OnActionSelected();
110 
111  if (Math.RandomFloat01() < 0.2)
112  {
113  if (!m_Utility.m_CommsHandler.CanBypass())
114  {
115  SCR_AITalkRequest rq = new SCR_AITalkRequest(ECommunicationType.REPORT_UNDER_FIRE, null, vector.Zero, 0, false, true, SCR_EAITalkRequestPreset.IRRELEVANT);
116  m_Utility.m_CommsHandler.AddRequest(rq);
117  }
118  }
119 
120  // If combat move is not used at all here, allow aiming immediately
121  // Because aiming is blocked by combat move aiming decorator
122  if (!m_bUseMovement.m_Value)
123  {
124  m_Utility.m_CombatMoveState.EnableAiming(true);
125  }
126  }
127 
128  override float CustomEvaluate()
129  {
130  // Fail action if timeout has been reached
131  float currentTime_ms = GetGame().GetWorld().GetWorldTime();
132  if (currentTime_ms > m_fDeleteActionTime_ms)
133  {
134  Fail();
135  return 0;
136  }
137 
138  return m_fPriority;
139  }
140 
141  static bool IsNewPositionMoreRelevant(vector myWorldPos, vector oldWorldPos, vector newWorldPos)
142  {
143  vector vDirOld = vector.Direction(myWorldPos, oldWorldPos);
144  vector vDirNew = vector.Direction(myWorldPos, newWorldPos);
145  float cosAngle = vector.Dot(vDirOld, vDirNew);
146 
147  return cosAngle < 0.707; // cos 45 deg
148  }
149 };
150 
152 {
153  static ref TStringArray s_aVarsOut = (new SCR_AIObserveUnknownFireBehavior(null, null, vector.Zero, false)).GetPortNames();
154  override TStringArray GetVariablesOut() { return s_aVarsOut; }
155 
156  override bool VisibleInPalette() { return true; }
157 };
m_fDuration
float m_fDuration
Definition: SendGoalMessage.c:437
SCR_AIActionBase
Definition: SCR_AIAction.c:1
m_fPriority
int m_fPriority
Definition: SCR_DestructionBaseComponent.c:713
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
s_aVarsOut
SCR_AIPickupInventoryItemsBehavior s_aVarsOut
Definition: SCR_AIGetCombatMoveRequestParameters.c:149
m_fDelay
protected float m_fDelay
Definition: SCR_TooltipManagerEditorUIComponent.c:8
m_fPriorityLevel
float m_fPriorityLevel
Definition: SendGoalMessage.c:3
SCR_AIObserveUnknownFireBehavior
Definition: SCR_AIObserveUnknownFireBehavior.c:8
m_bUseBinoculars
protected bool m_bUseBinoculars
Definition: SCR_AISmartActionSentinelComponent.c:25
SCR_AIActivityBase
Definition: SCR_AIActivity.c:1
SCR_AIGetObserveUnknownFireBehaviorParameters
Definition: SCR_AIObserveUnknownFireBehavior.c:151
SCR_AITalkRequest
void SCR_AITalkRequest(ECommunicationType type, IEntity entity, vector pos, int enumSignal, bool transmitIfNoReceivers, bool transmitIfPassenger, SCR_EAITalkRequestPreset preset)
Definition: SCR_AITalkRequest.c:37
distance
float distance
Definition: SCR_DestructibleTreeV2.c:29
ECommunicationType
ECommunicationType
Definition: SCR_AISoundHandling.c:1
m_fRadius
float m_fRadius
Definition: SCR_AITargetClusterState.c:30
SCR_AIGetActionParameters
Definition: SCR_AIGetActionParameters.c:22
m_vPosition
vector m_vPosition
Definition: SCR_AITalkRequest.c:23
position
vector position
Definition: SCR_DestructibleTreeV2.c:30
SCR_AIBehaviorBase
Definition: SCR_AIBehavior.c:1
SCR_AIThreatSystem
Definition: SCR_AIThreatSystem.c:17