Arma Reforger Explorer
1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Toggle main menu visibility
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
3
enum
SCR_EWheelDamageState
:
EDamageState
4
{
5
PUNCTURED
= 3
6
}
7
//---- REFACTOR NOTE END ----
8
9
class
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"
)]
18
protected
float
m_fDamagedLongitudinalFrictionScale
;
19
20
[
Attribute
( defvalue:
"0.4"
, uiwidget:
UIWidgets
.Auto,
desc
:
"Lateral friction multiplier for a damaged wheel."
,
category
:
"Wheel Damage"
)]
21
protected
float
m_fDamagedLateralFrictionScale
;
22
23
[
Attribute
( defvalue:
"1.5"
, uiwidget:
UIWidgets
.Auto,
desc
:
"Roughness increase for a damaged wheel."
,
category
:
"Wheel Damage"
)]
24
protected
float
m_fDamagedRoughnessIncrease
;
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"
)]
33
protected
float
m_fDestroyedLongitudinalFrictionScale
;
34
35
[
Attribute
( defvalue:
"0.2"
, uiwidget:
UIWidgets
.Auto,
desc
:
"Lateral friction multiplier for a destroyed wheel."
,
category
:
"Wheel Damage"
)]
36
protected
float
m_fDestroyedLateralFrictionScale
;
37
38
[
Attribute
( defvalue:
"3.0"
, uiwidget:
UIWidgets
.Auto,
desc
:
"Roughness increase for a destroyed wheel."
,
category
:
"Wheel Damage"
)]
39
protected
float
m_fDestroyedRoughnessIncrease
;
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
49
UpdateWheelState
();
50
UpdateDamageSignal
();
51
}
52
53
//------------------------------------------------------------------------------------------------
54
override
EHitZoneGroup
GetHitZoneGroup
()
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
64
UpdateWheelState
();
65
UpdateDamageSignal
()
66
}
67
68
//------------------------------------------------------------------------------------------------
70
int
GetWheelIndex
()
71
{
72
return
m_iWheelId;
73
}
74
75
//------------------------------------------------------------------------------------------------
77
void
SetWheelIndex
(
int
index
)
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
86
UpdateWheelState
();
87
UpdateDamageSignal
();
88
}
89
90
//------------------------------------------------------------------------------------------------
92
void
UpdateWheelState
()
93
{
94
if
(m_iWheelId == -1)
95
return
;
96
97
IEntity
owner =
GetOwner
();
98
99
IEntity
parent =
SCR_EntityHelper
.
GetMainParent
(owner,
true
);
100
101
VehicleWheeledSimulation
simulation =
VehicleWheeledSimulation
.Cast(parent.
FindComponent
(
VehicleWheeledSimulation
));
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
;
120
roughness +=
m_fDestroyedRoughnessIncrease
;
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
154
IEntity
parent =
SCR_EntityHelper
.
GetMainParent
(
GetOwner
(),
true
);
155
if
(!parent)
156
return
;
157
158
// Set TireDamage signal
159
float
damageState = GetDamageState();
160
161
SignalsManagerComponent
signalManager =
SignalsManagerComponent
.Cast(parent.
FindComponent
(
SignalsManagerComponent
));
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
//------------------------------------------------------------------------------------------------
223
void
WakeUpPhysics
()
224
{
225
IEntity
parent =
SCR_EntityHelper
.
GetMainParent
(
GetOwner
(),
true
);
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
//------------------------------------------------------------------------------------------------
245
float
GetEfficiency
()
246
{
247
return
GetDamageStateThreshold(GetDamageState());
248
}
249
}
EHitZoneGroup
EHitZoneGroup
Definition
EHitZoneGroup.c:2
m_eHitZoneGroup
ECharacterHitZoneGroup m_eHitZoneGroup
Definition
SCR_CharacterHitZone.c:184
index
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Definition
SCR_DestructionSynchronizationComponent.c:17
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition
SCR_RespawnBriefingComponent.c:17
m_RootDamageManager
SCR_VehicleDamageManagerComponent m_RootDamageManager
Definition
SCR_RotorDamageManagerComponent.c:8
GetEfficiency
float GetEfficiency()
Set wheel parameters when damage exceeds thresholds.
Definition
SCR_RotorHitZone.c:138
category
params category
Definition
SCR_VehicleDamageManagerComponent.c:302
m_fDestroyedLateralFrictionScale
float m_fDestroyedLateralFrictionScale
Definition
SCR_WheelHitZone.c:36
WakeUpPhysics
void WakeUpPhysics()
Wake physics up.
Definition
SCR_WheelHitZone.c:223
m_fDamagedRoughnessIncrease
float m_fDamagedRoughnessIncrease
Definition
SCR_WheelHitZone.c:24
m_fDamagedDrag
float m_fDamagedDrag
Definition
SCR_WheelHitZone.c:27
SetWheelIndex
void SetWheelIndex(int index)
Definition
SCR_WheelHitZone.c:77
m_fDamagedRadiusScale
float m_fDamagedRadiusScale
Definition
SCR_WheelHitZone.c:15
SCR_EWheelDamageState
SCR_EWheelDamageState
Definition
SCR_WheelHitZone.c:4
PUNCTURED
PUNCTURED
Definition
SCR_WheelHitZone.c:0
m_fDestroyedDrag
float m_fDestroyedDrag
Definition
SCR_WheelHitZone.c:42
m_fDestroyedRoughnessIncrease
float m_fDestroyedRoughnessIncrease
Definition
SCR_WheelHitZone.c:39
UpdateDamageSignal
void UpdateDamageSignal()
Definition
SCR_WheelHitZone.c:149
m_fDamagedLongitudinalFrictionScale
float m_fDamagedLongitudinalFrictionScale
Definition
SCR_WheelHitZone.c:18
GetWheelIndex
int GetWheelIndex()
Definition
SCR_WheelHitZone.c:70
m_fDestroyedLongitudinalFrictionScale
float m_fDestroyedLongitudinalFrictionScale
Definition
SCR_WheelHitZone.c:33
UpdateWheelState
void UpdateWheelState()
Set wheel parameters when damage exceeds thresholds.
Definition
SCR_WheelHitZone.c:92
m_fDestroyedRadiusScale
float m_fDestroyedRadiusScale
Definition
SCR_WheelHitZone.c:30
m_fDamagedLateralFrictionScale
float m_fDamagedLateralFrictionScale
Definition
SCR_WheelHitZone.c:21
GenericComponent
Definition
GenericComponent.c:13
IEntity
Definition
IEntity.c:13
IEntity::FindComponent
proto external Managed FindComponent(typename typeName)
IEntity::GetPhysics
proto external Physics GetPhysics()
IEntity::CoordToParent
proto external vector CoordToParent(vector coord)
IEntity::CoordToLocal
proto external vector CoordToLocal(vector coord)
Physics
Definition
Physics.c:22
SCR_DestructibleHitzone::PlayDestructionSound
void PlayDestructionSound(EDamageState damageState)
Start destruction sounds.
Definition
SCR_DestructibleHitzone.c:237
SCR_DestructibleHitzone::OnDamageStateChanged
override void OnDamageStateChanged(EDamageState newState, EDamageState previousDamageState, bool isJIP)
Kill occupants and start destruction.
Definition
SCR_DestructibleHitzone.c:77
SCR_EntityHelper
Definition
SCR_EntityHelper.c:2
SCR_EntityHelper::GetMainParent
static IEntity GetMainParent(IEntity entity, bool self=false)
Definition
SCR_EntityHelper.c:325
SCR_HitZone::GetOwner
IEntity GetOwner()
Definition
SCR_HitZone.c:42
SCR_SoundEvent
Definition
SCR_SoundEvent.c:2
SCR_VehicleHitZone
Definition
SCR_VehicleHitZone.c:2
SCR_VehicleHitZone::GetHitZoneGroup
override EHitZoneGroup GetHitZoneGroup()
Definition
SCR_VehicleHitZone.c:7
SignalsManagerComponent
Definition
SignalsManagerComponent.c:13
SoundComponent
Definition
SoundComponent.c:13
UIWidgets
Definition
attributes.c:40
VehicleWheeledSimulation
Definition
VehicleWheeledSimulation.c:13
vector
Definition
vector.c:13
Attribute
SCR_FieldOfViewSettings Attribute
Definition
SendGoalMessage.c:170
EDamageState
EDamageState
Definition
EDamageState.c:13
OnInit
@ OnInit
Definition
SndComponentCallbacks.c:17
scripts
Game
HitZone
SCR_WheelHitZone.c
Generated by
1.17.0