Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_EngineHitZone.c
Go to the documentation of this file.
2 {
3  [Attribute("25", UIWidgets.Auto, desc: "Minimum engine power scale (% of initial)", params: "0 100 0.1")]
4  protected float m_fMinimumEnginePowerScale;
5 
6  [Attribute("20", UIWidgets.Auto, desc: "Minimum engine startup chance (% of initial)", params: "0 100 0.1")]
7  protected float m_fMinimumEngineStartupChance;
8 
9  protected SCR_PowerComponent m_Power;
10 
11  //------------------------------------------------------------------------------------------------
12  float GetEfficiency()
13  {
14  EDamageState state = GetDamageState();
15  float efficiency = GetDamageStateThreshold(state);
16 
17  // Battery influence on engine power output
18  if (m_Power && m_Power.ShouldApplyNoPowerPenalty() && !m_Power.HasPower())
19  efficiency *= m_Power.GetNoPowerMultiplier();
20 
21  return Math.Lerp(0.01 * m_fMinimumEnginePowerScale, 1, efficiency);
22  }
23 
25  override void OnInit(IEntity pOwnerEntity, GenericComponent pManagerComponent)
26  {
27  super.OnInit(pOwnerEntity, pManagerComponent);
28 
29  Vehicle vehicle = Vehicle.Cast(pOwnerEntity.GetRootParent());
30  if (!vehicle)
31  return;
32 
34  if (damageManager)
35  damageManager.RegisterVehicleHitZone(this);
36 
37  m_Power = SCR_PowerComponent.Cast(vehicle.FindComponent(SCR_PowerComponent));
38  if (m_Power)
39  m_Power.GetEventBatteryStateChanged().Insert(UpdateEngineState);
40  }
41 
42  //------------------------------------------------------------------------------------------------
55  override void OnDamage(notnull BaseDamageContext damageContext)
56  {
57  super.OnDamage(damageContext);
58 
59  // Powerful impact should always stop engine
60  if (damageContext.damageValue < GetCriticalDamageThreshold()*GetMaxHealth())
61  return;
62 
63  BaseVehicleNodeComponent node = BaseVehicleNodeComponent.Cast(GetOwner().FindComponent(BaseVehicleNodeComponent));
65  {
66  VehicleControllerComponent controller;
67  if (node)
68  controller = VehicleControllerComponent.Cast(node.FindComponent(VehicleControllerComponent));
69 
70  if (controller && controller.IsEngineOn())
71  controller.StopEngine(false);
72  }
73  else
74  {
75  VehicleControllerComponent_SA controller;
76  if (node)
77  controller = VehicleControllerComponent_SA.Cast(node.FindComponent(VehicleControllerComponent_SA));
78 
79  if (controller && controller.IsEngineOn())
80  controller.StopEngine(false);
81  }
82  }
83 
84  //------------------------------------------------------------------------------------------------
88  override void OnDamageStateChanged()
89  {
90  super.OnDamageStateChanged();
91 
92  UpdateEngineState();
93  }
94 
95  //------------------------------------------------------------------------------------------------
99  void UpdateEngineState()
100  {
101  Vehicle vehicle = Vehicle.Cast(GetOwner().GetRootParent());
102  if (!vehicle)
103  return;
104 
105  SCR_VehicleDamageManagerComponent damageManager = SCR_VehicleDamageManagerComponent.Cast(vehicle.GetDamageManager());
106  if (damageManager)
107  damageManager.UpdateVehicleState();
108 
109  // Damage and battery influence on starter and engine power output
110  // TODO: Delegate this feature to controller/damage manager
111  EDamageState state = GetDamageState();
112  float health = GetDamageStateThreshold(state);
113  float startupChance;
114  if (m_Power && !m_Power.HasPower())
115  startupChance = 0;
116  else
117  startupChance = Math.Lerp(m_fMinimumEngineStartupChance, 100, health);
118 
120  {
121  VehicleControllerComponent controller = VehicleControllerComponent.Cast(vehicle.GetVehicleController());
122  if (controller)
123  controller.SetEngineStartupChance(startupChance);
124  }
125  else
126  {
127  VehicleControllerComponent_SA controller = VehicleControllerComponent_SA.Cast(vehicle.GetVehicleController());
128  if (controller)
129  controller.SetEngineStartupChance(startupChance);
130  }
131  }
132 }
BaseDamageContext
Definition: BaseDamageContext.c:12
GetMaxHealth
float GetMaxHealth()
Definition: SCR_DestructibleEntity.c:122
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_VehicleDamageManagerComponent
void SCR_VehicleDamageManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_VehicleDamageManagerComponent.c:1720
EDamageState
EDamageState
Definition: EDamageState.c:12
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
GetIsClientAuthority
override bool GetIsClientAuthority()
Definition: game.c:268
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_VehicleHitZone
Definition: SCR_VehicleHitZone.c:1
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
SCR_EngineHitZone
Definition: SCR_EngineHitZone.c:1
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24