Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AIGetAimDistanceCompensation.c
Go to the documentation of this file.
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 SCR_AICombatComponent m_CombatComp;
11
12 //------------------------------------------------------------------------------------------------
13 override void OnInit(AIAgent owner)
14 {
15 IEntity ent = owner.GetControlledEntity();
16 if (!ent)
17 return;
18 m_CombatComp = SCR_AICombatComponent.Cast(ent.FindComponent(SCR_AICombatComponent));
19 }
20
21 //------------------------------------------------------------------------------------------------
22 override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
23 {
24 if (!m_CombatComp)
25 return ENodeResult.FAIL;
26
27 BaseWeaponManagerComponent weaponMgr = m_CombatComp.GetCurrentWeaponManager();
28
29 if (!weaponMgr)
30 return ENodeResult.FAIL;
31
32 // Read input variables
33 vector vin;
34 vector vout;
35 float initSpeedCoef = 1.0;
37 GetVariableIn(INITIAL_SPEED_COEFFICIENT, initSpeedCoef); // if not connected it will be still default 1.0
38
39 // Resolve target position
40 vector targetPos;
41 IEntity targetEntity;
42
43 if (GetVariableIn(TARGET_ENTITY_PORT, targetEntity))
44 {
45 if (!targetEntity)
46 {
47 Print("GetAimDistanceCompensation: provided null entity", LogLevel.WARNING);
48 return ENodeResult.FAIL;
49 }
50 targetPos = targetEntity.GetOrigin();
51 }
52 else
54
55 // Resolve current weapon and muzzle
56 BaseWeaponComponent currentWeapon;
57 BaseMuzzleComponent currentMuzzle;
58
59 currentWeapon = weaponMgr.GetCurrentWeapon();
60 if (currentWeapon)
61 currentMuzzle = currentWeapon.GetCurrentMuzzle();
62
63 // Resolve distance to target
64 float distance;
65 if (currentMuzzle)
66 {
67 vector muzzleMatrix[4];
68 weaponMgr.GetCurrentMuzzleTransform(muzzleMatrix);
69 distance = vector.Distance(targetPos, muzzleMatrix[3]);
70 }
71 else
72 distance = vector.Distance(targetPos, owner.GetControlledEntity().GetOrigin());
73
74 // Read data from ballistic tables
75 float heightOffset;
76 float flightTime;
77 if (currentWeapon && currentMuzzle)
78 {
79 // For normal weapons with muzzles
80 heightOffset = BallisticTable.GetAimHeightOfNextProjectile(distance, flightTime, currentMuzzle);
81 }
82 else if (currentWeapon)
83 {
84 // For grenades
85 heightOffset = BallisticTable.GetHeightFromProjectile(distance, flightTime, currentWeapon.GetOwner(), initSpeedCoef);
86 }
87
88 // Convert compensation vector to target space
89 // The Aim Offset node receives the vector in target entity space
90 vector vHeightCompensation;
91 vHeightCompensation[1] = heightOffset;
92 if (targetEntity)
93 vHeightCompensation = targetEntity.VectorToLocal(vHeightCompensation);
94
95
96 vout = vin + vHeightCompensation;
97 // problem of calculation: if character is reloading magazine and no ammo is in barrel -> the heightOffset is zero
98 // if (float.AlmostEqual(heightOffset, 0.0))
99 // Print("Error in testing mission: compensation is zero!", LogLevel.ERROR);
101
102 return ENodeResult.SUCCESS;
103 }
104
105 //------------------------------------------------------------------------------------------------
106 protected static ref TStringArray s_aVarsOut = {VECTOR_OUT_PORT};
108
109 //------------------------------------------------------------------------------------------------
111 override TStringArray GetVariablesIn() { return s_aVarsIn; }
112
113 //------------------------------------------------------------------------------------------------
114 static override bool VisibleInPalette() {return true;}
115
116 //------------------------------------------------------------------------------------------------
117 protected static override string GetOnHoverDescription() {return "Returns vertical offset for ballistic compensation of range to target";}
118}
float distance
proto external Managed FindComponent(typename typeName)
proto external vector GetOrigin()
proto external vector VectorToLocal(vector vec)
proto void SetVariableOut(string name, void val)
proto bool GetVariableIn(string name, out void val)
override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
ENodeResult
Definition ENodeResult.c:13
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
array< string > TStringArray
Definition Types.c:385