Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AIFindTargetToLookAt.c
Go to the documentation of this file.
1 class SCR_AIFindTagetToLookAt: AITaskScripted
2 {
3  [Attribute("1", UIWidgets.EditBox, "Max time since target was last seen", "")]
4  float m_fTimeSinceSeenMax_S;
5 
6  [Attribute("1", UIWidgets.EditBox, "Max time since target was last detected", "")]
7  float m_fTimeSinceDetectedMax_S;
8 
9  protected static const string PORT_BASE_TARGET = "BaseTarget";
10 
11  protected PerceptionComponent m_PerceptionComp;
12  protected SCR_AIConfigComponent m_ConfigComp;
13 
14  #ifdef WORKBENCH
15  protected ref Shape m_Shape;
16  #endif
17 
18 
19  override void OnInit(AIAgent owner)
20  {
21  GenericEntity ent = GenericEntity.Cast(owner.GetControlledEntity());
22  if (!ent)
23  return;
24 
25  m_PerceptionComp = PerceptionComponent.Cast(ent.FindComponent(PerceptionComponent));
26  m_ConfigComp = SCR_AIConfigComponent.Cast(owner.FindComponent(SCR_AIConfigComponent));
27  }
28 
29 
30  override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
31  {
32  if (!m_ConfigComp || !m_ConfigComp.m_EnablePerception || !m_PerceptionComp)
33  return ENodeResult.FAIL;
34 
35  BaseTarget outTarget = null;
36 
37  float updateInterval = m_PerceptionComp.GetUpdateInterval();
38  float timeSinceSeenMax = Math.Max(m_fTimeSinceSeenMax_S, updateInterval) + 0.02;
39  float timeSinceDetectedMax = Math.Max(m_fTimeSinceDetectedMax_S, updateInterval) + 0.02;
40 
41  // Firse we search for target in detected category, since these targets are new and not identified yet
42  outTarget = m_PerceptionComp.GetClosestTarget(ETargetCategory.DETECTED, timeSinceSeenMax, timeSinceDetectedMax);
43 
44  //if (outTarget)
45  // Print("SCR_AIFindTagetToLookAt: Found detected target");
46 
47  // If there is no target in detected category, also check targets in enemy category
48  // Once target was identified, it stays in enemy category for a long time
49  if (!outTarget)
50  {
51  outTarget = m_PerceptionComp.GetClosestTarget(ETargetCategory.ENEMY, timeSinceSeenMax, timeSinceDetectedMax);
52  //if (outTarget)
53  // Print("SCR_AIFindTagetToLookAt: Found enemy target");
54  }
55 
56  //Print(string.Format("SCR_AIFindTagetToLookAt: Returning target: %1", outTarget));
57 
58  // Temporary fix to not look at disarmed (unconscious) targets
59  // Ideally it should be handled through GetClosestTarget call
60  if (outTarget && outTarget.IsDisarmed())
61  outTarget = null;
62 
63  SetVariableOut(PORT_BASE_TARGET, outTarget);
64 
65  #ifdef WORKBENCH
66  if (outTarget && DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_AI_SHOW_TARGET_LASTSEEN))
67  {
68  m_Shape = Shape.CreateSphere(COLOR_BLUE_A, ShapeFlags.NOOUTLINE|ShapeFlags.NOZBUFFER|ShapeFlags.TRANSP, outTarget.GetLastSeenPosition(), 0.1);
69  }
70  #endif
71 
72  if (outTarget)
73  return ENodeResult.SUCCESS;
74  else
75  return ENodeResult.FAIL;
76  }
77 
78 
79  protected static ref TStringArray s_aVarsOut = {
80  PORT_BASE_TARGET
81  };
82  override TStringArray GetVariablesOut()
83  {
84  return s_aVarsOut;
85  }
86 
87  override bool VisibleInPalette()
88  {
89  return true;
90  }
91 };
SCR_AIFindTagetToLookAt
Definition: SCR_AIFindTargetToLookAt.c:1
s_aVarsOut
SCR_AIPickupInventoryItemsBehavior s_aVarsOut
Definition: SCR_AIGetCombatMoveRequestParameters.c:149
ETargetCategory
ETargetCategory
Definition: ETargetCategory.c:12
GenericEntity
SCR_GenericBoxEntityClass GenericEntity
BaseTarget
Definition: BaseTarget.c:12
Attribute
typedef Attribute
Post-process effect of scripted camera.
m_Shape
private ref Shape m_Shape
Definition: UnitDisplayComponent.c:11
SCR_DebugMenuID
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition: DebugMenuID.c:3