Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_WheelHitZone.c
Go to the documentation of this file.
2 {
3  PUNCTURED = 3
4 }
5 
6 class SCR_WheelHitZone : SCR_VehicleHitZone
7 {
8  [Attribute( defvalue: "-1", uiwidget: UIWidgets.Auto, desc: "Wheel ID", category: "Wheel Damage")]
9  protected int m_iWheelId;
10 
11  [Attribute( defvalue: "0.9", uiwidget: UIWidgets.Auto, desc: "Radius multiplier for a damaged wheel.", category: "Wheel Damage")]
12  protected float m_fDamagedRadiusScale;
13 
14  [Attribute( defvalue: "0.4", uiwidget: UIWidgets.Auto, desc: "Longitudinal friction multiplier for a damaged wheel.", category: "Wheel Damage")]
16 
17  [Attribute( defvalue: "0.4", uiwidget: UIWidgets.Auto, desc: "Lateral friction multiplier for a damaged wheel.", category: "Wheel Damage")]
19 
20  [Attribute( defvalue: "1.5", uiwidget: UIWidgets.Auto, desc: "Roughness increase for a damaged wheel.", category: "Wheel Damage")]
21  protected float m_fDamagedRoughnessIncrease;
22 
23  [Attribute( defvalue: "0.1", uiwidget: UIWidgets.Auto, desc: "Drag of a damaged wheel.", category: "Wheel Damage")]
24  protected float m_fDamagedDrag;
25 
26  [Attribute( defvalue: "0.8", uiwidget: UIWidgets.Auto, desc: "Radius multiplier for a destroyed wheel.", category: "Wheel Damage")]
27  protected float m_fDestroyedRadiusScale;
28 
29  [Attribute( defvalue: "0.2", uiwidget: UIWidgets.Auto, desc: "Longitudinal friction multiplier for a destroyed wheel.", category: "Wheel Damage")]
31 
32  [Attribute( defvalue: "0.2", uiwidget: UIWidgets.Auto, desc: "Lateral friction multiplier for a destroyed wheel.", category: "Wheel Damage")]
34 
35  [Attribute( defvalue: "3.0", uiwidget: UIWidgets.Auto, desc: "Roughness increase for a destroyed wheel.", category: "Wheel Damage")]
37 
38  [Attribute( defvalue: "1.0", uiwidget: UIWidgets.Auto, desc: "Drag of a destroyed wheel.", category: "Wheel Damage")]
39  protected float m_fDestroyedDrag;
40 
41  //------------------------------------------------------------------------------------------------
42  override void OnInit(IEntity pOwnerEntity, GenericComponent pManagerComponent)
43  {
44  super.OnInit(pOwnerEntity, pManagerComponent);
45 
48  }
49 
50  //------------------------------------------------------------------------------------------------
51  override EHitZoneGroup GetHitZoneGroup()
52  {
53  return m_eHitZoneGroup;
54  }
55 
56  //------------------------------------------------------------------------------------------------
57  override void OnDamageStateChanged()
58  {
59  super.OnDamageStateChanged();
60 
63  }
64 
65  //------------------------------------------------------------------------------------------------
68  {
69  return m_iWheelId;
70  }
71 
72  //------------------------------------------------------------------------------------------------
74  void SetWheelIndex(int index)
75  {
76  m_iWheelId = index;
77 
78  // Notify the relevant damage manager if present
79  SCR_WheeledDamageManagerComponent damageManager = SCR_WheeledDamageManagerComponent.Cast(m_RootDamageManager);
80  if (damageManager)
81  damageManager.RegisterVehicleHitZone(this);
82 
85  }
86 
87  //------------------------------------------------------------------------------------------------
90  {
91  if (m_iWheelId == -1)
92  return;
93 
94  IEntity owner = GetOwner();
95 
96  IEntity parent = SCR_EntityHelper.GetMainParent(owner, true);
98  {
99  VehicleWheeledSimulation simulation = VehicleWheeledSimulation.Cast(parent.FindComponent(VehicleWheeledSimulation));
100  if (!simulation || !simulation.IsValid() || m_iWheelId >= simulation.WheelCount())
101  return;
102 
103  // Update simulation
104  float radius = simulation.WheelGetRadius(m_iWheelId);
105  float longitudinalFriction = simulation.WheelTyreGetLongitudinalFriction(m_iWheelId);
106  float lateralFriction = simulation.WheelTyreGetLateralFriction(m_iWheelId);
107  float roughness = simulation.WheelTyreGetRoughness(m_iWheelId);
108  float drag;
109 
110  // Only run the rest of code if state has changed
111  SCR_EWheelDamageState state = GetDamageState();
112  if (state == SCR_EWheelDamageState.DESTROYED)
113  {
114  radius *= m_fDestroyedRadiusScale;
115  longitudinalFriction *= m_fDestroyedLongitudinalFrictionScale;
116  lateralFriction *= m_fDestroyedLateralFrictionScale;
117  roughness += m_fDestroyedRoughnessIncrease;
118  drag = m_fDestroyedDrag;
119  }
120  else if (state == SCR_EWheelDamageState.PUNCTURED)
121  {
122  radius *= m_fDamagedRadiusScale;
123  longitudinalFriction *= m_fDamagedLongitudinalFrictionScale;
124  lateralFriction *= m_fDamagedLateralFrictionScale;
125  roughness += m_fDamagedRoughnessIncrease;
126  drag = m_fDamagedDrag;
127  }
128 
129  simulation.WheelSetRadiusState(m_iWheelId, radius);
130  simulation.WheelTyreSetLongitudinalFrictionState(m_iWheelId, longitudinalFriction);
131  simulation.WheelTyreSetLateralFrictionState(m_iWheelId, lateralFriction);
132  simulation.WheelTyreSetRoughnessState(m_iWheelId, roughness);
133  simulation.WheelSetRollingDrag(m_iWheelId, drag);
134 
135  // Need to wake physics up when wheel becomes destroyed
136  if (state == SCR_EWheelDamageState.PUNCTURED || state == SCR_EWheelDamageState.DESTROYED)
137  WakeUpPhysics();
138  }
139  else
140  {
141  VehicleWheeledSimulation_SA simulation = VehicleWheeledSimulation_SA.Cast(parent.FindComponent(VehicleWheeledSimulation_SA));
142  if (!simulation || !simulation.IsValid() || m_iWheelId >= simulation.WheelCount())
143  return;
144 
145  // Update simulation
146  float previousRadius = simulation.WheelGetRadiusState(m_iWheelId);
147  float radius = simulation.WheelGetRadius(m_iWheelId);
148  float longitudinalFriction = simulation.WheelTyreGetLongitudinalFriction(m_iWheelId);
149  float lateralFriction = simulation.WheelTyreGetLateralFriction(m_iWheelId);
150  float roughness = simulation.WheelTyreGetRoughness(m_iWheelId);
151  float drag;
152 
153  // Only run the rest of code if state has changed
154  SCR_EWheelDamageState state = GetDamageState();
155  if (state == SCR_EWheelDamageState.DESTROYED)
156  {
157  radius *= m_fDestroyedRadiusScale;
158  longitudinalFriction *= m_fDestroyedLongitudinalFrictionScale;
159  lateralFriction *= m_fDestroyedLateralFrictionScale;
160  roughness += m_fDestroyedRoughnessIncrease;
161  drag = m_fDestroyedDrag;
162  }
163  else if (state == SCR_EWheelDamageState.PUNCTURED)
164  {
165  radius *= m_fDamagedRadiusScale;
166  longitudinalFriction *= m_fDamagedLongitudinalFrictionScale;
167  lateralFriction *= m_fDamagedLateralFrictionScale;
168  roughness += m_fDamagedRoughnessIncrease;
169  drag = m_fDamagedDrag;
170  }
171 
172  simulation.WheelSetRadiusState(m_iWheelId, radius);
173  simulation.WheelTyreSetLongitudinalFrictionState(m_iWheelId, longitudinalFriction);
174  simulation.WheelTyreSetLateralFrictionState(m_iWheelId, lateralFriction);
175  simulation.WheelTyreSetRoughnessState(m_iWheelId, roughness);
176  simulation.WheelSetRollingDrag(m_iWheelId, drag);
177 
178  // Need to wake physics up when wheel becomes destroyed
179  if (!float.AlmostEqual(radius, previousRadius))
180  WakeUpPhysics();
181  }
182 
183  // Notify the relevant damage manager if present
184  SCR_WheeledDamageManagerComponent damageManager = SCR_WheeledDamageManagerComponent.Cast(m_RootDamageManager);
185  if (damageManager)
186  damageManager.UpdateVehicleState();
187  }
188 
189  //------------------------------------------------------------------------------------------------
190  protected void UpdateDamageSignal()
191  {
192  if (m_iWheelId == -1)
193  return;
194 
195  IEntity parent = SCR_EntityHelper.GetMainParent(GetOwner(), true);
196  if (!parent)
197  return;
198 
199  // Set TireDamage signal
200  float damageState = GetDamageState();
201 
202  SignalsManagerComponent signalManager = SignalsManagerComponent.Cast(parent.FindComponent(SignalsManagerComponent));
203  if (signalManager)
204  {
205  int damageSignal = signalManager.AddOrFindSignal("TireDamage" + m_iWheelId.ToString());
206  if (damageSignal != -1)
207  signalManager.SetSignalValue(damageSignal, damageState);
208  }
209  }
210 
211  //------------------------------------------------------------------------------------------------
212  override void PlayDestructionSound(EDamageState damageState)
213  {
214  SCR_EWheelDamageState pDS = GetPreviousDamageState();
215 
216  if (pDS <= SCR_EWheelDamageState.INTERMEDIARY && damageState >= SCR_EWheelDamageState.DESTROYED)
217  {
218  IEntity owner = GetOwner();
219 
220  IEntity parent = SCR_EntityHelper.GetMainParent(owner, true);
221  if (!parent)
222  return;
223 
224  SoundComponent soundComponent = SoundComponent.Cast(parent.FindComponent(SoundComponent));
225  Physics physics = owner.GetPhysics();
226  if (!physics || !soundComponent)
227  return;
228 
229  vector offset;
230  if (!HasColliderNodes())
231  {
232  // Use center of mass of whole entity
233  offset = physics.GetCenterOfMass();
234  offset = owner.CoordToParent(offset);
235  }
236  else
237  {
238  // Get collider geometry
239  int colliderID = -1;
240  array<string> colliderNames = {};
241  GetAllColliderNames(colliderNames);
242  foreach (string colliderName: colliderNames)
243  {
244  colliderID = physics.GetGeom(colliderNames[0]);
245  if (colliderID != -1)
246  break;
247  }
248 
249  if (colliderID == -1)
250  return;
251 
252  offset = physics.GetGeomWorldPosition(colliderID);
253  }
254 
255  offset = parent.CoordToLocal(offset);
256  soundComponent.SoundEventOffset(SCR_SoundEvent.SOUND_TIRE_PUNCTURE, offset);
257  }
258  }
259 
260  //------------------------------------------------------------------------------------------------
263  {
264  IEntity parent = SCR_EntityHelper.GetMainParent(GetOwner(), true);
265  Physics physics = parent.GetPhysics();
266  if (!physics)
267  return;
268 
269  if (!physics.IsDynamic())
270  return;
271 
272  if (physics.IsActive())
273  return;
274 
275  vector centerOfMass = physics.GetCenterOfMass();
276  float force = 0.01 * physics.GetMass();
277  physics.ApplyImpulseAt(centerOfMass, vector.Up * force);
278  physics.ApplyImpulseAt(centerOfMass, vector.Up * -force);
279  }
280 
281  //------------------------------------------------------------------------------------------------
284  {
285  return GetDamageStateThreshold(GetDamageState());
286  }
287 }
UpdateWheelState
void UpdateWheelState()
Set wheel parameters when damage exceeds thresholds.
Definition: SCR_WheelHitZone.c:89
m_eHitZoneGroup
protected ECharacterHitZoneGroup m_eHitZoneGroup
Definition: SCR_InventoryHitZonePointUI.c:403
SCR_EntityHelper
Definition: SCR_EntityHelper.c:1
m_fDestroyedDrag
protected float m_fDestroyedDrag
Definition: SCR_WheelHitZone.c:39
m_RootDamageManager
protected SCR_VehicleDamageManagerComponent m_RootDamageManager
Definition: SCR_RotorDamageManagerComponent.c:8
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
m_fDestroyedRoughnessIncrease
protected float m_fDestroyedRoughnessIncrease
Definition: SCR_WheelHitZone.c:36
SCR_SoundEvent
Definition: SCR_SoundEvent.c:1
EDamageState
EDamageState
Definition: EDamageState.c:12
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
m_fDamagedRadiusScale
protected float m_fDamagedRadiusScale
Definition: SCR_WheelHitZone.c:12
m_fDestroyedLongitudinalFrictionScale
protected float m_fDestroyedLongitudinalFrictionScale
Definition: SCR_WheelHitZone.c:30
m_fDamagedLateralFrictionScale
protected float m_fDamagedLateralFrictionScale
Definition: SCR_WheelHitZone.c:18
GetIsClientAuthority
override bool GetIsClientAuthority()
Definition: game.c:268
PUNCTURED
PUNCTURED
Definition: SCR_WheelHitZone.c:2
m_fDamagedDrag
protected float m_fDamagedDrag
Definition: SCR_WheelHitZone.c:24
GetHitZoneGroup
override EHitZoneGroup GetHitZoneGroup()
Definition: SCR_WheelHitZone.c:51
SCR_VehicleHitZone
Definition: SCR_VehicleHitZone.c:1
Attribute
enum SCR_EWheelDamageState EDamageState Attribute(defvalue:"-1", uiwidget:UIWidgets.Auto, desc:"Wheel ID", category:"Wheel Damage")] protected int m_iWheelId
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
OnInit
override void OnInit(IEntity pOwnerEntity, GenericComponent pManagerComponent)
Definition: SCR_WheelHitZone.c:42
m_fDamagedRoughnessIncrease
protected float m_fDamagedRoughnessIncrease
Definition: SCR_WheelHitZone.c:21
index
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Definition: SCR_DestructionSynchronizationComponent.c:17
SCR_EWheelDamageState
SCR_EWheelDamageState
Definition: SCR_WheelHitZone.c:1
OnDamageStateChanged
override void OnDamageStateChanged()
Definition: SCR_WheelHitZone.c:57
m_fDestroyedLateralFrictionScale
protected float m_fDestroyedLateralFrictionScale
Definition: SCR_WheelHitZone.c:33
PlayDestructionSound
override void PlayDestructionSound(EDamageState damageState)
Definition: SCR_WheelHitZone.c:212
m_fDestroyedRadiusScale
protected float m_fDestroyedRadiusScale
Definition: SCR_WheelHitZone.c:27
GetEfficiency
float GetEfficiency()
Definition: SCR_WheelHitZone.c:283
m_fDamagedLongitudinalFrictionScale
protected float m_fDamagedLongitudinalFrictionScale
Definition: SCR_WheelHitZone.c:15
UpdateDamageSignal
protected void UpdateDamageSignal()
Definition: SCR_WheelHitZone.c:190
SetWheelIndex
void SetWheelIndex(int index)
Definition: SCR_WheelHitZone.c:74
WakeUpPhysics
void WakeUpPhysics()
Wake physics up.
Definition: SCR_WheelHitZone.c:262
GetWheelIndex
int GetWheelIndex()
Definition: SCR_WheelHitZone.c:67
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180