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";
8 protected SCR_AIGroupUtilityComponent m_groupUtilityComponent;
11 protected static ref TStringArray s_aVarsIn = {
15 override TStringArray GetVariablesIn()
21 protected static ref TStringArray s_aVarsOut = {
22 PORT_DIRECTION_ANGLE,PORT_ANGULAR_RANGE
24 override TStringArray GetVariablesOut()
30 override void OnInit(AIAgent owner)
32 m_groupUtilityComponent = SCR_AIGroupUtilityComponent.Cast(owner.FindComponent(SCR_AIGroupUtilityComponent));
36 override ENodeResult EOnTaskSimulate(AIAgent owner,
float dt)
38 if (!m_groupUtilityComponent)
39 return NodeError(
this,owner,
"AIAgent does not have group utility component!");
42 if (!GetVariableIn(PORT_AGENT, defender))
44 return NodeError(
this, owner,
"No agent provided");
50 return NodeError(
this, owner,
"Not running defend activity!");
52 int index = defendActivity.FindRadialCoverAgent(defender);
53 int count = defendActivity.GetRadialCoverAgentsCount();
54 if (
index < 0 || count == 0)
56 ClearVariable(PORT_DIRECTION_ANGLE);
57 ClearVariable(PORT_ANGULAR_RANGE);
58 return ENodeResult.FAIL;
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!");
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;
79 protected override bool VisibleInPalette()
85 protected override string GetOnHoverDescription()
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";