Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_LightningComponent.c
Go to the documentation of this file.
1 [ComponentEditorProps(category: "GameScripted", description: "")]
2 class SCR_LightningComponentClass : ScriptComponentClass
3 {
4 }
5 
7 class SCR_LightningComponent : ScriptComponent
8 {
9  protected ref RandomGenerator m_pRandomGenerator = new RandomGenerator();
10 
11  [Attribute(defvalue: "4")]
12  protected int m_iMinFlashes;
13 
14  [Attribute(defvalue: "8")]
15  protected int m_iMaxFlashes;
16 
17  [Attribute(defvalue: "25")];
18  protected float m_fFlashMinDurationMillis;
19 
20  [Attribute(defvalue: "200")];
21  protected float m_fFlashMaxDurationMillis;
22 
23  [Attribute(defvalue: "30")];
24  protected float m_fFlashMinCooldownMillis;
25 
26  [Attribute(defvalue: "100")];
27  protected float m_fFlashMaxCooldownMillis;
28 
29  [Attribute(defvalue: "1")]
31 
32  [Attribute(defvalue: "3")]
34 
35 
36  [RplProp(onRplName: "OnFlashesRpl")]
37  protected int m_iNumFlashes;
38 
39  [RplProp(onRplName: "OnFlashesRpl")]
40  protected float m_fRadiusKM;
41 
42  [RplProp(onRplName: "OnFlashesRpl")]
43  protected ref array<float> m_aFlashesStartTime = {};
44 
45  [RplProp(onRplName: "OnFlashesRpl")]
46  protected ref array<float> m_aFlashesDuration = {};
47 
48  [RplProp(onRplName: "OnFlashesRpl")]
49  protected ref array<float> m_aFlashesCooldownDuration = {};
50 
51  protected int m_iCurFlashIndex;
52 
53  //------------------------------------------------------------------------------------------------
55  void OnFlashesRpl()
56  {
58  && m_iNumFlashes == m_aFlashesStartTime.Count()
59  && m_aFlashesStartTime.Count() == m_aFlashesDuration.Count()
60  && m_aFlashesStartTime.Count() == m_aFlashesCooldownDuration.Count())
61  {
62  ChimeraWorld world = GetOwner().GetWorld();
63  TimeAndWeatherManagerEntity tawme =world.GetTimeAndWeatherManager();
64  if(!tawme)
65  return;
66 
67  //inform weather entity
68  WeatherLightning wl = new WeatherLightning();
69  wl.SetPosition(GetOwner().GetOrigin());
70  wl.SetRadius(m_fRadiusKM);
71 
72  for(int n = m_iCurFlashIndex; n < m_aFlashesStartTime.Count(); n++)
73  {
74  WeatherLightningFlash wlf = new WeatherLightningFlash();
75 
76  wlf.SetStartTime(m_aFlashesStartTime[n]);
77  wlf.SetDuration(m_aFlashesDuration[n]);
78  wlf.SetCooldown(m_aFlashesCooldownDuration[n]);
79 
80  wl.AddLightningFlash(wlf);
81  }
82 
83  tawme.AddLightning(wl);
85  }
86  }
87 
88  //------------------------------------------------------------------------------------------------
89  override void OnPostInit(IEntity owner)
90  {
91  m_iCurFlashIndex = 0;
92 
93  //SetEventMask(owner, EntityEvent.FRAME);
94  RplComponent rpl = RplComponent.Cast(owner.FindComponent(RplComponent));
95 
96  ChimeraWorld world = ChimeraWorld.CastFrom(GetOwner().GetWorld());
97  if(!world)
98  return;
99 
100  TimeAndWeatherManagerEntity tawme = world.GetTimeAndWeatherManager();
101  if(!tawme)
102  return;
103 
104  if(rpl && rpl.Role() == RplRole.Authority)
105  {
107  m_iNumFlashes = m_iMinFlashes + ((int)(m_pRandomGenerator.RandFloat01() * ((float)m_iMaxFlashes - (float)m_iMinFlashes)));
108 
109  //decide whether to use game time or global engine time, however,
110  //if we use game time and auto-advancement is disabled, this will mess
111  //with the lightnings, or any other effect based on game time.
112  float curEngineTime = tawme.GetEngineTime();
113 
114  for(int n = 0; n < m_iNumFlashes; n++)
115  {
116  float flashStartTime = curEngineTime;
117  float flashDuration = (m_pRandomGenerator.RandFloatXY(m_fFlashMinDurationMillis, m_fFlashMaxDurationMillis) * 0.001);
118  float flashCooldownDuration = (m_pRandomGenerator.RandFloatXY(m_fFlashMinCooldownMillis, m_fFlashMaxCooldownMillis) * 0.001);
119 
120  curEngineTime += (flashDuration + flashCooldownDuration);
121 
122  m_aFlashesStartTime.Insert(flashStartTime);
123  m_aFlashesDuration.Insert(flashDuration);
124  m_aFlashesCooldownDuration.Insert(flashCooldownDuration);
125  }
126 
127  OnFlashesRpl();
128  }
129  }
130 }
m_fFlashMaxDurationMillis
protected float m_fFlashMaxDurationMillis
Definition: SCR_LightningComponent.c:20
ComponentEditorProps
SCR_FragmentEntityClass ComponentEditorProps
ChimeraWorld
Definition: ChimeraWorld.c:12
m_iMinFlashes
protected int m_iMinFlashes
Definition: SCR_LightningComponent.c:12
ScriptComponent
SCR_SiteSlotEntityClass ScriptComponent
m_aFlashesStartTime
protected ref array< float > m_aFlashesStartTime
Definition: SCR_LightningComponent.c:43
RplProp
SCR_RplTestEntityClass RplProp
Used for handling entity spawning requests for SCR_CatalogEntitySpawnerComponent and inherited classe...
m_fFlashMinDurationMillis
protected float m_fFlashMinDurationMillis
Definition: SCR_LightningComponent.c:17
m_fFlashMinVisibilityRadiusKM
protected float m_fFlashMinVisibilityRadiusKM
Definition: SCR_LightningComponent.c:30
m_pRandomGenerator
SCR_LightningComponentClass m_pRandomGenerator
Inform the weather manager a lightning has been spawned. Weather Manager will handle light changes.
m_iMaxFlashes
protected int m_iMaxFlashes
Definition: SCR_LightningComponent.c:15
OnFlashesRpl
void OnFlashesRpl()
Definition: SCR_LightningComponent.c:55
GetOrigin
vector GetOrigin()
Definition: SCR_AIUtilityComponent.c:279
Attribute
typedef Attribute
Post-process effect of scripted camera.
m_iNumFlashes
protected int m_iNumFlashes
Definition: SCR_LightningComponent.c:37
OnPostInit
override void OnPostInit(IEntity owner)
Called on PostInit when all components are added.
Definition: SCR_LightningComponent.c:89
m_fFlashMaxCooldownMillis
protected float m_fFlashMaxCooldownMillis
Definition: SCR_LightningComponent.c:26
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
SCR_LightningComponentClass
Definition: SCR_LightningComponent.c:2
m_aFlashesDuration
protected ref array< float > m_aFlashesDuration
Definition: SCR_LightningComponent.c:46
m_fFlashMaxVisibilityRadiusKM
protected float m_fFlashMaxVisibilityRadiusKM
Definition: SCR_LightningComponent.c:33
m_aFlashesCooldownDuration
protected ref array< float > m_aFlashesCooldownDuration
Definition: SCR_LightningComponent.c:49
m_fFlashMinCooldownMillis
protected float m_fFlashMinCooldownMillis
Definition: SCR_LightningComponent.c:23
m_iCurFlashIndex
protected int m_iCurFlashIndex
Definition: SCR_LightningComponent.c:51
m_fRadiusKM
protected float m_fRadiusKM
Definition: SCR_LightningComponent.c:40
int
SCR_PossessingManagerComponentClass int
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180