Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_HelicopterSoundComponent.c
Go to the documentation of this file.
1 [EntityEditorProps(category: "GameScripted/Sound", description: "")]
3 {
4 }
5 
6 class SCR_HelicopterSoundComponent : SCR_VehicleSoundComponent
7 {
8  // Signal names
9  protected const string SPEED_TO_CAMERA_SIGNAL_NAME = "SpeedToCamera";
10  protected const string DISTANCE_SIGNAL_NAME = "Distance";
11  protected const string ALTITUDE_AGL = "AltitudeAGL";
12  protected const string MAIN_ROTOR_RPM_SCALED = "MainRotorRPMScaled";
13  protected const string MAIN_ROTOR_HIT_ZONE_NAME = "RotorMain";
14  protected const string DAMAGE_STATE_SIGNAL_NAME = "DamageState";
15  protected const string ROTOR_MAIN_DAMAGE_STATE_SIGNAL_NAME = "RotorMainDamageState";
16 
17  // Constants
18  protected const float UPDATE_TIME = 0.15;
19  protected const float WASH_ROTOR_DISTANCE_LIMIT = 100;
20  protected const float ALTITUDE_LIMIT = 50;
21  protected const float MAIN_ROTOR_RPM_SCALED_THRESHOLD = 0.2;
22 
23  // Signal indexes
24  protected int m_iDistanceSignalIdx;
26  protected int m_AltitudeAGLSignalIdx;
27  protected int m_MainRotorRPMScaledIdx;
28 
29  //
30  protected SignalsManagerComponent m_SignalsManagerComponent;
31  protected float m_fTimer;
32 
34  protected AudioHandle m_WashRotorAudioHandle = AudioHandle.Invalid;
35 
37  protected SCR_HelicopterDamageManagerComponent m_HelicopterDamageManagerComponent;
38 
41 
43 
44  //------------------------------------------------------------------------------------------------
45  override void UpdateSoundJob(IEntity owner, float timeSlice)
46  {
47  super.UpdateSoundJob(owner, timeSlice);
48 
50  return;
51 
52  m_fTimer += timeSlice;
53  if (m_fTimer < UPDATE_TIME)
54  return;
55 
57  HandleWashRotor(owner);
58  m_fTimer = 0;
59  }
60 
61  //------------------------------------------------------------------------------------------------
64  protected void CalculateSpeedToCameraSignal(IEntity owner)
65  {
66  Physics physics = owner.GetPhysics();
67  if (!physics)
68  return;
69 
70  vector cameraTransform[4];
71  GetGame().GetWorld().GetCurrentCamera(cameraTransform);
72 
73  vector entityPos = owner.GetOrigin();
74  vector entityVelocity = physics.GetVelocity();
75 
76  vector directionCameraEntity = (cameraTransform[3] - entityPos).Normalized();
77  float speed = vector.Dot(entityVelocity, directionCameraEntity);
78 
79  // Set SpeedToCamera signal
81  }
82 
83  //------------------------------------------------------------------------------------------------
86  protected void HandleWashRotor(IEntity owner)
87  {
89  {
90  Terminate(m_WashRotorAudioHandle);
91  return;
92  }
93 
94  float altitudeAGL = m_SignalsManagerComponent.GetSignalValue(m_AltitudeAGLSignalIdx);
95  if (altitudeAGL > ALTITUDE_LIMIT)
96  {
97  Terminate(m_WashRotorAudioHandle);
98  return;
99  }
100 
101  vector mat[4];
102  owner.GetTransform(mat);
103  mat[3][1] = mat[3][1] - altitudeAGL;
104 
105  if (IsFinishedPlaying(m_WashRotorAudioHandle))
106  m_WashRotorAudioHandle = SoundEvent(SCR_SoundEvent.SOUND_ROTOR_WASH_LP);
107 
108  SetSoundTransformation(m_WashRotorAudioHandle, mat);
109  }
110 
111  //------------------------------------------------------------------------------------------------
112  protected void RegisterOnDamageChanged()
113  {
114  m_HelicopterDamageManagerComponent = SCR_HelicopterDamageManagerComponent.Cast(GetOwner().FindComponent(SCR_HelicopterDamageManagerComponent));
116  return;
117 
118  m_HelicopterDamageManagerComponent.GetOnDamageStateChanged().Insert(OnDamageStateChanged);
119  }
120 
121  //------------------------------------------------------------------------------------------------
122  protected void UnregisterOnDamageChanged()
123  {
125  m_HelicopterDamageManagerComponent.GetOnDamageStateChanged().Remove(OnDamageStateChanged);
126  }
127 
128  //------------------------------------------------------------------------------------------------
129  protected void OnDamageStateChanged(EDamageState state)
130  {
131  m_SignalsManagerComponent.SetSignalValue(m_SignalsManagerComponent.AddOrFindSignal(DAMAGE_STATE_SIGNAL_NAME), state);
132  }
133 
134  //------------------------------------------------------------------------------------------------
136  {
137  SCR_DamageManagerComponent hitZoneContainerComponent = SCR_DamageManagerComponent.Cast(GetOwner().FindComponent(SCR_DamageManagerComponent));
138  if (!hitZoneContainerComponent)
139  return;
140 
141  HitZone hitZone = hitZoneContainerComponent.GetHitZoneByName(MAIN_ROTOR_HIT_ZONE_NAME);
142  m_RotorMainHitZone = SCR_HitZone.Cast(hitZone);
143  if (m_RotorMainHitZone)
144  m_RotorMainHitZone.GetOnDamageStateChanged().Insert(RotorMainOnStateChanged);
145  }
146 
147  //------------------------------------------------------------------------------------------------
149  {
150  SCR_DamageManagerComponent hitZoneContainerComponent = SCR_DamageManagerComponent.Cast(GetOwner().FindComponent(SCR_DamageManagerComponent));
151  if (!hitZoneContainerComponent)
152  return;
153 
154  HitZone hitZone = hitZoneContainerComponent.GetHitZoneByName(MAIN_ROTOR_HIT_ZONE_NAME);
155  m_RotorMainHitZone = SCR_HitZone.Cast(hitZone);
156  if (m_RotorMainHitZone)
157  m_RotorMainHitZone.GetOnDamageStateChanged().Remove(RotorMainOnStateChanged);
158  }
159 
160  //------------------------------------------------------------------------------------------------
161  protected void RotorMainOnStateChanged()
162  {
163  m_eRotorMainDamageState = m_RotorMainHitZone.GetDamageState();
164 
166  return;
167 
169  }
170 
171  //------------------------------------------------------------------------------------------------
172  override void OnPostInit(IEntity owner)
173  {
174  super.OnPostInit(owner);
175 
176  m_SignalsManagerComponent = SignalsManagerComponent.Cast(owner.FindComponent(SignalsManagerComponent));
178  return;
179 
184  }
185 
186  //------------------------------------------------------------------------------------------------
187  override void OnInit(IEntity owner)
188  {
189  super.OnInit(owner);
190 
193  }
194 
195  //------------------------------------------------------------------------------------------------
196  // destructor
198  {
201  }
202 }
ROTOR_MAIN_DAMAGE_STATE_SIGNAL_NAME
const protected string ROTOR_MAIN_DAMAGE_STATE_SIGNAL_NAME
Definition: SCR_HelicopterSoundComponent.c:15
m_fTimer
protected float m_fTimer
Definition: SCR_HelicopterSoundComponent.c:31
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
SCR_VehicleSoundComponent
void SCR_VehicleSoundComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_VehicleSoundComponent.c:78
HandleWashRotor
protected void HandleWashRotor(IEntity owner)
Definition: SCR_HelicopterSoundComponent.c:86
m_WashRotorAudioHandle
protected AudioHandle m_WashRotorAudioHandle
Wash rotor audio handle.
Definition: SCR_HelicopterSoundComponent.c:34
HitZone
Definition: HitZone.c:12
m_iDistanceSignalIdx
protected int m_iDistanceSignalIdx
Definition: SCR_HelicopterSoundComponent.c:24
m_AltitudeAGLSignalIdx
protected int m_AltitudeAGLSignalIdx
Definition: SCR_HelicopterSoundComponent.c:26
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_SoundEvent
Definition: SCR_SoundEvent.c:1
~SCR_HelicopterSoundComponent
void ~SCR_HelicopterSoundComponent()
Definition: SCR_HelicopterSoundComponent.c:197
RegisterOnDamageChanged
protected void RegisterOnDamageChanged()
Definition: SCR_HelicopterSoundComponent.c:112
EDamageState
EDamageState
Definition: EDamageState.c:12
OnDamageStateChanged
protected void OnDamageStateChanged(EDamageState state)
Definition: SCR_HelicopterSoundComponent.c:129
m_MainRotorRPMScaledIdx
protected int m_MainRotorRPMScaledIdx
Definition: SCR_HelicopterSoundComponent.c:27
m_HelicopterDamageManagerComponent
protected SCR_HelicopterDamageManagerComponent m_HelicopterDamageManagerComponent
Damage state signal.
Definition: SCR_HelicopterSoundComponent.c:37
DAMAGE_STATE_SIGNAL_NAME
const protected string DAMAGE_STATE_SIGNAL_NAME
Definition: SCR_HelicopterSoundComponent.c:14
SoundEvent
SoundComponentClass SimpleSoundComponentClass SoundEvent(string eventName)
Play a sound from the owner entity's position.
ALTITUDE_AGL
const protected string ALTITUDE_AGL
Definition: SCR_HelicopterSoundComponent.c:11
UnregisterRotorMainOnDamageChanged
protected void UnregisterRotorMainOnDamageChanged()
Definition: SCR_HelicopterSoundComponent.c:148
ALTITUDE_LIMIT
const protected float ALTITUDE_LIMIT
Definition: SCR_HelicopterSoundComponent.c:20
m_eRotorMainDamageState
protected EDamageState m_eRotorMainDamageState
Definition: SCR_HelicopterSoundComponent.c:42
OnPostInit
override void OnPostInit(IEntity owner)
Called on PostInit when all components are added.
Definition: SCR_HelicopterSoundComponent.c:172
MAIN_ROTOR_RPM_SCALED_THRESHOLD
const protected float MAIN_ROTOR_RPM_SCALED_THRESHOLD
Definition: SCR_HelicopterSoundComponent.c:21
RotorMainOnStateChanged
protected void RotorMainOnStateChanged()
Definition: SCR_HelicopterSoundComponent.c:161
SCR_HitZoneStateSignal
Definition: SCR_HitZoneStateSignal.c:1
m_iSpeedToCameraSignalIdx
protected int m_iSpeedToCameraSignalIdx
Definition: SCR_HelicopterSoundComponent.c:25
m_RotorMainHitZone
protected SCR_HitZone m_RotorMainHitZone
Main rotor damage state.
Definition: SCR_HelicopterSoundComponent.c:40
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
SCR_VehicleSoundComponentClass
Definition: SCR_VehicleSoundComponent.c:2
m_SignalsManagerComponent
protected SignalsManagerComponent m_SignalsManagerComponent
Definition: SCR_HelicopterSoundComponent.c:30
WASH_ROTOR_DISTANCE_LIMIT
const protected float WASH_ROTOR_DISTANCE_LIMIT
Definition: SCR_HelicopterSoundComponent.c:19
SCR_HitZone
Definition: SCR_HitZone.c:1
UPDATE_TIME
const protected float UPDATE_TIME
Definition: SCR_HelicopterSoundComponent.c:18
SCR_HelicopterSoundComponentClass
Definition: SCR_HelicopterSoundComponent.c:2
DISTANCE_SIGNAL_NAME
const protected string DISTANCE_SIGNAL_NAME
Definition: SCR_HelicopterSoundComponent.c:10
SPEED_TO_CAMERA_SIGNAL_NAME
SCR_HelicopterSoundComponentClass SPEED_TO_CAMERA_SIGNAL_NAME
UnregisterOnDamageChanged
protected void UnregisterOnDamageChanged()
Definition: SCR_HelicopterSoundComponent.c:122
UpdateSoundJob
override void UpdateSoundJob(IEntity owner, float timeSlice)
Call when component is in range.
Definition: SCR_HelicopterSoundComponent.c:45
RegisterRotorMainOnDamageChanged
protected void RegisterRotorMainOnDamageChanged()
Definition: SCR_HelicopterSoundComponent.c:135
OnInit
override void OnInit(IEntity owner)
Definition: SCR_HelicopterSoundComponent.c:187
CalculateSpeedToCameraSignal
protected void CalculateSpeedToCameraSignal(IEntity owner)
Definition: SCR_HelicopterSoundComponent.c:64
MAIN_ROTOR_RPM_SCALED
const protected string MAIN_ROTOR_RPM_SCALED
Definition: SCR_HelicopterSoundComponent.c:12
MAIN_ROTOR_HIT_ZONE_NAME
const protected string MAIN_ROTOR_HIT_ZONE_NAME
Definition: SCR_HelicopterSoundComponent.c:13
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180