Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_WheelHitZone.c
Go to the documentation of this file.
1//---- REFACTOR NOTE START: This code will need to be refactored as current implementation is not conforming to the standards ----
2// TODO: Separate file
7//---- REFACTOR NOTE END ----
8
9class SCR_WheelHitZone : SCR_VehicleHitZone
10{
11 [Attribute( defvalue: "-1", uiwidget: UIWidgets.Auto, desc: "Wheel ID", category: "Wheel Damage")]
12 protected int m_iWheelId;
13
14 [Attribute( defvalue: "0.9", uiwidget: UIWidgets.Auto, desc: "Radius multiplier for a damaged wheel.", category: "Wheel Damage")]
15 protected float m_fDamagedRadiusScale;
16
17 [Attribute( defvalue: "0.4", uiwidget: UIWidgets.Auto, desc: "Longitudinal friction multiplier for a damaged wheel.", category: "Wheel Damage")]
19
20 [Attribute( defvalue: "0.4", uiwidget: UIWidgets.Auto, desc: "Lateral friction multiplier for a damaged wheel.", category: "Wheel Damage")]
22
23 [Attribute( defvalue: "1.5", uiwidget: UIWidgets.Auto, desc: "Roughness increase for a damaged wheel.", category: "Wheel Damage")]
25
26 [Attribute( defvalue: "0.1", uiwidget: UIWidgets.Auto, desc: "Drag of a damaged wheel.", category: "Wheel Damage")]
27 protected float m_fDamagedDrag;
28
29 [Attribute( defvalue: "0.8", uiwidget: UIWidgets.Auto, desc: "Radius multiplier for a destroyed wheel.", category: "Wheel Damage")]
30 protected float m_fDestroyedRadiusScale;
31
32 [Attribute( defvalue: "0.2", uiwidget: UIWidgets.Auto, desc: "Longitudinal friction multiplier for a destroyed wheel.", category: "Wheel Damage")]
34
35 [Attribute( defvalue: "0.2", uiwidget: UIWidgets.Auto, desc: "Lateral friction multiplier for a destroyed wheel.", category: "Wheel Damage")]
37
38 [Attribute( defvalue: "3.0", uiwidget: UIWidgets.Auto, desc: "Roughness increase for a destroyed wheel.", category: "Wheel Damage")]
40
41 [Attribute( defvalue: "1.0", uiwidget: UIWidgets.Auto, desc: "Drag of a destroyed wheel.", category: "Wheel Damage")]
42 protected float m_fDestroyedDrag;
43
44 //------------------------------------------------------------------------------------------------
45 override void OnInit(IEntity pOwnerEntity, GenericComponent pManagerComponent)
46 {
47 super.OnInit(pOwnerEntity, pManagerComponent);
48
51 }
52
53 //------------------------------------------------------------------------------------------------
55 {
56 return m_eHitZoneGroup;
57 }
58
59 //------------------------------------------------------------------------------------------------
60 override void OnDamageStateChanged(EDamageState newState, EDamageState previousDamageState, bool isJIP)
61 {
62 super.OnDamageStateChanged(newState, previousDamageState, isJIP);
63
66 }
67
68 //------------------------------------------------------------------------------------------------
71 {
72 return m_iWheelId;
73 }
74
75 //------------------------------------------------------------------------------------------------
78 {
79 m_iWheelId = index;
80
81 // Notify the relevant damage manager if present
82 SCR_WheeledDamageManagerComponent damageManager = SCR_WheeledDamageManagerComponent.Cast(m_RootDamageManager);
83 if (damageManager)
84 damageManager.RegisterVehicleHitZone(this);
85
88 }
89
90 //------------------------------------------------------------------------------------------------
93 {
94 if (m_iWheelId == -1)
95 return;
96
97 IEntity owner = GetOwner();
98
99 IEntity parent = SCR_EntityHelper.GetMainParent(owner, true);
100
102 if (!simulation || !simulation.IsValid() || m_iWheelId >= simulation.WheelCount())
103 return;
104
105 // Update simulation
106 float previousRadius = simulation.WheelGetRadiusState(m_iWheelId);
107 float radius = simulation.WheelGetRadius(m_iWheelId);
108 float longitudinalFriction = simulation.WheelTyreGetLongitudinalFriction(m_iWheelId);
109 float lateralFriction = simulation.WheelTyreGetLateralFriction(m_iWheelId);
110 float roughness = simulation.WheelTyreGetRoughness(m_iWheelId);
111 float drag;
112
113 // Only run the rest of code if state has changed
114 SCR_EWheelDamageState state = GetDamageState();
115 if (state == SCR_EWheelDamageState.DESTROYED)
116 {
117 radius *= m_fDestroyedRadiusScale;
118 longitudinalFriction *= m_fDestroyedLongitudinalFrictionScale;
119 lateralFriction *= m_fDestroyedLateralFrictionScale;
121 drag = m_fDestroyedDrag;
122 }
123 else if (state == SCR_EWheelDamageState.PUNCTURED)
124 {
125 radius *= m_fDamagedRadiusScale;
126 longitudinalFriction *= m_fDamagedLongitudinalFrictionScale;
127 lateralFriction *= m_fDamagedLateralFrictionScale;
128 roughness += m_fDamagedRoughnessIncrease;
129 drag = m_fDamagedDrag;
130 }
131
132 simulation.WheelSetRadiusState(m_iWheelId, radius);
133 simulation.WheelTyreSetLongitudinalFrictionState(m_iWheelId, longitudinalFriction);
134 simulation.WheelTyreSetLateralFrictionState(m_iWheelId, lateralFriction);
135 simulation.WheelTyreSetRoughnessState(m_iWheelId, roughness);
136 simulation.WheelSetRollingDrag(m_iWheelId, drag);
137
138 // Need to wake physics up when wheel becomes destroyed
139 if (!float.AlmostEqual(radius, previousRadius))
140 WakeUpPhysics();
141
142 // Notify the relevant damage manager if present
143 SCR_WheeledDamageManagerComponent damageManager = SCR_WheeledDamageManagerComponent.Cast(m_RootDamageManager);
144 if (damageManager)
145 damageManager.UpdateVehicleState();
146 }
147
148 //------------------------------------------------------------------------------------------------
149 protected void UpdateDamageSignal()
150 {
151 if (m_iWheelId == -1)
152 return;
153
155 if (!parent)
156 return;
157
158 // Set TireDamage signal
159 float damageState = GetDamageState();
160
162 if (signalManager)
163 {
164 int damageSignal = signalManager.AddOrFindSignal("TireDamage" + m_iWheelId.ToString());
165 if (damageSignal != -1)
166 signalManager.SetSignalValue(damageSignal, damageState);
167 }
168 }
169
170 //------------------------------------------------------------------------------------------------
171 override void PlayDestructionSound(EDamageState damageState)
172 {
173 SCR_EWheelDamageState pDS = GetPreviousDamageState();
174
175 if (pDS <= SCR_EWheelDamageState.INTERMEDIARY && damageState >= SCR_EWheelDamageState.DESTROYED)
176 {
177 IEntity owner = GetOwner();
178
179 IEntity parent = SCR_EntityHelper.GetMainParent(owner, true);
180 if (!parent)
181 return;
182
183 SoundComponent soundComponent = SoundComponent.Cast(parent.FindComponent(SoundComponent));
184 Physics physics = owner.GetPhysics();
185 if (!physics || !soundComponent)
186 return;
187
188 vector offset;
189 if (!HasColliderNodes())
190 {
191 // Use center of mass of whole entity
192 offset = physics.GetCenterOfMass();
193 offset = owner.CoordToParent(offset);
194 }
195 else
196 {
197 // Get collider geometry
198 int colliderID = -1;
199 array<string> colliderNames = {};
200 GetAllColliderNames(colliderNames);
201 foreach (string colliderName: colliderNames)
202 {
203 colliderID = physics.GetGeom(colliderNames[0]);
204 if (colliderID != -1)
205 break;
206 }
207
208 if (colliderID == -1)
209 return;
210
211 offset = physics.GetGeomWorldPosition(colliderID);
212 }
213
214 offset = parent.CoordToLocal(offset);
215 soundComponent.SoundEventOffset(SCR_SoundEvent.SOUND_TIRE_PUNCTURE, offset);
216 }
217 }
218
219 //---- REFACTOR NOTE START: This code will need to be refactored as current implementation is not conforming to the standards ----
220 // TODO: Move as static to SCR_PhysicsHelper
221 //------------------------------------------------------------------------------------------------
224 {
226 Physics physics = parent.GetPhysics();
227 if (!physics)
228 return;
229
230 if (!physics.IsDynamic())
231 return;
232
233 if (physics.IsActive())
234 return;
235
236 vector centerOfMass = physics.GetCenterOfMass();
237 float force = 0.01 * physics.GetMass();
238 physics.ApplyImpulseAt(centerOfMass, vector.Up * force);
239 physics.ApplyImpulseAt(centerOfMass, vector.Up * -force);
240 }
241 //---- REFACTOR NOTE END ----
242
243 //------------------------------------------------------------------------------------------------
246 {
247 return GetDamageStateThreshold(GetDamageState());
248 }
249}
EHitZoneGroup
ECharacterHitZoneGroup m_eHitZoneGroup
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
SCR_VehicleDamageManagerComponent m_RootDamageManager
float GetEfficiency()
Set wheel parameters when damage exceeds thresholds.
float m_fDestroyedLateralFrictionScale
void WakeUpPhysics()
Wake physics up.
float m_fDamagedRoughnessIncrease
float m_fDamagedDrag
void SetWheelIndex(int index)
float m_fDamagedRadiusScale
SCR_EWheelDamageState
PUNCTURED
float m_fDestroyedDrag
float m_fDestroyedRoughnessIncrease
void UpdateDamageSignal()
float m_fDamagedLongitudinalFrictionScale
int GetWheelIndex()
float m_fDestroyedLongitudinalFrictionScale
void UpdateWheelState()
Set wheel parameters when damage exceeds thresholds.
float m_fDestroyedRadiusScale
float m_fDamagedLateralFrictionScale
proto external Managed FindComponent(typename typeName)
proto external Physics GetPhysics()
proto external vector CoordToParent(vector coord)
proto external vector CoordToLocal(vector coord)
void PlayDestructionSound(EDamageState damageState)
Start destruction sounds.
override void OnDamageStateChanged(EDamageState newState, EDamageState previousDamageState, bool isJIP)
Kill occupants and start destruction.
static IEntity GetMainParent(IEntity entity, bool self=false)
IEntity GetOwner()
Definition SCR_HitZone.c:42
override EHitZoneGroup GetHitZoneGroup()
SCR_FieldOfViewSettings Attribute
EDamageState