Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_MovingSoundSourceManagerEntity.c
Go to the documentation of this file.
1[EntityEditorProps(category: "GameScripted/Sound", description: "Spawns moving sounds around camera")]
2class SCR_MovingSoundSourceEntityClass : GenericEntityClass
3{
4};
5
6class SCR_MovingSoundSourceEntity : GenericEntity
7{
8 [Attribute("", UIWidgets.ResourceNamePicker, desc: "Sound project name (acp)", "acp")]
10
11 [Attribute("", UIWidgets.Auto, desc: "Sound event name that will be triggered",)]
12 protected string m_SoundEventName;
13
14 [Attribute("0", UIWidgets.Slider, "[s]", "0 1000 1")]
15 protected int m_iTriggerInterval;
16
17 [Attribute("0", UIWidgets.Slider, "[m]", "0 10000 1")]
18 protected int m_iTrajectoryHeight;
19
20 [Attribute("0", UIWidgets.Slider, "[m]", "0 10000 1")]
21 protected int m_iTrajectoryDistance;
22
23 [Attribute("0", UIWidgets.Slider, "[m]", "0 10000 1")]
24 protected int m_iTrajectoryLenght;
25
26 [Attribute("0", UIWidgets.Slider, "[m/s]", "0 1000 1")]
27 protected int m_iMovementSpeed;
28
29 private float m_fTime = 30;
30
31 private ref array<ref SCR_MoveData> m_aMoveData = new array<ref SCR_MoveData>;
32
33 //------------------------------------------------------------------------------------------------
34 void PlayMoveSound(float timeSlice)
35 {
36 m_fTime += timeSlice;
37
38 if (m_fTime <= m_iTriggerInterval)
39 return;
40
41 m_fTime = 0;
42
43 SCR_MoveData moveData = GetMoveData();
44
45 vector mat[4];
46 Math3D.MatrixIdentity4(mat);
47 mat[3] = moveData.m_vPosition;
48
49 moveData.m_AudioHandle = AudioSystem.PlayEvent(m_sSoundProjectName, m_SoundEventName, mat);
50
51 if (moveData.m_AudioHandle == AudioHandle.Invalid)
52 return;
53
54 m_aMoveData.Insert(moveData);
55 }
56
57
58 //------------------------------------------------------------------------------------------------
59 SCR_MoveData GetMoveData()
60 {
61 // Get camera position
62 vector mat[4];
63 this.GetWorld().GetCurrentCamera(mat);
64 vector cameraPosition = mat[3];
65
66 SCR_MoveData moveData = new SCR_MoveData;
67
68 // Get start and end point
69 int side = Math.RandomIntInclusive(0, 1);
70 if( side == 0)
71 side = -1;
72
73 const int trajectoryDistance = cameraPosition[0] - m_iTrajectoryDistance * side;
74
75 vector A, B;
76
77 A[0] = trajectoryDistance;
78 B[0] = trajectoryDistance;
79
80 const float trajectoryLenght = m_iTrajectoryLenght * 0.5 * side;
81
82 A[2] = cameraPosition[2] + trajectoryLenght;
83 B[2] = cameraPosition[2] - trajectoryLenght;
84
85 // Get height
86 A[1] = m_iTrajectoryHeight * Math.RandomFloat(0.8, 1.2);
87 B[1] = m_iTrajectoryHeight * Math.RandomFloat(0.8, 1.2);
88
89 // Get time
90 moveData.m_fOveralMoveTime = m_iTrajectoryLenght / m_iMovementSpeed;
91
92 // Get velocity
93 vector velocity = B - A;
94 velocity /= moveData.m_fOveralMoveTime;
95
96 moveData.m_vPosition = A;
97 moveData.m_vVelocity = velocity;
98
99 return moveData;
100 }
101
102 //------------------------------------------------------------------------------------------------
103 void UpdateFlySoundPosition(float timeSlice)
104 {
105 int count = m_aMoveData.Count();
106
107 if (count == 0)
108 return;
109
110 count--;
111
112 for (int i = count; i >= 0; i--)
113 {
114 SCR_MoveData moveData = m_aMoveData[i];
115
116 // Sound finished playing
117 if (AudioSystem.IsSoundPlayed(moveData.m_AudioHandle))
118 {
119 m_aMoveData.Remove(i);
120 return;
121 }
122
123 moveData.m_fMoveTime += timeSlice;
124
125 // Remove when movement is over
126 if(moveData.m_fMoveTime >= moveData.m_fOveralMoveTime)
127 {
128 AudioSystem.TerminateSound(moveData.m_AudioHandle);
129 m_aMoveData.Remove(i);
130 return;
131 }
132
133 moveData.m_vPosition += moveData.m_vVelocity * timeSlice;
134
135 vector mat[4];
136 Math3D.MatrixIdentity4(mat);
137 mat[3] = moveData.m_vPosition;
138
139 AudioSystem.SetSoundTransformation(moveData.m_AudioHandle, mat);
140 }
141 }
142
143 //------------------------------------------------------------------------------------------------
144 void Terminate()
145 {
146 foreach(SCR_MoveData moveData : m_aMoveData)
147 {
148 AudioSystem.TerminateSoundFadeOut(moveData.m_AudioHandle, false, 0);
149 }
150 }
151
152 //------------------------------------------------------------------------------------------------
153 override void EOnPostFrame(IEntity owner, float timeSlice)
154 {
155 PlayMoveSound(timeSlice);
156 UpdateFlySoundPosition(timeSlice);
157 }
158
159 //------------------------------------------------------------------------------------------------
160 void SCR_MovingSoundSourceEntity(IEntitySource src, IEntity parent)
161 {
162 SetEventMask(EntityEvent.POSTFRAME | EntityEvent.INIT);
163 SetFlags(EntityFlags.NO_TREE | EntityFlags.NO_LINK);
164 }
165
166 //------------------------------------------------------------------------------------------------
167 void ~SCR_MovingSoundSourceEntity()
168 {
169 Terminate();
170 }
171
172}
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
void IEntity(IEntitySource src, IEntity parent)
protected script Constructor
proto external EntityEvent SetEventMask(EntityEvent e)
proto external BaseWorld GetWorld()
proto external EntityFlags SetFlags(EntityFlags flags, bool recursively=false)
Definition Math.c:13
SCR_FieldOfViewSettings Attribute
EntityEvent
Various entity events.
Definition EntityEvent.c:14
EntityFlags
Various entity flags.
Definition EntityFlags.c:14