Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_DebrisSpawnable.c
Go to the documentation of this file.
1[BaseContainerProps(), SCR_Spawnable_SmallDebrisTitle()]
3{
4 [Attribute("0 0 0", UIWidgets.Coords, "Random spawn position offset range (X Y Z in meters)", params: "0 inf")]
5 vector m_vRandomPositionOffset;
6 [Attribute(ResourceName.Empty, UIWidgets.ResourcePickerThumbnail, "Debris model prefabs to spawn (spawns ALL of them)", "et xob")]
7 ref array<ResourceName> m_ModelPrefabs;
8 [Attribute("0", desc: "Remap materials on all models defined in Phase Model array to those used on owner prefab. Remap is applied based on material slot names.")]
9 bool m_bUseMaterialsFromParent;
10 [Attribute("", UIWidgets.Object, "List of slots which should be remaped. If Materials From Parent is active, materials from parent will be extented by this list.", category: "Destruction Multi-Phase")]
11 ref array<ref SCR_DamageRemapData> m_aRemapData;
12 [Attribute("10", UIWidgets.Slider, "Mass of the debris", "0.01 1000 0.01")]
13 float m_fMass;
14 [Attribute("5", UIWidgets.Slider, "Minimum lifetime value for the debris (in s)", "0 3600 0.5")]
15 float m_fLifetimeMin;
16 [Attribute("10", UIWidgets.Slider, "Maximum lifetime value for the debris (in s)", "0 3600 0.5")]
17 float m_fLifetimeMax;
18 [Attribute("200", UIWidgets.Slider, "Maximum distance from camera above which the debris is not spawned (in m)", "0 3600 0.5")]
19 float m_fDistanceMax;
20 [Attribute("0", UIWidgets.Slider, "Higher priority overrides lower priority if at or over debris limit", "0 100 1")]
21 int m_fPriority;
22 [Attribute("0.1", UIWidgets.Slider, "Damage received to physics impulse (speed / mass) multiplier", "0 10000 0.01")]
23 float m_fDamageToImpulse;
24 [Attribute("2", UIWidgets.Slider, "Damage to speed multiplier, used when objects get too much damage to impulse", "0 10000 0.01")]
25 float m_fMaxDamageToSpeedMultiplier;
26 [Attribute("0.5", UIWidgets.Slider, "Random linear velocity multiplier (m/s)", "0 200 0.1")]
27 float m_fRandomVelocityLinear;
28 [Attribute("180", UIWidgets.Slider, "Random angular velocity multiplier (deg/s)", "0 3600 0.1")]
29 float m_fRandomVelocityAngular;
30 [Attribute("0", uiwidget: UIWidgets.ComboBox, "Type of material for debris sound", "", ParamEnumArray.FromEnum(SCR_EMaterialSoundTypeDebris))]
31 SCR_EMaterialSoundTypeDebris m_eMaterialSoundType;
32
33#ifdef WORKBENCH
34 //------------------------------------------------------------------------------------------------
37 override bool CompareAttributes(SCR_BaseSpawnable other)
38 {
39 SCR_DebrisSpawnable otherDebris = SCR_DebrisSpawnable.Cast(other);
40
41 if (!super.CompareAttributes(other))
42 return false;
43
44 if (otherDebris.m_ModelPrefabs != m_ModelPrefabs)
45 return false;
46
47 if (otherDebris.m_fLifetimeMin != m_fLifetimeMin)
48 return false;
49
50 if (otherDebris.m_fLifetimeMax != m_fLifetimeMax)
51 return false;
52
53 if (otherDebris.m_fDistanceMax != m_fDistanceMax)
54 return false;
55
56 if (otherDebris.m_fPriority != m_fPriority)
57 return false;
58
59 if (otherDebris.m_fDamageToImpulse != m_fDamageToImpulse)
60 return false;
61
62 if (otherDebris.m_fMaxDamageToSpeedMultiplier != m_fMaxDamageToSpeedMultiplier)
63 return false;
64
65 if (otherDebris.m_fRandomVelocityLinear != m_fRandomVelocityLinear)
66 return false;
67
68 if (otherDebris.m_fRandomVelocityAngular != m_fRandomVelocityAngular)
69 return false;
70
71 if (otherDebris.m_vRandomPositionOffset != m_vRandomPositionOffset)
72 return false;
73
74 if (otherDebris.m_eMaterialSoundType != m_eMaterialSoundType)
75 return false;
76
77 return true;
78 }
79
80 //------------------------------------------------------------------------------------------------
81 override void SetVariables(WorldEditorAPI api, IEntitySource source, array<ref ContainerIdPathEntry> path, int index)
82 {
83 super.SetVariables(api, source, path, index);
84
85 string prefabsArray = "";
86 // Set all variables of the spawn object
87 for (int i = 0, count = m_ModelPrefabs.Count(); i < count; i++)
88 {
89 prefabsArray += m_ModelPrefabs[i];
90
91 if (i != count - 1) // Not last item
92 prefabsArray += ",";
93 }
94
95 api.SetVariableValue(source, path, "m_ModelPrefabs", prefabsArray);
96
97 api.SetVariableValue(source, path, "m_fMass", m_fMass.ToString());
98 api.SetVariableValue(source, path, "m_fLifetimeMin", m_fLifetimeMin.ToString());
99 api.SetVariableValue(source, path, "m_fLifetimeMax", m_fLifetimeMax.ToString());
100 api.SetVariableValue(source, path, "m_fDistanceMax", m_fDistanceMax.ToString());
101 api.SetVariableValue(source, path, "m_fPriority", m_fPriority.ToString());
102 api.SetVariableValue(source, path, "m_fDamageToImpulse", m_fDamageToImpulse.ToString());
103 api.SetVariableValue(source, path, "m_fMaxDamageToSpeedMultiplier", m_fMaxDamageToSpeedMultiplier.ToString());
104 api.SetVariableValue(source, path, "m_fRandomVelocityLinear", m_fRandomVelocityLinear.ToString());
105 api.SetVariableValue(source, path, "m_fRandomVelocityAngular", m_fRandomVelocityAngular.ToString());
106 api.SetVariableValue(source, path, "m_vRandomPositionOffset", m_vRandomPositionOffset.ToString());
107 api.SetVariableValue(source, path, "m_eMaterialSoundType", m_eMaterialSoundType.ToString());
108 }
109
110 //------------------------------------------------------------------------------------------------
111 override bool CreateObject(WorldEditorAPI api, IEntitySource source, array<ref ContainerIdPathEntry> path, int index)
112 {
113 if (!AlreadyExists(api, source, index))
114 {
115 api.CreateObjectArrayVariableMember(source, path, "m_aPhaseDestroySpawnObjects", "SCR_DebrisSpawnable", index);
116 return true;
117 }
118
119 return false;
120 }
121#endif
122
123 //------------------------------------------------------------------------------------------------
125 override IEntity Spawn(IEntity owner, Physics parentPhysics, SCR_HitInfo hitInfo, bool snapToTerrain = false)
126 {
127 if (!hitInfo)
128 return null;
129
130 int numModelPrefabs = 0;
131 if (m_ModelPrefabs)
132 numModelPrefabs = m_ModelPrefabs.Count();
133
134 ResourceName modelEmpty;
135 string remapParent;
136 if(m_bUseMaterialsFromParent)
137 {
138 ResourceName parentModel = SCR_ResourceNameUtils.GetPrefabName(owner);
139 SCR_Global.GetModelAndRemapFromResource(parentModel, modelEmpty, remapParent);
140 }
141 string remapData;
142 foreach (SCR_DamageRemapData remapEntry: m_aRemapData)
143 {
144 remapData += "$remap '" + remapEntry.m_sMaterialSlotName + "' '" + remapEntry.m_sMaterialName + "';";
145 }
146
147 for (int i = 0; i < numModelPrefabs; i++)
148 {
149 ResourceName prefabPath = m_ModelPrefabs[i];
150
151 ResourceName modelPath;
152 string remap;
153 SCR_Global.GetModelAndRemapFromResource(prefabPath, modelPath, remap);
154 // Trying to remap slots which are not present in modelPath will result in error in Log Console. This is why we need to sanitize remap string to only contain valid entries.
155 // GetModelAndRemapFromResource will return non empty remap only if prefabPath is linking to actual prefab with remaped materials.
156 // Above behavior can be used to create a prefab, which remaps only 2 certain slots - those will be retrieved by code and used in sanitization process.
157 if (m_bUseMaterialsFromParent)
158 {
159 if (remap)
160 {
161 remap = SCR_DestructionUtility.SanitizeRemapString(remap,remapParent);
162 }
163 else
164 {
165 remap = remapParent;
166 }
167 }
168
169 remap += remapData;
170
171 if (modelPath == ResourceName.Empty)
172 continue;
173
174 vector spawnMat[4];
175 GetSpawnTransform(owner, spawnMat);
176
177 // Add random offset to spawn position
178 vector randomOffset = vector.Zero;
179 for (int axis = 0; axis < 3; axis++)
180 {
181 if (m_vRandomPositionOffset[axis] != 0)
182 randomOffset[axis] = Math.RandomFloat(-m_vRandomPositionOffset[axis], m_vRandomPositionOffset[axis]);
183 }
184 spawnMat[3] = spawnMat[3] + randomOffset;
185
186 SCR_DestructionDamageManagerComponent destructionComponent = SCR_DestructionDamageManagerComponent.Cast(owner.FindComponent(SCR_DestructionDamageManagerComponent));
187
188 float dmgSpeed = Math.Clamp(hitInfo.m_HitDamage * m_fDamageToImpulse / m_fMass, 0, m_fMaxDamageToSpeedMultiplier);
189
190 vector linearVelocity = hitInfo.m_HitDirection * Math.RandomFloat(0, 1);
191 linearVelocity += Vector(Math.RandomFloat(-1, 1), Math.RandomFloat(-1, 1), Math.RandomFloat(-1, 1)) * m_fRandomVelocityLinear;
192 linearVelocity *= dmgSpeed;
193 vector angularVelocity = Vector(Math.RandomFloat(-1, 1), Math.RandomFloat(-1, 1), Math.RandomFloat(-1, 1)) * Math.RandomFloat(0.25, 4) * m_fRandomVelocityAngular;
194 angularVelocity *= dmgSpeed;
195
196 if (parentPhysics)
197 {
198 linearVelocity += parentPhysics.GetVelocity();
199 angularVelocity += parentPhysics.GetAngularVelocity();
200 }
201#ifdef ENABLE_BASE_DESTRUCTION
202 SCR_DebrisSmallEntity.SpawnDebris(owner.GetWorld(), spawnMat, modelPath, m_fMass, Math.RandomFloat(m_fLifetimeMin, m_fLifetimeMax), m_fDistanceMax, m_fPriority, linearVelocity, angularVelocity, remap, false, m_eMaterialSoundType);
203#endif
204 }
205
206 return null;
207 }
208}
string path
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
SCR_AIGroupClass snapToTerrain
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
proto external Managed FindComponent(typename typeName)
proto external BaseWorld GetWorld()
Definition Math.c:13
void GetSpawnTransform(IEntity owner, out vector outMat[4], bool localCoords=false)
Calculates the spawn tranformation matrix for the object.
Material remap of debris spawned by damage system.
static string SanitizeRemapString(string originalRemap, string newRemap)
static bool GetModelAndRemapFromResource(ResourceName resourcePath, out ResourceName modelPath, out string remap)
Read the input resource and returns whether a model was successfully found, filling the output model ...
Definition Functions.c:1455
Class to temporarily store information about the last hit that dealt damage.
Definition SCR_HitInfo.c:3
AISpawnerGroupClass AIGroupClass Spawn()
Spawns a new group entity, sets its transformation and then calls OnSpawn.
SCR_FieldOfViewSettings Attribute
proto native vector Vector(float x, float y, float z)