Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_EffectModule.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
2 //Base generic effect class
5 {
6  [Attribute("", UIWidgets.ResourceNamePicker, desc: "Particle effect", params: "ptc")]
7  protected ResourceName m_sParticle; //the particle resource
8  [Attribute(desc: "Effect position")]
9  protected ref PointInfo m_effectPosition; //the position of the m_effectPosition
10  [Attribute(desc: "If not checked, the modul is activated and deactivated only with physics event. If checked, the effect is always active")]
11  protected bool m_bTickOnFrame; //if false, effect is activate only with EOnPhysic
12 #ifdef WORKBENCH
13  [Attribute("", desc: "Play the effect in Workbench", params: "Debug")]
14  protected bool m_bShowEffectInWB;
15 #endif
16  protected IEntity m_owner;
17  protected SCR_BaseEffectManagerComponent m_Manager;
18  protected ParticleEffectEntity m_sParticleEffect;
19  protected SignalsManagerComponent m_SignalManager;
20 
21 
22  [Attribute(desc: "Particle modifier action")]
23  protected ref array<ref SCR_BaseEffectParticleAction> m_aEffectActions; //array of actions which can modify the particle based on the signal value
24 
25 
26  //------------------------------------------------------------------------------------------------
27  bool GetTickOnFrame()
28  {
29  return m_bTickOnFrame;
30  }
31 
32  //------------------------------------------------------------------------------------------------
33  IEntity GetOwner()
34  {
35  return m_Manager.GetOwner();
36  }
37 
38  //------------------------------------------------------------------------------------------------
39  void TurnOn()
40  {
41  if (!m_sParticleEffect)
42  CreateEmitter();
43  if (!m_sParticleEffect)
44  return;
45  m_sParticleEffect.Play();
46  }
47 
48  //------------------------------------------------------------------------------------------------
49  void TurnOff()
50  {
51  if (!m_sParticleEffect)
52  return;
53  m_sParticleEffect.Stop();
54  }
55 
56  //------------------------------------------------------------------------------------------------
57  protected void CreateEmitter(bool PlayOnSpawn = false)
58  {
59  if (!m_sParticle)
60  return;
61 
62  if (!m_Manager)
63  {
64  if(!m_owner)
65  return;
66  }
67  else
68  {
69  m_owner = m_Manager.GetOwner();
70  }
71 
72  vector transform[4];
73  m_effectPosition.GetLocalTransform(transform);
74 
75  ParticleEffectEntitySpawnParams spawnParams();
76  spawnParams.UseFrameEvent = true;
77  spawnParams.Parent = m_owner;
78  spawnParams.PivotID = m_effectPosition.GetNodeId();
79  spawnParams.Transform = transform;
80 
81  m_sParticleEffect = ParticleEffectEntity.SpawnParticleEffect(m_sParticle, spawnParams);
82  }
83 
84 #ifdef WORKBENCH
85  //------------------------------------------------------------------------------------------------
86  protected void WB_PlayEffect()
87  {
88  CreateEmitter(true);
89  //TurnOn();
90  }
91 #endif
92 
93  //------------------------------------------------------------------------------------------------
94  ParticleEffectEntity GetEmitter()
95  {
96  return m_sParticleEffect;
97  }
98 
99  //------------------------------------------------------------------------------------------------
100  SignalsManagerComponent GetSignalManager()
101  {
102  return m_SignalManager;
103  }
104 
105  //------------------------------------------------------------------------------------------------
106  protected void InitActions()
107  {
108  foreach (SCR_BaseEffectParticleAction action : m_aEffectActions)
109  {
110  if (!action)
111  continue;
112  action.Init(this);
113  }
114  }
115 
116  //------------------------------------------------------------------------------------------------
117  protected void DeInitActions()
118  {
119  foreach (SCR_BaseEffectParticleAction action : m_aEffectActions)
120  {
121  if (!action)
122  continue;
123  action.DeInit();
124  }
125  m_aEffectActions.Clear();
126  }
127 
128 
129  //------------------------------------------------------------------------------------------------
130  void Init(SCR_BaseEffectManagerComponent manager)
131  {
132  m_Manager = manager;
133  if (manager)
134  m_SignalManager = SignalsManagerComponent.Cast(manager.GetOwner().FindComponent(SignalsManagerComponent));
135 
136  m_effectPosition.Init(manager.GetOwner());
137 
138  InitActions();
139  }
140 
141  //------------------------------------------------------------------------------------------------
142  void DeInit()
143  {
144  m_SignalManager = null;
145  m_Manager = null;
146  DeInitActions();
147  }
148 
149  //------------------------------------------------------------------------------------------------
150  void Update(IEntity owner, float timeSlice)
151  {
152  foreach (SCR_BaseEffectParticleAction action : m_aEffectActions)
153  {
154  if (!action)
155  continue;
156  action.Update();
157  }
158  }
159 
160 #ifdef WORKBENCH
161  //------------------------------------------------------------------------------------------------
162  void WB_Update(IEntity owner, float timeSlice)
163  {
164  if (m_bShowEffectInWB && m_sParticleEffect)
165  //m_sParticleEffect.WB_Update(timeSlice);
166  }
167 
168  //------------------------------------------------------------------------------------------------
169  void WB_OnInit(IEntity owner, inout vector mat[4], IEntitySource src)
170  {
171  TurnOff();
172  m_owner = owner;
173  WB_PlayEffect();
174  }
175 #endif
176 };
177 
178 //------------------------------------------------------------------------------------------------
179 //Helicopter specific effect class
182 {
183  [Attribute("10", UIWidgets.Auto, desc: "Time to play startup particle\n[s]")]
184  protected float m_fStartupTime;
185 
186  protected SCR_HelicopterControllerComponent m_HelicopterController;
187 
188  //------------------------------------------------------------------------------------------------
189  override void Init(SCR_BaseEffectManagerComponent manager)
190  {
191  super.Init(manager)
192  //do the stuff here
193  }
194 
195  //------------------------------------------------------------------------------------------------
196  override void Update(IEntity owner, float timeSlice)
197  {
198  super.Update(owner, timeSlice);
199  }
200 };
201 
203 {
208 };
209 
210 //------------------------------------------------------------------------------------------------
213 {
214  [Attribute("0", UIWidgets.ComboBox, "Type of parameter to change", "", ParamEnumArray.FromEnum(SCR_EmitterParam))]
215  protected SCR_EmitterParam m_Parameter;
216  [Attribute(desc: "New value of the parameter")]
217  protected float m_fValue;
218 
219  protected SCR_EffectModule m_Module;
220  protected bool m_bPerformed = false;
221 
222  //------------------------------------------------------------------------------------------------
223  void Init(notnull SCR_EffectModule module)
224  {
225  m_Module = module;
226  }
227 
228  //------------------------------------------------------------------------------------------------
229  void DeInit()
230  {
231  m_Module = null;
232  }
233 
234  //------------------------------------------------------------------------------------------------
235  void Update();
236 
237  //------------------------------------------------------------------------------------------------
238  protected void PerformAction()
239  {
240  if (m_Parameter == SCR_EmitterParam.TURN_ON)
241  {
242  m_Module.TurnOn();
243  }
244  else if (m_Parameter == SCR_EmitterParam.TURN_OFF)
245  {
246  m_Module.TurnOff();
247  }
248  else if (m_Parameter == SCR_EmitterParam.BIRTHRATE)
249  {
250  m_Module.GetEmitter().GetParticles().SetParam(-1, EmitterParam.BIRTH_RATE, m_fValue);
251  }
252  else if (m_Parameter == SCR_EmitterParam.LIFETIME)
253  {
254 
255  }
256  }
257 }
258 
259 
260 
261 //------------------------------------------------------------------------------------------------
263 class SCR_BaseEffectParticleSignalAction: SCR_BaseEffectParticleAction
264 {
265  [Attribute(desc: "Signal which drives the effect")]
266  protected string m_sSignal;
267  [Attribute(defvalue: SCR_Enum.GetDefault(SCR_ComparerOperator.GREATER_THAN_OR_EQUAL), UIWidgets.ComboBox, "Cond operator", "", ParamEnumArray.FromEnum(SCR_ComparerOperator) )]
268  private SCR_ComparerOperator m_eOperator;
269  [Attribute(desc: "Value of signal when the action will be executed")]
270  protected float m_fSignalValue;
271  protected int m_iSignalID;
272  SignalsManagerComponent m_SignalManager;
273 
274  //------------------------------------------------------------------------------------------------
275  override void Init(notnull SCR_EffectModule module)
276  {
277  super.Init(module);
278  m_SignalManager = module.GetSignalManager();
279  if (!m_SignalManager)
280  return;
281  m_iSignalID = m_SignalManager.FindSignal(m_sSignal);
282  }
283 
284  //------------------------------------------------------------------------------------------------
285  override void DeInit()
286  {
287  m_SignalManager = null;
288  m_iSignalID = -1;
289  super.DeInit();
290  }
291 
292  //------------------------------------------------------------------------------------------------
293  override void Update()
294  {
295  if (m_bPerformed)
296  {
297  if (m_SignalManager.GetSignalValue(m_iSignalID) == 0.0)
298  m_bPerformed = false; //if signal returns to 0.0, reset the flag
299  return;
300  }
301 
302  //add option to do this only once until the next change
303  PrintFormat("Signal value = %1", m_SignalManager.GetSignalValue(m_iSignalID));
304 
305  if (SCR_Comparer<float>.Compare(m_eOperator, (float)m_SignalManager.GetSignalValue(m_iSignalID), (float)m_fSignalValue ))
306  {
307  m_bPerformed = true;
308  PerformAction();
309  }
310  }
311 }
312 
313 
314 enum EVehicleEvent
315 {
316  ON_ENGINE_START,
317  ON_ENGINE_STOP,
318 };
319 
320 //------------------------------------------------------------------------------------------------
323 {
324  //TODO(zozo): this could be done better - some dynamic event getter would be useful
325  [Attribute(defvalue: "0", UIWidgets.ComboBox, "Events", "", ParamEnumArray.FromEnum(EVehicleEvent))]
326  protected EVehicleEvent m_eEvent;
327 
328  [Attribute(defvalue: "0", desc: "Perform the action only once")]
329  protected bool m_bOnce;
330  protected SCR_HelicopterControllerComponent m_VehicleController;
331  protected ScriptInvokerVoid m_EventHandler;
332 
333 
334  //------------------------------------------------------------------------------------------------
335  protected void RegisterEvent()
336  {
337  switch(m_eEvent)
338  {
339  case EVehicleEvent.ON_ENGINE_START:
340  {
341  m_EventHandler = m_VehicleController.GetOnEngineStart();
342  break;
343  };
344  case EVehicleEvent.ON_ENGINE_STOP:
345  {
346  m_EventHandler = m_VehicleController.GetOnEngineStop();
347  break;
348  };
349  }
350 
351  if (m_EventHandler)
352  m_EventHandler.Insert(PerformAction);
353  }
354 
355  //------------------------------------------------------------------------------------------------
356  override void Init(notnull SCR_EffectModule module)
357  {
358  super.Init(module);
359  IEntity owner = module.GetOwner();
360  if (!owner) //this would be weird, but doublecheck it
361  return;
362  m_VehicleController = SCR_HelicopterControllerComponent.Cast(owner.FindComponent(SCR_HelicopterControllerComponent));
363  if (!m_VehicleController)
364  {
365  Print("SCR_HelicopterControllerComponent controller not found. Action won't work", LogLevel.WARNING);
366  return;
367  }
368  RegisterEvent();
369  }
370 
371  //------------------------------------------------------------------------------------------------
372  override void DeInit()
373  {
374  m_VehicleController = null;
375  m_EventHandler.Clear();
376  super.DeInit();
377  }
378 
379  //------------------------------------------------------------------------------------------------
380  override void PerformAction()
381  {
382  super.PerformAction();
383  if (m_bOnce)
384  m_EventHandler.Remove(PerformAction);
385  }
386 
387 }
388 
389 //------------------------------------------------------------------------------------------------
392 class SCR_BaseEffectParticleHelicopterRotorControlAction: SCR_BaseEffectParticleAction
393 {
394  [Attribute( "", UIWidgets.EditBox, "Speed in m/s which tops the effect's interpolation from 100 to 0% lifetime value" )]
395  float m_ExhaustEndSpeedInM;
396 
397  const string SIGNAL_RPM = "MainRotorRPM";
398  const int RPM_THRESHOLD = 50; //when to enable or disable the rotor wash effect
399  protected int m_iSignalID;
400  SignalsManagerComponent m_SignalManager;
401  Physics m_Physics;
402  Particles m_Effect;
403 
404  //------------------------------------------------------------------------------------------------
405  override void Init(notnull SCR_EffectModule module)
406  {
407  super.Init(module);
408  m_SignalManager = module.GetSignalManager();
409  if (!m_SignalManager)
410  return;
411  m_iSignalID = m_SignalManager.FindSignal(SIGNAL_RPM);
412  m_Physics = module.GetOwner().GetPhysics();
413  int abc = 0;
414 
415 
416  }
417 
418  //------------------------------------------------------------------------------------------------
419  override void Update()
420  {
421  //PrintFormat("Signal value = %1", m_SignalManager.GetSignalValue(m_iSignalID));
422 
423  if ( !m_Effect && m_SignalManager.GetSignalValue(m_iSignalID) > RPM_THRESHOLD ) //engine is started, but effect hasn't been yet created
424  {
425  m_Module.TurnOn();
426  } else if ( m_Effect && m_SignalManager.GetSignalValue(m_iSignalID) < RPM_THRESHOLD ) //engine was already running. Now is turned off and RPM went down
427  {
428  m_Module.TurnOff();
429  m_Effect = null;
430  }
431 
432  if (!m_Effect && m_Module.GetEmitter() )
433  m_Effect = m_Module.GetEmitter().GetParticles(); //get the particles
434 
435 
436  if (m_Effect && m_Physics && m_ExhaustEndSpeedInM > 0)
437  {
438  vector velocity_vector = m_Physics.GetVelocity();
439  float speed_m_per_s = velocity_vector.Length();
440 
441  float lifetime_scale = Math.Clamp( 1 - (speed_m_per_s / m_ExhaustEndSpeedInM) , 0 , 1 );
442 
443  m_Effect.MultParam(-1, EmitterParam.LIFETIME, lifetime_scale);
444  m_Effect.MultParam(-1, EmitterParam.LIFETIME_RND, lifetime_scale);
445  }
446  }
447 }
SCR_Enum
Definition: SCR_Enum.c:1
Compare
SCR_VONRadialDisplay Compare
Definition: SCR_ContentBrowser_AddonsSubMenu.c:1612
SCR_EffectModuleHelicopterExhaust
Definition: SCR_EffectModule.c:181
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
m_Physics
private Physics m_Physics
Definition: InteractableBoxComponent.c:13
Init
void Init(IEntity entity=null, vector worldPos=vector.Zero, float timestamp=0.0, EAITargetInfoCategory category=0)
Definition: SCR_AITargetInfo.c:27
m_SignalManager
protected SignalsManagerComponent m_SignalManager
Definition: SCR_WristwatchComponent.c:55
m_owner
protected IEntity m_owner
Definition: SCR_CharacterRegistrationComponent.c:10
SCR_ComparerOperator
SCR_ComparerOperator
Definition: SCR_Comparer.c:2
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_EmitterParam
SCR_EmitterParam
Definition: SCR_EffectModule.c:202
m_bOnce
protected bool m_bOnce
Definition: SCR_CharacterTriggerEntity.c:38
Update
override void Update(float timeSlice)
Definition: SCR_CampaignBuildingGadgetToolComponent.c:28
SCR_BaseEffectParticleHelicopterEventAction
Definition: SCR_EffectModule.c:322
TURN_OFF
@ TURN_OFF
Definition: SCR_EffectModule.c:205
LIFETIME
@ LIFETIME
Definition: SCR_EffectModule.c:207
ScriptInvokerVoid
ScriptInvokerBase< ScriptInvokerVoidMethod > ScriptInvokerVoid
Definition: SCR_ScriptInvokerHelper.c:9
SCR_BaseEffectParticleAction
Definition: SCR_EffectModule.c:212
TURN_ON
@ TURN_ON
Definition: SCR_EffectModule.c:204
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
PerformAction
proto external void PerformAction(BaseUserAction action)
SCR_EffectModule
Definition: SCR_EffectModule.c:4
BIRTHRATE
@ BIRTHRATE
Definition: SCR_EffectModule.c:206
SCR_BaseEffectManagerComponent
Definition: SCR_BaseEffectManagerComponent.c:11
BaseContainerProps
SCR_AIGoalReaction_Follow BaseContainerProps
Handles insects that are supposed to be spawned around selected prefabs defined in prefab names array...
Definition: SCR_AIGoalReaction.c:468