Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AICalculateCoverQueryProps_CombatMove.c
Go to the documentation of this file.
2 {
3  //---------------------------------------------------------------
4  // Inputs
5  protected const static string PORT_COMBAT_MOVE_REQUEST = "CombatMoveRequest";
6 
7  // Outputs
8  protected const static string PORT_COVER_QUERY_PROPERTIES = "CoverQueryProps";
9 
10  protected ref CoverQueryProperties m_CoverQueryProps = new CoverQueryProperties();
11 
12  protected SCR_AICombatMoveState m_State;
13 
14  [Attribute("60.0", UIWidgets.EditBox, "Max angle between cover dir. and dir. to target, in degrees.")]
15  protected float m_fMaxCoverToTargetAngleDeg;
16  protected float m_fMinCoverToTargetAngleCos;
17 
18 
19  //------------------------------------------------------------------------------------------------
20  override void OnInit(AIAgent owner)
21  {
22  m_fMinCoverToTargetAngleCos = Math.Cos(Math.DEG2RAD * m_fMaxCoverToTargetAngleDeg);
23 
24  SCR_AIUtilityComponent utilityComp = SCR_AIUtilityComponent.Cast(owner.FindComponent(SCR_AIUtilityComponent));
25  if (utilityComp)
26  m_State = utilityComp.m_CombatMoveState;
27  }
28 
29  //---------------------------------------------------------------
30  override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
31  {
32  IEntity ownerEntity = owner.GetControlledEntity();
33  if (!ownerEntity)
34  return ENodeResult.FAIL;
35 
37  GetVariableIn(PORT_COMBAT_MOVE_REQUEST, rqBase);
39 
40  if (!rq)
41  return SCR_AIErrorMessages.NodeErrorCombatMoveRequest(this, owner, rqBase);
42 
43  vector myPos = ownerEntity.GetOrigin();
44 
45  CoverQueryProperties query = m_CoverQueryProps;
46 
47  // Resolve direction of query
48  if (rq.m_eDirection == SCR_EAICombatMoveDirection.ANYWHERE)
49  {
50  // Query in circle, don't use direction
51  query.m_vSectorDir = vector.Zero;
52  query.m_fScoreWeightDirection = 0;
53  query.m_fQuerySectorAngleCosMin = -1.0;
54  }
55  else
56  {
57  // Directional query is used
58  // Query in sector
59  vector queryDirection = SCR_AICombatMoveUtils.CalculateMoveDirection(rq.m_eDirection, myPos, rq.m_vMovePos);
60  query.m_vSectorDir = queryDirection;
61  query.m_fQuerySectorAngleCosMin = Math.Cos(rq.m_fCoverSearchSectorHalfAngleRad);
62 
63  if (rq.m_bUseCoverSearchDirectivity)
64  query.m_fScoreWeightDirection = 10.0;
65  else
66  query.m_fScoreWeightDirection = 0;
67  }
68 
69 
70  // Query sector properties
71  query.m_vSectorPos = myPos;
72  query.m_vAgentPos = myPos;
73  query.m_fSectorDistMin = rq.m_fCoverSearchDistMin;
74  query.m_fSectorDistMax = rq.m_fCoverSearchDistMax;
75 
76  // Threat pos
77  vector threatPos = ResolveThreatPos(myPos, rq);
78  query.m_vThreatPos = threatPos;
79 
80  // Weight distance
81  query.m_fScoreWeightDistance = 1.0;
82 
83  // Other
84  query.m_fCoverHeightMin = 0;
85  query.m_fCoverHeightMax = 10.0;
86  query.m_fScoreWeightNavmeshRay = 2.0; // Penalize non directly reachable covers
87  query.m_iMaxCoversToCheck = SCR_CoverQueryComponent.MAX_COVERS_HIGH_PRIORITY;
88 
89 
90  query.m_fCoverToThreatAngleCosMin = m_fMinCoverToTargetAngleCos;
91  query.m_bCheckVisibility = rq.m_bCheckCoverVisibility;
92  query.m_bSelectHighestScore = false; // Select lowest score cover (nearest)
93 
94  SetVariableOut(PORT_COVER_QUERY_PROPERTIES, query);
95 
96  return ENodeResult.SUCCESS;
97  }
98 
99  //---------------------------------------------------------------
100  vector ResolveThreatPos(vector myPos, SCR_AICombatMoveRequest_Move request)
101  {
102  // Move threat pos slightly closer to us, to prevent the cover test from hitting the target
103  vector vToTarget = vector.Direction(myPos, request.m_vTargetPos).Normalized();
104  vector threatPos = request.m_vTargetPos - 1.2 * vToTarget; // ! Todo improve this, might not work against vehicles
105  return threatPos;
106  }
107 
108  //---------------------------------------------------------------
109  override bool VisibleInPalette() { return true; }
110 
111  protected static ref TStringArray s_aVarsIn = {
112  PORT_COMBAT_MOVE_REQUEST
113  };
114  override TStringArray GetVariablesIn() { return s_aVarsIn; }
115 
116  protected static ref TStringArray s_aVarsOut = {
117  PORT_COVER_QUERY_PROPERTIES
118  };
119  override TStringArray GetVariablesOut() { return s_aVarsOut; }
120 }
SCR_AICombatMoveUtils
Definition: SCR_AICombatMoveUtils.c:5
SCR_AICombatMoveRequestBase
Definition: SCR_AICombatMoveRequest.c:37
s_aVarsOut
SCR_AIPickupInventoryItemsBehavior s_aVarsOut
Definition: SCR_AIGetCombatMoveRequestParameters.c:149
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_AIErrorMessages
Definition: NodeError.c:30
SCR_AICombatMoveRequest_Move
Definition: SCR_AICombatMoveRequest.c:78
m_State
private EEditableEntityState m_State
Definition: SCR_BaseEntitiesEditorUIEffect.c:3
SCR_AICalculateCoverQueryProps_CombatMove
Definition: SCR_AICalculateCoverQueryProps_CombatMove.c:1
SCR_CoverQueryComponent
void SCR_CoverQueryComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_CoverQueryComponent.c:17