Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_HelicopterDamageManagerComponent.c
Go to the documentation of this file.
2 {
3 }
4 
5 class SCR_HelicopterDamageManagerComponent : SCR_VehicleDamageManagerComponent
6 {
7  protected ref array<SCR_RotorHitZone> m_aRotorHitZones = {};
8  protected float m_fRotorsEfficiency = 1;
9 
10  //------------------------------------------------------------------------------------------------
13  // TODO: Consider for all vehicles. Note destructible response indexes may still need it until wreck is stopped.
14  void EnableContactMaskOnHost(bool enabled)
15  {
16  Vehicle vehicle = Vehicle.Cast(GetOwner());
17  if (!vehicle)
18  return;
19 
20  RplComponent rpl = vehicle.GetRplComponent();
21  if (rpl && rpl.IsProxy())
22  return;
23 
24  if (enabled)
25  SetEventMask(vehicle, EntityEvent.CONTACT);
26  else
27  ClearEventMask(vehicle, EntityEvent.CONTACT);
28  }
29 
30  //------------------------------------------------------------------------------------------------
31  override void OnDamageStateChanged(EDamageState state)
32  {
33  super.OnDamageStateChanged(state);
34 
36  EnableContactMaskOnHost(state != EDamageState.DESTROYED);
37  }
38 
39  //------------------------------------------------------------------------------------------------
40  // Register simulation feature hitzone
41  override void RegisterVehicleHitZone(notnull HitZone hitZone)
42  {
43  super.RegisterVehicleHitZone(hitZone);
44 
45  // If it has rotor point info, it is a physical rotor
46  SCR_RotorHitZone rotorHitZone = SCR_RotorHitZone.Cast(hitZone);
47  if (rotorHitZone && rotorHitZone.GetPointInfo() && !m_aRotorHitZones.Contains(rotorHitZone))
48  m_aRotorHitZones.Insert(rotorHitZone);
49  }
50 
51  //------------------------------------------------------------------------------------------------
52  // Register simulation feature hitzone
53  override void UnregisterVehicleHitZone(HitZone hitZone)
54  {
55  super.UnregisterVehicleHitZone(hitZone);
56 
57  // Also unregister rotor hitzones
58  SCR_RotorHitZone rotorHitZone = SCR_RotorHitZone.Cast(hitZone);
59  if (rotorHitZone && rotorHitZone.GetPointInfo())
60  m_aRotorHitZones.RemoveItem(rotorHitZone);
61  }
62 
63  //------------------------------------------------------------------------------------------------
64  // Compute current simulation state of vehicle
65  // Called when hitzone damage state needs to be interpreted
66  override void UpdateVehicleState()
67  {
68  super.UpdateVehicleState();
69 
70  HelicopterControllerComponent controller = HelicopterControllerComponent.Cast(m_Controller);
71  VehicleHelicopterSimulation simulation = VehicleHelicopterSimulation.Cast(m_Simulation);
72 
73  if (!controller || !simulation || !simulation.IsValid())
74  return;
75 
76  int rotorID;
77  SCR_RotorHitZone rotorHitZone;
78  int rotorCount = simulation.RotorCount();
79  array<float> rotorEfficiencies = {};
80 
81  // By default rotor efficiency shall match the combined engine and gearbox efficiency
82  for (int i; i < rotorCount; i++)
83  {
84  rotorEfficiencies.Insert(m_fEngineEfficiency * m_fGearboxEfficiency);
85  }
86 
87  foreach (HitZone hitZone : m_aVehicleHitZones)
88  {
89  rotorHitZone = SCR_RotorHitZone.Cast(hitZone);
90  if (rotorHitZone)
91  {
92  rotorID = rotorHitZone.GetRotorIndex();
93  if (rotorEfficiencies.IsIndexValid(rotorID))
94  rotorEfficiencies[rotorID] = rotorEfficiencies[rotorID] * rotorHitZone.GetEfficiency();
95  }
96  }
97 
98  // Set rotor efficiency on simulation
100  foreach (int i, float rotorEfficiency : rotorEfficiencies)
101  {
102  simulation.RotorSetForceScaleState(i, rotorEfficiency);
103  simulation.RotorSetTorqueScaleState(i, rotorEfficiency);
104  m_fRotorsEfficiency *= rotorEfficiency;
105  }
106 
107  // Account for rotor damage
109  }
110 
111  //------------------------------------------------------------------------------------------------
112  override void SetEngineFunctional(bool functional)
113  {
114  super.SetEngineFunctional(functional && m_bGearboxFunctional);
115  }
116 
117  //------------------------------------------------------------------------------------------------
118  override void UpdateMovementDamage()
119  {
120  float movementDamage;
121 
122  if (!m_bEngineFunctional)
123  movementDamage = 1;
124  else
126 
127  if (!float.AlmostEqual(movementDamage, GetMovementDamage()))
128  SetMovementDamage(movementDamage);
129 
130  VehicleControllerComponent controller = VehicleControllerComponent.Cast(m_Controller);
131  if (controller)
132  controller.SetCanMove(movementDamage < 1);
133  }
134 }
m_fRotorsEfficiency
protected float m_fRotorsEfficiency
Definition: SCR_HelicopterDamageManagerComponent.c:8
OnDamageStateChanged
override void OnDamageStateChanged(EDamageState state)
Definition: SCR_HelicopterDamageManagerComponent.c:31
SCR_VehicleDamageManagerComponentClass
void SCR_VehicleDamageManagerComponentClass(BaseContainer prefab)
m_aRotorHitZones
SCR_HelicopterDamageManagerComponentClass m_aRotorHitZones
m_Controller
protected CompartmentControllerComponent m_Controller
Definition: SCR_VehicleDamageManagerComponent.c:197
m_fGearboxEfficiency
protected float m_fGearboxEfficiency
Definition: SCR_VehicleDamageManagerComponent.c:203
HitZone
Definition: HitZone.c:12
RegisterVehicleHitZone
override void RegisterVehicleHitZone(notnull HitZone hitZone)
Definition: SCR_HelicopterDamageManagerComponent.c:41
SetEngineFunctional
override void SetEngineFunctional(bool functional)
Definition: SCR_HelicopterDamageManagerComponent.c:112
SCR_VehicleDamageManagerComponent
void SCR_VehicleDamageManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_VehicleDamageManagerComponent.c:1720
m_bGearboxFunctional
protected bool m_bGearboxFunctional
Definition: SCR_VehicleDamageManagerComponent.c:204
EDamageState
EDamageState
Definition: EDamageState.c:12
m_bEngineFunctional
protected bool m_bEngineFunctional
Definition: SCR_VehicleDamageManagerComponent.c:201
m_Simulation
protected VehicleBaseSimulation m_Simulation
Definition: SCR_VehicleDamageManagerComponent.c:198
m_aVehicleHitZones
protected ref array< HitZone > m_aVehicleHitZones
Common vehicle features that will influence its simulation.
Definition: SCR_VehicleDamageManagerComponent.c:196
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
UpdateVehicleState
override void UpdateVehicleState()
Definition: SCR_HelicopterDamageManagerComponent.c:66
UpdateMovementDamage
override void UpdateMovementDamage()
Definition: SCR_HelicopterDamageManagerComponent.c:118
UnregisterVehicleHitZone
override void UnregisterVehicleHitZone(HitZone hitZone)
Definition: SCR_HelicopterDamageManagerComponent.c:53
m_fEngineEfficiency
protected float m_fEngineEfficiency
Definition: SCR_VehicleDamageManagerComponent.c:200
EnableContactMaskOnHost
void EnableContactMaskOnHost(bool enabled)
Definition: SCR_HelicopterDamageManagerComponent.c:14
SCR_HelicopterDamageManagerComponentClass
Definition: SCR_HelicopterDamageManagerComponent.c:1