Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_RotorHitZone.c
Go to the documentation of this file.
2 {
3  MINOR = 3,
4  MAJOR = 4,
5  CRITICAL = 5
6 }
7 
8 class SCR_RotorHitZone : SCR_VehicleHitZone
9 {
10  [Attribute(defvalue: "-1", uiwidget: UIWidgets.Auto, desc: "Rotor ID", category: "Rotor Damage")]
11  protected int m_iRotorId;
12 
13  [Attribute(desc: "Rotor collision detection root point", category: "Rotor Damage")]
14  protected ref PointInfo m_RotorPointInfo;
15 
16  [Attribute(uiwidget: UIWidgets.Slider, desc: "Rotor radius measured up from root in Rotor Info space\n[m]", params: "0.5 50 0.01", category: "Helicopter Damage")]
17  protected float m_fRotorRadius;
18 
19  [Attribute(uiwidget: UIWidgets.Slider, desc: "Rotor thickness measured up from root in Rotor Info space\n[m]", params: "0.1 10 0.01", category: "Helicopter Damage")]
20  protected float m_fRotorThickness;
21 
22  [Attribute(uiwidget: UIWidgets.Slider, desc: "Average blade width measured up from side to side at the tip of the blade\n[m]", params: "0.1 1000 0.01", category: "Helicopter Damage")]
23  protected float m_fBladeWidth;
24 
25  [Attribute(uiwidget: UIWidgets.EditBox, desc: "Amount of blades on this rotor", category: "Helicopter Damage")]
26  protected int m_iBladeCount;
27 
28  [Attribute(defvalue: "0.9", uiwidget: UIWidgets.Auto, desc: "Efficiency with minor damage state", category: "Rotor Damage")]
29  protected float m_fEfficiencyMinor;
30 
31  [Attribute(defvalue: "0.8", uiwidget: UIWidgets.Auto, desc: "Efficiency with major damage state", category: "Rotor Damage")]
32  protected float m_fEfficiencyMajor;
33 
34  [Attribute(defvalue: "0.6", uiwidget: UIWidgets.Auto, desc: "Efficiency with critical damage state", category: "Rotor Damage")]
35  protected float m_fEfficiencyCritical;
36 
37  protected VehicleHelicopterSimulation m_Simulation;
38 
39  //------------------------------------------------------------------------------------------------
40  override void OnInit(IEntity pOwnerEntity, GenericComponent pManagerComponent)
41  {
42  super.OnInit(pOwnerEntity, pManagerComponent);
43 
44  if (m_RotorPointInfo)
45  m_RotorPointInfo.Init(pOwnerEntity);
46 
47  SetRotorIndex(m_iRotorId);
48  }
49 
50  //------------------------------------------------------------------------------------------------
67  override float ComputeEffectiveDamage(notnull BaseDamageContext damageContext, bool isDOT)
68  {
69  vector hitTransform[3] = {damageContext.hitPosition, damageContext.hitDirection, damageContext.hitNormal};
70 
71  if (!isDOT && damageContext.damageType == EDamageType.KINETIC && m_RotorPointInfo && Math.RandomFloat01() > RotorHitChance(hitTransform))
72  return 0;
73 
74  return super.ComputeEffectiveDamage(damageContext, isDOT);
75  }
76 
77  //------------------------------------------------------------------------------------------------
79  float RotorHitChance(vector hitTransform[3])
80  {
81  if (!m_Simulation || m_Simulation.RotorGetState(GetRotorIndex()) != RotorState.SPINNING)
82  return 1;
83 
84  if (m_fBladeWidth <= 0 || m_iBladeCount < 1)
85  return 1;
86 
87  vector transform[4];
88  m_RotorPointInfo.GetTransform(transform);
89  vector relativePosition = hitTransform[0].InvMultiply4(transform);
90 
91  float distanceFromAxis = vector.DistanceXZ(relativePosition, vector.Zero);
92  if (distanceFromAxis == 0)
93  return 1;
94 
95  return m_fBladeWidth * m_iBladeCount / (Math.PI2 * distanceFromAxis);
96  }
97 
98  //------------------------------------------------------------------------------------------------
99  override void OnDamageStateChanged()
100  {
101  super.OnDamageStateChanged();
102 
104  }
105 
106  //------------------------------------------------------------------------------------------------
108  {
109  return m_fRotorRadius;
110  }
111 
112  //------------------------------------------------------------------------------------------------
114  {
115  return m_iBladeCount;
116  }
117 
118 
119  //------------------------------------------------------------------------------------------------
120  PointInfo GetPointInfo()
121  {
122  return m_RotorPointInfo;
123  }
124 
125  //------------------------------------------------------------------------------------------------
127  {
128  return m_iRotorId;
129  }
130 
131  //------------------------------------------------------------------------------------------------
133  void SetRotorIndex(int id)
134  {
135  m_iRotorId = id;
136  Vehicle vehicle = Vehicle.Cast(GetOwner().GetRootParent());
137  if (!vehicle)
138  return;
139 
140  // Vehicle.GetDamageManager() may not return damage manager during hitzone init
142  if (damageManager)
143  damageManager.RegisterVehicleHitZone(this);
144 
145  m_Simulation = VehicleHelicopterSimulation.Cast(vehicle.FindComponent(VehicleHelicopterSimulation));
146  }
147 
148  //------------------------------------------------------------------------------------------------
150  {
151  Vehicle vehicle = Vehicle.Cast(GetOwner().GetRootParent());
152  if (!vehicle)
153  return;
154 
155  SCR_VehicleDamageManagerComponent damageManager = SCR_VehicleDamageManagerComponent.Cast(vehicle.GetDamageManager());
156  if (damageManager)
157  damageManager.UpdateVehicleState();
158  }
159 
160  //------------------------------------------------------------------------------------------------
163  {
164  float efficiency = 1;
165 
166  SCR_ERotorDamageState state = GetDamageState();
167  if (state == SCR_ERotorDamageState.DESTROYED)
168  efficiency = 0;
169  else if (state == SCR_ERotorDamageState.CRITICAL)
170  efficiency = m_fEfficiencyCritical;
171  else if (state == SCR_ERotorDamageState.MAJOR)
172  efficiency = m_fEfficiencyMajor;
173  else if (state == SCR_ERotorDamageState.MINOR)
174  efficiency = m_fEfficiencyMinor;
175 
176  return efficiency;
177  }
178 
179  //------------------------------------------------------------------------------------------------
181  bool IsSpinning()
182  {
183  return m_Simulation && m_Simulation.RotorGetState(m_iRotorId) == RotorState.SPINNING;
184  }
185 
186  //------------------------------------------------------------------------------------------------
188  bool HasCollision(vector worldPosition)
189  {
190  if (!m_RotorPointInfo)
191  return false;
192 
193  if (m_fRotorRadius <= 0)
194  return false;
195 
196  if (m_fRotorThickness <= 0)
197  return false;
198 
199  if (m_Simulation && m_Simulation.RotorGetState(m_iRotorId) != RotorState.SPINNING)
200  return false;
201 
202  vector transform[4];
203  m_RotorPointInfo.GetTransform(transform);
204  vector relativePosition = worldPosition.InvMultiply4(transform);
205 
206  // Check if position is below rotor or above rotor thickness
207  if (m_fRotorThickness > 0 && relativePosition[1] < 0 || relativePosition[1] > m_fRotorThickness)
208  return false;
209 
210  // Check if position is inside rotor cylinder
211  return vector.DistanceSqXZ(relativePosition, vector.Zero) <= m_fRotorRadius * m_fRotorRadius;
212  }
213 
214 #ifdef WORKBENCH
215  //------------------------------------------------------------------------------------------------
217  override void DrawDebug()
218  {
219  if (!m_RotorPointInfo)
220  return;
221 
222  if (m_fRotorRadius <= 0)
223  return;
224 
225  if (m_fRotorThickness <= 0)
226  return;
227 
228  vector transform[4];
229  m_RotorPointInfo.GetWorldTransform(transform);
230  vector transformTop[4] = transform;
231  transformTop[3] = transformTop[3] + transformTop[1] * m_fRotorThickness;
232 
233  ShapeFlags shapeFlags = ShapeFlags.ONCE | ShapeFlags.NOZBUFFER | ShapeFlags.TRANSP | ShapeFlags.DOUBLESIDE | ShapeFlags.NOOUTLINE;
234 
236  Shape.CreateArrow(transform[3], transformTop[3], 0, Color.DARK_MAGENTA, shapeFlags);
237 
239  SCR_Shape.DrawCircle(transform, m_fRotorRadius, Color.DARK_RED, COLOR_RED_A, shapeFlags);
240  Shape.CreateArrow(transform[3] - transform[0] * m_fRotorRadius, transform[3], 0, Color.DARK_RED, shapeFlags);
241  Shape.CreateArrow(transform[3] + transform[0] * m_fRotorRadius, transform[3], 0, Color.DARK_RED, shapeFlags);
242  Shape.CreateArrow(transform[3] - transform[2] * m_fRotorRadius, transform[3], 0, Color.DARK_RED, shapeFlags);
243  Shape.CreateArrow(transform[3] + transform[2] * m_fRotorRadius, transform[3], 0, Color.DARK_RED, shapeFlags);
244 
246  SCR_Shape.DrawCircle(transformTop, m_fRotorRadius, Color.DARK_BLUE, COLOR_BLUE_A, shapeFlags);
247  Shape.CreateArrow(transformTop[3] - transform[0] * m_fRotorRadius, transformTop[3], 0, Color.DARK_BLUE, shapeFlags);
248  Shape.CreateArrow(transformTop[3] + transform[0] * m_fRotorRadius, transformTop[3], 0, Color.DARK_BLUE, shapeFlags);
249  Shape.CreateArrow(transformTop[3] - transform[2] * m_fRotorRadius, transformTop[3], 0, Color.DARK_BLUE, shapeFlags);
250  Shape.CreateArrow(transformTop[3] + transform[2] * m_fRotorRadius, transformTop[3], 0, Color.DARK_BLUE, shapeFlags);
251  }
252 #endif
253 }
CRITICAL
CRITICAL
Definition: SCR_RotorHitZone.c:4
BaseDamageContext
Definition: BaseDamageContext.c:12
MAJOR
MAJOR
Definition: SCR_RotorHitZone.c:3
MINOR
MINOR
Definition: SCR_RotorHitZone.c:2
SCR_ERotorDamageState
SCR_ERotorDamageState
Definition: SCR_RotorHitZone.c:1
OnInit
override void OnInit(IEntity pOwnerEntity, GenericComponent pManagerComponent)
Definition: SCR_RotorHitZone.c:40
IsSpinning
bool IsSpinning()
Check if rotor is spinning.
Definition: SCR_RotorHitZone.c:181
ComputeEffectiveDamage
override float ComputeEffectiveDamage(notnull BaseDamageContext damageContext, bool isDOT)
Definition: SCR_RotorHitZone.c:67
m_iBladeCount
protected int m_iBladeCount
Definition: SCR_RotorHitZone.c:26
GetPointInfo
PointInfo GetPointInfo()
Definition: SCR_RotorHitZone.c:120
SCR_VehicleDamageManagerComponent
void SCR_VehicleDamageManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_VehicleDamageManagerComponent.c:1720
EDamageState
EDamageState
Definition: EDamageState.c:12
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
GetRotorRadius
float GetRotorRadius()
Definition: SCR_RotorHitZone.c:107
HasCollision
bool HasCollision(vector worldPosition)
Check if world position is within rotor disc.
Definition: SCR_RotorHitZone.c:188
OnDamageStateChanged
override void OnDamageStateChanged()
Definition: SCR_RotorHitZone.c:99
category
params category
Definition: SCR_RotorHitZone.c:17
m_RotorPointInfo
protected ref PointInfo m_RotorPointInfo
Definition: SCR_RotorHitZone.c:14
SCR_VehicleHitZone
Definition: SCR_VehicleHitZone.c:1
UpdateRotorState
void UpdateRotorState()
Definition: SCR_RotorHitZone.c:149
RotorHitChance
float RotorHitChance(vector hitTransform[3])
Calculates the chance the rotor was hit by a bullet between 0 and 1.
Definition: SCR_RotorHitZone.c:79
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
SCR_Shape
Definition: SCR_Shape.c:1
m_Simulation
protected VehicleHelicopterSimulation m_Simulation
Definition: SCR_RotorHitZone.c:37
m_fEfficiencyMajor
protected float m_fEfficiencyMajor
Definition: SCR_RotorHitZone.c:32
Attribute
enum SCR_ERotorDamageState EDamageState Attribute(defvalue:"-1", uiwidget:UIWidgets.Auto, desc:"Rotor ID", category:"Rotor Damage")] protected int m_iRotorId
GetRotorIndex
int GetRotorIndex()
Definition: SCR_RotorHitZone.c:126
m_fEfficiencyCritical
protected float m_fEfficiencyCritical
Definition: SCR_RotorHitZone.c:35
EDamageType
EDamageType
Definition: EDamageType.c:12
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
GetBladeCount
int GetBladeCount()
Definition: SCR_RotorHitZone.c:113
RotorState
RotorState
Definition: RotorState.c:12
SetRotorIndex
void SetRotorIndex(int id)
Register rotor hitzone with damage manager.
Definition: SCR_RotorHitZone.c:133
m_fEfficiencyMinor
protected float m_fEfficiencyMinor
Definition: SCR_RotorHitZone.c:29
GetEfficiency
float GetEfficiency()
Set wheel parameters when damage exceeds thresholds.
Definition: SCR_RotorHitZone.c:162