Arma Reforger Explorer
1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Toggle main menu visibility
Loading...
Searching...
No Matches
SCR_ShellSoundComponent.c
Go to the documentation of this file.
1
[
ComponentEditorProps
(
category
:
"GameScripted/Sound"
, description:
"THIS IS THE SCRIPT DESCRIPTION."
, color:
"0 0 255 255"
)]
2
class
SCR_ShellSoundComponentClass
:
ProjectileSoundComponentClass
3
{
4
};
5
6
//------------------------------------------------------------------------------------------------
7
class
SCR_ShellSoundComponent : ProjectileSoundComponent
8
{
9
protected
ProjectileMoveComponent
m_ProjectileMoveComponent
;
10
protected
SignalsManagerComponent
m_SignalsManagerComponent
;
11
12
protected
int
m_iSignalIdxSpeed
= -1;
13
protected
int
m_iSignalIdxSpeedVertical
= -1;
14
protected
int
m_iSignalIdxDistanceToClosestPoint
= -1;
15
protected
int
m_iSignalIdxCosAngleProjectileToListener
= -1;
16
17
//------------------------------------------------------------------------------------------------
18
override
void
UpdateSoundJob
(
IEntity
owner,
float
timeSlice)
19
{
20
// Check component availability
21
if
(!
m_SignalsManagerComponent
|| !
m_ProjectileMoveComponent
)
22
return
;
23
24
// Get projectile velocity and set speed-related signals
25
vector
velocity =
m_ProjectileMoveComponent
.GetVelocity();
26
float
speed = velocity.Length();
27
m_SignalsManagerComponent
.SetSignalValue(
m_iSignalIdxSpeed
, speed);
28
m_SignalsManagerComponent
.SetSignalValue(
m_iSignalIdxSpeedVertical
, velocity[1]);
29
30
// Calculate a rough "Closest Point to camera position" based on simple linear projectile trajectory estimation
31
vector
position
= owner.
GetOrigin
();
32
velocity.Normalize();
// Turn velocity into direction vector
33
vector
cameraPosition = GetCameraPosition();
34
vector
dirProjectileToListener =
vector
.Direction(
position
,cameraPosition);
35
vector
closestPoint =
position
+ velocity *
vector
.Dot(dirProjectileToListener, velocity);
36
float
distanceToClosestPoint =
vector
.Distance(closestPoint,
position
);
37
m_SignalsManagerComponent
.SetSignalValue(
m_iSignalIdxDistanceToClosestPoint
, distanceToClosestPoint);
38
39
// Get cosinus of angle from projectile velocity to listener
40
dirProjectileToListener.Normalize();
41
float
cosAngleProjectileToListener =
vector
.Dot(dirProjectileToListener,velocity);
42
m_SignalsManagerComponent
.SetSignalValue(
m_iSignalIdxCosAngleProjectileToListener
, cosAngleProjectileToListener);
43
}
44
45
//------------------------------------------------------------------------------------------------
46
private
vector
GetCameraPosition()
47
{
48
CameraBase playerCamera =
GetGame
().GetCameraManager().CurrentCamera();
49
if
(!playerCamera)
50
return
vector
.Zero;
51
52
return
playerCamera.GetOrigin();
53
}
54
55
//------------------------------------------------------------------------------------------------
56
override
void
OnPostInit
(
IEntity
owner)
57
{
58
super.OnPostInit(owner);
59
60
// Find SignalsManager and BaseMove Components
61
m_SignalsManagerComponent
= SignalsManagerComponent.Cast(owner.
FindComponent
(SignalsManagerComponent));
62
m_ProjectileMoveComponent
= ProjectileMoveComponent.Cast(owner.
FindComponent
(ProjectileMoveComponent));
63
64
// Warn for missing components
65
if
(!
m_SignalsManagerComponent
)
66
Print
(
"Warning: SCR_ShellSoundComponent requires SignalsManagerComponent!"
);
67
68
if
(!
m_ProjectileMoveComponent
)
69
Print
(
"Warning: SCR_ShellSoundComponent requires ProjectileMoveComponent (or something inheriting from it)!"
);
70
71
// Get and set indices of signals
72
m_iSignalIdxSpeed
=
m_SignalsManagerComponent
.AddOrFindSignal(
"Speed"
);
73
m_iSignalIdxSpeedVertical
=
m_SignalsManagerComponent
.AddOrFindSignal(
"SpeedVertical"
);
74
m_iSignalIdxDistanceToClosestPoint
=
m_SignalsManagerComponent
.AddOrFindSignal(
"DistanceToClosestPoint"
, 1000);
75
m_iSignalIdxCosAngleProjectileToListener
=
m_SignalsManagerComponent
.AddOrFindSignal(
"CosAngleProjectileToListener"
);
76
}
77
78
//------------------------------------------------------------------------------------------------
79
void
SCR_ShellSoundComponent(IEntityComponentSource src,
IEntity
ent,
IEntity
parent)
80
{
81
SetScriptedMethodsCall(
true
);
82
}
83
84
//------------------------------------------------------------------------------------------------
85
void
~SCR_ShellSoundComponent()
86
{
87
}
88
};
GetGame
ArmaReforgerScripted GetGame()
Definition
game.c:1398
ComponentEditorProps
enum EAIGroupCombatMode ComponentEditorProps(category:"GameScripted/AI", description:"Component for utility AI system for groups")
Definition
SCR_AIGroupUtilityComponent.c:12
position
vector position
Definition
SCR_DestructibleTreeV2.c:30
category
params category
Definition
SCR_VehicleDamageManagerComponent.c:302
IEntity
enum EVehicleType IEntity
IEntity
Definition
IEntity.c:13
IEntity::FindComponent
proto external Managed FindComponent(typename typeName)
IEntity::GetOrigin
proto external vector GetOrigin()
ProjectileMoveComponent
Definition
ProjectileMoveComponent.c:13
ProjectileSoundComponentClass
Definition
ProjectileSoundComponent.c:13
SCR_ShellSoundComponentClass
Definition
SCR_ShellSoundComponent.c:3
SCR_ShellSoundComponent::UpdateSoundJob
override void UpdateSoundJob(IEntity owner, float timeSlice)
Definition
SCR_ShellSoundComponent.c:18
SCR_ShellSoundComponent::m_ProjectileMoveComponent
ProjectileMoveComponent m_ProjectileMoveComponent
Definition
SCR_ShellSoundComponent.c:9
SCR_ShellSoundComponent::m_iSignalIdxSpeedVertical
int m_iSignalIdxSpeedVertical
Definition
SCR_ShellSoundComponent.c:13
SCR_ShellSoundComponent::m_iSignalIdxDistanceToClosestPoint
int m_iSignalIdxDistanceToClosestPoint
Definition
SCR_ShellSoundComponent.c:14
SCR_ShellSoundComponent::m_iSignalIdxCosAngleProjectileToListener
int m_iSignalIdxCosAngleProjectileToListener
Definition
SCR_ShellSoundComponent.c:15
SCR_ShellSoundComponent::m_SignalsManagerComponent
SignalsManagerComponent m_SignalsManagerComponent
Definition
SCR_ShellSoundComponent.c:10
SCR_ShellSoundComponent::m_iSignalIdxSpeed
int m_iSignalIdxSpeed
Definition
SCR_ShellSoundComponent.c:12
SignalsManagerComponent
Definition
SignalsManagerComponent.c:13
vector
Definition
vector.c:13
Print
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
OnPostInit
@ OnPostInit
Definition
SndComponentCallbacks.c:15
scripts
Game
Components
SCR_ShellSoundComponent.c
Generated by
1.17.0