Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AIFindFirePositionBehavior.c
Go to the documentation of this file.
1 
6 {
7  static const float SNIPER_MIN_DISTANCE = 70.0;
8  static const float SNIPER_MAX_DISTANCE = 180.0;
9  static const float SNIPER_DURATION_S = 3*60.0;
10 
11  ref SCR_BTParam<vector> m_vTargetPosition = new SCR_BTParam<vector>("TargetPos");
12  ref SCR_BTParam<float> m_fMinDistance = new SCR_BTParam<float>("MinDist");
13  ref SCR_BTParam<float> m_fMaxDistance = new SCR_BTParam<float>("MaxDist");
14  ref SCR_BTParam<float> m_fDuration_s = new SCR_BTParam<float>("Duration_s");
15 
16  EAIUnitType m_eTargetUnitType;
17 
18  //----------------------------------------------------------------------------------------------------------------
19  void InitParameters(vector targetPos, float minDistance, float maxDistance, float duration)
20  {
21  m_vTargetPosition.Init(this, targetPos);
22  m_fMinDistance.Init(this, minDistance);
23  m_fMaxDistance.Init(this, maxDistance);
24  m_fDuration_s.Init(this, duration);
25  }
26  //----------------------------------------------------------------------------------------------------------------
27  void SCR_AIFindFirePositionBehavior(SCR_AIUtilityComponent utility, SCR_AIActivityBase groupActivity, vector targetPos,
28  float minDistance, float maxDistance, EAIUnitType targetUnitType, float duration, float priorityLevel = PRIORITY_LEVEL_NORMAL)
29  {
30  InitParameters(targetPos, minDistance, maxDistance, duration);
31 
32  m_eTargetUnitType = targetUnitType;
33 
34  m_sBehaviorTree = "{905124EEBF36D180}AI/BehaviorTrees/Chimera/Soldier/FindFirePosition.bt";
35  SetPriority(PRIORITY_BEHAVIOR_FIND_FIRE_POSITION);
36  m_fPriorityLevel.m_Value = priorityLevel;
37  m_bAllowLook = true;
38  }
39 
40  //----------------------------------------------------------------------------------------------------------------
41  override float CustomEvaluate()
42  {
43  // Complete when we have found some target to attack
44  if (m_Utility.m_CombatComponent.GetCurrentTarget())
45  {
46  Complete();
47  return 0;
48  }
49 
50  return GetPriority();
51  }
52 
53  //-----------------------------------------------------------------------------------------------------
54  override void OnActionSelected()
55  {
56  super.OnActionSelected();
57 
58  m_Utility.m_CombatComponent.SetExpectedEnemyType(m_eTargetUnitType);
59  }
60 }
61 
62 class SCR_AIGetFindFirePositionNextPos : SCR_AIActionTask
63 {
64  protected static const string PORT_NEXT_POSITION = "NextPosition";
65 
66  // When searching for next position, it will be within this range from our current position
67  protected const float NEXT_POS_MIN_DIST = 13.0;
68  protected const float NEXT_POS_MAX_DIST = 20.0;
69 
70  // When walking towards or away from target, the position will be randomized by this radius
71  protected const float WALK_DIRECTLY_RANDOM_RADIUS = 4.0;
72 
73  //-----------------------------------------------------------------------------------------------------
74  override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
75  {
76  if (!m_UtilityComp)
77  return ENodeResult.FAIL;
78 
79  SCR_AIActionBase executedAction = GetExecutedAction();
80  SCR_AIFindFirePositionBehavior behavior = SCR_AIFindFirePositionBehavior.Cast(executedAction);
81  if (!behavior)
82  return ENodeResult.FAIL;
83 
84  vector targetPos = behavior.m_vTargetPosition.m_Value;
85  IEntity myEntity = owner.GetControlledEntity();
86  vector myPos = myEntity.GetOrigin();
87 
88  vector vFromTarget = vector.Direction(targetPos, myPos);
89  vFromTarget[1] = 0;
90  float distanceToTarget = vFromTarget.Length();
91  vector vDirFromTarget = vFromTarget.Normalized(); // Direction vector from target to us
92  vDirFromTarget.Normalize();
93 
94  vector nextMovePos;
95  float minDist = behavior.m_fMinDistance.m_Value;
96  float maxDist = behavior.m_fMaxDistance.m_Value;
97  if (distanceToTarget > minDist &&
98  distanceToTarget < maxDist)
99  {
100  // We are within optimal range, walk around
101  nextMovePos = s_AIRandomGenerator.GenerateRandomPointInRadius(NEXT_POS_MIN_DIST, NEXT_POS_MAX_DIST, myPos);
102  }
103  else
104  {
105  float randomDistance = Math.RandomFloat(10, 20);
106  float dirMultiplier = 1;
107  if (distanceToTarget > maxDist)
108  {
109  // We are too far, move closer
110  dirMultiplier = -1;
111  }
112 
113  vector nextMovePosCenter = myPos + dirMultiplier * randomDistance * vDirFromTarget;
114  nextMovePos = s_AIRandomGenerator.GenerateRandomPointInRadius(0, WALK_DIRECTLY_RANDOM_RADIUS, nextMovePosCenter);
115  }
116 
117  SetVariableOut(PORT_NEXT_POSITION, nextMovePos);
118 
119  return ENodeResult.SUCCESS;
120  }
121 
122  //-----------------------------------------------------------------------------------------------------
123  override bool VisibleInPalette() { return true; }
124 
125  //-----------------------------------------------------------------------------------------------------
126  protected static ref TStringArray s_aVarsOut = { PORT_NEXT_POSITION };
127  override TStringArray GetVariablesOut() { return s_aVarsOut; }
128 }
129 
131 {
132  static ref TStringArray s_aVarsOut = (new SCR_AIFindFirePositionBehavior(null, null, vector.Zero, 0, 0, 0, 0)).GetPortNames();
133  override TStringArray GetVariablesOut() { return s_aVarsOut; }
134 
135  override bool VisibleInPalette() { return true; }
136 };
GetExecutedAction
proto external ref AIActionBase GetExecutedAction()
SCR_AIActionBase
Definition: SCR_AIAction.c:1
SCR_AIFindFirePositionBehavior
Definition: SCR_AIFindFirePositionBehavior.c:5
NEXT_POS_MAX_DIST
const protected float NEXT_POS_MAX_DIST
Definition: SCR_AIFindFirePositionBehavior.c:68
VisibleInPalette
override bool VisibleInPalette()
Definition: SCR_AIFindFirePositionBehavior.c:123
GetVariablesOut
override TStringArray GetVariablesOut()
Definition: SCR_AIFindFirePositionBehavior.c:127
NEXT_POS_MIN_DIST
const protected float NEXT_POS_MIN_DIST
Definition: SCR_AIFindFirePositionBehavior.c:67
m_fPriorityLevel
float m_fPriorityLevel
Definition: SendGoalMessage.c:3
SCR_AIActivityBase
Definition: SCR_AIActivity.c:1
GetPriority
int GetPriority()
Definition: SCR_BaseManualCameraComponent.c:107
WALK_DIRECTLY_RANDOM_RADIUS
const protected float WALK_DIRECTLY_RANDOM_RADIUS
Definition: SCR_AIFindFirePositionBehavior.c:71
EOnTaskSimulate
override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
Definition: SCR_AIFindFirePositionBehavior.c:74
EAIUnitType
EAIUnitType
Definition: EAIUnitType.c:12
PORT_NEXT_POSITION
SCR_AIFindFirePositionBehavior PORT_NEXT_POSITION
SCR_AIGetFirePositionBehaviorParameters
Definition: SCR_AIFindFirePositionBehavior.c:130
SCR_AIGetActionParameters
Definition: SCR_AIGetActionParameters.c:22
SCR_AIActionTask
Definition: SCR_AIBehaviorTask.c:1
SCR_AIBehaviorBase
Definition: SCR_AIBehavior.c:1
m_eTargetUnitType
EAIUnitType m_eTargetUnitType
Definition: SendGoalMessage.c:434