Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_DestructionBaseHandler.c
Go to the documentation of this file.
1#define ENABLE_BASE_DESTRUCTION
2//------------------------------------------------------------------------------------------------
8{
9 [Attribute("", UIWidgets.ResourceNamePicker, desc: "Model to swap to on destruction", params: "xob et")]
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")]
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")]
26
27 [Attribute("0", UIWidgets.CheckBox, "If true the physics will be disabled after hitzone is destroyed")]
29
30 [Attribute("0", UIWidgets.CheckBox, "If true and this entity doesnt have a parent then it will be permanently deleted")]
32#ifdef ENABLE_BASE_DESTRUCTION
33
34 protected IEntity m_pOwner; // TODO: Remove once we can get the owner dynamically
36
37 //------------------------------------------------------------------------------------------------
39 void StartDestruction(bool immediate = false)
40 {
41 if (immediate)
42 {
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
49 if (destructionManager)
50 destructionManager.DestroyInFrame(this);
51 else
52 Debug.DPrint("SCR_MPDestructionManager is missing, cannot perform DestroyInFrame");
53
54 return;
55 }
56
58 {
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
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 //------------------------------------------------------------------------------------------------
98 {
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 {
148 if (parentContainer && parentContainer.GetDefaultHitZone() && parentContainer.GetDefaultHitZone().GetDamageState() == EDamageState.DESTROYED)
149 {
150 DeleteSelf();
151 return;
152 }
153 }
154
156 {
157 DeleteSelf();
158 return;
159 }
160
161 if (m_bAllowHideWreck || !m_sWreckModel.IsEmpty())
163
165 DetachFromParent(true);
166
167 // Some objects have no valid destruction physics
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);
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}
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition Debug.c:13
Adds ability to attach an object to a slot.
proto external Managed FindComponent(typename typeName)
proto external Physics GetPhysics()
proto external IEntity GetParent()
proto external bool IsDeleted()
Object holding reference to resource. In destructor release the resource.
Definition Resource.c:25
void StartDestruction(bool immediate=false)
Start destruction effects.
void StartDestruction(bool immediate=false)
Destroy.
void Init(IEntity owner, HitZone hitZone)
void OnRepair()
Revert model back to default.
void SetModel(ResourceName modelName, bool allowEmpty=false)
static ResourceName GetPrefabAttributeResource(notnull IEntity entity, string containerType, string attributeName)
Definition Functions.c:1953
void DestroyInFrame(SCR_DestructionBaseHandler handler)
static SCR_MPDestructionManager GetInstance()
Returns the instance of the destruction manager.
Visual object.
Definition VObject.c:14
enum EPhysicsLayerPresets Vehicle
Definition gameLib.c:24
SCR_FieldOfViewSettings Attribute
EntityFlags
Various entity flags.
Definition EntityFlags.c:14
EDamageState
SimulationState
ActiveState
Definition ActiveState.c:16
Tuple param1