Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AIGetAimDistanceCompensation.c
Go to the documentation of this file.
1 class SCR_AIGetAimDistanceCompensation : AITaskScripted
2 {
3  protected static string TARGET_ENTITY_PORT = "TargetEntity";
4  protected static string TARGET_POSITION_PORT = "TargetPosition";
5  protected static string VECTOR_IN_PORT = "VectorIn";
6  protected static string INITIAL_SPEED_COEFFICIENT = "InitialSpeedCoefficient";
7 
8  protected static string VECTOR_OUT_PORT = "VectorOut";
9 
10  protected BaseWeaponManagerComponent m_WeaponMgr;
11 
12  //------------------------------------------------------------------------------------------------
13  override void OnInit(AIAgent owner)
14  {
15  IEntity ent = owner.GetControlledEntity();
16  if (!ent)
17  return;
18  m_WeaponMgr = BaseWeaponManagerComponent.Cast(ent.FindComponent(BaseWeaponManagerComponent));
19  }
20 
21  //------------------------------------------------------------------------------------------------
22  override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
23  {
24  if (!m_WeaponMgr)
25  return ENodeResult.FAIL;
26 
27  // Read input variables
28  vector vin;
29  vector vout;
30  float initSpeedCoef = 1.0;
31  GetVariableIn(VECTOR_IN_PORT, vin);
32  GetVariableIn(INITIAL_SPEED_COEFFICIENT, initSpeedCoef); // if not connected it will be still default 1.0
33 
34  // Resolve target position
35  vector targetPos;
36  IEntity targetEntity;
37 
38  if (GetVariableIn(TARGET_ENTITY_PORT, targetEntity))
39  {
40  if (!targetEntity)
41  {
42  Print("GetAimDistanceCompensation: provided null entity", LogLevel.WARNING);
43  return ENodeResult.FAIL;
44  }
45  targetPos = targetEntity.GetOrigin();
46  }
47  else
48  GetVariableIn(TARGET_POSITION_PORT, targetPos);
49 
50  // Resolve current weapon and muzzle
51  BaseWeaponComponent currentWeapon;
52  BaseMuzzleComponent currentMuzzle;
53 
54  currentWeapon = m_WeaponMgr.GetCurrentWeapon();
55  if (currentWeapon)
56  currentMuzzle = currentWeapon.GetCurrentMuzzle();
57 
58  // Resolve distance to target
59  float distance;
60  if (currentMuzzle)
61  {
62  vector muzzleMatrix[4];
63  m_WeaponMgr.GetCurrentMuzzleTransform(muzzleMatrix);
64  distance = vector.Distance(targetPos, muzzleMatrix[3]);
65  }
66  else
67  distance = vector.Distance(targetPos, owner.GetControlledEntity().GetOrigin());
68 
69  // Read data from ballistic tables
70  float heightOffset;
71  float flightTime;
72  if (currentWeapon && currentMuzzle)
73  {
74  // For normal weapons with muzzles
75  heightOffset = BallisticTable.GetAimHeightOfNextProjectile(distance, flightTime, currentMuzzle);
76  }
77  else if (currentWeapon)
78  {
79  // For grenades
80  heightOffset = BallisticTable.GetHeightFromProjectile(distance, flightTime, currentWeapon.GetOwner(), initSpeedCoef);
81  }
82 
83  // Convert compensation vector to target space
84  // The Aim Offset node receives the vector in target entity space
85  vector vHeightCompensation;
86  vHeightCompensation[1] = heightOffset;
87  if (targetEntity)
88  vHeightCompensation = targetEntity.VectorToLocal(vHeightCompensation);
89 
90 
91  vout = vin + vHeightCompensation;
92  // problem of calculation: if character is reloading magazine and no ammo is in barrel -> the heightOffset is zero
93  // if (float.AlmostEqual(heightOffset, 0.0))
94  // Print("Error in testing mission: compensation is zero!", LogLevel.ERROR);
95  SetVariableOut(VECTOR_OUT_PORT, vout);
96 
97  return ENodeResult.SUCCESS;
98  }
99 
100  //------------------------------------------------------------------------------------------------
101  protected static ref TStringArray s_aVarsOut = {VECTOR_OUT_PORT};
102  override TStringArray GetVariablesOut() { return s_aVarsOut; }
103 
104  //------------------------------------------------------------------------------------------------
105  protected static ref TStringArray s_aVarsIn = {TARGET_ENTITY_PORT, TARGET_POSITION_PORT, VECTOR_IN_PORT, INITIAL_SPEED_COEFFICIENT};
106  override TStringArray GetVariablesIn() { return s_aVarsIn; }
107 
108  //------------------------------------------------------------------------------------------------
109  override bool VisibleInPalette() {return true;}
110 
111  //------------------------------------------------------------------------------------------------
112  protected override string GetOnHoverDescription() {return "Returns vertical offset for ballistic compensation of range to target";}
113 }
s_aVarsOut
SCR_AIPickupInventoryItemsBehavior s_aVarsOut
Definition: SCR_AIGetCombatMoveRequestParameters.c:149
distance
float distance
Definition: SCR_DestructibleTreeV2.c:29
BaseWeaponComponent
Definition: BaseWeaponComponent.c:12
BallisticTable
Definition: BallisticTable.c:12
SCR_AIGetAimDistanceCompensation
Definition: SCR_AIGetAimDistanceCompensation.c:1
BaseMuzzleComponent
Definition: BaseMuzzleComponent.c:12