Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AIFindTargetToLookAt.c
Go to the documentation of this file.
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
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 = {
81 };
83 {
84 return s_aVarsOut;
85 }
86
87 static override bool VisibleInPalette()
88 {
89 return true;
90 }
91};
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition DebugMenuID.c:4
Diagnostic and developer menu system.
Definition DiagMenu.c:18
proto external Managed FindComponent(typename typeName)
Definition Math.c:13
proto void SetVariableOut(string name, void val)
override void OnInit(AIAgent owner)
PerceptionComponent m_PerceptionComp
static override bool VisibleInPalette()
static ref TStringArray s_aVarsOut
static const string PORT_BASE_TARGET
override TStringArray GetVariablesOut()
override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
SCR_AIConfigComponent m_ConfigComp
Instance of created debug visualizer.
Definition Shape.c:14
ENodeResult
Definition ENodeResult.c:13
const int COLOR_BLUE_A
Definition constants.c:28
ShapeFlags
Definition ShapeFlags.c:13
SCR_FieldOfViewSettings Attribute
ETargetCategory
array< string > TStringArray
Definition Types.c:385