Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
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 [Attribute("", desc: "Play the effect in Workbench", params: "Debug")]
13 protected bool m_bShowEffectInWB;
14 protected IEntity m_owner;
18
19
20 [Attribute(desc: "Particle modifier action")]
21 protected ref array<ref SCR_BaseEffectParticleAction> m_aEffectActions; //array of actions which can modify the particle based on the signal value
22
23
24 //------------------------------------------------------------------------------------------------
26 {
27 return m_bTickOnFrame;
28 }
29
30 //------------------------------------------------------------------------------------------------
32 {
33 return m_Manager.GetOwner();
34 }
35
36 //------------------------------------------------------------------------------------------------
37 void TurnOn()
38 {
42 return;
43 m_sParticleEffect.Play();
44 }
45
46 //------------------------------------------------------------------------------------------------
47 void TurnOff()
48 {
50 return;
51 m_sParticleEffect.Stop();
52 }
53
54 //------------------------------------------------------------------------------------------------
55 protected void CreateEmitter(bool PlayOnSpawn = false)
56 {
57 if (!m_sParticle)
58 return;
59
60 if (!m_Manager)
61 {
62 if(!m_owner)
63 return;
64 }
65 else
66 {
67 m_owner = m_Manager.GetOwner();
68 }
69
70 vector transform[4];
71 m_effectPosition.GetLocalTransform(transform);
72
74 spawnParams.UseFrameEvent = true;
75 spawnParams.Parent = m_owner;
76 spawnParams.PivotID = m_effectPosition.GetNodeId();
77 spawnParams.Transform = transform;
78
79 m_sParticleEffect = ParticleEffectEntity.SpawnParticleEffect(m_sParticle, spawnParams);
80 }
81
82#ifdef WORKBENCH
83 //------------------------------------------------------------------------------------------------
84 protected void WB_PlayEffect()
85 {
86 CreateEmitter(true);
87 //TurnOn();
88 }
89#endif
90
91 //------------------------------------------------------------------------------------------------
96
97 //------------------------------------------------------------------------------------------------
102
103 //------------------------------------------------------------------------------------------------
104 protected void InitActions()
105 {
107 {
108 if (!action)
109 continue;
110 action.Init(this);
111 }
112 }
113
114 //------------------------------------------------------------------------------------------------
115 protected void DeInitActions()
116 {
118 {
119 if (!action)
120 continue;
121 action.DeInit();
122 }
123 m_aEffectActions.Clear();
124 }
125
126
127 //------------------------------------------------------------------------------------------------
129 {
130 m_Manager = manager;
131 if (manager)
132 m_SignalManager = SignalsManagerComponent.Cast(manager.GetOwner().FindComponent(SignalsManagerComponent));
133
134 m_effectPosition.Init(manager.GetOwner());
135
136 InitActions();
137 }
138
139 //------------------------------------------------------------------------------------------------
140 void DeInit()
141 {
142 m_SignalManager = null;
143 m_Manager = null;
145 }
146
147 //------------------------------------------------------------------------------------------------
148 void Update(IEntity owner, float timeSlice)
149 {
151 {
152 if (!action)
153 continue;
154 action.Update();
155 }
156 }
157
158#ifdef WORKBENCH
159 //------------------------------------------------------------------------------------------------
160 void WB_Update(IEntity owner, float timeSlice)
161 {
163 //m_sParticleEffect.WB_Update(timeSlice);
164 }
165
166 //------------------------------------------------------------------------------------------------
167 void WB_OnInit(IEntity owner, inout vector mat[4], IEntitySource src)
168 {
169 TurnOff();
170 m_owner = owner;
171 WB_PlayEffect();
172 }
173#endif
174};
175
176//------------------------------------------------------------------------------------------------
177//Helicopter specific effect class
180{
181 [Attribute("10", UIWidgets.Auto, desc: "Time to play startup particle\n[s]")]
182 protected float m_fStartupTime;
183
184 protected SCR_HelicopterControllerComponent m_HelicopterController;
185
186 //------------------------------------------------------------------------------------------------
188 {
189 super.Init(manager)
190 //do the stuff here
191 }
192
193 //------------------------------------------------------------------------------------------------
194 override void Update(IEntity owner, float timeSlice)
195 {
196 super.Update(owner, timeSlice);
197 }
198};
199
207
208//------------------------------------------------------------------------------------------------
211{
212 [Attribute("0", UIWidgets.ComboBox, "Type of parameter to change", "", ParamEnumArray.FromEnum(SCR_EmitterParam))]
214 [Attribute(desc: "New value of the parameter")]
215 protected float m_fValue;
216
218 protected bool m_bPerformed = false;
219
220 //------------------------------------------------------------------------------------------------
221 void Init(notnull SCR_EffectModule module)
222 {
223 m_Module = module;
224 }
225
226 //------------------------------------------------------------------------------------------------
227 void DeInit()
228 {
229 m_Module = null;
230 }
231
232 //------------------------------------------------------------------------------------------------
233 void Update();
234
235 //------------------------------------------------------------------------------------------------
236 protected void PerformAction()
237 {
238 if (m_Parameter == SCR_EmitterParam.TURN_ON)
239 {
240 m_Module.TurnOn();
241 }
242 else if (m_Parameter == SCR_EmitterParam.TURN_OFF)
243 {
244 m_Module.TurnOff();
245 }
246 else if (m_Parameter == SCR_EmitterParam.BIRTHRATE)
247 {
248 m_Module.GetEmitter().GetParticles().SetParam(-1, EmitterParam.BIRTH_RATE, m_fValue);
249 }
250 else if (m_Parameter == SCR_EmitterParam.LIFETIME)
251 {
252
253 }
254 }
255}
256
257
258
259//------------------------------------------------------------------------------------------------
261class SCR_BaseEffectParticleSignalAction: SCR_BaseEffectParticleAction
262{
263 [Attribute(desc: "Signal which drives the effect")]
264 protected string m_sSignal;
265 [Attribute(defvalue: SCR_Enum.GetDefault(SCR_ComparerOperator.GREATER_THAN_OR_EQUAL), UIWidgets.ComboBox, "Cond operator", "", ParamEnumArray.FromEnum(SCR_ComparerOperator) )]
266 private SCR_ComparerOperator m_eOperator;
267 [Attribute(desc: "Value of signal when the action will be executed")]
268 protected float m_fSignalValue;
269 protected int m_iSignalID;
270 SignalsManagerComponent m_SignalManager;
271
272 //------------------------------------------------------------------------------------------------
273 override void Init(notnull SCR_EffectModule module)
274 {
275 super.Init(module);
276 m_SignalManager = module.GetSignalManager();
277 if (!m_SignalManager)
278 return;
279 m_iSignalID = m_SignalManager.FindSignal(m_sSignal);
280 }
281
282 //------------------------------------------------------------------------------------------------
283 override void DeInit()
284 {
285 m_SignalManager = null;
286 m_iSignalID = -1;
287 super.DeInit();
288 }
289
290 //------------------------------------------------------------------------------------------------
291 override void Update()
292 {
293 if (m_bPerformed)
294 {
295 if (m_SignalManager.GetSignalValue(m_iSignalID) == 0.0)
296 m_bPerformed = false; //if signal returns to 0.0, reset the flag
297 return;
298 }
299
300 //add option to do this only once until the next change
301 PrintFormat("Signal value = %1", m_SignalManager.GetSignalValue(m_iSignalID));
302
303 if (SCR_Comparer<float>.Compare(m_eOperator, (float)m_SignalManager.GetSignalValue(m_iSignalID), (float)m_fSignalValue ))
304 {
305 m_bPerformed = true;
307 }
308 }
309}
310
311
312enum EVehicleEvent
313{
314 ON_ENGINE_START,
315 ON_ENGINE_STOP,
316};
317
318//------------------------------------------------------------------------------------------------
321{
322 //TODO(zozo): this could be done better - some dynamic event getter would be useful
323 [Attribute(defvalue: "0", UIWidgets.ComboBox, "Events", "", ParamEnumArray.FromEnum(EVehicleEvent))]
324 protected EVehicleEvent m_eEvent;
325
326 [Attribute(defvalue: "0", desc: "Perform the action only once")]
327 protected bool m_bOnce;
328 protected SCR_HelicopterControllerComponent m_VehicleController;
330
331
332 //------------------------------------------------------------------------------------------------
333 protected void RegisterEvent()
334 {
335 switch(m_eEvent)
336 {
337 case EVehicleEvent.ON_ENGINE_START:
338 {
339 m_EventHandler = m_VehicleController.GetOnEngineStart();
340 break;
341 };
342 case EVehicleEvent.ON_ENGINE_STOP:
343 {
344 m_EventHandler = m_VehicleController.GetOnEngineStop();
345 break;
346 };
347 }
348
349 if (m_EventHandler)
351 }
352
353 //------------------------------------------------------------------------------------------------
354 override void Init(notnull SCR_EffectModule module)
355 {
356 super.Init(module);
357 IEntity owner = module.GetOwner();
358 if (!owner) //this would be weird, but doublecheck it
359 return;
360 m_VehicleController = SCR_HelicopterControllerComponent.Cast(owner.FindComponent(SCR_HelicopterControllerComponent));
362 {
363 Print("SCR_HelicopterControllerComponent controller not found. Action won't work", LogLevel.WARNING);
364 return;
365 }
367 }
368
369 //------------------------------------------------------------------------------------------------
370 override void DeInit()
371 {
372 m_VehicleController = null;
373 m_EventHandler.Clear();
374 super.DeInit();
375 }
376
377 //------------------------------------------------------------------------------------------------
378 override void PerformAction()
379 {
380 super.PerformAction();
381 if (m_bOnce)
383 }
384
385}
386
387//------------------------------------------------------------------------------------------------
390class SCR_BaseEffectParticleHelicopterRotorControlAction: SCR_BaseEffectParticleAction
391{
392 [Attribute( "", UIWidgets.EditBox, "Speed in m/s which tops the effect's interpolation from 100 to 0% lifetime value" )]
393 float m_ExhaustEndSpeedInM;
394
395 const string SIGNAL_RPM = "MainRotorRPM";
396 const int RPM_THRESHOLD = 50; //when to enable or disable the rotor wash effect
397 protected int m_iSignalID;
398 SignalsManagerComponent m_SignalManager;
399 ParticleEffectEntity m_EffectEntity;
400
401 //------------------------------------------------------------------------------------------------
402 override void Init(notnull SCR_EffectModule module)
403 {
404 super.Init(module);
405 m_SignalManager = module.GetSignalManager();
406 if (!m_SignalManager)
407 return;
408
409 m_iSignalID = m_SignalManager.FindSignal(SIGNAL_RPM);
410 }
411
412 //------------------------------------------------------------------------------------------------
413 override void Update()
414 {
415 //PrintFormat("Signal value = %1", m_SignalManager.GetSignalValue(m_iSignalID));
416
417 Particles particles;
418 if (m_EffectEntity)
419 particles = m_EffectEntity.GetParticles();
420
421 if (!particles && m_SignalManager.GetSignalValue(m_iSignalID) > RPM_THRESHOLD) // engine is started, but effect hasn't been yet created
422 {
423 m_Module.TurnOn();
424 }
425 else
426 if (particles && 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_EffectEntity = null;
430 particles = null;
431 }
432
433 if (!particles && m_Module.GetEmitter())
434 {
435 m_EffectEntity = m_Module.GetEmitter();
436 if (m_EffectEntity)
437 particles = m_EffectEntity.GetParticles(); // get the particles
438 }
439
440 if (!particles)
441 return;
442
443 if (m_ExhaustEndSpeedInM <= 0)
444 return;
445
446 Physics physics = m_Module.GetOwner().GetPhysics();
447 if (!physics)
448 return;
449
450 float speed_m_per_s = physics.GetVelocity().Length();
451 float lifetime_scale = Math.Clamp(1 - (speed_m_per_s / m_ExhaustEndSpeedInM), 0, 1);
452
453 particles.MultParam(-1, EmitterParam.LIFETIME, lifetime_scale);
454 particles.MultParam(-1, EmitterParam.LIFETIME_RND, lifetime_scale);
455 }
456}
override void Init()
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
SCR_ComparerOperator
Definition SCR_Comparer.c:3
void ParticleEffectEntity(IEntitySource src, IEntity parent)
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
ScriptInvokerBase< ScriptInvokerVoidMethod > ScriptInvokerVoid
SCR_VONRadialDisplay Compare
SignalsManagerComponent m_SignalManager
SCR_EmitterParam
@ BIRTHRATE
@ TURN_OFF
@ TURN_ON
enum EVehicleType IEntity
proto external Managed FindComponent(typename typeName)
PointInfo - allows to define position.
Definition PointInfo.c:9
void Init(notnull SCR_EffectModule module)
override void Init(notnull SCR_EffectModule module)
SCR_HelicopterControllerComponent m_VehicleController
override void Init(SCR_BaseEffectManagerComponent manager)
override void Update(IEntity owner, float timeSlice)
SCR_HelicopterControllerComponent m_HelicopterController
SignalsManagerComponent GetSignalManager()
SCR_BaseEffectManagerComponent m_Manager
SignalsManagerComponent m_SignalManager
ParticleEffectEntity m_sParticleEffect
ref array< ref SCR_BaseEffectParticleAction > m_aEffectActions
ref PointInfo m_effectPosition
void Init(SCR_BaseEffectManagerComponent manager)
void Update(IEntity owner, float timeSlice)
ParticleEffectEntity GetEmitter()
ResourceName m_sParticle
void CreateEmitter(bool PlayOnSpawn=false)
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
proto void PrintFormat(string fmt, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL, LogLevel level=LogLevel.NORMAL)
SCR_FieldOfViewSettings Attribute
EmitterParam
@ LIFETIME
Float.