Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_PowerComponent.c
Go to the documentation of this file.
1 [EntityEditorProps(category: "GameScripted/ScriptWizard", description: "THIS IS THE SCRIPT DESCRIPTION.", color: "0 0 255 255")]
3 {
4 }
5 
6 class SCR_PowerComponent : ScriptGameComponent
7 {
8  [Attribute( defvalue: "1", uiwidget: UIWidgets.CheckBox, desc: "Should the engine output be reduced when there's no power (batteries destroyed)")]
9  private bool m_bShouldApplyNoPowerPenalty;
10 
11  [Attribute( defvalue: "0.4", uiwidget: UIWidgets.EditBox, desc: "The multiplier to apply to the engine output in case the vehicle has no power (batteries destroyed)")]
12  private float m_fNoPowerMultiplier;
13 
14  private ref ScriptInvoker m_EventBatteryStateChanged;
15  private ref array<HitZone> m_aBatteryHitZones;
16  private bool m_bHasPower = true;
17 
18  //------------------------------------------------------------------------------------------------
20  bool HasPower()
21  {
22  return m_bHasPower;
23  }
24 
25  //------------------------------------------------------------------------------------------------
28  {
29  return m_bShouldApplyNoPowerPenalty;
30  }
31 
32  //------------------------------------------------------------------------------------------------
35  {
36  return m_fNoPowerMultiplier;
37  }
38 
39  //------------------------------------------------------------------------------------------------
42  ScriptInvoker GetEventBatteryStateChanged(bool createNew = true)
43  {
44  if (createNew && !m_EventBatteryStateChanged)
45  m_EventBatteryStateChanged = new ScriptInvoker();
46 
48  }
49 
53  {
54  // Power is available if there are no colliders
55  bool hasPower = !m_aBatteryHitZones || m_aBatteryHitZones.IsEmpty();
56 
58  {
59  foreach (HitZone hitZone : m_aBatteryHitZones)
60  {
61  if (hitZone.GetDamageState() != EDamageState.DESTROYED)
62  {
63  hasPower = true;
64  break;
65  }
66  }
67  }
68 
69  if (m_bHasPower == hasPower)
70  return;
71 
72  m_bHasPower = hasPower;
73 
75  m_EventBatteryStateChanged.Invoke(hasPower);
76  }
77 
78  //------------------------------------------------------------------------------------------------
81  void RegisterBatteryHitZone(notnull HitZone hitZone)
82  {
83  if (!m_aBatteryHitZones)
84  m_aBatteryHitZones = {};
85 
86  m_aBatteryHitZones.Insert(hitZone);
87 
88  // Trigger power state update if new battery has different state
89  bool hasPower = hitZone.GetDamageState() != EDamageState.DESTROYED;
90  if (m_bHasPower != hasPower)
92  }
93 }
UpdatePowerState
void UpdatePowerState()
Definition: SCR_PowerComponent.c:52
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
HitZone
Definition: HitZone.c:12
m_EventBatteryStateChanged
private ref ScriptInvoker m_EventBatteryStateChanged
Definition: SCR_PowerComponent.c:14
Attribute
SCR_PowerComponentClass ScriptGameComponentClass Attribute(defvalue:"1", uiwidget:UIWidgets.CheckBox, desc:"Should the engine output be reduced when there's no power (batteries destroyed)")] private bool m_bShouldApplyNoPowerPenalty
ScriptGameComponentClass
Definition: ScriptGameComponent.c:12
m_bHasPower
private bool m_bHasPower
Definition: SCR_PowerComponent.c:16
EDamageState
EDamageState
Definition: EDamageState.c:12
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
m_fNoPowerMultiplier
private float m_fNoPowerMultiplier
Definition: SCR_PowerComponent.c:12
GetNoPowerMultiplier
float GetNoPowerMultiplier()
Definition: SCR_PowerComponent.c:34
HasPower
bool HasPower()
Definition: SCR_PowerComponent.c:20
RegisterBatteryHitZone
void RegisterBatteryHitZone(notnull HitZone hitZone)
Definition: SCR_PowerComponent.c:81
GetEventBatteryStateChanged
ScriptInvoker GetEventBatteryStateChanged(bool createNew=true)
Definition: SCR_PowerComponent.c:42
m_aBatteryHitZones
private ref array< HitZone > m_aBatteryHitZones
Definition: SCR_PowerComponent.c:15
SCR_PowerComponentClass
Definition: SCR_PowerComponent.c:2
ShouldApplyNoPowerPenalty
bool ShouldApplyNoPowerPenalty()
Definition: SCR_PowerComponent.c:27
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180