Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AIGetRadialAngleForAgent.c
Go to the documentation of this file.
1 class SCR_AIGetRadialAngleForAgent : AITaskScripted
2 {
3  static const string PORT_AGENT = "AgentIn";
4  static const string PORT_ATTACK_LOCATION = "AttackLocationIn";
5  static const string PORT_DIRECTION_ANGLE = "AgentDiractionOut";
6  static const string PORT_ANGULAR_RANGE = "AngularRangeOut";
7 
8  protected SCR_AIGroupUtilityComponent m_groupUtilityComponent;
9 
10  //------------------------------------------------------------------------------------------------
11  protected static ref TStringArray s_aVarsIn = {
12  PORT_AGENT,
13  PORT_ATTACK_LOCATION
14  };
15  override TStringArray GetVariablesIn()
16  {
17  return s_aVarsIn;
18  }
19 
20  //------------------------------------------------------------------------------------------------
21  protected static ref TStringArray s_aVarsOut = {
22  PORT_DIRECTION_ANGLE,PORT_ANGULAR_RANGE
23  };
24  override TStringArray GetVariablesOut()
25  {
26  return s_aVarsOut;
27  }
28 
29  //------------------------------------------------------------------------------------------------
30  override void OnInit(AIAgent owner)
31  {
32  m_groupUtilityComponent = SCR_AIGroupUtilityComponent.Cast(owner.FindComponent(SCR_AIGroupUtilityComponent));
33  }
34 
35  //------------------------------------------------------------------------------------------------
36  override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
37  {
38  if (!m_groupUtilityComponent)
39  return NodeError(this,owner, "AIAgent does not have group utility component!");
40 
41  AIAgent defender;
42  if (!GetVariableIn(PORT_AGENT, defender))
43  {
44  return NodeError(this, owner, "No agent provided");
45  };
46 
47 
48  SCR_AIDefendActivity defendActivity = SCR_AIDefendActivity.Cast(m_groupUtilityComponent.GetCurrentAction());
49  if (!defendActivity)
50  return NodeError(this, owner, "Not running defend activity!");
51 
52  int index = defendActivity.FindRadialCoverAgent(defender);
53  int count = defendActivity.GetRadialCoverAgentsCount();
54  if (index < 0 || count == 0)
55  {
56  ClearVariable(PORT_DIRECTION_ANGLE);
57  ClearVariable(PORT_ANGULAR_RANGE);
58  return ENodeResult.FAIL;
59  };
60 
61  vector attackLocation, originOfLocalSpace = defendActivity.m_Waypoint.m_Value.GetOrigin();
62  if (!GetVariableIn(PORT_ATTACK_LOCATION, attackLocation))
63  return NodeError(this, owner, "No attack direction provided!");
64 
65  vector directionToDefend = attackLocation - originOfLocalSpace;
66  float angleToDefend = directionToDefend.ToYaw();
67  float sector = 360 / count;
68  float length = directionToDefend.Length();
69  int directionAngle = Math.Round(angleToDefend + sector * index);
70  directionAngle = directionAngle % 360;
71  directionToDefend[0] = Math.Sin(directionAngle * Math.DEG2RAD) * length;
72  directionToDefend[2] = Math.Cos(directionAngle * Math.DEG2RAD) * length;
73  SetVariableOut(PORT_DIRECTION_ANGLE, directionToDefend + originOfLocalSpace);
74  SetVariableOut(PORT_ANGULAR_RANGE, sector/2);
75  return ENodeResult.SUCCESS;
76  }
77 
78  //------------------------------------------------------------------------------------------------
79  protected override bool VisibleInPalette()
80  {
81  return true;
82  }
83 
84  //------------------------------------------------------------------------------------------------
85  protected override string GetOnHoverDescription()
86  {
87  return "Returns direction of defending and angle of sector covarage centered around the direction. If provided agent is not registered for sector coverage it FAILS";
88  }
89 
90 };
SCR_AIDefendActivity
Definition: SCR_AIDefendActivity.c:1
s_aVarsOut
SCR_AIPickupInventoryItemsBehavior s_aVarsOut
Definition: SCR_AIGetCombatMoveRequestParameters.c:149
NodeError
ENodeResult NodeError(Node node, AIAgent owner, string msg)
Error call to be used in scripted BT nodes.
Definition: NodeError.c:3
index
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Definition: SCR_DestructionSynchronizationComponent.c:17
SCR_AIGetRadialAngleForAgent
Definition: SCR_AIGetRadialAngleForAgent.c:1