Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_SoundHandle.c
Go to the documentation of this file.
1 [BaseContainerProps(configRoot: true)]
3 {
5  vector m_aMat[4];
6 
8  int m_iSoundGroup;
9 
11  int m_iSoundType;
12 
14  int m_iSoundDef;
15 
17  SCR_SoundDef m_SoundDef;
18 
20  ref array<int> m_aRepTime;
21 
23  int m_iRepTimeIdx;
24 
26  float m_fDensity;
27 
28  //------------------------------------------------------------------------------------------------
32  void UpdateDensity(float sampleLenght, float worldTime)
33  {
34  float sequenceLenght = GetSequenceLenght(worldTime);
35  if (sequenceLenght == 0)
36  {
37  m_fDensity = 0;
38  return;
39  }
40 
41  m_fDensity = Math.Clamp(sampleLenght * m_aRepTime.Count() / sequenceLenght, 0, 1) * 100;
42  }
43 
44  //------------------------------------------------------------------------------------------------
48  float GetSequenceLenght(float worldTime)
49  {
50  int size = m_aRepTime.Count();
51  if (size == 0)
52  return 0;
53  else
54  return m_aRepTime[size - 1] - worldTime + m_SoundDef.m_iSampleLength;
55  }
56 
57  //------------------------------------------------------------------------------------------------
58  protected int GetRandomInt(int value, int random)
59  {
60  if (random == 0)
61  return value;
62 
63  int min = value - random;
64  if (min < 1)
65  min = 1;
66 
67  return Math.RandomIntInclusive(min, value + random);
68  }
69 
70  //------------------------------------------------------------------------------------------------
71  protected void CreateSequence(array<ref SCR_SequenceDef> sequenceDefinitions, int idx)
72  {
73  SCR_SequenceDef sequenceDefinition = sequenceDefinitions[idx];
74 
75  for (int i = 0, count = GetRandomInt(sequenceDefinition.m_iRepCount, sequenceDefinition.m_iRepCountRnd); i < count; i++)
76  {
77  if (i > 0)
78  m_aRepTime.Insert(GetRandomInt(sequenceDefinition.m_iRepTime, sequenceDefinition.m_iRepTimeRnd) + m_aRepTime[m_aRepTime.Count() - 1]);
79 
80  int idxNew = idx - 1;
81  if (idxNew >= 0)
82  CreateSequence(sequenceDefinitions, idxNew);
83  }
84  }
85 
86  //------------------------------------------------------------------------------------------------
89  void UpdateRepTime(float gameTime)
90  {
91  if (m_aRepTime)
92  m_aRepTime.Clear();
93  else
94  m_aRepTime = {};
95 
96  m_aRepTime.Insert(gameTime + GetRandomInt(m_SoundDef.m_iStartDelay, m_SoundDef.m_iStartDelayRnd));
97 
98  if (m_SoundDef.m_aSequenceDef.Count() == 0)
99  Print("AmbientSoundsComponent: " + typename.EnumToString(ESoundName, m_SoundDef.m_eSoundName) + " is missing sequence definition", LogLevel.WARNING);
100  else
101  CreateSequence(m_SoundDef.m_aSequenceDef, m_SoundDef.m_aSequenceDef.Count() - 1);
102  }
103 
104  //------------------------------------------------------------------------------------------------
105  // constructor
112  void SCR_SoundHandle(int soundGroupIdx, int soundTypeIdx, int soundDefIdx, vector mat[4], array<ref SCR_SoundGroup> soundGroup, float worldTime)
113  {
114  m_iSoundGroup = soundGroupIdx;
115  m_iSoundType = soundTypeIdx;
116  m_iSoundDef = soundDefIdx;
117  m_aMat = mat;
118  m_SoundDef = soundGroup[soundGroupIdx].m_aSoundType[soundTypeIdx].m_aSoundDef[soundDefIdx];
119  UpdateRepTime(worldTime);
120  UpdateDensity(m_SoundDef.m_iSampleLength, worldTime);
121  }
122 }
SCR_SequenceDef
Definition: SCR_SequenceDef.c:2
ESoundName
ESoundName
Definition: SCR_SoundDef.c:1
SCR_SoundHandle
Definition: SCR_SoundHandle.c:2
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