Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AICalculateNextCombatMovePos.c
Go to the documentation of this file.
2{
3 // Inputs
4 protected static const string PORT_REQUEST = "Request";
5 protected static const string PORT_TARGET_POS = "TargetPos";
6
7 // Outputs
8 protected static const string PORT_POS = "Pos";
9
10 //--------------------------------------------------------------------------------------------
11 override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
12 {
13 IEntity myEntity = owner.GetControlledEntity();
14 if (!myEntity)
15 return ENodeResult.FAIL;
16
17 // Read inputs
21 if (!rq)
22 return SCR_AIErrorMessages.NodeErrorCombatMoveRequest(this, owner, rq);
23
24 // Case for CUSTOM_POS is trivial, we move directly there
25 if (rq.m_eDirection == SCR_EAICombatMoveDirection.CUSTOM_POS)
26 {
27 SetVariableOut(PORT_POS, rq.m_vMovePos);
28 return ENodeResult.SUCCESS;
29 }
30
31 // The remaining cases are for moving a given distance in given direction
32
33 vector ownerPos = myEntity.GetOrigin();
34
35 vector moveDir = SCR_AICombatMoveUtils.CalculateMoveDirection(rq.m_eDirection, ownerPos, rq.m_vMovePos); // It can't return 000!
36
37 // Estimated move speed, depends on what we are controlling
38 float estMoveSpeed = SCR_AICombatMoveUtils.GetEstimatedMoveSpeed(rq);
39 float moveDistance = rq.m_fMoveDuration_s * estMoveSpeed;
40
41 // Randomize destination pos
42 vector newPositionCenter = ownerPos + moveDir * moveDistance;
43
44 vector randomizedPos = RandomizeDestinationPos(moveDistance, newPositionCenter);
45
46 SetVariableOut(PORT_POS, randomizedPos);
47
48 return ENodeResult.SUCCESS;
49 }
50
51 //--------------------------------------------------------------------------------------------
52 protected vector RandomizeDestinationPos(float distance, vector centerPos)
53 {
54 float radius = 0.1 * distance;
55 vector pos = s_AIRandomGenerator.GenerateRandomPointInRadius(0, radius, centerPos, true);
56 pos[1] = centerPos[1];
57 return pos;
58 }
59
60 //--------------------------------------------------------------------------------------------
61 protected static ref TStringArray s_aVarsOut = {
63 };
65
66 protected static ref TStringArray s_aVarsIn = {
68 };
69 override TStringArray GetVariablesIn() { return s_aVarsIn; }
70
71 static override bool VisibleInPalette() { return true; }
72
73}
class SCR_AINodePortsHelpers s_AIRandomGenerator
float distance
proto external vector GetOrigin()
proto void SetVariableOut(string name, void val)
proto bool GetVariableIn(string name, out void val)
override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
vector RandomizeDestinationPos(float distance, vector centerPos)
ENodeResult
Definition ENodeResult.c:13
array< string > TStringArray
Definition Types.c:385