Arma Reforger Explorer
1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Toggle main menu visibility
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
)]
2
class
SCR_TreeDebrisSmallEntityClass
:
SCR_BaseDebrisSmallEntityClass
3
{
4
}
5
6
class
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
}
m_bDelete
SCR_BaseDebrisSmallEntityClass m_bDelete
Whether this debris has reached end of its lifetime and should be deleted.
SCR_BaseDebrisSmallEntity
void SCR_BaseDebrisSmallEntity(IEntitySource src, IEntity parent)
Definition
BaseDebrisSmallEntity.c:127
m_fLifeTime
float m_fLifeTime
The lifetime in seconds.
Definition
BaseDebrisSmallEntity.c:20
m_fAgeTime
float m_fAgeTime
Entity age in seconds. After this time is bigger thatn m_fLifeTime, debris will despawn.
Definition
BaseDebrisSmallEntity.c:23
DeleteDebris
void DeleteDebris()
Delete debris - unregisters it from the list and makes it scale down and delete.
Definition
BaseDebrisSmallEntity.c:120
SCR_AudioSource
void SCR_AudioSource(SCR_AudioSourceConfiguration audioSourceConfiguration, vector mat[4])
Definition
SCR_AudioSource.c:139
EntityEditorProps
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
Definition
SCR_CompassComponent.c:10
distance
float distance
Definition
SCR_DestructibleTreeV2.c:29
PlaySound
void PlaySound(string soundName)
Definition
SCR_DetonatorGadgetComponent.c:292
EOnContact
override void EOnContact(IEntity owner, IEntity other, Contact contact)
Definition
SCR_ParticleContactComponent.c:82
EOnFrame
override void EOnFrame(IEntity owner, float timeSlice)
Definition
SCR_PlayerProfileManagerComponent.c:169
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition
SCR_RespawnBriefingComponent.c:17
params
category params
Definition
SCR_SpherePointGeneratorPreviewComponent.c:21
category
params category
Definition
SCR_VehicleDamageManagerComponent.c:302
EOnPhysicsActive
void EOnPhysicsActive(IEntity owner, bool activeState)
Definition
SCR_VehicleDamageManagerComponent.c:1820
AudioHandle
Definition
EnAudio.c:9
AudioSystem
Definition
AudioSystem.c:13
Contact
Definition
Contact.c:16
IEntity
Definition
IEntity.c:13
IEntity::GetOrigin
proto external vector GetOrigin()
IEntity::GetPhysics
proto external Physics GetPhysics()
IEntity::GetWorld
proto external BaseWorld GetWorld()
IEntitySource
Definition
IEntitySource.c:13
Math
Definition
Math.c:13
SCR_BaseDebrisSmallEntityClass
Definition
BaseDebrisSmallEntity.c:5
SCR_SoundManagerModule
Definition
SCR_SoundManagerModule.c:12
SCR_TreeDebrisSmallEntityClass
Definition
TreeDebrisSmallEntity.c:3
vector
Definition
vector.c:13
EOnInit
override void EOnInit(IEntity owner)
Definition
SCR_AIConfigComponent.c:87
Attribute
SCR_FieldOfViewSettings Attribute
Definition
SendGoalMessage.c:170
EntityEvent
EntityEvent
Various entity events.
Definition
EntityEvent.c:14
EntityFlags
EntityFlags
Various entity flags.
Definition
EntityFlags.c:14
SimulationState
SimulationState
Definition
SimulationState.c:19
scripts
Game
Entities
debris
TreeDebrisSmallEntity.c
Generated by
1.17.0