Arma Reforger Explorer
1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Toggle main menu visibility
Loading...
Searching...
No Matches
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
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;
36
GetVariableIn
(
VECTOR_IN_PORT
, vin);
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
53
GetVariableIn
(
TARGET_POSITION_PORT
, targetPos);
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);
100
SetVariableOut
(
VECTOR_OUT_PORT
, vout);
101
102
return
ENodeResult
.SUCCESS;
103
}
104
105
//------------------------------------------------------------------------------------------------
106
protected
static
ref
TStringArray
s_aVarsOut
= {
VECTOR_OUT_PORT
};
107
override
TStringArray
GetVariablesOut
() {
return
s_aVarsOut
; }
108
109
//------------------------------------------------------------------------------------------------
110
protected
static
ref
TStringArray
s_aVarsIn
= {
TARGET_ENTITY_PORT
,
TARGET_POSITION_PORT
,
VECTOR_IN_PORT
,
INITIAL_SPEED_COEFFICIENT
};
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
}
distance
float distance
Definition
SCR_DestructibleTreeV2.c:29
AITaskScripted
Definition
AITaskScripted.c:13
BallisticTable
Definition
BallisticTable.c:13
BaseMuzzleComponent
Definition
BaseMuzzleComponent.c:13
BaseWeaponComponent
Definition
BaseWeaponComponent.c:13
IEntity
Definition
IEntity.c:13
IEntity::FindComponent
proto external Managed FindComponent(typename typeName)
IEntity::GetOrigin
proto external vector GetOrigin()
IEntity::VectorToLocal
proto external vector VectorToLocal(vector vec)
Node::SetVariableOut
proto void SetVariableOut(string name, void val)
Node::GetVariableIn
proto bool GetVariableIn(string name, out void val)
SCR_AIGetAimDistanceCompensation
Definition
SCR_AIGetAimDistanceCompensation.c:2
SCR_AIGetAimDistanceCompensation::s_aVarsIn
static ref TStringArray s_aVarsIn
Definition
SCR_AIGetAimDistanceCompensation.c:110
SCR_AIGetAimDistanceCompensation::EOnTaskSimulate
override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
Definition
SCR_AIGetAimDistanceCompensation.c:22
SCR_AIGetAimDistanceCompensation::INITIAL_SPEED_COEFFICIENT
static string INITIAL_SPEED_COEFFICIENT
Definition
SCR_AIGetAimDistanceCompensation.c:6
SCR_AIGetAimDistanceCompensation::TARGET_POSITION_PORT
static string TARGET_POSITION_PORT
Definition
SCR_AIGetAimDistanceCompensation.c:4
SCR_AIGetAimDistanceCompensation::GetVariablesIn
override TStringArray GetVariablesIn()
Definition
SCR_AIGetAimDistanceCompensation.c:111
SCR_AIGetAimDistanceCompensation::m_CombatComp
SCR_AICombatComponent m_CombatComp
Definition
SCR_AIGetAimDistanceCompensation.c:10
SCR_AIGetAimDistanceCompensation::GetOnHoverDescription
static override string GetOnHoverDescription()
Definition
SCR_AIGetAimDistanceCompensation.c:117
SCR_AIGetAimDistanceCompensation::TARGET_ENTITY_PORT
static string TARGET_ENTITY_PORT
Definition
SCR_AIGetAimDistanceCompensation.c:3
SCR_AIGetAimDistanceCompensation::GetVariablesOut
override TStringArray GetVariablesOut()
Definition
SCR_AIGetAimDistanceCompensation.c:107
SCR_AIGetAimDistanceCompensation::s_aVarsOut
static ref TStringArray s_aVarsOut
Definition
SCR_AIGetAimDistanceCompensation.c:106
SCR_AIGetAimDistanceCompensation::OnInit
override void OnInit(AIAgent owner)
Definition
SCR_AIGetAimDistanceCompensation.c:13
SCR_AIGetAimDistanceCompensation::VECTOR_IN_PORT
static string VECTOR_IN_PORT
Definition
SCR_AIGetAimDistanceCompensation.c:5
SCR_AIGetAimDistanceCompensation::VisibleInPalette
static override bool VisibleInPalette()
Definition
SCR_AIGetAimDistanceCompensation.c:114
SCR_AIGetAimDistanceCompensation::VECTOR_OUT_PORT
static string VECTOR_OUT_PORT
Definition
SCR_AIGetAimDistanceCompensation.c:8
vector
Definition
vector.c:13
ENodeResult
ENodeResult
Definition
ENodeResult.c:13
Print
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
LogLevel
Enum with severity of the logging message.
Definition
LogLevel.c:14
TStringArray
array< string > TStringArray
Definition
Types.c:385
scripts
Game
AI
ScriptedNodes
Aiming
SCR_AIGetAimDistanceCompensation.c
Generated by
1.17.0