Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AIFindCover.c
Go to the documentation of this file.
1 class SCR_AIFindCover : AITaskScripted
2 {
3  // Inputs
4  protected static const string PORT_TARGET_POS = "TargetPos";
5  protected static const string PORT_COVER_QUERY_PROPERTIES = "CoverQueryProps";
6 
7  // Outputs
8  protected static const string PORT_COVER_LOCK = "CoverLock";
9 
10 
11  protected SCR_AICombatMoveState m_State;
12 
13 
14 #ifdef WORKBENCH
15  protected ref array<ref Shape> m_aDebugShapes = {};
16  protected ref Shape m_CoverShape;
17 
18  protected static const ShapeFlags m_SphereFlags = ShapeFlags.NOOUTLINE|ShapeFlags.NOZBUFFER|ShapeFlags.TRANSP;
19  protected static const ShapeFlags m_LineFlags = ShapeFlags.NOOUTLINE|ShapeFlags.TRANSP;
20  protected static const float DEBUGSPHERE_RADIUS = 0.1;
21 #endif
22 
23  //------------------------------------------------------------------------------------------------
24  override void OnInit(AIAgent owner)
25  {
26  SCR_AIUtilityComponent utilityComp = SCR_AIUtilityComponent.Cast(owner.FindComponent(SCR_AIUtilityComponent));
27  if (utilityComp)
28  m_State = utilityComp.m_CombatMoveState;
29  }
30 
31  //------------------------------------------------------------------------------------------------
32  override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
33  {
34  IEntity ownerEntity = owner.GetControlledEntity();
35  if (!ownerEntity || !m_State)
36  return ENodeResult.FAIL;
37 
38  //------------------------------------------------------------------------------------------------
39  // Read inputs
40 
41  CoverQueryProperties queryProps;
42  GetVariableIn(PORT_COVER_QUERY_PROPERTIES, queryProps);
43  if (!queryProps)
44  return ENodeResult.FAIL;
45 
46  //------------------------------------------------------------------------------------------------
47  // Find cover
48 
49  CoverQueryComponent coverComp = GetCoverQueryComponent(owner);
50  if (!coverComp)
51  return ENodeResult.FAIL;
52 
53 #ifdef WORKBENCH
54  ClearDebug();
55 #endif
56 
57  vector coverPos, coverTallestPos;
58  int tilex, tiley, coverId;
59 
60  ECoverSearchState coverSearchState = coverComp.GetBestCover("Soldiers", queryProps, coverPos, coverTallestPos, tilex, tiley, coverId);
61  if (coverSearchState == ECoverSearchState.RUNNING)
62  return ENodeResult.RUNNING;
63 
64  bool coverFound = coverSearchState == ECoverSearchState.SUCCESS;
65 
66 #ifdef WORKBENCH
67  if (DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_AI_DEBUG_COVERS))
68  {
69  m_aDebugShapes.Insert(Shape.CreateSphere(Color.GREEN, m_SphereFlags, ownerEntity.GetOrigin(), 0.2));
70  }
71 #endif
72 
73  if (!coverFound)
74  {
75  // Release previous cover lock
76  //m_State.ReleaseCover(); // Do not release previous cover if new one was not found. We still want to occupy it.
77  ClearVariable(PORT_COVER_LOCK);
78  return ENodeResult.FAIL;
79  }
80 
81  // Create new cover lock, and release the old one
82  m_State.AssignCover(new SCR_AICoverLock(tilex, tiley, coverId, coverPos, coverTallestPos));
83 
84  SetVariableOut(PORT_COVER_LOCK, m_State.GetAssignedCover());
85 
86 #ifdef WORKBENCH
87  if (DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_AI_DEBUG_COVERS))
88  {
89  m_CoverShape = Shape.CreateSphere(Color.PINK, m_SphereFlags, coverPos, 0.5);
90  }
91 #endif
92 
93  return ENodeResult.SUCCESS;
94  }
95 
96  //------------------------------------------------------------------------------------------------
97  CoverQueryComponent GetCoverQueryComponent(AIAgent owner)
98  {
99  AIGroup myGroup = owner.GetParentGroup();
100  if (!myGroup)
101  return null;
102  CoverQueryComponent coverComp = CoverQueryComponent.Cast(myGroup.FindComponent(CoverQueryComponent));
103  return coverComp;
104  }
105 
106  protected static ref TStringArray s_aVarsIn = {
107  PORT_COVER_QUERY_PROPERTIES
108  };
109  override TStringArray GetVariablesIn()
110  {
111  return s_aVarsIn;
112  }
113 
114  protected static ref TStringArray s_aVarsOut = {
115  PORT_COVER_LOCK
116  };
117  override TStringArray GetVariablesOut()
118  {
119  return s_aVarsOut;
120  }
121 
122  override static protected bool VisibleInPalette() { return true; }
123 
124  override string GetOnHoverDescription()
125  {
126  return "Finds and locks cover through cover manager. Keep in mind that cover is also assigned to CombatMoveState!";
127  }
128 
129  override bool CanReturnRunning() { return true; }
130 
131  #ifdef WORKBENCH
132  private void ClearDebug()
133  {
134  m_aDebugShapes.Clear();
135  }
136  #endif
137 }
ECoverSearchState
ECoverSearchState
Definition: ECoverSearchState.c:12
s_aVarsOut
SCR_AIPickupInventoryItemsBehavior s_aVarsOut
Definition: SCR_AIGetCombatMoveRequestParameters.c:149
SCR_AICoverLock
Definition: SCR_AICoverLock.c:19
SCR_AIFindCover
Definition: SCR_AIFindCover.c:1
m_State
private EEditableEntityState m_State
Definition: SCR_BaseEntitiesEditorUIEffect.c:3
m_aDebugShapes
protected ref array< ref Shape > m_aDebugShapes
Definition: SCR_PowerlineGeneratorEntity.c:64
SCR_DebugMenuID
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition: DebugMenuID.c:3