Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_BuildingSoundComponent.c
Go to the documentation of this file.
1 [ComponentEditorProps(category: "GameScripted/Sound", description: "THIS IS THE SCRIPT DESCRIPTION.")]
3 {
4 }
5 
6 class SCR_BuildingSoundComponent : SoundComponent
7 {
8  [Attribute("8", UIWidgets.Slider, "Time interval when maximum WindSpeed [s]", "0 60 1")]
9  int m_iTimeIntervalMin;
10 
11  [Attribute("20", UIWidgets.Slider, "Time interval when minimum WindSpeed [s]", "0 60 1")]
13 
14  [Attribute("0 0 0", UIWidgets.Coords, "Mins OOB Point")]
15  vector m_vMins;
16 
17  [Attribute("0 0 0", UIWidgets.Coords, "Maxs OOB Point")]
18  vector m_vMaxs;
19 
20  private static const float RANDOM_PERCENTAGE_MIN = 0.7;
21  private static const float RANDOM_PERCENTAGE_MAX = 1.3;
22 
23  protected float m_fTriggerInterval;
24 
25  //------------------------------------------------------------------------------------------------
26  private void TriggeredSoundHandler(IEntity owner, float timeSlice)
27  {
28  vector mat[4];
29  Math3D.MatrixIdentity4(mat);
30  mat[3] = GetSoundPosition(owner);
31 
32  //Set Interior signal
33  SetInteriorSignal(owner);
34 
35  // Play sound
36  SoundEventTransform(SCR_SoundEvent.SOUND_CREAK, mat);
37 
38  // Get remetition time
40  }
41 
42  //------------------------------------------------------------------------------------------------
43  private void SetInteriorSignal(IEntity owner)
44  {
45  bool interior;
46 
47  float gInterior = GetGame().GetSignalsManager().GetSignalValue(GetGame().GetSignalsManager().AddOrFindSignal("GInterior"));
48 
49  if (gInterior == 1)
50  {
51  PlayerController playerControler = GetGame().GetPlayerController();
52  if (!playerControler)
53  return;
54 
55  PlayerCamera playerCamera = playerControler.GetPlayerCamera();
56  if (!playerCamera)
57  return;
58 
59  interior = IsInWorldBounds(playerCamera.GetOrigin(), owner);
60  }
61 
62  SignalsManagerComponent signalsManagerComponent = SignalsManagerComponent.Cast(owner.FindComponent(SignalsManagerComponent));
63  if (signalsManagerComponent)
64  signalsManagerComponent.SetSignalValue(signalsManagerComponent.AddOrFindSignal("Interior"), interior);
65  }
66 
67  //------------------------------------------------------------------------------------------------
68  private bool IsInWorldBounds(vector point, IEntity entity)
69  {
70  vector mins = vector.Zero;
71  vector maxs = vector.Zero;
72 
73  entity.GetWorldBounds(mins, maxs);
74 
75  return !(point[0] < mins[0] || point[0] > maxs[0] || point[1] < mins[1] || point[1] > maxs[1] || point[2] < mins[2] || point[2] > maxs[2]);
76  }
77 
78  //------------------------------------------------------------------------------------------------
79  private void GetTimeInterval()
80  {
81  float windSpeed = GetGame().GetSignalsManager().GetSignalValue(GetGame().GetSignalsManager().AddOrFindSignal("WindSpeed"));
82  float timeInterval = Interpolate(windSpeed, SCR_AmbientSoundsComponent.WINDSPEED_MIN, SCR_AmbientSoundsComponent.WINDSPEED_MAX, m_iTimeIntervalMax, m_iTimeIntervalMin);
83 
84  m_fTriggerInterval = Math.RandomFloat(timeInterval * RANDOM_PERCENTAGE_MIN, timeInterval * RANDOM_PERCENTAGE_MAX);
85  }
86 
87  //------------------------------------------------------------------------------------------------
88  private vector GetSoundPosition(IEntity owner)
89  {
90  vector v;
91  v[0] = Math.RandomFloat(m_vMins[0], m_vMaxs[0]);
92  v[1] = Math.RandomFloat(m_vMins[1], m_vMaxs[1]);
93  v[2] = Math.RandomFloat(m_vMins[2], m_vMaxs[2]);
94 
95  // From Local To World Space;
96  v = owner.CoordToParent(v);
97 
98  return v;
99  }
100 
101  //------------------------------------------------------------------------------------------------
102  private float Interpolate(float in, float Xmin, float Xmax, float Ymin, float Ymax)
103  {
104  if (in <= Xmin)
105  return Ymin;
106 
107  if (in >= Xmax)
108  return Ymax;
109 
110  return ((Ymin * (Xmax - in) + Ymax * (in - Xmin)) / (Xmax - Xmin));
111  }
112 
113  //------------------------------------------------------------------------------------------------
114  override void UpdateSoundJob(IEntity owner, float timeSlice)
115  {
116  m_fTriggerInterval -= timeSlice;
117 
118  if (m_fTriggerInterval > 0)
119  return;
120 
121  TriggeredSoundHandler(owner, timeSlice);
122  }
123 
124  //------------------------------------------------------------------------------------------------
125  override void OnUpdateSoundJobBegin(IEntity owner)
126  {
127  GetTimeInterval();
128  }
129 
130  //------------------------------------------------------------------------------------------------
131  // constructor
135  void SCR_BuildingSoundComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
136  {
137  SetScriptedMethodsCall(true);
138  }
139 }
ComponentEditorProps
SCR_FragmentEntityClass ComponentEditorProps
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_SoundEvent
Definition: SCR_SoundEvent.c:1
GetSignalsManager
proto external SignalsManagerComponent GetSignalsManager()
Returns the signals manager associated with this controller.
SoundComponentClass
Definition: SoundComponent.c:12
m_fTriggerInterval
protected float m_fTriggerInterval
Definition: SCR_BuildingSoundComponent.c:23
Attribute
SCR_BuildingSoundComponentClass SoundComponentClass Attribute("8", UIWidgets.Slider, "Time interval when maximum WindSpeed [s]", "0 60 1")] int m_iTimeIntervalMin
m_vMins
vector m_vMins
Definition: SCR_BuildingSoundComponent.c:15
IsInWorldBounds
private bool IsInWorldBounds(vector point, IEntity entity)
Definition: SCR_BuildingSoundComponent.c:68
SCR_AmbientSoundsComponent
Definition: SCR_AmbientSoundsComponent.c:17
m_vMaxs
vector m_vMaxs
Definition: SCR_BuildingSoundComponent.c:18
SoundEventTransform
proto external AudioHandle SoundEventTransform(string eventName, vector transf[])
Play a sound from a set transformation.
GetTimeInterval
private void GetTimeInterval()
Definition: SCR_BuildingSoundComponent.c:79
SetInteriorSignal
private void SetInteriorSignal(IEntity owner)
Definition: SCR_BuildingSoundComponent.c:43
TriggeredSoundHandler
private void TriggeredSoundHandler(IEntity owner, float timeSlice)
Definition: SCR_BuildingSoundComponent.c:26
OnUpdateSoundJobBegin
override void OnUpdateSoundJobBegin(IEntity owner)
Called when dynamic simulation is started.
Definition: SCR_BuildingSoundComponent.c:125
UpdateSoundJob
override void UpdateSoundJob(IEntity owner, float timeSlice)
Call when component is in range.
Definition: SCR_BuildingSoundComponent.c:114
AddOrFindSignal
SignalsManagerComponentClass GameComponentClass AddOrFindSignal(string signalName, float value=0)
GetSoundPosition
private vector GetSoundPosition(IEntity owner)
Definition: SCR_BuildingSoundComponent.c:88
SetScriptedMethodsCall
proto external void SetScriptedMethodsCall(bool state)
Set flag for script callbacks.
SCR_BuildingSoundComponentClass
Definition: SCR_BuildingSoundComponent.c:2
SCR_BuildingSoundComponent
void SCR_BuildingSoundComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_BuildingSoundComponent.c:135
Interpolate
private float Interpolate(float in, float Xmin, float Xmax, float Ymin, float Ymax)
Definition: SCR_BuildingSoundComponent.c:102
m_iTimeIntervalMax
int m_iTimeIntervalMax
Definition: SCR_BuildingSoundComponent.c:11
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180