Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ImpactEffectComponent.c
Go to the documentation of this file.
1 class SCR_ImpactEffectComponentClass : ScriptComponentClass
2 {
3  [Attribute()]
4  ref array<ResourceName> m_aDefaultParticles;
5 
6  [Attribute()]
7  ref array<ResourceName> m_aWaterParticles;
8 }
9 
10 class SCR_ImpactEffectComponent : ScriptComponent
11 {
12  protected ref ParticleEffectEntitySpawnParams m_ParticleSpawnParams;
13  protected SoundComponent m_SoundComponent;
14 
15  protected const float MIN_TINY_IMPULSE = 2500;
16  protected const float MIN_SMALL_IMPULSE = 5000;
17  protected const float MIN_MEDIUM_IMPULSE = 10000;
18  protected const float MIN_BIG_IMPULSE = 20000;
19  protected const float MIN_HUGE_IMPULSE = 40000;
20 
21  protected const ref array<string> WATER_SOUNDS = {SCR_SoundEvent.SOUND_VEHICLE_WATER_SMALL, SCR_SoundEvent.SOUND_VEHICLE_WATER_MEDIUM, SCR_SoundEvent.SOUND_VEHICLE_WATER_BIG, SCR_SoundEvent.SOUND_VEHICLE_WATER_BIG};
22 
23  protected const int MAX_CALLS_PER_CONTACT = 1;
24  protected const float RESET_TIME = 1000;
25 
26  protected int m_iCachedContactCalls;
27 
28  //------------------------------------------------------------------------------------------------
29  protected array<ResourceName> GetDefaultParticles()
30  {
31  return SCR_ImpactEffectComponentClass.Cast(GetComponentData(GetOwner())).m_aDefaultParticles;
32  }
33 
34  //------------------------------------------------------------------------------------------------
35  protected array<ResourceName> GetWaterParticles()
36  {
37  return SCR_ImpactEffectComponentClass.Cast(GetComponentData(GetOwner())).m_aWaterParticles;
38  }
39 
40  //------------------------------------------------------------------------------------------------
41  protected void ResetContactsDelayed()
42  {
44  }
45 
46  //------------------------------------------------------------------------------------------------
47  void OnImpact(notnull IEntity other, notnull Contact contact)
48  {
50  return;
51 
52  int responseIndex = contact.Physics2.GetResponseIndex();
53 
54  // Exclude collisions with physics objects with tiny response index e.g. bushes, fences etc.
55  if (responseIndex == SCR_EPhysicsResponseIndex.TINY_DESTRUCTIBLE || responseIndex == SCR_EPhysicsResponseIndex.SMALL_DESTRUCTIBLE)
56  return;
57 
58  // Exclude collisions with other vehicle parts
59  if (SCR_VehicleDamageManagerComponent.Cast(other.GetRootParent().FindComponent(SCR_VehicleDamageManagerComponent)))
60  return;
61 
62  // all contacts will be ignored until cached contacts are reset
64  GetGame().GetCallqueue().CallLater(ResetContactsDelayed, RESET_TIME);
65 
67 
68  if (contact.Impulse < MIN_TINY_IMPULSE)
69  return;
70 
71  int magnitude = -1;
72  if (contact.Impulse < MIN_SMALL_IMPULSE)
73  magnitude = 0;
74  else if (contact.Impulse < MIN_MEDIUM_IMPULSE)
75  magnitude = 1;
76  else
77  magnitude = 2;
78 
79  vector transform[4];
80  Math3D.MatrixIdentity4(transform);
81  transform[3] = contact.Position;
82 
83  GameMaterial material = contact.Material2;
84  ParticleEffectInfo effectInfo = material.GetParticleEffectInfo();
85  ResourceName resourceName = effectInfo.GetBlastResource(magnitude);
86 
87  if (resourceName.IsEmpty())
88  resourceName = GetDefaultParticles()[magnitude];
89 
90  EmitParticles(transform, resourceName);
91 
92  if (magnitude > -1)
93  Rpc(RPC_OnImpactBroadcast, contact.Position, contact.Normal, magnitude);
94  }
95 
96  //------------------------------------------------------------------------------------------------
97  protected void OnWaterEnter()
98  {
99  if (GetWaterParticles().IsEmpty())
100  return;
101 
102  Physics physics = GetOwner().GetPhysics();
103  if (!physics)
104  return;
105 
106  // Only vertical axis is measured since water particles only go up
107  float impulse = Math.AbsFloat(physics.GetVelocity()[1]) * physics.GetMass();
108 
110  return;
111 
112  int magnitude = -1;
114  magnitude = 0;
115  else if (impulse < MIN_MEDIUM_IMPULSE)
116  magnitude = 1;
117  else if (impulse < MIN_BIG_IMPULSE)
118  magnitude = 2;
119  else
120  magnitude = 3;
121 
122  vector ownerTransform[4];
123  GetOwner().GetTransform(ownerTransform);
124 
125  EWaterSurfaceType surfaceType;
126  float lakeArea;
127  float waterHeight = SCR_WorldTools.GetWaterSurfaceY(GetGame().GetWorld(), ownerTransform[3], surfaceType, lakeArea);
128 
129  vector transform[4];
130  Math3D.MatrixIdentity3(transform);
131  vector particleOrigin = {ownerTransform[3][0], waterHeight, ownerTransform[3][2]};
132  transform[3] = particleOrigin;
133 
134  ResourceName resourceName = GetWaterParticles()[magnitude];
135  string soundEvent = WATER_SOUNDS[magnitude];
136 
137  if (resourceName.IsEmpty())
138  resourceName = GetWaterParticles()[0];
139 
140  EmitParticles(transform, resourceName);
141  PlaySound(soundEvent);
142 
143  if (magnitude > -1)
144  Rpc(RPC_OnWaterEnterBroadcast, transform, magnitude);
145  }
146 
147  //------------------------------------------------------------------------------------------------
148  protected void EmitParticles(vector transform[4], ResourceName particleResource)
149  {
150  if (!m_ParticleSpawnParams || particleResource.IsEmpty())
151  return;
152 
153  m_ParticleSpawnParams.Transform = transform;
154  ParticleEffectEntity.SpawnParticleEffect(particleResource, m_ParticleSpawnParams);
155  }
156 
157  //------------------------------------------------------------------------------------------------
158  protected void PlaySound(string soundEvent)
159  {
160  if (!m_SoundComponent || soundEvent.IsEmpty())
161  return;
162 
163  m_SoundComponent.SoundEvent(soundEvent);
164  }
165 
166  //------------------------------------------------------------------------------------------------
167  [RplRpc(RplChannel.Unreliable, RplRcver.Broadcast)]
168  protected void RPC_OnImpactBroadcast(vector contactPos, vector contactNormal, int magnitude)
169  {
170  vector transform[4];
171  Math3D.MatrixIdentity4(transform);
172  transform[3] = contactPos;
173 
174  TraceParam trace = new TraceParam();
175  trace.Start = contactPos + contactNormal;
176  trace.End = contactPos - contactNormal;
177  trace.Flags = TraceFlags.WORLD | TraceFlags.ENTS;
178 
179  GetOwner().GetWorld().TraceMove(trace, TraceFilter);
180 
181  GameMaterial contactMat = trace.SurfaceProps;
182  ParticleEffectInfo effectInfo = contactMat.GetParticleEffectInfo();
183  ResourceName resourceName = effectInfo.GetBlastResource(magnitude);
184 
185  if (resourceName.IsEmpty())
186  resourceName = GetDefaultParticles()[magnitude];
187 
188  EmitParticles(transform, resourceName);
189  }
190 
191  //------------------------------------------------------------------------------------------------
192  [RplRpc(RplChannel.Unreliable, RplRcver.Broadcast)]
193  protected void RPC_OnWaterEnterBroadcast(vector transform[4], int magnitude)
194  {
195  ResourceName resourceName = GetWaterParticles()[magnitude];
196  string soundEvent = WATER_SOUNDS[magnitude];
197 
198  if (resourceName.IsEmpty())
199  resourceName = GetWaterParticles()[0];
200 
201  EmitParticles(transform, resourceName);
202  PlaySound(soundEvent);
203  }
204 
205  //------------------------------------------------------------------------------------------------
206  protected bool TraceFilter(notnull IEntity e)
207  {
208  return e != GetOwner() && e.GetRootParent() != GetOwner(); // ignore if traced entity is vehicle or vehicle part
209  }
210 
211  //------------------------------------------------------------------------------------------------
212  override void EOnInit(IEntity owner)
213  {
214  m_ParticleSpawnParams = new ParticleEffectEntitySpawnParams();
215  m_ParticleSpawnParams.TransformMode = ETransformMode.WORLD;
216  m_ParticleSpawnParams.UseFrameEvent = true;
217 
218  m_SoundComponent = SoundComponent.Cast(GetOwner().FindComponent(SoundComponent));
219 
220  SCR_VehicleBuoyancyComponent buoyancyComp = SCR_VehicleBuoyancyComponent.Cast(GetOwner().FindComponent(SCR_VehicleBuoyancyComponent));
221  if (!buoyancyComp)
222  return;
223 
224  buoyancyComp.GetOnWaterEnter().Insert(OnWaterEnter);
225  }
226 
227  //------------------------------------------------------------------------------------------------
228  override void OnPostInit(IEntity owner)
229  {
230  SetEventMask(GetOwner(), EntityEvent.INIT);
231  }
232 }
233 
RPC_OnWaterEnterBroadcast
protected void RPC_OnWaterEnterBroadcast(vector transform[4], int magnitude)
Definition: SCR_ImpactEffectComponent.c:193
EmitParticles
protected void EmitParticles(vector transform[4], ResourceName particleResource)
Definition: SCR_ImpactEffectComponent.c:148
ScriptComponent
SCR_SiteSlotEntityClass ScriptComponent
MIN_HUGE_IMPULSE
const protected float MIN_HUGE_IMPULSE
Definition: SCR_ImpactEffectComponent.c:19
m_ParticleSpawnParams
SCR_ImpactEffectComponentClass m_ParticleSpawnParams
ResetContactsDelayed
protected void ResetContactsDelayed()
Definition: SCR_ImpactEffectComponent.c:41
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
RPC_OnImpactBroadcast
protected void RPC_OnImpactBroadcast(vector contactPos, vector contactNormal, int magnitude)
Definition: SCR_ImpactEffectComponent.c:168
SCR_SoundEvent
Definition: SCR_SoundEvent.c:1
SCR_VehicleDamageManagerComponent
void SCR_VehicleDamageManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_VehicleDamageManagerComponent.c:1720
SCR_EPhysicsResponseIndex
SCR_EPhysicsResponseIndex
Definition: SCR_VehicleDamageManagerComponent.c:133
SCR_WorldTools
Definition: SCR_WorldTools.c:1
RplRpc
SCR_AchievementsHandlerClass ScriptComponentClass RplRpc(RplChannel.Reliable, RplRcver.Owner)] void UnlockOnClient(AchievementId achievement)
Definition: SCR_AchievementsHandler.c:11
WATER_SOUNDS
const protected ref array< string > WATER_SOUNDS
Definition: SCR_ImpactEffectComponent.c:21
SCR_ImpactEffectComponentClass
Definition: SCR_ImpactEffectComponent.c:1
OnWaterEnter
protected void OnWaterEnter()
Definition: SCR_ImpactEffectComponent.c:97
MIN_SMALL_IMPULSE
const protected float MIN_SMALL_IMPULSE
Definition: SCR_ImpactEffectComponent.c:16
m_iCachedContactCalls
protected int m_iCachedContactCalls
Definition: SCR_ImpactEffectComponent.c:26
OnImpact
void OnImpact(notnull IEntity other, notnull Contact contact)
Definition: SCR_ImpactEffectComponent.c:47
impulse
SCR_DestructibleTreeV2Class impulse
Attribute
typedef Attribute
Post-process effect of scripted camera.
MIN_BIG_IMPULSE
const protected float MIN_BIG_IMPULSE
Definition: SCR_ImpactEffectComponent.c:18
OnPostInit
override void OnPostInit(IEntity owner)
Editable Mine.
Definition: SCR_ImpactEffectComponent.c:228
RESET_TIME
const protected float RESET_TIME
Definition: SCR_ImpactEffectComponent.c:24
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
GetDefaultParticles
protected array< ResourceName > GetDefaultParticles()
Definition: SCR_ImpactEffectComponent.c:29
TraceFilter
protected bool TraceFilter(notnull IEntity e)
Definition: SCR_ImpactEffectComponent.c:206
PlaySound
protected void PlaySound(string soundEvent)
Definition: SCR_ImpactEffectComponent.c:158
EOnInit
override void EOnInit(IEntity owner)
Initialise this component with data from FactionsManager.
Definition: SCR_ImpactEffectComponent.c:212
GetWaterParticles
protected array< ResourceName > GetWaterParticles()
Definition: SCR_ImpactEffectComponent.c:35
m_SoundComponent
protected SoundComponent m_SoundComponent
Definition: SCR_ImpactEffectComponent.c:13
ParticleEffectInfo
Definition: ParticleEffectInfo.c:12
MIN_TINY_IMPULSE
const protected float MIN_TINY_IMPULSE
Definition: SCR_ImpactEffectComponent.c:15
MAX_CALLS_PER_CONTACT
const protected int MAX_CALLS_PER_CONTACT
Definition: SCR_ImpactEffectComponent.c:23
GameMaterial
Definition: GameMaterial.c:12
MIN_MEDIUM_IMPULSE
const protected float MIN_MEDIUM_IMPULSE
Definition: SCR_ImpactEffectComponent.c:17
EWaterSurfaceType
EWaterSurfaceType
Definition: EWaterSurfaceType.c:7