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_DestructionBaseHandler.c
Go to the documentation of this file.
1
#define ENABLE_BASE_DESTRUCTION
2
//------------------------------------------------------------------------------------------------
6
[
BaseContainerProps
()]
7
class
SCR_DestructionBaseHandler
8
{
9
[
Attribute
(
""
,
UIWidgets
.ResourceNamePicker,
desc
:
"Model to swap to on destruction"
,
params
:
"xob et"
)]
10
protected
ResourceName
m_sWreckModel
;
11
12
[
Attribute
(
"1"
,
UIWidgets
.Slider,
desc
:
"Delay for the wreck model switch upon destruction (ms)"
,
params
:
"1 10000 1"
)]
13
protected
int
m_iWreckDelay
;
14
15
[
Attribute
(
"100"
,
UIWidgets
.Slider,
desc
:
"Default mass of the wreck physics, to be set if the part did not have physics before destruction"
,
params
:
"0 10000 1"
)]
16
protected
float
m_fDefaultWreckMass
;
17
18
[
Attribute
(
"0"
,
UIWidgets
.CheckBox,
"If true the part will detach from parent after hitzone is destroyed"
)]
19
protected
bool
m_bDetachAfterDestroyed
;
20
21
[
Attribute
(
"1"
,
UIWidgets
.CheckBox,
"If true the part will be hidden after it is destroyed, unless wreck model is provided"
)]
22
protected
bool
m_bAllowHideWreck
;
23
24
[
Attribute
(
"1"
,
UIWidgets
.CheckBox,
"If true and not detached the part will be deleted after parent entity is destroyed"
)]
25
protected
bool
m_bDeleteAfterParentDestroyed
;
26
27
[
Attribute
(
"0"
,
UIWidgets
.CheckBox,
"If true the physics will be disabled after hitzone is destroyed"
)]
28
protected
bool
m_bDisablePhysicsAfterDestroyed
;
29
30
[
Attribute
(
"0"
,
UIWidgets
.CheckBox,
"If true and this entity doesnt have a parent then it will be permanently deleted"
)]
31
protected
bool
m_bDeleteAfterDestroyed
;
32
#ifdef ENABLE_BASE_DESTRUCTION
33
34
protected
IEntity
m_pOwner
;
// TODO: Remove once we can get the owner dynamically
35
protected
bool
m_bIsDestructionDelayed
;
36
37
//------------------------------------------------------------------------------------------------
39
void
StartDestruction
(
bool
immediate =
false
)
40
{
41
if
(immediate)
42
{
43
if
(
m_bIsDestructionDelayed
)
44
GetGame
().GetCallqueue().Remove(
StartDestruction
);
45
46
// Delegation is only allowed through destruction manager, ensuring the event will always be triggered inside frame
47
// This includes deletion, physics deactivation, deletion
48
SCR_MPDestructionManager
destructionManager =
SCR_MPDestructionManager
.
GetInstance
();
49
if
(destructionManager)
50
destructionManager.
DestroyInFrame
(
this
);
51
else
52
Debug
.DPrint(
"SCR_MPDestructionManager is missing, cannot perform DestroyInFrame"
);
53
54
return
;
55
}
56
57
if
(!
m_bIsDestructionDelayed
)
58
{
59
m_bIsDestructionDelayed
=
true
;
60
61
// The delay allows for particle effects to envelop vehicle before it is transformed to wreck.
62
// CallLater is used as a simple measure to delay that operation
63
GetGame
().GetCallqueue().CallLater(
StartDestruction
,
m_iWreckDelay
,
param1
:
true
);
64
}
65
}
66
67
//------------------------------------------------------------------------------------------------
69
void
OnRepair
()
70
{
71
if
(!
m_pOwner
||
m_pOwner
.IsDeleted())
72
return
;
73
74
ResourceName
object
=
SCR_Global
.
GetPrefabAttributeResource
(
m_pOwner
,
"MeshObject"
,
"Object"
);
75
SetModel
(
object
);
76
77
// Some objects have no valid destruction physics
78
if
(!
m_bDisablePhysicsAfterDestroyed
)
79
return
;
80
81
m_pOwner
.SetFlags(
EntityFlags
.TRACEABLE,
false
);
82
83
Physics
physics =
m_pOwner
.GetPhysics();
84
if
(!physics)
85
return
;
86
87
// Set proper physics simulation state for slotted entities, use just collision physics.
88
if
(
m_pOwner
.GetParent())
89
physics.ChangeSimulationState(
SimulationState
.COLLISION);
90
else
91
physics.ChangeSimulationState(
SimulationState
.SIMULATION);
92
}
93
94
//------------------------------------------------------------------------------------------------
97
void
HandleDestruction
()
98
{
99
m_bIsDestructionDelayed
=
false
;
100
101
if
(!
m_pOwner
||
m_pOwner
.IsDeleted())
102
return
;
103
104
IEntity
parent =
m_pOwner
.GetParent();
105
if
(parent && parent.
IsDeleted
())
106
return
;
107
108
// Destroy all children slotted entities
109
array<EntitySlotInfo> slotInfos = {};
110
EntitySlotInfo
.GetSlotInfos(
m_pOwner
, slotInfos);
111
IEntity
slotEntity;
112
SCR_DamageManagerComponent damageMgr;
113
HitZone
hitZone;
114
foreach
(
EntitySlotInfo
slotInfo : slotInfos)
115
{
116
if
(!slotInfo)
117
continue
;
118
119
slotEntity = slotInfo.GetAttachedEntity();
120
if
(!slotEntity)
121
continue
;
122
123
if
(slotEntity.
IsDeleted
())
124
continue
;
125
126
damageMgr = SCR_DamageManagerComponent.GetDamageManager(slotEntity);
127
if
(!damageMgr)
128
continue
;
129
130
hitZone = damageMgr.GetDefaultHitZone();
131
132
if
(damageMgr.GetState() ==
EDamageState
.DESTROYED)
133
{
134
SCR_DestructibleHitzone
destructibleHitZone =
SCR_DestructibleHitzone
.Cast(hitZone);
135
if
(destructibleHitZone)
136
destructibleHitZone.
StartDestruction
(
true
);
137
}
138
else
139
{
140
hitZone.SetHealth(0);
141
}
142
}
143
144
// Check parent only if the part is not set to be deleted anyway
145
if
(
m_bDeleteAfterParentDestroyed
&& parent)
146
{
147
HitZoneContainerComponent
parentContainer =
HitZoneContainerComponent
.Cast(parent.
FindComponent
(
HitZoneContainerComponent
));
148
if
(parentContainer && parentContainer.GetDefaultHitZone() && parentContainer.GetDefaultHitZone().GetDamageState() ==
EDamageState
.DESTROYED)
149
{
150
DeleteSelf();
151
return
;
152
}
153
}
154
155
if
(
m_bDeleteAfterDestroyed
)
156
{
157
DeleteSelf();
158
return
;
159
}
160
161
if
(
m_bAllowHideWreck
|| !
m_sWreckModel
.IsEmpty())
162
SetModel
(
m_sWreckModel
,
m_bAllowHideWreck
);
163
164
if
(
m_bDetachAfterDestroyed
)
165
DetachFromParent(
true
);
166
167
// Some objects have no valid destruction physics
168
if
(!
m_bDisablePhysicsAfterDestroyed
)
169
return
;
170
171
m_pOwner
.ClearFlags(
EntityFlags
.TRACEABLE,
false
);
172
173
Physics
physics =
m_pOwner
.GetPhysics();
174
if
(physics)
175
physics.ChangeSimulationState(
SimulationState
.NONE);
176
}
177
178
//------------------------------------------------------------------------------------------------
181
private
void
DetachFromParent(
bool
updateHierarchy)
182
{
183
if
(!
m_pOwner
||
m_pOwner
.
IsDeleted
())
184
return
;
185
186
IEntity
parent =
m_pOwner
.
GetParent
();
187
if
(!parent || parent.
IsDeleted
())
188
return
;
189
190
Physics
physics =
m_pOwner
.
GetPhysics
();
191
if
(!physics)
192
return
;
193
194
vector
velocity = physics.GetVelocity();
195
vector
angularVelocity = physics.GetAngularVelocity();
196
197
EntitySlotInfo
slotInfo =
EntitySlotInfo
.GetSlotInfo(
m_pOwner
);
198
if
(slotInfo)
199
slotInfo.DetachEntity(updateHierarchy);
200
201
if
(physics.IsDynamic() && !
m_pOwner
.
GetParent
())
202
{
203
physics.SetVelocity(velocity);
204
physics.SetAngularVelocity(angularVelocity);
205
}
206
}
207
208
//------------------------------------------------------------------------------------------------
210
void
DeleteSelf()
211
{
212
if
(!
m_pOwner
||
m_pOwner
.IsDeleted())
213
return
;
214
215
if
(
m_pOwner
.GetParent())
216
DetachFromParent(
false
);
217
218
m_pOwner
.SetObject(null,
string
.Empty);
219
RplComponent.DeleteRplEntity(
m_pOwner
,
true
);
220
}
221
222
//------------------------------------------------------------------------------------------------
227
protected
void
SetModel
(
ResourceName
modelName,
bool
allowEmpty =
false
)
228
{
229
if
(!
m_pOwner
||
m_pOwner
.IsDeleted())
230
return
;
231
232
Vehicle
vehicle =
Vehicle
.Cast(
m_pOwner
);
233
if
(vehicle)
234
{
235
vehicle.SetWreckModel(modelName);
236
SCR_BaseEffectManagerComponent
effectComp =
SCR_BaseEffectManagerComponent
.Cast(vehicle.FindComponent(
SCR_BaseEffectManagerComponent
));
237
if
(effectComp)
238
effectComp.Deactivate(vehicle);
239
}
240
else
241
{
242
Resource
resource =
Resource
.Load(modelName);
243
VObject
model;
244
if
(resource && resource.IsValid())
245
model = resource.GetResource().ToVObject();
246
247
if
(model || allowEmpty)
248
m_pOwner
.SetObject(model,
string
.Empty);
249
}
250
251
m_pOwner
.Update();
252
253
// If there is no model, ignore the rest
254
Physics
physics =
m_pOwner
.GetPhysics();
255
if
(!physics)
256
return
;
257
258
// If the object has dynamic physics, pass the state
259
float
mass = physics.GetMass();
260
if
(mass == 0)
261
mass =
m_fDefaultWreckMass
;
262
263
if
(physics.UpdateGeometries())
264
{
265
physics.SetActive(
ActiveState
.ACTIVE);
266
physics.EnableGravity(
true
);
267
m_pOwner
.SetFlags(
EntityFlags
.TRACEABLE);
268
}
269
else
270
{
271
physics.ChangeSimulationState(
SimulationState
.NONE);
272
m_pOwner
.ClearFlags(
EntityFlags
.TRACEABLE);
273
}
274
}
275
276
//------------------------------------------------------------------------------------------------
277
void
Init
(
IEntity
owner,
HitZone
hitZone)
278
{
279
m_pOwner
= owner;
280
}
281
#endif
282
}
GetGame
ArmaReforgerScripted GetGame()
Definition
game.c:1398
BaseContainerProps
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
Definition
SCR_AIAnimationWaypoint.c:14
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition
SCR_RespawnBriefingComponent.c:17
params
category params
Definition
SCR_SpherePointGeneratorPreviewComponent.c:21
Debug
Definition
Debug.c:13
EntitySlotInfo
Adds ability to attach an object to a slot.
Definition
EntitySlotInfo.c:9
HitZoneContainerComponent
Definition
HitZoneContainerComponent.c:13
HitZone
Definition
HitZone.c:13
IEntity
Definition
IEntity.c:13
IEntity::FindComponent
proto external Managed FindComponent(typename typeName)
IEntity::GetPhysics
proto external Physics GetPhysics()
IEntity::GetParent
proto external IEntity GetParent()
IEntity::IsDeleted
proto external bool IsDeleted()
Physics
Definition
Physics.c:22
Resource
Object holding reference to resource. In destructor release the resource.
Definition
Resource.c:25
ResourceName
Definition
ResourceName.c:13
SCR_BaseEffectManagerComponent
Definition
SCR_BaseEffectManagerComponent.c:12
SCR_DestructibleHitzone
Definition
SCR_DestructibleHitzone.c:5
SCR_DestructibleHitzone::StartDestruction
void StartDestruction(bool immediate=false)
Start destruction effects.
Definition
SCR_DestructibleHitzone.c:106
SCR_DestructionBaseHandler
Definition
SCR_DestructionBaseHandler.c:8
SCR_DestructionBaseHandler::m_bDeleteAfterDestroyed
bool m_bDeleteAfterDestroyed
Definition
SCR_DestructionBaseHandler.c:31
SCR_DestructionBaseHandler::HandleDestruction
void HandleDestruction()
Definition
SCR_DestructionBaseHandler.c:97
SCR_DestructionBaseHandler::m_fDefaultWreckMass
float m_fDefaultWreckMass
Definition
SCR_DestructionBaseHandler.c:16
SCR_DestructionBaseHandler::StartDestruction
void StartDestruction(bool immediate=false)
Destroy.
Definition
SCR_DestructionBaseHandler.c:39
SCR_DestructionBaseHandler::m_sWreckModel
ResourceName m_sWreckModel
Definition
SCR_DestructionBaseHandler.c:10
SCR_DestructionBaseHandler::m_iWreckDelay
int m_iWreckDelay
Definition
SCR_DestructionBaseHandler.c:13
SCR_DestructionBaseHandler::Init
void Init(IEntity owner, HitZone hitZone)
Definition
SCR_DestructionBaseHandler.c:277
SCR_DestructionBaseHandler::m_bDeleteAfterParentDestroyed
bool m_bDeleteAfterParentDestroyed
Definition
SCR_DestructionBaseHandler.c:25
SCR_DestructionBaseHandler::m_pOwner
IEntity m_pOwner
Definition
SCR_DestructionBaseHandler.c:34
SCR_DestructionBaseHandler::m_bDetachAfterDestroyed
bool m_bDetachAfterDestroyed
Definition
SCR_DestructionBaseHandler.c:19
SCR_DestructionBaseHandler::m_bDisablePhysicsAfterDestroyed
bool m_bDisablePhysicsAfterDestroyed
Definition
SCR_DestructionBaseHandler.c:28
SCR_DestructionBaseHandler::m_bAllowHideWreck
bool m_bAllowHideWreck
Definition
SCR_DestructionBaseHandler.c:22
SCR_DestructionBaseHandler::OnRepair
void OnRepair()
Revert model back to default.
Definition
SCR_DestructionBaseHandler.c:69
SCR_DestructionBaseHandler::SetModel
void SetModel(ResourceName modelName, bool allowEmpty=false)
Definition
SCR_DestructionBaseHandler.c:227
SCR_DestructionBaseHandler::m_bIsDestructionDelayed
bool m_bIsDestructionDelayed
Definition
SCR_DestructionBaseHandler.c:35
SCR_Global
Definition
Functions.c:7
SCR_Global::GetPrefabAttributeResource
static ResourceName GetPrefabAttributeResource(notnull IEntity entity, string containerType, string attributeName)
Definition
Functions.c:1953
SCR_MPDestructionManager
Definition
SCR_MPDestructionManager.c:104
SCR_MPDestructionManager::DestroyInFrame
void DestroyInFrame(SCR_DestructionBaseHandler handler)
Definition
SCR_MPDestructionManager.c:177
SCR_MPDestructionManager::GetInstance
static SCR_MPDestructionManager GetInstance()
Returns the instance of the destruction manager.
Definition
SCR_MPDestructionManager.c:151
UIWidgets
Definition
attributes.c:40
VObject
Visual object.
Definition
VObject.c:14
vector
Definition
vector.c:13
Vehicle
enum EPhysicsLayerPresets Vehicle
Definition
gameLib.c:24
Attribute
SCR_FieldOfViewSettings Attribute
Definition
SendGoalMessage.c:170
EntityFlags
EntityFlags
Various entity flags.
Definition
EntityFlags.c:14
EDamageState
EDamageState
Definition
EDamageState.c:13
SimulationState
SimulationState
Definition
SimulationState.c:19
ActiveState
ActiveState
Definition
ActiveState.c:16
param1
Tuple param1
scripts
Game
Destruction
SCR_DestructionBaseHandler.c
Generated by
1.17.0