Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_DestructionCommon.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
2 // THIS FILE CONTAINS COMMON FUNCTIONS USED BY THE VARIOUS DESTRUCTION SYSTEMS
3 //------------------------------------------------------------------------------------------------
4 
5 //------------------------------------------------------------------------------------------------
8 {
9  static const float PARTICLE_IMPULSE_DEFAULT = 0.5;
10  static const float PARTICLE_IMPULSE_INCENDIARY = 1;
11  static const float PARTICLE_IMPULSE_EXPLOSION = 1;
12  static const float PARTICLE_IMPULSE_COLLISION = 0.5;
13 
14  //------------------------------------------------------------------------------------------------
16  static float GetPTCImpulseScale(EDamageType type)
17  {
18  float impulseScale = PARTICLE_IMPULSE_DEFAULT;
19 
20  switch (type)
21  {
22  case EDamageType.INCENDIARY:
23  {
24  impulseScale = PARTICLE_IMPULSE_INCENDIARY;
25  break;
26  }
27  case EDamageType.EXPLOSIVE:
28  {
29  impulseScale = PARTICLE_IMPULSE_EXPLOSION;
30  break;
31  }
32  case EDamageType.COLLISION:
33  {
34  impulseScale = PARTICLE_IMPULSE_COLLISION;
35  break;
36  }
37  }
38 
39  return impulseScale;
40  }
41 
42  //------------------------------------------------------------------------------------------------
44  static ParticleEffectEntity PlayParticleEffect_FractionDestruction(IEntity entity, ResourceName particlePath, EDamageType type, vector hitPos, vector hitDir)
45  {
46  if (!entity)
47  return null;
48 
49  if (particlePath == ResourceName.Empty)
50  return null;
51 
52  vector fw = hitDir * 0.5 + entity.GetWorldTransformAxis(2);
53  fw.Normalize();
54  vector rt = vector.Up * fw;
55  rt.Normalize();
56  vector up = fw * rt;
57  up.Normalize();
58 
59  ParticleEffectEntitySpawnParams spawnParams();
60  spawnParams.Transform[0] = rt;
61  spawnParams.Transform[1] = up;
62  spawnParams.Transform[2] = fw;
63  spawnParams.Transform[3] = hitPos;
64  spawnParams.UseFrameEvent = true;
65 
66  ParticleEffectEntity ptc = ParticleEffectEntity.SpawnParticleEffect(particlePath, spawnParams);
67  if (!ptc)
68  return null;
69 
70  float velocityScale = GetPTCImpulseScale(type);
71  Particles particles = ptc.GetParticles();
72  particles.MultParam(-1, EmitterParam.VELOCITY, velocityScale);
73  particles.MultParam(-1, EmitterParam.VELOCITY_RND, velocityScale);
74 
75  return ptc;
76  }
77 
78  //------------------------------------------------------------------------------------------------
80  static ParticleEffectEntity PlayParticleEffect_CompleteDestruction(IEntity entity, ResourceName particlePath, EDamageType damageType, bool atBoundBoxCenter = true)
81  {
82  if (!entity)
83  return null;
84 
85  if (particlePath == ResourceName.Empty)
86  return null;
87 
88  ParticleEffectEntitySpawnParams spawnParams();
89  spawnParams.TransformMode = ETransformMode.WORLD;
90  entity.GetWorldTransform(spawnParams.Transform);
91  spawnParams.UseFrameEvent = true;
92 
93  if (atBoundBoxCenter)
94  {
95  vector mins, maxs;
96  entity.GetBounds(mins, maxs);
97  vector center = (maxs - mins) * 0.5 + mins;
98  spawnParams.Transform[3] = center.Multiply4(spawnParams.Transform);
99  }
100 
101  ParticleEffectEntity ptc = ParticleEffectEntity.SpawnParticleEffect(particlePath, spawnParams);
102  if (!ptc)
103  return null;
104 
105  float velocityScale = GetPTCImpulseScale(damageType);
106  Particles particles = ptc.GetParticles();
107  particles.MultParam(-1, EmitterParam.VELOCITY, velocityScale);
108  particles.MultParam(-1, EmitterParam.VELOCITY_RND, velocityScale);
109 
110  return ptc;
111  }
112 
113  //------------------------------------------------------------------------------------------------
115  static ParticleEffectEntity PlayParticleEffect_Child(ResourceName particlePath, EDamageType damageType, notnull IEntity parent, vector mat[4])
116  {
117  if (particlePath == ResourceName.Empty)
118  return null;
119 
120  vector parentTransform[4];
121  parent.GetWorldTransform(parentTransform);
122 
123  ParticleEffectEntitySpawnParams spawnParams();
124  Math3D.MatrixInvMultiply4(parentTransform, mat, spawnParams.Transform);
125  spawnParams.Parent = parent;
126  spawnParams.UseFrameEvent = true;
127 
128  ParticleEffectEntity ptc = ParticleEffectEntity.SpawnParticleEffect(particlePath, spawnParams);
129  if (!ptc)
130  return null;
131 
132  float velocityScale = GetPTCImpulseScale(damageType);
133  Particles particles = ptc.GetParticles();
134  particles.MultParam(-1, EmitterParam.VELOCITY, velocityScale);
135  particles.MultParam(-1, EmitterParam.VELOCITY_RND, velocityScale);
136 
137  return ptc;
138  }
139 
140  //------------------------------------------------------------------------------------------------
142  static ParticleEffectEntity PlayParticleEffect_Transform(ResourceName particlePath, EDamageType damageType, vector mat[4])
143  {
144  if (particlePath == ResourceName.Empty)
145  return null;
146 
147  ParticleEffectEntitySpawnParams spawnParams();
148  spawnParams.Transform = mat;
149  spawnParams.UseFrameEvent = true;
150 
151  ParticleEffectEntity ptc = ParticleEffectEntity.SpawnParticleEffect(particlePath, spawnParams);
152  if (!ptc)
153  return null;
154 
155  float velocityScale = GetPTCImpulseScale(damageType);
156  Particles particles = ptc.GetParticles();
157  if (particles)
158  {
159  particles.MultParam(-1, EmitterParam.VELOCITY, velocityScale);
160  particles.MultParam(-1, EmitterParam.VELOCITY_RND, velocityScale);
161  }
162 
163  return ptc;
164  }
165 };
type
EDamageType type
Definition: SCR_DestructibleTreeV2.c:32
EDamageType
EDamageType
Definition: EDamageType.c:12
SCR_DestructionCommon
Class containing common functions between destructible classes.
Definition: SCR_DestructionCommon.c:7