Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
TreeDebrisSmallEntity.c
Go to the documentation of this file.
1[EntityEditorProps(category: "GameScripted/Debris", description: "Entity used to represent small chunks of tree debris.", dynamicBox: true)]
5
6class SCR_TreeDebrisSmallEntity : SCR_BaseDebrisSmallEntity
7{
8 [Attribute(defvalue:"30", params:"0 inf", desc:"How long until the debris despawns (seconds)")]
9 float m_fTimeToDespawn;
10
11 [Attribute(defvalue:"10", params:"0 inf", desc:"Randomly increases despawn time by 0 to x (seconds)")]
12 int m_iDespawnRandomizationTime;
13
14 [Attribute(defvalue:"5000", params:"0 inf", desc:"Distance from camera when entity will be deleted")]
15 float m_fMaxDistance;
16
17 [Attribute()]
18 ref SCR_AudioSourceConfiguration m_audioSourceConfigurationImpact;
19
20 [Attribute()]
21 ref SCR_AudioSourceConfiguration m_audioSourceConfigurationBreak;
22
24 protected vector m_vSoundPositionLast;
25
27 protected float m_fEntityDimensionMax;
28
30 protected float m_fMinimalDistance;
31
33 protected float m_fSoundCoolDownEnd;
34
36 protected float m_fSoundThreshold;
37
39 protected AudioHandle m_AudioHandleDebrisImpact = AudioHandle.Invalid;
40
42 protected AudioHandle m_AudioHandleDebrisBreak = AudioHandle.Invalid;
43
45 protected static const float TREE_KINETIC_ENERGY_THRESHOLD = 20;
46
48 protected static const float DEBRIS_BREAK_TIME_MIN = 0.7;
49
51 protected static const float ENTITY_SIZE_FACTOR = 0.06;
52
53 //------------------------------------------------------------------------------------------------
54 void SCR_TreeDebrisSmallEntity(IEntitySource src, IEntity parent)
55 {
56 m_fLifeTime = m_fTimeToDespawn;
57
58 m_fLifeTime = m_fLifeTime + Math.RandomInt(0, m_iDespawnRandomizationTime);
59
60 SetEventMask(EntityEvent.INIT);
61 SetFlags(EntityFlags.ACTIVE, true);
62 }
63
64 //------------------------------------------------------------------------------------------------
65 override void EOnContact(IEntity owner, IEntity other, Contact contact)
66 {
67 if (m_bDelete)
68 return;
69
70 float spdDiff = contact.GetRelativeNormalVelocityAfter() - contact.GetRelativeNormalVelocityBefore();
71
72 // Play sound
73 if (spdDiff > m_fSoundThreshold && vector.DistanceSq(m_vSoundPositionLast, contact.Position) >= m_fMinimalDistance && m_fAgeTime > MINIMAL_AGE && m_fAgeTime > m_fSoundCoolDownEnd)
74 PlaySound(contact.Position, spdDiff);
75
76 // Sound debug
77#ifdef ENABLE_DIAG
78 m_fdVelocity = spdDiff;
79#endif // ENABLE_DIAG
80 }
81
82 //------------------------------------------------------------------------------------------------
83 void PlaySound(vector pos, float dVelocity)
84 {
85 // Get SoundManager
86 SCR_SoundManagerModule soundManager = SCR_SoundManagerModule.GetInstance(GetWorld());
87 if (!soundManager)
88 return;
89
90 SCR_AudioSource audioSource = soundManager.CreateAudioSource(this, m_audioSourceConfigurationImpact, pos);
91 if (!audioSource)
92 return;
93
94 // Stop previous sound and/or debris break sound
95 AudioSystem.TerminateSound(m_AudioHandleDebrisImpact);
96
97 if (m_AudioHandleDebrisBreak != AudioHandle.Invalid && m_fAgeTime >= DEBRIS_BREAK_TIME_MIN)
98 {
99 AudioSystem.TerminateSound(m_AudioHandleDebrisBreak);
100 m_AudioHandleDebrisBreak = AudioHandle.Invalid;
101 }
102
103 // Set signals
104 audioSource.SetSignalValue(SCR_AudioSource.COLLISION_D_V_SIGNAL_NAME, dVelocity - m_fSoundThreshold);
105 audioSource.SetSignalValue(SCR_AudioSource.ENTITY_SIZE_SIGNAL_NAME, GetPhysics().GetMass());
106
107 // Play sound
108 soundManager.PlayAudioSource(audioSource);
109 m_AudioHandleDebrisImpact = audioSource.m_AudioHandle;
110
111 // Store position of the last played sound
112 m_vSoundPositionLast = pos;
113
114 // Set CoolDown based on boundingbox size
115 m_fSoundCoolDownEnd = m_fAgeTime + m_fEntityDimensionMax * ENTITY_SIZE_FACTOR;
116
117#ifdef ENABLE_DIAG
118 SoundDebugPlaySound(m_fSoundThreshold, dVelocity, pos);
119#endif // ENABLE_DIAG
120 }
121
122 //------------------------------------------------------------------------------------------------
123 override void EOnFrame(IEntity owner, float timeSlice)
124 {
125 super.EOnFrame(owner, timeSlice);
126
127 // Check if within camera range, set to delete if not.
128 if (!m_bDelete)
129 {
130 const float distance = GetDistanceToCamera(owner.GetWorld(), owner.GetOrigin());
131 if (distance >= m_fMaxDistance)
132 DeleteDebris();
133 }
134
135#ifdef ENABLE_DIAG
136 SoundDebugOnFrame(m_fSoundThreshold);
137#endif // ENABLE_DIAG
138 }
139
140 //------------------------------------------------------------------------------------------------
142 override void EOnInit(IEntity owner)
143 {
144 // Play "debris break" sound if defined
145 if (m_audioSourceConfigurationBreak && m_audioSourceConfigurationBreak.IsValid())
146 {
147 // Get SoundManager
148 SCR_SoundManagerModule soundManager = SCR_SoundManagerModule.GetInstance(owner.GetWorld());
149 if (!soundManager)
150 return;
151
152 SCR_AudioSource audioSource = soundManager.CreateAudioSource(this, m_audioSourceConfigurationBreak);
153 if (!audioSource)
154 return;
155
156 audioSource.SetSignalValue(SCR_AudioSource.ENTITY_SIZE_SIGNAL_NAME, GetPhysics().GetMass());
157 soundManager.PlayAudioSource(audioSource);
158 m_AudioHandleDebrisBreak = audioSource.m_AudioHandle;
159 }
160
161 // Only activate OnContact event and proceed if the audioSourceConfiguration is valid
162 if (m_audioSourceConfigurationImpact && m_audioSourceConfigurationImpact.IsValid())
163 {
164 SetEventMask(EntityEvent.CONTACT);
165
166 // Get bounding volume, set member variables
167 vector mins, maxs;
168 GetBounds(mins, maxs);
169 m_fEntityDimensionMax = Math.Max(maxs[0] - mins[0], Math.Max(maxs[1] - mins[1], maxs[2] - mins[2]));
170
171 m_fMinimalDistance = MINIMAL_DISTANCE_SQ * m_fEntityDimensionMax;
172
173 m_fSoundThreshold = Math.Sqrt(2 * TREE_KINETIC_ENERGY_THRESHOLD / GetPhysics().GetMass());
174
175 m_vSoundPositionLast = vector.Lerp(mins, maxs, 0.5);
176 }
177 }
178
179 //------------------------------------------------------------------------------------------------
180 override void EOnPhysicsActive(IEntity owner, bool activeState)
181 {
182 if (!activeState)
183 {
184 owner.GetPhysics().ChangeSimulationState(SimulationState.COLLISION);
185 ClearEventMask(EntityEvent.SIMULATE | EntityEvent.PHYSICSACTIVE);
186 }
187 }
188}
SCR_BaseDebrisSmallEntityClass m_bDelete
Whether this debris has reached end of its lifetime and should be deleted.
void SCR_BaseDebrisSmallEntity(IEntitySource src, IEntity parent)
float m_fLifeTime
The lifetime in seconds.
float m_fAgeTime
Entity age in seconds. After this time is bigger thatn m_fLifeTime, debris will despawn.
void DeleteDebris()
Delete debris - unregisters it from the list and makes it scale down and delete.
void SCR_AudioSource(SCR_AudioSourceConfiguration audioSourceConfiguration, vector mat[4])
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
float distance
void PlaySound(string soundName)
override void EOnContact(IEntity owner, IEntity other, Contact contact)
override void EOnFrame(IEntity owner, float timeSlice)
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
void EOnPhysicsActive(IEntity owner, bool activeState)
proto external vector GetOrigin()
proto external Physics GetPhysics()
proto external BaseWorld GetWorld()
Definition Math.c:13
override void EOnInit(IEntity owner)
SCR_FieldOfViewSettings Attribute
EntityEvent
Various entity events.
Definition EntityEvent.c:14
EntityFlags
Various entity flags.
Definition EntityFlags.c:14
SimulationState