Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_FireplaceComponent.c
Go to the documentation of this file.
1 [EntityEditorProps(category: "GameScripted", color: "0 0 255 255")]
3 {
4  [Attribute("{C0E2E7DC28B71E2C}Particles/Enviroment/Campfire_medium_normal.ptc", UIWidgets.ResourceNamePicker, "Prefab of fire particle used for a fire action.", "ptc")]
5  protected ResourceName m_sParticle;
6 
7  [Attribute("0 0.2 0", UIWidgets.EditBox, "Particle offset in local space from the origin of the entity")]
8  protected vector m_vParticleOffset;
9 
10  //------------------------------------------------------------------------------------------------
12  ResourceName GetParticle()
13  {
14  return m_sParticle;
15  }
16 
17  //------------------------------------------------------------------------------------------------
19  vector GetParticleOffset()
20  {
21  return m_vParticleOffset;
22  }
23 }
24 
25 class SCR_FireplaceComponent : SCR_BaseInteractiveLightComponent
26 {
27  private ParticleEffectEntity m_pFireParticle;
29  protected IEntity m_DecalEntity;
30  protected float m_fTimer;
31  protected float m_fCompDataLV;
32 
33  protected static const float FLICKER_STEP = 0.05;
34  protected static const float FLICKER_THRESHOLD = 0.35;
35  protected static const float FLICKER_FREQUENCY = 1 / 30;
36 
37  //------------------------------------------------------------------------------------------------
38  override void ToggleLight(bool turnOn, bool skipTransition = false, bool playSound = true)
39  {
40  if (m_bIsOn == turnOn)
41  return;
42 
43  super.ToggleLight(turnOn, skipTransition, playSound);
44 
45  // don't continue if DS server is running in console (particles, decals)
46  if (System.IsConsoleApp())
47  return;
48 
49  if (turnOn)
50  {
51  TurnOn();
52  }
53  else
54  {
55  TurnOff();
56  }
57  }
58 
59  //------------------------------------------------------------------------------------------------
61  void TurnOn()
62  {
63  SCR_FireplaceComponentClass componentData = SCR_FireplaceComponentClass.Cast(GetComponentData(GetOwner()));
64  if (!m_pFireParticle && componentData)
65  {
66  ParticleEffectEntitySpawnParams spawnParams = new ParticleEffectEntitySpawnParams();
67  spawnParams.TargetWorld = GetOwner().GetWorld();
68  spawnParams.Parent = GetOwner();
69  Math3D.MatrixIdentity4(spawnParams.Transform);
70  spawnParams.Transform[3] = componentData.GetParticleOffset();
71 
72  m_pFireParticle = ParticleEffectEntity.SpawnParticleEffect(componentData.GetParticle(), spawnParams);
73  }
74  else if (m_pFireParticle)
75  {
76  m_pFireParticle.Play();
77  }
78 
79  // Show decals
80  if (m_DecalEntity)
81  m_DecalEntity.SetFlags(EntityFlags.VISIBLE, false);
82 
83  if (componentData)
84  m_fCompDataLV = componentData.GetLightLV();
85 
86  SetEventMask(GetOwner(), EntityEvent.VISIBLE);
87  }
88 
89  //------------------------------------------------------------------------------------------------
91  void TurnOff()
92  {
93  // Hide decals
94  if (m_DecalEntity)
95  m_DecalEntity.ClearFlags(EntityFlags.VISIBLE, false);
96 
97  //Reset fire particles
98  if (m_pFireParticle)
99  {
100  m_pFireParticle.Stop();
101  }
102 
103  ClearEventMask(GetOwner(), EntityEvent.VISIBLE);
104  }
105 
106  //------------------------------------------------------------------------------------------------
107  override void OnPostInit(IEntity owner)
108  {
109  BaseSlotComponent decalComponent = BaseSlotComponent.Cast(GetOwner().FindComponent(BaseSlotComponent));
110  if (decalComponent)
111  m_DecalEntity = decalComponent.GetAttachedEntity();
112 
114  if (m_ComponentData)
115  m_fCurLV = m_ComponentData.GetLightLV();
116 
117  if (m_DecalEntity)
118  m_DecalEntity.ClearFlags(EntityFlags.VISIBLE, false);
119 
120  super.OnPostInit(owner);
121  }
122 
123  //------------------------------------------------------------------------------------------------
124  override void EOnVisible(IEntity owner, int frameNumber)
125  {
126  super.EOnVisible(owner, frameNumber);
127 
128  if (GetOwner().GetWorld().IsEditMode() || !IsOn() || m_aLights.IsEmpty())
129  return;
130 
131  float timeSlice = GetOwner().GetWorld().GetTimeSlice();
132 
133  m_fTimer += timeSlice;
134 
135  if (m_fTimer < FLICKER_FREQUENCY)
136  return;
137 
138  m_fTimer = 0;
139  bool canFlickerBrighter = m_fCurLV < m_fCompDataLV * (1 + FLICKER_THRESHOLD);
140  bool canFlickerDimmer = m_fCurLV > m_fCompDataLV * (1 - FLICKER_THRESHOLD);
141 
142  if (canFlickerBrighter && canFlickerDimmer)
143  {
144  if (Math.RandomIntInclusive(0, 1) == 0)
145  m_fCurLV += FLICKER_STEP;
146  else
147  m_fCurLV -= FLICKER_STEP;
148  }
149  else if (canFlickerBrighter)
150  m_fCurLV += FLICKER_STEP;
151  else
152  m_fCurLV -= FLICKER_STEP;
153 
154  array<ref SCR_BaseLightData> lightData = m_ComponentData.GetLightData();
155  for (int i = Math.Min(m_aLights.Count(), lightData.Count()) -1; i >= 0; i--)
156  {
157  auto ld = lightData[i]; // make sure that data is loaded
158  if (ld)
159  m_aLights[i].SetColor(Color.FromVector(ld.GetLightColor()), m_fCurLV);
160  }
161  }
162 
163  //------------------------------------------------------------------------------------------------
164  override bool RplLoad(ScriptBitReader reader)
165  {
166  // Can't relay on RplLoad method of base class as with the fireplace we have to execute ToggleLight method in both on / off state.
167  bool isOn = false;
168  reader.ReadBool(isOn);
169  ToggleLight(isOn, true);
170 
171  return true;
172  }
173 
174  override void OnDelete(IEntity owner)
175  {
176  super.OnDelete(owner);
177 
178  RemoveLights();
179 
180  if (m_pFireParticle)
181  RplComponent.DeleteRplEntity(m_pFireParticle, false);
182  }
183 }
m_DecalEntity
protected IEntity m_DecalEntity
Definition: SCR_FireplaceComponent.c:29
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
m_ComponentData
protected SCR_BaseInteractiveLightComponentClass m_ComponentData
Definition: SCR_FireplaceComponent.c:28
SCR_BaseInteractiveLightComponentClass
Definition: SCR_BaseInteractiveLightComponent.c:2
TurnOff
void TurnOff()
Remove every particle associed with this effect.
Definition: SCR_FireplaceComponent.c:91
RemoveLights
void RemoveLights()
Definition: SCR_BaseInteractiveLightComponent.c:296
m_fCompDataLV
protected float m_fCompDataLV
Definition: SCR_FireplaceComponent.c:31
ToggleLight
override void ToggleLight(bool turnOn, bool skipTransition=false, bool playSound=true)
Definition: SCR_FireplaceComponent.c:38
OnDelete
override void OnDelete(IEntity owner)
Definition: SCR_FireplaceComponent.c:174
IsOn
bool IsOn()
Definition: SCR_BaseInteractiveLightComponent.c:88
TurnOn
void TurnOn()
Definition: SCR_FireplaceComponent.c:61
m_pFireParticle
SCR_FireplaceComponentClass m_pFireParticle
Attribute
typedef Attribute
Post-process effect of scripted camera.
RplLoad
override bool RplLoad(ScriptBitReader reader)
Definition: SCR_FireplaceComponent.c:164
m_aLights
SCR_BaseInteractiveLightComponentClass m_aLights
OnPostInit
override void OnPostInit(IEntity owner)
Called on PostInit when all components are added.
Definition: SCR_FireplaceComponent.c:107
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
EOnVisible
override void EOnVisible(IEntity owner, int frameNumber)
Definition: SCR_FireplaceComponent.c:124
m_fCurLV
protected float m_fCurLV
Definition: SCR_BaseInteractiveLightComponent.c:47
SCR_FireplaceComponentClass
Definition: SCR_FireplaceComponent.c:2
m_bIsOn
protected bool m_bIsOn
Definition: SCR_BaseInteractiveLightComponent.c:50
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180
m_fTimer
protected float m_fTimer
Definition: SCR_FireplaceComponent.c:30