Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AIGetFireTimes.c
Go to the documentation of this file.
1 class SCR_AIGetFireTimes: AITaskScripted
2 {
3  static const string PORT_FIRE_BURST = "FireBurstTime";
4  static const string PORT_STABILIZATION = "StabilizationTime";
5  static const string PORT_SUPPRESSION = "SuppressionTime";
6  static const string PORT_REJECT_TIME = "RejectAimingTime";
7 
8  protected static string TARGET_ENTITY_PORT = "TargetEntity";
9  protected static string TARGET_POSITION_PORT = "TargetPosition";
10 
11  static const float CLOSE_RANGE_THRESHOLD_SQ = 15 * 15;
12 
13  private SCR_AICombatComponent m_CombatComponent;
14  private SCR_AIUtilityComponent m_Utility;
15 
16 
17  //------------------------------------------------------------------------------------------------
18  override void OnInit(AIAgent owner)
19  {
20  IEntity ent = owner.GetControlledEntity();
21  if (ent)
22  m_CombatComponent = SCR_AICombatComponent.Cast(ent.FindComponent(SCR_AICombatComponent));
23  }
24 
25  //------------------------------------------------------------------------------------------------
26  protected static ref TStringArray s_aVarsOut = {
27  PORT_FIRE_BURST,
28  PORT_STABILIZATION,
29  PORT_SUPPRESSION,
30  PORT_REJECT_TIME
31  };
32  override array<string> GetVariablesOut()
33  {
34  return s_aVarsOut;
35  }
36 
37  //------------------------------------------------------------------------------------------------
38  protected static ref TStringArray s_aVarsIn = {TARGET_ENTITY_PORT, TARGET_POSITION_PORT};
39  override TStringArray GetVariablesIn() { return s_aVarsIn; }
40 
41  //------------------------------------------------------------------------------------------------
42  override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
43  {
44 
45  if (!m_CombatComponent)
46  return ENodeResult.FAIL;
47 
48  EWeaponType weaponType = m_CombatComponent.GetCurrentWeaponType();
49  float random = Math.RandomFloat(0.1,0.3);
50 
51  // Factors are different than 1 only in close range
52  float distStabilizationTimeFactor = 1;
53  float distBurstTimeFactor = 1;
54 
55  vector targetPos;
56  IEntity ownerEntity = owner.GetControlledEntity();
57 
58  if (!ownerEntity)
59  return ENodeResult.FAIL;
60 
61  IEntity targetEntity;
62 
63  if (GetVariableIn(TARGET_ENTITY_PORT, targetEntity))
64  targetPos = targetEntity.GetOrigin();
65  else
66  GetVariableIn(TARGET_POSITION_PORT, targetPos);
67 
68  if (targetPos != vector.Zero)
69  {
70  float distToTargetSq = vector.DistanceSq(ownerEntity.GetOrigin(), targetPos);
71 
72  if (distToTargetSq < CLOSE_RANGE_THRESHOLD_SQ)
73  {
74  distStabilizationTimeFactor = Math.Map(distToTargetSq, 0, CLOSE_RANGE_THRESHOLD_SQ, 0, 1);
75  distBurstTimeFactor = Math.Map(distToTargetSq, 0, CLOSE_RANGE_THRESHOLD_SQ, 0, 1);
76  }
77  }
78 
79  switch (weaponType)
80  {
81  case EWeaponType.WT_RIFLE:
82  {
83  SetVariableOut(PORT_FIRE_BURST, random * distBurstTimeFactor);
84  SetVariableOut(PORT_STABILIZATION, 0.5 * distStabilizationTimeFactor);
85  SetVariableOut(PORT_SUPPRESSION, 0.5 + random);
86  SetVariableOut(PORT_REJECT_TIME, 0.5);
87  break;
88  }
89  case EWeaponType.WT_MACHINEGUN:
90  {
91  SetVariableOut(PORT_FIRE_BURST, random * 2 * distBurstTimeFactor);
92  SetVariableOut(PORT_STABILIZATION, 0.3 * distStabilizationTimeFactor);
93  SetVariableOut(PORT_SUPPRESSION, 0.3 + random*2);
94  SetVariableOut(PORT_REJECT_TIME, 0.5);
95  break;
96  }
97  case EWeaponType.WT_SMOKEGRENADE:
98  {
99  ClearVariable(PORT_FIRE_BURST);
100  SetVariableOut(PORT_STABILIZATION, 3.0 * distStabilizationTimeFactor);
101  ClearVariable(PORT_SUPPRESSION);
102  SetVariableOut(PORT_REJECT_TIME, 10.0);
103  break;
104  }
105  case EWeaponType.WT_FRAGGRENADE:
106  {
107  ClearVariable(PORT_FIRE_BURST);
108  SetVariableOut(PORT_STABILIZATION, 3.0 * distStabilizationTimeFactor);
109  ClearVariable(PORT_SUPPRESSION);
110  SetVariableOut(PORT_REJECT_TIME, 10.0);
111  break;
112  }
113  case EWeaponType.WT_HANDGUN:
114  {
115  ClearVariable(PORT_FIRE_BURST);
116  SetVariableOut(PORT_STABILIZATION, 1.0 * distStabilizationTimeFactor);
117  ClearVariable(PORT_SUPPRESSION);
118  SetVariableOut(PORT_REJECT_TIME, 1.0);
119  break;
120  }
121  case EWeaponType.WT_ROCKETLAUNCHER:
122  {
123  ClearVariable(PORT_FIRE_BURST);
124  SetVariableOut(PORT_STABILIZATION, 0.5 * distStabilizationTimeFactor);
125  ClearVariable(PORT_SUPPRESSION);
126  SetVariableOut(PORT_REJECT_TIME, 10.0);
127  break;
128  }
129  case EWeaponType.WT_SNIPERRIFLE:
130  {
131  ClearVariable(PORT_FIRE_BURST);
132  SetVariableOut(PORT_STABILIZATION, 1.0 * distStabilizationTimeFactor);
133  ClearVariable(PORT_SUPPRESSION);
134  SetVariableOut(PORT_REJECT_TIME, 20.0);
135  break;
136  }
137  default:
138  {
139  SetVariableOut(PORT_FIRE_BURST, random * 3 * distBurstTimeFactor);
140  ClearVariable(PORT_STABILIZATION);
141  SetVariableOut(PORT_SUPPRESSION, random * 3);
142  SetVariableOut(PORT_REJECT_TIME, 0.5);
143  break;
144  }
145  }
146 
147  return ENodeResult.SUCCESS;
148  }
149 
150  //------------------------------------------------------------------------------------------------
151  override bool VisibleInPalette() {return true;}
152 
153  //------------------------------------------------------------------------------------------------
154  protected override string GetOnHoverDescription() {return "Get all time constants for fire - it is weapon dependent";}
155 };
156 
s_aVarsOut
SCR_AIPickupInventoryItemsBehavior s_aVarsOut
Definition: SCR_AIGetCombatMoveRequestParameters.c:149
m_CombatComponent
SCR_AICombatComponent m_CombatComponent
Definition: SCR_AIUtilityComponent.c:12
EWeaponType
EWeaponType
Definition: EWeaponType.c:12
SCR_AIGetFireTimes
Definition: SCR_AIGetFireTimes.c:1